< prev index next >

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

Print this page




  58 
  59     private static final Object METAL_RADIO_BUTTON_UI_KEY = new Object();
  60 
  61     /**
  62      * The color of the focused radio button.
  63      */
  64     protected Color focusColor;
  65 
  66     /**
  67      * The color of the selected radio button.
  68      */
  69     protected Color selectColor;
  70 
  71     /**
  72      * The color of a disabled text.
  73      */
  74     protected Color disabledTextColor;
  75 
  76     private boolean defaults_initialized = false;
  77 


  78     // ********************************
  79     //        Create PlAF
  80     // ********************************
  81 
  82     /**
  83      * Returns an instance of {@code MetalRadioButtonUI}.
  84      *
  85      * @param c a component
  86      * @return an instance of {@code MetalRadioButtonUI}
  87      */
  88     public static ComponentUI createUI(JComponent c) {
  89         AppContext appContext = AppContext.getAppContext();
  90         MetalRadioButtonUI metalRadioButtonUI =
  91                 (MetalRadioButtonUI) appContext.get(METAL_RADIO_BUTTON_UI_KEY);
  92         if (metalRadioButtonUI == null) {
  93             metalRadioButtonUI = new MetalRadioButtonUI();
  94             appContext.put(METAL_RADIO_BUTTON_UI_KEY, metalRadioButtonUI);
  95         }
  96         return metalRadioButtonUI;
  97     }
  98 
  99     // ********************************
 100     //        Install Defaults
 101     // ********************************
 102     public void installDefaults(AbstractButton b) {
 103         super.installDefaults(b);
 104         if(!defaults_initialized) {
 105             focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
 106             selectColor = UIManager.getColor(getPropertyPrefix() + "select");
 107             disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
 108             defaults_initialized = true;
 109         }
 110         LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);

 111     }
 112 
 113     protected void uninstallDefaults(AbstractButton b) {
 114         super.uninstallDefaults(b);
 115         defaults_initialized = false;




 116     }
 117 
 118     // ********************************
 119     //         Default Accessors
 120     // ********************************
 121 
 122     /**
 123      * Returns the color of the selected {@code JRadioButton}.
 124      *
 125      * @return the color of the selected {@code JRadioButton}
 126      */
 127     protected Color getSelectColor() {
 128         return selectColor;
 129     }
 130 
 131     /**
 132      * Returns the color of the disabled text.
 133      *
 134      * @return the color of the disabled text
 135      */


 227 
 228         } else {
 229             getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
 230         }
 231 
 232 
 233         // Draw the Text
 234         if(text != null) {
 235             View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 236             if (v != null) {
 237                 v.paint(g, textRect);
 238             } else {
 239                int mnemIndex = b.getDisplayedMnemonicIndex();
 240                if(model.isEnabled()) {
 241                    // *** paint the text normally
 242                    g.setColor(b.getForeground());
 243                } else {
 244                    // *** paint the text disabled
 245                    g.setColor(getDisabledTextColor());
 246                }
 247                SwingUtilities2.drawStringUnderlineCharAt(c,g,text,
 248                        mnemIndex, textRect.x, textRect.y + fm.getAscent());
 249            }
 250            if(b.hasFocus() && b.isFocusPainted() &&
 251               textRect.width > 0 && textRect.height > 0 ) {
 252                paintFocus(g,textRect,size);
 253            }
 254         }
 255     }
 256 
 257     protected void paintFocus(Graphics g, Rectangle t, Dimension d){
 258         g.setColor(getFocusColor());
 259         g.drawRect(t.x-1, t.y-1, t.width+1, t.height+1);
 260     }
 261 }


  58 
  59     private static final Object METAL_RADIO_BUTTON_UI_KEY = new Object();
  60 
  61     /**
  62      * The color of the focused radio button.
  63      */
  64     protected Color focusColor;
  65 
  66     /**
  67      * The color of the selected radio button.
  68      */
  69     protected Color selectColor;
  70 
  71     /**
  72      * The color of a disabled text.
  73      */
  74     protected Color disabledTextColor;
  75 
  76     private boolean defaults_initialized = false;
  77 
  78     private TextUIDrawing textUIDrawing;
  79 
  80     // ********************************
  81     //        Create PlAF
  82     // ********************************
  83 
  84     /**
  85      * Returns an instance of {@code MetalRadioButtonUI}.
  86      *
  87      * @param c a component
  88      * @return an instance of {@code MetalRadioButtonUI}
  89      */
  90     public static ComponentUI createUI(JComponent c) {
  91         AppContext appContext = AppContext.getAppContext();
  92         MetalRadioButtonUI metalRadioButtonUI =
  93                 (MetalRadioButtonUI) appContext.get(METAL_RADIO_BUTTON_UI_KEY);
  94         if (metalRadioButtonUI == null) {
  95             metalRadioButtonUI = new MetalRadioButtonUI();
  96             appContext.put(METAL_RADIO_BUTTON_UI_KEY, metalRadioButtonUI);
  97         }
  98         return metalRadioButtonUI;
  99     }
 100 
 101     // ********************************
 102     //        Install Defaults
 103     // ********************************
 104     public void installDefaults(AbstractButton b) {
 105         super.installDefaults(b);
 106         if(!defaults_initialized) {
 107             focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
 108             selectColor = UIManager.getColor(getPropertyPrefix() + "select");
 109             disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
 110             defaults_initialized = true;
 111         }
 112         LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
 113         textUIDrawing = SwingUtilities2.getTextUIDrawing(textUIDrawing);
 114     }
 115 
 116     protected void uninstallDefaults(AbstractButton b) {
 117         super.uninstallDefaults(b);
 118         defaults_initialized = false;
 119         if (textUIDrawing != SwingUtilities2.DEFAULT_UI_TEXT_DRAWING
 120                 && textUIDrawing instanceof UIResource) {
 121             textUIDrawing = SwingUtilities2.DEFAULT_UI_TEXT_DRAWING;
 122         }
 123     }
 124 
 125     // ********************************
 126     //         Default Accessors
 127     // ********************************
 128 
 129     /**
 130      * Returns the color of the selected {@code JRadioButton}.
 131      *
 132      * @return the color of the selected {@code JRadioButton}
 133      */
 134     protected Color getSelectColor() {
 135         return selectColor;
 136     }
 137 
 138     /**
 139      * Returns the color of the disabled text.
 140      *
 141      * @return the color of the disabled text
 142      */


 234 
 235         } else {
 236             getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
 237         }
 238 
 239 
 240         // Draw the Text
 241         if(text != null) {
 242             View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 243             if (v != null) {
 244                 v.paint(g, textRect);
 245             } else {
 246                int mnemIndex = b.getDisplayedMnemonicIndex();
 247                if(model.isEnabled()) {
 248                    // *** paint the text normally
 249                    g.setColor(b.getForeground());
 250                } else {
 251                    // *** paint the text disabled
 252                    g.setColor(getDisabledTextColor());
 253                }
 254                textUIDrawing.drawStringUnderlineCharAt(c,g,text,
 255                        mnemIndex, textRect.x, textRect.y + fm.getAscent());
 256            }
 257            if(b.hasFocus() && b.isFocusPainted() &&
 258               textRect.width > 0 && textRect.height > 0 ) {
 259                paintFocus(g,textRect,size);
 260            }
 261         }
 262     }
 263 
 264     protected void paintFocus(Graphics g, Rectangle t, Dimension d){
 265         g.setColor(getFocusColor());
 266         g.drawRect(t.x-1, t.y-1, t.width+1, t.height+1);
 267     }
 268 }
< prev index next >