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/] [StandaloneAppletWindow.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* StandaloneAppletWindow.java -- an applet frame
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 java.applet.Applet;
41
import java.applet.AppletContext;
42
import java.awt.BorderLayout;
43
import java.awt.Dimension;
44
import java.awt.Frame;
45
import java.awt.Insets;
46
import java.awt.Label;
47
import java.awt.Menu;
48
import java.awt.MenuBar;
49
import java.awt.MenuItem;
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52
import java.awt.event.ComponentEvent;
53
import java.awt.event.ComponentListener;
54
import java.awt.event.ContainerEvent;
55
import java.awt.event.ContainerListener;
56
import java.awt.event.HierarchyBoundsListener;
57
import java.awt.event.HierarchyEvent;
58
import java.awt.event.HierarchyListener;
59
import java.awt.event.InputMethodEvent;
60
import java.awt.event.InputMethodListener;
61
import java.awt.event.MouseEvent;
62
import java.awt.event.MouseListener;
63
import java.awt.event.MouseMotionListener;
64
import java.awt.event.WindowAdapter;
65
import java.awt.event.WindowEvent;
66
import java.util.HashMap;
67
import java.util.List;
68
 
69
class StandaloneAppletWindow
70
    extends Frame
71
    implements ActionListener, ContainerListener, ComponentListener,
72
    MouseListener, MouseMotionListener, InputMethodListener, HierarchyListener,
73
    HierarchyBoundsListener
74
{
75
 
76
  // This class implements various listeners because the author of an applet
77
  // may attach listeners to it, unaware of the applet's parent (this class).
78
  // So, we must pass all listener events on this plugin applet window to the
79
  // actual applet.
80
 
81
  private static int testWindowCount;
82
  private static HashMap contexts = new HashMap();
83
  private Applet applet;
84
  private Label status = new Label();
85
 
86
  private MenuItem restartItem;
87
  private MenuItem reloadItem;
88
  private MenuItem cancelItem;
89
  private MenuItem saveItem;
90
  private MenuItem startItem;
91
  private MenuItem cloneItem;
92
  private MenuItem tagItem;
93
  private MenuItem infoItem;
94
  private MenuItem editItem;
95
  private MenuItem encodingItem;
96
  private MenuItem printItem;
97
  private MenuItem propertiesItem;
98
  private MenuItem closeItem;
99
  private MenuItem quitItem;
100
 
101
  StandaloneAppletWindow(AppletTag tag, List appletWindows)
102
  {
103
    appletWindows.add(this);
104
    applet = Main.createApplet(tag);
105
 
106
    if (contexts.get(tag.codebase) == null)
107
      contexts.put(tag.codebase, new StandaloneAppletContext(appletWindows));
108
 
109
    setLayout(new BorderLayout());
110
    add(applet, BorderLayout.CENTER);
111
    add(status, BorderLayout.SOUTH);
112
 
113
    addWindowListener(new WindowAdapter()
114
        {
115
          public void windowClosing(WindowEvent event)
116
          {
117
            applet.stop();
118
            StandaloneAppletWindow.this.hide();
119
            System.exit(0);
120
          }
121
        });
122
 
123
    addContainerListener(this);
124
    addComponentListener(this);
125
    addMouseListener(this);
126
    addMouseMotionListener(this);
127
    addInputMethodListener(this);
128
    addHierarchyListener(this);
129
    addHierarchyBoundsListener(this);
130
 
131
    restartItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuRestart"));
132
    restartItem.setEnabled(false);
133
    restartItem.addActionListener(this);
134
    reloadItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuReload"));
135
    reloadItem.setEnabled(false);
136
    reloadItem.addActionListener(this);
137
    cancelItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuCancel"));
138
    cancelItem.setEnabled(false);
139
    cancelItem.addActionListener(this);
140
    saveItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuSave"));
141
    saveItem.setEnabled(false);
142
    saveItem.addActionListener(this);
143
    startItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuStart"));
144
    startItem.setEnabled(false);
145
    startItem.addActionListener(this);
146
    cloneItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuClone"));
147
    cloneItem.setEnabled(false);
148
    cloneItem.addActionListener(this);
149
    closeItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuClose"));
150
    closeItem.setEnabled(false);
151
    closeItem.addActionListener(this);
152
    tagItem =
153
      new MenuItem(Messages.getString("StandaloneAppletWindow.MenuTag"));
154
    tagItem.setEnabled(false);
155
    tagItem.addActionListener(this);
156
    infoItem =
157
      new MenuItem(Messages.getString("StandaloneAppletWindow.MenuInfo"));
158
    infoItem.setEnabled(false);
159
    infoItem.addActionListener(this);
160
    editItem =
161
      new MenuItem(Messages.getString("StandaloneAppletWindow.MenuEdit"));
162
    editItem.setEnabled(false);
163
    editItem.addActionListener(this);
164
    editItem.setEnabled(false);
165
    encodingItem =
166
      new MenuItem(Messages.getString("StandaloneAppletWindow.MenuEncoding"));
167
    encodingItem.setEnabled(false);
168
    encodingItem.addActionListener(this);
169
    printItem =
170
      new MenuItem(Messages.getString("StandaloneAppletWindow.MenuPrint"));
171
    printItem.setEnabled(false);
172
    printItem.addActionListener(this);
173
    propertiesItem =
174
      new MenuItem(Messages.getString("StandaloneAppletWindow.MenuProperties"));
175
    propertiesItem.setEnabled(false);
176
    propertiesItem.addActionListener(this);
177
    quitItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuQuit"));
178
    quitItem.addActionListener(this);
179
 
180
    MenuBar menuBar = new MenuBar();
181
    Menu menuApplet = new Menu(Messages.getString("StandaloneAppletWindow.MenuTitle"));
182
    menuBar.add(menuApplet);
183
    menuApplet.add(restartItem);
184
    menuApplet.add(reloadItem);
185
    menuApplet.add(cancelItem);
186
    menuApplet.add(saveItem);
187
    menuApplet.add(startItem);
188
    menuApplet.add(cloneItem);
189
    menuApplet.addSeparator();
190
    menuApplet.add(tagItem);
191
    menuApplet.add(infoItem);
192
    menuApplet.add(editItem);
193
    menuApplet.add(encodingItem);
194
    menuApplet.addSeparator();
195
    menuApplet.add(printItem);
196
    menuApplet.addSeparator();
197
    menuApplet.add(propertiesItem);
198
    menuApplet.addSeparator();
199
    menuApplet.add(closeItem);
200
    menuApplet.add(quitItem);
201
    setMenuBar(menuBar);
202
    setTitle(Messages.getString("StandaloneAppletWindow.WindowTitle")
203
             + " " + tag.code);
204
 
205
    AppletContext context = (AppletContext) contexts.get(tag.codebase);
206
    ((StandaloneAppletContext) context).addApplet(applet);
207
 
208
    applet.setStub(new CommonAppletStub(tag, context, applet));
209
 
210
    // Create the frame's peer. Otherwise getPreferredSize will read
211
    // its insets as 0.
212
    addNotify();
213
    Insets i = getInsets();
214
    Dimension size = tag.getSize();
215
    setSize(i.left + size.width + i.right,
216
            i.top + size.height + status.getPreferredSize().height
217
            + i.bottom);
218
    applet.setSize(size);
219
 
220
    // Initialize the applet before showing this window so that the
221
    // applet doesn't receive events before it has been initialized.
222
    applet.init();
223
    applet.start();
224
    setVisible(true);
225
  }
226
 
227
  private void closeWindow()
228
  {
229
    applet.stop();
230
    StandaloneAppletViewer.appletWindows.remove(this);
231
    StandaloneAppletWindow.this.hide();
232
  }
233
 
234
  public void actionPerformed(ActionEvent e)
235
  {
236
    if (e.getSource() == quitItem)
237
      {
238
        closeWindow();
239
        System.exit(0);
240
      }
241
    else if (e.getSource() == closeItem)
242
      {
243
        // Close current window.
244
        closeWindow();
245
 
246
        // Exit if there are other windows left.
247
        if (StandaloneAppletViewer.appletWindows.isEmpty())
248
          System.exit(0);
249
      }
250
  }
251
 
252
  void showStatus(String status)
253
  {
254
    this.status.setText(status);
255
  }
256
 
257
 
258
  ///////////////////////////////////
259
  /// ContainerListener Methods /////
260
  ///////////////////////////////////
261
 
262
  /**
263
   * This method is called when a component is added to the container.
264
   *
265
   * @param event the <code>ContainerEvent</code> indicating component
266
   *          addition
267
   */
268
  public void componentAdded(ContainerEvent event)
269
  {
270
    if (applet != null)
271
      {
272
        ContainerListener[] l = applet.getContainerListeners();
273
        for (int i = 0; i < l.length; i++)
274
          l[i].componentAdded(event);
275
      }
276
  }
277
 
278
  /**
279
   * This method is called when a component is removed from the container.
280
   *
281
   * @param event the <code>ContainerEvent</code> indicating component removal
282
   */
283
  public void componentRemoved(ContainerEvent event)
284
  {
285
    if (applet != null)
286
      {
287
        ContainerListener[] l = applet.getContainerListeners();
288
        for (int i = 0; i < l.length; i++)
289
          l[i].componentRemoved(event);
290
      }
291
  }
292
 
293
  ///////////////////////////////////
294
  /// ComponentListener Methods /////
295
  ///////////////////////////////////
296
 
297
  /**
298
   * This method is called when the component is resized.
299
   *
300
   * @param event the <code>ComponentEvent</code> indicating the resize
301
   */
302
  public void componentResized(ComponentEvent event)
303
  {
304
    if (applet != null)
305
      {
306
        ComponentListener[] l = applet.getComponentListeners();
307
        for (int i = 0; i < l.length; i++)
308
          l[i].componentResized(event);
309
      }
310
  }
311
 
312
  /**
313
   * This method is called when the component is moved.
314
   *
315
   * @param event the <code>ComponentEvent</code> indicating the move
316
   */
317
  public void componentMoved(ComponentEvent event)
318
  {
319
    if (applet != null)
320
      {
321
        ComponentListener[] l = applet.getComponentListeners();
322
        for (int i = 0; i < l.length; i++)
323
          l[i].componentMoved(event);
324
      }
325
  }
326
 
327
  /**
328
   * This method is called when the component is made visible.
329
   *
330
   * @param event the <code>ComponentEvent</code> indicating the visibility
331
   */
332
  public void componentShown(ComponentEvent event)
333
  {
334
    if (applet != null)
335
      {
336
        ComponentListener[] l = applet.getComponentListeners();
337
        for (int i = 0; i < l.length; i++)
338
          l[i].componentShown(event);
339
      }
340
  }
341
 
342
  /**
343
   * This method is called when the component is hidden.
344
   *
345
   * @param event the <code>ComponentEvent</code> indicating the visibility
346
   */
347
  public void componentHidden(ComponentEvent event)
348
  {
349
    if (applet != null)
350
      {
351
        ComponentListener[] l = applet.getComponentListeners();
352
        for (int i = 0; i < l.length; i++)
353
          l[i].componentHidden(event);
354
      }
355
  }
356
 
357
  ///////////////////////////////////
358
  ////// MouseListener Methods //////
359
  ///////////////////////////////////
360
 
361
  /**
362
   * This method is called when the mouse is clicked (pressed and released
363
   * in short succession) on a component.
364
   *
365
   * @param event the <code>MouseEvent</code> indicating the click
366
   */
367
  public void mouseClicked(MouseEvent event)
368
  {
369
    if (applet != null)
370
      {
371
        MouseListener[] l = applet.getMouseListeners();
372
        for (int i = 0; i < l.length; i++)
373
          l[i].mouseClicked(event);
374
      }
375
  }
376
 
377
  /**
378
   * This method is called when the mouse is pressed over a component.
379
   *
380
   * @param event the <code>MouseEvent</code> for the press
381
   */
382
  public void mousePressed(MouseEvent event)
383
  {
384
    if (applet != null)
385
      {
386
        MouseListener[] l = applet.getMouseListeners();
387
        for (int i = 0; i < l.length; i++)
388
          l[i].mousePressed(event);
389
      }
390
  }
391
 
392
  /**
393
   * This method is called when the mouse is released over a component.
394
   *
395
   * @param event the <code>MouseEvent</code> for the release
396
   */
397
  public void mouseReleased(MouseEvent event)
398
  {
399
    if (applet != null)
400
      {
401
        MouseListener[] l = applet.getMouseListeners();
402
        for (int i = 0; i < l.length; i++)
403
          l[i].mouseReleased(event);
404
      }
405
  }
406
 
407
  /**
408
   * This method is called when the mouse enters a component.
409
   *
410
   * @param event the <code>MouseEvent</code> for the entry
411
   */
412
  public void mouseEntered(MouseEvent event)
413
  {
414
    if (applet != null)
415
      {
416
        MouseListener[] l = applet.getMouseListeners();
417
        for (int i = 0; i < l.length; i++)
418
          l[i].mouseEntered(event);
419
      }
420
  }
421
 
422
  /**
423
   * This method is called when the mouse exits a component.
424
   *
425
   * @param event the <code>MouseEvent</code> for the exit
426
   */
427
  public void mouseExited(MouseEvent event)
428
  {
429
    if (applet != null)
430
      {
431
        MouseListener[] l = applet.getMouseListeners();
432
        for (int i = 0; i < l.length; i++)
433
          l[i].mouseExited(event);
434
      }
435
  }
436
 
437
  ///////////////////////////////////
438
  /// MouseMotionListener Methods ///
439
  ///////////////////////////////////
440
 
441
  /**
442
   * This method is called when the mouse is moved over a component
443
   * while a button has been pressed.
444
   *
445
   * @param event the <code>MouseEvent</code> indicating the motion
446
   */
447
  public void mouseDragged(MouseEvent event)
448
  {
449
    if (applet != null)
450
      {
451
        MouseMotionListener[] l = applet.getMouseMotionListeners();
452
        for (int i = 0; i < l.length; i++)
453
          l[i].mouseDragged(event);
454
      }
455
  }
456
 
457
  /**
458
   * This method is called when the mouse is moved over a component
459
   * while no button is pressed.
460
   *
461
   * @param event the <code>MouseEvent</code> indicating the motion
462
   */
463
  public void mouseMoved(MouseEvent event)
464
  {
465
    if (applet != null)
466
      {
467
        MouseMotionListener[] l = applet.getMouseMotionListeners();
468
        for (int i = 0; i < l.length; i++)
469
          l[i].mouseMoved(event);
470
      }
471
  }
472
 
473
  ///////////////////////////////////
474
  /// InputMethodListener Methods ///
475
  ///////////////////////////////////
476
 
477
  /**
478
   * This method is called when the text is changed.
479
   *
480
   * @param event the <code>InputMethodEvent</code> indicating the text change
481
   */
482
  public void inputMethodTextChanged(InputMethodEvent event)
483
  {
484
    if (applet != null)
485
      {
486
        InputMethodListener[] l = applet.getInputMethodListeners();
487
        for (int i = 0; i < l.length; i++)
488
          l[i].inputMethodTextChanged(event);
489
      }
490
  }
491
 
492
  /**
493
   * This method is called when the cursor position within the text is changed.
494
   *
495
   * @param event the <code>InputMethodEvent</code> indicating the change
496
   */
497
  public void caretPositionChanged(InputMethodEvent event)
498
  {
499
    if (applet != null)
500
      {
501
        InputMethodListener[] l = applet.getInputMethodListeners();
502
        for (int i = 0; i < l.length; i++)
503
          l[i].caretPositionChanged(event);
504
      }
505
  }
506
 
507
  ///////////////////////////////////
508
  //// HierarchyListener Methods ////
509
  ///////////////////////////////////
510
 
511
  /**
512
   * Called when the hierarchy of this component changes. Use
513
   * <code>getChangeFlags()</code> on the event to see what exactly changed.
514
   *
515
   * @param event the event describing the change
516
   */
517
  public void hierarchyChanged(HierarchyEvent event)
518
  {
519
    if (applet != null)
520
      {
521
        HierarchyListener[] l = applet.getHierarchyListeners();
522
        for (int i = 0; i < l.length; i++)
523
          l[i].hierarchyChanged(event);
524
      }
525
  }
526
 
527
  /////////////////////////////////////////
528
  //// HierarchyBoundsListener Methods ////
529
  /////////////////////////////////////////
530
 
531
  /**
532
   * Called when an ancestor component of the source is moved.
533
   *
534
   * @param e the event describing the ancestor's motion
535
   */
536
  public void ancestorMoved(HierarchyEvent e)
537
  {
538
    if (applet != null)
539
      {
540
        HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
541
        for (int i = 0; i < l.length; i++)
542
          l[i].ancestorMoved(e);
543
      }
544
  }
545
 
546
  /**
547
   * Called when an ancestor component is resized.
548
   *
549
   * @param e the event describing the ancestor's resizing
550
   */
551
  public void ancestorResized(HierarchyEvent e)
552
  {
553
    if (applet != null)
554
      {
555
        HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
556
        for (int i = 0; i < l.length; i++)
557
          l[i].ancestorResized(e);
558
      }
559
  }
560
}

powered by: WebSVN 2.1.0

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