annotate src/samer/applet/WindowApplet.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 /*
samer@0 2 * WindowApplet.java
samer@0 3 *
samer@0 4 * Copyright (c) 2000, Samer Abdallah, King's College London.
samer@0 5 * All rights reserved.
samer@0 6 *
samer@0 7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 8 * without even the implied warranty of MERCHANTABILITY or
samer@0 9 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 10 */
samer@0 11
samer@0 12 package samer.applet;
samer@0 13
samer@0 14 import java.awt.*;
samer@0 15 import java.awt.event.*;
samer@0 16 import java.util.Random;
samer@0 17 import java.net.*;
samer@0 18 import samer.core.*;
samer@0 19 import samer.core.util.*;
samer@0 20 import samer.core.util.heavy.*;
samer@0 21 import samer.tools.*;
samer@0 22
samer@0 23 //import samer.core.util.common.Tools;
samer@0 24
samer@0 25 public class WindowApplet extends JApplet implements Shell.Window, ActionListener
samer@0 26 {
samer@0 27 private WindowListener wl=null;
samer@0 28
samer@0 29 public void init()
samer@0 30 {
samer@0 31 super.init();
samer@0 32
samer@0 33 JAppletShell.registerWindow(this,name);
samer@0 34
samer@0 35 PopupMenu p=new PopupMenu( "Frame");
samer@0 36 p.addActionListener(this);
samer@0 37 p.add("recycle");
samer@0 38 add(p);
samer@0 39 // addContainerListener(this); check for empty? see AppShell
samer@0 40 addMouseListener(new PopupHandler(p,true));
samer@0 41 }
samer@0 42
samer@0 43 public void actionPerformed(ActionEvent e) {
samer@0 44 if (e.getActionCommand().equals("recycle")) {
samer@0 45 // simulate window closing behaviour by
samer@0 46 // calling listeners - this REQUESTS that
samer@0 47 // the window be released gracefully
samer@0 48 if (wl!=null) {
samer@0 49 Shell.trace("firing windowClosing event");
samer@0 50 wl.windowClosing(new WindowEvent(
samer@0 51 JAppletShell.dummyFrame(),
samer@0 52 WindowEvent.WINDOW_CLOSING));
samer@0 53 }
samer@0 54 }
samer@0 55 }
samer@0 56
samer@0 57 public void start()
samer@0 58 {
samer@0 59 super.start();
samer@0 60
samer@0 61 if (name!=null) {
samer@0 62 if (name.equals("exposed")) JAppletShell.expose();
samer@0 63 }
samer@0 64
samer@0 65 // if we need to have access to private properties:
samer@0 66 // Manager props = new Manager(this);
samer@0 67 }
samer@0 68
samer@0 69 private boolean destroying=false;
samer@0 70
samer@0 71 public void destroy()
samer@0 72 {
samer@0 73 destroying=true;
samer@0 74
samer@0 75 if (wl!=null) {
samer@0 76 Shell.trace("firing windowClosing event");
samer@0 77
samer@0 78 // this may precipitate component removals or a window dispose
samer@0 79 // we should ignore any dispose requests we get - that's
samer@0 80 // why we set destroying=true;
samer@0 81 wl.windowClosing(new WindowEvent(
samer@0 82 JAppletShell.dummyFrame(),
samer@0 83 WindowEvent.WINDOW_CLOSING));
samer@0 84 }
samer@0 85
samer@0 86 wl=null; // forget about window listeners
samer@0 87
samer@0 88 // window is no longer available for use
samer@0 89 JAppletShell.deregisterWindow(this,name);
samer@0 90
samer@0 91 // after this, if components are removed, this may
samer@0 92 // precipitate a call to dispose if any container
samer@0 93 // listeners are registered - we leave destroying=true
samer@0 94 // so that nothing happens.
samer@0 95 super.destroy();
samer@0 96 }
samer@0 97
samer@0 98 public Container container() { return this; }
samer@0 99 public synchronized void addWindowListener(WindowListener l) {
samer@0 100 Shell.trace("adding window listener");
samer@0 101 wl = AWTEventMulticaster.add(wl,l);
samer@0 102 }
samer@0 103
samer@0 104 public void expose() { validate(); }
samer@0 105 public void dispose() {
samer@0 106 if (!destroying) {
samer@0 107 removeAll();
samer@0 108 wl=null; // forget about listeners
samer@0 109
samer@0 110 // window is now available for reuse
samer@0 111 JAppletShell.registerWindow(this,name);
samer@0 112 }
samer@0 113 }
samer@0 114 }