author | malenkov |
Wed, 30 Apr 2014 19:28:05 +0400 | |
changeset 24544 | c0133e7c7162 |
parent 23298 | 1c729daf92a0 |
child 25201 | 4adc75e0c4e5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
11268
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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 javax.swing; |
|
26 |
||
27 |
import java.awt.*; |
|
28 |
import java.util.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import javax.swing.event.*; |
|
31 |
||
32 |
import sun.awt.AppContext; |
|
23298 | 33 |
import sun.swing.SwingUtilities2; |
2 | 34 |
|
35 |
/** |
|
36 |
* A MenuSelectionManager owns the selection in menu hierarchy. |
|
37 |
* |
|
38 |
* @author Arnaud Weber |
|
39 |
*/ |
|
40 |
public class MenuSelectionManager { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
41 |
private Vector<MenuElement> selection = new Vector<MenuElement>(); |
2 | 42 |
|
43 |
/* diagnostic aids -- should be false for production builds. */ |
|
44 |
private static final boolean TRACE = false; // trace creates and disposes |
|
45 |
private static final boolean VERBOSE = false; // show reuse hits/misses |
|
46 |
private static final boolean DEBUG = false; // show bad params, misc. |
|
47 |
||
48 |
private static final StringBuilder MENU_SELECTION_MANAGER_KEY = |
|
49 |
new StringBuilder("javax.swing.MenuSelectionManager"); |
|
50 |
||
51 |
/** |
|
52 |
* Returns the default menu selection manager. |
|
53 |
* |
|
54 |
* @return a MenuSelectionManager object |
|
55 |
*/ |
|
56 |
public static MenuSelectionManager defaultManager() { |
|
57 |
synchronized (MENU_SELECTION_MANAGER_KEY) { |
|
58 |
AppContext context = AppContext.getAppContext(); |
|
59 |
MenuSelectionManager msm = (MenuSelectionManager)context.get( |
|
60 |
MENU_SELECTION_MANAGER_KEY); |
|
61 |
if (msm == null) { |
|
62 |
msm = new MenuSelectionManager(); |
|
63 |
context.put(MENU_SELECTION_MANAGER_KEY, msm); |
|
23298 | 64 |
|
65 |
// installing additional listener if found in the AppContext |
|
66 |
Object o = context.get(SwingUtilities2.MENU_SELECTION_MANAGER_LISTENER_KEY); |
|
67 |
if (o != null && o instanceof ChangeListener) { |
|
68 |
msm.addChangeListener((ChangeListener) o); |
|
69 |
} |
|
2 | 70 |
} |
71 |
||
72 |
return msm; |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* Only one ChangeEvent is needed per button model instance since the |
|
78 |
* event's only state is the source property. The source of events |
|
79 |
* generated is always "this". |
|
80 |
*/ |
|
81 |
protected transient ChangeEvent changeEvent = null; |
|
82 |
protected EventListenerList listenerList = new EventListenerList(); |
|
83 |
||
84 |
/** |
|
85 |
* Changes the selection in the menu hierarchy. The elements |
|
86 |
* in the array are sorted in order from the root menu |
|
87 |
* element to the currently selected menu element. |
|
88 |
* <p> |
|
89 |
* Note that this method is public but is used by the look and |
|
90 |
* feel engine and should not be called by client applications. |
|
91 |
* |
|
92 |
* @param path an array of <code>MenuElement</code> objects specifying |
|
93 |
* the selected path |
|
94 |
*/ |
|
95 |
public void setSelectedPath(MenuElement[] path) { |
|
96 |
int i,c; |
|
97 |
int currentSelectionCount = selection.size(); |
|
98 |
int firstDifference = 0; |
|
99 |
||
100 |
if(path == null) { |
|
101 |
path = new MenuElement[0]; |
|
102 |
} |
|
103 |
||
104 |
if (DEBUG) { |
|
105 |
System.out.print("Previous: "); printMenuElementArray(getSelectedPath()); |
|
106 |
System.out.print("New: "); printMenuElementArray(path); |
|
107 |
} |
|
108 |
||
109 |
for(i=0,c=path.length;i<c;i++) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
110 |
if (i < currentSelectionCount && selection.elementAt(i) == path[i]) |
2 | 111 |
firstDifference++; |
112 |
else |
|
113 |
break; |
|
114 |
} |
|
115 |
||
116 |
for(i=currentSelectionCount - 1 ; i >= firstDifference ; i--) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
117 |
MenuElement me = selection.elementAt(i); |
2 | 118 |
selection.removeElementAt(i); |
119 |
me.menuSelectionChanged(false); |
|
120 |
} |
|
121 |
||
122 |
for(i = firstDifference, c = path.length ; i < c ; i++) { |
|
123 |
if (path[i] != null) { |
|
124 |
selection.addElement(path[i]); |
|
125 |
path[i].menuSelectionChanged(true); |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
fireStateChanged(); |
|
130 |
} |
|
131 |
||
132 |
/** |
|
133 |
* Returns the path to the currently selected menu item |
|
134 |
* |
|
135 |
* @return an array of MenuElement objects representing the selected path |
|
136 |
*/ |
|
137 |
public MenuElement[] getSelectedPath() { |
|
138 |
MenuElement res[] = new MenuElement[selection.size()]; |
|
139 |
int i,c; |
|
140 |
for(i=0,c=selection.size();i<c;i++) |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
141 |
res[i] = selection.elementAt(i); |
2 | 142 |
return res; |
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Tell the menu selection to close and unselect all the menu components. Call this method |
|
147 |
* when a choice has been made |
|
148 |
*/ |
|
149 |
public void clearSelectedPath() { |
|
150 |
if (selection.size() > 0) { |
|
151 |
setSelectedPath(null); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* Adds a ChangeListener to the button. |
|
157 |
* |
|
158 |
* @param l the listener to add |
|
159 |
*/ |
|
160 |
public void addChangeListener(ChangeListener l) { |
|
161 |
listenerList.add(ChangeListener.class, l); |
|
162 |
} |
|
163 |
||
164 |
/** |
|
165 |
* Removes a ChangeListener from the button. |
|
166 |
* |
|
167 |
* @param l the listener to remove |
|
168 |
*/ |
|
169 |
public void removeChangeListener(ChangeListener l) { |
|
170 |
listenerList.remove(ChangeListener.class, l); |
|
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* Returns an array of all the <code>ChangeListener</code>s added |
|
175 |
* to this MenuSelectionManager with addChangeListener(). |
|
176 |
* |
|
177 |
* @return all of the <code>ChangeListener</code>s added or an empty |
|
178 |
* array if no listeners have been added |
|
179 |
* @since 1.4 |
|
180 |
*/ |
|
181 |
public ChangeListener[] getChangeListeners() { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
182 |
return listenerList.getListeners(ChangeListener.class); |
2 | 183 |
} |
184 |
||
185 |
/** |
|
186 |
* Notifies all listeners that have registered interest for |
|
187 |
* notification on this event type. The event instance |
|
188 |
* is created lazily. |
|
189 |
* |
|
190 |
* @see EventListenerList |
|
191 |
*/ |
|
192 |
protected void fireStateChanged() { |
|
193 |
// Guaranteed to return a non-null array |
|
194 |
Object[] listeners = listenerList.getListenerList(); |
|
195 |
// Process the listeners last to first, notifying |
|
196 |
// those that are interested in this event |
|
197 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
198 |
if (listeners[i]==ChangeListener.class) { |
|
199 |
// Lazily create the event: |
|
200 |
if (changeEvent == null) |
|
201 |
changeEvent = new ChangeEvent(this); |
|
202 |
((ChangeListener)listeners[i+1]).stateChanged(changeEvent); |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
/** |
|
208 |
* When a MenuElement receives an event from a MouseListener, it should never process the event |
|
209 |
* directly. Instead all MenuElements should call this method with the event. |
|
210 |
* |
|
211 |
* @param event a MouseEvent object |
|
212 |
*/ |
|
213 |
public void processMouseEvent(MouseEvent event) { |
|
214 |
int screenX,screenY; |
|
215 |
Point p; |
|
216 |
int i,c,j,d; |
|
217 |
Component mc; |
|
218 |
Rectangle r2; |
|
219 |
int cWidth,cHeight; |
|
220 |
MenuElement menuElement; |
|
221 |
MenuElement subElements[]; |
|
222 |
MenuElement path[]; |
|
11268 | 223 |
Vector<MenuElement> tmp; |
2 | 224 |
int selectionSize; |
225 |
p = event.getPoint(); |
|
226 |
||
459
d555ba8bbec1
6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents:
2
diff
changeset
|
227 |
Component source = event.getComponent(); |
2 | 228 |
|
459
d555ba8bbec1
6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents:
2
diff
changeset
|
229 |
if ((source != null) && !source.isShowing()) { |
2 | 230 |
// This can happen if a mouseReleased removes the |
231 |
// containing component -- bug 4146684 |
|
232 |
return; |
|
233 |
} |
|
234 |
||
235 |
int type = event.getID(); |
|
236 |
int modifiers = event.getModifiers(); |
|
237 |
// 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2 |
|
238 |
if ((type==MouseEvent.MOUSE_ENTERED|| |
|
239 |
type==MouseEvent.MOUSE_EXITED) |
|
240 |
&& ((modifiers & (InputEvent.BUTTON1_MASK | |
|
241 |
InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 )) { |
|
242 |
return; |
|
243 |
} |
|
244 |
||
459
d555ba8bbec1
6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents:
2
diff
changeset
|
245 |
if (source != null) { |
d555ba8bbec1
6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents:
2
diff
changeset
|
246 |
SwingUtilities.convertPointToScreen(p, source); |
d555ba8bbec1
6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents:
2
diff
changeset
|
247 |
} |
2 | 248 |
|
249 |
screenX = p.x; |
|
250 |
screenY = p.y; |
|
251 |
||
11268 | 252 |
tmp = (Vector<MenuElement>)selection.clone(); |
2 | 253 |
selectionSize = tmp.size(); |
254 |
boolean success = false; |
|
255 |
for (i=selectionSize - 1;i >= 0 && success == false; i--) { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
11268
diff
changeset
|
256 |
menuElement = tmp.elementAt(i); |
2 | 257 |
subElements = menuElement.getSubElements(); |
258 |
||
259 |
path = null; |
|
260 |
for (j = 0, d = subElements.length;j < d && success == false; j++) { |
|
261 |
if (subElements[j] == null) |
|
262 |
continue; |
|
263 |
mc = subElements[j].getComponent(); |
|
264 |
if(!mc.isShowing()) |
|
265 |
continue; |
|
266 |
if(mc instanceof JComponent) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
267 |
cWidth = mc.getWidth(); |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
268 |
cHeight = mc.getHeight(); |
2 | 269 |
} else { |
270 |
r2 = mc.getBounds(); |
|
271 |
cWidth = r2.width; |
|
272 |
cHeight = r2.height; |
|
273 |
} |
|
274 |
p.x = screenX; |
|
275 |
p.y = screenY; |
|
276 |
SwingUtilities.convertPointFromScreen(p,mc); |
|
277 |
||
278 |
/** Send the event to visible menu element if menu element currently in |
|
279 |
* the selected path or contains the event location |
|
280 |
*/ |
|
281 |
if( |
|
282 |
(p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) { |
|
283 |
int k; |
|
284 |
if(path == null) { |
|
285 |
path = new MenuElement[i+2]; |
|
286 |
for(k=0;k<=i;k++) |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
11268
diff
changeset
|
287 |
path[k] = tmp.elementAt(k); |
2 | 288 |
} |
289 |
path[i+1] = subElements[j]; |
|
290 |
MenuElement currentSelection[] = getSelectedPath(); |
|
291 |
||
292 |
// Enter/exit detection -- needs tuning... |
|
293 |
if (currentSelection[currentSelection.length-1] != |
|
294 |
path[i+1] && |
|
295 |
(currentSelection.length < 2 || |
|
296 |
currentSelection[currentSelection.length-2] != |
|
297 |
path[i+1])) { |
|
298 |
Component oldMC = currentSelection[currentSelection.length-1].getComponent(); |
|
299 |
||
300 |
MouseEvent exitEvent = new MouseEvent(oldMC, MouseEvent.MOUSE_EXITED, |
|
301 |
event.getWhen(), |
|
302 |
event.getModifiers(), p.x, p.y, |
|
303 |
event.getXOnScreen(), |
|
304 |
event.getYOnScreen(), |
|
305 |
event.getClickCount(), |
|
306 |
event.isPopupTrigger(), |
|
307 |
MouseEvent.NOBUTTON); |
|
308 |
currentSelection[currentSelection.length-1]. |
|
309 |
processMouseEvent(exitEvent, path, this); |
|
310 |
||
311 |
MouseEvent enterEvent = new MouseEvent(mc, |
|
312 |
MouseEvent.MOUSE_ENTERED, |
|
313 |
event.getWhen(), |
|
314 |
event.getModifiers(), p.x, p.y, |
|
315 |
event.getXOnScreen(), |
|
316 |
event.getYOnScreen(), |
|
317 |
event.getClickCount(), |
|
318 |
event.isPopupTrigger(), |
|
319 |
MouseEvent.NOBUTTON); |
|
320 |
subElements[j].processMouseEvent(enterEvent, path, this); |
|
321 |
} |
|
322 |
MouseEvent mouseEvent = new MouseEvent(mc, event.getID(),event. getWhen(), |
|
323 |
event.getModifiers(), p.x, p.y, |
|
324 |
event.getXOnScreen(), |
|
325 |
event.getYOnScreen(), |
|
326 |
event.getClickCount(), |
|
327 |
event.isPopupTrigger(), |
|
328 |
MouseEvent.NOBUTTON); |
|
329 |
subElements[j].processMouseEvent(mouseEvent, path, this); |
|
330 |
success = true; |
|
331 |
event.consume(); |
|
332 |
} |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
private void printMenuElementArray(MenuElement path[]) { |
|
338 |
printMenuElementArray(path, false); |
|
339 |
} |
|
340 |
||
341 |
private void printMenuElementArray(MenuElement path[], boolean dumpStack) { |
|
342 |
System.out.println("Path is("); |
|
343 |
int i, j; |
|
344 |
for(i=0,j=path.length; i<j ;i++){ |
|
345 |
for (int k=0; k<=i; k++) |
|
346 |
System.out.print(" "); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
347 |
MenuElement me = path[i]; |
2 | 348 |
if(me instanceof JMenuItem) { |
349 |
System.out.println(((JMenuItem)me).getText() + ", "); |
|
350 |
} else if (me instanceof JMenuBar) { |
|
351 |
System.out.println("JMenuBar, "); |
|
352 |
} else if(me instanceof JPopupMenu) { |
|
353 |
System.out.println("JPopupMenu, "); |
|
354 |
} else if (me == null) { |
|
355 |
System.out.println("NULL , "); |
|
356 |
} else { |
|
357 |
System.out.println("" + me + ", "); |
|
358 |
} |
|
359 |
} |
|
360 |
System.out.println(")"); |
|
361 |
||
362 |
if (dumpStack == true) |
|
363 |
Thread.dumpStack(); |
|
364 |
} |
|
365 |
||
366 |
/** |
|
367 |
* Returns the component in the currently selected path |
|
368 |
* which contains sourcePoint. |
|
369 |
* |
|
370 |
* @param source The component in whose coordinate space sourcePoint |
|
371 |
* is given |
|
372 |
* @param sourcePoint The point which is being tested |
|
373 |
* @return The component in the currently selected path which |
|
374 |
* contains sourcePoint (relative to the source component's |
|
375 |
* coordinate space. If sourcePoint is not inside a component |
|
376 |
* on the currently selected path, null is returned. |
|
377 |
*/ |
|
378 |
public Component componentForPoint(Component source, Point sourcePoint) { |
|
379 |
int screenX,screenY; |
|
380 |
Point p = sourcePoint; |
|
381 |
int i,c,j,d; |
|
382 |
Component mc; |
|
383 |
Rectangle r2; |
|
384 |
int cWidth,cHeight; |
|
385 |
MenuElement menuElement; |
|
386 |
MenuElement subElements[]; |
|
11268 | 387 |
Vector<MenuElement> tmp; |
2 | 388 |
int selectionSize; |
389 |
||
390 |
SwingUtilities.convertPointToScreen(p,source); |
|
391 |
||
392 |
screenX = p.x; |
|
393 |
screenY = p.y; |
|
394 |
||
11268 | 395 |
tmp = (Vector<MenuElement>)selection.clone(); |
2 | 396 |
selectionSize = tmp.size(); |
397 |
for(i=selectionSize - 1 ; i >= 0 ; i--) { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
11268
diff
changeset
|
398 |
menuElement = tmp.elementAt(i); |
2 | 399 |
subElements = menuElement.getSubElements(); |
400 |
||
401 |
for(j = 0, d = subElements.length ; j < d ; j++) { |
|
402 |
if (subElements[j] == null) |
|
403 |
continue; |
|
404 |
mc = subElements[j].getComponent(); |
|
405 |
if(!mc.isShowing()) |
|
406 |
continue; |
|
407 |
if(mc instanceof JComponent) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
408 |
cWidth = mc.getWidth(); |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
409 |
cHeight = mc.getHeight(); |
2 | 410 |
} else { |
411 |
r2 = mc.getBounds(); |
|
412 |
cWidth = r2.width; |
|
413 |
cHeight = r2.height; |
|
414 |
} |
|
415 |
p.x = screenX; |
|
416 |
p.y = screenY; |
|
417 |
SwingUtilities.convertPointFromScreen(p,mc); |
|
418 |
||
419 |
/** Return the deepest component on the selection |
|
420 |
* path in whose bounds the event's point occurs |
|
421 |
*/ |
|
422 |
if (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight) { |
|
423 |
return mc; |
|
424 |
} |
|
425 |
} |
|
426 |
} |
|
427 |
return null; |
|
428 |
} |
|
429 |
||
430 |
/** |
|
431 |
* When a MenuElement receives an event from a KeyListener, it should never process the event |
|
432 |
* directly. Instead all MenuElements should call this method with the event. |
|
433 |
* |
|
434 |
* @param e a KeyEvent object |
|
435 |
*/ |
|
436 |
public void processKeyEvent(KeyEvent e) { |
|
437 |
MenuElement[] sel2 = new MenuElement[0]; |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
438 |
sel2 = selection.toArray(sel2); |
2 | 439 |
int selSize = sel2.length; |
440 |
MenuElement[] path; |
|
441 |
||
442 |
if (selSize < 1) { |
|
443 |
return; |
|
444 |
} |
|
445 |
||
446 |
for (int i=selSize-1; i>=0; i--) { |
|
447 |
MenuElement elem = sel2[i]; |
|
448 |
MenuElement[] subs = elem.getSubElements(); |
|
449 |
path = null; |
|
450 |
||
451 |
for (int j=0; j<subs.length; j++) { |
|
452 |
if (subs[j] == null || !subs[j].getComponent().isShowing() |
|
453 |
|| !subs[j].getComponent().isEnabled()) { |
|
454 |
continue; |
|
455 |
} |
|
456 |
||
457 |
if(path == null) { |
|
458 |
path = new MenuElement[i+2]; |
|
459 |
System.arraycopy(sel2, 0, path, 0, i+1); |
|
460 |
} |
|
461 |
path[i+1] = subs[j]; |
|
462 |
subs[j].processKeyEvent(e, path, this); |
|
463 |
if (e.isConsumed()) { |
|
464 |
return; |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
// finally dispatch event to the first component in path |
|
470 |
path = new MenuElement[1]; |
|
471 |
path[0] = sel2[0]; |
|
472 |
path[0].processKeyEvent(e, path, this); |
|
473 |
if (e.isConsumed()) { |
|
474 |
return; |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
/** |
|
479 |
* Return true if c is part of the currently used menu |
|
480 |
*/ |
|
481 |
public boolean isComponentPartOfCurrentMenu(Component c) { |
|
482 |
if(selection.size() > 0) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
483 |
MenuElement me = selection.elementAt(0); |
2 | 484 |
return isComponentPartOfCurrentMenu(me,c); |
485 |
} else |
|
486 |
return false; |
|
487 |
} |
|
488 |
||
489 |
private boolean isComponentPartOfCurrentMenu(MenuElement root,Component c) { |
|
490 |
MenuElement children[]; |
|
491 |
int i,d; |
|
492 |
||
493 |
if (root == null) |
|
494 |
return false; |
|
495 |
||
496 |
if(root.getComponent() == c) |
|
497 |
return true; |
|
498 |
else { |
|
499 |
children = root.getSubElements(); |
|
500 |
for(i=0,d=children.length;i<d;i++) { |
|
501 |
if(isComponentPartOfCurrentMenu(children[i],c)) |
|
502 |
return true; |
|
503 |
} |
|
504 |
} |
|
505 |
return false; |
|
506 |
} |
|
507 |
} |