1 /*
2 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
91 g.setColor(selectionForeground); // Uses protected field.
92 }
93
94 WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
95
96 g.setColor(oldColor);
97 }
98
99 @Override
100 protected void paintBackground(Graphics g, JMenuItem menuItem,
101 Color bgColor) {
102 if (WindowsMenuItemUI.isVistaPainting()) {
103 WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
104 return;
105 }
106 super.paintBackground(g, menuItem, bgColor);
107 }
108
109 static void paintBackground(WindowsMenuItemUIAccessor menuItemUI,
110 Graphics g, JMenuItem menuItem, Color bgColor) {
111 assert isVistaPainting();
112 if (isVistaPainting()) {
113 int menuWidth = menuItem.getWidth();
114 int menuHeight = menuItem.getHeight();
115 if (menuItem.isOpaque()) {
116 Color oldColor = g.getColor();
117 g.setColor(menuItem.getBackground());
118 g.fillRect(0,0, menuWidth, menuHeight);
119 g.setColor(oldColor);
120 }
121 XPStyle xp = XPStyle.getXP();
122 Part part = menuItemUI.getPart(menuItem);
123 Skin skin = xp.getSkin(menuItem, part);
124 skin.paintSkin(g, 0 , 0,
125 menuWidth,
126 menuHeight,
127 menuItemUI.getState(menuItem));
128 }
129 }
130
131 static void paintText(WindowsMenuItemUIAccessor menuItemUI, Graphics g,
132 JMenuItem menuItem, Rectangle textRect,
133 String text) {
134 assert isVistaPainting();
135 if (isVistaPainting()) {
136 State state = menuItemUI.getState(menuItem);
137
138 /* part of it copied from WindowsGraphicsUtils.java */
139 FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
140 int mnemIndex = menuItem.getDisplayedMnemonicIndex();
141 // W2K Feature: Check to see if the Underscore should be rendered.
153 static State getState(WindowsMenuItemUIAccessor menuItemUI, JMenuItem menuItem) {
154 State state;
155 ButtonModel model = menuItem.getModel();
156 if (model.isArmed()) {
157 state = (model.isEnabled()) ? State.HOT : State.DISABLEDHOT;
158 } else {
159 state = (model.isEnabled()) ? State.NORMAL : State.DISABLED;
160 }
161 return state;
162 }
163
164 static Part getPart(WindowsMenuItemUIAccessor menuItemUI, JMenuItem menuItem) {
165 return Part.MP_POPUPITEM;
166 }
167
168 /*
169 * TODO idk can we use XPStyle.isVista?
170 * is it possible that in some theme some Vista parts are not defined while
171 * others are?
172 */
173 static boolean isVistaPainting() {
174 XPStyle xp = XPStyle.getXP();
175 return xp != null && xp.isSkinDefined(null, Part.MP_POPUPITEM);
176 }
177 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
91 g.setColor(selectionForeground); // Uses protected field.
92 }
93
94 WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
95
96 g.setColor(oldColor);
97 }
98
99 @Override
100 protected void paintBackground(Graphics g, JMenuItem menuItem,
101 Color bgColor) {
102 if (WindowsMenuItemUI.isVistaPainting()) {
103 WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
104 return;
105 }
106 super.paintBackground(g, menuItem, bgColor);
107 }
108
109 static void paintBackground(WindowsMenuItemUIAccessor menuItemUI,
110 Graphics g, JMenuItem menuItem, Color bgColor) {
111 XPStyle xp = XPStyle.getXP();
112 assert isVistaPainting(xp);
113 if (isVistaPainting(xp)) {
114 int menuWidth = menuItem.getWidth();
115 int menuHeight = menuItem.getHeight();
116 if (menuItem.isOpaque()) {
117 Color oldColor = g.getColor();
118 g.setColor(menuItem.getBackground());
119 g.fillRect(0,0, menuWidth, menuHeight);
120 g.setColor(oldColor);
121 }
122 Part part = menuItemUI.getPart(menuItem);
123 Skin skin = xp.getSkin(menuItem, part);
124 skin.paintSkin(g, 0 , 0,
125 menuWidth,
126 menuHeight,
127 menuItemUI.getState(menuItem));
128 }
129 }
130
131 static void paintText(WindowsMenuItemUIAccessor menuItemUI, Graphics g,
132 JMenuItem menuItem, Rectangle textRect,
133 String text) {
134 assert isVistaPainting();
135 if (isVistaPainting()) {
136 State state = menuItemUI.getState(menuItem);
137
138 /* part of it copied from WindowsGraphicsUtils.java */
139 FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
140 int mnemIndex = menuItem.getDisplayedMnemonicIndex();
141 // W2K Feature: Check to see if the Underscore should be rendered.
153 static State getState(WindowsMenuItemUIAccessor menuItemUI, JMenuItem menuItem) {
154 State state;
155 ButtonModel model = menuItem.getModel();
156 if (model.isArmed()) {
157 state = (model.isEnabled()) ? State.HOT : State.DISABLEDHOT;
158 } else {
159 state = (model.isEnabled()) ? State.NORMAL : State.DISABLED;
160 }
161 return state;
162 }
163
164 static Part getPart(WindowsMenuItemUIAccessor menuItemUI, JMenuItem menuItem) {
165 return Part.MP_POPUPITEM;
166 }
167
168 /*
169 * TODO idk can we use XPStyle.isVista?
170 * is it possible that in some theme some Vista parts are not defined while
171 * others are?
172 */
173 static boolean isVistaPainting(final XPStyle xp) {
174 return xp != null && xp.isSkinDefined(null, Part.MP_POPUPITEM);
175 }
176
177 static boolean isVistaPainting() {
178 return isVistaPainting(XPStyle.getXP());
179 }
180 }
|