KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SInternalFrame


1 /*
2  * $Id: SInternalFrame.java,v 1.9 2005/05/13 12:06:16 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import org.wings.event.SInternalFrameEvent;
17 import org.wings.event.SInternalFrameListener;
18 import org.wings.plaf.InternalFrameCG;
19
20 /**
21  * @author <a HREF="mailto:engels@mercatis.de">Holger Engels</a>
22  * @version $Revision: 1.9 $
23  */

24 public class SInternalFrame
25         extends SRootContainer
26         implements LowLevelEventListener {
27     private boolean iconifyable = true;
28     private boolean maximizable = true;
29     private boolean closable = true;
30
31     private boolean iconified = false;
32     private boolean maximized = false;
33     private boolean closed = false;
34
35     protected SIcon icon = null;
36
37     protected String JavaDoc title = null;
38
39     public SInternalFrame() {
40         super();
41     }
42
43     public void setIconifyable(boolean v) {
44         reloadIfChange(iconifyable, v);
45     }
46
47     public boolean isIconifyable() { return iconifyable; }
48
49     public void setMaximizable(boolean v) {
50         maximizable = v;
51         reloadIfChange(maximizable, v);
52     }
53
54     public boolean isMaximizable() { return maximizable; }
55
56     public void setClosable(boolean v) {
57         closable = v;
58         reloadIfChange(closable, v);
59     }
60
61     public boolean isClosable() { return closable; }
62
63     public void setIconified(boolean v) {
64         v &= isIconifyable();
65         boolean old = iconified;
66         iconified = v;
67         if (old != iconified) {
68             reload();
69             if (iconified)
70                 setMaximized(false);
71         }
72     }
73
74     public boolean isIconified() { return iconified; }
75
76     public void setMaximized(boolean v) {
77         v &= isMaximizable();
78         boolean old = maximized;
79         maximized = v;
80         if (old != maximized) {
81             reload();
82             if (maximized)
83                 setIconified(false);
84         }
85     }
86
87     public boolean isMaximized() { return maximized; }
88
89     public void setClosed(boolean v) {
90         v &= isClosable();
91         boolean old = closed;
92         closed = v;
93         if (old != closed)
94             reload();
95     }
96
97     public boolean isClosed() { return closed; }
98
99     public void setIcon(SIcon i) {
100         if (i != icon || i != null && !i.equals(icon)) {
101             icon = i;
102             reload();
103         }
104     }
105
106     public SIcon getIcon() {
107         return icon;
108     }
109
110     public void setTitle(String JavaDoc t) {
111         String JavaDoc oldTitle = title;
112         title = t;
113         if ((title == null && oldTitle != null) ||
114                 (title != null && !title.equals(oldTitle)))
115             reload();
116     }
117
118     public String JavaDoc getTitle() {
119         return title;
120     }
121
122     public void dispose() {
123         SDesktopPane desktop = (SDesktopPane) getParent();
124         desktop.remove(this);
125     }
126
127     public void setVisible(boolean visible) {
128         if (visible)
129             show();
130         else
131             hide();
132     }
133
134     public void show() {
135         super.setVisible(true);
136         if (isIconified()) {
137             setIconified(false);
138         }
139         if (isClosed()) {
140             setClosed(false);
141         }
142     }
143
144     public void hide() {
145         super.setVisible(false);
146     }
147
148     public void addInternalFrameListener(SInternalFrameListener listener) {
149         addEventListener(SInternalFrameListener.class, listener);
150     }
151
152     public void removeInternalFrameListener(SInternalFrameListener listener) {
153         removeEventListener(SInternalFrameListener.class, listener);
154     }
155
156     private SInternalFrameEvent event;
157
158     // LowLevelEventListener interface. Handle own events.
159
public void processLowLevelEvent(String JavaDoc action, String JavaDoc[] values) {
160         processKeyEvents(values);
161
162         switch (new Integer JavaDoc(values[0]).intValue()) {
163             case SInternalFrameEvent.INTERNAL_FRAME_CLOSED:
164                 setClosed(true);
165                 break;
166
167             case SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
168                 setIconified(true);
169                 break;
170
171             case SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
172                 setIconified(false);
173                 break;
174
175             case SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED:
176                 setMaximized(true);
177                 break;
178
179             case SInternalFrameEvent.INTERNAL_FRAME_UNMAXIMIZED:
180                 setMaximized(false);
181                 break;
182
183             default:
184                 throw new RuntimeException JavaDoc("unknown id: " + values[0]);
185         }
186
187         event = new SInternalFrameEvent(this, new Integer JavaDoc(values[0]).intValue());
188         SForm.addArmedComponent(this); // trigger later invocation of fire*()
189
}
190
191     public void fireIntermediateEvents() {}
192
193     public void fireFinalEvents() {
194         super.fireFinalEvents();
195         // Guaranteed to return a non-null array
196
Object JavaDoc[] listeners = getListenerList();
197         // Process the listeners last to first, notifying
198
// those that are interested in this event
199
for (int i = listeners.length - 2; i >= 0; i -= 2) {
200             if (listeners[i] == SInternalFrameListener.class) {
201                 SInternalFrameListener listener;
202                 listener = (SInternalFrameListener) listeners[i + 1];
203                 switch (event.getID()) {
204                     case SInternalFrameEvent.INTERNAL_FRAME_CLOSED:
205                         listener.internalFrameClosed(event);
206                         break;
207
208                     case SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
209                         listener.internalFrameIconified(event);
210                         break;
211
212                     case SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
213                         listener.internalFrameDeiconified(event);
214                         break;
215
216                     case SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED:
217                         listener.internalFrameMaximized(event);
218                         break;
219
220                     case SInternalFrameEvent.INTERNAL_FRAME_UNMAXIMIZED:
221                         listener.internalFrameUnmaximized(event);
222                         break;
223                 }
224             }
225         }
226
227         event = null;
228     }
229
230     public boolean isEpochCheckEnabled() {
231         return true;
232     }
233
234     public void setCG(InternalFrameCG cg) {
235         super.setCG(cg);
236     }
237 }
238
239
240
Popular Tags