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 57855
Collapse All | Expand All

(-)DialogVisualizerWrapper.java (-5 / +106 lines)
Lines 13-19 Link Here
13
13
14
package org.netbeans.modules.vcscore.commands;
14
package org.netbeans.modules.vcscore.commands;
15
15
16
import java.awt.AWTEvent;
17
import java.awt.EventQueue;
18
import java.awt.Toolkit;
19
import java.awt.event.AWTEventListener;
16
import java.awt.event.ActionListener;
20
import java.awt.event.ActionListener;
21
import java.awt.event.InvocationEvent;
22
import java.util.Iterator;
17
23
18
import org.netbeans.api.vcs.commands.CommandTask;
24
import org.netbeans.api.vcs.commands.CommandTask;
19
25
Lines 246-257 Link Here
246
        return null;
252
        return null;
247
    }
253
    }
248
    
254
    
249
    /**
255
    private PumpControl pumpControl;
250
     * @param args the command line arguments
256
    
251
     *
257
    public void show() {
252
    public static void main(String args[]) {
258
        pumpControl = new PumpControl();
253
        new DialogVisualizerWrapper(new javax.swing.JFrame(), true).show();
259
        super.show();
260
    }
261
    
262
    public void dispose() {
263
        super.dispose();
264
        pumpControl.release();
254
    }
265
    }
266
    
267
    /**
268
     * Control the event pump.
269
     * Do not let invocation events from outside of VCS and JDK to process.
270
     * This is a protection of our modal dialog, so that scheduled events do not
271
     * create GUI upon us.
255
     */
272
     */
273
    private class PumpControl implements Runnable {
274
        
275
        private java.util.List ignoredEvents = new java.util.ArrayList();
276
        private EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
277
        private CleanUpEvent cleanUpEvent = new CleanUpEvent(Toolkit.getDefaultToolkit(), this);
278
        
279
        public PumpControl() {
280
            cleanUp();
281
            queue.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), this));
282
        }
283
        
284
        private void cleanUp() {
285
            java.util.List eventsToReturn = new java.util.ArrayList();
286
            while (queue.peekEvent() != null) {
287
                try {
288
                    AWTEvent event = queue.getNextEvent();
289
                    if (ignore(event)) {
290
                        ignoredEvents.add(event);
291
                    } else {
292
                        eventsToReturn.add(event);
293
                    }
294
                } catch (InterruptedException iex) {}
295
            }
296
            for (Iterator it = eventsToReturn.iterator(); it.hasNext(); ) {
297
                AWTEvent event = (AWTEvent) it.next();
298
                queue.postEvent(event);
299
            }
300
        }
301
        
302
        public void run() {
303
            if (queue != null) {
304
                try {
305
                    Thread.currentThread().sleep(20);
306
                } catch (InterruptedException iex) {}
307
                cleanUp();
308
                queue.postEvent(cleanUpEvent);
309
            }
310
        }
311
        
312
        public void release() {
313
            // Post all the ignored events now
314
            for (Iterator it = ignoredEvents.iterator(); it.hasNext(); ) {
315
                AWTEvent event = (AWTEvent) it.next();
316
                queue.postEvent(event);
317
                //System.out.println("POST Event: "+event);
318
            }
319
            // Stop cleaning up.
320
            queue = null;
321
        }
322
        
323
        private boolean ignore(AWTEvent event) {
324
            //System.out.println("HAVE Event: "+event);
325
            if (event instanceof InvocationEvent) {
326
                InvocationEvent ie = (InvocationEvent) event;
327
                String ids;
328
                try {
329
                    java.lang.reflect.Field runnableField = ie.getClass().getDeclaredField("runnable");
330
                    runnableField.setAccessible(true);
331
                    Object runnable = runnableField.get(ie);
332
                    ids = runnable.getClass().getName();
333
                } catch (Exception ex) {
334
                    ids = ie.paramString();
335
                }
336
                if (ids.indexOf("javax.swing") >= 0 || ids.indexOf("java.awt") >= 0 ||
337
                        ids.indexOf("sun.awt.") >= 0 ||
338
                        ids.indexOf("vcscore") >= 0) {
339
                    return false;
340
                } else {
341
                    //System.out.println("IGNORED Event: "+event);
342
                    return true;
343
                }
344
            }
345
            return false;
346
        }
347
        
348
        
349
        private class CleanUpEvent extends InvocationEvent {
350
            public CleanUpEvent(Object source, Runnable run) {
351
                // ID = PaintEvent.PAINT, to have the lowest priority.
352
                super(source, java.awt.event.PaintEvent.PAINT, run, null, false);
353
            }
354
        }
355
        
356
    }
256
    
357
    
257
}
358
}

Return to bug 57855