001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import org.wings.event.SInternalFrameEvent;
016: import org.wings.event.SInternalFrameListener;
017: import org.wings.plaf.InternalFrameCG;
018: import org.wings.style.Selector;
019:
020: /**
021: * A root container repesenting an iconifyable and minimizable internal window.
022: *
023: * @author <a href="mailto:engels@mercatis.de">Holger Engels</a>
024: */
025: public class SInternalFrame extends SRootContainer implements
026: LowLevelEventListener {
027: /**
028: * A Pseudo selector addressing the container area of this container.
029: * Refer to {@link SComponent#setAttribute(org.wings.style.Selector, org.wings.style.CSSProperty, String)}
030: */
031: public static final Selector SELECTOR_CONTENT = new Selector(
032: "content area");
033: /**
034: * A Pseudo selector addressing the title bar
035: * Refer to {@link SComponent#setAttribute(org.wings.style.Selector, org.wings.style.CSSProperty, String)}
036: */
037: public static final Selector SELECTOR_TITLE = new Selector(
038: "title bar");
039:
040: private boolean iconifyable = true;
041: private boolean maximizable = true;
042: private boolean closable = true;
043:
044: private boolean iconified = false;
045: private boolean maximized = false;
046: private boolean closed = false;
047:
048: protected SIcon icon = null;
049:
050: protected String title = null;
051:
052: public SInternalFrame() {
053: super ();
054: }
055:
056: public void setIconifyable(boolean v) {
057: iconifyable = v;
058: reloadIfChange(iconifyable, v);
059: }
060:
061: public boolean isIconifyable() {
062: return iconifyable;
063: }
064:
065: public void setMaximizable(boolean v) {
066: maximizable = v;
067: reloadIfChange(maximizable, v);
068: }
069:
070: public boolean isMaximizable() {
071: return maximizable;
072: }
073:
074: public void setClosable(boolean v) {
075: closable = v;
076: reloadIfChange(closable, v);
077: }
078:
079: public boolean isClosable() {
080: return closable;
081: }
082:
083: public void setIconified(boolean v) {
084: v &= isIconifyable();
085: boolean old = iconified;
086: iconified = v;
087: if (old != iconified) {
088: reload();
089: if (iconified)
090: setMaximized(false);
091: }
092: }
093:
094: public boolean isIconified() {
095: return iconified;
096: }
097:
098: public void setMaximized(boolean v) {
099: v &= isMaximizable();
100: boolean old = maximized;
101: maximized = v;
102: if (old != maximized) {
103: reload();
104: if (maximized)
105: setIconified(false);
106: }
107: }
108:
109: public boolean isMaximized() {
110: return maximized;
111: }
112:
113: public void setClosed(boolean closed) {
114: closed &= isClosable();
115: if (closed)
116: hide();
117: else
118: reloadIfChange(this .closed, closed);
119: this .closed = closed;
120: }
121:
122: public boolean isClosed() {
123: return closed;
124: }
125:
126: public void setIcon(SIcon i) {
127: if (i != icon || i != null && !i.equals(icon)) {
128: icon = i;
129: reload();
130: }
131: }
132:
133: public SIcon getIcon() {
134: return icon;
135: }
136:
137: public void setTitle(String t) {
138: String oldTitle = title;
139: title = t;
140: if ((title == null && oldTitle != null)
141: || (title != null && !title.equals(oldTitle)))
142: reload();
143: }
144:
145: public String getTitle() {
146: return title;
147: }
148:
149: public void dispose() {
150: SDesktopPane desktop = (SDesktopPane) getParent();
151: desktop.remove(this );
152: }
153:
154: public void setVisible(boolean visible) {
155: if (visible)
156: show();
157: else
158: hide();
159: }
160:
161: public void show() {
162: super .setVisible(true);
163: if (isIconified()) {
164: setIconified(false);
165: }
166: if (isClosed()) {
167: setClosed(false);
168: }
169: }
170:
171: public void hide() {
172: super .setVisible(false);
173: }
174:
175: @Override
176: protected boolean isShowingChildren() {
177: return !iconified;
178: }
179:
180: public void addInternalFrameListener(SInternalFrameListener listener) {
181: addEventListener(SInternalFrameListener.class, listener);
182: }
183:
184: public void removeInternalFrameListener(
185: SInternalFrameListener listener) {
186: removeEventListener(SInternalFrameListener.class, listener);
187: }
188:
189: private SInternalFrameEvent event;
190:
191: // LowLevelEventListener interface. Handle own events.
192: public void processLowLevelEvent(String action, String[] values) {
193: processKeyEvents(values);
194: if (action.endsWith("_keystroke"))
195: return;
196:
197: switch (new Integer(values[0])) {
198: case SInternalFrameEvent.INTERNAL_FRAME_CLOSED:
199: setClosed(true);
200: break;
201:
202: case SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
203: setIconified(true);
204: break;
205:
206: case SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
207: setIconified(false);
208: break;
209:
210: case SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED:
211: setMaximized(true);
212: break;
213:
214: case SInternalFrameEvent.INTERNAL_FRAME_UNMAXIMIZED:
215: setMaximized(false);
216: break;
217:
218: default:
219: throw new RuntimeException("unknown id: " + values[0]);
220: }
221:
222: event = new SInternalFrameEvent(this , new Integer(values[0])
223: .intValue());
224: SForm.addArmedComponent(this ); // trigger later invocation of fire*()
225: }
226:
227: public void fireIntermediateEvents() {
228: }
229:
230: public void fireFinalEvents() {
231: super .fireFinalEvents();
232: // Guaranteed to return a non-null array
233: Object[] listeners = getListenerList();
234: // Process the listeners last to first, notifying
235: // those that are interested in this event
236: for (int i = listeners.length - 2; i >= 0; i -= 2) {
237: if (listeners[i] == SInternalFrameListener.class) {
238: SInternalFrameListener listener;
239: listener = (SInternalFrameListener) listeners[i + 1];
240: switch (event.getID()) {
241: case SInternalFrameEvent.INTERNAL_FRAME_CLOSED:
242: listener.internalFrameClosed(event);
243: break;
244:
245: case SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
246: listener.internalFrameIconified(event);
247: break;
248:
249: case SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
250: listener.internalFrameDeiconified(event);
251: break;
252:
253: case SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED:
254: listener.internalFrameMaximized(event);
255: break;
256:
257: case SInternalFrameEvent.INTERNAL_FRAME_UNMAXIMIZED:
258: listener.internalFrameUnmaximized(event);
259: break;
260: }
261: }
262: }
263:
264: event = null;
265: }
266:
267: public boolean isEpochCheckEnabled() {
268: return true;
269: }
270:
271: public void setCG(InternalFrameCG cg) {
272: super.setCG(cg);
273: }
274: }
|