@Override public void actionPerformed(ActionEvent e) { int selIndexBefore = getSelectedIndex(); defaultAction.actionPerformed( e ); int selIndexCurrent = getSelectedIndex(); if( selIndexBefore != selIndexCurrent ) return; if( focusNext && 0 == selIndexCurrent && getModel().getSize() > 1 && getModel().getSize() > getColumnCount() ) return; KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Container container = kfm.getCurrentFocusCycleRoot(); FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); if( null == policy ) policy = kfm.getDefaultFocusTraversalPolicy(); Component next = focusNext ? policy.getComponentAfter( container, CategoryList.this ) : policy.getComponentBefore( container, CategoryList.this ); if( null != next && next instanceof CategoryButton ) { clearSelection(); next.requestFocus(); } }
/** Opens a modal propertySheet on given Node * @param n the node to show properties for */ public void showProperties (Node n) { Dialog d = findCachedPropertiesDialog( n ); if( null == d ) { Node[] nds = new Node[] { n }; openProperties(new NbSheet(), nds); } else { d.setVisible( true ); //#131724 - PropertySheet clears its Nodes in removeNotify and keeps //only a weakref which is being reused in subsequent addNotify //so we should set the Nodes again in case the weakref got garbage collected //pls note that PropertySheet code checks for redundant calls of setNodes NbSheet sheet = findCachedSheet( d ); if( null != sheet ) sheet.setNodes(new Node[] { n }); d.toFront(); FocusTraversalPolicy ftp = d.getFocusTraversalPolicy(); if( null != ftp && null != ftp.getDefaultComponent(d) ) { ftp.getDefaultComponent(d).requestFocusInWindow(); } else { d.requestFocusInWindow(); } } }
/** Opens a modal propertySheet on given set of Nodes * @param n the array of nodes to show properties for */ public void showProperties (Node[] nodes) { Dialog d = findCachedPropertiesDialog( nodes ); if( null == d ) { openProperties(new NbSheet(), nodes); } else { d.setVisible( true ); //#131724 - PropertySheet clears its Nodes in removeNotify and keeps //only a weakref which is being reused in subsequent addNotify //so we should set the Nodes again in case the weakref got garbage collected //pls note that PropertySheet code checks for redundant calls of setNodes NbSheet sheet = findCachedSheet( d ); if( null != sheet ) sheet.setNodes(nodes); d.toFront(); FocusTraversalPolicy ftp = d.getFocusTraversalPolicy(); if( null != ftp && null != ftp.getDefaultComponent(d) ) { ftp.getDefaultComponent(d).requestFocusInWindow(); } else { d.requestFocusInWindow(); } } }
/** * Requests focus on a child of the spinner if the spinner doesn't have * focus. */ private void focusSpinnerIfNecessary() { Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if( spinner.isRequestFocusEnabled() && (fo == null || !SwingUtilities.isDescendingFrom(fo, spinner)) ) { Container root = spinner; if( !root.isFocusCycleRoot() ) { root = root.getFocusCycleRootAncestor(); } if( root != null ) { FocusTraversalPolicy ftp = root.getFocusTraversalPolicy(); Component child = ftp.getComponentAfter(root, spinner); if( child != null && SwingUtilities.isDescendingFrom(child, spinner) ) { child.requestFocus(); } } } }
public Component getComponentAfter(Container aContainer, Component aComponent) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getComponentAfter(root, aComponent); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getComponentAfter(root, aComponent); } return null; }
public Component getComponentBefore(Container aContainer, Component aComponent) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getComponentBefore(root, aComponent); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getComponentBefore(root, aComponent); } return null; }
public Component getFirstComponent(Container aContainer) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getFirstComponent(root); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getFirstComponent(root); } return null; }
public Component getLastComponent(Container aContainer) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getLastComponent(root); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getLastComponent(root); } return null; }
public static void test(Window win, Class<? extends FocusTraversalPolicy> expectedPolicy) { FocusTraversalPolicy ftp = win.getFocusTraversalPolicy(); System.out.println("==============" + "\n" + "Tested window: " + win + "\n" + "Expected policy: " + expectedPolicy + "\n" + "Effective policy: " + ftp.getClass()); if (!expectedPolicy.equals(ftp.getClass())) { throw new RuntimeException("Test failed: wrong effective focus policy"); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { ObjectInputStream.GetField f = in.readFields(); @SuppressWarnings("unchecked") HashMap<Component, Component> newForwardMap = (HashMap<Component, Component> ) f.get("forwardMap", null); if (newForwardMap == null) { throw new InvalidObjectException("Null forwardMap"); } forwardMap = newForwardMap; @SuppressWarnings("unchecked") HashMap<Component, Component> newBackwardMap = (HashMap<Component, Component>) f.get("backwardMap", null); if (newBackwardMap == null) { throw new InvalidObjectException("Null backwardMap"); } backwardMap = newBackwardMap; delegatePolicy = (FocusTraversalPolicy)in.readObject(); delegateManager = (DefaultFocusManager)in.readObject(); }
/** * Returns the component after. * @return the component after * @param aContainer a container * @param aComponent a component */ public Component getComponentAfter(Container aContainer, Component aComponent) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getComponentAfter(root, aComponent); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getComponentAfter(root, aComponent); } return null; }
/** * Returns the component before. * @return the component before * @param aContainer a container * @param aComponent a component */ public Component getComponentBefore(Container aContainer, Component aComponent) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getComponentBefore(root, aComponent); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getComponentBefore(root, aComponent); } return null; }
/** * Returns the first component. * @return the first component * @param aContainer a container */ public Component getFirstComponent(Container aContainer) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getFirstComponent(root); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getFirstComponent(root); } return null; }
/** * Returns the last component. * @return the last component * @param aContainer a container */ public Component getLastComponent(Container aContainer) { Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor(); // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's // traversal policy is non-legacy, then honor it. if (root != null) { FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); if (policy != gluePolicy) { return policy.getLastComponent(root); } comparator.setComponentOrientation(root.getComponentOrientation()); return layoutPolicy.getLastComponent(root); } return null; }