本文整理汇总了Java中javax.swing.plaf.synth.ColorType类的典型用法代码示例。如果您正苦于以下问题:Java ColorType类的具体用法?Java ColorType怎么用?Java ColorType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColorType类属于javax.swing.plaf.synth包,在下文中一共展示了ColorType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColorForState
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* {@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;
}
示例2: update
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* 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);
}
}
示例3: paint
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* 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);
}
}
示例4: paintText
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* 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);
}
}
示例5: paintText
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
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());
}
}
}
示例6: getColorForState
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* @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;
}
示例7: compute
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
@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;
}
示例8: getColorForState
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* @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;
}
示例9: ThemeValue
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/** 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);
}
示例10: checkFunctioning
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
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;
}
}
示例11: paintRegion
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* 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);
}
}
示例12: paint
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
/**
* 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));
}
示例13: updateStyle
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
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();
}
示例14: paint
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
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);
}
示例15: configureRenderer
import javax.swing.plaf.synth.ColorType; //导入依赖的package包/类
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));
}
}
}