< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 261             if (type == ColorType.BACKGROUND) {
 262                 return c.getBackground();
 263             }
 264             else if (type == ColorType.FOREGROUND) {
 265                 return c.getForeground();
 266             }
 267             else if (type == ColorType.TEXT_FOREGROUND) {
 268                 // If getForeground returns a non-UIResource it means the
 269                 // developer has explicitly set the foreground, use it over
 270                 // that of TEXT_FOREGROUND as that is typically the expected
 271                 // behavior.
 272                 Color color = c.getForeground();
 273                 if (color != null && !(color instanceof UIResource)) {
 274                     return color;
 275                 }
 276             }
 277         }
 278         return getColorForState(context, type);
 279     }
 280 




 281     protected Font getFontForState(SynthContext context) {






 282         return font;
 283     }
 284 
 285     /**
 286      * Returns the X thickness to use for this GTKStyle.
 287      *
 288      * @return x thickness.
 289      */
 290     int getXThickness() {
 291         return xThickness;
 292     }
 293 
 294     /**
 295      * Returns the Y thickness to use for this GTKStyle.
 296      *
 297      * @return y thickness.
 298      */
 299     int getYThickness() {
 300         return yThickness;
 301     }


 694         if (value instanceof Boolean) {
 695             return ((Boolean)value).booleanValue();
 696         }
 697         return defaultValue;
 698     }
 699 
 700     /**
 701      * Returns the value to initialize the opacity property of the Component
 702      * to. A Style should NOT assume the opacity will remain this value, the
 703      * developer may reset it or override it.
 704      *
 705      * @param context SynthContext identifying requestor
 706      * @return opaque Whether or not the JComponent is opaque.
 707      */
 708     @Override
 709     public boolean isOpaque(SynthContext context) {
 710         Region region = context.getRegion();
 711         if (region == Region.COMBO_BOX ||
 712               region == Region.DESKTOP_PANE ||
 713               region == Region.DESKTOP_ICON ||
 714               region == Region.EDITOR_PANE ||
 715               region == Region.FORMATTED_TEXT_FIELD ||
 716               region == Region.INTERNAL_FRAME ||
 717               region == Region.LIST ||
 718               region == Region.MENU_BAR ||
 719               region == Region.PANEL ||
 720               region == Region.PASSWORD_FIELD ||
 721               region == Region.POPUP_MENU ||
 722               region == Region.PROGRESS_BAR ||
 723               region == Region.ROOT_PANE ||
 724               region == Region.SCROLL_PANE ||
 725               region == Region.SPINNER ||
 726               region == Region.SPLIT_PANE_DIVIDER ||
 727               region == Region.TABLE ||
 728               region == Region.TEXT_AREA ||
 729               region == Region.TEXT_FIELD ||
 730               region == Region.TEXT_PANE ||
 731               region == Region.TOOL_BAR_DRAG_WINDOW ||
 732               region == Region.TOOL_TIP ||
 733               region == Region.TREE ||
 734               region == Region.VIEWPORT) {
 735             return true;
 736         }










 737         Component c = context.getComponent();
 738         String name = c.getName();
 739         if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") {
 740             return true;
 741         }
 742         return false;
 743     }
 744 
 745     @Override
 746     public Object get(SynthContext context, Object key) {
 747         // See if this is a class specific value.
 748         String classKey = CLASS_SPECIFIC_MAP.get(key);
 749         if (classKey != null) {
 750             Object value = getClassSpecificValue(classKey);
 751             if (value != null) {
 752                 return value;
 753             }
 754         }
 755 
 756         // Is it a specific value ?


 812             }
 813             // For all other kinds of arrow buttons (e.g. combobox arrow
 814             // buttons), we will simply fall back on the value of
 815             // ArrowButton.size as defined in the UIDefaults for
 816             // GTKLookAndFeel when we call UIManager.get() below...
 817         }
 818         else if ("CheckBox.iconTextGap".equals(key) ||
 819                  "RadioButton.iconTextGap".equals(key))
 820         {
 821             // The iconTextGap value needs to include "indicator-spacing"
 822             // and it also needs to leave enough space for the focus line,
 823             // which falls between the indicator icon and the text.
 824             // See getRadioInsets() and 6489585 for more details.
 825             int indicatorSpacing =
 826                 getClassSpecificIntValue(context, "indicator-spacing", 2);
 827             int focusSize =
 828                 getClassSpecificIntValue(context, "focus-line-width", 1);
 829             int focusPad =
 830                 getClassSpecificIntValue(context, "focus-padding", 1);
 831             return indicatorSpacing + focusSize + focusPad;








 832         }
 833 
 834         // Is it a stock icon ?
 835         GTKStockIcon stockIcon = null;
 836         synchronized (ICONS_MAP) {
 837             stockIcon = ICONS_MAP.get(key);
 838         }
 839 
 840         if (stockIcon != null) {
 841             return stockIcon;
 842         }
 843 
 844         // Is it another kind of value ?
 845         if (key != "engine") {
 846             // For backward compatibility we'll fallback to the UIManager.
 847             // We don't go to the UIManager for engine as the engine is GTK
 848             // specific.
 849             Object value = UIManager.get(key);
 850             if (key == "Table.rowHeight") {
 851                 int focusLineWidth = getClassSpecificIntValue(context,


1091 
1092                 if (methodName == null) {
1093                     return c.newInstance();
1094                 }
1095                 Method m = c.getMethod(methodName, (Class[])null);
1096 
1097                 return m.invoke(c, (Object[])null);
1098             } catch (ClassNotFoundException cnfe) {
1099             } catch (IllegalAccessException iae) {
1100             } catch (InvocationTargetException ite) {
1101             } catch (NoSuchMethodException nsme) {
1102             } catch (InstantiationException ie) {
1103             }
1104             return null;
1105         }
1106     }
1107 
1108     static {
1109         CLASS_SPECIFIC_MAP = new HashMap<String,String>();
1110         CLASS_SPECIFIC_MAP.put("Slider.thumbHeight", "slider-width");

1111         CLASS_SPECIFIC_MAP.put("Slider.trackBorder", "trough-border");
1112         CLASS_SPECIFIC_MAP.put("SplitPane.size", "handle-size");
1113         CLASS_SPECIFIC_MAP.put("Tree.expanderSize", "expander-size");
1114         CLASS_SPECIFIC_MAP.put("ScrollBar.thumbHeight", "slider-width");
1115         CLASS_SPECIFIC_MAP.put("ScrollBar.width", "slider-width");
1116         CLASS_SPECIFIC_MAP.put("TextArea.caretForeground", "cursor-color");
1117         CLASS_SPECIFIC_MAP.put("TextArea.caretAspectRatio", "cursor-aspect-ratio");
1118         CLASS_SPECIFIC_MAP.put("TextField.caretForeground", "cursor-color");
1119         CLASS_SPECIFIC_MAP.put("TextField.caretAspectRatio", "cursor-aspect-ratio");
1120         CLASS_SPECIFIC_MAP.put("PasswordField.caretForeground", "cursor-color");
1121         CLASS_SPECIFIC_MAP.put("PasswordField.caretAspectRatio", "cursor-aspect-ratio");
1122         CLASS_SPECIFIC_MAP.put("FormattedTextField.caretForeground", "cursor-color");
1123         CLASS_SPECIFIC_MAP.put("FormattedTextField.caretAspectRatio", "cursor-aspect-");
1124         CLASS_SPECIFIC_MAP.put("TextPane.caretForeground", "cursor-color");
1125         CLASS_SPECIFIC_MAP.put("TextPane.caretAspectRatio", "cursor-aspect-ratio");
1126         CLASS_SPECIFIC_MAP.put("EditorPane.caretForeground", "cursor-color");
1127         CLASS_SPECIFIC_MAP.put("EditorPane.caretAspectRatio", "cursor-aspect-ratio");
1128 
1129         ICONS_MAP = new HashMap<String, GTKStockIcon>();
1130         ICONS_MAP.put("FileChooser.cancelIcon", new GTKStockIcon("gtk-cancel", 4));
1131         ICONS_MAP.put("FileChooser.okIcon",     new GTKStockIcon("gtk-ok",     4));
1132         ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("gtk-dialog-error", 6));
1133         ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("gtk-dialog-info", 6));
   1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 261             if (type == ColorType.BACKGROUND) {
 262                 return c.getBackground();
 263             }
 264             else if (type == ColorType.FOREGROUND) {
 265                 return c.getForeground();
 266             }
 267             else if (type == ColorType.TEXT_FOREGROUND) {
 268                 // If getForeground returns a non-UIResource it means the
 269                 // developer has explicitly set the foreground, use it over
 270                 // that of TEXT_FOREGROUND as that is typically the expected
 271                 // behavior.
 272                 Color color = c.getForeground();
 273                 if (color != null && !(color instanceof UIResource)) {
 274                     return color;
 275                 }
 276             }
 277         }
 278         return getColorForState(context, type);
 279     }
 280 
 281     Font getDefaultFont() {
 282         return font;
 283     }
 284 
 285     protected Font getFontForState(SynthContext context) {
 286         Font propFont = UIManager
 287                               .getFont(context.getRegion().getName() + ".font");
 288         if (propFont != null) {
 289             // if font property got a value then return it
 290             return propFont;
 291         }
 292         return font;
 293     }
 294 
 295     /**
 296      * Returns the X thickness to use for this GTKStyle.
 297      *
 298      * @return x thickness.
 299      */
 300     int getXThickness() {
 301         return xThickness;
 302     }
 303 
 304     /**
 305      * Returns the Y thickness to use for this GTKStyle.
 306      *
 307      * @return y thickness.
 308      */
 309     int getYThickness() {
 310         return yThickness;
 311     }


 704         if (value instanceof Boolean) {
 705             return ((Boolean)value).booleanValue();
 706         }
 707         return defaultValue;
 708     }
 709 
 710     /**
 711      * Returns the value to initialize the opacity property of the Component
 712      * to. A Style should NOT assume the opacity will remain this value, the
 713      * developer may reset it or override it.
 714      *
 715      * @param context SynthContext identifying requestor
 716      * @return opaque Whether or not the JComponent is opaque.
 717      */
 718     @Override
 719     public boolean isOpaque(SynthContext context) {
 720         Region region = context.getRegion();
 721         if (region == Region.COMBO_BOX ||
 722               region == Region.DESKTOP_PANE ||
 723               region == Region.DESKTOP_ICON ||


 724               region == Region.INTERNAL_FRAME ||
 725               region == Region.LIST ||
 726               region == Region.MENU_BAR ||
 727               region == Region.PANEL ||

 728               region == Region.POPUP_MENU ||
 729               region == Region.PROGRESS_BAR ||
 730               region == Region.ROOT_PANE ||
 731               region == Region.SCROLL_PANE ||

 732               region == Region.SPLIT_PANE_DIVIDER ||
 733               region == Region.TABLE ||
 734               region == Region.TEXT_AREA ||


 735               region == Region.TOOL_BAR_DRAG_WINDOW ||
 736               region == Region.TOOL_TIP ||
 737               region == Region.TREE ||
 738               region == Region.VIEWPORT) {
 739             return true;
 740         }
 741         if (!GTKLookAndFeel.is3()) {
 742             if (region == Region.EDITOR_PANE ||
 743                   region == Region.FORMATTED_TEXT_FIELD ||
 744                   region == Region.PASSWORD_FIELD ||
 745                   region == Region.SPINNER ||
 746                   region == Region.TEXT_FIELD ||
 747                   region == Region.TEXT_PANE) {
 748                 return true;
 749             }
 750         }
 751         Component c = context.getComponent();
 752         String name = c.getName();
 753         if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") {
 754             return true;
 755         }
 756         return false;
 757     }
 758 
 759     @Override
 760     public Object get(SynthContext context, Object key) {
 761         // See if this is a class specific value.
 762         String classKey = CLASS_SPECIFIC_MAP.get(key);
 763         if (classKey != null) {
 764             Object value = getClassSpecificValue(classKey);
 765             if (value != null) {
 766                 return value;
 767             }
 768         }
 769 
 770         // Is it a specific value ?


 826             }
 827             // For all other kinds of arrow buttons (e.g. combobox arrow
 828             // buttons), we will simply fall back on the value of
 829             // ArrowButton.size as defined in the UIDefaults for
 830             // GTKLookAndFeel when we call UIManager.get() below...
 831         }
 832         else if ("CheckBox.iconTextGap".equals(key) ||
 833                  "RadioButton.iconTextGap".equals(key))
 834         {
 835             // The iconTextGap value needs to include "indicator-spacing"
 836             // and it also needs to leave enough space for the focus line,
 837             // which falls between the indicator icon and the text.
 838             // See getRadioInsets() and 6489585 for more details.
 839             int indicatorSpacing =
 840                 getClassSpecificIntValue(context, "indicator-spacing", 2);
 841             int focusSize =
 842                 getClassSpecificIntValue(context, "focus-line-width", 1);
 843             int focusPad =
 844                 getClassSpecificIntValue(context, "focus-padding", 1);
 845             return indicatorSpacing + focusSize + focusPad;
 846         } else if (GTKLookAndFeel.is3() && "ComboBox.forceOpaque".equals(key)) {
 847             return true;
 848         } else if ("Tree.expanderSize".equals(key)) {
 849             Object value = getClassSpecificValue("expander-size");
 850             if (value instanceof Integer) {
 851                 return (Integer)value + 4;
 852             }
 853             return null;
 854         }
 855 
 856         // Is it a stock icon ?
 857         GTKStockIcon stockIcon = null;
 858         synchronized (ICONS_MAP) {
 859             stockIcon = ICONS_MAP.get(key);
 860         }
 861 
 862         if (stockIcon != null) {
 863             return stockIcon;
 864         }
 865 
 866         // Is it another kind of value ?
 867         if (key != "engine") {
 868             // For backward compatibility we'll fallback to the UIManager.
 869             // We don't go to the UIManager for engine as the engine is GTK
 870             // specific.
 871             Object value = UIManager.get(key);
 872             if (key == "Table.rowHeight") {
 873                 int focusLineWidth = getClassSpecificIntValue(context,


1113 
1114                 if (methodName == null) {
1115                     return c.newInstance();
1116                 }
1117                 Method m = c.getMethod(methodName, (Class[])null);
1118 
1119                 return m.invoke(c, (Object[])null);
1120             } catch (ClassNotFoundException cnfe) {
1121             } catch (IllegalAccessException iae) {
1122             } catch (InvocationTargetException ite) {
1123             } catch (NoSuchMethodException nsme) {
1124             } catch (InstantiationException ie) {
1125             }
1126             return null;
1127         }
1128     }
1129 
1130     static {
1131         CLASS_SPECIFIC_MAP = new HashMap<String,String>();
1132         CLASS_SPECIFIC_MAP.put("Slider.thumbHeight", "slider-width");
1133         CLASS_SPECIFIC_MAP.put("Slider.thumbWidth", "slider-length");
1134         CLASS_SPECIFIC_MAP.put("Slider.trackBorder", "trough-border");
1135         CLASS_SPECIFIC_MAP.put("SplitPane.size", "handle-size");

1136         CLASS_SPECIFIC_MAP.put("ScrollBar.thumbHeight", "slider-width");
1137         CLASS_SPECIFIC_MAP.put("ScrollBar.width", "slider-width");
1138         CLASS_SPECIFIC_MAP.put("TextArea.caretForeground", "cursor-color");
1139         CLASS_SPECIFIC_MAP.put("TextArea.caretAspectRatio", "cursor-aspect-ratio");
1140         CLASS_SPECIFIC_MAP.put("TextField.caretForeground", "cursor-color");
1141         CLASS_SPECIFIC_MAP.put("TextField.caretAspectRatio", "cursor-aspect-ratio");
1142         CLASS_SPECIFIC_MAP.put("PasswordField.caretForeground", "cursor-color");
1143         CLASS_SPECIFIC_MAP.put("PasswordField.caretAspectRatio", "cursor-aspect-ratio");
1144         CLASS_SPECIFIC_MAP.put("FormattedTextField.caretForeground", "cursor-color");
1145         CLASS_SPECIFIC_MAP.put("FormattedTextField.caretAspectRatio", "cursor-aspect-");
1146         CLASS_SPECIFIC_MAP.put("TextPane.caretForeground", "cursor-color");
1147         CLASS_SPECIFIC_MAP.put("TextPane.caretAspectRatio", "cursor-aspect-ratio");
1148         CLASS_SPECIFIC_MAP.put("EditorPane.caretForeground", "cursor-color");
1149         CLASS_SPECIFIC_MAP.put("EditorPane.caretAspectRatio", "cursor-aspect-ratio");
1150 
1151         ICONS_MAP = new HashMap<String, GTKStockIcon>();
1152         ICONS_MAP.put("FileChooser.cancelIcon", new GTKStockIcon("gtk-cancel", 4));
1153         ICONS_MAP.put("FileChooser.okIcon",     new GTKStockIcon("gtk-ok",     4));
1154         ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("gtk-dialog-error", 6));
1155         ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("gtk-dialog-info", 6));
< prev index next >