KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > AppletView


1 /*
2   Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 */

18
19 package org.objectweb.jac.aspects.gui;
20  
21 import java.applet.Applet JavaDoc;
22 import java.applet.AppletContext JavaDoc;
23 import java.applet.AppletStub JavaDoc;
24 import java.applet.AudioClip JavaDoc;
25 import java.awt.Image JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Vector JavaDoc;
33 import javax.swing.JApplet JavaDoc;
34 import org.objectweb.jac.aspects.gui.Border;
35 import org.objectweb.jac.aspects.gui.View;
36 import org.objectweb.jac.core.rtti.FieldItem;
37 import org.objectweb.jac.core.rtti.MethodItem;
38
39 /**
40  * This class allows the programmer to insert specialized object views
41  * defined as applets.
42  *
43  * <p>This is useful when views can be used by an Internet browser at
44  * client-side.
45  *
46  * <p>The programmer must subclass this class and overload the
47  * <code>init</code> method.
48  *
49  * @see #init() */

50
51 public class AppletView extends JApplet JavaDoc
52     implements View/*, ComponentListener */
53 {
54     protected String JavaDoc label;
55     protected DisplayContext context;
56     protected ViewFactory factory;
57     protected Object JavaDoc[] parameters;
58     protected String JavaDoc type;
59     protected Object JavaDoc substance;
60
61     /**
62      * The AppletView's constructor.
63      *
64      * @param factory
65      * @param context
66      * @param substance the object that is represented by this view */

67
68     public AppletView(ViewFactory factory, DisplayContext context, Object JavaDoc substance) {
69         this.substance = substance;
70         this.factory = factory;
71         this.context = context;
72         init();
73         start();
74     }
75
76     Border viewBorder;
77    
78     /**
79      * Get the value of viewBorder.
80      * @return value of viewBorder.
81      */

82     public Border getViewBorder() {
83         return viewBorder;
84     }
85    
86     /**
87      * Set the value of viewBorder.
88      * @param v Value to assign to viewBorder.
89      */

90     public void setViewBorder(Border v) {
91         this.viewBorder = v;
92     }
93    
94     View parentView;
95    
96     /**
97      * Get the value of parent.
98      * @return value of parent.
99      */

100     public View getParentView() {
101         return parentView;
102     }
103    
104     /**
105      * Set the value of parent.
106      * @param v Value to assign to parent.
107      */

108     public void setParentView(View v) {
109         this.parentView = v;
110     }
111
112     public View getRootView() {
113         if (parentView==null)
114             return this;
115         return parentView.getRootView();
116     }
117
118     public boolean isDescendantOf(View ancestor) {
119         if (this==ancestor)
120             return true;
121         else if (parentView==null)
122             return false;
123         else
124             return parentView.isDescendantOf(ancestor);
125     }
126
127     // style used to change display (css for web)
128
String JavaDoc style;
129
130     public void setStyle(String JavaDoc style) {
131         this.style = style;
132     }
133
134     public String JavaDoc getStyle() {
135         return style;
136     }
137
138
139     // View interface
140

141     Border border;
142    
143     /**
144      * Get the value of border.
145      * @return value of border.
146      */

147     public Border getBorder() {
148         return border;
149     }
150    
151     /**
152      * Set the value of border.
153      * @param v Value to assign to border.
154      */

155     public void setBorder(Border v) {
156         this.border = v;
157     }
158    
159     String JavaDoc description;
160    
161     /**
162      * Get the value of description.
163      * @return value of description.
164      */

165     public String JavaDoc getDescription() {
166         return description;
167     }
168    
169     /**
170      * Set the value of description.
171      * @param v Value to assign to description.
172      */

173     public void setDescription(String JavaDoc v) {
174         this.description = v;
175     }
176    
177
178     public void setLabel(String JavaDoc label) {
179         this.label = label;
180     }
181    
182     public String JavaDoc getLabel() {
183         return label;
184     }
185
186     MethodItem message;
187    
188     /**
189      * Get the value of message.
190      * @return value of message.
191      */

192     public MethodItem getMessage() {
193         return message;
194     }
195    
196     /**
197      * Set the value of message.
198      * @param v Value to assign to message.
199      */

200     public void setMessage(MethodItem v) {
201         this.message = v;
202     }
203
204     public void setContext(DisplayContext context) {
205         this.context = context;
206     }
207
208     public DisplayContext getContext() {
209         return context;
210     }
211
212     public void setFactory(ViewFactory factory) {
213         this.factory = factory;
214     }
215
216     public ViewFactory getFactory() {
217         return factory;
218     }
219
220     public void setWidth(int width) {
221     }
222
223     public void setHeight(int heigth) {
224     }
225
226     public void setParameters(Object JavaDoc[] parameters) {
227         this.parameters = parameters;
228     }
229
230     public Object JavaDoc[] getParameters() {
231         return parameters;
232     }
233
234     public void setType(String JavaDoc type) {
235         this.type = type;
236     }
237
238     public String JavaDoc getType() {
239         return type;
240     }
241
242     public boolean equalsView(ViewIdentity view) {
243         return
244             ( ( type!=null &&
245                 type.equals(view.getType()) )
246               || (type==null && view.getType()==null ) )
247             && ( ( parameters!=null &&
248                    Arrays.equals(parameters,view.getParameters()) )
249                  || (parameters==null && view.getParameters()==null) );
250     }
251
252     public boolean equalsView(String JavaDoc type, Object JavaDoc[] parameters) {
253         return this.type.equals(type)
254             && Arrays.equals(this.parameters,parameters);
255     }
256
257     public void close(boolean validate) {
258         closed = true;
259     }
260
261     boolean closed = false;
262
263     public boolean isClosed() {
264         return closed;
265     }
266    
267     public Object JavaDoc getSubstance() {
268         return substance;
269     }
270    
271     public void setSubstance(Object JavaDoc substance) {
272         this.substance = substance;
273     }
274
275     public void setFocus(FieldItem field, Object JavaDoc option) {
276     }
277
278     /**
279      * Initializes the applet view.
280      *
281      * <p>The programmer must overload this class and start the init
282      * method code with <code>super.init()</code> so that the applet's
283      * container initialization is done. */

284
285     public void init() {
286         setStub(new InternalStub(new InternalContext(),this));
287     }
288
289     // The following classes simulate an applet container for the JAC
290
// Swing GUI.
291

292     static class InternalStub implements AppletStub JavaDoc {
293         InternalContext context;
294         public InternalStub(InternalContext context,Applet JavaDoc applet) {
295             this.context = context;
296             context.setApplet(applet);
297         }
298         public void appletResize(int width, int height) {
299             //Log.trace("gui.applet","resizing applet");
300
//applet.setSize(width,height);
301
}
302         public AppletContext JavaDoc getAppletContext() {
303             return context;
304         }
305         public URL JavaDoc getCodeBase() {
306             URL JavaDoc ret = null;
307             try {
308                 ret = new URL JavaDoc("file:/");
309             } catch(Exception JavaDoc e) {
310                 e.printStackTrace();
311             }
312             return ret;
313         }
314         public URL JavaDoc getDocumentBase() {
315             URL JavaDoc ret = null;
316             try {
317                 ret = new URL JavaDoc("file:/");
318             } catch(Exception JavaDoc e) {
319                 e.printStackTrace();
320             }
321             return ret;
322         }
323         public String JavaDoc getParameter(String JavaDoc name) {
324             return null;
325         }
326         public boolean isActive() {
327             return true;
328         }
329     }
330
331     static class InternalContext implements AppletContext JavaDoc {
332         public void setApplet(Applet JavaDoc a) {
333             v.add(a);
334         }
335         Vector JavaDoc v=new Vector JavaDoc();
336         public Applet JavaDoc getApplet(String JavaDoc name) {
337             return (Applet JavaDoc)v.get(0);
338         }
339         public Enumeration JavaDoc getApplets() {
340             return v.elements();
341         }
342         public AudioClip JavaDoc getAudioClip(URL JavaDoc url) {
343             return null;
344         }
345         public Image JavaDoc getImage(URL JavaDoc url) {
346             return null;
347         }
348         public void showDocument(URL JavaDoc url) {}
349         public void showDocument(URL JavaDoc url, String JavaDoc target) {}
350         public void showStatus(String JavaDoc status) {}
351         // since JDK 1.4
352
Vector JavaDoc streamKeys=new Vector JavaDoc();
353         public void setStream(String JavaDoc key,
354                               InputStream JavaDoc stream)
355             throws IOException JavaDoc {}
356         public InputStream JavaDoc getStream(String JavaDoc key) {
357             return null;
358         }
359         public Iterator JavaDoc getStreamKeys() {
360             return streamKeys.iterator();
361         }
362     }
363
364 }
365
Popular Tags