source: release-kits/shared/launch4j/src/net/sf/launch4j/formimpl/GlassPane.java@ 15024

Last change on this file since 15024 was 15024, checked in by oranfry, 16 years ago

putting launch4j in the shared area

File size: 1.9 KB
Line 
1package net.sf.launch4j.formimpl;
2
3import java.awt.AWTEvent;
4import java.awt.Component;
5import java.awt.Cursor;
6import java.awt.Toolkit;
7import java.awt.Window;
8import java.awt.event.AWTEventListener;
9import java.awt.event.KeyAdapter;
10import java.awt.event.KeyEvent;
11import java.awt.event.MouseAdapter;
12
13import javax.swing.JComponent;
14import javax.swing.SwingUtilities;
15
16/**
17 * This is the glass pane class that intercepts screen interactions during
18 * system busy states.
19 *
20 * Based on JavaWorld article by Yexin Chen.
21 */
22public class GlassPane extends JComponent implements AWTEventListener {
23 private final Window _window;
24
25 public GlassPane(Window w) {
26 _window = w;
27 addMouseListener(new MouseAdapter() {});
28 addKeyListener(new KeyAdapter() {});
29 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
30 }
31
32 /**
33 * Receives all key events in the AWT and processes the ones that originated
34 * from the current window with the glass pane.
35 *
36 * @param event
37 * the AWTEvent that was fired
38 */
39 public void eventDispatched(AWTEvent event) {
40 Object source = event.getSource();
41 if (event instanceof KeyEvent
42 && source instanceof Component) {
43 /*
44 * If the event originated from the window w/glass pane,
45 * consume the event.
46 */
47 if ((SwingUtilities.windowForComponent((Component) source) == _window)) {
48 ((KeyEvent) event).consume();
49 }
50 }
51 }
52
53 /**
54 * Sets the glass pane as visible or invisible. The mouse cursor will be set
55 * accordingly.
56 */
57 public void setVisible(boolean visible) {
58 if (visible) {
59 // Start receiving all events and consume them if necessary
60 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
61 } else {
62 // Stop receiving all events
63 Toolkit.getDefaultToolkit().removeAWTEventListener(this);
64 }
65 super.setVisible(visible);
66 }
67}
Note: See TracBrowser for help on using the repository browser.