Index: awt/src/main/java/common/java/awt/KeyboardFocusManager.java =================================================================== --- awt/src/main/java/common/java/awt/KeyboardFocusManager.java (revision 485572) +++ awt/src/main/java/common/java/awt/KeyboardFocusManager.java (working copy) @@ -18,6 +18,7 @@ package java.awt; import java.awt.event.FocusEvent; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; import java.beans.PropertyChangeListener; @@ -26,67 +27,105 @@ import java.beans.VetoableChangeListener; import java.beans.VetoableChangeSupport; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Vector; +import javax.swing.KeyStroke; + import org.apache.harmony.awt.internal.nls.Messages; -public abstract class KeyboardFocusManager implements KeyEventDispatcher, KeyEventPostProcessor { - public static final int FORWARD_TRAVERSAL_KEYS = 0; +public abstract class KeyboardFocusManager implements KeyEventDispatcher, + KeyEventPostProcessor { + public static final int FORWARD_TRAVERSAL_KEYS = 0; - public static final int BACKWARD_TRAVERSAL_KEYS = 1; + public static final int BACKWARD_TRAVERSAL_KEYS = 1; - public static final int UP_CYCLE_TRAVERSAL_KEYS = 2; + public static final int UP_CYCLE_TRAVERSAL_KEYS = 2; - public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3; + public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3; - final static int[] compTraversalIDs = { FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, - UP_CYCLE_TRAVERSAL_KEYS }; + final static int[] compTraversalIDs = { + FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, + UP_CYCLE_TRAVERSAL_KEYS }; - final static int[] contTraversalIDs = { FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, - UP_CYCLE_TRAVERSAL_KEYS, DOWN_CYCLE_TRAVERSAL_KEYS }; + final static int[] contTraversalIDs = { + FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, + UP_CYCLE_TRAVERSAL_KEYS, DOWN_CYCLE_TRAVERSAL_KEYS }; - private final Map> defaultFocusTraversalKeys = new HashMap>(); + private FocusTraversalPolicy defaultFocusTraversalPolicy = new DefaultFocusTraversalPolicy(); - private FocusTraversalPolicy defaultFocusTraversalPolicy = new DefaultFocusTraversalPolicy(); - // focus state is static, i. e. 1 per class loader: - static Component focusOwner; + static Component focusOwner; - static Component actualFocusOwner; + static Component actualFocusOwner; - private static Component actualPrevFocusOwner; + private static Component actualPrevFocusOwner; - private static Component permanentFocusOwner; + private static Component permanentFocusOwner; - private static Container currentFocusCycleRoot; + private static Container currentFocusCycleRoot; - static Window activeWindow; + static Window activeWindow; - private static Window actualActiveWindow; + private static Window actualActiveWindow; - static Window focusedWindow; + static Window focusedWindow; - static Window actualFocusedWindow; + static Window actualFocusedWindow; - private static Window prevFocusedWindow; + private static Window prevFocusedWindow; - private final Vector keyEventDispatchers = new Vector(); + private static final Set DEFAULT_FWD_KS; - private final Vector keyEventPostProcessors = new Vector(); + private static final Set DEFAULT_BWD_KS; - private PropertyChangeSupport propertyChangeSupport; + private static final Set EMPTY_UNMOD_SET; - private VetoableChangeSupport vetoableChangeSupport; + private static final String TK_NAMES[] = { + "forwardDefaultFocusTraversalKeys", //$NON-NLS-1$ + "backwardDefaultFocusTraversalKeys", //$NON-NLS-1$ + "upCycleDefaultFocusTraversalKeys", //$NON-NLS-1$ + "downCycleDefaultFocusTraversalKeys" }; //$NON-NLS-1$ - // private final Toolkit toolkit = Toolkit.getDefaultToolkit(); + private final Vector keyEventDispatchers = new Vector(); + + private final Vector keyEventPostProcessors = new Vector(); + + private PropertyChangeSupport propertyChangeSupport; + + private VetoableChangeSupport vetoableChangeSupport; + + private final Set[] ftk; + + static { + Set s = Collections.emptySet(); + + EMPTY_UNMOD_SET = Collections.unmodifiableSet(s); + + s = new LinkedHashSet(); + s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0)); + s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, + InputEvent.CTRL_DOWN_MASK)); + DEFAULT_FWD_KS = Collections.unmodifiableSet(s); + + s = new LinkedHashSet(); + s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, + InputEvent.SHIFT_DOWN_MASK)); + s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, + InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)); + DEFAULT_BWD_KS = Collections.unmodifiableSet(s); + } + public KeyboardFocusManager() { - for (int element : contTraversalIDs) { - defaultFocusTraversalKeys.put(new Integer(element), null); - } + ftk = new Set[4]; + ftk[0] = DEFAULT_FWD_KS; + ftk[1] = DEFAULT_BWD_KS; + ftk[2] = EMPTY_UNMOD_SET; + ftk[3] = EMPTY_UNMOD_SET; } public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) { @@ -97,8 +136,10 @@ keyEventPostProcessors.add(processor); } - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener); + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + getPropertyChangeSupport().addPropertyChangeListener(propertyName, + listener); } public void addPropertyChangeListener(PropertyChangeListener listener) { @@ -109,13 +150,16 @@ getVetoableChangeSupport().addVetoableChangeListener(listener); } - public void addVetoableChangeListener(String propertyName, VetoableChangeListener listener) { - getVetoableChangeSupport().addVetoableChangeListener(propertyName, listener); + public void addVetoableChangeListener(String propertyName, + VetoableChangeListener listener) { + getVetoableChangeSupport().addVetoableChangeListener(propertyName, + listener); } public void clearGlobalFocusOwner() { if (focusOwner != null) { - setFocus(focusOwner, focusOwner.getWindowAncestor(), false, null, false, true); + setFocus(focusOwner, focusOwner.getWindowAncestor(), false, null, + false, true); } } @@ -138,13 +182,16 @@ protected abstract void enqueueKeyEvents(long a0, Component a1); - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - getPropertyChangeSupport().firePropertyChange(propertyName, oldValue, newValue); + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + getPropertyChangeSupport().firePropertyChange(propertyName, oldValue, + newValue); } - protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) - throws PropertyVetoException { - getVetoableChangeSupport().fireVetoableChange(propertyName, oldValue, newValue); + protected void fireVetoableChange(String propertyName, Object oldValue, + Object newValue) throws PropertyVetoException { + getVetoableChangeSupport().fireVetoableChange(propertyName, oldValue, + newValue); } public final void focusNextComponent() { @@ -180,11 +227,13 @@ } } - @SuppressWarnings("unchecked") public Set getDefaultFocusTraversalKeys(int id) { - Integer kId = Integer.valueOf(id); - checkTraversalKeysID(defaultFocusTraversalKeys, kId); - return (Set) defaultFocusTraversalKeys.get(kId); + if ((id < 0) || (id > 3)) { + // awt.78=invalid focus traversal key identifier + throw new IllegalArgumentException(Messages.getString("awt.78")); //$NON-NLS-1$ + } + + return ftk[id]; } public FocusTraversalPolicy getDefaultFocusTraversalPolicy() { @@ -206,7 +255,8 @@ return activeWindow; } - protected Container getGlobalCurrentFocusCycleRoot() throws SecurityException { + protected Container getGlobalCurrentFocusCycleRoot() + throws SecurityException { checkInstance(); // TODO: get global current focus cycle root somehow // (not from the current class loader) @@ -223,12 +273,13 @@ /** * This method will throw a SecurityException if this KeyboardFocusManager * is not the current KeyboardFocusManager for the calling thread's context. - * + * * @throws SecurityException */ private void checkInstance() throws SecurityException { if (getCurrentKeyboardFocusManager() != this) { - // awt.7C=this KeyboardFocusManager is not installed in the current thread's context + // awt.7C=this KeyboardFocusManager is not installed in the current + // thread's context throw new SecurityException(Messages.getString("awt.7C")); //$NON-NLS-1$ } } @@ -265,12 +316,16 @@ return getPropertyChangeSupport().getPropertyChangeListeners(); } - public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { - return getPropertyChangeSupport().getPropertyChangeListeners(propertyName); + public PropertyChangeListener[] getPropertyChangeListeners( + String propertyName) { + return getPropertyChangeSupport().getPropertyChangeListeners( + propertyName); } - public VetoableChangeListener[] getVetoableChangeListeners(String propertyName) { - return getVetoableChangeSupport().getVetoableChangeListeners(propertyName); + public VetoableChangeListener[] getVetoableChangeListeners( + String propertyName) { + return getVetoableChangeSupport().getVetoableChangeListeners( + propertyName); } public VetoableChangeListener[] getVetoableChangeListeners() { @@ -296,7 +351,8 @@ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener); + getPropertyChangeSupport().removePropertyChangeListener(propertyName, + listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { @@ -309,11 +365,12 @@ public void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener) { - getVetoableChangeSupport().removeVetoableChangeListener(propertyName, listener); + getVetoableChangeSupport().removeVetoableChangeListener(propertyName, + listener); } - public static void setCurrentKeyboardFocusManager(KeyboardFocusManager newManager) - throws SecurityException { + public static void setCurrentKeyboardFocusManager( + KeyboardFocusManager newManager) throws SecurityException { KeyboardFocusManager oldManager; final Toolkit toolkit = Toolkit.getDefaultToolkit(); toolkit.lockAWT(); @@ -324,8 +381,8 @@ secMan.checkPermission(new AWTPermission(permission)); } oldManager = toolkit.currentKeyboardFocusManager; - toolkit.currentKeyboardFocusManager = ((newManager != null) ? newManager - : new DefaultKeyboardFocusManager()); + toolkit.currentKeyboardFocusManager = ((newManager != null) + ? newManager : new DefaultKeyboardFocusManager()); } finally { toolkit.unlockAWT(); } @@ -334,36 +391,56 @@ } String propName = "managingFocus"; //$NON-NLS-1$ if (oldManager != null) { - oldManager.firePropertyChange(propName, Boolean.TRUE, Boolean.FALSE); + oldManager + .firePropertyChange(propName, Boolean.TRUE, Boolean.FALSE); } newManager.firePropertyChange(propName, Boolean.FALSE, Boolean.TRUE); } - public void setDefaultFocusTraversalKeys(int id, Set keystrokes) { - Integer kId = Integer.valueOf(id); - Set oldKeyStrokes = defaultFocusTraversalKeys.get(kId); - checkTraversalKeysID(defaultFocusTraversalKeys, kId); - checkKeyStrokes(contTraversalIDs, defaultFocusTraversalKeys, kId, keystrokes); - defaultFocusTraversalKeys.put(kId, keystrokes); - String propName = null; - switch (id) { - case FORWARD_TRAVERSAL_KEYS: - propName = "forwardDefaultFocusTraversalKeys"; //$NON-NLS-1$ - break; - case BACKWARD_TRAVERSAL_KEYS: - propName = "backwardDefaultFocusTraversalKeys"; //$NON-NLS-1$ - break; - case UP_CYCLE_TRAVERSAL_KEYS: - propName = "upCycleDefaultFocusTraversalKeys"; //$NON-NLS-1$ - break; - case DOWN_CYCLE_TRAVERSAL_KEYS: - propName = "downCycleDefaultFocusTraversalKeys"; //$NON-NLS-1$ - break; + public void setDefaultFocusTraversalKeys(int id, + Set keystrokes) { + final Set old; + + if ((id < 0) || (id > 3)) { + // awt.78=invalid focus traversal key identifier + throw new IllegalArgumentException(Messages.getString("awt.78")); //$NON-NLS-1$ } - firePropertyChange(propName, oldKeyStrokes, keystrokes); + + if (keystrokes == null) { + throw new IllegalArgumentException(Messages.getString( + "awt.01", "keystrokes")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + old = ftk[id]; + + for (AWTKeyStroke ks : keystrokes) { + if (ks == null) { + // awt.79=cannot set null focus traversal key + throw new IllegalArgumentException(Messages.getString("awt.79")); //$NON-NLS-1$ + } + + if (ks.getKeyEventType() == KeyEvent.KEY_TYPED) { + // awt.7A=focus traversal keys cannot map to KEY_TYPED + // events + throw new IllegalArgumentException(Messages.getString("awt.7A")); //$NON-NLS-1$ + } + + for (int i = 0; i < 4; i++) { + if ((i != id) && ftk[i].contains(ks)) { + // awt.7B=focus traversal keys must be unique for a + // Component + throw new IllegalArgumentException(Messages + .getString("awt.7B")); //$NON-NLS-1$ + } + } + } + + ftk[id] = Collections.unmodifiableSet(keystrokes); + firePropertyChange(TK_NAMES[id], old, keystrokes); } - public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy defaultPolicy) { + public void setDefaultFocusTraversalPolicy( + FocusTraversalPolicy defaultPolicy) { if (defaultPolicy == null) { // awt.77=default focus traversal policy cannot be null throw new IllegalArgumentException(Messages.getString("awt.77")); //$NON-NLS-1$ @@ -379,7 +456,8 @@ // fire Vetoable change[before it is reflected in Java focus state], // catch veto exception try { - fireVetoableChange(propName, KeyboardFocusManager.activeWindow, activeWindow); + fireVetoableChange(propName, KeyboardFocusManager.activeWindow, + activeWindow); } catch (PropertyVetoException e) { // abort the change, i. e. // don't reflect the change in KFM, don't report to property change @@ -388,13 +466,15 @@ } Window oldActiveWindow = KeyboardFocusManager.activeWindow; KeyboardFocusManager.activeWindow = activeWindow; - firePropertyChange(propName, oldActiveWindow, KeyboardFocusManager.activeWindow); + firePropertyChange(propName, oldActiveWindow, + KeyboardFocusManager.activeWindow); } public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) { Container oldFocusCycleRoot = currentFocusCycleRoot; currentFocusCycleRoot = newFocusCycleRoot; - firePropertyChange("currentFocusCycleRoot", oldFocusCycleRoot, currentFocusCycleRoot); //$NON-NLS-1$ + firePropertyChange( + "currentFocusCycleRoot", oldFocusCycleRoot, currentFocusCycleRoot); //$NON-NLS-1$ } protected void setGlobalFocusOwner(Component focusOwner) { @@ -402,7 +482,8 @@ // fire Vetoable change[before it is reflected in Java focus state], // catch veto exception try { - fireVetoableChange(propName, KeyboardFocusManager.focusOwner, focusOwner); + fireVetoableChange(propName, KeyboardFocusManager.focusOwner, + focusOwner); } catch (PropertyVetoException e) { // abort the change, i. e. // don't reflect the change in KFM, don't report to property change @@ -412,18 +493,21 @@ Component oldFocusOwner = KeyboardFocusManager.focusOwner; if ((focusOwner == null) || focusOwner.isFocusable()) { KeyboardFocusManager.focusOwner = focusOwner; - if ((focusOwner != null) && focusOwner != getCurrentFocusCycleRoot()) { - //don't clear current focus cycle root every time a component - //is losing focus - //TODO: do it[clear] somewhere else(maybe Window.dispose()??) - Container root = ((focusOwner instanceof Window) ? (Window) focusOwner - : focusOwner.getFocusCycleRootAncestor()); + if ((focusOwner != null) + && focusOwner != getCurrentFocusCycleRoot()) { + // don't clear current focus cycle root every time a component + // is losing focus + // TODO: do it[clear] somewhere else(maybe Window.dispose()??) + Container root = ((focusOwner instanceof Window) + ? (Window) focusOwner : focusOwner + .getFocusCycleRootAncestor()); if (root == null || root.isFocusCycleRoot()) { setGlobalCurrentFocusCycleRoot(root); } } } - firePropertyChange(propName, oldFocusOwner, KeyboardFocusManager.focusOwner); + firePropertyChange(propName, oldFocusOwner, + KeyboardFocusManager.focusOwner); } protected void setGlobalFocusedWindow(Window focusedWindow) { @@ -431,7 +515,8 @@ // fire Vetoable change[before it is reflected in Java focus state], // catch veto exception try { - fireVetoableChange(propName, KeyboardFocusManager.focusedWindow, focusedWindow); + fireVetoableChange(propName, KeyboardFocusManager.focusedWindow, + focusedWindow); } catch (PropertyVetoException e) { // abort the change, i. e. // don't reflect the change in KFM, don't report to property change @@ -442,7 +527,8 @@ if (focusedWindow == null || focusedWindow.isFocusableWindow()) { KeyboardFocusManager.focusedWindow = focusedWindow; } - firePropertyChange(propName, oldFocusedWindow, KeyboardFocusManager.focusedWindow); + firePropertyChange(propName, oldFocusedWindow, + KeyboardFocusManager.focusedWindow); } protected void setGlobalPermanentFocusOwner(Component permanentFocusOwner) { @@ -450,7 +536,8 @@ // fire Vetoable change[before it is reflected in Java focus state], // catch veto exception try { - fireVetoableChange(propName, KeyboardFocusManager.permanentFocusOwner, + fireVetoableChange(propName, + KeyboardFocusManager.permanentFocusOwner, permanentFocusOwner); } catch (PropertyVetoException e) { // abort the change, i. e. @@ -481,11 +568,17 @@ } static void checkKeyStrokes(int[] traversalIDs, - Map> traversalKeys, Integer kId, - Set keystrokes) { - if (keystrokes == null || keystrokes.isEmpty()) { + Map> traversalKeys, + Integer kId, Set keystrokes) { + if (keystrokes == null) { + throw new IllegalArgumentException(Messages.getString( + "awt.01", "keystrokes")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + if (keystrokes.isEmpty()) { return; } + for (AWTKeyStroke key : keystrokes) { if (key == null) { // awt.79=cannot set null focus traversal key @@ -500,17 +593,18 @@ for (int element : traversalIDs) { Integer theID = Integer.valueOf(element); Set val = traversalKeys.get(theID); - if ((!theID.equals(kId)) && - val != null && - val.contains(key)) { - // awt.7B=focus traversal keys must be unique for a Component - throw new IllegalArgumentException(Messages.getString("awt.7B")); //$NON-NLS-1$ + if ((!theID.equals(kId)) && val != null && val.contains(key)) { + // awt.7B=focus traversal keys must be unique for a + // Component + throw new IllegalArgumentException(Messages + .getString("awt.7B")); //$NON-NLS-1$ } } } } - boolean requestFocus(Component c, boolean temporary, boolean crossWindow, boolean callCB) { + boolean requestFocus(Component c, boolean temporary, boolean crossWindow, + boolean callCB) { Window wnd = ((c != null) ? c.getWindowAncestor() : null); return requestFocus(c, wnd, temporary, crossWindow, callCB); } @@ -521,8 +615,8 @@ * Component's request focus callCB is set to true, when called directly * from native event dispatching code - to false. */ - boolean requestFocus(Component c, Window wnd, boolean temporary, boolean crossWindow, - boolean callCB) { + boolean requestFocus(Component c, Window wnd, boolean temporary, + boolean crossWindow, boolean callCB) { Window focusedWnd = actualFocusedWindow; Window activeWnd = actualActiveWindow; // don't take focus from other applications: @@ -547,10 +641,10 @@ wnd.behaviour.setFocus(true, focusedWnd); // try to change // focusedWindow(?) } - // if (!wnd.isFocused()) { - // return false; //async focus - wait until window actually gains - // // focus - // } + // if (!wnd.isFocused()) { + // return false; //async focus - wait until window actually gains + // // focus + // } wnd.setRequestedFocus(c); setFocus(c, wnd, true, actualPrevFocusOwner, temporary, callCB); if (wnd != null) { @@ -561,8 +655,8 @@ } /** - * Perform additional checks to determine if a Window can - * become focused + * Perform additional checks to determine if a Window can become focused + * * @param wnd * @return */ @@ -584,7 +678,8 @@ Frame getOwningFrame(Window w) { Window wnd; - for (wnd = w; (wnd != null) && !(wnd instanceof Frame); wnd = wnd.getOwner()) { + for (wnd = w; (wnd != null) && !(wnd instanceof Frame); wnd = wnd + .getOwner()) { ; } return (Frame) wnd; @@ -593,15 +688,14 @@ /** * all focus related events are posted to EventQueue and internal(non-Java) * focus state is updated to be able to post some events correctly As - * opposed to focus spec user-defined KeyboardFocusManager doesn't - * have to take care about proper event ordering: events are posted in - * proper order + * opposed to focus spec user-defined KeyboardFocusManager doesn't have to + * take care about proper event ordering: events are posted in proper order */ void setFocus(Component c, Window wnd, boolean focus, Component opposite, boolean temporary, boolean callCB) { Window focusedWnd = actualFocusedWindow; - Window oppositeAncestorWnd = ((opposite != null) ? opposite.getWindowAncestor() - : (focus ? focusedWnd : null)); + Window oppositeAncestorWnd = ((opposite != null) ? opposite + .getWindowAncestor() : (focus ? focusedWnd : null)); Window ancestorWnd = (!focus ? focusedWnd : wnd); if (!focus && (ancestorWnd == null)) { ancestorWnd = actualActiveWindow; @@ -613,18 +707,22 @@ // when losing focus to some component in other window // post temporary event: if (!focus && (opposite != null) && !callCB) { - temporary = (c.getWindowAncestor() != opposite.getWindowAncestor()); + temporary = (c.getWindowAncestor() != opposite + .getWindowAncestor()); } - FocusEvent newEvent = new FocusEvent(c, focus ? FocusEvent.FOCUS_GAINED - : FocusEvent.FOCUS_LOST, temporary, opposite); + FocusEvent newEvent = new FocusEvent(c, focus + ? FocusEvent.FOCUS_GAINED : FocusEvent.FOCUS_LOST, + temporary, opposite); // remember previous focus owner to be able to post it as opposite // later // [when opposite component gains focus] // but clear it if application loses focus if (!focus) { - actualPrevFocusOwner = ((opposite != null) ? actualFocusOwner : null); + actualPrevFocusOwner = ((opposite != null) ? actualFocusOwner + : null); } - actualFocusOwner = (focus ? c : ((c == actualFocusOwner) ? null : actualFocusOwner)); + actualFocusOwner = (focus ? c : ((c == actualFocusOwner) ? null + : actualFocusOwner)); c.postEvent(newEvent); } // post window events when losing focus only if @@ -641,8 +739,8 @@ } /** - * set focus to the appropriate child Component of the given Window - * as if it is the focused Window + * set focus to the appropriate child Component of the given Window as if it + * is the focused Window */ boolean requestFocusInWindow(Window wnd, boolean callCB) { if (wnd == null) { @@ -654,10 +752,12 @@ wnd.setRequestedFocus(null); } Component lastFocusOwner = wnd.getMostRecentFocusOwner(); - if ((lastFocusOwner != null) && lastFocusOwner.getWindowAncestor() != wnd) { + if ((lastFocusOwner != null) + && lastFocusOwner.getWindowAncestor() != wnd) { lastFocusOwner = null; } - Component compToFocus = ((lastReqFocus != null) ? lastReqFocus : lastFocusOwner); + Component compToFocus = ((lastReqFocus != null) ? lastReqFocus + : lastFocusOwner); if (compToFocus != null) { return requestFocus(compToFocus, wnd, false, false, callCB); } @@ -667,13 +767,13 @@ } /** - * all focus related WindowEvents are posted to EventQueue - * and internal(non-Java) focus state is immediately updated - * (Java focus state is updated only right before actually - * dispatching these events to components) - * Activation events are also posted from here, so + * all focus related WindowEvents are posted to EventQueue and + * internal(non-Java) focus state is immediately updated (Java focus state + * is updated only right before actually dispatching these events to + * components) Activation events are also posted from here, so * KeyboardFocusManager(if replaced by user) doesn't have to care about * "synthesizing" them, as opposed to focus spec. + * * @return - true if focused Window changed */ boolean postWindowEvent(Window wnd, Window opposite, boolean focus) { @@ -686,13 +786,14 @@ if ((opposite == null) && (prevFocusedWindow != null)) { opposite = prevFocusedWindow; } - Window oppositeDecorWnd = ((opposite != null) ? opposite.getFrameDialogOwner() : null); - boolean focusedWindowChanged = ((wnd != null) && (focus ? focusedWnd != wnd - : opposite != wnd)); - boolean activeWindowChanged = ((decorWnd != null) && (focus ? actualActiveWindow != decorWnd - : oppositeDecorWnd != decorWnd)); - WindowEvent activationEvent = (activeWindowChanged ? new WindowEvent(decorWnd, - activationEventId, oppositeDecorWnd) : null); + Window oppositeDecorWnd = ((opposite != null) ? opposite + .getFrameDialogOwner() : null); + boolean focusedWindowChanged = ((wnd != null) && (focus + ? focusedWnd != wnd : opposite != wnd)); + boolean activeWindowChanged = ((decorWnd != null) && (focus + ? actualActiveWindow != decorWnd : oppositeDecorWnd != decorWnd)); + WindowEvent activationEvent = (activeWindowChanged ? new WindowEvent( + decorWnd, activationEventId, oppositeDecorWnd) : null); if (activeWindowChanged && focus) { decorWnd.postEvent(activationEvent); actualActiveWindow = decorWnd;