/* Copyright 1996 Matthew Freedman and University of Washington mattf@cac.washington.edu This program may be freely used, modified, or redistributed for any non-commercial purpose as long as credit is given. This file contains the NinaShell and NinaFrame classes, used for wrapping the Nina class in an applet. */ import java.awt.*; import java.util.*; /* NinaShell is one possible applet wrapper for the Nina drawing object. It takes one parameters, "window_mode". If the value is "floating" the Nina will come up in its own floating frame. Otherwise it gets created inline, on the page. This class has only one method that should be called from outside: drawFig(NinaParams s, NinaController controller): draw a figure, pass in a NinaParams object and an object that implements the NinaController interface, meaning it has a do_update method for setting new drawing parameters when Nina is ready to draw. */ public class NinaShell extends java.applet.Applet { Nina nina; NinaController controller = null; NinaFrame frame = null; Panel btn_panel; Button close_btn = null; boolean floating; boolean initted = false; NinaParams queued_p = null; NinaController queued_controller; /* Called from outside to launch a new figure. Caller passes in handle to self. We pass it on to real drawing object */ public void drawFig(NinaParams p, NinaController controller) { if (!initted) { /* Can't draw yet */ queued_p = p; queued_controller = controller; return; } if ((nina == null) && (floating)) { frame = new NinaFrame("NINA: NINA Is Not An Acronym", this); frame.add("Center", nina = new Nina()); btn_panel = new Panel(); close_btn = new Button("Close"); close_btn.setFont(new Font("Helvetica", Font.BOLD, 14)); btn_panel.add(close_btn); frame.add("South", btn_panel); frame.resize(500, 500); frame.show(); } nina.drawFig(p, controller); } public void init() { String mode; mode = getParameter("window_mode"); if ((mode != null) && mode.equals("floating")) { floating = true; } else { floating = false; setLayout(new GridLayout(1, 1, 0, 0)); add(nina = new Nina()); } validate(); /* Does this really do anything? */ initted = true; if (queued_p != null) drawFig(queued_p, controller); } public boolean action(Event e, Object arg) { if (e.target == close_btn) { nina.die(); nina = null; frame.hide(); frame.dispose(); frame = null; return(true); } return(false); } } /* Create a subclass of Frame that is different in that it hands its action events back to its creator */ class NinaFrame extends Frame { java.applet.Applet app; public NinaFrame(String s, java.applet.Applet app) { super(s); this.app = app; } public boolean action(Event e, Object arg) { return(app.action(e, arg)); } }