protected final void assertEventDispatchThread() { assertEventDispatchThread(this); }
@Override protected void setParent(Container parent) { // If this container is being removed from the component hierarchy // and contains the focused component, clear the focus if (parent == null && containsFocus()) { clearFocus(); } super.setParent(parent); }
protected void descendantAdded(Component descendant) { Container parent = getParent(); if (parent != null) { parent.descendantAdded(descendant); } }
public Component getDescendantAt(int x, int y) { Component component = getComponentAt(x, y); if (component instanceof Container) { Container container = (Container)component; component = container.getDescendantAt(x - container.getX(), y - container.getY()); } if (component == null) { component = this; } return component; }
protected void descendantGainedFocus(Component descendant, Component previousFocusedComponent) { Container parent = getParent(); if (parent != null) { parent.descendantGainedFocus(descendant, previousFocusedComponent); } }
protected void descendantLostFocus(Component descendant) { Container parent = getParent(); if (parent != null) { parent.descendantLostFocus(descendant); } }
@Override public void insert(Component component, int index) { assertEventDispatchThread(); if (component == null) { throw new IllegalArgumentException("component is null."); } if (component instanceof Container && ((Container)component).isAncestor(this)) { throw new IllegalArgumentException("Component already exists in ancestry."); } if (component.getParent() != null) { throw new IllegalArgumentException("Component already has a parent."); } component.setParent(Container.this); components.insert(component, index); // Repaint the area occupied by the new component repaint(component.getDecoratedBounds()); invalidate(); containerListeners.componentInserted(Container.this, index); }
if (isEnabled()) { Component component = getComponentAt(x, y);
@Override public void install(Component component) { super.install(component); Container container = (Container)component; // Add this as a container listener container.getContainerListeners().add(this); container.getContainerMouseListeners().add(this); // Set the focus traversal policy container.setFocusTraversalPolicy(DEFAULT_FOCUS_TRAVERSAL_POLICY); }
/** * Moves a component within the component sequence. * * @param from * @param to */ public void move(int from, int to) { assertEventDispatchThread(); if (from != to) { int n = components.getLength(); indexBoundsCheck("from", from, 0, n - 1); indexBoundsCheck("to", to, 0, n - 1); Sequence<Component> removed = components.remove(from, 1); Component component = removed.get(0); components.insert(component, to); // Repaint the area occupied by the component repaint(component.getDecoratedBounds()); // Notify listeners containerListeners.componentMoved(this, from, to); } }
@Override public Sequence<Component> remove(int index, int count) { assertEventDispatchThread(); Sequence<Component> removed = components.remove(index, count); // Set the removed components' parent to null and repaint the area // formerly occupied by the components for (int i = 0, n = removed.getLength(); i < n; i++) { Component component = removed.get(i); if (component == mouseOverComponent) { if (mouseOverComponent.isMouseOver()) { mouseOverComponent.mouseOut(); } mouseOverComponent = null; Mouse.setCursor(this); } repaint(component.getDecoratedBounds()); component.setParent(null); } if (removed.getLength() > 0) { invalidate(); containerListeners.componentsRemoved(Container.this, index, removed); } return removed; }
int n = container.getLength(); if (n > 0) { switch (direction) { nextComponent = container.get(0); } else { int index = container.indexOf(component); if (index == -1) { throw new IllegalArgumentException(); nextComponent = container.get(index + 1); } else { if (wrap) { nextComponent = container.get(0); nextComponent = container.get(n - 1); } else { int index = container.indexOf(component); if (index == -1) { throw new IllegalArgumentException(); nextComponent = container.get(index - 1); } else { if (wrap) { nextComponent = container.get(n - 1);
protected void descendantRemoved(Component descendant) { Container parent = getParent(); if (parent != null) { parent.descendantRemoved(descendant); } }
/** * Flags the component's hierarchy as invalid, and clears any cached * preferred size. */ public void invalidate() { Container.assertEventDispatchThread(this); valid = false; // Clear the preferred size and baseline preferredSize = null; baseline = -1; if (parent != null) { parent.invalidate(); } }
protected void setParent(Container parent) { // If this component is being removed from the component hierarchy // and is currently focused, clear the focus if (parent == null && isFocused()) { clearFocus(); } Container previousParent = this.parent; this.parent = parent; if (previousParent != null) { previousParent.descendantRemoved(this); } if (parent != null) { parent.descendantAdded(this); } componentListeners.parentChanged(this, previousParent); }
/** * Called to notify a component that its focus state has changed. * * @param focused * <tt>true</tt> if the component has received the input focus; * <tt>false</tt> if the component has lost the focus. * * @param obverseComponent * If <tt>focused</tt> is true, the component that has lost the focus; * otherwise, the component that has gained the focus. */ protected void setFocused(boolean focused, Component obverseComponent) { if (focused) { parent.descendantGainedFocus(this, obverseComponent); } else { parent.descendantLostFocus(this); } componentStateListeners.focusedChanged(this, obverseComponent); }
Container.assertEventDispatchThread(this); if (parent != null) { && height > 0) { parent.repaint(x + this.x, y + this.y, width, height, immediate); parent.repaint(tranformedBounds.x + this.x, tranformedBounds.y + this.y, tranformedBounds.width, tranformedBounds.height, immediate);
@Override protected void descendantRemoved(Component descendant) { super.descendantRemoved(descendant); if (descendant == focusDescendant) { focusDescendant = null; } }
@Override protected void descendantGainedFocus(Component descendant, Component previousFocusedComponent) { this.focusDescendant = descendant; super.descendantGainedFocus(descendant, previousFocusedComponent); }