Java Code Examples for javax.swing.UIDefaults

The following examples show how to use javax.swing.UIDefaults. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openjdk-8   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the value retrieved from the <code>UIDefaults</code> table.
 * The object is created each time it is accessed.
 *
 * @param table a <code>UIDefaults</code> table
 * @return the created <code>Object</code>
 */
@Override
public Object createValue(UIDefaults table) {
    Object obj = null;
    // check specified state
    if (state!=null){
        obj = uiDefaults.get(prefix+"["+state+"]."+suffix);
    }
    // check enabled state
    if (obj==null){
        obj = uiDefaults.get(prefix+"[Enabled]."+suffix);
    }
    // check for defaults
    if (obj==null){
        if (isFont) {
            obj = uiDefaults.get("defaultFont");
        } else {
            obj = uiDefaults.get(suffix);
        }
    }
    return obj;
}
 
Example 3
Source Project: Bytecoder   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the value retrieved from the <code>UIDefaults</code> table.
 * The object is created each time it is accessed.
 *
 * @param table a <code>UIDefaults</code> table
 * @return the created <code>Object</code>
 */
@Override
public Object createValue(UIDefaults table) {
    Object obj = null;
    // check specified state
    if (state!=null){
        obj = uiDefaults.get(prefix+"["+state+"]."+suffix);
    }
    // check enabled state
    if (obj==null){
        obj = uiDefaults.get(prefix+"[Enabled]."+suffix);
    }
    // check for defaults
    if (obj==null){
        if (isFont) {
            obj = uiDefaults.get("defaultFont");
        } else {
            obj = uiDefaults.get(suffix);
        }
    }
    return obj;
}
 
Example 4
Source Project: openjdk-jdk9   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 5
Source Project: openjdk-jdk8u   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 6
Source Project: FlatLaf   Source File: IntelliJTheme.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * http://www.jetbrains.org/intellij/sdk/docs/reference_guide/ui_themes/themes_customize.html#defining-named-colors
 */
private void loadNamedColors( UIDefaults defaults ) {
	if( colors == null )
		return;

	namedColors = new HashMap<>();

	for( Map.Entry<String, String> e : colors.entrySet() ) {
		String value = e.getValue();
		ColorUIResource color = UIDefaultsLoader.parseColor( value );
		if( color != null ) {
			String key = e.getKey();
			namedColors.put( key, color );
			defaults.put( "ColorPalette." + key, color );
		}
	}
}
 
Example 7
private void initBorderDefaults(UIDefaults table) {
	Object[] borderDefaults = { "TextField.border", Borders.getTextFieldBorder(), "PasswordField.border",
			Borders.getTextFieldBorder(), "FilterTextField.border", Borders.getTextFieldBorder(),
			"FormattedTextField.border", Borders.getTextFieldBorder(), "TextArea.border", Borders.getTextFieldBorder(),
			"SplitPane.border", Borders.getSplitPaneBorder(), "ScrollPane.border", Borders.getScrollPaneBorder(),
			"InternalFrame.border", Borders.getInternalFrameBorder(), "Table.scrollPaneBorder", null,   // removed
			// table
			// border,
			// original:
			// Borders.getSplitPaneBorder()
			"Table.tabbedPaneBorder", null,   // remove double borders
			"ToolBar.border", Borders.getToolBarBorder(), "Spinner.border", Borders.getSpinnerBorder(),
			"ComboBox.border", Borders.getComboBoxBorder(), "Button.border", Borders.getEmptyButtonBorder(),
			"ToggleButton.border", Borders.getEmptyButtonBorder(), "ProgressBar.border", Borders.getProgressBarBorder(),
			"PopupMenu.border", Borders.getPopupMenuBorder(), "CheckBox.border", Borders.getCheckBoxBorder(),
			"RadioButton.border", Borders.getCheckBoxBorder(), "ToolTip.border", Borders.getToolTipBorder(),
			"MenuBar.border", Borders.getMenuBarBorder(), "CheckBox.icon", IconFactory.getCheckBoxIcon(),
			"RadioButton.icon", IconFactory.getRadioButtonIcon(), "ComboBox.focusCellHighlightBorder",
			Borders.getComboBoxListCellRendererFocusBorder(), };
	table.putDefaults(borderDefaults);
}
 
Example 8
public static void main(final String[] args)
        throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
        UIDefaults ui = UIManager.getDefaults();
        ui.put("control", new ColorUIResource(54, 54, 54));
        final JDialog dialog = new JDialog();
        final JFrame frame = new JFrame();
        frame.pack();
        dialog.pack();
        final Color dialogBackground = dialog.getBackground();
        final Color frameBackground = frame.getBackground();
        frame.dispose();
        dialog.dispose();
        if (!dialogBackground.equals(frameBackground)) {
            System.err.println("Expected:" + frameBackground);
            System.err.println("Actual:" + dialogBackground);
            throw new RuntimeException("Wrong background color");
        }
    });
}
 
Example 9
Source Project: hottub   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates the value retrieved from the <code>UIDefaults</code> table.
 * The object is created each time it is accessed.
 *
 * @param table a <code>UIDefaults</code> table
 * @return the created <code>Object</code>
 */
@Override
public Object createValue(UIDefaults table) {
    Object obj = null;
    // check specified state
    if (state!=null){
        obj = uiDefaults.get(prefix+"["+state+"]."+suffix);
    }
    // check enabled state
    if (obj==null){
        obj = uiDefaults.get(prefix+"[Enabled]."+suffix);
    }
    // check for defaults
    if (obj==null){
        if (isFont) {
            obj = uiDefaults.get("defaultFont");
        } else {
            obj = uiDefaults.get(suffix);
        }
    }
    return obj;
}
 
Example 10
@Override
public void addCustomEntriesToTable(UIDefaults table) {

    Border blackLineBorder =
            new BorderUIResource(new LineBorder(getBlack()));
    Border whiteLineBorder =
            new BorderUIResource(new LineBorder(getWhite()));

    Object textBorder = new BorderUIResource(new CompoundBorder(
            blackLineBorder,
            new BasicBorders.MarginBorder()));

    table.put("ToolTip.border", blackLineBorder);
    table.put("TitledBorder.border", blackLineBorder);
    table.put("Table.focusCellHighlightBorder", whiteLineBorder);
    table.put("Table.focusCellForeground", getWhite());

    table.put("TextField.border", textBorder);
    table.put("PasswordField.border", textBorder);
    table.put("TextArea.border", textBorder);
    table.put("TextPane.font", textBorder);


}
 
Example 11
/**
 * Creates the value retrieved from the <code>UIDefaults</code> table.
 * The object is created each time it is accessed.
 *
 * @param table a <code>UIDefaults</code> table
 * @return the created <code>Object</code>
 */
@Override
public Object createValue(UIDefaults table) {
    Object obj = null;
    // check specified state
    if (state!=null){
        obj = uiDefaults.get(prefix+"["+state+"]."+suffix);
    }
    // check enabled state
    if (obj==null){
        obj = uiDefaults.get(prefix+"[Enabled]."+suffix);
    }
    // check for defaults
    if (obj==null){
        if (isFont) {
            obj = uiDefaults.get("defaultFont");
        } else {
            obj = uiDefaults.get(suffix);
        }
    }
    return obj;
}
 
Example 12
Source Project: seaglass   Source File: SeaGlassLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Use Aqua settings for some properties if we're on a Mac.
 *
 * @param d the UI defaults map.
 */
private void defineAquaSettings(UIDefaults d) {
    try {

        // Instantiate Aqua but don't install it.
        Class<?>    lnfClass     = Class.forName(UIManager.getSystemLookAndFeelClassName(), true,
                                                 Thread.currentThread().getContextClassLoader());
        LookAndFeel aqua         = (LookAndFeel) lnfClass.newInstance();
        UIDefaults  aquaDefaults = aqua.getDefaults();

        // Use Aqua for any menu UI classes.
        d.put("MenuBarUI", aquaDefaults.get("MenuBarUI"));
        d.put("MenuUI", aquaDefaults.get("MenuUI"));
    } catch (Exception e) {

        // TODO Should we do something with this exception?
        e.printStackTrace();
    }
}
 
Example 13
Source Project: Java8CN   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the value retrieved from the <code>UIDefaults</code> table.
 * The object is created each time it is accessed.
 *
 * @param table a <code>UIDefaults</code> table
 * @return the created <code>Object</code>
 */
@Override
public Object createValue(UIDefaults table) {
    Object obj = null;
    // check specified state
    if (state!=null){
        obj = uiDefaults.get(prefix+"["+state+"]."+suffix);
    }
    // check enabled state
    if (obj==null){
        obj = uiDefaults.get(prefix+"[Enabled]."+suffix);
    }
    // check for defaults
    if (obj==null){
        if (isFont) {
            obj = uiDefaults.get("defaultFont");
        } else {
            obj = uiDefaults.get(suffix);
        }
    }
    return obj;
}
 
Example 14
public static void main(final String[] args)
        throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
        UIDefaults ui = UIManager.getDefaults();
        ui.put("control", new ColorUIResource(54, 54, 54));
        final JDialog dialog = new JDialog();
        final JFrame frame = new JFrame();
        frame.pack();
        dialog.pack();
        final Color dialogBackground = dialog.getBackground();
        final Color frameBackground = frame.getBackground();
        frame.dispose();
        dialog.dispose();
        if (!dialogBackground.equals(frameBackground)) {
            System.err.println("Expected:" + frameBackground);
            System.err.println("Actual:" + dialogBackground);
            throw new RuntimeException("Wrong background color");
        }
    });
}
 
Example 15
Source Project: jdk8u_jdk   Source File: XTextFieldPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 16
Source Project: jdk8u-jdk   Source File: ContrastMetalTheme.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addCustomEntriesToTable(UIDefaults table) {

    Border blackLineBorder =
            new BorderUIResource(new LineBorder(getBlack()));
    Border whiteLineBorder =
            new BorderUIResource(new LineBorder(getWhite()));

    Object textBorder = new BorderUIResource(new CompoundBorder(
            blackLineBorder,
            new BasicBorders.MarginBorder()));

    table.put("ToolTip.border", blackLineBorder);
    table.put("TitledBorder.border", blackLineBorder);
    table.put("Table.focusCellHighlightBorder", whiteLineBorder);
    table.put("Table.focusCellForeground", getWhite());

    table.put("TextField.border", textBorder);
    table.put("PasswordField.border", textBorder);
    table.put("TextArea.border", textBorder);
    table.put("TextPane.font", textBorder);


}
 
Example 17
@Override
public void addCustomEntriesToTable(UIDefaults table) {

    Border blackLineBorder =
            new BorderUIResource(new LineBorder(getBlack()));
    Border whiteLineBorder =
            new BorderUIResource(new LineBorder(getWhite()));

    Object textBorder = new BorderUIResource(new CompoundBorder(
            blackLineBorder,
            new BasicBorders.MarginBorder()));

    table.put("ToolTip.border", blackLineBorder);
    table.put("TitledBorder.border", blackLineBorder);
    table.put("Table.focusCellHighlightBorder", whiteLineBorder);
    table.put("Table.focusCellForeground", getWhite());

    table.put("TextField.border", textBorder);
    table.put("PasswordField.border", textBorder);
    table.put("TextArea.border", textBorder);
    table.put("TextPane.font", textBorder);


}
 
Example 18
@Override
public void addCustomEntriesToTable(UIDefaults table) {
    super.addCustomEntriesToTable(table);

    final int internalFrameIconSize = 22;
    table.put("InternalFrame.closeIcon", MetalIconFactory.
            getInternalFrameCloseIcon(internalFrameIconSize));
    table.put("InternalFrame.maximizeIcon", MetalIconFactory.
            getInternalFrameMaximizeIcon(internalFrameIconSize));
    table.put("InternalFrame.iconifyIcon", MetalIconFactory.
            getInternalFrameMinimizeIcon(internalFrameIconSize));
    table.put("InternalFrame.minimizeIcon", MetalIconFactory.
            getInternalFrameAltMaximizeIcon(internalFrameIconSize));


    table.put("ScrollBar.width", 21);



}
 
Example 19
Source Project: TencentKona-8   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 20
Source Project: TencentKona-8   Source File: XTextFieldPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 21
/**
 * Initializes the module. Use this method to perform all initial setup operations. This method is called only once in
 * a modules lifetime. If the initializing cannot be completed, throw a ModuleInitializeException to indicate the
 * error,. The module will not be available to the system.
 *
 * @param subSystem
 *          the subSystem.
 * @throws ModuleInitializeException
 *           if an error ocurred while initializing the module.
 */
public void initialize( final SubSystem subSystem ) throws ModuleInitializeException {
  if ( subSystem.getExtendedConfig().getBoolProperty(
      "org.pentaho.reporting.engine.classic.core.modules.gui.base.SwingDialogTranslation" ) ) { //$NON-NLS-1$
    final ResourceBundle resources = ResourceBundle.getBundle( SwingCommonModule.BUNDLE_NAME );
    final UIDefaults defaults = UIManager.getDefaults();
    final Enumeration en = resources.getKeys();
    while ( en.hasMoreElements() ) {
      try {
        final String keyName = (String) en.nextElement();
        defaults.put( keyName, resources.getObject( keyName ) );
      } catch ( Exception e ) {
        // Ignored; if it happens, we would not care that much ..
      }
    }
  }
}
 
Example 22
Source Project: jdk8u-jdk   Source File: Test8039750.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    UIDefaults table= new MetalLookAndFeel().getDefaults();
    test(table.get("ToolBar.rolloverBorder"),
            "javax.swing.plaf.metal.MetalBorders$ButtonBorder",
            "javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
    test(table.get("ToolBar.nonrolloverBorder"),
            "javax.swing.plaf.metal.MetalBorders$ButtonBorder",
            "javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
    test(table.get("RootPane.frameBorder"),
            "javax.swing.plaf.metal.MetalBorders$FrameBorder");
    test(table.get("RootPane.plainDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$DialogBorder");
    test(table.get("RootPane.informationDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$DialogBorder");
    test(table.get("RootPane.errorDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder");
    test(table.get("RootPane.colorChooserDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
    test(table.get("RootPane.fileChooserDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
    test(table.get("RootPane.questionDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
    test(table.get("RootPane.warningDialogBorder"),
            "javax.swing.plaf.metal.MetalBorders$WarningDialogBorder");
}
 
Example 23
Source Project: jdk1.8-source-analysis   Source File: NimbusDefaults.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public Object createValue(UIDefaults defaults) {
    Font f = defaults.getFont(parentKey);
    if (f != null) {
        // always round size for now so we have exact int font size
        // (or we may have lame looking fonts)
        float size = Math.round(f.getSize2D() * sizeOffset);
        int style = f.getStyle();
        if (bold != null) {
            if (bold.booleanValue()) {
                style = style | Font.BOLD;
            } else {
                style = style & ~Font.BOLD;
            }
        }
        if (italic != null) {
            if (italic.booleanValue()) {
                style = style | Font.ITALIC;
            } else {
                style = style & ~Font.ITALIC;
            }
        }
        return f.deriveFont(style, size);
    } else {
        return null;
    }
}
 
Example 24
Source Project: jdk8u_jdk   Source File: NimbusStyle.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Painter getPainter(Map<String, Object> defaults, String key) {
    Object p = defaults.get(key);
    if (p instanceof UIDefaults.LazyValue) {
        p = ((UIDefaults.LazyValue)p).createValue(UIManager.getDefaults());
    }
    return (p instanceof Painter ? (Painter)p : null);
}
 
Example 25
Source Project: freecol   Source File: FreeColLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the default font in all UI elements.
 *
 * @param defaultFont A {@code Font} to use by default.
 */
public static void installFont(Font defaultFont) {
    UIDefaults u = UIManager.getDefaults();
    java.util.Enumeration<Object> keys = u.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (u.get(key) instanceof javax.swing.plaf.FontUIResource) {
            u.put(key, defaultFont);
        }
    }
}
 
Example 26
Source Project: littleluck   Source File: LuckMenuUIBundle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void installOther(UIDefaults table)
{
    // 注: 下列三个属性决定JMenu在弹出菜单中的布局
    table.put(AFTERCHECKICONGAP, 4);

    table.put(MINIMUMTEXTOFFSET, 0);

    table.put(CHECKICONOFFSET, 4);
}
 
Example 27
Source Project: littleluck   Source File: LuckMenuUIBundle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void loadImages(UIDefaults table)
{
    table.put(ARROW_NORMAL_IMG, LuckRes.getImage("menu/arrow_normal.png"));

    table.put(ARROW_ROLLVER_IMG, LuckRes.getImage("menu/arrow_rollver.png"));

    table.put(ARROW_ICON, getIconRes(new LuckArrowIcon()));

    table.put(CHECK_ICON, getIconRes(new LuckIcon(16, 0)));
}
 
Example 28
Source Project: littleluck   Source File: LuckMenuUIBundle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void installBorder(UIDefaults table)
{
    table.put(MENUBAR_BORDER, getBorderRes(BorderFactory.createEmptyBorder(3, 0, 3, 0)));

    table.put(MENU_BORDER, getBorderRes(BorderFactory.createEmptyBorder()));
}
 
Example 29
Source Project: FlatLaf   Source File: FlatInputMaps.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object createValue( UIDefaults table ) {
	InputMap inputMap = new InputMapUIResource();
	for( Object[] bindings : bindingsArray )
		LookAndFeel.loadKeyBindings( inputMap, bindings );
	return inputMap;
}
 
Example 30
Source Project: openjdk-jdk8u   Source File: SynthParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void endInputMap() throws SAXException {
    if (_inputMapID != null) {
        register(_inputMapID, new UIDefaults.LazyInputMap(
                 _inputMapBindings.toArray(new Object[_inputMapBindings.
                 size()])));
    }
    _inputMapBindings.clear();
    _inputMapID = null;
}