. You typically don't need to interact with
this class directly, rather you will load a
that will create a set of SynthStyles.
| Method from javax.swing.plaf.synth.SynthStyle Detail: |
public Object get(SynthContext context,
Object key) {
return getDefaultValue(key);
}
Getter for a region specific style property. |
public boolean getBoolean(SynthContext context,
Object key,
boolean defaultValue) {
Object value = get(context, key);
if (value instanceof Boolean) {
return ((Boolean)value).booleanValue();
}
return defaultValue;
}
Convenience method to get a specific style property whose value is
an Boolean. |
public Color getColor(SynthContext context,
ColorType type) {
JComponent c = context.getComponent();
Region id = context.getRegion();
int cs = context.getComponentState();
// For the enabled state, prefer the widget's colors
if (!id.isSubregion() && cs == SynthConstants.ENABLED) {
if (type == ColorType.BACKGROUND) {
return c.getBackground();
}
else if (type == ColorType.FOREGROUND) {
return c.getForeground();
}
else if (type == ColorType.TEXT_FOREGROUND) {
// If getForeground returns a non-UIResource it means the
// developer has explicitly set the foreground, use it over
// that of TEXT_FOREGROUND as that is typically the expected
// behavior.
Color color = c.getForeground();
if (!(color instanceof UIResource)) {
return color;
}
}
}
// Then use what we've locally defined
Color color = getColorForState(context, type);
if (color == null) {
// No color, fallback to that of the widget.
if (type == ColorType.BACKGROUND ||
type == ColorType.TEXT_BACKGROUND) {
return c.getBackground();
}
else if (type == ColorType.FOREGROUND ||
type == ColorType.TEXT_FOREGROUND) {
return c.getForeground();
}
}
return color;
}
Returns the color for the specified state. This gives precedence to
foreground and background of the JComponent. If the
Color from the JComponent is not appropriate,
or not used, this will invoke getColorForState. Subclasses
should generally not have to override this, instead override
#getColorForState . |
abstract protected Color getColorForState(SynthContext context,
ColorType type)
Returns the color for the specified state. This should NOT call any
methods on the JComponent. |
public Font getFont(SynthContext context) {
JComponent c = context.getComponent();
if (context.getComponentState() == SynthConstants.ENABLED) {
return c.getFont();
}
Font cFont = c.getFont();
if (cFont != null && !(cFont instanceof UIResource)) {
return cFont;
}
return getFontForState(context);
}
Returns the Font for the specified state. This redirects to the
JComponent from the context as necessary.
If this does not redirect
to the JComponent #getFontForState is invoked. |
abstract protected Font getFontForState(SynthContext context)
Returns the font for the specified state. This should NOT call any
method on the JComponent. |
public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
return SYNTH_GRAPHICS;
}
Returns the SynthGraphicUtils for the specified context. |
public Icon getIcon(SynthContext context,
Object key) {
Object value = get(context, key);
if (value instanceof Icon) {
return (Icon)value;
}
return null;
}
Convenience method to get a specific style property whose value is
an Icon. |
public Insets getInsets(SynthContext context,
Insets insets) {
if (insets == null) {
insets = new Insets(0, 0, 0, 0);
}
insets.top = insets.bottom = insets.left = insets.right = 0;
return insets;
}
Returns the Insets that are used to calculate sizing information. |
public int getInt(SynthContext context,
Object key,
int defaultValue) {
Object value = get(context, key);
if (value instanceof Number) {
return ((Number)value).intValue();
}
return defaultValue;
}
Convenience method to get a specific style property whose value is
a Number. If the value is a Number,
intValue is returned, otherwise defaultValue
is returned. |
public SynthPainter getPainter(SynthContext context) {
return null;
}
Returns the SynthPainter that will be used for painting.
This may return null. |
public String getString(SynthContext context,
Object key,
String defaultValue) {
Object value = get(context, key);
if (value instanceof String) {
return (String)value;
}
return defaultValue;
}
Convenience method to get a specific style property whose value is
a String. |
public void installDefaults(SynthContext context) {
if (!context.isSubregion()) {
JComponent c = context.getComponent();
Region region = context.getRegion();
Font font = c.getFont();
if (font == null || (font instanceof UIResource)) {
c.setFont(getFontForState(context));
}
Color background = c.getBackground();
if (background == null || (background instanceof UIResource)) {
c.setBackground(getColorForState(context,
ColorType.BACKGROUND));
}
Color foreground = c.getForeground();
if (foreground == null || (foreground instanceof UIResource)) {
c.setForeground(getColorForState(context,
ColorType.FOREGROUND));
}
LookAndFeel.installProperty(c, "opaque", Boolean.valueOf(isOpaque(context)));
}
}
Installs the necessary state from this Style on the
JComponent from context. |
void installDefaults(SynthContext context,
SynthUI ui) {
// Special case the Border as this will likely change when the LAF
// can have more control over this.
if (!context.isSubregion()) {
JComponent c = context.getComponent();
Border border = c.getBorder();
if (border == null || border instanceof UIResource) {
c.setBorder(new SynthBorder(ui, getInsets(context, null)));
}
}
installDefaults(context);
}
|
public boolean isOpaque(SynthContext context) {
return true;
}
Returns true if the region is opaque. |
public void uninstallDefaults(SynthContext context) {
if (!context.isSubregion()) {
// NOTE: because getForeground, getBackground and getFont will look
// at the parent Container, if we set them to null it may
// mean we they return a non-null and non-UIResource value
// preventing install from correctly settings its colors/font. For
// this reason we do not uninstall the fg/bg/font.
JComponent c = context.getComponent();
Border border = c.getBorder();
if (border instanceof UIResource) {
c.setBorder(null);
}
}
}
Uninstalls any state that this style installed on
the JComponent from context.
Styles should NOT depend upon this being called, in certain cases
it may never be called. |