2
|
1 |
/*
|
|
2 |
* Copyright 2002-2007 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package sun.awt.X11;
|
|
26 |
|
|
27 |
import java.awt.*;
|
|
28 |
import java.awt.peer.*;
|
|
29 |
|
|
30 |
import java.lang.reflect.Field;
|
|
31 |
import java.util.Vector;
|
|
32 |
import java.util.logging.*;
|
|
33 |
import sun.awt.SunToolkit;
|
|
34 |
|
|
35 |
public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
|
36 |
|
|
37 |
/************************************************
|
|
38 |
*
|
|
39 |
* Data members
|
|
40 |
*
|
|
41 |
************************************************/
|
|
42 |
private static Logger log = Logger.getLogger("sun.awt.X11.XMenuPeer");
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Window that correspond to this menu
|
|
46 |
*/
|
|
47 |
XMenuWindow menuWindow;
|
|
48 |
|
|
49 |
|
|
50 |
/*
|
|
51 |
* Menu's fields & methods
|
|
52 |
*/
|
|
53 |
private final static Field f_items;
|
|
54 |
|
|
55 |
static {
|
|
56 |
f_items = SunToolkit.getField(Menu.class, "items");
|
|
57 |
}
|
|
58 |
|
|
59 |
/************************************************
|
|
60 |
*
|
|
61 |
* Construction
|
|
62 |
*
|
|
63 |
************************************************/
|
|
64 |
XMenuPeer(Menu target) {
|
|
65 |
super(target);
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* This function is called when menu is bound
|
|
70 |
* to its container window. Creates submenu window
|
|
71 |
* that fills its items vector while construction
|
|
72 |
*/
|
|
73 |
void setContainer(XBaseMenuWindow container) {
|
|
74 |
super.setContainer(container);
|
|
75 |
menuWindow = new XMenuWindow(this);
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
/************************************************
|
|
80 |
*
|
|
81 |
* Implementaion of interface methods
|
|
82 |
*
|
|
83 |
************************************************/
|
|
84 |
|
|
85 |
/*
|
|
86 |
* From MenuComponentPeer
|
|
87 |
*/
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Disposes menu window if needed
|
|
91 |
*/
|
|
92 |
public void dispose() {
|
|
93 |
if (menuWindow != null) {
|
|
94 |
menuWindow.dispose();
|
|
95 |
}
|
|
96 |
super.dispose();
|
|
97 |
}
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Resets text metrics for this item, for its menu window
|
|
101 |
* and for all descendant menu windows
|
|
102 |
*/
|
|
103 |
public void setFont(Font font) {
|
|
104 |
//TODO:We can decrease count of repaints here
|
|
105 |
//and get rid of recursion
|
|
106 |
resetTextMetrics();
|
|
107 |
|
|
108 |
XMenuWindow menuWindow = getMenuWindow();
|
|
109 |
if (menuWindow != null) {
|
|
110 |
menuWindow.setItemsFont(font);
|
|
111 |
}
|
|
112 |
|
|
113 |
repaintIfShowing();
|
|
114 |
}
|
|
115 |
|
|
116 |
/*
|
|
117 |
* From MenuPeer
|
|
118 |
*/
|
|
119 |
/**
|
|
120 |
* addSeparator routines are not used
|
|
121 |
* in peers. Shared code invokes addItem("-")
|
|
122 |
* for adding separators
|
|
123 |
*/
|
|
124 |
public void addSeparator() {
|
|
125 |
if (log.isLoggable(Level.FINER)) log.finer("addSeparator is not implemented");
|
|
126 |
}
|
|
127 |
|
|
128 |
public void addItem(MenuItem item) {
|
|
129 |
XMenuWindow menuWindow = getMenuWindow();
|
|
130 |
if (menuWindow != null) {
|
|
131 |
menuWindow.addItem(item);
|
|
132 |
} else {
|
|
133 |
if (log.isLoggable(Level.FINE)) {
|
|
134 |
log.fine("Attempt to use XMenuWindowPeer without window");
|
|
135 |
}
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
public void delItem(int index) {
|
|
140 |
XMenuWindow menuWindow = getMenuWindow();
|
|
141 |
if (menuWindow != null) {
|
|
142 |
menuWindow.delItem(index);
|
|
143 |
} else {
|
|
144 |
if (log.isLoggable(Level.FINE)) {
|
|
145 |
log.fine("Attempt to use XMenuWindowPeer without window");
|
|
146 |
}
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
/************************************************
|
|
151 |
*
|
|
152 |
* Access to target's fields
|
|
153 |
*
|
|
154 |
************************************************/
|
|
155 |
Vector getTargetItems() {
|
|
156 |
try {
|
|
157 |
return (Vector)f_items.get(getTarget());
|
|
158 |
} catch (IllegalAccessException iae) {
|
|
159 |
iae.printStackTrace();
|
|
160 |
return null;
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
/************************************************
|
|
165 |
*
|
|
166 |
* Overriden behaviour
|
|
167 |
*
|
|
168 |
************************************************/
|
|
169 |
boolean isSeparator() {
|
|
170 |
return false;
|
|
171 |
}
|
|
172 |
|
|
173 |
//Fix for 6180416: Shortcut keys are displayed against Menus on XToolkit
|
|
174 |
//Menu should always return null as shortcutText
|
|
175 |
String getShortcutText() {
|
|
176 |
return null;
|
|
177 |
}
|
|
178 |
|
|
179 |
/************************************************
|
|
180 |
*
|
|
181 |
* Utility functions
|
|
182 |
*
|
|
183 |
************************************************/
|
|
184 |
|
|
185 |
/**
|
|
186 |
* Returns menu window of this menu or null
|
|
187 |
* it this menu has no container and so its
|
|
188 |
* window can't be created.
|
|
189 |
*/
|
|
190 |
XMenuWindow getMenuWindow() {
|
|
191 |
return menuWindow;
|
|
192 |
}
|
|
193 |
|
|
194 |
}
|