< prev index next >

src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java

Print this page




 115     }
 116 
 117     @Override
 118     public void installDefaults(SynthContext context) {
 119         super.installDefaults(context);
 120         Map<Object, Object> aaTextInfo = GTKLookAndFeel.aaTextInfo;
 121         if (aaTextInfo != null && !context.getRegion().isSubregion()) {
 122             context.getComponent().putClientProperty(KEY_TEXT_ANTIALIASING,
 123                     aaTextInfo.get(KEY_TEXT_ANTIALIASING));
 124             context.getComponent().putClientProperty(KEY_TEXT_LCD_CONTRAST,
 125                     aaTextInfo.get(KEY_TEXT_LCD_CONTRAST));
 126         }
 127     }
 128 
 129     @Override
 130     public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
 131         return GTK_GRAPHICS;
 132     }
 133 
 134     /**
 135      * Returns a <code>SynthPainter</code> that will route the appropriate
 136      * calls to a <code>GTKEngine</code>.
 137      *
 138      * @param state SynthContext identifying requestor
 139      * @return SynthPainter
 140      */
 141     @Override
 142     public SynthPainter getPainter(SynthContext state) {
 143         return GTKPainter.INSTANCE;
 144     }
 145 
 146     protected Color getColorForState(SynthContext context, ColorType type) {
 147         if (type == ColorType.FOCUS || type == GTKColorType.BLACK) {
 148             return BLACK_COLOR;
 149         }
 150         else if (type == GTKColorType.WHITE) {
 151             return WHITE_COLOR;
 152         }
 153 
 154         Region id = context.getRegion();
 155         int state = context.getComponentState();
 156         state = GTKLookAndFeel.synthStateToGTKState(id, state);


 288 
 289     /**
 290      * Returns the X thickness to use for this GTKStyle.
 291      *
 292      * @return x thickness.
 293      */
 294     int getXThickness() {
 295         return xThickness;
 296     }
 297 
 298     /**
 299      * Returns the Y thickness to use for this GTKStyle.
 300      *
 301      * @return y thickness.
 302      */
 303     int getYThickness() {
 304         return yThickness;
 305     }
 306 
 307     /**
 308      * Returns the Insets. If <code>insets</code> is non-null the resulting
 309      * insets will be placed in it, otherwise a new Insets object will be
 310      * created and returned.
 311      *
 312      * @param context SynthContext identifying requestor
 313      * @param insets Where to place Insets
 314      * @return Insets.
 315      */
 316     @Override
 317     public Insets getInsets(SynthContext state, Insets insets) {
 318         Region id = state.getRegion();
 319         JComponent component = state.getComponent();
 320         String name = (id.isSubregion()) ? null : component.getName();
 321 
 322         if (insets == null) {
 323             insets = new Insets(0, 0, 0, 0);
 324         } else {
 325             insets.top = insets.bottom = insets.left = insets.right = 0;
 326         }
 327 
 328         if (id == Region.ARROW_BUTTON || id == Region.BUTTON ||


 599      * SCROLL_PANE region).
 600      *
 601      * @param wt WidgetType for which to fetch the value
 602      * @param key Key identifying class specific value
 603      * @return Value, or null if one has not been defined
 604      */
 605     private static Object getClassSpecificValue(WidgetType wt, String key) {
 606         synchronized (UNIXToolkit.GTK_LOCK) {
 607             return nativeGetClassValue(wt.ordinal(), key);
 608         }
 609     }
 610 
 611     /**
 612      * Convenience method to get a class specific integer value for
 613      * a particular WidgetType.
 614      *
 615      * @param wt WidgetType for which to fetch the value
 616      * @param key Key identifying class specific value
 617      * @param defaultValue Returned if there is no value for the specified
 618      *        type
 619      * @return Value, or defaultValue if <code>key</code> is not defined
 620      */
 621     private static int getClassSpecificIntValue(WidgetType wt, String key,
 622                                                 int defaultValue)
 623     {
 624         Object value = getClassSpecificValue(wt, key);
 625         if (value instanceof Number) {
 626             return ((Number)value).intValue();
 627         }
 628         return defaultValue;
 629     }
 630 
 631     /**
 632      * Returns the value for a class specific property. A class specific value
 633      * is a value that will be picked up based on class hierarchy.
 634      *
 635      * @param key Key identifying class specific value
 636      * @return Value, or null if one has not been defined.
 637      */
 638     Object getClassSpecificValue(String key) {
 639         synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
 640             return nativeGetClassValue(widgetType, key);
 641         }
 642     }
 643 
 644     /**
 645      * Convenience method to get a class specific integer value.
 646      *
 647      * @param context SynthContext identifying requestor
 648      * @param key Key identifying class specific value
 649      * @param defaultValue Returned if there is no value for the specified
 650      *        type
 651      * @return Value, or defaultValue if <code>key</code> is not defined
 652      */
 653     int getClassSpecificIntValue(SynthContext context, String key,
 654                                  int defaultValue)
 655     {
 656         Object value = getClassSpecificValue(key);
 657 
 658         if (value instanceof Number) {
 659             return ((Number)value).intValue();
 660         }
 661         return defaultValue;
 662     }
 663 
 664     /**
 665      * Convenience method to get a class specific Insets value.
 666      *
 667      * @param context SynthContext identifying requestor
 668      * @param key Key identifying class specific value
 669      * @param defaultValue Returned if there is no value for the specified
 670      *        type
 671      * @return Value, or defaultValue if <code>key</code> is not defined
 672      */
 673     Insets getClassSpecificInsetsValue(SynthContext context, String key,
 674                                        Insets defaultValue)
 675     {
 676         Object value = getClassSpecificValue(key);
 677 
 678         if (value instanceof Insets) {
 679             return (Insets)value;
 680         }
 681         return defaultValue;
 682     }
 683 
 684     /**
 685      * Convenience method to get a class specific Boolean value.
 686      *
 687      * @param context SynthContext identifying requestor
 688      * @param key Key identifying class specific value
 689      * @param defaultValue Returned if there is no value for the specified
 690      *        type
 691      * @return Value, or defaultValue if <code>key</code> is not defined
 692      */
 693     boolean getClassSpecificBoolValue(SynthContext context, String key,
 694                                       boolean defaultValue)
 695     {
 696         Object value = getClassSpecificValue(key);
 697 
 698         if (value instanceof Boolean) {
 699             return ((Boolean)value).booleanValue();
 700         }
 701         return defaultValue;
 702     }
 703 
 704     /**
 705      * Returns the value to initialize the opacity property of the Component
 706      * to. A Style should NOT assume the opacity will remain this value, the
 707      * developer may reset it or override it.
 708      *
 709      * @param context SynthContext identifying requestor
 710      * @return opaque Whether or not the JComponent is opaque.
 711      */


1051                 if (co == null || co.isLeftToRight()) {
1052                     if (!loadedLTR) {
1053                         loadedLTR = true;
1054                         ltrIcon = ((GTKStyle)context.getStyle()).
1055                                   getStockIcon(context, key, size);
1056                     }
1057                     return ltrIcon;
1058                 }
1059                 else if (!loadedRTL) {
1060                     loadedRTL = true;
1061                     rtlIcon = ((GTKStyle)context.getStyle()).
1062                               getStockIcon(context, key,size);
1063                 }
1064                 return rtlIcon;
1065             }
1066             return ltrIcon;
1067         }
1068     }
1069 
1070     /**
1071      * GTKLazyValue is a slimmed down version of <code>ProxyLaxyValue</code>.
1072      * The code is duplicate so that it can get at the package private
1073      * classes in gtk.
1074      */
1075     static class GTKLazyValue implements UIDefaults.LazyValue {
1076         /**
1077          * Name of the class to create.
1078          */
1079         private String className;
1080         private String methodName;
1081 
1082         GTKLazyValue(String name) {
1083             this(name, null);
1084         }
1085 
1086         GTKLazyValue(String name, String methodName) {
1087             this.className = name;
1088             this.methodName = methodName;
1089         }
1090 
1091         public Object createValue(UIDefaults table) {




 115     }
 116 
 117     @Override
 118     public void installDefaults(SynthContext context) {
 119         super.installDefaults(context);
 120         Map<Object, Object> aaTextInfo = GTKLookAndFeel.aaTextInfo;
 121         if (aaTextInfo != null && !context.getRegion().isSubregion()) {
 122             context.getComponent().putClientProperty(KEY_TEXT_ANTIALIASING,
 123                     aaTextInfo.get(KEY_TEXT_ANTIALIASING));
 124             context.getComponent().putClientProperty(KEY_TEXT_LCD_CONTRAST,
 125                     aaTextInfo.get(KEY_TEXT_LCD_CONTRAST));
 126         }
 127     }
 128 
 129     @Override
 130     public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
 131         return GTK_GRAPHICS;
 132     }
 133 
 134     /**
 135      * Returns a {@code SynthPainter} that will route the appropriate
 136      * calls to a {@code GTKEngine}.
 137      *
 138      * @param state SynthContext identifying requestor
 139      * @return SynthPainter
 140      */
 141     @Override
 142     public SynthPainter getPainter(SynthContext state) {
 143         return GTKPainter.INSTANCE;
 144     }
 145 
 146     protected Color getColorForState(SynthContext context, ColorType type) {
 147         if (type == ColorType.FOCUS || type == GTKColorType.BLACK) {
 148             return BLACK_COLOR;
 149         }
 150         else if (type == GTKColorType.WHITE) {
 151             return WHITE_COLOR;
 152         }
 153 
 154         Region id = context.getRegion();
 155         int state = context.getComponentState();
 156         state = GTKLookAndFeel.synthStateToGTKState(id, state);


 288 
 289     /**
 290      * Returns the X thickness to use for this GTKStyle.
 291      *
 292      * @return x thickness.
 293      */
 294     int getXThickness() {
 295         return xThickness;
 296     }
 297 
 298     /**
 299      * Returns the Y thickness to use for this GTKStyle.
 300      *
 301      * @return y thickness.
 302      */
 303     int getYThickness() {
 304         return yThickness;
 305     }
 306 
 307     /**
 308      * Returns the Insets. If {@code insets} is non-null the resulting
 309      * insets will be placed in it, otherwise a new Insets object will be
 310      * created and returned.
 311      *
 312      * @param context SynthContext identifying requestor
 313      * @param insets Where to place Insets
 314      * @return Insets.
 315      */
 316     @Override
 317     public Insets getInsets(SynthContext state, Insets insets) {
 318         Region id = state.getRegion();
 319         JComponent component = state.getComponent();
 320         String name = (id.isSubregion()) ? null : component.getName();
 321 
 322         if (insets == null) {
 323             insets = new Insets(0, 0, 0, 0);
 324         } else {
 325             insets.top = insets.bottom = insets.left = insets.right = 0;
 326         }
 327 
 328         if (id == Region.ARROW_BUTTON || id == Region.BUTTON ||


 599      * SCROLL_PANE region).
 600      *
 601      * @param wt WidgetType for which to fetch the value
 602      * @param key Key identifying class specific value
 603      * @return Value, or null if one has not been defined
 604      */
 605     private static Object getClassSpecificValue(WidgetType wt, String key) {
 606         synchronized (UNIXToolkit.GTK_LOCK) {
 607             return nativeGetClassValue(wt.ordinal(), key);
 608         }
 609     }
 610 
 611     /**
 612      * Convenience method to get a class specific integer value for
 613      * a particular WidgetType.
 614      *
 615      * @param wt WidgetType for which to fetch the value
 616      * @param key Key identifying class specific value
 617      * @param defaultValue Returned if there is no value for the specified
 618      *        type
 619      * @return Value, or defaultValue if {@code key} is not defined
 620      */
 621     private static int getClassSpecificIntValue(WidgetType wt, String key,
 622                                                 int defaultValue)
 623     {
 624         Object value = getClassSpecificValue(wt, key);
 625         if (value instanceof Number) {
 626             return ((Number)value).intValue();
 627         }
 628         return defaultValue;
 629     }
 630 
 631     /**
 632      * Returns the value for a class specific property. A class specific value
 633      * is a value that will be picked up based on class hierarchy.
 634      *
 635      * @param key Key identifying class specific value
 636      * @return Value, or null if one has not been defined.
 637      */
 638     Object getClassSpecificValue(String key) {
 639         synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
 640             return nativeGetClassValue(widgetType, key);
 641         }
 642     }
 643 
 644     /**
 645      * Convenience method to get a class specific integer value.
 646      *
 647      * @param context SynthContext identifying requestor
 648      * @param key Key identifying class specific value
 649      * @param defaultValue Returned if there is no value for the specified
 650      *        type
 651      * @return Value, or defaultValue if {@code key} is not defined
 652      */
 653     int getClassSpecificIntValue(SynthContext context, String key,
 654                                  int defaultValue)
 655     {
 656         Object value = getClassSpecificValue(key);
 657 
 658         if (value instanceof Number) {
 659             return ((Number)value).intValue();
 660         }
 661         return defaultValue;
 662     }
 663 
 664     /**
 665      * Convenience method to get a class specific Insets value.
 666      *
 667      * @param context SynthContext identifying requestor
 668      * @param key Key identifying class specific value
 669      * @param defaultValue Returned if there is no value for the specified
 670      *        type
 671      * @return Value, or defaultValue if {@code key} is not defined
 672      */
 673     Insets getClassSpecificInsetsValue(SynthContext context, String key,
 674                                        Insets defaultValue)
 675     {
 676         Object value = getClassSpecificValue(key);
 677 
 678         if (value instanceof Insets) {
 679             return (Insets)value;
 680         }
 681         return defaultValue;
 682     }
 683 
 684     /**
 685      * Convenience method to get a class specific Boolean value.
 686      *
 687      * @param context SynthContext identifying requestor
 688      * @param key Key identifying class specific value
 689      * @param defaultValue Returned if there is no value for the specified
 690      *        type
 691      * @return Value, or defaultValue if {@code key} is not defined
 692      */
 693     boolean getClassSpecificBoolValue(SynthContext context, String key,
 694                                       boolean defaultValue)
 695     {
 696         Object value = getClassSpecificValue(key);
 697 
 698         if (value instanceof Boolean) {
 699             return ((Boolean)value).booleanValue();
 700         }
 701         return defaultValue;
 702     }
 703 
 704     /**
 705      * Returns the value to initialize the opacity property of the Component
 706      * to. A Style should NOT assume the opacity will remain this value, the
 707      * developer may reset it or override it.
 708      *
 709      * @param context SynthContext identifying requestor
 710      * @return opaque Whether or not the JComponent is opaque.
 711      */


1051                 if (co == null || co.isLeftToRight()) {
1052                     if (!loadedLTR) {
1053                         loadedLTR = true;
1054                         ltrIcon = ((GTKStyle)context.getStyle()).
1055                                   getStockIcon(context, key, size);
1056                     }
1057                     return ltrIcon;
1058                 }
1059                 else if (!loadedRTL) {
1060                     loadedRTL = true;
1061                     rtlIcon = ((GTKStyle)context.getStyle()).
1062                               getStockIcon(context, key,size);
1063                 }
1064                 return rtlIcon;
1065             }
1066             return ltrIcon;
1067         }
1068     }
1069 
1070     /**
1071      * GTKLazyValue is a slimmed down version of {@code ProxyLaxyValue}.
1072      * The code is duplicate so that it can get at the package private
1073      * classes in gtk.
1074      */
1075     static class GTKLazyValue implements UIDefaults.LazyValue {
1076         /**
1077          * Name of the class to create.
1078          */
1079         private String className;
1080         private String methodName;
1081 
1082         GTKLazyValue(String name) {
1083             this(name, null);
1084         }
1085 
1086         GTKLazyValue(String name, String methodName) {
1087             this.className = name;
1088             this.methodName = methodName;
1089         }
1090 
1091         public Object createValue(UIDefaults table) {


< prev index next >