Index: src/org/openide/windows/TopComponent.java =================================================================== RCS file: /cvs/openide/src/org/openide/windows/TopComponent.java,v retrieving revision 1.95 diff -u -r1.95 TopComponent.java --- src/org/openide/windows/TopComponent.java 6 Feb 2003 16:41:21 -0000 1.95 +++ src/org/openide/windows/TopComponent.java 20 Feb 2003 16:51:43 -0000 @@ -15,6 +15,7 @@ import java.awt.Image; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.*; import java.beans.*; @@ -38,6 +39,7 @@ import javax.swing.JComponent; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; +import javax.swing.Timer; import javax.swing.text.Keymap; import org.openide.ErrorManager; @@ -98,7 +100,16 @@ private static SystemAction[] DEFAULT_ACTIONS; /** a lock for operations in default impl of getLookup */ - private static Object defaultLookupLock = new Object (); + private static final Object defaultLookupLock = new Object (); + + /** a lock for operations with DelayedSetter */ + private static final Object lockDelayer = new Object (); + + /** Init delay for second change of the activated nodes. */ + private static final int INIT_DELAY = 70; + + /** Maximum delay for repeated change of the activated nodes. */ + private static final int MAX_DELAY = 350; /** reference to Lookup with default implementation for the * component @@ -174,17 +185,83 @@ * @return the activated nodes for this component */ public final Node[] getActivatedNodes () { + synchronized (lockDelayer) { + if (delayedSetter != null) { + return delayedSetter.getNodesImmediatelly (); + } + } return getManager ().getActivatedNodes (); } /** Set the set of activated nodes in this component. * @param nodes activated nodes for this component */ - public final void setActivatedNodes (Node[] nodes) { + public void setActivatedNodes (Node[] nodes) { + scheduleActivatedNodes (nodes); + } + + private void doSetActivatedNodes (Node[] nodes) { getManager ().setActivatedNodes (nodes); firePropertyChange ("activatedNodes", null, null); // NOI18N } + private class DelayedSetter implements ActionListener { + DelayedSetter () {} + private Node[] nodes; + private Timer timer; + private boolean firstChange = true; + + public void scheduleActivatedNodes (Node[] nodes) { + this.nodes = nodes; + synchronized (this) { + if (timer == null) { + // start timer with INIT_DELAY + timer = new Timer (INIT_DELAY, this); + timer.setCoalesce (true); + timer.setRepeats (false); + } + if (timer.isRunning ()) { + // if timer is running then double init delay + if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2); + firstChange = false; + } else { + firstChange = true; + } + // make sure timer is running + timer.restart(); + } + if (firstChange) { + // the first change is set immediatelly + doSetActivatedNodes (nodes); + } + } + + public void actionPerformed (ActionEvent evt) { + synchronized (this) { + timer.stop (); + } + // set activated nodes for 2nd and next changes + if (!firstChange) { + doSetActivatedNodes (nodes); + } + } + + public Node[] getNodesImmediatelly () { + return nodes; + } + } + + private transient DelayedSetter delayedSetter; + + // schudule activation the nodes + private void scheduleActivatedNodes (Node[] nodes) { + synchronized (lockDelayer) { + if (delayedSetter == null) + delayedSetter = new DelayedSetter (); + } + delayedSetter.scheduleActivatedNodes (nodes); + } + /** Get the undo/redo support for this component. * The default implementation returns a dummy support that cannot * undo anything. Index: src/org/openide/explorer/ExplorerPanel.java =================================================================== RCS file: /cvs/openide/src/org/openide/explorer/ExplorerPanel.java,v retrieving revision 1.42 diff -u -r1.42 ExplorerPanel.java --- src/org/openide/explorer/ExplorerPanel.java 19 Feb 2003 10:42:49 -0000 1.42 +++ src/org/openide/explorer/ExplorerPanel.java 20 Feb 2003 16:51:44 -0000 @@ -7,7 +7,7 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -56,13 +56,6 @@ /** action handler for cut/copy/paste/delete */ private static final ExplorerActions actions = new ExplorerActions (); - /** Init delay for second change of the activated nodes. */ - private static final int INIT_DELAY = 70; - - /** Maximum delay for repeated change of the activated nodes. */ - private static final int MAX_DELAY = 350; - - /** Initialize the explorer panel with the provided manager. * @param manager the explorer manager to use */ @@ -267,7 +260,7 @@ } if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { - scheduleActivatedNodes (manager.getSelectedNodes ()); + setActivatedNodes (manager.getSelectedNodes ()); return; } if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) { @@ -275,59 +268,6 @@ return; } } - } - - private class DelayedSetter implements ActionListener { - DelayedSetter () {} - private Node[] nodes; - private Timer timer; - private boolean firstChange = true; - - public void scheduleActivatedNodes (Node[] nodes) { - synchronized (this) { - this.nodes = nodes; - if (timer == null) { - // start timer with INIT_DELAY - timer = new Timer (INIT_DELAY, this); - timer.setCoalesce (true); - timer.setRepeats (false); - } - if (timer.isRunning ()) { - // if timer is running then double init delay - if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2); - firstChange = false; - } else { - // the first change is set immediatelly - setActivatedNodes (nodes); - firstChange = true; - } - // make sure timer is running - timer.restart(); - } - } - - public void actionPerformed (ActionEvent evt) { - synchronized (this) { - synchronized (this) { - timer.stop (); - } - } - // set activated nodes for 2nd and next changes - if (!firstChange) { - setActivatedNodes (nodes); - } - } - } - - private transient DelayedSetter delayedSetter; - - // schudule activation the nodes - private final void scheduleActivatedNodes (Node[] nodes) { - synchronized (this) { - if (delayedSetter == null) - delayedSetter = new DelayedSetter (); - } - delayedSetter.scheduleActivatedNodes (nodes); } } Index: src/org/openide/explorer/ExplorerActions.java =================================================================== RCS file: /cvs/openide/src/org/openide/explorer/ExplorerActions.java,v retrieving revision 1.53 diff -u -r1.53 ExplorerActions.java --- src/org/openide/explorer/ExplorerActions.java 29 Jan 2003 01:42:40 -0000 1.53 +++ src/org/openide/explorer/ExplorerActions.java 20 Feb 2003 16:51:44 -0000 @@ -7,7 +7,7 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -720,7 +720,7 @@ } public void propertyChange(PropertyChangeEvent e) { - timer.start(); + timer.restart(); } public void clipboardChanged(ClipboardEvent ev) { @@ -751,8 +751,8 @@ super(delay, l); } - public void start() { - super.start(); + public void restart() { + super.restart(); running = true; }