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 * @(#) GenericWindowShadow.java 1.13 - last change made 05/02/97 34 */ 35 36package sunsoft.jws.visual.rt.shadow; 37 38import sunsoft.jws.visual.rt.shadow.java.awt.WindowShadow; 39import sunsoft.jws.visual.rt.awt.RootFrame; 40import sunsoft.jws.visual.rt.awt.RootDialog; 41import sunsoft.jws.visual.rt.base.Global; 42import sunsoft.jws.visual.rt.base.VJException; 43import sunsoft.jws.visual.rt.base.Message; 44 45 46import java.awt.*; 47 48/** 49 * Wraps an AWT widget. The attributes available for this 50 * class are listed below. In the type column, type names beginning 51 * with "sunsoft.jws.visual.rt" have been abbreviated to begin with 52 * "rt". 53 * 54 * < pre> 55name type default value 56----------------------------------------------------------------------- 57class java.lang.String rt.awt.RootFrame 58title java.lang.String "Generic Window" 59* < /pre> 60* 61* class: the java class(that must be a sub-class of 62* sunsoft.jws.visual.rt.awt.RootFrame and have a null constructor) of 63* a user-written window class. The GenericWindowShadow class can be 64* used for quickly incorporating user's existing windows into a 65* Visual Java GUI. 66* < p> 67* Check the super class for additional attributes. 68* 69* @see RootFrame 70* @see RootDialog 71* @see GenericComponentShadow 72* @version 1.13, 05/02/97 73*/ 74public class GenericWindowShadow extends WindowShadow { 75 private String className; 76 private Class genericClass; 77 78 public GenericWindowShadow() { 79 attributes.add(/* NOI18N */"class", 80 /* NOI18N */"java.lang.String", 81 /* NOI18N */"sunsoft.jws.visual.rt.awt.RootFrame", 82 NOEDITOR); 83 attributes.add(/* NOI18N */"title", 84 /* NOI18N */"java.lang.String", 85 /* NOI18N */"Generic Window", NOEDITOR); 86 attributes.alias(/* NOI18N */"text", /* NOI18N */"title"); 87 88 if (Global.isIrix()) 89 attributes.add(/* NOI18N */"font", /* NOI18N */"java.awt.Font", 90 new Font(/* NOI18N */"Sansserif", Font.PLAIN, 12), 91 DONTFETCH); 92 93 if (Global.isWindows()) { 94 attributes.add(/* NOI18N */"background", 95 /* NOI18N */"java.awt.Color", 96 Color.lightGray, DONTFETCH); 97 attributes.add(/* NOI18N */"font", 98 /* NOI18N */"java.awt.Font", 99 new Font(/* NOI18N */"Dialog", Font.PLAIN, 12), 100 DONTFETCH); 101 } 102 } 103 104 protected boolean useLayoutSize() { 105 return false; 106 } 107 108 protected Object getOnBody(String key) { 109 if (key.equals(/* NOI18N */"class")) 110 return getFromTable(/* NOI18N */"class"); 111 else if (key.equals(/* NOI18N */"title")) { 112 if (body instanceof RootFrame) 113 return ((RootFrame)body).getTitle(); 114 else 115 return ((RootDialog)body).getTitle(); 116 } 117 else 118 return super.getOnBody(key); 119 } 120 121 protected void setOnBody(String key, Object value) { 122 if (key.equals(/* NOI18N */"class")) { 123 // Don't create a new instance unless 124 // the class name has changed 125 if (className.equals((String)value)) 126 return; 127 128 Object obj = loadClass((String)value); 129 destroy(); 130 body = obj; 131 create(); 132 } else if (key.equals(/* NOI18N */"title")) { 133 if (body instanceof RootFrame) 134 ((RootFrame)body).setTitle((String)value); 135 else 136 ((RootDialog)body).setTitle((String)value); 137 } 138 else 139 super.setOnBody(key, value); 140 } 141 142 public void createBody() { 143 body = loadClass((String)get(/* NOI18N */"class")); 144 } 145 146 protected void registerBody() { 147 super.registerBody(); 148 149 Window win = (Window)body; 150 if (win.countComponents() == 0) 151 win.add(new Label(/* NOI18N */"Generic Window")); 152 } 153 154 private Object loadClass(String name) { 155 Class c; 156 Object obj; 157 158 // Load the class if the name doesn't match the previous name 159 if (!name.equals(className)) { 160 try { 161 c = Class.forName(name); 162 } 163 catch (ClassNotFoundException ex) { 164 throw new VJException( 165 /* JSTYLED */ 166 Global.fmtMsg("sunsoft.jws.visual.rt.shadow.GenericWindowShadow.Class__not__found", name)); 167 } 168 } else { 169 c = genericClass; 170 } 171 172 // Create a new instance from the class 173 try { 174 obj = c.newInstance(); 175 if (!(obj instanceof RootFrame) 176 && !(obj instanceof RootDialog)) { 177 throw new VJException( 178 /* JSTYLED */ 179 Global.fmtMsg("sunsoft.jws.visual.rt.shadow.GenericWindowShadow.NotARootSubclass", name)); 180 } 181 } 182 catch (IllegalAccessException ex) { 183 throw new VJException( 184 /* JSTYLED */ 185 Global.fmtMsg("sunsoft.jws.visual.rt.shadow.GenericWindowShadow.IllegalAccess", name)); 186 } 187 catch (InstantiationException ex) { 188 throw new VJException( 189 /* JSTYLED */ 190 Global.fmtMsg("sunsoft.jws.visual.rt.shadow.GenericWindowShadow.InstantiationException", name)); 191 } 192 catch (NoSuchMethodError ex) { 193 throw new VJException( 194 /* JSTYLED */ 195 Global.fmtMsg("sunsoft.jws.visual.rt.shadow.GenericWindowShadow.Noconstructor", name)); 196 } 197 198 // No errors occurred, so update the name and class variables. 199 genericClass = c; 200 className = name; 201 202 return obj; 203 } 204 205 public boolean handleEvent(Message msg, Event evt) 206 { 207 if (msg.target == this && evt.id == Event.WINDOW_DESTROY) 208 { 209 Window win = (Window)body; 210 win.hide(); 211 return true; 212 } else 213 return super.handleEvent(msg, evt); 214 } 215} 216