FileDocCategorySizeDatePackage
SynthContext.javaAPI DocJava SE 5 API5199Fri Aug 26 14:58:12 BST 2005javax.swing.plaf.synth

SynthContext

public class SynthContext extends Object
An immutable transient object containing contextual information about a Region. A SynthContext should only be considered valid for the duration of the method it is passed to. In other words you should not cache a SynthContext that is passed to you and expect it to remain valid.
version
1.9, 12/19/03
since
1.5
author
Scott Violet

Fields Summary
private static final Map
contextMap
private JComponent
component
private Region
region
private SynthStyle
style
private int
state
Constructors Summary
SynthContext()

    
public SynthContext(JComponent component, Region region, SynthStyle style, int state)
Creates a SynthContext with the specified values. This is meant for subclasses and custom UI implementors. You very rarely need to construct a SynthContext, though some methods will take one.

param
component JComponent
param
region Identifies the portion of the JComponent
param
style Style associated with the component
param
state State of the component as defined in SynthConstants.
throws
NullPointerException if component, region of style is null.

        if (component == null || region == null || style == null) {
            throw new NullPointerException(
                "You must supply a non-null component, region and style");
        }
        reset(component, region, style, state);
    
Methods Summary
voiddispose()

        this.component = null;
        this.style = null;
        releaseContext(this);
    
public javax.swing.JComponentgetComponent()
Returns the hosting component containing the region.

return
Hosting Component

        return component;
    
public intgetComponentState()
Returns the state of the widget, which is a bitmask of the values defined in SynthConstants. A region will at least be in one of ENABLED, MOUSE_OVER, PRESSED or DISABLED.

see
SynthConstants
return
State of Component

        return state;
    
static javax.swing.plaf.synth.SynthContextgetContext(java.lang.Class type, javax.swing.JComponent component, javax.swing.plaf.synth.Region region, javax.swing.plaf.synth.SynthStyle style, int state)

        contextMap = new HashMap();
    
        SynthContext context = null;

        synchronized(contextMap) {
            java.util.List instances = (java.util.List)contextMap.get(type);

            if (instances != null) {
                int size = instances.size();

                if (size > 0) {
                    context = (SynthContext)instances.remove(size - 1);
                }
            }
        }
        if (context == null) {
            try {
                context = (SynthContext)type.newInstance();
            } catch (IllegalAccessException iae) {
            } catch (InstantiationException ie) {
            }
        }
        context.reset(component, region, style, state);
        return context;
    
javax.swing.plaf.synth.SynthPaintergetPainter()
Convenience method to get the Painter from the current SynthStyle. This will NEVER return null.

        SynthPainter painter = getStyle().getPainter(this);

        if (painter != null) {
            return painter;
        }
        return SynthPainter.NULL_PAINTER;
    
public javax.swing.plaf.synth.RegiongetRegion()
Returns the Region identifying this state.

return
Region of the hosting component

        return region;
    
public javax.swing.plaf.synth.SynthStylegetStyle()
Returns the style associated with this Region.

return
SynthStyle associated with the region.

        return style;
    
booleanisSubregion()
A convenience method for getRegion().isSubregion().

        return getRegion().isSubregion();
    
static voidreleaseContext(javax.swing.plaf.synth.SynthContext context)

        synchronized(contextMap) {
            java.util.List instances = (java.util.List)contextMap.get(
                                       context.getClass());

            if (instances == null) {
                instances = new ArrayList(5);
                contextMap.put(context.getClass(), instances);
            }
            instances.add(context);
        }
    
voidreset(javax.swing.JComponent component, javax.swing.plaf.synth.Region region, javax.swing.plaf.synth.SynthStyle style, int state)
Resets the state of the Context.

        this.component = component;
        this.region = region;
        this.style = style;
        this.state = state;
    
voidsetComponentState(int state)

        this.state = state;
    
voidsetStyle(javax.swing.plaf.synth.SynthStyle style)

        this.style = style;