Java 类javax.swing.plaf.synth.ColorType 实例源码

项目:OpenJSharp    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:jdk8u-jdk    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:openjdk-jdk10    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:openjdk9    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:Java8CN    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:jdk8u_jdk    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:lookaside_java-1.8.0-openjdk    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:swingx    文件:SynthUtils.java   
/**
 * A convenience method that handles painting of the background. All SynthUI
 * implementations should override update and invoke this method.
 * 
 * @param context must not be null
 * @param g must not be null
 * @param the bounds to fill, may be null to indicate the complete size
 */
public static void update(SynthContext context, Graphics g, Rectangle bounds) {
    JComponent c = context.getComponent();
    SynthStyle style = context.getStyle();
    int x, y, width, height;

    if (bounds == null) {
        x = 0;
        y = 0;
        width = c.getWidth();
        height = c.getHeight();
    } else {
        x = bounds.x;
        y = bounds.y;
        width = bounds.width;
        height = bounds.height;
    }

    // Fill in the background, if necessary.
    boolean subregion = context.getRegion().isSubregion();
    if ((subregion && style.isOpaque(context))
            || (!subregion && c.isOpaque())) {
        g.setColor(style.getColor(context, ColorType.BACKGROUND));
        g.fillRect(x, y, width, height);
    }
}
项目:seaglass    文件:SeaGlassToolTipUI.java   
/**
 * Paints the specified component.
 *
 * @param context
 *            context for the component being painted
 * @param g
 *            the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JToolTip tip = (JToolTip) context.getComponent();

    Insets insets = tip.getInsets();
    View v = (View) tip.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Rectangle paintTextR = new Rectangle(insets.left, insets.top, tip.getWidth() - (insets.left + insets.right), tip.getHeight()
                - (insets.top + insets.bottom));
        v.paint(g, paintTextR);
    } else {
        g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
        g.setFont(style.getFont(context));
        context.getStyle().getGraphicsUtils(context).paintText(context, g, tip.getTipText(), insets.left, insets.top, -1);
    }
}
项目:seaglass    文件:SeaGlassTabbedPaneUI.java   
/**
 * Paint the label text for a tab.
 *
 * @param ss           the SynthContext.
 * @param g            the Graphics context.
 * @param tabPlacement the side the tabs are on.
 * @param font         the font to use.
 * @param metrics      the font metrics.
 * @param tabIndex     the index of the tab to lay out.
 * @param title        the text for the label, if any.
 * @param textRect     Rectangle to place text in
 * @param isSelected   is the tab selected?
 */
protected void paintText(SeaGlassContext ss, Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title,
        Rectangle textRect, boolean isSelected) {
    g.setFont(font);

    View v = getTextViewForTab(tabIndex);

    if (v != null) {
        // html
        v.paint(g, textRect);
    } else {
        // plain text
        int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
        FontMetrics    fm = SwingUtilities2.getFontMetrics(tabPane, g);
        title = SwingUtilities2.clipStringIfNecessary(tabPane, fm, title, textRect.width);
        g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));
        ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title, textRect, mnemIndex);
    }
}
项目:seaglass    文件:SeaGlassGraphicsUtils.java   
static void paintText(Graphics g, SeaGlassMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (!lh.getText().equals("")) {
        if (lh.getHtmlView() != null) {
            // Text is HTML
            lh.getHtmlView().paint(g, lr.getTextRect());
        } else {
            // Text isn't HTML
            g.setColor(lh.getStyle().getColor(
                    lh.getContext(), ColorType.TEXT_FOREGROUND));
            g.setFont(lh.getStyle().getFont(lh.getContext()));
            lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(),
                    lr.getTextRect().x, lr.getTextRect().y,
                    lh.getMenuItem().getDisplayedMnemonicIndex());
        }
    }
}
项目:infobip-open-jdk-8    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:jdk8u-dev-jdk    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:jdk7-jdk    文件:NimbusStyle.java   
/**
 * @inheritDoc
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:openjdk-source-code-learn    文件:NimbusStyle.java   
/**
 * @inheritDoc
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:OLD-OpenJDK8    文件:NimbusStyle.java   
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:openjdk-jdk7u-jdk    文件:NimbusStyle.java   
/**
 * @inheritDoc
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:openjdk-icedtea7    文件:NimbusStyle.java   
/**
 * @inheritDoc
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:consulo    文件:GTKPlusUIUtil.java   
@Nonnull
@Override
protected Boolean compute() {
  if (!UIUtil.isUnderGTKLookAndFeel()) {
    return false;
  }

  JTextArea dummyArea = new JTextArea();
  dummyArea.updateUI();

  SynthContext synthContext = getSynthContext(dummyArea.getUI(), dummyArea);

  Color colorBack = synthContext.getStyle().getColor(synthContext, ColorType.TEXT_BACKGROUND);
  Color colorFore = synthContext.getStyle().getColor(synthContext, ColorType.TEXT_FOREGROUND);

  double textAvg = colorFore.getRed() / 256. + colorFore.getGreen() / 256. + colorFore.getBlue() / 256.;
  double bgAvg = colorBack.getRed() / 256. + colorBack.getGreen() / 256. + colorBack.getBlue() / 256.;
  return textAvg > bgAvg;
}
项目:JRLib    文件:OpaqueNimbusStyle.java   
/**
 * @InheritDoc
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
项目:incubator-netbeans    文件:ThemeValue.java   
/** Creates a new instance of GTKColor */
public ThemeValue(Region region, ColorType colorType, Object fallback) {
    this.fallback = fallback;
    this.aRegion = region;
    this.aColorType = colorType;
    register(this);
}
项目:incubator-netbeans    文件:ThemeValue.java   
/** Creates a new instance of GTKColor */
public ThemeValue(Region region, ColorType colorType, Object fallback, boolean darken) {
    this.fallback = fallback;
    this.aRegion = region;
    this.aColorType = colorType;
    this.darken = darken;
    register(this);
}
项目:incubator-netbeans    文件:ThemeValue.java   
private static void checkFunctioning() {
    functioning = Boolean.FALSE;
    try {
        gtkColorType = UIUtils.classForName ("com.sun.java.swing.plaf.gtk.GTKColorType"); //NOI18N

        synthStyle_getColorForState = SynthStyle.class.getDeclaredMethod ("getColorForState",  //NOI18N
             SynthContext.class, ColorType.class );

        synthStyle_getColorForState.setAccessible(true);

        synthStyle_getFontForState = SynthStyle.class.getDeclaredMethod ("getFontForState", //NOI18N
            SynthContext.class );

        synthStyle_getFontForState.setAccessible(true);


        LIGHT = (ColorType) valueOfField (gtkColorType, "LIGHT"); //NOI18N
        DARK = (ColorType) valueOfField (gtkColorType, "DARK"); //NOI18N
        MID = (ColorType) valueOfField (gtkColorType, "MID"); //NOI18N
        BLACK = (ColorType) valueOfField (gtkColorType, "BLACK"); //NOI18N
        WHITE = (ColorType) valueOfField (gtkColorType, "WHITE"); //NOI18N

        functioning = Boolean.TRUE;
    } catch (Exception e) {
        System.err.println ("Cannot initialize GTK colors - using hardcoded defaults: " + e); //NOI18N
        if (log) {
            e.printStackTrace();
        }
        return;
    }
}
项目:seaglass    文件:SeaGlassLookAndFeel.java   
/**
 * Paint a region.
 *
 * @param state  the SynthContext describing the current component, region,
 *               and state.
 * @param g      the Graphics context used to paint the subregion.
 * @param bounds the bounds to paint in.
 */
private static void paintRegion(SynthContext state, Graphics g, Rectangle bounds) {
    JComponent c      = state.getComponent();
    SynthStyle style  = state.getStyle();
    int        x;
    int        y;
    int        width;
    int        height;

    if (bounds == null) {
        x      = 0;
        y      = 0;
        width  = c.getWidth();
        height = c.getHeight();
    } else {
        x      = bounds.x;
        y      = bounds.y;
        width  = bounds.width;
        height = bounds.height;
    }

    // Fill in the background, if necessary.
    boolean subregion = state.getRegion().isSubregion();

    if ((subregion && style.isOpaque(state)) || (!subregion && c.isOpaque())) {
        g.setColor(style.getColor(state, ColorType.BACKGROUND));
        g.fillRect(x, y, width, height);
    }
}
项目:seaglass    文件:SeaGlassButtonUI.java   
/**
 * Paint the button.
 *
 * @param context the Synth context.
 * @param g       the Graphics context.
 */
protected void paint(SeaGlassContext context, Graphics g) {
    AbstractButton b = (AbstractButton) context.getComponent();

    g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
    g.setFont(style.getFont(context));
    context.getStyle().getGraphicsUtils(context).paintText(context, g, b.getText(), getIcon(b), b.getHorizontalAlignment(),
                                                           b.getVerticalAlignment(), b.getHorizontalTextPosition(),
                                                           b.getVerticalTextPosition(), b.getIconTextGap(),
                                                           b.getDisplayedMnemonicIndex(), getTextShiftOffset(context));
}
项目:seaglass    文件:SeaGlassListUI.java   
private void updateStyle(JComponent c) {
    SeaGlassContext context = getContext(c, ENABLED);
    SynthStyle oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);

    if (style != oldStyle) {
        context.setComponentState(SELECTED);
        Color sbg = list.getSelectionBackground();
        if (sbg == null || sbg instanceof UIResource) {
            list.setSelectionBackground(style.getColor(
                             context, ColorType.TEXT_BACKGROUND));
        }

        Color sfg = list.getSelectionForeground();
        if (sfg == null || sfg instanceof UIResource) {
            list.setSelectionForeground(style.getColor(
                             context, ColorType.TEXT_FOREGROUND));
        }

        useListColors = style.getBoolean(context,
                              "List.rendererUseListColors", true);
        useUIBorder = style.getBoolean(context,
                              "List.rendererUseUIBorder", true);

        int height = style.getInt(context, "List.cellHeight", -1);
        if (height != -1) {
            list.setFixedCellHeight(height);
        }
        if (oldStyle != null) {
            uninstallKeyboardActions();
            installKeyboardActions();
        }
    }
    context.dispose();
}
项目:seaglass    文件:SeaGlassLabelUI.java   
protected void paint(SeaGlassContext context, Graphics g) {
    JLabel label = (JLabel) context.getComponent();
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
    g.setFont(style.getFont(context));
    context.getStyle().getGraphicsUtils(context).paintText(context, g, label.getText(), icon, label.getHorizontalAlignment(),
        label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(),
        label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0);
}
项目:seaglass    文件:SeaGlassTreeUI.java   
private void configureRenderer(SeaGlassContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) renderer;
        SeaGlassStyle style = (SeaGlassStyle)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));
        }
    }
}
项目:seaglass    文件:SeaGlassGraphicsUtils.java   
static void paintAccText(Graphics g, SeaGlassMenuItemLayoutHelper lh,
                         MenuItemLayoutHelper.LayoutResult lr) {
    String accText = lh.getAccText();
    if (accText != null && !accText.equals("")) {
        g.setColor(lh.getAccStyle().getColor(lh.getAccContext(),
                ColorType.TEXT_FOREGROUND));
        g.setFont(lh.getAccStyle().getFont(lh.getAccContext()));
        lh.getAccGraphicsUtils().paintText(lh.getAccContext(), g, accText,
                lr.getAccRect().x, lr.getAccRect().y, -1);
    }
}
项目:seaglass    文件:SeaGlassStyle.java   
/**
 * Returns the color for the specified state. This should NOT call any
 * methods on the <code>JComponent</code>.
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, SeaGlassStyle handles ColorTypes slightly differently
 * from Synth.</p>
 *
 * <ul>
 *   <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *     named "background".</li>
 *   <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *     UIDefaults named "textBackground".</li>
 *   <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *     named "textForeground".</li>
 *   <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *     UIDefaults named "textForeground".</li>
 * </ul>
 *
 * @param  ctx  context SynthContext identifying requester
 * @param  type Type of color being requested.
 *
 * @return Color to render with
 */
@Override
public Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;

    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {

        // map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return defaultColor;
    }

    Color c = (Color) get(ctx, key);

    // if all else fails, return a default color (which is a
    // ColorUIResource)
    if (c == null)
        c = defaultColor;

    return c;
}
项目:Solve4x    文件:CustomPainter.java   
@Override
public void paintPanelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
    //create a round rectangle
    RoundRectangle2D.Double rect = new RoundRectangle2D.Double();
    rect.setRoundRect(x, y, w-5, h-5, 15, 15);
    //find the color needed
    Color col = context.getStyle().getColor(context, ColorType.BACKGROUND);
    Graphics2D g2 = (Graphics2D)g;
    //set rendering hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //set the color to the color found above
    g2.setColor(col);
    //draw/fill the rect
    g2.fill(rect);
}
项目:Solve4x    文件:CustomPainter.java   
@Override
public void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
    //create a round rectangle
    RoundRectangle2D.Double rect = new RoundRectangle2D.Double();
    rect.setRoundRect(x, y, w-5, h-5, 10, 10);
    //find the needed color
    Color col = context.getStyle().getColor(context, ColorType.BACKGROUND);
    Graphics2D g2 = (Graphics2D)g;
    //set the color to the one found above
    g2.setColor(col);
    //set the rendering hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //draw/fill the round rectangle
    g2.fill(rect);
}
项目:Solve4x    文件:CustomPainter.java   
@Override
public void paintTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
    //create a round rectangle
    RoundRectangle2D.Double rect = new RoundRectangle2D.Double();
    rect.setRoundRect(x, y, w-5, h-5, 10, 10);
    //get the color we need to use
    Color col = context.getStyle().getColor(context, ColorType.BACKGROUND);
    Graphics2D g2 = (Graphics2D)g;
    //set the color from the one found above
    g2.setColor(col);
    //set rendering hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //draw/fill the round rectangle
    g2.fill(rect);
}
项目:incubator-netbeans    文件:GtkLFCustoms.java   
@Override
public Object[] createLookAndFeelCustomizationKeysAndValues() {
    if (ThemeValue.functioning()) {
        return new Object[] {
            //XXX once the JDK team has integrated support for standard
            //UIManager keys into 1.5 (not there as of b47), these can 
            //probably be deleted, resulting in a performance improvement:
            "control", control,
            "controlHighlight", new ThemeValue (Region.PANEL, ThemeValue.LIGHT, Color.LIGHT_GRAY), //NOI18N
            "controlShadow", new ThemeValue (Region.PANEL, ThemeValue.DARK, Color.DARK_GRAY), //NOI18N
            "controlDkShadow", new ThemeValue (Region.PANEL, ThemeValue.BLACK, Color.BLACK), //NOI18N
            "controlLtHighlight", new ThemeValue (Region.PANEL, ThemeValue.WHITE, Color.WHITE), //NOI18N
            "textText", new ThemeValue (Region.PANEL, ColorType.TEXT_FOREGROUND, Color.BLACK), //NOI18N
            "text", new ThemeValue (Region.PANEL, ColorType.TEXT_BACKGROUND, Color.GRAY), //NOI18N

            "tab_unsel_fill", control, //NOI18N

            "SplitPane.dividerSize", new Integer (2),  //NOI18N

            SYSTEMFONT, controlFont, //NOI18N
            USERFONT, controlFont, //NOI18N
            MENUFONT, controlFont, //NOI18N
            LISTFONT, controlFont, //NOI18N
            "Label.font", controlFont, //NOI18N
            "Panel.font", controlFont, //NOI18N

            // workaround: GTKLookAndFeel FileChooser is unusable, cannot
            // choose a dir and doesn't look native anyway.  We force MetalFileChooserUI

            "FileChooserUI", "javax.swing.plaf.metal.MetalFileChooserUI", // NOI18N
            "FileView.computerIcon",       javax.swing.plaf.metal.MetalIconFactory.getTreeComputerIcon(), // NOI18N
            "FileView.hardDriveIcon",      javax.swing.plaf.metal.MetalIconFactory.getTreeHardDriveIcon(), // NOI18N
            "FileView.floppyDriveIcon",    javax.swing.plaf.metal.MetalIconFactory.getTreeFloppyDriveIcon(), // NOI18N
            "FileChooser.newFolderIcon",   javax.swing.plaf.metal.MetalIconFactory.getFileChooserNewFolderIcon(), // NOI18N
            "FileChooser.upFolderIcon",    javax.swing.plaf.metal.MetalIconFactory.getFileChooserUpFolderIcon(), // NOI18N
            "FileChooser.homeFolderIcon",  javax.swing.plaf.metal.MetalIconFactory.getFileChooserHomeFolderIcon(), // NOI18N
            "FileChooser.detailsViewIcon", javax.swing.plaf.metal.MetalIconFactory.getFileChooserDetailViewIcon(), // NOI18N
            "FileChooser.listViewIcon",    javax.swing.plaf.metal.MetalIconFactory.getFileChooserListViewIcon(), // NOI18N
            "FileChooser.usesSingleFilePane", Boolean.TRUE, // NOI18N
            "FileChooser.ancestorInputMap", // NOI18N
                        new UIDefaults.LazyInputMap(new Object[] {
                            "ESCAPE", "cancelSelection", // NOI18N
                            "F2", "editFileName", // NOI18N
                            "F5", "refresh", // NOI18N
                            "BACK_SPACE", "Go Up", // NOI18N
                            "ENTER", "approveSelection", // NOI18N
                            "ctrl ENTER", "approveSelection" // NOI18N
                        }),
            // special tree icons - only for property sheet
            "Tree.gtk_expandedIcon", new GTKExpandedIcon(),
            "Tree.gtk_collapsedIcon", new GTKCollapsedIcon(),
        };
    } else {
        Object[] result = new Object[] {
            TOOLBAR_UI, new UIDefaults.ProxyLazyValue("org.netbeans.swing.plaf.gtk.GtkToolbarUI"), //NOI18N
            // special tree icons - only for property sheet
            "Tree.gtk_expandedIcon", new GTKExpandedIcon(),
            "Tree.gtk_collapsedIcon", new GTKCollapsedIcon(),
        };
        return result;
    }
}
项目:intellij-ce-playground    文件:GtkPaintingUtil.java   
public static Color getForeground(final BasicMenuItemUI ui, final JMenuItem menuItem) {
  final SynthContext context = getSynthContext(ui, menuItem);
  return context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND);
}
项目:swingx    文件:SynthXListUI.java   
private void updateStyle() {
    // compare local reference to style from factory
    // nothing to do if same
    if (style == getStyle()) return;
    // check if this is called from init or from later update
    // if from later updates, need to cleanup old
    boolean refresh = style != null;
    if (refresh) {
        style.uninstallDefaults(getContext(ENABLED));
    }
    // update local reference
    style = getStyle();
    // special case border
    installSynthBorder();
    // install defaults 
    style.installDefaults(getContext(ENABLED));
    // install selected properties
    SynthContext selectedContext = getContext(SELECTED);
    Color sbg = list.getSelectionBackground();
    if (sbg == null || sbg instanceof UIResource) {
        list.setSelectionBackground(style.getColor(
                selectedContext, ColorType.TEXT_BACKGROUND));
    }

    Color sfg = list.getSelectionForeground();
    if (sfg == null || sfg instanceof UIResource) {
        list.setSelectionForeground(style.getColor(
                selectedContext, ColorType.TEXT_FOREGROUND));
    }
    // install cell height
    int height = style.getInt(selectedContext, "List.cellHeight", -1);
    if (height != -1) {
        list.setFixedCellHeight(height);
    }
    // we do this because ... ??
    if (refresh) {
        uninstallKeyboardActions();
        installKeyboardActions();
    }
    // install currently unused properties of this delegate
    useListColors = style.getBoolean(selectedContext,
            "List.rendererUseListColors", true);
    useUIBorder = style.getBoolean(selectedContext,
            "List.rendererUseUIBorder", true);

}
项目:seaglass    文件:SeaGlassSliderUI.java   
public void paint(SeaGlassContext context, Graphics g) {
    recalculateIfInsetsChanged();
    recalculateIfOrientationChanged();
    Rectangle clip = g.getClipBounds();

    if (lastSize == null || !lastSize.equals(slider.getSize())) {
        calculateGeometry();
    }

    if (paintValue) {
        FontMetrics fm = SwingUtilities2.getFontMetrics(slider, g);
        int labelWidth = context.getStyle().getGraphicsUtils(context).computeStringWidth(context, g.getFont(), fm,
            "" + slider.getValue());
        valueRect.x = thumbRect.x + (thumbRect.width - labelWidth) / 2;

        // For horizontal sliders, make sure value is not painted
        // outside slider bounds.
        if (slider.getOrientation() == JSlider.HORIZONTAL) {
            if (valueRect.x + labelWidth > contentDim.width) {
                valueRect.x = contentDim.width - labelWidth;
            }
            valueRect.x = Math.max(valueRect.x, 0);
        }

        g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
        context.getStyle().getGraphicsUtils(context).paintText(context, g, "" + slider.getValue(), valueRect.x, valueRect.y, -1);
    }

    SeaGlassContext subcontext = getContext(slider, Region.SLIDER_TRACK);
    paintTrack(subcontext, g, trackRect);
    subcontext.dispose();

    subcontext = getContext(slider, Region.SLIDER_THUMB);
    paintThumb(subcontext, g, thumbRect);
    subcontext.dispose();

    if (slider.getPaintTicks() && clip.intersects(tickRect)) {
        paintTicks(g);
    }

    if (slider.getPaintLabels() && clip.intersects(labelRect)) {
        paintLabels(g);
    }
}
项目:seaglass    文件:SeaGlassProgressBarUI.java   
protected void paintText(SeaGlassContext context, Graphics g, String title) {
    if (progressBar.isStringPainted()) {
        SynthStyle style = context.getStyle();
        Font font = style.getFont(context);
        FontMetrics fm = SwingUtilities2.getFontMetrics(progressBar, g, font);
        int strLength = style.getGraphicsUtils(context).computeStringWidth(context, font, fm, title);
        Rectangle bounds = progressBar.getBounds();

        if (rotateText && progressBar.getOrientation() == JProgressBar.VERTICAL) {
            Graphics2D g2 = (Graphics2D) g;
            // Calculate the position for the text.
            Point textPos;
            AffineTransform rotation;
            if (progressBar.getComponentOrientation().isLeftToRight()) {
                rotation = AffineTransform.getRotateInstance(-Math.PI / 2);
                textPos = new Point((bounds.width + fm.getAscent() - fm.getDescent()) / 2, (bounds.height + strLength) / 2);
            } else {
                rotation = AffineTransform.getRotateInstance(Math.PI / 2);
                textPos = new Point((bounds.width - fm.getAscent() + fm.getDescent()) / 2, (bounds.height - strLength) / 2);
            }

            // Progress bar isn't wide enough for the font. Don't paint it.
            if (textPos.x < 0) {
                return;
            }

            // Paint the text.
            font = font.deriveFont(rotation);
            g2.setFont(font);
            g2.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
            style.getGraphicsUtils(context).paintText(context, g, title, textPos.x, textPos.y, -1);
        } else {
            // Calculate the bounds for the text.
            // Rossi: Move text down by one pixel: Looks better but is a hack that may not look good for other font sizes / fonts
            Rectangle textRect = new Rectangle((bounds.width / 2) - (strLength / 2),
                (bounds.height - (fm.getAscent() + fm.getDescent())) / 2+1, 0, 0);

            // Progress bar isn't tall enough for the font. Don't paint it.
            if (textRect.y < 0) {
                return;
            }

            // Paint the text.
            g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
            g.setFont(font);
            style.getGraphicsUtils(context).paintText(context, g, title, textRect.x, textRect.y, -1);
        }
    }
}
项目:seaglass    文件:SeaGlassTextFieldUI.java   
/**
 * Private method to update styles.
 *
 * @param c       the JTextField component.
 * @param context the SeaGlassContext.
 * @param prefix  the control prefix, e.g. "TextField",
 *                "FormattedTextField", or "PasswordField".
 */
static void updateStyle(JTextComponent c, SeaGlassContext context, String prefix) {
    SeaGlassStyle style = (SeaGlassStyle) context.getStyle();

    Color color = c.getCaretColor();

    if (color == null || color instanceof UIResource) {
        c.setCaretColor((Color) style.get(context, prefix + ".caretForeground"));
    }

    Color fg = c.getForeground();

    if (fg == null || fg instanceof UIResource) {
        fg = style.getColorForState(context, ColorType.TEXT_FOREGROUND);
        if (fg != null) {
            c.setForeground(fg);
        }
    }

    Object ar = style.get(context, prefix + ".caretAspectRatio");

    if (ar instanceof Number) {
        c.putClientProperty("caretAspectRatio", ar);
    }

    context.setComponentState(SELECTED | FOCUSED);

    Color s = c.getSelectionColor();

    if (s == null || s instanceof UIResource) {
        c.setSelectionColor(style.getColor(context, ColorType.TEXT_BACKGROUND));
    }

    Color sfg = c.getSelectedTextColor();

    if (sfg == null || sfg instanceof UIResource) {
        c.setSelectedTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
    }

    context.setComponentState(DISABLED);

    Color dfg = c.getDisabledTextColor();

    if (dfg == null || dfg instanceof UIResource) {
        c.setDisabledTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
    }

    Insets margin = c.getMargin();

    if (margin == null || margin instanceof UIResource) {
        margin = (Insets) style.get(context, prefix + ".margin");
        if (margin == null) {
            // Some places assume margins are non-null.
            margin = SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS;
        }

        c.setMargin(margin);
    }

    Caret caret = c.getCaret();

    if (caret instanceof UIResource) {
        Object o = style.get(context, prefix + ".caretBlinkRate");

        if (o != null && o instanceof Integer) {
            Integer rate = (Integer) o;

            caret.setBlinkRate(rate.intValue());
        }
    }
}
项目:seaglass    文件:SeaGlassTreeUI.java   
private void paintRow(TreeCellRenderer renderer, DefaultTreeCellRenderer dtcr, SeaGlassContext treeContext, SeaGlassContext cellContext,
    Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, Rectangle rowBounds, TreePath path, int row, boolean isExpanded,
    boolean hasBeenExpanded, boolean isLeaf) {
    // Don't paint the renderer if editing this row.
    boolean selected = tree.isRowSelected(row);

    JTree.DropLocation dropLocation = tree.getDropLocation();
    boolean isDrop = dropLocation != null && dropLocation.getChildIndex() == -1 && path == dropLocation.getPath();

    int state = ENABLED;
    if (selected || isDrop) {
        state |= SELECTED;
    }

    if (tree.isFocusOwner() && row == getLeadSelectionRow()) {
        state |= FOCUSED;
    }

    cellContext.setComponentState(state);

    if (dtcr != null && (dtcr.getBorderSelectionColor() instanceof UIResource)) {
        dtcr.setBorderSelectionColor(style.getColor(cellContext, ColorType.FOCUS));
    }
    SeaGlassLookAndFeel.updateSubregion(cellContext, g, rowBounds);
    cellContext.getPainter().paintTreeCellBackground(cellContext, g, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
    cellContext.getPainter().paintTreeCellBorder(cellContext, g, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
    if (editingComponent != null && editingRow == row) {
        return;
    }

    int leadIndex;

    if (tree.hasFocus()) {
        leadIndex = getLeadSelectionRow();
    } else {
        leadIndex = -1;
    }

    Component component = renderer.getTreeCellRendererComponent(tree, path.getLastPathComponent(), selected, isExpanded, isLeaf, row,
        (leadIndex == row));

    rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y, bounds.width, bounds.height, true);
}