< prev index next >

src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/XPStyle.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2014, 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


 110                     ThemeReader.isThemed() &&
 111                     !(UIManager.getLookAndFeel()
 112                       instanceof WindowsClassicLookAndFeel)) {
 113 
 114                     xp = new XPStyle();
 115                 }
 116             }
 117         }
 118         return ThemeReader.isXPStyleEnabled() ? xp : null;
 119     }
 120 
 121     static boolean isVista() {
 122         XPStyle xp = XPStyle.getXP();
 123         return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT));
 124     }
 125 
 126     /** Get a named <code>String</code> value from the current style
 127      *
 128      * @param part a <code>Part</code>
 129      * @param state a <code>String</code>
 130      * @param attributeKey a <code>String</code>
 131      * @return a <code>String</code> or null if key is not found
 132      *    in the current style
 133      *
 134      * This is currently only used by WindowsInternalFrameTitlePane for painting
 135      * title foregound and can be removed when no longer needed
 136      */
 137     String getString(Component c, Part part, State state, Prop prop) {
 138         return getTypeEnumName(c, part, state, prop);
 139     }
 140 
 141     TypeEnum getTypeEnum(Component c, Part part, State state, Prop prop) {
 142         int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
 143                                             State.getValue(part, state),
 144                                             prop.getValue());
 145         return TypeEnum.getTypeEnum(prop, enumValue);
 146     }
 147 
 148     private static String getTypeEnumName(Component c, Part part, State state, Prop prop) {
 149         int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
 150                                             State.getValue(part, state),


 155         return TypeEnum.getTypeEnum(prop, enumValue).getName();
 156     }
 157 
 158 
 159 
 160 
 161     /** Get a named <code>int</code> value from the current style
 162      *
 163      * @param part a <code>Part</code>
 164      * @return an <code>int</code> or null if key is not found
 165      *    in the current style
 166      */
 167     int getInt(Component c, Part part, State state, Prop prop, int fallback) {
 168         return ThemeReader.getInt(part.getControlName(c), part.getValue(),
 169                                   State.getValue(part, state),
 170                                   prop.getValue());
 171     }
 172 
 173     /** Get a named <code>Dimension</code> value from the current style
 174      *
 175      * @param key a <code>String</code>
 176      * @return a <code>Dimension</code> or null if key is not found
 177      *    in the current style
 178      *
 179      * This is currently only used by WindowsProgressBarUI and the value
 180      * should probably be cached there instead of here.
 181      */
 182     Dimension getDimension(Component c, Part part, State state, Prop prop) {
 183         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 184                                               State.getValue(part, state),
 185                                               prop.getValue());
 186         return (d != null) ? d : new Dimension();
 187     }
 188 
 189     /** Get a named <code>Point</code> (e.g. a location or an offset) value
 190      *  from the current style
 191      *
 192      * @param key a <code>String</code>
 193      * @return a <code>Point</code> or null if key is not found
 194      *    in the current style
 195      *
 196      * This is currently only used by WindowsInternalFrameTitlePane for painting
 197      * title foregound and can be removed when no longer needed
 198      */
 199     Point getPoint(Component c, Part part, State state, Prop prop) {
 200         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 201                                               State.getValue(part, state),
 202                                               prop.getValue());
 203         return (d != null) ? new Point(d.width, d.height) : new Point();
 204     }
 205 
 206     /** Get a named <code>Insets</code> value from the current style
 207      *
 208      * @param key a <code>String</code>
 209      * @return an <code>Insets</code> object or null if key is not found
 210      *    in the current style
 211      *
 212      * This is currently only used to create borders and by
 213      * WindowsInternalFrameTitlePane for painting title foregound.
 214      * The return value is already cached in those places.
 215      */
 216     Insets getMargin(Component c, Part part, State state, Prop prop) {
 217         Insets insets = ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
 218                                                     State.getValue(part, state),
 219                                                     prop.getValue());
 220         return (insets != null) ? insets : new Insets(0, 0, 0, 0);
 221     }
 222 
 223 
 224     /** Get a named <code>Color</code> value from the current style
 225      *
 226      * @param part a <code>Part</code>
 227      * @return a <code>Color</code> or null if key is not found
 228      *    in the current style
 229      */
 230     synchronized Color getColor(Skin skin, Prop prop, Color fallback) {
 231         String key = skin.toString() + "." + prop.name();
 232         Part part = skin.part;
 233         Color color = colorMap.get(key);
 234         if (color == null) {
 235             color = ThemeReader.getColor(part.getControlName(null), part.getValue(),
 236                                          State.getValue(part, skin.state),
 237                                          prop.getValue());
 238             if (color != null) {
 239                 color = new ColorUIResource(color);
 240                 colorMap.put(key, color);
 241             }
 242         }
 243         return (color != null) ? color : fallback;
 244     }
 245 
 246     Color getColor(Component c, Part part, State state, Prop prop, Color fallback) {


   1 /*
   2  * Copyright (c) 2002, 2017, 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


 110                     ThemeReader.isThemed() &&
 111                     !(UIManager.getLookAndFeel()
 112                       instanceof WindowsClassicLookAndFeel)) {
 113 
 114                     xp = new XPStyle();
 115                 }
 116             }
 117         }
 118         return ThemeReader.isXPStyleEnabled() ? xp : null;
 119     }
 120 
 121     static boolean isVista() {
 122         XPStyle xp = XPStyle.getXP();
 123         return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT));
 124     }
 125 
 126     /** Get a named <code>String</code> value from the current style
 127      *
 128      * @param part a <code>Part</code>
 129      * @param state a <code>String</code>
 130      * @param prop a <code>String</code>
 131      * @return a <code>String</code> or null if key is not found
 132      *    in the current style
 133      *
 134      * This is currently only used by WindowsInternalFrameTitlePane for painting
 135      * title foregound and can be removed when no longer needed
 136      */
 137     String getString(Component c, Part part, State state, Prop prop) {
 138         return getTypeEnumName(c, part, state, prop);
 139     }
 140 
 141     TypeEnum getTypeEnum(Component c, Part part, State state, Prop prop) {
 142         int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
 143                                             State.getValue(part, state),
 144                                             prop.getValue());
 145         return TypeEnum.getTypeEnum(prop, enumValue);
 146     }
 147 
 148     private static String getTypeEnumName(Component c, Part part, State state, Prop prop) {
 149         int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
 150                                             State.getValue(part, state),


 155         return TypeEnum.getTypeEnum(prop, enumValue).getName();
 156     }
 157 
 158 
 159 
 160 
 161     /** Get a named <code>int</code> value from the current style
 162      *
 163      * @param part a <code>Part</code>
 164      * @return an <code>int</code> or null if key is not found
 165      *    in the current style
 166      */
 167     int getInt(Component c, Part part, State state, Prop prop, int fallback) {
 168         return ThemeReader.getInt(part.getControlName(c), part.getValue(),
 169                                   State.getValue(part, state),
 170                                   prop.getValue());
 171     }
 172 
 173     /** Get a named <code>Dimension</code> value from the current style
 174      *

 175      * @return a <code>Dimension</code> or null if key is not found
 176      *    in the current style
 177      *
 178      * This is currently only used by WindowsProgressBarUI and the value
 179      * should probably be cached there instead of here.
 180      */
 181     Dimension getDimension(Component c, Part part, State state, Prop prop) {
 182         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 183                                               State.getValue(part, state),
 184                                               prop.getValue());
 185         return (d != null) ? d : new Dimension();
 186     }
 187 
 188     /** Get a named <code>Point</code> (e.g. a location or an offset) value
 189      *  from the current style
 190      *

 191      * @return a <code>Point</code> or null if key is not found
 192      *    in the current style
 193      *
 194      * This is currently only used by WindowsInternalFrameTitlePane for painting
 195      * title foregound and can be removed when no longer needed
 196      */
 197     Point getPoint(Component c, Part part, State state, Prop prop) {
 198         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 199                                               State.getValue(part, state),
 200                                               prop.getValue());
 201         return (d != null) ? new Point(d.width, d.height) : new Point();
 202     }
 203 
 204     /** Get a named <code>Insets</code> value from the current style
 205      *

 206      * @return an <code>Insets</code> object or null if key is not found
 207      *    in the current style
 208      *
 209      * This is currently only used to create borders and by
 210      * WindowsInternalFrameTitlePane for painting title foregound.
 211      * The return value is already cached in those places.
 212      */
 213     Insets getMargin(Component c, Part part, State state, Prop prop) {
 214         Insets insets = ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
 215                                                     State.getValue(part, state),
 216                                                     prop.getValue());
 217         return (insets != null) ? insets : new Insets(0, 0, 0, 0);
 218     }
 219 
 220 
 221     /** Get a named <code>Color</code> value from the current style
 222      *

 223      * @return a <code>Color</code> or null if key is not found
 224      *    in the current style
 225      */
 226     synchronized Color getColor(Skin skin, Prop prop, Color fallback) {
 227         String key = skin.toString() + "." + prop.name();
 228         Part part = skin.part;
 229         Color color = colorMap.get(key);
 230         if (color == null) {
 231             color = ThemeReader.getColor(part.getControlName(null), part.getValue(),
 232                                          State.getValue(part, skin.state),
 233                                          prop.getValue());
 234             if (color != null) {
 235                 color = new ColorUIResource(color);
 236                 colorMap.put(key, color);
 237             }
 238         }
 239         return (color != null) ? color : fallback;
 240     }
 241 
 242     Color getColor(Component c, Part part, State state, Prop prop, Color fallback) {


< prev index next >