< prev index next >

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

Print this page




  39 /**
  40  * A Windows L&amp;F implementation of LabelUI.  This implementation
  41  * is completely static, i.e. there's only one UIView implementation
  42  * that's shared by all JLabel objects.
  43  *
  44  * @author Hans Muller
  45  */
  46 
  47 public class MetalLabelUI extends BasicLabelUI
  48 {
  49    /**
  50     * The default <code>MetalLabelUI</code> instance. This field might
  51     * not be used. To change the default instance use a subclass which
  52     * overrides the <code>createUI</code> method, and place that class
  53     * name in defaults table under the key "LabelUI".
  54     */
  55     protected static MetalLabelUI metalLabelUI = new MetalLabelUI();
  56 
  57     private static final Object METAL_LABEL_UI_KEY = new Object();
  58 


  59     /**
  60      * Returns an instance of {@code MetalLabelUI}.
  61      *
  62      * @param c a component
  63      * @return an instance of {@code MetalLabelUI}
  64      */
  65     public static ComponentUI createUI(JComponent c) {
  66         if (System.getSecurityManager() != null) {
  67             AppContext appContext = AppContext.getAppContext();
  68             MetalLabelUI safeMetalLabelUI =
  69                     (MetalLabelUI) appContext.get(METAL_LABEL_UI_KEY);
  70             if (safeMetalLabelUI == null) {
  71                 safeMetalLabelUI = new MetalLabelUI();
  72                 appContext.put(METAL_LABEL_UI_KEY, safeMetalLabelUI);
  73             }
  74             return safeMetalLabelUI;
  75         }
  76         return metalLabelUI;
  77     }
  78 















  79     /**
  80      * Just paint the text gray (Label.disabledForeground) rather than
  81      * in the labels foreground color.
  82      *
  83      * @see #paint
  84      * @see #paintEnabledText
  85      */
  86     protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
  87     {
  88         int mnemIndex = l.getDisplayedMnemonicIndex();
  89         g.setColor(UIManager.getColor("Label.disabledForeground"));
  90         SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
  91                                                    textX, textY);
  92     }
  93 }


  39 /**
  40  * A Windows L&amp;F implementation of LabelUI.  This implementation
  41  * is completely static, i.e. there's only one UIView implementation
  42  * that's shared by all JLabel objects.
  43  *
  44  * @author Hans Muller
  45  */
  46 
  47 public class MetalLabelUI extends BasicLabelUI
  48 {
  49    /**
  50     * The default <code>MetalLabelUI</code> instance. This field might
  51     * not be used. To change the default instance use a subclass which
  52     * overrides the <code>createUI</code> method, and place that class
  53     * name in defaults table under the key "LabelUI".
  54     */
  55     protected static MetalLabelUI metalLabelUI = new MetalLabelUI();
  56 
  57     private static final Object METAL_LABEL_UI_KEY = new Object();
  58 
  59     private TextUIDrawing textUIDrawing;
  60 
  61     /**
  62      * Returns an instance of {@code MetalLabelUI}.
  63      *
  64      * @param c a component
  65      * @return an instance of {@code MetalLabelUI}
  66      */
  67     public static ComponentUI createUI(JComponent c) {
  68         if (System.getSecurityManager() != null) {
  69             AppContext appContext = AppContext.getAppContext();
  70             MetalLabelUI safeMetalLabelUI =
  71                     (MetalLabelUI) appContext.get(METAL_LABEL_UI_KEY);
  72             if (safeMetalLabelUI == null) {
  73                 safeMetalLabelUI = new MetalLabelUI();
  74                 appContext.put(METAL_LABEL_UI_KEY, safeMetalLabelUI);
  75             }
  76             return safeMetalLabelUI;
  77         }
  78         return metalLabelUI;
  79     }
  80 
  81     @Override
  82     protected void installDefaults(JLabel c) {
  83         super.installDefaults(c);
  84         textUIDrawing = SwingUtilities2.getTextUIDrawing(textUIDrawing);
  85     }
  86 
  87     @Override
  88     protected void uninstallDefaults(JLabel c) {
  89         super.uninstallDefaults(c);
  90         if (textUIDrawing != SwingUtilities2.DEFAULT_UI_TEXT_DRAWING
  91                 && textUIDrawing instanceof UIResource) {
  92             textUIDrawing = SwingUtilities2.DEFAULT_UI_TEXT_DRAWING;
  93         }
  94     }
  95 
  96     /**
  97      * Just paint the text gray (Label.disabledForeground) rather than
  98      * in the labels foreground color.
  99      *
 100      * @see #paint
 101      * @see #paintEnabledText
 102      */
 103     protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
 104     {
 105         int mnemIndex = l.getDisplayedMnemonicIndex();
 106         g.setColor(UIManager.getColor("Label.disabledForeground"));
 107         textUIDrawing.drawStringUnderlineCharAt(l, g, s, mnemIndex,
 108                                                    textX, textY);
 109     }
 110 }
< prev index next >