001: /*
002: * @(#)XletFrame.java 1.9 05/03/21
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package sun.mtask.xlet;
029:
030: import java.awt.Container;
031: import java.awt.Frame;
032: import java.awt.BorderLayout;
033: import java.awt.Insets;
034:
035: import sun.awt.SunToolkit;
036: import java.awt.Toolkit;
037:
038: import sun.mtask.xlet.PXletManager;
039:
040: import java.awt.event.WindowEvent;
041: import java.awt.event.WindowAdapter;
042:
043: class XletFrame extends Frame {
044: Container theContainer;
045: // Dimensions of an xlet frame
046: private static int x;
047: private static int y;
048: private static int w;
049: private static int h;
050: private static int wOffset;
051: private static int hOffset;
052: private static boolean initialized = false;
053:
054: private static boolean verbose = (System
055: .getProperty("cdcams.verbose") != null)
056: && (System.getProperty("cdcams.verbose").toLowerCase()
057: .equals("true"));
058:
059: private boolean doDecorations;
060:
061: XletFrame(String name) {
062: super (name);
063: if (!XletFrame.initialized) {
064: throw new Error("FATAL ERROR: Did not initialize "
065: + "xlet frame dimensions");
066: }
067:
068: String decorations = System.getProperty("cdcams.decorations");
069: if (decorations == null) {
070: doDecorations = true;
071: } else {
072: doDecorations = decorations.equals("true");
073: }
074:
075: if (doDecorations) {
076: addWindowListener(new WindowAdapter() {
077: public void windowClosing(WindowEvent windowevent) {
078: System.exit(0);
079: }
080: });
081: } else {
082: XletFrame.w += XletFrame.wOffset;
083: XletFrame.h += XletFrame.hOffset;
084: setUndecorated(true);
085: }
086: }
087:
088: XletFrame(String name, String laf, String theme) {
089: this (name);
090: }
091:
092: XletFrame(String name, PXletManager manager, String laf,
093: String theme) {
094: this (name);
095: }
096:
097: class XletContainer extends Container {
098: Frame frame;
099:
100: XletContainer(Frame xletFrame) {
101: frame = xletFrame;
102: }
103:
104: public void setVisible(boolean visible) {
105: if (visible) {
106: frame.setBounds(x, y, w, h);
107: }
108:
109: super .setVisible(visible);
110: frame.setVisible(visible);
111: }
112: }
113:
114: Container getContainer() {
115: if (theContainer != null) {
116: return theContainer;
117: }
118: Container c = new XletContainer(this );
119: c.setLayout(new BorderLayout());
120: add(c);
121: validate();
122: // Keep container invisible, per the xlet spec
123: c.setVisible(false);
124: // This is the one container
125: theContainer = c;
126: return theContainer;
127: }
128:
129: // No look and feel changes in vanilla basis or personal
130: void changeLookAndFeel(String lafName) {
131: if (verbose) {
132: System.err.println("LOOK AND FEEL CHANGE NOT SUPPORTED");
133: }
134: }
135:
136: void changeLookAndFeelTheme(String themeName) {
137: if (verbose) {
138: System.err.println("LOOK AND FEEL CHANGE NOT SUPPORTED");
139: }
140: }
141:
142: // native void synthesizeFocusIn();
143:
144: public void activate() {
145: SunToolkit tk = (SunToolkit) Toolkit.getDefaultToolkit();
146: tk.activate(this );
147: }
148:
149: public void deactivate() {
150: SunToolkit tk = (SunToolkit) Toolkit.getDefaultToolkit();
151: tk.deactivate(this );
152: }
153:
154: public static void setFrameDimensions(int dimX, int dimY, int dimW,
155: int dimH, int dimWOffset, int dimHOffset) {
156: if (verbose) {
157: System.err.println("SETTING XLET FRAME DIMENSIONS: " + dimX
158: + ", " + dimY + ", " + dimW + ", " + dimH + ", "
159: + dimWOffset + ", " + dimHOffset);
160: }
161: x = dimX;
162: y = dimY;
163: w = dimW;
164: h = dimH;
165: wOffset = dimWOffset;
166: hOffset = dimHOffset;
167: }
168:
169: //
170: // Source XletFrame with x,y,w,h,hOffset arguments
171: //
172: public static void main(String[] args) {
173: String xStr = args[0];
174: String yStr = args[1];
175: String wStr = args[2];
176: String hStr = args[3];
177: String wOffsetStr = args[4];
178: String hOffsetStr = args[5];
179: try {
180: setFrameDimensions(Integer.parseInt(xStr), Integer
181: .parseInt(yStr), Integer.parseInt(wStr), Integer
182: .parseInt(hStr), Integer.parseInt(wOffsetStr),
183: Integer.parseInt(hOffsetStr));
184: initialized = true;
185: } catch (Exception e) {
186: e.printStackTrace();
187: }
188: }
189:
190: }
|