KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > swing > event > PanelEvent


1 /*
2  * PanelEvent.java
3  *
4  * Created on 21. Februar 2006, 11:36
5  */

6 /*
7  * Copyright 2006 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.swing.event;
23
24 import de.schlichtherle.swing.EnhancedPanel;
25
26 import java.awt.AWTEvent JavaDoc;
27 import java.awt.Window JavaDoc;
28
29 /**
30  * Fired when the ancestor window of an {@link EnhancedPanel} is shown or
31  * hidden.
32  * <p>
33  * Note that since TrueZIP 6.1, this class has been refactored to subclass
34  * {@link AWTEvent} (which subclasses {@link java.util.EventObject}) instead
35  * of <code>EventObject</code> directly.
36  * This has been done in order to allow coalescing multiple events for the
37  * same cause by posting them to the AWT's Event Queue, from which the
38  * coalesced event would then be dispatched by AWT's Event Dispatching Thread.
39  * <p>
40  * However, since TrueZIP 6.4, these events are fired <em>synchronously</em>
41  * again, whereby it is ensured that only a single event is fired for each
42  * cause. The super class is kept for backwards compatibility only.
43  *
44  * @author Christian Schlichtherle
45  * @version @version@
46  * @since TrueZIP 5.1
47  */

48 public class PanelEvent extends AWTEvent JavaDoc {
49
50     /** The id for Ancestor Window Shown Event. */
51     public static final int ANCESTOR_WINDOW_SHOWN = RESERVED_ID_MAX + 1;
52
53     /** The id for Ancestor Window Hidden Event. */
54     public static final int ANCESTOR_WINDOW_HIDDEN = RESERVED_ID_MAX + 2;
55
56     /**
57      */

58     public PanelEvent(EnhancedPanel source, int id) {
59         super(source, id);
60
61         switch (id) {
62             case ANCESTOR_WINDOW_SHOWN:
63             case ANCESTOR_WINDOW_HIDDEN:
64                 break;
65
66             default:
67                 throw new IllegalArgumentException JavaDoc();
68         }
69     }
70
71     /**
72      * Returns the source of this event as an <code>EnhancedPanel</code>
73      * or <code>null</code> if it's not an instance of this class.
74      */

75     public EnhancedPanel getSourcePanel() {
76         return source instanceof EnhancedPanel ? (EnhancedPanel) source : null;
77     }
78
79     /**
80      * Returns the ancestor window for this event or <code>null</code> if the
81      * source of this event is not an <code>EnhancedPanel</code>.
82      */

83     public Window JavaDoc getAncestorWindow() {
84         EnhancedPanel panel = getSourcePanel();
85         return panel != null ? panel.getAncestorWindow() : null;
86     }
87
88     public String JavaDoc paramString() {
89         switch (id) {
90             case ANCESTOR_WINDOW_SHOWN:
91                 return "id=ANCESTOR_WINDOW_SHOWN";
92
93             case ANCESTOR_WINDOW_HIDDEN:
94                 return "id=ANCESTOR_WINDOW_HIDDEN";
95
96             default:
97                 throw new AssertionError JavaDoc();
98         }
99     }
100 }
101
Popular Tags