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