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

项目:MFM    文件:StatusBar.java   
/**
 * Adds a new zone in the StatusBar
 *
 * @param id
 * @param zone
 * @param constraints one of the constraint support by the
 *                    {@link com.l2fprod.common.swing.PercentLayout}
 */
public void addZone(String id, Component zone, String constraints) {
    // is there already a zone with this id?
    Component previousZone = getZone(id);
    if (previousZone != null) {
        remove(previousZone);
        idToZones.remove(id);
    }

    if (zone instanceof JComponent) {
        JComponent jc = (JComponent) zone;
        if (jc.getBorder() == null || jc.getBorder() instanceof UIResource) {
            if (jc instanceof JLabel) {
                jc.setBorder(
                        new CompoundBorder(zoneBorder, new EmptyBorder(0, 2, 0, 2)));
                //    ((JLabel) jc).setText(" ");
            } else {
                jc.setBorder(zoneBorder);
            }
        }
    }

    add(zone, constraints);
    idToZones.put(id, zone);
}
项目:OpenJSharp    文件: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;
    }
}
项目:openjdk-jdk10    文件: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;
    }
}
项目:OpenJSharp    文件: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);
    }
}
项目:OpenJSharp    文件: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);
    }
}
项目:openjdk-jdk10    文件: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();
    }
}
项目:OpenJSharp    文件:BasicTextUI.java   
/**
 * Deinstalls the UI for a component.  This removes the listeners,
 * uninstalls the highlighter, removes views, and nulls out the keymap.
 *
 * @param c the editor component
 * @see ComponentUI#uninstallUI
 */
public void uninstallUI(JComponent c) {
    // detach from the model
    editor.removePropertyChangeListener(updateHandler);
    editor.getDocument().removeDocumentListener(updateHandler);

    // view part
    painted = false;
    uninstallDefaults();
    rootView.setView(null);
    c.removeAll();
    LayoutManager lm = c.getLayout();
    if (lm instanceof UIResource) {
        c.setLayout(null);
    }

    // controller part
    uninstallKeyboardActions();
    uninstallListeners();

    editor = null;
}
项目:OpenJSharp    文件:SynthStyle.java   
/**
 * Installs the necessary state from this Style on the
 * <code>JComponent</code> from <code>context</code>.
 *
 * @param context SynthContext identifying component to install properties
 *        to.
 */
public void installDefaults(SynthContext context) {
    if (!context.isSubregion()) {
        JComponent c = context.getComponent();
        Region region = context.getRegion();
        Font font = c.getFont();

        if (font == null || (font instanceof UIResource)) {
            c.setFont(getFontForState(context));
        }
        Color background = c.getBackground();
        if (background == null || (background instanceof UIResource)) {
            c.setBackground(getColorForState(context,
                                             ColorType.BACKGROUND));
        }
        Color foreground = c.getForeground();
        if (foreground == null || (foreground instanceof UIResource)) {
            c.setForeground(getColorForState(context,
                     ColorType.FOREGROUND));
        }
        LookAndFeel.installProperty(c, "opaque", Boolean.valueOf(isOpaque(context)));
    }
}
项目:OpenJSharp    文件: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;
    }
}
项目:OpenJSharp    文件: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;
    }
}
项目:OpenJSharp    文件: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());
}
项目:OpenJSharp    文件: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();
    }
}
项目:openjdk-jdk10    文件: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);
    }
}
项目:openjdk-jdk10    文件:BasicTextUI.java   
/**
 * Deinstalls the UI for a component.  This removes the listeners,
 * uninstalls the highlighter, removes views, and nulls out the keymap.
 *
 * @param c the editor component
 * @see ComponentUI#uninstallUI
 */
public void uninstallUI(JComponent c) {
    // detach from the model
    editor.removePropertyChangeListener(updateHandler);
    editor.getDocument().removeDocumentListener(updateHandler);

    // view part
    painted = false;
    uninstallDefaults();
    rootView.setView(null);
    c.removeAll();
    LayoutManager lm = c.getLayout();
    if (lm instanceof UIResource) {
        c.setLayout(null);
    }

    // controller part
    uninstallKeyboardActions();
    uninstallListeners();

    editor = null;
}
项目:jdk8u-jdk    文件: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);
    }
}
项目:jdk8u-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);
    }
}
项目:openjdk-jdk10    文件:SynthTreeUI.java   
/**
 * {@inheritDoc}
 */
@Override
protected void uninstallDefaults() {
    SynthContext context = getContext(tree, ENABLED);

    style.uninstallDefaults(context);
    style = null;

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


    if (tree.getTransferHandler() instanceof UIResource) {
        tree.setTransferHandler(null);
    }
}
项目:openjdk-jdk10    文件: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());
}
项目:jdk8u-jdk    文件:SynthStyle.java   
/**
 * Installs the necessary state from this Style on the
 * <code>JComponent</code> from <code>context</code>.
 *
 * @param context SynthContext identifying component to install properties
 *        to.
 */
public void installDefaults(SynthContext context) {
    if (!context.isSubregion()) {
        JComponent c = context.getComponent();
        Region region = context.getRegion();
        Font font = c.getFont();

        if (font == null || (font instanceof UIResource)) {
            c.setFont(getFontForState(context));
        }
        Color background = c.getBackground();
        if (background == null || (background instanceof UIResource)) {
            c.setBackground(getColorForState(context,
                                             ColorType.BACKGROUND));
        }
        Color foreground = c.getForeground();
        if (foreground == null || (foreground instanceof UIResource)) {
            c.setForeground(getColorForState(context,
                     ColorType.FOREGROUND));
        }
        LookAndFeel.installProperty(c, "opaque", Boolean.valueOf(isOpaque(context)));
    }
}
项目:jdk8u-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);
        }
    }
}
项目:openjdk-jdk10    文件: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;
    }
}
项目:openjdk-jdk10    文件: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");

}
项目:openjdk-jdk10    文件: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);
        }
    }
}
项目:jdk8u-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();
    }
}
项目:incubator-netbeans    文件:ViewUtil.java   
/**
 * Change background of given component to light gray on Mac look and feel
 * when the component is in a tabbed container and its background hasn't been
 * already changed (is instance of UIResource).
 * @param c
 */
static void adjustBackground( JComponent c ) {
    if( !isAquaLaF || useDefaultBackground )
        return;

    if( !isInTabbedContainer(c) )
        return;

    Color currentBackground = c.getBackground();
    if( currentBackground instanceof UIResource ) {
        c.setBackground(UIManager.getColor("NbExplorerView.background"));
    }
}
项目:incubator-netbeans    文件:ShortcutCellPanel.java   
@Override
protected void paintComponent(Graphics g) {
    Color c = getBackground();
    if (c instanceof UIResource) {
        // Nimbus LaF: if the color is a UIResource, it will paint
        // the leftover area with default JPanel color which is gray, which looks ugly
        super.setBackground(new Color(c.getRGB()));
    }
    super.paintComponent(g);
    super.setBackground(c);
}
项目:incubator-netbeans    文件:CloseButtonTabbedPane.java   
private Component findTabAt(int index) {
    int componentIndex = -1;
    for( Component c : getComponents() ) {
        if( c instanceof UIResource )
            continue;
        if( ++componentIndex == index )
            return c;
    }
    return null;
}
项目:incubator-netbeans    文件:FlatToolBar.java   
protected void setBorderToRollover(Component c) {
    if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) c;

        if (b.getBorder() instanceof UIResource) {
            b.setBorder(myRolloverBorder);
        }

        b.setRolloverEnabled(true);
    }
}
项目:openjdk-jdk10    文件:BasicTextUI.java   
/**
 * As needed updates cursor for the target editor.
 */
private void updateCursor() {
    if ((! editor.isCursorSet())
           || editor.getCursor() instanceof UIResource) {
        Cursor cursor = (editor.isEditable()) ? textCursor : null;
        editor.setCursor(cursor);
    }
}
项目:Moenagade    文件:LayoutStyle.java   
private int getCBRBPadding(JComponent c, int position) {
    if (c.getUIClassID() == "CheckBoxUI" ||
          c.getUIClassID() == "RadioButtonUI") {
        Border border = c.getBorder();
        if (border instanceof UIResource) {
            return getInset(c, position);
        }
    }
    return 0;
}
项目:QN-ACTR-Release    文件:ExactTable.java   
/**
 * duplicated to avoid repeating the same checks multiple times
 */
@Override
protected void configureEnclosingScrollPane() {
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setColumnHeaderView(getTableHeader());
            Border border = scrollPane.getBorder();
            if (border == null || border instanceof UIResource) {
                scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
            }
            //rowHeader=new RowHeader(dataModel);
            rowHeader.install(this, scrollPane);
            installLabels(scrollPane);
            installSelectAllButton(scrollPane);
            viewport.addChangeListener(scrollListener);
        }
    }
}
项目:OpenJSharp    文件:DefaultLayoutStyle.java   
/**
 * If <code>c</code> is a check box or radio button, and the border is
 * not painted this returns the inset along the specified axis.
 */
public int getButtonGap(JComponent c, int position) {
    String classID = c.getUIClassID();
    if ((classID == "CheckBoxUI" || classID == "RadioButtonUI") &&
            !((AbstractButton)c).isBorderPainted()) {
        Border border = c.getBorder();
        if (border instanceof UIResource) {
            return getInset(c, position);
        }
    }
    return 0;
}
项目:OpenJSharp    文件:SwingUtilities.java   
/**
 * Installs a {@code DropTarget} on the component as necessary for a
 * {@code TransferHandler} change.
 */
static void installSwingDropTargetAsNecessary(Component c,
                                                     TransferHandler t) {

    if (!getSuppressDropTarget()) {
        DropTarget dropHandler = c.getDropTarget();
        if ((dropHandler == null) || (dropHandler instanceof UIResource)) {
            if (t == null) {
                c.setDropTarget(null);
            } else if (!GraphicsEnvironment.isHeadless()) {
                c.setDropTarget(new TransferHandler.SwingDropTarget(c));
            }
        }
    }
}
项目:OpenJSharp    文件: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;
    }
}
项目:OpenJSharp    文件:SwingUtilities.java   
/**
 * Returns the InputMap provided by the UI for condition
 * <code>condition</code> in component <code>component</code>.
 * <p>This will return {@code null} if the UI has not installed a InputMap
 * of the specified type.
 *
 * @since 1.3
 */
public static InputMap getUIInputMap(JComponent component, int condition) {
    InputMap map = component.getInputMap(condition, false);
    while (map != null) {
        InputMap parent = map.getParent();
        if (parent instanceof UIResource) {
            return parent;
        }
        map = parent;
    }
    return null;
}
项目:OpenJSharp    文件:SwingUtilities.java   
/**
 * Returns the ActionMap provided by the UI
 * in component <code>component</code>.
 * <p>This will return {@code null} if the UI has not installed an ActionMap.
 *
 * @since 1.3
 */
public static ActionMap getUIActionMap(JComponent component) {
    ActionMap map = component.getActionMap(false);
    while (map != null) {
        ActionMap parent = map.getParent();
        if (parent instanceof UIResource) {
            return parent;
        }
        map = parent;
    }
    return null;
}
项目:OpenJSharp    文件:JFormattedTextField.java   
/**
 * Resets the Actions that come from the TextFormatter to
 * <code>actions</code>.
 */
private void setFormatterActions(Action[] actions) {
    if (actions == null) {
        if (textFormatterActionMap != null) {
            textFormatterActionMap.clear();
        }
    }
    else {
        if (textFormatterActionMap == null) {
            ActionMap map = getActionMap();

            textFormatterActionMap = new ActionMap();
            while (map != null) {
                ActionMap parent = map.getParent();

                if (parent instanceof UIResource || parent == null) {
                    map.setParent(textFormatterActionMap);
                    textFormatterActionMap.setParent(parent);
                    break;
                }
                map = parent;
            }
        }
        for (int counter = actions.length - 1; counter >= 0;
             counter--) {
            Object key = actions[counter].getValue(Action.NAME);

            if (key != null) {
                textFormatterActionMap.put(key, actions[counter]);
            }
        }
    }
}
项目:OpenJSharp    文件:MetalMenuBarUI.java   
/**
 * If necessary paints the background of the component, then
 * invokes <code>paint</code>.
 *
 * @param g Graphics to paint to
 * @param c JComponent painting on
 * @throws NullPointerException if <code>g</code> or <code>c</code> is
 *         null
 * @see javax.swing.plaf.ComponentUI#update
 * @see javax.swing.plaf.ComponentUI#paint
 * @since 1.5
 */
public void update(Graphics g, JComponent c) {
    boolean isOpaque = c.isOpaque();
    if (g == null) {
        throw new NullPointerException("Graphics must be non-null");
    }
    if (isOpaque && (c.getBackground() instanceof UIResource) &&
                    UIManager.get("MenuBar.gradient") != null) {
        if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
            JToolBar tb = (JToolBar)MetalToolBarUI.
                 findRegisteredComponentOfType(c, JToolBar.class);
            if (tb.isOpaque() &&tb.getBackground() instanceof UIResource) {
                MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
                                        c.getWidth(), c.getHeight() +
                                        tb.getHeight(), true);
                paint(g, c);
                return;
            }
        }
        MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
                                c.getWidth(), c.getHeight(),true);
        paint(g, c);
    }
    else {
        super.update(g, c);
    }
}
项目:openjdk-jdk10    文件:MetalMenuBarUI.java   
/**
 * If necessary paints the background of the component, then
 * invokes <code>paint</code>.
 *
 * @param g Graphics to paint to
 * @param c JComponent painting on
 * @throws NullPointerException if <code>g</code> or <code>c</code> is
 *         null
 * @see javax.swing.plaf.ComponentUI#update
 * @see javax.swing.plaf.ComponentUI#paint
 * @since 1.5
 */
public void update(Graphics g, JComponent c) {
    boolean isOpaque = c.isOpaque();
    if (g == null) {
        throw new NullPointerException("Graphics must be non-null");
    }
    if (isOpaque && (c.getBackground() instanceof UIResource) &&
                    UIManager.get("MenuBar.gradient") != null) {
        if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
            JToolBar tb = (JToolBar)MetalToolBarUI.
                 findRegisteredComponentOfType(c, JToolBar.class);
            if (tb.isOpaque() &&tb.getBackground() instanceof UIResource) {
                MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
                                        c.getWidth(), c.getHeight() +
                                        tb.getHeight(), true);
                paint(g, c);
                return;
            }
        }
        MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
                                c.getWidth(), c.getHeight(),true);
        paint(g, c);
    }
    else {
        super.update(g, c);
    }
}
项目:OpenJSharp    文件:BasicTextUI.java   
/**
 * As needed updates cursor for the target editor.
 */
private void updateCursor() {
    if ((! editor.isCursorSet())
           || editor.getCursor() instanceof UIResource) {
        Cursor cursor = (editor.isEditable()) ? textCursor : null;
        editor.setCursor(cursor);
    }
}