1 |
/* Container.java -- parent container class in AWT |
/* Container.java -- parent container class in AWT |
2 |
Copyright (C) 1999, 2000, 2002 Free Software Foundation |
Copyright (C) 1999, 2000, 2002 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
37 |
|
|
38 |
package java.awt; |
package java.awt; |
39 |
|
|
40 |
|
import java.awt.event.AWTEventListener; |
41 |
import java.awt.event.ContainerEvent; |
import java.awt.event.ContainerEvent; |
42 |
import java.awt.event.ContainerListener; |
import java.awt.event.ContainerListener; |
43 |
|
import java.awt.event.MouseEvent; |
44 |
import java.awt.peer.ComponentPeer; |
import java.awt.peer.ComponentPeer; |
45 |
import java.awt.peer.ContainerPeer; |
import java.awt.peer.ContainerPeer; |
46 |
import java.awt.peer.LightweightPeer; |
import java.awt.peer.LightweightPeer; |
47 |
|
import java.beans.PropertyChangeListener; |
48 |
import java.io.PrintStream; |
import java.io.PrintStream; |
49 |
import java.io.PrintWriter; |
import java.io.PrintWriter; |
50 |
|
import java.io.Serializable; |
51 |
import java.util.EventListener; |
import java.util.EventListener; |
52 |
|
import java.util.Set; |
53 |
import javax.accessibility.Accessible; |
import javax.accessibility.Accessible; |
54 |
|
|
55 |
/** |
/** |
74 |
Component[] component; |
Component[] component; |
75 |
LayoutManager layoutMgr; |
LayoutManager layoutMgr; |
76 |
|
|
77 |
// XXX Implement package visible class java.awt.LightweightDispatcher. |
LightweightDispatcher dispatcher; |
|
/* LightweightDispatcher dispatcher; */ |
|
78 |
|
|
79 |
Dimension maxSize; |
Dimension maxSize; |
80 |
|
|
107 |
* Returns the number of components in this container. |
* Returns the number of components in this container. |
108 |
* |
* |
109 |
* @return The number of components in this container. |
* @return The number of components in this container. |
110 |
* |
* @deprecated use {@link #getComponentCount()} instead |
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>getComponentCount()</code>. |
|
111 |
*/ |
*/ |
112 |
public int countComponents() |
public int countComponents() |
113 |
{ |
{ |
114 |
return ncomponents; |
return getComponentCount(); |
115 |
} |
} |
116 |
|
|
117 |
/** |
/** |
118 |
* Returns the component at the specified index. |
* Returns the component at the specified index. |
119 |
* |
* |
120 |
* @param index The index of the component to retrieve. |
* @param index The index of the component to retrieve. |
|
* |
|
121 |
* @return The requested component. |
* @return The requested component. |
122 |
* |
* @throws ArrayIndexOutOfBoundsException If the specified index is invalid |
|
* @exception ArrayIndexOutOfBoundsException If the specified index is not |
|
|
* valid. |
|
123 |
*/ |
*/ |
124 |
public Component getComponent (int n) |
public Component getComponent(int n) |
125 |
{ |
{ |
126 |
if (n < 0 || n >= ncomponents) |
if (n < 0 || n >= ncomponents) |
127 |
throw new ArrayIndexOutOfBoundsException("no such component"); |
throw new ArrayIndexOutOfBoundsException("no such component"); |
159 |
* borders, the margin, etc. |
* borders, the margin, etc. |
160 |
* |
* |
161 |
* @return The insets for this container. |
* @return The insets for this container. |
162 |
* |
* @deprecated use {@link #getInsets()} instead |
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>getInsets()</code>. |
|
163 |
*/ |
*/ |
164 |
public Insets insets() |
public Insets insets() |
165 |
{ |
{ |
171 |
* component list. |
* component list. |
172 |
* |
* |
173 |
* @param component The component to add to the container. |
* @param component The component to add to the container. |
|
* |
|
174 |
* @return The same component that was added. |
* @return The same component that was added. |
175 |
*/ |
*/ |
176 |
public Component add (Component comp) |
public Component add(Component comp) |
177 |
{ |
{ |
178 |
addImpl (comp, null, -1); |
addImpl(comp, null, -1); |
179 |
return comp; |
return comp; |
180 |
} |
} |
181 |
|
|
189 |
* |
* |
190 |
* @return The same component that was added. |
* @return The same component that was added. |
191 |
*/ |
*/ |
192 |
public Component add (String name, Component comp) |
public Component add(String name, Component comp) |
193 |
{ |
{ |
194 |
addImpl (comp, name, -1); |
addImpl(comp, name, -1); |
195 |
return comp; |
return comp; |
196 |
} |
} |
197 |
|
|
207 |
* |
* |
208 |
* @param throws ArrayIndexOutOfBounds If the specified index is invalid. |
* @param throws ArrayIndexOutOfBounds If the specified index is invalid. |
209 |
*/ |
*/ |
210 |
public Component add (Component comp, int index) |
public Component add(Component comp, int index) |
211 |
{ |
{ |
212 |
addImpl (comp, null, index); |
addImpl(comp, null, index); |
213 |
return comp; |
return comp; |
214 |
} |
} |
215 |
|
|
221 |
* @param component The component to be added to this container. |
* @param component The component to be added to this container. |
222 |
* @param constraints The layout constraints for this component. |
* @param constraints The layout constraints for this component. |
223 |
*/ |
*/ |
224 |
public void add (Component comp, Object constraints) |
public void add(Component comp, Object constraints) |
225 |
{ |
{ |
226 |
addImpl (comp, constraints, -1); |
addImpl(comp, constraints, -1); |
227 |
} |
} |
228 |
|
|
229 |
/** |
/** |
238 |
* |
* |
239 |
* @param throws ArrayIndexOutOfBounds If the specified index is invalid. |
* @param throws ArrayIndexOutOfBounds If the specified index is invalid. |
240 |
*/ |
*/ |
241 |
public void add (Component comp, Object constraints, int index) |
public void add(Component comp, Object constraints, int index) |
242 |
{ |
{ |
243 |
addImpl (comp, constraints, index); |
addImpl(comp, constraints, index); |
244 |
} |
} |
245 |
|
|
246 |
/** |
/** |
258 |
* |
* |
259 |
* @param throws ArrayIndexOutOfBounds If the specified index is invalid. |
* @param throws ArrayIndexOutOfBounds If the specified index is invalid. |
260 |
*/ |
*/ |
261 |
protected void addImpl (Component comp, Object constraints, int index) |
protected void addImpl(Component comp, Object constraints, int index) |
262 |
{ |
{ |
263 |
if (index > ncomponents |
if (index > ncomponents |
264 |
|| (index < 0 && index != -1) |
|| (index < 0 && index != -1) |
265 |
|| comp instanceof Window |
|| comp instanceof Window |
266 |
|| (comp instanceof Container |
|| (comp instanceof Container |
267 |
&& ((Container) comp).isAncestorOf (this))) |
&& ((Container) comp).isAncestorOf(this))) |
268 |
throw new IllegalArgumentException (); |
throw new IllegalArgumentException(); |
269 |
|
|
270 |
// Reparent component, and make sure component is instantiated if |
// Reparent component, and make sure component is instantiated if |
271 |
// we are. |
// we are. |
272 |
if (comp.parent != null) |
if (comp.parent != null) |
273 |
comp.parent.remove (comp); |
comp.parent.remove(comp); |
274 |
comp.parent = this; |
comp.parent = this; |
275 |
if (peer != null) |
if (peer != null) |
276 |
{ |
{ |
277 |
comp.addNotify (); |
comp.addNotify(); |
278 |
|
|
279 |
if (comp.isLightweight()) |
if (comp.isLightweight()) |
280 |
enableEvents(comp.eventMask); |
enableEvents(comp.eventMask); |
281 |
} |
} |
282 |
|
|
283 |
invalidate (); |
invalidate(); |
284 |
|
|
285 |
if (component == null) |
if (component == null) |
286 |
component = new Component[4]; // FIXME, better initial size? |
component = new Component[4]; // FIXME, better initial size? |
291 |
{ |
{ |
292 |
int nl = component.length * 2; |
int nl = component.length * 2; |
293 |
Component[] c = new Component[nl]; |
Component[] c = new Component[nl]; |
294 |
System.arraycopy (component, 0, c, 0, ncomponents); |
System.arraycopy(component, 0, c, 0, ncomponents); |
295 |
component = c; |
component = c; |
296 |
} |
} |
297 |
if (index == -1) |
if (index == -1) |
298 |
component[ncomponents++] = comp; |
component[ncomponents++] = comp; |
299 |
else |
else |
300 |
{ |
{ |
301 |
System.arraycopy (component, index, component, index + 1, |
System.arraycopy(component, index, component, index + 1, |
302 |
ncomponents - index); |
ncomponents - index); |
303 |
component[index] = comp; |
component[index] = comp; |
304 |
++ncomponents; |
++ncomponents; |
310 |
if (layoutMgr instanceof LayoutManager2) |
if (layoutMgr instanceof LayoutManager2) |
311 |
{ |
{ |
312 |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
313 |
lm2.addLayoutComponent (comp, constraints); |
lm2.addLayoutComponent(comp, constraints); |
314 |
} |
} |
315 |
else if (constraints instanceof String) |
else if (constraints instanceof String) |
316 |
layoutMgr.addLayoutComponent ((String) constraints, comp); |
layoutMgr.addLayoutComponent((String) constraints, comp); |
317 |
else |
else |
318 |
layoutMgr.addLayoutComponent (null, comp); |
layoutMgr.addLayoutComponent(null, comp); |
319 |
} |
} |
320 |
|
|
321 |
// Post event to notify of adding the container. |
// Post event to notify of adding the container. |
322 |
ContainerEvent ce = new ContainerEvent (this, |
ContainerEvent ce = new ContainerEvent(this, |
323 |
ContainerEvent.COMPONENT_ADDED, |
ContainerEvent.COMPONENT_ADDED, |
324 |
comp); |
comp); |
325 |
getToolkit().getSystemEventQueue().postEvent(ce); |
getToolkit().getSystemEventQueue().postEvent(ce); |
330 |
* |
* |
331 |
* @param index The index of the component to remove. |
* @param index The index of the component to remove. |
332 |
*/ |
*/ |
333 |
public void remove (int index) |
public void remove(int index) |
334 |
{ |
{ |
335 |
Component r = component[index]; |
Component r = component[index]; |
336 |
|
|
337 |
r.removeNotify (); |
r.removeNotify(); |
338 |
|
|
339 |
System.arraycopy (component, index + 1, component, index, |
System.arraycopy(component, index + 1, component, index, |
340 |
ncomponents - index - 1); |
ncomponents - index - 1); |
341 |
component[--ncomponents] = null; |
component[--ncomponents] = null; |
342 |
|
|
343 |
invalidate (); |
invalidate(); |
344 |
|
|
345 |
if (layoutMgr != null) |
if (layoutMgr != null) |
346 |
layoutMgr.removeLayoutComponent (r); |
layoutMgr.removeLayoutComponent(r); |
347 |
|
|
348 |
// Post event to notify of adding the container. |
// Post event to notify of adding the container. |
349 |
ContainerEvent ce = new ContainerEvent (this, |
ContainerEvent ce = new ContainerEvent(this, |
350 |
ContainerEvent.COMPONENT_REMOVED, |
ContainerEvent.COMPONENT_REMOVED, |
351 |
r); |
r); |
352 |
getToolkit().getSystemEventQueue().postEvent(ce); |
getToolkit().getSystemEventQueue().postEvent(ce); |
357 |
* |
* |
358 |
* @return component The component to remove from this container. |
* @return component The component to remove from this container. |
359 |
*/ |
*/ |
360 |
public void remove (Component comp) |
public void remove(Component comp) |
361 |
{ |
{ |
362 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
363 |
{ |
{ |
364 |
if (component[i] == comp) |
if (component[i] == comp) |
365 |
{ |
{ |
366 |
remove (i); |
remove(i); |
367 |
break; |
break; |
368 |
} |
} |
369 |
} |
} |
375 |
public void removeAll() |
public void removeAll() |
376 |
{ |
{ |
377 |
while (ncomponents > 0) |
while (ncomponents > 0) |
378 |
remove (0); |
remove(0); |
379 |
} |
} |
380 |
|
|
381 |
/** |
/** |
397 |
public void setLayout(LayoutManager mgr) |
public void setLayout(LayoutManager mgr) |
398 |
{ |
{ |
399 |
layoutMgr = mgr; |
layoutMgr = mgr; |
400 |
invalidate (); |
invalidate(); |
401 |
} |
} |
402 |
|
|
403 |
/** |
/** |
406 |
public void doLayout() |
public void doLayout() |
407 |
{ |
{ |
408 |
if (layoutMgr != null) |
if (layoutMgr != null) |
409 |
layoutMgr.layoutContainer (this); |
layoutMgr.layoutContainer(this); |
410 |
} |
} |
411 |
|
|
412 |
/** |
/** |
413 |
* Layout the components in this container. |
* Layout the components in this container. |
414 |
* |
* |
415 |
* @deprecated This method is deprecated in favor of |
* @deprecated use {@link #doLayout()} instead |
|
* <code>doLayout()</code>. |
|
416 |
*/ |
*/ |
417 |
public void layout() |
public void layout() |
418 |
{ |
{ |
425 |
*/ |
*/ |
426 |
public void invalidate() |
public void invalidate() |
427 |
{ |
{ |
428 |
super.invalidate (); |
super.invalidate(); |
429 |
} |
} |
430 |
|
|
431 |
/** |
/** |
436 |
// FIXME: use the tree lock? |
// FIXME: use the tree lock? |
437 |
synchronized (this) |
synchronized (this) |
438 |
{ |
{ |
439 |
if (! isValid ()) |
if (! isValid()) |
440 |
{ |
{ |
441 |
validateTree (); |
validateTree(); |
442 |
} |
} |
443 |
} |
} |
444 |
} |
} |
453 |
return; |
return; |
454 |
|
|
455 |
ContainerPeer cPeer = null; |
ContainerPeer cPeer = null; |
456 |
if ((peer != null) && !(peer instanceof LightweightPeer)) |
if (peer != null && ! (peer instanceof LightweightPeer)) |
457 |
{ |
{ |
458 |
cPeer = (ContainerPeer) peer; |
cPeer = (ContainerPeer) peer; |
459 |
cPeer.beginValidate(); |
cPeer.beginValidate(); |
460 |
} |
} |
461 |
|
|
462 |
doLayout (); |
doLayout(); |
463 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
464 |
{ |
{ |
465 |
Component comp = component[i]; |
Component comp = component[i]; |
466 |
if (! comp.isValid ()) |
if (! comp.isValid()) |
467 |
{ |
{ |
468 |
if (comp instanceof Container) |
if (comp instanceof Container) |
469 |
{ |
{ |
499 |
public Dimension getPreferredSize() |
public Dimension getPreferredSize() |
500 |
{ |
{ |
501 |
if (layoutMgr != null) |
if (layoutMgr != null) |
502 |
return layoutMgr.preferredLayoutSize (this); |
return layoutMgr.preferredLayoutSize(this); |
503 |
else |
else |
504 |
return super.getPreferredSize (); |
return super.getPreferredSize(); |
505 |
} |
} |
506 |
|
|
507 |
/** |
/** |
508 |
* Returns the preferred size of this container. |
* Returns the preferred size of this container. |
509 |
* |
* |
510 |
* @return The preferred size of this container. |
* @return The preferred size of this container. |
511 |
* |
* @deprecated use {@link #getPreferredSize()} instead |
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>getPreferredSize()</code>. |
|
512 |
*/ |
*/ |
513 |
public Dimension preferredSize() |
public Dimension preferredSize() |
514 |
{ |
{ |
523 |
public Dimension getMinimumSize() |
public Dimension getMinimumSize() |
524 |
{ |
{ |
525 |
if (layoutMgr != null) |
if (layoutMgr != null) |
526 |
return layoutMgr.minimumLayoutSize (this); |
return layoutMgr.minimumLayoutSize(this); |
527 |
else |
else |
528 |
return super.getMinimumSize (); |
return super.getMinimumSize(); |
529 |
} |
} |
530 |
|
|
531 |
/** |
/** |
532 |
* Returns the minimum size of this container. |
* Returns the minimum size of this container. |
533 |
* |
* |
534 |
* @return The minimum size of this container. |
* @return The minimum size of this container. |
535 |
* |
* @deprecated use {@link #getMinimumSize()} instead |
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>getMinimumSize()</code>. |
|
536 |
*/ |
*/ |
537 |
public Dimension minimumSize() |
public Dimension minimumSize() |
538 |
{ |
{ |
549 |
if (layoutMgr != null && layoutMgr instanceof LayoutManager2) |
if (layoutMgr != null && layoutMgr instanceof LayoutManager2) |
550 |
{ |
{ |
551 |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
552 |
return lm2.maximumLayoutSize (this); |
return lm2.maximumLayoutSize(this); |
553 |
} |
} |
554 |
else |
else |
555 |
return super.getMaximumSize (); |
return super.getMaximumSize(); |
556 |
} |
} |
557 |
|
|
558 |
/** |
/** |
567 |
if (layoutMgr instanceof LayoutManager2) |
if (layoutMgr instanceof LayoutManager2) |
568 |
{ |
{ |
569 |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
570 |
return lm2.getLayoutAlignmentX (this); |
return lm2.getLayoutAlignmentX(this); |
571 |
} |
} |
572 |
else |
else |
573 |
return super.getAlignmentX(); |
return super.getAlignmentX(); |
585 |
if (layoutMgr instanceof LayoutManager2) |
if (layoutMgr instanceof LayoutManager2) |
586 |
{ |
{ |
587 |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
LayoutManager2 lm2 = (LayoutManager2) layoutMgr; |
588 |
return lm2.getLayoutAlignmentY (this); |
return lm2.getLayoutAlignmentY(this); |
589 |
} |
} |
590 |
else |
else |
591 |
return super.getAlignmentY(); |
return super.getAlignmentY(); |
609 |
} |
} |
610 |
|
|
611 |
/** |
/** |
|
* Perform a graphics operation on the children of this container. |
|
|
* For each applicable child, the visitChild() method will be called |
|
|
* to perform the graphics operation. |
|
|
* |
|
|
* @param gfx The graphics object that will be used to derive new |
|
|
* graphics objects for the children. |
|
|
* |
|
|
* @param visitor Object encapsulating the graphics operation that |
|
|
* should be performed. |
|
|
* |
|
|
* @param lightweightOnly If true, only lightweight components will |
|
|
* be visited. |
|
|
*/ |
|
|
private void visitChildren(Graphics gfx, GfxVisitor visitor, |
|
|
boolean lightweightOnly) |
|
|
{ |
|
|
// FIXME: do locking |
|
|
|
|
|
for (int i = 0; i < ncomponents; ++i) |
|
|
{ |
|
|
Component comp = component[i]; |
|
|
boolean applicable = comp.isVisible() |
|
|
&& (comp.isLightweight() || !lightweightOnly); |
|
|
|
|
|
if (applicable) |
|
|
visitChild(gfx, visitor, comp); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Perform a graphics operation on a child. A translated and clipped |
|
|
* graphics object will be created, and the visit() method of the |
|
|
* visitor will be called to perform the operation. |
|
|
* |
|
|
* @param gfx The graphics object that will be used to derive new |
|
|
* graphics objects for the child. |
|
|
* |
|
|
* @param visitor Object encapsulating the graphics operation that |
|
|
* should be performed. |
|
|
* |
|
|
* @param comp The child component that should be visited. |
|
|
*/ |
|
|
private void visitChild(Graphics gfx, GfxVisitor visitor, |
|
|
Component comp) |
|
|
{ |
|
|
Rectangle bounds = comp.getBounds(); |
|
|
Rectangle clip = gfx.getClipBounds().intersection(bounds); |
|
|
|
|
|
if (clip.isEmpty()) return; |
|
|
|
|
|
Graphics gfx2 = gfx.create(); |
|
|
gfx2.setClip(clip.x, clip.y, clip.width, clip.height); |
|
|
gfx2.translate(bounds.x, bounds.y); |
|
|
|
|
|
visitor.visit(comp, gfx2); |
|
|
} |
|
|
|
|
|
/** |
|
612 |
* Updates this container. The implementation of this method in this |
* Updates this container. The implementation of this method in this |
613 |
* class forwards to any lightweight components in this container. If |
* class forwards to any lightweight components in this container. If |
614 |
* this method is subclassed, this method should still be invoked as |
* this method is subclassed, this method should still be invoked as |
659 |
visitChildren(g, GfxPrintAllVisitor.INSTANCE, true); |
visitChildren(g, GfxPrintAllVisitor.INSTANCE, true); |
660 |
} |
} |
661 |
|
|
|
void dispatchEventImpl(AWTEvent e) |
|
|
{ |
|
|
if ((e.id <= ContainerEvent.CONTAINER_LAST |
|
|
&& e.id >= ContainerEvent.CONTAINER_FIRST) |
|
|
&& (containerListener != null |
|
|
|| (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) |
|
|
processEvent(e); |
|
|
else |
|
|
super.dispatchEventImpl(e); |
|
|
} |
|
|
|
|
662 |
/** |
/** |
663 |
* Adds the specified container listener to this object's list of |
* Adds the specified container listener to this object's list of |
664 |
* container listeners. |
* container listeners. |
667 |
*/ |
*/ |
668 |
public synchronized void addContainerListener(ContainerListener l) |
public synchronized void addContainerListener(ContainerListener l) |
669 |
{ |
{ |
670 |
containerListener = AWTEventMulticaster.add (containerListener, l); |
containerListener = AWTEventMulticaster.add(containerListener, l); |
671 |
} |
} |
672 |
|
|
673 |
/** |
/** |
681 |
containerListener = AWTEventMulticaster.remove(containerListener, l); |
containerListener = AWTEventMulticaster.remove(containerListener, l); |
682 |
} |
} |
683 |
|
|
684 |
|
/** |
685 |
|
* @since 1.4 |
686 |
|
*/ |
687 |
public synchronized ContainerListener[] getContainerListeners() |
public synchronized ContainerListener[] getContainerListeners() |
688 |
{ |
{ |
689 |
return (ContainerListener[]) |
return (ContainerListener[]) |
691 |
ContainerListener.class); |
ContainerListener.class); |
692 |
} |
} |
693 |
|
|
694 |
/** @since 1.3 */ |
/** |
695 |
|
* @since 1.3 |
696 |
|
*/ |
697 |
public EventListener[] getListeners(Class listenerType) |
public EventListener[] getListeners(Class listenerType) |
698 |
{ |
{ |
699 |
if (listenerType == ContainerListener.class) |
if (listenerType == ContainerListener.class) |
742 |
* AWT 1.0 event processor. |
* AWT 1.0 event processor. |
743 |
* |
* |
744 |
* @param event The event that occurred. |
* @param event The event that occurred. |
745 |
* |
* @deprecated use {@link #dispatchEvent(AWTEvent)} instead |
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>dispatchEvent()</code>. |
|
746 |
*/ |
*/ |
747 |
public void deliverEvent(Event e) |
public void deliverEvent(Event e) |
748 |
{ |
{ |
762 |
* @return The component containing the specified point, or |
* @return The component containing the specified point, or |
763 |
* <code>null</code> if there is no such point. |
* <code>null</code> if there is no such point. |
764 |
*/ |
*/ |
765 |
public Component getComponentAt (int x, int y) |
public Component getComponentAt(int x, int y) |
766 |
{ |
{ |
767 |
if (! contains (x, y)) |
if (! contains(x, y)) |
768 |
return null; |
return null; |
769 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
770 |
{ |
{ |
774 |
|
|
775 |
int x2 = x - component[i].x; |
int x2 = x - component[i].x; |
776 |
int y2 = y - component[i].y; |
int y2 = y - component[i].y; |
777 |
if (component[i].contains (x2, y2)) |
if (component[i].contains(x2, y2)) |
778 |
return component[i]; |
return component[i]; |
779 |
} |
} |
780 |
return this; |
return this; |
792 |
* |
* |
793 |
* @return The component containing the specified point, or <code>null</code> |
* @return The component containing the specified point, or <code>null</code> |
794 |
* if there is no such point. |
* if there is no such point. |
795 |
* |
* @deprecated use {@link #getComponentAt(int, int)} instead |
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>getComponentAt(int, int)</code>. |
|
796 |
*/ |
*/ |
797 |
public Component locate(int x, int y) |
public Component locate(int x, int y) |
798 |
{ |
{ |
808 |
* case <code>null</code> is returned. |
* case <code>null</code> is returned. |
809 |
* |
* |
810 |
* @param point The point to return the component at. |
* @param point The point to return the component at. |
|
* |
|
811 |
* @return The component containing the specified point, or <code>null</code> |
* @return The component containing the specified point, or <code>null</code> |
812 |
* if there is no such point. |
* if there is no such point. |
813 |
*/ |
*/ |
816 |
return getComponentAt(p.x, p.y); |
return getComponentAt(p.x, p.y); |
817 |
} |
} |
818 |
|
|
819 |
public Component findComponentAt (int x, int y) |
public Component findComponentAt(int x, int y) |
820 |
{ |
{ |
821 |
if (! contains (x, y)) |
if (! contains(x, y)) |
822 |
return null; |
return null; |
823 |
|
|
824 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
834 |
if (component[i] instanceof Container) |
if (component[i] instanceof Container) |
835 |
{ |
{ |
836 |
Container k = (Container) component[i]; |
Container k = (Container) component[i]; |
837 |
Component r = k.findComponentAt (x2, y2); |
Component r = k.findComponentAt(x2, y2); |
838 |
if (r != null) |
if (r != null) |
839 |
return r; |
return r; |
840 |
} |
} |
841 |
else if (component[i].contains (x2, y2)) |
else if (component[i].contains(x2, y2)) |
842 |
return component[i]; |
return component[i]; |
843 |
} |
} |
844 |
|
|
855 |
* to create its peer. Peers for any child components will also be |
* to create its peer. Peers for any child components will also be |
856 |
* created. |
* created. |
857 |
*/ |
*/ |
858 |
public void addNotify () |
public void addNotify() |
859 |
{ |
{ |
860 |
addNotifyContainerChildren (); |
addNotifyContainerChildren(); |
861 |
super.addNotify(); |
super.addNotify(); |
862 |
} |
} |
863 |
|
|
|
private void addNotifyContainerChildren() |
|
|
{ |
|
|
for (int i = ncomponents; --i >= 0; ) |
|
|
{ |
|
|
component[i].addNotify(); |
|
|
if (component[i].isLightweight()) |
|
|
enableEvents(component[i].eventMask); |
|
|
} |
|
|
} |
|
|
|
|
864 |
/** |
/** |
865 |
* Called when this container is removed from its parent container to |
* Called when this container is removed from its parent container to |
866 |
* inform it to destroy its peer. This causes the peers of all child |
* inform it to destroy its peer. This causes the peers of all child |
869 |
public void removeNotify() |
public void removeNotify() |
870 |
{ |
{ |
871 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
872 |
component[i].removeNotify (); |
component[i].removeNotify(); |
873 |
super.removeNotify(); |
super.removeNotify(); |
874 |
} |
} |
875 |
|
|
882 |
* @return <code>true</code> if this container is an ancestor of the |
* @return <code>true</code> if this container is an ancestor of the |
883 |
* specified component, <code>false</code>. |
* specified component, <code>false</code>. |
884 |
*/ |
*/ |
885 |
public boolean isAncestorOf (Component comp) |
public boolean isAncestorOf(Component comp) |
886 |
{ |
{ |
887 |
for (;;) |
while (true) |
888 |
{ |
{ |
889 |
if (comp == null) |
if (comp == null) |
890 |
return false; |
return false; |
916 |
* @param stream The <code>PrintStream</code> to write to. |
* @param stream The <code>PrintStream</code> to write to. |
917 |
* @param indent The indentation point. |
* @param indent The indentation point. |
918 |
*/ |
*/ |
919 |
public void list (PrintStream out, int indent) |
public void list(PrintStream out, int indent) |
920 |
{ |
{ |
921 |
super.list (out, indent); |
super.list(out, indent); |
922 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
923 |
component[i].list (out, indent + 2); |
component[i].list(out, indent + 2); |
924 |
} |
} |
925 |
|
|
926 |
/** |
/** |
932 |
*/ |
*/ |
933 |
public void list(PrintWriter out, int indent) |
public void list(PrintWriter out, int indent) |
934 |
{ |
{ |
935 |
super.list (out, indent); |
super.list(out, indent); |
936 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
937 |
component[i].list (out, indent + 2); |
component[i].list(out, indent + 2); |
938 |
} |
} |
939 |
|
|
940 |
|
public void setFocusTraversalKeys(int id, Set keys) |
|
/* The following classes are used in concert with the |
|
|
visitChildren() method to implement all the graphics operations |
|
|
that requires traversal of the containment hierarchy. */ |
|
|
|
|
|
abstract static class GfxVisitor |
|
941 |
{ |
{ |
|
public abstract void visit(Component c, Graphics gfx); |
|
942 |
} |
} |
943 |
|
public Set getFocusTraversalKeys(int id) |
944 |
static class GfxPaintVisitor extends GfxVisitor |
{ |
945 |
|
return null; |
946 |
|
} |
947 |
|
public boolean areFocusTraversalKeysSet(int id) |
948 |
|
{ |
949 |
|
return false; |
950 |
|
} |
951 |
|
public boolean isFocusCycleRoot(Container c) |
952 |
|
{ |
953 |
|
return false; |
954 |
|
} |
955 |
|
public void transferFocusBackward() |
956 |
|
{ |
957 |
|
} |
958 |
|
public void setFocusTraversalPolicy(FocusTraversalPolicy policy) |
959 |
|
{ |
960 |
|
} |
961 |
|
public FocusTraversalPolicy getFocusTraversalPolicy() |
962 |
|
{ |
963 |
|
return null; |
964 |
|
} |
965 |
|
public boolean isFocusTraversalPolicySet() |
966 |
|
{ |
967 |
|
return false; |
968 |
|
} |
969 |
|
public void setFocusCycleRoot(boolean focusCycleRoot) |
970 |
|
{ |
971 |
|
} |
972 |
|
public boolean isFocusCycleRoot() |
973 |
|
{ |
974 |
|
return false; |
975 |
|
} |
976 |
|
public void transferFocusDownCycle() |
977 |
|
{ |
978 |
|
} |
979 |
|
public void applyComponentOrientation(ComponentOrientation o) |
980 |
|
{ |
981 |
|
} |
982 |
|
public void addPropertyChangeListener(PropertyChangeListener l) |
983 |
|
{ |
984 |
|
} |
985 |
|
public void addPropertyChangeListener(String name, PropertyChangeListener l) |
986 |
{ |
{ |
|
public void visit(Component c, Graphics gfx) { c.paint(gfx); } |
|
|
public static final GfxVisitor INSTANCE = new GfxPaintVisitor(); |
|
987 |
} |
} |
988 |
|
|
989 |
static class GfxPrintVisitor extends GfxVisitor |
|
990 |
|
// Hidden helper methods. |
991 |
|
|
992 |
|
/** |
993 |
|
* Perform a graphics operation on the children of this container. |
994 |
|
* For each applicable child, the visitChild() method will be called |
995 |
|
* to perform the graphics operation. |
996 |
|
* |
997 |
|
* @param gfx The graphics object that will be used to derive new |
998 |
|
* graphics objects for the children. |
999 |
|
* |
1000 |
|
* @param visitor Object encapsulating the graphics operation that |
1001 |
|
* should be performed. |
1002 |
|
* |
1003 |
|
* @param lightweightOnly If true, only lightweight components will |
1004 |
|
* be visited. |
1005 |
|
*/ |
1006 |
|
private void visitChildren(Graphics gfx, GfxVisitor visitor, |
1007 |
|
boolean lightweightOnly) |
1008 |
{ |
{ |
1009 |
public void visit(Component c, Graphics gfx) { c.print(gfx); } |
// FIXME: do locking |
1010 |
public static final GfxVisitor INSTANCE = new GfxPrintVisitor(); |
|
1011 |
|
for (int i = 0; i < ncomponents; ++i) |
1012 |
|
{ |
1013 |
|
Component comp = component[i]; |
1014 |
|
boolean applicable = comp.isVisible() |
1015 |
|
&& (comp.isLightweight() || !lightweightOnly); |
1016 |
|
|
1017 |
|
if (applicable) |
1018 |
|
visitChild(gfx, visitor, comp); |
1019 |
|
} |
1020 |
} |
} |
1021 |
|
|
1022 |
static class GfxPaintAllVisitor extends GfxVisitor |
/** |
1023 |
|
* Perform a graphics operation on a child. A translated and clipped |
1024 |
|
* graphics object will be created, and the visit() method of the |
1025 |
|
* visitor will be called to perform the operation. |
1026 |
|
* |
1027 |
|
* @param gfx The graphics object that will be used to derive new |
1028 |
|
* graphics objects for the child. |
1029 |
|
* |
1030 |
|
* @param visitor Object encapsulating the graphics operation that |
1031 |
|
* should be performed. |
1032 |
|
* |
1033 |
|
* @param comp The child component that should be visited. |
1034 |
|
*/ |
1035 |
|
private void visitChild(Graphics gfx, GfxVisitor visitor, |
1036 |
|
Component comp) |
1037 |
{ |
{ |
1038 |
public void visit(Component c, Graphics gfx) { c.paintAll(gfx); } |
Rectangle bounds = comp.getBounds(); |
1039 |
public static final GfxVisitor INSTANCE = new GfxPaintAllVisitor(); |
Rectangle clip = gfx.getClipBounds().intersection(bounds); |
1040 |
|
|
1041 |
|
if (clip.isEmpty()) return; |
1042 |
|
|
1043 |
|
Graphics gfx2 = gfx.create(); |
1044 |
|
gfx2.setClip(clip.x, clip.y, clip.width, clip.height); |
1045 |
|
gfx2.translate(bounds.x, bounds.y); |
1046 |
|
|
1047 |
|
visitor.visit(comp, gfx2); |
1048 |
} |
} |
1049 |
|
|
1050 |
static class GfxPrintAllVisitor extends GfxVisitor |
void dispatchEventImpl(AWTEvent e) |
1051 |
{ |
{ |
1052 |
public void visit(Component c, Graphics gfx) { c.printAll(gfx); } |
if ((e.id <= ContainerEvent.CONTAINER_LAST |
1053 |
public static final GfxVisitor INSTANCE = new GfxPrintAllVisitor(); |
&& e.id >= ContainerEvent.CONTAINER_FIRST) |
1054 |
|
&& (containerListener != null |
1055 |
|
|| (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) |
1056 |
|
processEvent(e); |
1057 |
|
else |
1058 |
|
super.dispatchEventImpl(e); |
1059 |
} |
} |
1060 |
|
|
1061 |
// This is used to implement Component.transferFocus. |
// This is used to implement Component.transferFocus. |
1062 |
Component findNextFocusComponent (Component child) |
Component findNextFocusComponent(Component child) |
1063 |
{ |
{ |
1064 |
int start, end; |
int start, end; |
1065 |
if (child != null) |
if (child != null) |
1090 |
// global within in given window. So instead if we reach |
// global within in given window. So instead if we reach |
1091 |
// the end we try to look in our parent, if we have one. |
// the end we try to look in our parent, if we have one. |
1092 |
if (parent != null) |
if (parent != null) |
1093 |
return parent.findNextFocusComponent (this); |
return parent.findNextFocusComponent(this); |
1094 |
j -= ncomponents; |
j -= ncomponents; |
1095 |
} |
} |
1096 |
if (component[j] instanceof Container) |
if (component[j] instanceof Container) |
1097 |
{ |
{ |
1098 |
Component c = component[j]; |
Component c = component[j]; |
1099 |
c = c.findNextFocusComponent (null); |
c = c.findNextFocusComponent(null); |
1100 |
if (c != null) |
if (c != null) |
1101 |
return c; |
return c; |
1102 |
} |
} |
1103 |
else if (component[j].isFocusTraversable ()) |
else if (component[j].isFocusTraversable()) |
1104 |
return component[j]; |
return component[j]; |
1105 |
} |
} |
1106 |
|
|
1107 |
return null; |
return null; |
1108 |
} |
} |
1109 |
|
|
1110 |
|
private void addNotifyContainerChildren() |
1111 |
|
{ |
1112 |
|
for (int i = ncomponents; --i >= 0; ) |
1113 |
|
{ |
1114 |
|
component[i].addNotify(); |
1115 |
|
if (component[i].isLightweight()) |
1116 |
|
enableEvents(component[i].eventMask); |
1117 |
|
} |
1118 |
|
} |
1119 |
|
|
1120 |
|
|
1121 |
|
// Nested classes. |
1122 |
|
|
1123 |
|
/* The following classes are used in concert with the |
1124 |
|
visitChildren() method to implement all the graphics operations |
1125 |
|
that requires traversal of the containment hierarchy. */ |
1126 |
|
|
1127 |
|
abstract static class GfxVisitor |
1128 |
|
{ |
1129 |
|
public abstract void visit(Component c, Graphics gfx); |
1130 |
|
} |
1131 |
|
|
1132 |
|
static class GfxPaintVisitor extends GfxVisitor |
1133 |
|
{ |
1134 |
|
public void visit(Component c, Graphics gfx) { c.paint(gfx); } |
1135 |
|
public static final GfxVisitor INSTANCE = new GfxPaintVisitor(); |
1136 |
|
} |
1137 |
|
|
1138 |
|
static class GfxPrintVisitor extends GfxVisitor |
1139 |
|
{ |
1140 |
|
public void visit(Component c, Graphics gfx) { c.print(gfx); } |
1141 |
|
public static final GfxVisitor INSTANCE = new GfxPrintVisitor(); |
1142 |
|
} |
1143 |
|
|
1144 |
|
static class GfxPaintAllVisitor extends GfxVisitor |
1145 |
|
{ |
1146 |
|
public void visit(Component c, Graphics gfx) { c.paintAll(gfx); } |
1147 |
|
public static final GfxVisitor INSTANCE = new GfxPaintAllVisitor(); |
1148 |
|
} |
1149 |
|
|
1150 |
|
static class GfxPrintAllVisitor extends GfxVisitor |
1151 |
|
{ |
1152 |
|
public void visit(Component c, Graphics gfx) { c.printAll(gfx); } |
1153 |
|
public static final GfxVisitor INSTANCE = new GfxPrintAllVisitor(); |
1154 |
|
} |
1155 |
|
|
1156 |
/** |
/** |
1157 |
* This class provides accessibility support for subclasses of container. |
* This class provides accessibility support for subclasses of container. |
1158 |
* |
* |
1274 |
} // class AccessibleContainerHandler |
} // class AccessibleContainerHandler |
1275 |
} // class AccessibleAWTPanel |
} // class AccessibleAWTPanel |
1276 |
} // class Container |
} // class Container |
1277 |
|
|
1278 |
|
|
1279 |
|
/** |
1280 |
|
* Undocumented helper class. |
1281 |
|
* STUBBED |
1282 |
|
*/ |
1283 |
|
class LightweightDispatcher implements Serializable, AWTEventListener |
1284 |
|
{ |
1285 |
|
private static final long serialVersionUID = 5184291520170872969L; |
1286 |
|
private Container nativeContainer; |
1287 |
|
private Component focus; |
1288 |
|
private transient Component mouseEventTarget; |
1289 |
|
private transient Component targetLastEntered; |
1290 |
|
private transient boolean isMouseInNativeContainer; |
1291 |
|
private Cursor nativeCursor; |
1292 |
|
private long eventMask; |
1293 |
|
LightweightDispatcher(Container c) |
1294 |
|
{ |
1295 |
|
} |
1296 |
|
void dispose() |
1297 |
|
{ |
1298 |
|
} |
1299 |
|
void enableEvents(long l) |
1300 |
|
{ |
1301 |
|
} |
1302 |
|
boolean dispatchEvent(AWTEvent e) |
1303 |
|
{ |
1304 |
|
return true; |
1305 |
|
} |
1306 |
|
boolean isMouseGrab(MouseEvent e) |
1307 |
|
{ |
1308 |
|
return true; |
1309 |
|
} |
1310 |
|
boolean processMouseEvent(MouseEvent e) |
1311 |
|
{ |
1312 |
|
return true; |
1313 |
|
} |
1314 |
|
void trackMouseEnterExit(Component c, MouseEvent e) |
1315 |
|
{ |
1316 |
|
} |
1317 |
|
void startListeningForOtherDrags() |
1318 |
|
{ |
1319 |
|
} |
1320 |
|
void stopListeningForOtherDrags() |
1321 |
|
{ |
1322 |
|
} |
1323 |
|
public void eventDispatched(AWTEvent e) |
1324 |
|
{ |
1325 |
|
} |
1326 |
|
void retargetMouseEvent(Component c, int i, MouseEvent e) |
1327 |
|
{ |
1328 |
|
} |
1329 |
|
} // class LightweightDispatcher |