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 (-2 / +79 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 98-104 Link Here
98
    private static SystemAction[] DEFAULT_ACTIONS;
100
    private static SystemAction[] DEFAULT_ACTIONS;
99
    
101
    
100
    /** a lock for operations in default impl of getLookup */
102
    /** a lock for operations in default impl of getLookup */
101
    private static Object defaultLookupLock = new Object ();
103
    private static final Object defaultLookupLock = new Object ();
104
    
105
    /** a lock for operations with DelayedSetter */
106
    private static final Object lockDelayer = new Object ();
107
    
108
    /** Init delay for second change of the activated nodes. */
109
    private static final int INIT_DELAY = 70;
110
    
111
    /** Maximum delay for repeated change of the activated nodes. */
112
    private static final int MAX_DELAY = 350;
102
    
113
    
103
    /** reference to Lookup with default implementation for the 
114
    /** reference to Lookup with default implementation for the 
104
     * component
115
     * component
Lines 174-190 Link Here
174
    * @return the activated nodes for this component
185
    * @return the activated nodes for this component
175
    */
186
    */
176
    public final Node[] getActivatedNodes () {
187
    public final Node[] getActivatedNodes () {
188
        synchronized (lockDelayer) {
189
            if (delayedSetter != null) {
190
                return delayedSetter.getNodesImmediatelly ();
191
            }
192
        }
177
        return getManager ().getActivatedNodes ();
193
        return getManager ().getActivatedNodes ();
178
    }
194
    }
179
195
180
    /** Set the set of activated nodes in this component.
196
    /** Set the set of activated nodes in this component.
181
    * @param nodes activated nodes for this component
197
    * @param nodes activated nodes for this component
182
    */
198
    */
183
    public final void setActivatedNodes (Node[] nodes) {
199
    public void setActivatedNodes (Node[] nodes) {
200
        scheduleActivatedNodes (nodes);
201
    }
202
    
203
    private void doSetActivatedNodes (Node[] nodes) {
184
        getManager ().setActivatedNodes (nodes);
204
        getManager ().setActivatedNodes (nodes);
185
        firePropertyChange ("activatedNodes", null, null); // NOI18N
205
        firePropertyChange ("activatedNodes", null, null); // NOI18N
186
    }
206
    }
187
207
208
    private class DelayedSetter implements ActionListener {
209
	DelayedSetter () {}	
210
        private Node[] nodes;
211
        private Timer timer;
212
        private boolean firstChange = true;
213
214
        public void scheduleActivatedNodes (Node[] nodes) {
215
            this.nodes = nodes;
216
            synchronized (this) {
217
                if (timer == null) {
218
                    // start timer with INIT_DELAY
219
                    timer = new Timer (INIT_DELAY, this);
220
                    timer.setCoalesce (true);
221
                    timer.setRepeats (false);
222
                }
223
                if (timer.isRunning ()) {
224
                    // if timer is running then double init delay
225
                    if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2);
226
                    firstChange = false;
227
                } else {
228
                    firstChange = true;
229
                }
230
                // make sure timer is running
231
                timer.restart();
232
            }
233
            if (firstChange) {
234
                // the first change is set immediatelly
235
                doSetActivatedNodes (nodes);
236
            }
237
        }
238
239
        public void actionPerformed (ActionEvent evt) {
240
            synchronized (this) {
241
                timer.stop ();
242
            }
243
            // set activated nodes for 2nd and next changes
244
            if (!firstChange) {
245
                doSetActivatedNodes (nodes);
246
            }
247
        }
248
        
249
        public Node[] getNodesImmediatelly () {
250
            return nodes;
251
        }
252
    }
253
    
254
    private transient DelayedSetter delayedSetter;
255
    
256
    // schudule activation the nodes
257
    private void scheduleActivatedNodes (Node[] nodes) {
258
        synchronized (lockDelayer) {
259
            if (delayedSetter == null)
260
                delayedSetter = new DelayedSetter ();
261
        }
262
        delayedSetter.scheduleActivatedNodes (nodes);
263
    }
264
    
188
    /** Get the undo/redo support for this component.
265
    /** Get the undo/redo support for this component.
189
    * The default implementation returns a dummy support that cannot
266
    * The default implementation returns a dummy support that cannot
190
    * undo anything.
267
    * 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