/* 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 ControllerController class. */ import java.awt.*; import java.util.*; /* This class is the overall controlling applet for the NINA user interface. It coordinates the communications between the applets containing the controllers for lines, colors, and delay with the applet containing the Nina figure draw-er. It has three visible buttons -- Draw, Lock, and Reset. It implements the NinaController interface so that it can provide a do_update method to Nina. It coordinates the communications between the Nina applet and the individual Controller applets. */ public class ControllerController extends java.applet.Applet implements NinaController { NinaParams params; NinaShell nina; LineControllers lines; DelayControllers delays; ColorControllers colors; Button draw, lock, reset; public void init() { java.applet.Applet a; Enumeration e; setLayout(new GridLayout(1, 3, 0, 0)); setFont(new Font("Helvetica", Font.BOLD, 18)); add(draw = new Button("Draw")); add(lock = new Button("Lock")); add(reset = new Button("Reset")); /* Get handles for the other applets */ /* getAppletContext().getApplet(name) seems thoroughly broken on Netscape, so let's do this in the most absurd way possible */ while (true) { int app_cnt; app_cnt = 0; for (e = getAppletContext().getApplets(); e.hasMoreElements(); ) { a = (java.applet.Applet)(e.nextElement()); if (a != null) // Sometimes we get null applets. Very annoying app_cnt++; } if (app_cnt == 5) break; try { Thread.sleep(500); } catch (InterruptedException err) { } } e = getAppletContext().getApplets(); for (int i = 0; i < 5; i++) { a = (java.applet.Applet)(e.nextElement()); if (a instanceof LineControllers) lines = (LineControllers) a; else if (a instanceof DelayControllers) delays = (DelayControllers) a; else if (a instanceof ColorControllers) colors = (ColorControllers) a; else if (a instanceof NinaShell) nina = (NinaShell) a; } /* Get params for a first figure */ params = new NinaParams(); params.setup(); /* Set up the interface to match the parameters we just got */ lines.setParams(params); delays.setParams(params); colors.setParams(params); } /* Handle a button press */ public boolean action(Event evt, Object obj) { if (evt.target == draw) { /* Collect values from controllers */ lines.getParams(params); delays.getParams(params); colors.getParams(params); /* Regen anything that is random */ params.setup(); /* Draw the figure */ nina.drawFig(params, this); /* Send any new randomized params back to controllers */ lines.setParams(params); delays.setParams(params); colors.setParams(params); } else if (evt.target == lock) { /* Lock in the current parameters, i.e. turn off all random flags. First get the current values */ lines.getParams(params); delays.getParams(params); colors.getParams(params); params.ran_lines = false; params.ran_lines = false; params.ran_a_pulse = false; params.ran_b_pulse = false; params.auto_draw = false; params.ran_colors = false; params.ran_palette = false; lines.setParams(params); delays.setParams(params); colors.setParams(params); } else if (evt.target == reset) { /* Put everything back to defaults */ params = new NinaParams(); params.setup(); nina.drawFig(params, this); lines.setParams(params); delays.setParams(params); colors.setParams(params); } return(true); } /* If Nina does its own redraw due to mouse-click or auto-draw timer, it notifies us here, and we update parameter structures. */ public void do_update() { lines.getParams(params); delays.getParams(params); colors.getParams(params); /* Regen anything that is random */ params.setup(); /* Send any new randomized params back to controllers */ lines.setParams(params); delays.setParams(params); colors.setParams(params); } public Insets insets() { return new Insets(15, 5, 15, 5); } }