KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)WindowsCheckBoxMenuItemUI.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 /**
20  * Windows check box menu item.
21  * <p>
22  * <strong>Warning:</strong>
23  * Serialized objects of this class will not be compatible with
24  * future Swing releases. The current serialization support is appropriate
25  * for short term storage or RMI between applications running the same
26  * version of Swing. A future release of Swing will provide support for
27  * long term persistence.
28  */

29 public class WindowsCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
30
31     final WindowsMenuItemUIAccessor accessor =
32         new WindowsMenuItemUIAccessor() {
33
34             public JMenuItem getMenuItem() {
35                 return menuItem;
36             }
37
38             public State getState(JMenuItem menuItem) {
39                 return WindowsMenuItemUI.getState(this, menuItem);
40             }
41
42             public Part getPart(JMenuItem menuItem) {
43                 return WindowsMenuItemUI.getPart(this, menuItem);
44             }
45     };
46     public static ComponentUI createUI(JComponent b) {
47         return new WindowsCheckBoxMenuItemUI();
48     }
49     
50     @Override JavaDoc
51     protected void paintBackground(Graphics g, JMenuItem menuItem,
52             Color bgColor) {
53         if (WindowsMenuItemUI.isVistaPainting()) {
54             WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
55             return;
56         }
57         super.paintBackground(g, menuItem, bgColor);
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,
72                                         textRect, text);
73             return;
74         }
75         ButtonModel model = menuItem.getModel();
76         Color oldColor = g.getColor();
77
78         if(model.isEnabled() && model.isArmed()) {
79             g.setColor(selectionForeground); // Uses protected field.
80
}
81
82         WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
83
84         g.setColor(oldColor);
85     }
86 }
87
88
Popular Tags