author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5506 | 202f599c92aa |
child 13604 | 31089af1a447 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 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; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
32 |
import sun.util.logging.PlatformLogger; |
2 | 33 |
import sun.awt.SunToolkit; |
34 |
||
35 |
public class XMenuPeer extends XMenuItemPeer implements MenuPeer { |
|
36 |
||
37 |
/************************************************ |
|
38 |
* |
|
39 |
* Data members |
|
40 |
* |
|
41 |
************************************************/ |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
42 |
private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMenuPeer"); |
2 | 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() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
125 |
if (log.isLoggable(PlatformLogger.FINER)) log.finer("addSeparator is not implemented"); |
2 | 126 |
} |
127 |
||
128 |
public void addItem(MenuItem item) { |
|
129 |
XMenuWindow menuWindow = getMenuWindow(); |
|
130 |
if (menuWindow != null) { |
|
131 |
menuWindow.addItem(item); |
|
132 |
} else { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
133 |
if (log.isLoggable(PlatformLogger.FINE)) { |
2 | 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 { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
144 |
if (log.isLoggable(PlatformLogger.FINE)) { |
2 | 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 |
} |