javax.swing.plaf.synth.ColorType Java Examples

The following examples show how to use javax.swing.plaf.synth.ColorType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NimbusStyle.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #2
Source File: GTKPlusUIUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: NimbusStyle.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #4
Source File: SeaGlassGraphicsUtils.java    From seaglass with Apache License 2.0 6 votes vote down vote up
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());
        }
    }
}
 
Example #5
Source File: SeaGlassTabbedPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #6
Source File: SeaGlassToolTipUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #7
Source File: NimbusStyle.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #8
Source File: NimbusStyle.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #9
Source File: NimbusStyle.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #10
Source File: NimbusStyle.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #11
Source File: NimbusStyle.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #12
Source File: NimbusStyle.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #13
Source File: NimbusStyle.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #14
Source File: NimbusStyle.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #15
Source File: NimbusStyle.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #16
Source File: NimbusStyle.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #17
Source File: NimbusStyle.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #18
Source File: NimbusStyle.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * {@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;
}
 
Example #19
Source File: NimbusStyle.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #20
Source File: NimbusStyle.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #21
Source File: NimbusStyle.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #22
Source File: SeaGlassLookAndFeel.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #23
Source File: SeaGlassStyle.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: ThemeValue.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #25
Source File: SeaGlassGraphicsUtils.java    From seaglass with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #26
Source File: SeaGlassTreeUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example #27
Source File: ThemeValue.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example #28
Source File: SeaGlassLabelUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #29
Source File: SeaGlassListUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #30
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}