OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [appletviewer/] [PluginAppletWindow.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* PluginAppletWindow.java -- an embeddable applet window
2
   Copyright (C) 2003, 2004, 2006  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package gnu.classpath.tools.appletviewer;
39
 
40
import gnu.java.awt.EmbeddedWindow;
41
 
42
import java.applet.Applet;
43
import java.applet.AppletContext;
44
import java.awt.Dimension;
45
import java.awt.event.ComponentEvent;
46
import java.awt.event.ComponentListener;
47
import java.awt.event.ContainerEvent;
48
import java.awt.event.ContainerListener;
49
import java.awt.event.HierarchyBoundsListener;
50
import java.awt.event.HierarchyEvent;
51
import java.awt.event.HierarchyListener;
52
import java.awt.event.InputMethodEvent;
53
import java.awt.event.InputMethodListener;
54
import java.awt.event.MouseEvent;
55
import java.awt.event.MouseListener;
56
import java.awt.event.MouseMotionListener;
57
import java.io.IOException;
58
import java.io.StringReader;
59
import java.net.MalformedURLException;
60
import java.net.URL;
61
import java.util.ArrayList;
62
import java.util.HashMap;
63
 
64
 
65
class PluginAppletWindow
66
    extends EmbeddedWindow
67
    implements ContainerListener, ComponentListener, MouseListener,
68
    MouseMotionListener, InputMethodListener, HierarchyListener,
69
    HierarchyBoundsListener
70
{
71
 
72
  // This class implements various listeners because the author of an applet
73
  // may attach listeners to it, unaware of the applet's parent (this class).
74
  // So, we must pass all listener events on this plugin applet window to the
75
  // actual applet.
76
 
77
  private static HashMap contexts = new HashMap();
78
  private Applet applet;
79
  private TagParser parser;
80
  private AppletTag tag;
81
 
82
  PluginAppletWindow()
83
  {
84
    super();
85
    addContainerListener(this);
86
    addComponentListener(this);
87
    addMouseListener(this);
88
    addMouseMotionListener(this);
89
    addInputMethodListener(this);
90
    addHierarchyListener(this);
91
    addHierarchyBoundsListener(this);
92
  }
93
 
94
  ///////////////////////////////////
95
  /// ContainerListener Methods /////
96
  ///////////////////////////////////
97
 
98
  /**
99
   * This method is called when a component is added to the container.
100
   *
101
   * @param event the <code>ContainerEvent</code> indicating component
102
   *          addition
103
   */
104
  public void componentAdded(ContainerEvent event)
105
  {
106
    if (applet != null)
107
      {
108
        ContainerListener[] l = applet.getContainerListeners();
109
        for (int i = 0; i < l.length; i++)
110
          l[i].componentAdded(event);
111
      }
112
  }
113
 
114
  /**
115
   * This method is called when a component is removed from the container.
116
   *
117
   * @param event the <code>ContainerEvent</code> indicating component removal
118
   */
119
  public void componentRemoved(ContainerEvent event)
120
  {
121
    if (applet != null)
122
      {
123
        ContainerListener[] l = applet.getContainerListeners();
124
        for (int i = 0; i < l.length; i++)
125
          l[i].componentRemoved(event);
126
      }
127
  }
128
 
129
  ///////////////////////////////////
130
  /// ComponentListener Methods /////
131
  ///////////////////////////////////
132
 
133
  /**
134
   * This method is called when the component is resized.
135
   *
136
   * @param event the <code>ComponentEvent</code> indicating the resize
137
   */
138
  public void componentResized(ComponentEvent event)
139
  {
140
    if (applet != null)
141
      {
142
        ComponentListener[] l = applet.getComponentListeners();
143
        for (int i = 0; i < l.length; i++)
144
          l[i].componentResized(event);
145
      }
146
  }
147
 
148
  /**
149
   * This method is called when the component is moved.
150
   *
151
   * @param event the <code>ComponentEvent</code> indicating the move
152
   */
153
  public void componentMoved(ComponentEvent event)
154
  {
155
    if (applet != null)
156
      {
157
        ComponentListener[] l = applet.getComponentListeners();
158
        for (int i = 0; i < l.length; i++)
159
          l[i].componentMoved(event);
160
      }
161
  }
162
 
163
  /**
164
   * This method is called when the component is made visible.
165
   *
166
   * @param event the <code>ComponentEvent</code> indicating the visibility
167
   */
168
  public void componentShown(ComponentEvent event)
169
  {
170
    if (applet != null)
171
      {
172
        ComponentListener[] l = applet.getComponentListeners();
173
        for (int i = 0; i < l.length; i++)
174
          l[i].componentShown(event);
175
      }
176
  }
177
 
178
  /**
179
   * This method is called when the component is hidden.
180
   *
181
   * @param event the <code>ComponentEvent</code> indicating the visibility
182
   */
183
  public void componentHidden(ComponentEvent event)
184
  {
185
    if (applet != null)
186
      {
187
        ComponentListener[] l = applet.getComponentListeners();
188
        for (int i = 0; i < l.length; i++)
189
          l[i].componentHidden(event);
190
      }
191
  }
192
 
193
  ///////////////////////////////////
194
  ////// MouseListener Methods //////
195
  ///////////////////////////////////
196
 
197
  /**
198
   * This method is called when the mouse is clicked (pressed and released
199
   * in short succession) on a component.
200
   *
201
   * @param event the <code>MouseEvent</code> indicating the click
202
   */
203
  public void mouseClicked(MouseEvent event)
204
  {
205
    if (applet != null)
206
      {
207
        MouseListener[] l = applet.getMouseListeners();
208
        for (int i = 0; i < l.length; i++)
209
          l[i].mouseClicked(event);
210
      }
211
  }
212
 
213
  /**
214
   * This method is called when the mouse is pressed over a component.
215
   *
216
   * @param event the <code>MouseEvent</code> for the press
217
   */
218
  public void mousePressed(MouseEvent event)
219
  {
220
    if (applet != null)
221
      {
222
        MouseListener[] l = applet.getMouseListeners();
223
        for (int i = 0; i < l.length; i++)
224
          l[i].mousePressed(event);
225
      }
226
  }
227
 
228
  /**
229
   * This method is called when the mouse is released over a component.
230
   *
231
   * @param event the <code>MouseEvent</code> for the release
232
   */
233
  public void mouseReleased(MouseEvent event)
234
  {
235
    if (applet != null)
236
      {
237
        MouseListener[] l = applet.getMouseListeners();
238
        for (int i = 0; i < l.length; i++)
239
          l[i].mouseReleased(event);
240
      }
241
  }
242
 
243
  /**
244
   * This method is called when the mouse enters a component.
245
   *
246
   * @param event the <code>MouseEvent</code> for the entry
247
   */
248
  public void mouseEntered(MouseEvent event)
249
  {
250
    if (applet != null)
251
      {
252
        MouseListener[] l = applet.getMouseListeners();
253
        for (int i = 0; i < l.length; i++)
254
          l[i].mouseEntered(event);
255
      }
256
  }
257
 
258
  /**
259
   * This method is called when the mouse exits a component.
260
   *
261
   * @param event the <code>MouseEvent</code> for the exit
262
   */
263
  public void mouseExited(MouseEvent event)
264
  {
265
    if (applet != null)
266
      {
267
        MouseListener[] l = applet.getMouseListeners();
268
        for (int i = 0; i < l.length; i++)
269
          l[i].mouseExited(event);
270
      }
271
  }
272
 
273
  ///////////////////////////////////
274
  /// MouseMotionListener Methods ///
275
  ///////////////////////////////////
276
 
277
  /**
278
   * This method is called when the mouse is moved over a component
279
   * while a button has been pressed.
280
   *
281
   * @param event the <code>MouseEvent</code> indicating the motion
282
   */
283
  public void mouseDragged(MouseEvent event)
284
  {
285
    if (applet != null)
286
      {
287
        MouseMotionListener[] l = applet.getMouseMotionListeners();
288
        for (int i = 0; i < l.length; i++)
289
          l[i].mouseDragged(event);
290
      }
291
  }
292
 
293
  /**
294
   * This method is called when the mouse is moved over a component
295
   * while no button is pressed.
296
   *
297
   * @param event the <code>MouseEvent</code> indicating the motion
298
   */
299
  public void mouseMoved(MouseEvent event)
300
  {
301
    if (applet != null)
302
      {
303
        MouseMotionListener[] l = applet.getMouseMotionListeners();
304
        for (int i = 0; i < l.length; i++)
305
          l[i].mouseMoved(event);
306
      }
307
  }
308
 
309
  ///////////////////////////////////
310
  /// InputMethodListener Methods ///
311
  ///////////////////////////////////
312
 
313
  /**
314
   * This method is called when the text is changed.
315
   *
316
   * @param event the <code>InputMethodEvent</code> indicating the text change
317
   */
318
  public void inputMethodTextChanged(InputMethodEvent event)
319
  {
320
    if (applet != null)
321
      {
322
        InputMethodListener[] l = applet.getInputMethodListeners();
323
        for (int i = 0; i < l.length; i++)
324
          l[i].inputMethodTextChanged(event);
325
      }
326
  }
327
 
328
  /**
329
   * This method is called when the cursor position within the text is changed.
330
   *
331
   * @param event the <code>InputMethodEvent</code> indicating the change
332
   */
333
  public void caretPositionChanged(InputMethodEvent event)
334
  {
335
    if (applet != null)
336
      {
337
        InputMethodListener[] l = applet.getInputMethodListeners();
338
        for (int i = 0; i < l.length; i++)
339
          l[i].caretPositionChanged(event);
340
      }
341
  }
342
 
343
  ///////////////////////////////////
344
  //// HierarchyListener Methods ////
345
  ///////////////////////////////////
346
 
347
  /**
348
   * Called when the hierarchy of this component changes. Use
349
   * <code>getChangeFlags()</code> on the event to see what exactly changed.
350
   *
351
   * @param event the event describing the change
352
   */
353
  public void hierarchyChanged(HierarchyEvent event)
354
  {
355
    if (applet != null)
356
      {
357
        HierarchyListener[] l = applet.getHierarchyListeners();
358
        for (int i = 0; i < l.length; i++)
359
          l[i].hierarchyChanged(event);
360
      }
361
  }
362
 
363
  /////////////////////////////////////////
364
  //// HierarchyBoundsListener Methods ////
365
  /////////////////////////////////////////
366
 
367
  /**
368
   * Called when an ancestor component of the source is moved.
369
   *
370
   * @param e the event describing the ancestor's motion
371
   */
372
  public void ancestorMoved(HierarchyEvent e)
373
  {
374
    if (applet != null)
375
      {
376
        HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
377
        for (int i = 0; i < l.length; i++)
378
          l[i].ancestorMoved(e);
379
      }
380
  }
381
 
382
  /**
383
   * Called when an ancestor component is resized.
384
   *
385
   * @param e the event describing the ancestor's resizing
386
   */
387
  public void ancestorResized(HierarchyEvent e)
388
  {
389
    if (applet != null)
390
      {
391
        HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
392
        for (int i = 0; i < l.length; i++)
393
          l[i].ancestorResized(e);
394
      }
395
  }
396
 
397
  void setParser(String tag, String documentbase) throws MalformedURLException, IOException
398
  {
399
    URL documentbaseURL = TagParser.getLocationToURL(documentbase);
400
    StringReader in = new StringReader(tag);
401
    this.parser = new TagParser(in, documentbaseURL);
402
  }
403
 
404
  // /////////////////////////////////
405
  // //// EmbeddedWindow Method //////
406
  // /////////////////////////////////
407
 
408
  /**
409
   * Set the native handle of the window system to embed the window in.
410
   *
411
   * @param handle the native handle.
412
   */
413
  public void setHandle(long handle)
414
  {
415
    super.setHandle(handle);
416
    addNotify();
417
 
418
    ArrayList l = parser.parseAppletTags();
419
    int s = l.size();
420
 
421
    for (int i = 0; i < s; i++)
422
      {
423
        tag = (AppletTag) l.get(i);
424
        applet = Main.createApplet(tag);
425
 
426
        if (contexts.get(tag.getCodeBase()) == null)
427
          contexts.put(tag.getCodeBase(), new PluginAppletContext());
428
 
429
        add(applet);
430
 
431
        AppletContext context = (AppletContext) contexts.get(tag.getCodeBase());
432
        ((PluginAppletContext) context).addApplet(applet);
433
 
434
        applet.setStub(new CommonAppletStub(tag, context, applet));
435
        Dimension size = getSize();
436
        if (size.width == 0 || size.height == 0)
437
          size = tag.getSize();
438
        applet.setSize(size);
439
 
440
        // Initialize the applet before showing this window so that
441
        // the applet doesn't receive events before it has been
442
        // initialized.
443
        applet.init();
444
        applet.start();
445
        setVisible(true);
446
      }
447
  }
448
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.