001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.awt.*;
008: import java.awt.event.*;
009: import java.io.*;
010: import java.util.*;
011:
012: import com.javelin.swinglets.plaf.*;
013:
014: /**
015: * A Frame is a page. This can be a web frame, mobile phone page, UI Window. etc.
016: *
017: * @author Robin Sharp
018: */
019:
020: public class SFrame extends SContainer {
021: /**
022: * Target this Frame for reloading.
023: */
024: public final static String SELF = "_self";
025:
026: /**
027: * Target the parent Frame for reloading.
028: */
029: public final static String PARENT = "_parent";
030:
031: /**
032: * Target a new Frame for reloading.
033: */
034: public final static String NEW = "_blank";
035:
036: /**
037: * Target this window for the Frame for reloading.
038: */
039: public final static String TOP = "_top";
040:
041: /**
042: * Construct a fully qualified SFrame. This is used to initialise
043: * the top most frame. This binds the Frame to the SwingletManager.
044: */
045: public SFrame(String name) {
046: if (name == null)
047: throw new IllegalArgumentException("Name cannot be null.");
048:
049: setName(name);
050: //System.out.println( "SFRAME " + name );
051:
052: SwingletManager sm = getSwingletManager();
053: if (sm != null) {
054: sm.putValue(getName(), this );
055: }
056: }
057:
058: /**
059: * Construct a fully qualified SFrame. This binds the Frame to the
060: * SwingletManager.
061: */
062: public SFrame(SFrame frame) {
063: if (frame == null) {
064: SwingletManager sm = getSwingletManager();
065: if (sm != null) {
066: sm.putValue(getName(), this );
067: }
068: } else {
069: setFrame(frame);
070:
071: SwingletManager sm = getSwingletManager();
072: if (sm != null) {
073: sm.putValue(getName(), this );
074: }
075: getSwingletManager().putValue(getName(), this );
076: }
077: }
078:
079: /**
080: * Construct a fully qualified SFrame. The parent frame will need setting
081: * before this component can receive events, or this frame will need
082: * ti be added to the SwingletManager directly.
083: */
084: public SFrame() {
085: SwingletManager sm = getSwingletManager();
086: if (sm != null) {
087: sm.putValue(getName(), this );
088: }
089: }
090:
091: /**
092: * Get the Parent Frame
093: */
094: public SFrame getParentFrame() {
095: return parentFrame;
096: }
097:
098: /**
099: * Set the Parent Frame. This is for use with the null constructor.
100: */
101: public SFrame setFrame(SFrame parentFrame) {
102: firePropertyChange("parentFrame", this .parentFrame,
103: this .parentFrame = parentFrame);
104: return this ;
105: }
106:
107: /**
108: * Get the Parent Frame
109: */
110: public SFrame getTopLevelFrame() {
111: if (parentFrame == null)
112: return this ;
113:
114: return parentFrame.getTopLevelFrame();
115: }
116:
117: /**
118: * Returns the name of the L&F class that renders this component.
119: */
120: public Class getUIClass() {
121: return SFrame.class;
122: }
123:
124: /**
125: * Set the MenuBar on this SFrame
126: */
127: public SFrame setMenuBar(SMenuBar menuBar) {
128: if (this .menuBar == menuBar)
129: return this ;
130:
131: //Remove the frame from the old menu bar
132: if (this .menuBar != null) {
133: this .menuBar.setFrame(null);
134: }
135:
136: this .menuBar = menuBar;
137:
138: //Add the frame on the new menu bar
139: if (menuBar != null) {
140: menuBar.setFrame(this );
141: }
142:
143: return this ;
144: }
145:
146: /**
147: * Get the menu bar for this SFrame
148: */
149: public SMenuBar getMenuBar() {
150: return menuBar;
151: }
152:
153: /**
154: * Get a sub component by name. This will try to get a component from
155: * the menu bar, then from the container.
156: */
157: public SComponent getComponent(String name) {
158: if (getMenuBar() != null) {
159: SComponent c = getMenuBar().getComponent(name);
160: if (c != null)
161: return c;
162: }
163:
164: return super .getComponent(name);
165: }
166:
167: /**
168: * Set the title of the Page.
169: */
170: public SFrame setTitle(String title) {
171: firePropertyChange("title", this .title, this .title = title);
172: return this ;
173: }
174:
175: /**
176: * Get the title of the Page.
177: */
178: public String getTitle() {
179: return title;
180: }
181:
182: /**
183: * Set the description of the Page.
184: */
185: public SFrame setDescription(String description) {
186: firePropertyChange("description", this .description,
187: this .description = description);
188: return this ;
189: }
190:
191: /**
192: * Get the description of the Page.
193: */
194: public String getDescription() {
195: return description;
196: }
197:
198: /**
199: * Set the author of the Page.
200: */
201: public SFrame setAuthor(String author) {
202: firePropertyChange("author", this .author, this .author = author);
203: return this ;
204: }
205:
206: /**
207: * Get the author of the Page.
208: */
209: public String getAuthor() {
210: return author;
211: }
212:
213: /**
214: * Set the link color of the Page.
215: */
216: public SFrame setLinkColor(Color linkColor) {
217: firePropertyChange("linkColor", this .linkColor,
218: this .linkColor = linkColor);
219: return this ;
220: }
221:
222: /**
223: * Get the line color of the Page.
224: * <P>
225: * If the color is null return the theme.getAcceleratorForeground()
226: */
227: public Color getLinkColor() {
228: return linkColor;
229: }
230:
231: /**
232: * Set the active link color of the Page.
233: */
234: public SFrame setActiveLinkColor(Color activeLinkColor) {
235: firePropertyChange("activeLinkColor", this .activeLinkColor,
236: this .activeLinkColor = activeLinkColor);
237: return this ;
238: }
239:
240: /**
241: * Set the active link color of the Page.
242: * <P>
243: * If the color is null return the theme.getAcceleratorSelectedForeground()
244: */
245: public Color getActiveLinkColor() {
246: return activeLinkColor;
247: }
248:
249: /**
250: * Set the background image of the Page.
251: */
252: public SFrame setBackgroundIcon(SIcon backgroundIcon) {
253: firePropertyChange("backgroundIcon", this .backgroundIcon,
254: this .backgroundIcon = backgroundIcon);
255: return this ;
256: }
257:
258: /**
259: * Set the background image of the Page.
260: */
261: public SIcon getBackgroundIcon() {
262: return backgroundIcon;
263: }
264:
265: /**
266: * Get the URL for this frame.
267: */
268: public String getComponentUrl() {
269: if (componentUrl == null) {
270: StringBuffer buf = new StringBuffer();
271: buf.append("?");
272: buf.append(SConstants.SOURCE_CONTAINER);
273: buf.append("=");
274:
275: if (parentFrame == null)
276: buf.append(getName());
277: else
278: buf.append(parentFrame.getName());
279:
280: buf.append("&");
281: buf.append(SConstants.TARGET_COMPONENT);
282: buf.append("=");
283: buf.append(getName());
284:
285: componentUrl = buf.toString();
286: }
287:
288: return componentUrl;
289: }
290:
291: // DISPATCH & EVENTS //////////////////////////////////////////////////////
292:
293: /**
294: * Adds the specified window listener to receive window events from
295: * this window.
296: */
297: public synchronized SFrame addWindowListener(WindowListener listener) {
298: getUI().addListener(listener);
299: return this ;
300: }
301:
302: /**
303: * Removes the specified window listener so that it no longer
304: * receives window events from this window.
305: */
306: public synchronized SFrame removeWindowListener(
307: WindowListener listener) {
308: getUI().removeListener(listener);
309: return this ;
310: }
311:
312: // PRIVATE ///////////////////////////////////////////////////////////////////////////////
313:
314: protected String title;
315: protected String description;
316: protected String author;
317:
318: protected Color textColor;
319: protected Color linkColor;
320: protected Color activeLinkColor;
321: protected SIcon backgroundIcon;
322:
323: protected SMenuBar menuBar;
324:
325: protected SFrame parentFrame;
326:
327: protected Hashtable scripts;
328: }
|