类javax.swing.plaf.UIResource源码实例Demo

下面列出了怎么用javax.swing.plaf.UIResource的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: XTextAreaPeer.java
@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");

}
 
源代码2 项目: FlatLaf   文件: FlatLaf.java
@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;
}
 
源代码3 项目: darklaf   文件: DarkListUIBridge.java
/**
 * 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);
    }
}
 
源代码4 项目: darklaf   文件: DarkSpinnerUI.java
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;
}
 
源代码5 项目: darklaf   文件: DarkButtonUI.java
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);
        }
    }
}
 
源代码6 项目: TencentKona-8   文件: AquaTabbedPaneContrastUI.java
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());
}
 
源代码7 项目: darklaf   文件: FontDefaultsInitTask.java
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;
}
 
源代码8 项目: TencentKona-8   文件: AquaFocusHandler.java
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;
    }
}
 
源代码9 项目: jdk1.8-source-analysis   文件: NimbusIcon.java
@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);
    }
}
 
源代码10 项目: jdk1.8-source-analysis   文件: NimbusIcon.java
@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);
    }
}
 
源代码11 项目: jdk1.8-source-analysis   文件: NimbusDefaults.java
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;
    }
}
 
源代码12 项目: dragonwell8_jdk   文件: AquaUtils.java
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();
    }
}
 
源代码13 项目: FlatLaf   文件: FlatRootPaneUI.java
@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 );
	}
}
 
源代码14 项目: FlatLaf   文件: FlatButtonUI.java
@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 ) );
}
 
源代码15 项目: dragonwell8_jdk   文件: SynthStyle.java
/**
 * 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);
        }
    }
}
 
源代码16 项目: dragonwell8_jdk   文件: AquaTabbedPaneContrastUI.java
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());
}
 
源代码17 项目: TencentKona-8   文件: NimbusIcon.java
@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);
    }
}
 
源代码18 项目: dragonwell8_jdk   文件: AquaFocusHandler.java
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;
    }
}
 
源代码19 项目: dragonwell8_jdk   文件: SynthTreeUI.java
/**
 * {@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);
    }
}
 
源代码20 项目: TencentKona-8   文件: AquaFocusHandler.java
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;
    }
}
 
源代码21 项目: TencentKona-8   文件: AquaUtils.java
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();
    }
}
 
源代码22 项目: FlatLaf   文件: FlatButtonBorder.java
@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;
}
 
源代码23 项目: darklaf   文件: PropertyUtil.java
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);
    }
}
 
源代码24 项目: darklaf   文件: DarkToggleButtonUI.java
@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);
}
 
源代码25 项目: TencentKona-8   文件: SwingUtilities.java
/**
 * 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;
    }
}
 
源代码26 项目: darklaf   文件: DarkTabbedPaneUI.java
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;
    }
}
 
源代码27 项目: TencentKona-8   文件: SynthTreeUI.java
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));
        }
    }
}
 
源代码28 项目: darklaf   文件: DarkListUIBridge.java
/**
 * 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);
            }
        }
    }
}
 
源代码29 项目: darklaf   文件: DarkListUIBridge.java
/**
 * 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();
}
 
源代码30 项目: darklaf   文件: DarkTableUI.java
@Override
public void focusGained(final FocusEvent e) {
    Color bg = table.getSelectionBackground();
    if (bg instanceof UIResource) {
        table.setSelectionBackground(selectionBackground);
    }
    table.repaint();
}
 
 类所在包
 同包方法