/** * "Captures" the mouse, causing all mouse input to be delegated to the * given component rather than propagating down the component hierarchy. * * @param capturerArgument * The component that wants to capture the mouse. The mouse pointer must * currently be over the component. */ public static void capture(Component capturerArgument) { if (capturerArgument == null) { throw new IllegalArgumentException("capturer is null."); } if (!capturerArgument.isMouseOver()) { throw new IllegalArgumentException("Mouse pointer is not currently over capturer."); } if (Mouse.capturer != null) { throw new IllegalStateException("Mouse is already captured."); } Mouse.capturer = capturerArgument; }
/** * "Captures" the mouse, causing all mouse input to be delegated to the * given component rather than propagating down the component hierarchy. * * @param capturer * The component that wants to capture the mouse. The mouse pointer must * currently be over the component. */ public static void capture(Component capturer) { if (capturer == null) { throw new IllegalArgumentException("capturer is null."); } if (!capturer.isMouseOver()) { throw new IllegalArgumentException("Mouse pointer is not currently over capturer."); } if (Mouse.capturer != null) { throw new IllegalStateException("Mouse is already captured."); } Mouse.capturer = capturer; }
@Override protected void mouseOut() { // Ensure that mouse out is called on descendant components if (mouseOverComponent != null && mouseOverComponent.isMouseOver()) { mouseOverComponent.mouseOut(); } mouseOverComponent = null; super.mouseOut(); }
@Override protected void mouseOut() { // Ensure that mouse out is called on descendant components if (mouseOverComponent != null && mouseOverComponent.isMouseOver()) { mouseOverComponent.mouseOut(); } mouseOverComponent = null; super.mouseOut(); }
/** * Sets the cursor that is displayed when the mouse pointer is over * this component. * * @param cursor * The cursor to display over the component, or <tt>null</tt> to inherit * the cursor of the parent container. */ public void setCursor(Cursor cursor) { Cursor previousCursor = this.cursor; if (previousCursor != cursor) { this.cursor = cursor; if (isMouseOver()) { Mouse.setCursor(this); } componentListeners.cursorChanged(this, previousCursor); } }
/** * Sets the cursor that is displayed when the mouse pointer is over * this component. * * @param cursor * The cursor to display over the component, or <tt>null</tt> to inherit * the cursor of the parent container. */ public void setCursor(Cursor cursor) { Cursor previousCursor = this.cursor; if (previousCursor != cursor) { this.cursor = cursor; if (isMouseOver()) { Mouse.setCursor(this); } componentListeners.cursorChanged(this, previousCursor); } }
/** * Sets the component's enabled state. Enabled components respond to user * input events; disabled components do not. * * @param enabled * <tt>true</tt> if the component is enabled; <tt>false</tt>, otherwise. */ public void setEnabled(boolean enabled) { if (this.enabled != enabled) { if (!enabled) { // If this component has the focus, clear it if (isFocused()) { clearFocus(); } // Ensure that the mouse out event is processed if (isMouseOver()) { mouseOut(); } } this.enabled = enabled; componentStateListeners.enabledChanged(this); } }
/** * Sets the component's enabled state. Enabled components respond to user * input events; disabled components do not. * * @param enabled * <tt>true</tt> if the component is enabled; <tt>false</tt>, otherwise. */ public void setEnabled(boolean enabled) { if (this.enabled != enabled) { if (!enabled) { // If this component has the focus, clear it if (isFocused()) { clearFocus(); } // Ensure that the mouse out event is processed if (isMouseOver()) { mouseOut(); } } this.enabled = enabled; componentStateListeners.enabledChanged(this); } }
/** * If the mouse is currently over the component, causes the component to * fire <tt>mouseOut()</tt> and a <tt>mouseMove()</tt> at the current mouse * location. * <p> * This method is primarily useful when consuming container mouse motion * events, since it allows a caller to reset the mouse state based on the * event consumption logic. */ public void reenterMouse() { if (isMouseOver()) { mouseOut(); Display display = getDisplay(); Point location = display.getMouseLocation(); location = mapPointFromAncestor(display, x, y); mouseMove(location.x, location.y); } }
/** * If the mouse is currently over the component, causes the component to * fire <tt>mouseOut()</tt> and a <tt>mouseMove()</tt> at the current mouse * location. * <p> * This method is primarily useful when consuming container mouse motion * events, since it allows a caller to reset the mouse state based on the * event consumption logic. */ public void reenterMouse() { if (isMouseOver()) { mouseOut(); Display display = getDisplay(); Point location = display.getMouseLocation(); location = mapPointFromAncestor(display, x, y); mouseMove(location.x, location.y); } }
if (!component.isMouseOver()) { component.mouseOver();
if (!component.isMouseOver()) { component.mouseOver();
@Override protected boolean mouseWheel(Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) { boolean consumed = false; if (isEnabled()) { // Notify container listeners consumed = containerMouseListeners.mouseWheel(this, scrollType, scrollAmount, wheelRotation, x, y); if (!consumed) { // Propagate event to subcomponents Component component = getComponentAt(x, y); if (component != null) { // Ensure that mouse over is called if (!component.isMouseOver()) { component.mouseOver(); } consumed = component.mouseWheel(scrollType, scrollAmount, wheelRotation, x - component.getX(), y - component.getY()); } // Notify the base class if (!consumed) { consumed = super.mouseWheel(scrollType, scrollAmount, wheelRotation, x, y); } } } return consumed; }
@Override protected boolean mouseWheel(Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) { boolean consumed = false; if (isEnabled()) { // Notify container listeners consumed = containerMouseListeners.mouseWheel(this, scrollType, scrollAmount, wheelRotation, x, y); if (!consumed) { // Propagate event to subcomponents Component component = getComponentAt(x, y); if (component != null) { // Ensure that mouse over is called if (!component.isMouseOver()) { component.mouseOver(); } consumed = component.mouseWheel(scrollType, scrollAmount, wheelRotation, x - component.getX(), y - component.getY()); } // Notify the base class if (!consumed) { consumed = super.mouseWheel(scrollType, scrollAmount, wheelRotation, x, y); } } } return consumed; }
@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; }
@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; }
if (isMouseOver()) { mouseOut();
&& !mouseOverComponent.isMouseOver()) { mouseOverComponent = null;
if (!component.isMouseOver()) { component.mouseOver();
if (!component.isMouseOver()) { component.mouseOver();