KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > WindowsRadioButtonMenuItemUI


1 /*
2  * @(#)WindowsRadioButtonMenuItemUI.java 1.17 07/01/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.windows;
9
10 import java.awt.*;
11 import javax.swing.*;
12 import javax.swing.plaf.*;
13 import javax.swing.plaf.basic.*;
14
15 import com.sun.java.swing.plaf.windows.TMSchema.Part;
16 import com.sun.java.swing.plaf.windows.TMSchema.State;
17
18 /**
19  * Windows rendition of the component.
20  * <p>
21  * <strong>Warning:</strong>
22  * Serialized objects of this class will not be compatible with
23  * future Swing releases. The current serialization support is appropriate
24  * for short term storage or RMI between applications running the same
25  * version of Swing. A future release of Swing will provide support for
26  * long term persistence.
27  */

28 public class WindowsRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI {
29
30     final WindowsMenuItemUIAccessor accessor =
31         new WindowsMenuItemUIAccessor() {
32
33            public JMenuItem getMenuItem() {
34                return menuItem;
35            }
36
37            public State getState(JMenuItem menuItem) {
38                return WindowsMenuItemUI.getState(this, menuItem);
39            }
40            
41            public Part getPart(JMenuItem menuItem) {
42                return WindowsMenuItemUI.getPart(this, menuItem);
43            }
44     };
45     public static ComponentUI createUI(JComponent b) {
46         return new WindowsRadioButtonMenuItemUI();
47     }
48
49     @Override JavaDoc
50     protected void paintBackground(Graphics g, JMenuItem menuItem,
51             Color bgColor) {
52         if (WindowsMenuItemUI.isVistaPainting()) {
53             WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
54             return;
55         }
56         super.paintBackground(g, menuItem, bgColor);
57     }
58
59     /**
60      * Method which renders the text of the current menu item.
61      * <p>
62      * @param g Graphics context
63      * @param menuItem Current menu item to render
64      * @param textRect Bounding rectangle to render the text.
65      * @param text String to render
66      * @since 1.4
67      */

68     protected void paintText(Graphics g, JMenuItem menuItem,
69             Rectangle textRect, String JavaDoc text) {
70         if (WindowsMenuItemUI.isVistaPainting()) {
71             WindowsMenuItemUI.paintText(accessor, g, menuItem, textRect, text);
72             return;
73         }
74         ButtonModel model = menuItem.getModel();
75         Color oldColor = g.getColor();
76
77         if(model.isEnabled() && model.isArmed()) {
78             g.setColor(selectionForeground); // Uses protected field.
79
}
80
81         WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
82
83         g.setColor(oldColor);
84     }
85 }
86
87
Popular Tags