/* Copyright (C) 2002 J. M. Spivey */ import java.awt.*; import java.awt.event.*; class Loader extends Dialog { private Turmites parent; private Panel choices = new Panel(); private Panel buttons = new Panel(); private final String[][] menu = { { "Flash", "rL1bL1bL1bL1" }, { "Turk", "rL1bR1bL1bL1" }, { "Spiral", "gL1bL1bA2bL1gR1bL1gR1bL1" }, { "Greek Spiral", "rL1bR2bL1bL1rR1bL2bL1bL1" }, { "George", "rR2gL2yL2rL2yR2bR1bR1bR1" }, { "Mystery", "rR1yR1bL1gL1" }, { "Mystery 2", "yR1bR1rL1gL1" }, { "Binary counter", "bL2bA1gA1bL1bL3bL1bL1bL1rL4bA3bL1bL1gL1bL1gL1bL1" }, { "Last saved", "" } }; private int choice = 0; private String saved = ""; public void setSaved(String s) { saved = s; } public Loader(Turmites parent) { super(parent, "Choose a turmite"); setModal(true); this.parent = parent; choices.setLayout(new GridLayout(menu.length, 1)); CheckboxGroup grp = new CheckboxGroup(); for (int i = 0; i < menu.length; i++) { final int ii = i; Checkbox cb = new Checkbox(menu[i][0], grp, i == 0); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { choice = ii; } }); choices.add(cb); } addButton("Load", new ActionListener() { public void actionPerformed(ActionEvent e) { String desc = menu[choice][1]; if (desc.equals("")) desc = saved; Loader.this.parent.load(desc); Loader.this.setVisible(false); } }); addButton("Cancel", new ActionListener() { public void actionPerformed(ActionEvent e) { Loader.this.setVisible(false); } }); add(choices, "Center"); add(buttons, "South"); pack(); } public void addButton(String label, ActionListener action) { Button b = new Button(label); if (action != null) b.addActionListener(action); buttons.add(b); } public String defaultDesc() { return menu[0][1]; } }