Java Code Examples for javax.swing.plaf.UIResource

The following examples show how to use javax.swing.plaf.UIResource. 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
@Override
protected void configureScrollBarColors() {
    UIDefaults uidefaults = XToolkit.getUIDefaults();
    Color bg = scrollbar.getBackground();
    if (bg == null || bg instanceof UIResource) {
        scrollbar.setBackground(uidefaults.getColor("ScrollBar.background"));
    }

    Color fg = scrollbar.getForeground();
    if (fg == null || fg instanceof UIResource) {
        scrollbar.setForeground(uidefaults.getColor("ScrollBar.foreground"));
    }

    thumbHighlightColor = uidefaults.getColor("ScrollBar.thumbHighlight");
    thumbLightShadowColor = uidefaults.getColor("ScrollBar.thumbShadow");
    thumbDarkShadowColor = uidefaults.getColor("ScrollBar.thumbDarkShadow");
    thumbColor = uidefaults.getColor("ScrollBar.thumb");
    trackColor = uidefaults.getColor("ScrollBar.track");

    trackHighlightColor = uidefaults.getColor("ScrollBar.trackHighlight");

}
 
Example 2
Source Project: FlatLaf   Source File: FlatLaf.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object createValue( UIDefaults table ) {
	Font defaultFont = UIManager.getFont( "defaultFont" );

	if( lastDefaultFont != defaultFont ) {
		lastDefaultFont = defaultFont;

		if( scaleFactor != 1 ) {
			// scale font
			int newFontSize = Math.round( defaultFont.getSize() * scaleFactor );
			font = new FontUIResource( defaultFont.deriveFont( (float) newFontSize ) );
		} else {
			// make sure that font is a UIResource for LaF switching
			font = (defaultFont instanceof UIResource)
				? defaultFont
				: new FontUIResource( defaultFont );
		}
	}

	return font;
}
 
Example 3
Source Project: darklaf   Source File: DarkListUIBridge.java    License: MIT License 6 votes vote down vote up
/**
 * Sets the list properties that have not been explicitly overridden to {@code null}. A property is considered
 * overridden if its current value is not a {@code UIResource}.
 *
 * @see #installDefaults
 * @see #uninstallUI
 * @see CellRendererPane
 */
protected void uninstallDefaults() {
    LookAndFeel.uninstallBorder(list);
    if (list.getFont() instanceof UIResource) {
        list.setFont(null);
    }
    if (list.getForeground() instanceof UIResource) {
        list.setForeground(null);
    }
    if (list.getBackground() instanceof UIResource) {
        list.setBackground(null);
    }
    if (list.getSelectionBackground() instanceof UIResource) {
        list.setSelectionBackground(null);
    }
    if (list.getSelectionForeground() instanceof UIResource) {
        list.setSelectionForeground(null);
    }
    if (list.getCellRenderer() instanceof UIResource) {
        list.setCellRenderer(null);
    }
    if (list.getTransferHandler() instanceof UIResource) {
        list.setTransferHandler(null);
    }
}
 
Example 4
Source Project: darklaf   Source File: DarkSpinnerUI.java    License: MIT License 6 votes vote down vote up
private JButton createArrow(final int direction) {
    int buttonPad = UIManager.getInt("Spinner.buttonPad");
    Insets insets = new Insets(0, buttonPad, 0, buttonPad);
    JButton button = ArrowButton.createUpDownArrow(spinner,
                                                   getArrowIcon(direction),
                                                   getArrowInactiveIcon(direction), direction,
                                                   false, true, insets);
    Border buttonBorder = UIManager.getBorder("Spinner.arrowButtonBorder");
    if (buttonBorder instanceof UIResource) {
        // Wrap the border to avoid having the UIResource be replaced by
        // the ButtonUI. This is the opposite of using BorderUIResource.
        button.setBorder(new CompoundBorder(buttonBorder, null));
    } else {
        button.setBorder(buttonBorder);
    }
    button.setInheritsPopupMenu(true);
    return button;
}
 
Example 5
Source Project: darklaf   Source File: DarkButtonUI.java    License: MIT License 6 votes vote down vote up
protected void paintButtonBackground(final Graphics g, final JComponent c) {
    Graphics2D g2 = (Graphics2D) g;
    AbstractButton b = (AbstractButton) c;
    if (shouldDrawBackground(b)) {
        int arc = getArc(c);
        int width = c.getWidth();
        int height = c.getHeight();
        Insets margin = b.getMargin();
        if (margin instanceof UIResource) margin = new Insets(0, 0, 0, 0);
        if (ButtonConstants.isBorderlessVariant(c)) {
            paintBorderlessBackground(b, g2, arc, width, height, margin);
        } else {
            paintDefaultBackground(b, g2, arc, width, height);
        }
    }
}
 
Example 6
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example 7
Source Project: darklaf   Source File: FontDefaultsInitTask.java    License: MIT License 6 votes vote down vote up
private Font fontWithRule(final Font font, final FontSizeRule rule) {
    if (font == null) return null;
    float size = font.getSize2D();
    float newSize = rule.adjustFontSize(size);
    if (newSize == size) return font;
    if (newSize <= 0) {
        LOGGER.warning("Font " + font + " would be invisible after applying " + rule + ". Font won't be changed!");
        return font;
    }
    Font withRule = font.deriveFont(newSize);
    if (font instanceof UIResource
        && !(withRule instanceof UIResource)) {
        withRule = new DarkFontUIResource(withRule);
    }
    return withRule;
}
 
Example 8
static void swapSelectionColors(final String prefix, final JList c, final Object value) {
    if (!isComponentValid(c)) return;

    final Color bg = c.getSelectionBackground();
    final Color fg = c.getSelectionForeground();
    if (!(bg instanceof UIResource) || !(fg instanceof UIResource)) return;

    if (Boolean.FALSE.equals(value)) {
        setSelectionColors(c, "List.selectionInactiveForeground", "List.selectionInactiveBackground");
        return;
    }

    if (Boolean.TRUE.equals(value)) {
        setSelectionColors(c, "List.selectionForeground", "List.selectionBackground");
        return;
    }
}
 
Example 9
Source Project: jdk1.8-source-analysis   Source File: NimbusIcon.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int getIconWidth(SynthContext context) {
    if (context == null) {
        return width;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar && ((JToolBar)c).getOrientation() == JToolBar.VERTICAL) {
        //we only do the -1 hack for UIResource borders, assuming
        //that the border is probably going to be our border
        if (c.getBorder() instanceof UIResource) {
            return c.getWidth() - 1;
        } else {
            return c.getWidth();
        }
    } else {
        return scale(context, width);
    }
}
 
Example 10
Source Project: jdk1.8-source-analysis   Source File: NimbusIcon.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar){
        JToolBar toolbar = (JToolBar)c;
        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
            //we only do the -1 hack for UIResource borders, assuming
            //that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
Example 11
Source Project: jdk1.8-source-analysis   Source File: NimbusDefaults.java    License: Apache License 2.0 6 votes vote down vote up
private DerivedColor getDerivedColor(String uin, String parentUin,
                                    float hOffset, float sOffset,
                                    float bOffset, int aOffset,
                                    boolean uiResource) {
    DerivedColor color;
    if (uiResource) {
        color = new DerivedColor.UIResource(parentUin,
                hOffset, sOffset, bOffset, aOffset);
    } else {
        color = new DerivedColor(parentUin, hOffset, sOffset,
            bOffset, aOffset);
    }

    if (derivedColors.containsKey(color)) {
        return derivedColors.get(color);
    } else {
        derivedColors.put(color, color);
        color.rederiveColor(); /// move to ARP.decodeColor() ?
        colorTree.addColor(uin, color);
        return color;
    }
}
 
Example 12
Source Project: dragonwell8_jdk   Source File: AquaUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void fillRect(final Graphics g, final Component c, final Color color,
                     final int x, final int y, final int w, final int h) {
    if (!(g instanceof Graphics2D)) {
        return;
    }
    final Graphics2D cg = (Graphics2D) g.create();
    try {
        if (color instanceof UIResource && isWindowTextured(c)
                && color.equals(SystemColor.window)) {
            cg.setComposite(AlphaComposite.Src);
            cg.setColor(resetAlpha(color));
        } else {
            cg.setColor(color);
        }
        cg.fillRect(x, y, w, h);
    } finally {
        cg.dispose();
    }
}
 
Example 13
Source Project: FlatLaf   Source File: FlatRootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void installDefaults( JRootPane c ) {
	super.installDefaults( c );

	// Update background color of JFrame or JDialog parent to avoid bad border
	// on HiDPI screens when switching from light to dark Laf.
	// The background of JFrame is initialized in JFrame.frameInit() and
	// the background of JDialog in JDialog.dialogInit(),
	// but it was not updated when switching Laf.
	Container parent = c.getParent();
	if( parent instanceof JFrame || parent instanceof JDialog ) {
		Color background = parent.getBackground();
		if( background == null || background instanceof UIResource )
			parent.setBackground( UIManager.getColor( "control" ) );
	}

	// enable dark window appearance on macOS when running in JetBrains Runtime
	if( SystemInfo.IS_JETBRAINS_JVM && SystemInfo.IS_MAC_OS_10_14_MOJAVE ) {
		LookAndFeel laf = UIManager.getLookAndFeel();
		boolean isDark = laf instanceof FlatLaf && ((FlatLaf)laf).isDark();
		c.putClientProperty( "jetbrains.awt.windowDarkAppearance", isDark );
	}
}
 
Example 14
Source Project: FlatLaf   Source File: FlatButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text ) {
	if( isHelpButton( b ) )
		return;

	if( defaultBoldText && isDefaultButton( b ) && b.getFont() instanceof UIResource ) {
		Font boldFont = g.getFont().deriveFont( Font.BOLD );
		g.setFont( boldFont );

		int boldWidth = b.getFontMetrics( boldFont ).stringWidth( text );
		if( boldWidth > textRect.width ) {
			textRect.x -= (boldWidth - textRect.width) / 2;
			textRect.width = boldWidth;
		}
	}

	paintText( g, b, textRect, text, getForeground( b ) );
}
 
Example 15
Source Project: dragonwell8_jdk   Source File: SynthStyle.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Uninstalls any state that this style installed on
 * the <code>JComponent</code> from <code>context</code>.
 * <p>
 * Styles should NOT depend upon this being called, in certain cases
 * it may never be called.
 *
 * @param context SynthContext identifying component to install properties
 *        to.
 */
public void uninstallDefaults(SynthContext context) {
    if (!context.isSubregion()) {
        // NOTE: because getForeground, getBackground and getFont will look
        // at the parent Container, if we set them to null it may
        // mean we they return a non-null and non-UIResource value
        // preventing install from correctly settings its colors/font. For
        // this reason we do not uninstall the fg/bg/font.

        JComponent c = context.getComponent();
        Border border = c.getBorder();

        if (border instanceof UIResource) {
            c.setBorder(null);
        }
    }
}
 
Example 16
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example 17
Source Project: TencentKona-8   Source File: NimbusIcon.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getIconWidth(SynthContext context) {
    if (context == null) {
        return width;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar && ((JToolBar)c).getOrientation() == JToolBar.VERTICAL) {
        //we only do the -1 hack for UIResource borders, assuming
        //that the border is probably going to be our border
        if (c.getBorder() instanceof UIResource) {
            return c.getWidth() - 1;
        } else {
            return c.getWidth();
        }
    } else {
        return scale(context, width);
    }
}
 
Example 18
static void swapSelectionColors(final String prefix, final JList c, final Object value) {
    if (!isComponentValid(c)) return;

    final Color bg = c.getSelectionBackground();
    final Color fg = c.getSelectionForeground();
    if (!(bg instanceof UIResource) || !(fg instanceof UIResource)) return;

    if (Boolean.FALSE.equals(value)) {
        setSelectionColors(c, "List.selectionInactiveForeground", "List.selectionInactiveBackground");
        return;
    }

    if (Boolean.TRUE.equals(value)) {
        setSelectionColors(c, "List.selectionForeground", "List.selectionBackground");
        return;
    }
}
 
Example 19
Source Project: dragonwell8_jdk   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void uninstallDefaults() {
    SynthContext context = getContext(tree, ENABLED);

    style.uninstallDefaults(context);
    context.dispose();
    style = null;

    context = getContext(tree, Region.TREE_CELL, ENABLED);
    cellStyle.uninstallDefaults(context);
    context.dispose();
    cellStyle = null;


    if (tree.getTransferHandler() instanceof UIResource) {
        tree.setTransferHandler(null);
    }
}
 
Example 20
static void swapSelectionColors(final String prefix, final JTable c, final Object value) {
    if (!isComponentValid(c)) return;

    final Color bg = c.getSelectionBackground();
    final Color fg = c.getSelectionForeground();
    if (!(bg instanceof UIResource) || !(fg instanceof UIResource)) return;

    if (Boolean.FALSE.equals(value)) {
        setSelectionColors(c, "Table.selectionInactiveForeground", "Table.selectionInactiveBackground");
        return;
    }

    if (Boolean.TRUE.equals(value)) {
        setSelectionColors(c, "Table.selectionForeground", "Table.selectionBackground");
        return;
    }
}
 
Example 21
Source Project: TencentKona-8   Source File: AquaUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void fillRect(final Graphics g, final Component c, final Color color,
                     final int x, final int y, final int w, final int h) {
    if (!(g instanceof Graphics2D)) {
        return;
    }
    final Graphics2D cg = (Graphics2D) g.create();
    try {
        if (color instanceof UIResource && isWindowTextured(c)
                && color.equals(SystemColor.window)) {
            cg.setComposite(AlphaComposite.Src);
            cg.setColor(resetAlpha(color));
        } else {
            cg.setColor(color);
        }
        cg.fillRect(x, y, w, h);
    } finally {
        cg.dispose();
    }
}
 
Example 22
Source Project: FlatLaf   Source File: FlatButtonBorder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
	if( FlatButtonUI.isToolBarButton( c ) ) {
		// In toolbars, use button margin only if explicitly set.
		// Otherwise use toolbar margin specified in UI defaults.
		Insets margin = (c instanceof AbstractButton)
			? ((AbstractButton)c).getMargin()
			: null;

		FlatUIUtils.setInsets( insets, UIScale.scale( FlatUIUtils.addInsets( toolbarSpacingInsets,
			(margin != null && !(margin instanceof UIResource)) ? margin : toolbarMargin ) ) );
	} else {
		insets = super.getBorderInsets( c, insets );

		// use smaller left and right insets for icon-only or single-character buttons (so that they are square)
		if( FlatButtonUI.isIconOnlyOrSingleCharacterButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource )
			insets.left = insets.right = Math.min( insets.top, insets.bottom );
	}

	return insets;
}
 
Example 23
Source Project: darklaf   Source File: PropertyUtil.java    License: MIT License 5 votes vote down vote up
public static void installForeground(final Component component, final Color color) {
    if (component == null || color == null) return;
    Color c = component.getForeground();
    if (c == null || c instanceof UIResource) {
        component.setForeground(color);
    }
}
 
Example 24
Source Project: darklaf   Source File: DarkToggleButtonUI.java    License: MIT License 5 votes vote down vote up
@Override
protected Color getForeground(final AbstractButton button) {
    if (button.isSelected()
        && !ToggleButtonConstants.isSlider(button)
        && !ButtonConstants.isBorderlessVariant(button)
        && button.getForeground() instanceof UIResource) {
        return selectedForeground;
    }
    return super.getForeground(button);
}
 
Example 25
Source Project: TencentKona-8   Source File: SwingUtilities.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convenience method to change the UI ActionMap for <code>component</code>
 * to <code>uiActionMap</code>. If <code>uiActionMap</code> is {@code null},
 * this removes any previously installed UI ActionMap.
 *
 * @since 1.3
 */
public static void replaceUIActionMap(JComponent component,
                                      ActionMap uiActionMap) {
    ActionMap map = component.getActionMap((uiActionMap != null));

    while (map != null) {
        ActionMap parent = map.getParent();
        if (parent == null || (parent instanceof UIResource)) {
            map.setParent(uiActionMap);
            return;
        }
        map = parent;
    }
}
 
Example 26
Source Project: darklaf   Source File: DarkTabbedPaneUI.java    License: MIT License 5 votes vote down vote up
protected Color getTabForeground(final int index, final boolean isSelected) {
    if (tabPane.isEnabled() && tabPane.isEnabledAt(index)) {
        Color fg = tabPane.getForegroundAt(index);
        if (isSelected && (fg instanceof UIResource)) {
            Color selectedFG = selectedForeground;
            if (selectedFG != null) {
                fg = selectedFG;
            }
        }
        return fg;
    } else {
        return disabledForeground;
    }
}
 
Example 27
Source Project: TencentKona-8   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 28
Source Project: darklaf   Source File: DarkListUIBridge.java    License: MIT License 5 votes vote down vote up
/**
 * Update is file list.
 */
protected void updateIsFileList() {
    boolean b = PropertyUtil.getBooleanProperty(list, "List.isFileList");
    if (b != isFileList) {
        isFileList = b;
        Font oldFont = list.getFont();
        if (oldFont == null || oldFont instanceof UIResource) {
            Font newFont = UIManager.getFont(b ? "FileChooser.listFont" : "List.font");
            if (newFont != null && newFont != oldFont) {
                list.setFont(newFont);
            }
        }
    }
}
 
Example 29
Source Project: darklaf   Source File: DarkListUIBridge.java    License: MIT License 5 votes vote down vote up
/**
 * Initializes list properties such as font, foreground, and background, and adds the CellRendererPane. The font,
 * foreground, and background properties are only set if their current value is either null or a UIResource, other
 * properties are set if the current value is null.
 *
 * @see #uninstallDefaults
 * @see #installUI
 * @see CellRendererPane
 */
protected void installDefaults() {
    list.setLayout(null);

    LookAndFeel.installBorder(list, "List.border");

    LookAndFeel.installColorsAndFont(list, "List.background", "List.foreground", "List.font");

    LookAndFeel.installProperty(list, PropertyKey.OPAQUE, Boolean.TRUE);

    if (list.getCellRenderer() == null) {
        @SuppressWarnings("unchecked")
        ListCellRenderer<Object> tmp = (ListCellRenderer<Object>) (UIManager.get("List.cellRenderer"));
        list.setCellRenderer(tmp);
    }

    Color sbg = list.getSelectionBackground();
    if (sbg == null || sbg instanceof UIResource) {
        list.setSelectionBackground(UIManager.getColor("List.selectionBackground"));
    }

    Color sfg = list.getSelectionForeground();
    if (sfg == null || sfg instanceof UIResource) {
        list.setSelectionForeground(UIManager.getColor("List.selectionForeground"));
    }

    Long l = (Long) UIManager.get("List.timeFactor");
    timeFactor = (l != null) ? l : 1000L;

    updateIsFileList();
}
 
Example 30
Source Project: darklaf   Source File: DarkTableUI.java    License: MIT License 5 votes vote down vote up
@Override
public void focusGained(final FocusEvent e) {
    Color bg = table.getSelectionBackground();
    if (bg instanceof UIResource) {
        table.setSelectionBackground(selectionBackground);
    }
    table.repaint();
}