35 * 36 * @author Scott Violet 37 */ 38 class GTKStyleFactory extends SynthStyleFactory { 39 40 /** 41 * Saves all styles that have been accessed. In most common cases, 42 * the hash key is simply the WidgetType, but in more complex cases 43 * it will be a ComplexKey object that contains arguments to help 44 * differentiate similar styles. 45 */ 46 private final Map<Object, GTKStyle> stylesCache; 47 48 private Font defaultFont; 49 50 GTKStyleFactory() { 51 stylesCache = new HashMap<Object, GTKStyle>(); 52 } 53 54 /** 55 * Returns the <code>GTKStyle</code> to use based on the 56 * <code>Region</code> id 57 * 58 * @param c this parameter isn't used, may be null. 59 * @param id of the region to get the style. 60 */ 61 public synchronized SynthStyle getStyle(JComponent c, Region id) { 62 WidgetType wt = GTKEngine.getWidgetType(c, id); 63 64 Object key = null; 65 if (id == Region.SCROLL_BAR) { 66 // The style/insets of a scrollbar can depend on a number of 67 // factors (see GTKStyle.getScrollBarInsets()) so use a 68 // complex key here. 69 if (c != null) { 70 JScrollBar sb = (JScrollBar)c; 71 boolean sp = (sb.getParent() instanceof JScrollPane); 72 boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL); 73 boolean ltr = sb.getComponentOrientation().isLeftToRight(); 74 boolean focusable = sb.isFocusable(); 75 key = new ComplexKey(wt, sp, horiz, ltr, focusable); 76 } | 35 * 36 * @author Scott Violet 37 */ 38 class GTKStyleFactory extends SynthStyleFactory { 39 40 /** 41 * Saves all styles that have been accessed. In most common cases, 42 * the hash key is simply the WidgetType, but in more complex cases 43 * it will be a ComplexKey object that contains arguments to help 44 * differentiate similar styles. 45 */ 46 private final Map<Object, GTKStyle> stylesCache; 47 48 private Font defaultFont; 49 50 GTKStyleFactory() { 51 stylesCache = new HashMap<Object, GTKStyle>(); 52 } 53 54 /** 55 * Returns the {@code GTKStyle} to use based on the 56 * {@code Region} id 57 * 58 * @param c this parameter isn't used, may be null. 59 * @param id of the region to get the style. 60 */ 61 public synchronized SynthStyle getStyle(JComponent c, Region id) { 62 WidgetType wt = GTKEngine.getWidgetType(c, id); 63 64 Object key = null; 65 if (id == Region.SCROLL_BAR) { 66 // The style/insets of a scrollbar can depend on a number of 67 // factors (see GTKStyle.getScrollBarInsets()) so use a 68 // complex key here. 69 if (c != null) { 70 JScrollBar sb = (JScrollBar)c; 71 boolean sp = (sb.getParent() instanceof JScrollPane); 72 boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL); 73 boolean ltr = sb.getComponentOrientation().isLeftToRight(); 74 boolean focusable = sb.isFocusable(); 75 key = new ComplexKey(wt, sp, horiz, ltr, focusable); 76 } |