xref: /titanic_41/usr/src/cmd/krb5/kadmin/gui/visualrt/sunsoft/jws/visual/rt/shadow/java/awt/FrameShadow.java (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * ident	"%Z%%M%	%I%	%E% SMI"
24  *
25  * Copyright (c) 2000 by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28 
29 /*
30  *        Copyright (C) 1996  Active Software, Inc.
31  *                  All rights reserved.
32  *
33  * @(#) @(#) FrameShadow.java 1.65 - last change made 08/11/97
34  */
35 
36 package sunsoft.jws.visual.rt.shadow.java.awt;
37 
38 import sunsoft.jws.visual.rt.base.Global;
39 import sunsoft.jws.visual.rt.base.DesignerAccess;
40 import sunsoft.jws.visual.rt.base.*;
41 import sunsoft.jws.visual.rt.type.ImageRef;
42 import sunsoft.jws.visual.rt.awt.RootFrame;
43 
44 import java.awt.*;
45 
46 /**
47  * Wraps an AWT widget.  The attributes available for this
48  * class are listed below.  In the type column, type names beginning
49  * with "sunsoft.jws.visual.rt" have been abbreviated to begin with "rt".
50  *
51  * <pre>
52 name            type                      default value
53 -----------------------------------------------------------------------
54 + background      java.awt.Color            #c0c0c0
55 icon            rt.type.ImageRef          null
56 menubar         rt.type.MenuBarRef        null
57 resizable       java.lang.Boolean         true
58 title           java.lang.String          "Unnamed Frame"
59 *  < /pre>
60 *
61 * + = this attribute overrides one inherited from an ancestor class.
62 *  < p>
63 * Check the super class for additional attributes.
64 *
65 * @see Frame
66 * @version 	1.65, 08/11/97
67 */
68 public class FrameShadow extends WindowShadow {
69 
70     private int cursorCount = 0;
71     private int prevCursor = Frame.DEFAULT_CURSOR;
72 
FrameShadow()73     public FrameShadow() {
74         attributes.add(/* NOI18N */"title", /* NOI18N */"java.lang.String",
75 		    /* JSTYLED */
76 		       Global.getMsg("sunsoft.jws.visual.rt.shadow.java.awt.FrameShadow.title"),
77 		       NOEDITOR);
78         attributes.alias(/* NOI18N */"text", /* NOI18N */"title");
79         attributes.add(/* NOI18N */"resizable",
80 		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, 0);
81         attributes.add(/* NOI18N */"icon",
82 		       /* NOI18N */"sunsoft.jws.visual.rt.type.ImageRef",
83 		       null, 0);
84         attributes.add(/* NOI18N */"menubar",
85 		    /* JSTYLED */
86 		       /* NOI18N */"sunsoft.jws.visual.rt.shadow.java.awt.MenuBarShadow",
87 		       null, DEFAULT | TRANSIENT);
88 
89         if (Global.isIrix())
90 	    attributes.add(/* NOI18N */"font", /* NOI18N */"java.awt.Font",
91 			   new Font(/* NOI18N */"Sansserif",
92 				    Font.PLAIN, 12), DONTFETCH);
93 
94         if (Global.isWindows()) {
95             attributes.add(/* NOI18N */"font", /* NOI18N */"java.awt.Font",
96 			   new Font(/* NOI18N */"Dialog",
97 				    Font.PLAIN, 12), DONTFETCH);
98         }
99     }
100 
getOnBody(String key)101     protected Object getOnBody(String key) {
102         Frame frame = (Frame)body;
103 
104         if (key.equals(/* NOI18N */"title"))
105 	    return frame.getTitle();
106         else if (key.equals(/* NOI18N */"resizable"))
107             return new Boolean(frame.isResizable());
108         else if (key.equals(/* NOI18N */"icon"))
109             return getFromTable(/* NOI18N */"icon");
110         else if (key.equals(/* NOI18N */"menubar")) {
111             MenuBar menuBar = frame.getMenuBar();
112             if (menuBar == null)
113                 return null;
114             else
115                 return DesignerAccess.getShadowTable().get(menuBar);
116         } else
117             return (super.getOnBody(key));
118     }
119 
setOnBody(String key, Object value)120     protected void setOnBody(String key, Object value) {
121         Frame frame = (Frame)body;
122 
123         if (key.equals(/* NOI18N */"title")) {
124             frame.setTitle((String) value);
125         } else if (key.equals(/* NOI18N */"resizable")) {
126             frame.setResizable(((Boolean) value).booleanValue());
127         } else if (key.equals(/* NOI18N */"menubar")) {
128             MenuBarShadow s = (MenuBarShadow)getOnBody(/* NOI18N */"menubar");
129             if (s != null) {
130                 remove(s);
131                 s.destroy();
132             }
133 
134             if (value != null) {
135                 s = (MenuBarShadow)value;
136                 add(s);
137                 s.create();
138             }
139         } else if (key.equals(/* NOI18N */"icon")) {
140             if (value != null) {
141                 try {
142                     frame.setIconImage(((ImageRef) value).
143 				    getImage(frame, getGroup().getApplet()));
144                 }
145                 catch (VJException ex) {
146                     if (isLive())
147 			    /* JSTYLED */
148 			    System.out.println(/* NOI18N */"Error: " + ex.getMessage());
149                     else
150                         throw ex;
151                 }
152             } else if (frame.getPeer() == null)
153                 frame.setIconImage(null);
154         }
155         else
156             super.setOnBody(key, value);
157     }
158 
getUserTypeName()159     protected String getUserTypeName() {
160         return (/* NOI18N */"frame");
161     }
162 
createBody()163     public void createBody() {
164         if (!inDesignerRoot())
165 	    body = new RootFrame();
166         else {
167             try {
168                 body = DesignerAccess.getFrameClass().newInstance();
169             } catch (InstantiationException ex) {
170                 throw new Error(ex.toString());
171             } catch (IllegalAccessException ex) {
172                 throw new Error(ex.toString());
173             }
174         }
175     }
176 
177     // Overridden AMContainer interfaces
178 
addChildBody(Shadow child)179     public void addChildBody(Shadow child) {
180         // frames will have a single central child and maybe a menubar
181         if (body != null) {
182             Frame frame = (Frame)body;
183 
184             if (child instanceof MenuBarShadow) {
185                 // add the menubar
186                 MenuBar currentMenuBar = frame.getMenuBar();
187                 if (currentMenuBar != null
188 		    && currentMenuBar != child.getBody()) {
189 			/* JSTYLED */
190                     throw new Error(Global.fmtMsg("sunsoft.jws.visual.rt.awt.java.awt.FrameShadow.AlreadyHasMenubar", child.get(/* NOI18N */"name")));
191                 } else {
192                     frame.setMenuBar((MenuBar) child.getBody());
193                 }
194             } else {
195                 // add a component
196                 if (frame.getLayout() instanceof BorderLayout) {
197                     frame.add(/* NOI18N */"Center",
198 			      (Component) child.getBody());
199                 } else {
200                     super.addChildBody(child);
201                 }
202             }
203         }
204     }
205 
removeChildBody(Shadow child)206     public void removeChildBody(Shadow child) {
207         if (body != null) {
208             if ((child instanceof MenuBarShadow)) {
209 		/* JSTYLED */
210                 if (!((Frame) body).getMenuBar().equals((MenuBar) child.getBody())) {
211 			/* JSTYLED */
212                     throw new Error(Global.fmtMsg("sunsoft.jws.visual.rt.awt.java.awt.FrameShadow.MenubarNotInstalled", child.get(/* NOI18N */"name")));
213                 } else {
214                     // remove the  menubar
215                     ((Frame) body).remove((MenuComponent) child.getBody());
216                 }
217             } else {
218                 // remove a component
219                 ((Frame) body).remove((Component) child.getBody());
220             }
221         }
222     }
223 
incrCursor()224     int incrCursor() {
225         cursorCount++;
226         return cursorCount;
227     }
228 
decrCursor()229     int decrCursor() {
230         cursorCount--;
231         if (cursorCount < 0)
232             cursorCount = 0;
233         return cursorCount;
234     }
235 
setPrevCursor(int cursor)236     void setPrevCursor(int cursor) {
237         prevCursor = cursor;
238     }
239 
getPrevCursor()240     int getPrevCursor() {
241         return prevCursor;
242     }
243 }
244