< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java

Print this page




  32 import sun.awt.AppContext;
  33 import sun.security.action.GetPropertyAction;
  34 import sun.swing.SwingUtilities2;
  35 
  36 /**
  37  * A concrete implementation of {@code MetalTheme} providing
  38  * the original look of the Java Look and Feel, code-named "Steel". Refer
  39  * to {@link MetalLookAndFeel#setCurrentTheme} for details on changing
  40  * the default theme.
  41  * <p>
  42  * All colors returned by {@code DefaultMetalTheme} are completely
  43  * opaque.
  44  *
  45  * <h3><a name="fontStyle"></a>Font Style</h3>
  46  *
  47  * {@code DefaultMetalTheme} uses bold fonts for many controls.  To make all
  48  * controls (with the exception of the internal frame title bars and
  49  * client decorated frame title bars) use plain fonts you can do either of
  50  * the following:
  51  * <ul>
  52  * <li>Set the system property <code>swing.boldMetal</code> to
  53  *     <code>false</code>.  For example,
  54  *     <code>java&nbsp;-Dswing.boldMetal=false&nbsp;MyApp</code>.
  55  * <li>Set the defaults property <code>swing.boldMetal</code> to
  56  *     <code>Boolean.FALSE</code>.  For example:
  57  *     <code>UIManager.put("swing.boldMetal",&nbsp;Boolean.FALSE);</code>
  58  * </ul>
  59  * The defaults property <code>swing.boldMetal</code>, if set,
  60  * takes precedence over the system property of the same name. After
  61  * setting this defaults property you need to re-install
  62  * <code>MetalLookAndFeel</code>, as well as update the UI
  63  * of any previously created widgets. Otherwise the results are undefined.
  64  * The following illustrates how to do this:
  65  * <pre>
  66  *   // turn off bold fonts
  67  *   UIManager.put("swing.boldMetal", Boolean.FALSE);
  68  *
  69  *   // re-install the Metal Look and Feel
  70  *   UIManager.setLookAndFeel(new MetalLookAndFeel());
  71  *
  72  *   // Update the ComponentUIs for all Components. This
  73  *   // needs to be invoked for all windows.
  74  *   SwingUtilities.updateComponentTreeUI(rootComponent);
  75  * </pre>
  76  * <p>
  77  * <strong>Warning:</strong>
  78  * Serialized objects of this class will not be compatible with
  79  * future Swing releases. The current serialization support is
  80  * appropriate for short term storage or RMI between applications running
  81  * the same version of Swing.  As of 1.4, support for long term storage
  82  * of all JavaBeans&trade;
  83  * has been added to the <code>java.beans</code> package.
  84  * Please see {@link java.beans.XMLEncoder}.
  85  *
  86  * @see MetalLookAndFeel
  87  * @see MetalLookAndFeel#setCurrentTheme
  88  *
  89  * @author Steve Wilson
  90  */
  91 @SuppressWarnings("serial") // Same-version serialization only
  92 public class DefaultMetalTheme extends MetalTheme {
  93     /**
  94      * Whether or not fonts should be plain.  This is only used if
  95      * the defaults property 'swing.boldMetal' == "false".
  96      */
  97     private static final boolean PLAIN_FONTS;
  98 
  99     /**
 100      * Names of the fonts to use.
 101      */
 102     private static final String[] fontNames = {
 103         Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG
 104     };
 105     /**
 106      * Styles for the fonts.  This is ignored if the defaults property
 107      * <code>swing.boldMetal</code> is false, or PLAIN_FONTS is true.
 108      */
 109     private static final int[] fontStyles = {
 110         Font.BOLD, Font.PLAIN, Font.PLAIN, Font.BOLD, Font.BOLD, Font.PLAIN
 111     };
 112     /**
 113      * Sizes for the fonts.
 114      */
 115     private static final int[] fontSizes = {
 116         12, 12, 12, 12, 12, 10
 117     };
 118 
 119     // note the properties listed here can currently be used by people
 120     // providing runtimes to hint what fonts are good.  For example the bold
 121     // dialog font looks bad on a Mac, so Apple could use this property to
 122     // hint at a good font.
 123     //
 124     // However, we don't promise to support these forever.  We may move
 125     // to getting these from the swing.properties file, or elsewhere.
 126     /**
 127      * System property names used to look up fonts.


 367             fonts = new FontUIResource[6];
 368         }
 369 
 370         public FontUIResource getFont(int type) {
 371             int mappedType = defaultMapping[type];
 372             if (fonts[type] == null) {
 373                 Font f = getPrivilegedFont(mappedType);
 374 
 375                 if (f == null) {
 376                     f = new Font(getDefaultFontName(type),
 377                              getDefaultFontStyle(type),
 378                              getDefaultFontSize(type));
 379                 }
 380                 fonts[type] = new FontUIResource(f);
 381             }
 382             return fonts[type];
 383         }
 384 
 385         /**
 386          * This is the same as invoking
 387          * <code>Font.getFont(key)</code>, with the exception
 388          * that it is wrapped inside a <code>doPrivileged</code> call.
 389          */
 390         protected Font getPrivilegedFont(final int key) {
 391             return java.security.AccessController.doPrivileged(
 392                 new java.security.PrivilegedAction<Font>() {
 393                     public Font run() {
 394                         return Font.getFont(getDefaultPropertyName(key));
 395                     }
 396                 }
 397                 );
 398         }
 399     }
 400 
 401     /**
 402      * The WindowsFontDelegate uses DesktopProperties to obtain fonts.
 403      */
 404     private static class WindowsFontDelegate extends FontDelegate {
 405         private MetalFontDesktopProperty[] props;
 406         private boolean[] checkedPriviledged;
 407 
 408         public WindowsFontDelegate() {




  32 import sun.awt.AppContext;
  33 import sun.security.action.GetPropertyAction;
  34 import sun.swing.SwingUtilities2;
  35 
  36 /**
  37  * A concrete implementation of {@code MetalTheme} providing
  38  * the original look of the Java Look and Feel, code-named "Steel". Refer
  39  * to {@link MetalLookAndFeel#setCurrentTheme} for details on changing
  40  * the default theme.
  41  * <p>
  42  * All colors returned by {@code DefaultMetalTheme} are completely
  43  * opaque.
  44  *
  45  * <h3><a name="fontStyle"></a>Font Style</h3>
  46  *
  47  * {@code DefaultMetalTheme} uses bold fonts for many controls.  To make all
  48  * controls (with the exception of the internal frame title bars and
  49  * client decorated frame title bars) use plain fonts you can do either of
  50  * the following:
  51  * <ul>
  52  * <li>Set the system property {@code swing.boldMetal} to
  53  *     {@code false}.  For example,
  54  *     <code>java&nbsp;-Dswing.boldMetal=false&nbsp;MyApp</code>.
  55  * <li>Set the defaults property {@code swing.boldMetal} to
  56  *     {@code Boolean.FALSE}.  For example:
  57  *     <code>UIManager.put("swing.boldMetal",&nbsp;Boolean.FALSE);</code>
  58  * </ul>
  59  * The defaults property {@code swing.boldMetal}, if set,
  60  * takes precedence over the system property of the same name. After
  61  * setting this defaults property you need to re-install
  62  * {@code MetalLookAndFeel}, as well as update the UI
  63  * of any previously created widgets. Otherwise the results are undefined.
  64  * The following illustrates how to do this:
  65  * <pre>
  66  *   // turn off bold fonts
  67  *   UIManager.put("swing.boldMetal", Boolean.FALSE);
  68  *
  69  *   // re-install the Metal Look and Feel
  70  *   UIManager.setLookAndFeel(new MetalLookAndFeel());
  71  *
  72  *   // Update the ComponentUIs for all Components. This
  73  *   // needs to be invoked for all windows.
  74  *   SwingUtilities.updateComponentTreeUI(rootComponent);
  75  * </pre>
  76  * <p>
  77  * <strong>Warning:</strong>
  78  * Serialized objects of this class will not be compatible with
  79  * future Swing releases. The current serialization support is
  80  * appropriate for short term storage or RMI between applications running
  81  * the same version of Swing.  As of 1.4, support for long term storage
  82  * of all JavaBeans&trade;
  83  * has been added to the {@code java.beans} package.
  84  * Please see {@link java.beans.XMLEncoder}.
  85  *
  86  * @see MetalLookAndFeel
  87  * @see MetalLookAndFeel#setCurrentTheme
  88  *
  89  * @author Steve Wilson
  90  */
  91 @SuppressWarnings("serial") // Same-version serialization only
  92 public class DefaultMetalTheme extends MetalTheme {
  93     /**
  94      * Whether or not fonts should be plain.  This is only used if
  95      * the defaults property 'swing.boldMetal' == "false".
  96      */
  97     private static final boolean PLAIN_FONTS;
  98 
  99     /**
 100      * Names of the fonts to use.
 101      */
 102     private static final String[] fontNames = {
 103         Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG
 104     };
 105     /**
 106      * Styles for the fonts.  This is ignored if the defaults property
 107      * {@code swing.boldMetal} is false, or PLAIN_FONTS is true.
 108      */
 109     private static final int[] fontStyles = {
 110         Font.BOLD, Font.PLAIN, Font.PLAIN, Font.BOLD, Font.BOLD, Font.PLAIN
 111     };
 112     /**
 113      * Sizes for the fonts.
 114      */
 115     private static final int[] fontSizes = {
 116         12, 12, 12, 12, 12, 10
 117     };
 118 
 119     // note the properties listed here can currently be used by people
 120     // providing runtimes to hint what fonts are good.  For example the bold
 121     // dialog font looks bad on a Mac, so Apple could use this property to
 122     // hint at a good font.
 123     //
 124     // However, we don't promise to support these forever.  We may move
 125     // to getting these from the swing.properties file, or elsewhere.
 126     /**
 127      * System property names used to look up fonts.


 367             fonts = new FontUIResource[6];
 368         }
 369 
 370         public FontUIResource getFont(int type) {
 371             int mappedType = defaultMapping[type];
 372             if (fonts[type] == null) {
 373                 Font f = getPrivilegedFont(mappedType);
 374 
 375                 if (f == null) {
 376                     f = new Font(getDefaultFontName(type),
 377                              getDefaultFontStyle(type),
 378                              getDefaultFontSize(type));
 379                 }
 380                 fonts[type] = new FontUIResource(f);
 381             }
 382             return fonts[type];
 383         }
 384 
 385         /**
 386          * This is the same as invoking
 387          * {@code Font.getFont(key)}, with the exception
 388          * that it is wrapped inside a {@code doPrivileged} call.
 389          */
 390         protected Font getPrivilegedFont(final int key) {
 391             return java.security.AccessController.doPrivileged(
 392                 new java.security.PrivilegedAction<Font>() {
 393                     public Font run() {
 394                         return Font.getFont(getDefaultPropertyName(key));
 395                     }
 396                 }
 397                 );
 398         }
 399     }
 400 
 401     /**
 402      * The WindowsFontDelegate uses DesktopProperties to obtain fonts.
 403      */
 404     private static class WindowsFontDelegate extends FontDelegate {
 405         private MetalFontDesktopProperty[] props;
 406         private boolean[] checkedPriviledged;
 407 
 408         public WindowsFontDelegate() {


< prev index next >