001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: import java.util.ArrayList;
031: import java.util.Collections;
032: import java.util.List;
033:
034: /**
035: * A Frame is the browser window. It is created by the Application instance and
036: * automatically toggled to visible. When visible is set to false, the session
037: * is closed.
038: * <p>
039: * <b>Example:</b> <br>
040: * <img src="doc-files/Frame-1.png"> <br>
041: *
042: * <pre>
043: * Frame frm = Application.current().getFrame();
044: * frm.setTitle("Frame Test");
045: *
046: * for (int i = 0; i < 5; i++) {
047: * Dialog dlg = new Dialog();
048: * dlg.setBounds((i * 100) + 10, 10, 90, 300);
049: * dlg.setTitle("Dlg-" + (i + 1) + "-" + dlg.getX() + "-" + dlg.getY());
050: * Label lb = new Label("#" + (i + 1));
051: * lb.setBounds(10, 10, 50, 30);
052: * dlg.getChildren().add(lb);
053: * frm.getChildren().add(dlg);
054: * }
055: *
056: * </pre>
057: *
058: * </p>
059: *
060: * @author Joshua J. Gertzen
061: */
062: public final class Frame extends AbstractWindow {
063: private List<Dialog> children = new ArrayList<Dialog>();
064: private List<Dialog> roChildren = Collections
065: .unmodifiableList(children);
066: private int innerHeight;
067: private int innerWidth;
068: private boolean allowSizeChange;
069:
070: //Prevent the creation of any other Frame.
071: Frame() {
072:
073: }
074:
075: /**
076: * Returns a read-only list of all visible child dialogs.
077: * @return A read-only list of all visible child dialogs.
078: */
079: public List<Dialog> getDialogs() {
080: return roChildren;
081: }
082:
083: void dialogVisibilityChanged(Dialog d, boolean visible) {
084: if (visible) {
085: children.add(d);
086: } else {
087: children.remove(d);
088: }
089: }
090:
091: public int getInnerWidth() {
092: return innerWidth;
093: }
094:
095: void setInnerWidth(int innerWidth) {
096: if (innerWidth < 0 || innerWidth > 65536)
097: innerWidth = 0;
098: this .innerWidth = innerWidth;
099: }
100:
101: public int getInnerHeight() {
102: return innerHeight - (getMenu() == null ? 0 : MENU_BAR_HEIGHT);
103: }
104:
105: void setInnerHeight(int innerHeight) {
106: if (innerHeight < 0 || innerHeight > 65536)
107: innerHeight = 0;
108: this .innerHeight = innerHeight;
109: }
110:
111: void sizeChanged(int width, int height) {
112: try {
113: allowSizeChange = true;
114: if (width < 0)
115: width = 0;
116: if (height < 0)
117: height = 0;
118: setSize(width, height);
119: } finally {
120: allowSizeChange = false;
121: }
122: }
123:
124: /**
125: * @throws UnsupportedOperationException
126: */
127: @Override
128: public int getX() {
129: throw new UnsupportedOperationException(
130: getStandardPropertyUnsupportedMsg(PROPERTY_X, true));
131: }
132:
133: /**
134: * @throws UnsupportedOperationException
135: */
136: @Override
137: public void setX(int x) {
138: throw new UnsupportedOperationException(
139: getStandardPropertyUnsupportedMsg(PROPERTY_X, false));
140: }
141:
142: /**
143: * @throws UnsupportedOperationException
144: */
145: @Override
146: public int getY() {
147: throw new UnsupportedOperationException(
148: getStandardPropertyUnsupportedMsg(PROPERTY_Y, true));
149: }
150:
151: /**
152: * @throws UnsupportedOperationException
153: */
154: @Override
155: public void setY(int y) {
156: throw new UnsupportedOperationException(
157: getStandardPropertyUnsupportedMsg(PROPERTY_Y, false));
158: }
159:
160: /**
161: * @throws UnsupportedOperationException
162: */
163: @Override
164: public void setWidth(int width) {
165: if (allowSizeChange) {
166: super .setWidth(width);
167: } else {
168: throw new UnsupportedOperationException(
169: getStandardPropertyUnsupportedMsg(PROPERTY_WIDTH,
170: false));
171: }
172: }
173:
174: /**
175: * @throws UnsupportedOperationException
176: */
177: @Override
178: public void setHeight(int height) {
179: if (allowSizeChange) {
180: super .setHeight(height);
181: } else {
182: throw new UnsupportedOperationException(
183: getStandardPropertyUnsupportedMsg(PROPERTY_HEIGHT,
184: false));
185: }
186: }
187:
188: /**
189: * Although tecnhically visible is false for a Window by default, the
190: * Application instance automatically sets visible to true when the app is
191: * started. Setting visible to false will cause the app instance to close
192: * and terminate the session.
193: *
194: * @see thinwire.ui.Component#setVisible(boolean)
195: */
196: public void setVisible(boolean visible) {
197: if (isVisible() != visible) {
198: if (visible) {
199: app.showWindow(this );
200: } else {
201: List<Dialog> dialogs = getDialogs();
202:
203: for (Dialog d : dialogs.toArray(new Dialog[dialogs
204: .size()])) {
205: d.setVisible(false);
206: }
207:
208: app.hideWindow(this);
209: }
210:
211: super.setVisible(visible);
212: }
213: }
214: }
|