001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package graphical;
012:
013: import java.awt.Dimension;
014:
015: import netscape.application.Bitmap;
016: import netscape.application.Button;
017: import netscape.application.ExternalWindow;
018: import netscape.application.InternalWindow;
019: import netscape.application.Rect;
020: import netscape.application.Target;
021: import netscape.application.View;
022: import netscape.application.Window;
023:
024: /**
025: IconInternalWindow.
026: <p>
027: The window is by default closeable and minimizeable.
028: *
029: */
030: public class IconInternalWindow extends InternalWindow {
031: public static final String MINIMIZE = "Minimize";
032:
033: private Minimize minimize;
034:
035: private Button minButton;
036: private boolean minimizeable;
037:
038: private String m_closeCommand;
039: private Target m_closeTarget = null;
040:
041: private String m_desktopBroadcastCommand;
042: private Target m_desktopBroadcastTarget = null;
043:
044: public WindowTiler windowTiler = null;
045:
046: public IconInternalWindow(Minimize minimize) {
047: super ();
048: commonConstruction(minimize);
049: }
050:
051: public IconInternalWindow(int x, int y, int width, int height,
052: Minimize minimize) {
053: super (x, y, width, height);
054: commonConstruction(minimize);
055: }
056:
057: public IconInternalWindow(int type, int x, int y, int width,
058: int height, Minimize minimize) {
059: super (type, x, y, width, height);
060: commonConstruction(minimize);
061: }
062:
063: public IconInternalWindow(Rect rect, Minimize minimize) {
064: super (rect);
065: commonConstruction(minimize);
066: }
067:
068: private void commonConstruction(Minimize minimize) {
069: minButton = createMinButton();
070: setMinimize(minimize, null);
071: setCloseable(true);
072: }
073:
074: public void setMinimize(Minimize minimize,
075: ExternalWindow externalWindow) {
076: setMinimizeInfo(minimize);
077: windowsAndViews(externalWindow);
078: }
079:
080: public void setMinimize(Bitmap bitmap, String title,
081: ExternalWindow externalWindow, WindowTiler windowTiler) {
082: if (bitmap == null) {
083: setMinimizeable(false);
084: return;
085: }
086:
087: setMinimizeable(true);
088:
089: setMinimizeInfo(new Minimize(bitmap, this , title));
090: windowsAndViews(externalWindow);
091: this .windowTiler = windowTiler;
092: }
093:
094: private void setMinimizeInfo(Minimize minimize) {
095: this .minimize = minimize;
096: minimizeable = (minimize == null) ? false
097: : (minimize.image() != null);
098: layoutParts();
099: }
100:
101: private void windowsAndViews(ExternalWindow externalWindow) {
102: if (minimize != null) {
103: minimize.setWindow(this );
104: if (externalWindow != null) {
105: minimize.setRootView(externalWindow.rootView());
106:
107: if (externalWindow.menuView() != null) {
108: minimize.menuHeight = externalWindow.menuView()
109: .height();
110: }
111: }
112: }
113: }
114:
115: /**
116: * "true" can be overridden to false if validation steps fail.
117: */
118: public void setMinimizeable(boolean flag) {
119: minimizeable = flag;
120:
121: if (type() == BLANK_TYPE) {
122: minimizeable = false;
123: }
124:
125: // validate minimizeable before proceeding
126: if (minimizeable) {
127: setMinimizeInfo(minimize);
128: }
129:
130: if (minimizeable) {
131: addSubviewToWindow(minButton);
132: } else {
133: minButton.removeFromSuperview();
134: }
135: }
136:
137: public void addSubview(View aView) {
138: if (aView == minButton) {
139: addSubviewToWindow(aView);
140: } else {
141: super .addSubview(aView);
142: }
143: }
144:
145: public void layoutParts() {
146: super .layoutParts();
147:
148: if (minButton != null) {
149: minButton.removeFromSuperview();
150: minButton
151: .moveTo(
152: width() - minButton.bounds.width,
153: 2 + (titleBarMargin() - 4 - minButton.bounds.height) / 2);
154:
155: if (minimizeable) {
156: addSubview(minButton);
157: }
158: }
159: }
160:
161: protected Button createMinButton() {
162: Button button;
163: button = new Button(0, 0, 1, 1);
164: button.setImage(Bitmap
165: .bitmapNamed("netscape/application/CloseButton.gif"));
166: button
167: .setAltImage(Bitmap
168: .bitmapNamed("netscape/application/CloseButtonActive.gif"));
169: button.setTransparent(true);
170: button.sizeToMinSize();
171: button.setHorizResizeInstruction(View.RIGHT_MARGIN_CAN_CHANGE);
172: button.setVertResizeInstruction(View.BOTTOM_MARGIN_CAN_CHANGE);
173: button.moveTo(width() - button.bounds.width,
174: 2 + (titleBarMargin() - 4 - button.bounds.height) / 2);
175: button.setTarget(this );
176: button.setCommand(MINIMIZE);
177: button.removeAllCommandsForKeys();
178: return button;
179: }
180:
181: protected int titleBarMargin() {
182: if (type() == BLANK_TYPE) {
183: return 0;
184: } else {
185: return border().topMargin();
186: }
187: }
188:
189: public void performCommand(String command, Object arg) {
190: if (MINIMIZE.equals(command)) {
191: if (minimizeable) {
192: hide();
193:
194: if (minimize != null) {
195: if (windowTiler != null) {
196: windowTiler.minimizeWindow(minimize);
197: }
198:
199: minimize.show();
200: minimize.draw();
201: }
202: }
203: } else if (applications.Messages.CMD_DESKTOP_BROADCAST
204: .equals(command)) {
205: // If the broadcast message makes it here, nobody is interested,
206: // so throw it out.
207: // System.out.println("Broadcasting Tax Chg trashed======\n" + "\n=======");
208: return;
209: } else {
210: if (HIDE.equals(command)) {
211: if (m_closeTarget != null) {
212: m_closeTarget.performCommand(m_closeCommand, null);
213:
214: // This isn't nice but close processing might abort the
215: // command to it is up to the close handler to actually hide
216: // the window as performCommand cannot return a result. I must
217: // not super the event. (MCW).
218: return;
219: }
220: }
221:
222: super .performCommand(command, arg);
223: }
224: }
225:
226: public void setCloseTarget(Target closeTarget) {
227: m_closeTarget = closeTarget;
228: }
229:
230: public void setCloseCommand(String closeCommand) {
231: m_closeCommand = closeCommand;
232: }
233:
234: public void setDesktopBroadcastTarget(Target target) {
235: m_desktopBroadcastTarget = target;
236: }
237:
238: public void setDesktopBroadcastCommand(String command) {
239: m_desktopBroadcastCommand = command;
240: }
241:
242: public Target desktopBroadcastTarget() {
243: return m_desktopBroadcastTarget;
244: }
245:
246: public String desktopBroadcastCommand() {
247: return m_desktopBroadcastCommand;
248: }
249:
250: public void setWindowTiler(WindowTiler windowTiler) {
251: this .windowTiler = windowTiler;
252: }
253:
254: /**
255: * hideIcon - Designed to be called when an external program
256: * is restoring a minimized window. It will remove the icon.
257: */
258: public void hideIcon() {
259: minimize.hide();
260: windowTiler.restoreWindow(minimize);
261: minimize.setDirty(true);
262: }
263:
264: /**
265: * Override to include save on close etc.
266: */
267: public boolean closeRequest() {
268: return true;
269: }
270: }
|