samer@0: /* samer@0: * WindowApplet.java samer@0: * samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.applet; samer@0: samer@0: import java.awt.*; samer@0: import java.awt.event.*; samer@0: import java.util.Random; samer@0: import java.net.*; samer@0: import samer.core.*; samer@0: import samer.core.util.*; samer@0: import samer.core.util.heavy.*; samer@0: import samer.tools.*; samer@0: samer@0: //import samer.core.util.common.Tools; samer@0: samer@0: public class WindowApplet extends JApplet implements Shell.Window, ActionListener samer@0: { samer@0: private WindowListener wl=null; samer@0: samer@0: public void init() samer@0: { samer@0: super.init(); samer@0: samer@0: JAppletShell.registerWindow(this,name); samer@0: samer@0: PopupMenu p=new PopupMenu( "Frame"); samer@0: p.addActionListener(this); samer@0: p.add("recycle"); samer@0: add(p); samer@0: // addContainerListener(this); check for empty? see AppShell samer@0: addMouseListener(new PopupHandler(p,true)); samer@0: } samer@0: samer@0: public void actionPerformed(ActionEvent e) { samer@0: if (e.getActionCommand().equals("recycle")) { samer@0: // simulate window closing behaviour by samer@0: // calling listeners - this REQUESTS that samer@0: // the window be released gracefully samer@0: if (wl!=null) { samer@0: Shell.trace("firing windowClosing event"); samer@0: wl.windowClosing(new WindowEvent( samer@0: JAppletShell.dummyFrame(), samer@0: WindowEvent.WINDOW_CLOSING)); samer@0: } samer@0: } samer@0: } samer@0: samer@0: public void start() samer@0: { samer@0: super.start(); samer@0: samer@0: if (name!=null) { samer@0: if (name.equals("exposed")) JAppletShell.expose(); samer@0: } samer@0: samer@0: // if we need to have access to private properties: samer@0: // Manager props = new Manager(this); samer@0: } samer@0: samer@0: private boolean destroying=false; samer@0: samer@0: public void destroy() samer@0: { samer@0: destroying=true; samer@0: samer@0: if (wl!=null) { samer@0: Shell.trace("firing windowClosing event"); samer@0: samer@0: // this may precipitate component removals or a window dispose samer@0: // we should ignore any dispose requests we get - that's samer@0: // why we set destroying=true; samer@0: wl.windowClosing(new WindowEvent( samer@0: JAppletShell.dummyFrame(), samer@0: WindowEvent.WINDOW_CLOSING)); samer@0: } samer@0: samer@0: wl=null; // forget about window listeners samer@0: samer@0: // window is no longer available for use samer@0: JAppletShell.deregisterWindow(this,name); samer@0: samer@0: // after this, if components are removed, this may samer@0: // precipitate a call to dispose if any container samer@0: // listeners are registered - we leave destroying=true samer@0: // so that nothing happens. samer@0: super.destroy(); samer@0: } samer@0: samer@0: public Container container() { return this; } samer@0: public synchronized void addWindowListener(WindowListener l) { samer@0: Shell.trace("adding window listener"); samer@0: wl = AWTEventMulticaster.add(wl,l); samer@0: } samer@0: samer@0: public void expose() { validate(); } samer@0: public void dispose() { samer@0: if (!destroying) { samer@0: removeAll(); samer@0: wl=null; // forget about listeners samer@0: samer@0: // window is now available for reuse samer@0: JAppletShell.registerWindow(this,name); samer@0: } samer@0: } samer@0: }