2
* Copyright (c) 2001-2009 JGoodies Karsten Lentzsch. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of JGoodies Karsten Lentzsch nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
package com.jgoodies.looks.windows;
33
import java.awt.Color;
34
import java.awt.Dimension;
35
import java.awt.Graphics;
38
import javax.swing.plaf.ComponentUI;
39
import javax.swing.plaf.UIResource;
41
import com.jgoodies.looks.common.MenuItemRenderer;
44
* The JGoodies Windows XP look&feel implementation of <code>MenuUI</code>.<p>
46
* It differs from the superclass in that it uses an overhauled menu
47
* rendering an aligmnent system. Furthermore, you can set a client property
48
* <tt>Options.NO_ICONS_KEY</tt> to indicate that this menu has no icons.
50
* @author Karsten Lentzsch
51
* @version $Revision: 1.2 $
53
* @see com.jgoodies.looks.Options
56
public final class WindowsXPMenuUI extends com.sun.java.swing.plaf.windows.WindowsMenuUI {
58
private static final String MENU_PROPERTY_PREFIX = "Menu";
59
private static final String SUBMENU_PROPERTY_PREFIX = "MenuItem";
61
// May be changed to SUBMENU_PROPERTY_PREFIX later
62
private String propertyPrefix = MENU_PROPERTY_PREFIX;
64
private MenuItemRenderer renderer;
66
public static ComponentUI createUI(JComponent b) {
67
return new WindowsXPMenuUI();
70
// Install and Uninstall **************************************************
72
protected void installDefaults() {
73
super.installDefaults();
74
if (arrowIcon == null || arrowIcon instanceof UIResource) {
75
arrowIcon = UIManager.getIcon("Menu.arrowIcon");
84
acceleratorForeground,
85
acceleratorSelectionForeground);
87
(Integer) UIManager.get(getPropertyPrefix() + ".textIconGap");
88
defaultTextIconGap = gap != null ? gap.intValue() : 2;
91
protected void uninstallDefaults() {
92
super.uninstallDefaults();
96
protected String getPropertyPrefix() {
97
return propertyPrefix;
100
protected Dimension getPreferredMenuItemSize(
106
if (isSubMenu(menuItem)) {
107
ensureSubMenuInstalled();
108
return renderer.getPreferredMenuItemSize(
115
super.getPreferredMenuItemSize(
120
int width = size.width;
121
int height = size.height;
124
return new Dimension(width, height);
128
protected void paintMenuItem(
136
if (isSubMenu(menuItem)) {
137
renderer.paintMenuItem(
158
* Checks if we have already detected the correct menu type,
159
* menu in menu bar vs. sub menu; reinstalls if necessary.
161
private void ensureSubMenuInstalled() {
162
if (propertyPrefix.equals(SUBMENU_PROPERTY_PREFIX))
165
ButtonModel model = menuItem.getModel();
167
//save values of armed and selected properties.
168
//they will be resetted in #ununinstallDefaults().
169
boolean oldArmed = model.isArmed();
170
boolean oldSelected = model.isSelected();
173
propertyPrefix = SUBMENU_PROPERTY_PREFIX;
176
//restore values of armed and selected properties
177
model.setArmed(oldArmed);
178
model.setSelected(oldSelected);
182
// Helper Code **********************************************************
184
private boolean isSubMenu(JMenuItem aMenuItem) {
185
return !((JMenu) aMenuItem).isTopLevelMenu();
b'\\ No newline at end of file'