static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) { synchronized (heavyweightRequests) { // Any other case represents a failure condition which we did // not expect. We need to clearFocusRequestList() and patch up // the event as best as possible. if (removeFirstRequest()) { return (FocusEvent)retargetFocusEvent(fe); } Component source = fe.getComponent(); Component opposite = fe.getOppositeComponent(); boolean temporary = false; if (fe.getID() == FocusEvent.FOCUS_LOST && (opposite == null || isTemporary(opposite, source))) { temporary = true; } return new CausedFocusEvent(source, fe.getID(), temporary, opposite, CausedFocusEvent.Cause.NATIVE_SYSTEM); } }
boolean addLightweightRequest(Component descendant, boolean temporary, CausedFocusEvent.Cause cause) { if (log.isLoggable(PlatformLogger.Level.FINE)) { if (this == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) { log.fine("Assertion (this != HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) failed"); } if (descendant == null) { log.fine("Assertion (descendant != null) failed"); } } Component lastDescendant = ((lightweightRequests.size() > 0) ? lightweightRequests.getLast().component : null); if (descendant != lastDescendant) { // Not a duplicate request lightweightRequests.add (new LightweightFocusRequest(descendant, temporary, cause)); return true; } else { return false; } }
boolean transferFocus(boolean clearOnFailure) { if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("clearOnFailure = " + clearOnFailure); } Component toFocus = getNextFocusCandidate(); boolean res = false; if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) { res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD); } if (clearOnFailure && !res) { if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("clear global focus owner"); } KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwnerPriv(); } if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("returning result: " + res); } return res; }
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent, boolean clearOnFailure) { if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() && toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK)) { return true; } else { Component nextFocus = toFocus.getNextFocusCandidate(); if (nextFocus != null && nextFocus != vetoedComponent && nextFocus.requestFocusInWindow(CausedFocusEvent.Cause.ROLLBACK)) { return true; } else if (clearOnFailure) { clearGlobalFocusOwnerPriv(); return true; } else { return false; } } }
@Override public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { if (!focusAllowedFor()) { return false; } if (getPlatformWindow().rejectFocusRequest(cause)) { return false; } Window opposite = LWKeyboardFocusManagerPeer.getInstance(). getCurrentFocusedWindow(); changeFocusedWindow(true, opposite); return true; }
public static boolean deliverFocus(Component lightweightChild, Component target, boolean temporary, boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause) { // TODO: do something to eliminate this forwarding return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild, target, temporary, focusedWindowChangeAllowed, time, cause, getNativeFocusOwner()); }
@Override public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { if (!focusAllowedFor()) { return false; } /*if (getPlatformWindow().rejectFocusRequest(cause)) { return false; }*/ Window opposite = LWKeyboardFocusManagerPeer.getInstance(). getCurrentFocusedWindow(); changeFocusedWindow(true, opposite); return true; }
public void processFocusEvent(FocusEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { if (e instanceof CausedFocusEvent) { if (((CausedFocusEvent) e).getCause() == CausedFocusEvent.Cause.TRAVERSAL_FORWARD) { if (impl.getModel().getRowCount() > 0) { // if focus from cell editor if (e.getSource() == impl && impl.getSelectedRow() >= 0) { int selectedColumn = impl.getSelectedColumn(); focusTo(impl.getSelectedRow(), selectedColumn >= 0 ? selectedColumn : 0); } else moveToStart(0, 0); } else impl.transferFocus(); } else if (((CausedFocusEvent) e).getCause() == CausedFocusEvent.Cause.TRAVERSAL_BACKWARD) { if (impl.getModel().getRowCount() > 0) { moveToEnd(impl.getRowCount() - 1, impl.getColumnCount() - 1); } else impl.transferFocusBackward(); } } } }
/** * Transfers the focus to the previous component, as though this Component * were the focus owner. * @see #requestFocus() * @since 1.4 */ public void transferFocusBackward() { Container rootAncestor = getFocusCycleRootAncestor(); Component comp = this; while (rootAncestor != null && !(rootAncestor.isShowing() && rootAncestor.isFocusable() && rootAncestor.isEnabled())) { comp = rootAncestor; rootAncestor = comp.getFocusCycleRootAncestor(); } if (rootAncestor != null) { FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy(); Component toFocus = policy.getComponentBefore(rootAncestor, comp); if (toFocus == null) { toFocus = policy.getDefaultComponent(rootAncestor); } if (toFocus != null) { toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD); } } }
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent, boolean clearOnFailure) { if (toFocus.isShowing() && toFocus.isFocusable() && toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK)) { return true; } else { Component nextFocus = toFocus.preNextFocusHelper(); if (nextFocus != vetoedComponent && Component.postNextFocusHelper(nextFocus)) { return true; } else if (clearOnFailure) { clearGlobalFocusOwner(); return true; } else { return false; } } }
boolean addLightweightRequest(Component descendant, boolean temporary, CausedFocusEvent.Cause cause) { if (log.isLoggable(PlatformLogger.FINE)) { if (this == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) { log.fine("Assertion (this != HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) failed"); } if (descendant == null) { log.fine("Assertion (descendant != null) failed"); } } Component lastDescendant = ((lightweightRequests.size() > 0) ? lightweightRequests.getLast().component : null); if (descendant != lastDescendant) { // Not a duplicate request lightweightRequests.add (new LightweightFocusRequest(descendant, temporary, cause)); return true; } else { return false; } }
boolean transferFocus(boolean clearOnFailure) { if (focusLog.isLoggable(PlatformLogger.FINER)) { focusLog.finer("clearOnFailure = " + clearOnFailure); } Component toFocus = getNextFocusCandidate(); boolean res = false; if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) { res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD); } if (clearOnFailure && !res) { if (focusLog.isLoggable(PlatformLogger.FINER)) { focusLog.finer("clear global focus owner"); } KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); } if (focusLog.isLoggable(PlatformLogger.FINER)) { focusLog.finer("returning result: " + res); } return res; }
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent, boolean clearOnFailure) { if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() && toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK)) { return true; } else { Component nextFocus = toFocus.getNextFocusCandidate(); if (nextFocus != null && nextFocus != vetoedComponent && nextFocus.requestFocusInWindow(CausedFocusEvent.Cause.ROLLBACK)) { return true; } else if (clearOnFailure) { clearGlobalFocusOwner(); return true; } else { return false; } } }