FileDocCategorySizeDatePackage
GTKStyleFactory.javaAPI DocJava SE 6 API5933Tue Jun 10 00:21:56 BST 2008com.sun.java.swing.plaf.gtk

GTKStyleFactory

public class GTKStyleFactory extends SynthStyleFactory
author
Scott Violet

Fields Summary
private static final boolean
isNativeGtk
States if there is native GTK support.
private final Map
stylesCache
Saves all styles that have been accessed. In most common cases, the hash key is simply the WidgetType, but in more complex cases it will be a ComplexKey object that contains arguments to help differentiate similar styles.
private Font
defaultFont
Constructors Summary
GTKStyleFactory()

        stylesCache = new HashMap<Object, GTKStyle>();
    
Methods Summary
public synchronized javax.swing.plaf.synth.SynthStylegetStyle(javax.swing.JComponent c, javax.swing.plaf.synth.Region id)
Returns the GTKStyle to use based on the Region id

param
c this parameter isn't used, may be null.
param
id of the region to get the style.

        WidgetType wt = GTKNativeEngine.getWidgetType(c, id);

        Object key = null;
        if (id == Region.SCROLL_BAR) {
            // The style/insets of a scrollbar can depend on a number of
            // factors (see GTKStyle.getScrollBarInsets()) so use a
            // complex key here.
            if (c != null) {
                JScrollBar sb = (JScrollBar)c;
                boolean sp = (sb.getParent() instanceof JScrollPane);
                boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL);
                boolean ltr = sb.getComponentOrientation().isLeftToRight();
                boolean focusable = sb.isFocusable();
                key = new ComplexKey(wt, sp, horiz, ltr, focusable);
            }
        } 
        else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
            // The style/insets of a checkbox or radiobutton can depend
            // on the component orientation, so use a complex key here.
            if (c != null) {
                boolean ltr = c.getComponentOrientation().isLeftToRight();
                key = new ComplexKey(wt, ltr);
            }
        }
        else if (id == Region.BUTTON) {
            // The style/insets of a button can depend on whether it is
            // default capable or in a toolbar, so use a complex key here.
            if (c != null) {
                JButton btn = (JButton)c;
                boolean toolButton = (btn.getParent() instanceof JToolBar);
                boolean defaultCapable = btn.isDefaultCapable();
                key = new ComplexKey(wt, toolButton, defaultCapable);
            }
        }
        if (key == null) {
            // Otherwise, just use the WidgetType as the key.
            key = wt;
        }

        GTKStyle result = stylesCache.get(key);
        if (result == null) {
            result = isNativeGtk ? 
                     new GTKNativeStyle(defaultFont, wt) : 
                     new GTKDefaultStyle(defaultFont);
            stylesCache.put(key, result);
        }
        
        return result;
    
voidinitStyles(java.awt.Font defaultFont)

        this.defaultFont = defaultFont;
        stylesCache.clear();