This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 31244
Collapse All | Expand All

(-)src/org/openide/windows/TopComponent.java (-3 / +88 lines)
Lines 15-20 Link Here
15
15
16
import java.awt.Image;
16
import java.awt.Image;
17
import java.awt.event.ActionEvent;
17
import java.awt.event.ActionEvent;
18
import java.awt.event.ActionListener;
18
import java.awt.event.KeyEvent;
19
import java.awt.event.KeyEvent;
19
import java.util.*;
20
import java.util.*;
20
import java.beans.*;
21
import java.beans.*;
Lines 38-43 Link Here
38
import javax.swing.JComponent;
39
import javax.swing.JComponent;
39
import javax.swing.KeyStroke;
40
import javax.swing.KeyStroke;
40
import javax.swing.SwingUtilities;
41
import javax.swing.SwingUtilities;
42
import javax.swing.Timer;
41
import javax.swing.text.Keymap;
43
import javax.swing.text.Keymap;
42
44
43
import org.openide.ErrorManager;
45
import org.openide.ErrorManager;
Lines 56-61 Link Here
56
58
57
import org.openide.modules.Dependency;
59
import org.openide.modules.Dependency;
58
import org.openide.modules.SpecificationVersion;
60
import org.openide.modules.SpecificationVersion;
61
import org.openide.util.RequestProcessor;
59
62
60
/** Embeddable visual component to be displayed in the IDE.
63
/** Embeddable visual component to be displayed in the IDE.
61
 * This is the basic unit of display in the IDE--windows should not be
64
 * This is the basic unit of display in the IDE--windows should not be
Lines 98-104 Link Here
98
    private static SystemAction[] DEFAULT_ACTIONS;
101
    private static SystemAction[] DEFAULT_ACTIONS;
99
    
102
    
100
    /** a lock for operations in default impl of getLookup */
103
    /** a lock for operations in default impl of getLookup */
101
    private static Object defaultLookupLock = new Object ();
104
    private static final Object defaultLookupLock = new Object ();
105
    
106
    /** a lock for operations with DelayedSetter */
107
    private static final Object lockDelayer = new Object ();
108
    
109
    /** Init delay for second change of the activated nodes. */
110
    private static final int INIT_DELAY = 70;
111
    
112
    /** Maximum delay for repeated change of the activated nodes. */
113
    private static final int MAX_DELAY = 350;
102
    
114
    
103
    /** reference to Lookup with default implementation for the 
115
    /** reference to Lookup with default implementation for the 
104
     * component
116
     * component
Lines 169-190 Link Here
169
    public static final Registry getRegistry () {
181
    public static final Registry getRegistry () {
170
        return WindowManager.getDefault().getRegistry();
182
        return WindowManager.getDefault().getRegistry();
171
    }
183
    }
184
    
185
    private boolean running = false;
172
186
173
    /** Get the set of activated nodes in this component.
187
    /** Get the set of activated nodes in this component.
174
    * @return the activated nodes for this component
188
    * @return the activated nodes for this component
175
    */
189
    */
176
    public final Node[] getActivatedNodes () {
190
    public final Node[] getActivatedNodes () {
177
        return getManager ().getActivatedNodes ();
191
        Node[] nodes = null;
192
        synchronized (lockDelayer) {
193
            if (delayedSetter != null) {
194
                nodes = delayedSetter.getNodesImmediatelly ();
195
            }
196
        }
197
        if (running) return nodes;
198
        doSetActivatedNodes (nodes);
199
        return nodes;
178
    }
200
    }
179
201
180
    /** Set the set of activated nodes in this component.
202
    /** Set the set of activated nodes in this component.
181
    * @param nodes activated nodes for this component
203
    * @param nodes activated nodes for this component
182
    */
204
    */
183
    public final void setActivatedNodes (Node[] nodes) {
205
    public void setActivatedNodes (Node[] nodes) {
206
        scheduleActivatedNodes (nodes);
207
    }
208
    
209
    private void doSetActivatedNodes (Node[] nodes) {
210
        running = true;
184
        getManager ().setActivatedNodes (nodes);
211
        getManager ().setActivatedNodes (nodes);
185
        firePropertyChange ("activatedNodes", null, null); // NOI18N
212
        firePropertyChange ("activatedNodes", null, null); // NOI18N
213
        running = false;
186
    }
214
    }
187
215
216
    private class DelayedSetter implements ActionListener {
217
	DelayedSetter () {}	
218
        private Node[] nodes;
219
        private Timer timer;
220
        private boolean firstChange = true;
221
222
        public void scheduleActivatedNodes (Node[] nodes) {
223
            this.nodes = nodes;
224
            synchronized (this) {
225
                if (timer == null) {
226
                    // start timer with INIT_DELAY
227
                    timer = new Timer (INIT_DELAY, this);
228
                    timer.setCoalesce (true);
229
                    timer.setRepeats (false);
230
                }
231
                if (timer.isRunning ()) {
232
                    // if timer is running then double init delay
233
                    if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2);
234
                    firstChange = false;
235
                } else {
236
                    firstChange = true;
237
                }
238
                // make sure timer is running
239
                timer.restart();
240
            }
241
            if (firstChange) {
242
                // the first change is set immediatelly
243
                doSetActivatedNodes (nodes);
244
            }
245
        }
246
247
        public void actionPerformed (ActionEvent evt) {
248
            synchronized (this) {
249
                timer.stop ();
250
            }
251
            // set activated nodes for 2nd and next changes
252
            if (!firstChange) {
253
                doSetActivatedNodes (nodes);
254
            }
255
        }
256
        
257
        public Node[] getNodesImmediatelly () {
258
            return nodes;
259
        }
260
    }
261
    
262
    private transient DelayedSetter delayedSetter;
263
    
264
    // schudule activation the nodes
265
    private void scheduleActivatedNodes (Node[] nodes) {
266
        synchronized (lockDelayer) {
267
            if (delayedSetter == null)
268
                delayedSetter = new DelayedSetter ();
269
        }
270
        delayedSetter.scheduleActivatedNodes (nodes);
271
    }
272
    
188
    /** Get the undo/redo support for this component.
273
    /** Get the undo/redo support for this component.
189
    * The default implementation returns a dummy support that cannot
274
    * The default implementation returns a dummy support that cannot
190
    * undo anything.
275
    * undo anything.
(-)src/org/openide/explorer/ExplorerPanel.java (-62 / +2 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 56-68 Link Here
56
    /** action handler for cut/copy/paste/delete */
56
    /** action handler for cut/copy/paste/delete */
57
    private static final ExplorerActions actions = new ExplorerActions ();
57
    private static final ExplorerActions actions = new ExplorerActions ();
58
    
58
    
59
    /** Init delay for second change of the activated nodes. */
60
    private static final int INIT_DELAY = 70;
61
    
62
    /** Maximum delay for repeated change of the activated nodes. */
63
    private static final int MAX_DELAY = 350;
64
    
65
66
    /** Initialize the explorer panel with the provided manager.
59
    /** Initialize the explorer panel with the provided manager.
67
    * @param manager the explorer manager to use
60
    * @param manager the explorer manager to use
68
    */
61
    */
Lines 267-273 Link Here
267
            }
260
            }
268
            
261
            
269
            if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
262
            if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
270
                scheduleActivatedNodes (manager.getSelectedNodes ());
263
                setActivatedNodes (manager.getSelectedNodes ());
271
                return;
264
                return;
272
            }
265
            }
273
            if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
266
            if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
Lines 275-333 Link Here
275
                return;
268
                return;
276
            }
269
            }
277
        }
270
        }
278
    }
279
280
    private class DelayedSetter implements ActionListener {
281
	DelayedSetter () {}	
282
        private Node[] nodes;
283
        private Timer timer;
284
        private boolean firstChange = true;
285
286
        public void scheduleActivatedNodes (Node[] nodes) {
287
            synchronized (this) {
288
                this.nodes = nodes;
289
                if (timer == null) {
290
                    // start timer with INIT_DELAY
291
                    timer = new Timer (INIT_DELAY, this);
292
                    timer.setCoalesce (true);
293
                    timer.setRepeats (false);
294
                }
295
                if (timer.isRunning ()) {
296
                    // if timer is running then double init delay
297
                    if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2);
298
                    firstChange = false;
299
                } else {
300
                    // the first change is set immediatelly
301
                    setActivatedNodes (nodes);
302
                    firstChange = true;
303
                }
304
                // make sure timer is running
305
                timer.restart();
306
            }
307
        }
308
309
        public void actionPerformed (ActionEvent evt) {
310
            synchronized (this) {
311
                synchronized (this) {
312
                    timer.stop ();
313
                }
314
            }
315
            // set activated nodes for 2nd and next changes
316
            if (!firstChange) {
317
                setActivatedNodes (nodes);
318
            }
319
        }
320
    }
321
    
322
    private transient DelayedSetter delayedSetter;
323
    
324
    // schudule activation the nodes
325
    private final void scheduleActivatedNodes (Node[] nodes) {
326
        synchronized (this) {
327
            if (delayedSetter == null)
328
                delayedSetter = new DelayedSetter ();
329
        }
330
        delayedSetter.scheduleActivatedNodes (nodes);
331
    }
271
    }
332
    
272
    
333
}
273
}
(-)src/org/openide/explorer/ExplorerActions.java (-4 / +4 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 720-726 Link Here
720
        }
720
        }
721
        
721
        
722
        public void propertyChange(PropertyChangeEvent e) {
722
        public void propertyChange(PropertyChangeEvent e) {
723
            timer.start();
723
            timer.restart();
724
        }
724
        }
725
725
726
        public void clipboardChanged(ClipboardEvent ev) {
726
        public void clipboardChanged(ClipboardEvent ev) {
Lines 751-758 Link Here
751
            super(delay, l);
751
            super(delay, l);
752
        }
752
        }
753
        
753
        
754
        public void start() {
754
        public void restart() {
755
            super.start();
755
            super.restart();
756
            running = true;
756
            running = true;
757
        }
757
        }
758
        
758
        

Return to bug 31244