--- /dev/null
+/* -*-java-*-
+ *
+ * $Id: AnagGUI.java,v 1.1 2001/02/04 19:53:07 mdw Exp $
+ *
+ * Front-end GUI
+ *
+ * (c) 2001 Mark Wooding
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of Anag: a simple wordgame helper.
+ *
+ * Anag is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Anag is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Anag; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------*
+ *
+ * $Log: AnagGUI.java,v $
+ * Revision 1.1 2001/02/04 19:53:07 mdw
+ * Simple GUI front-end in Java.
+ *
+ */
+
+/*----- Imports -----------------------------------------------------------*/
+
+import java.lang.*;
+import java.util.*;
+import java.io.*;
+import java.awt.*;
+import java.applet.*;
+import java.awt.event.*;
+
+/*----- Main code ---------------------------------------------------------*/
+
+class Whinge extends Frame {
+ public Whinge(String gripe) {
+ super("Error!");
+ GridBagLayout gb = new GridBagLayout();
+ setLayout(gb);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) { dispose(); }
+ });
+
+ GridBagConstraints g = new GridBagConstraints();
+ g.gridx = g.gridy = GridBagConstraints.RELATIVE;
+ g.gridwidth = GridBagConstraints.REMAINDER; g.gridheight = 1;
+ g.weightx = g.weighty = 1;
+ g.insets = new Insets(24, 24, 8, 24);
+ Label l = new Label(gripe);
+ add(l); gb.setConstraints(l, g);
+
+ Button b = new Button("Bummer");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { dispose(); }
+ });
+ g.weighty = 0;
+ g.insets.top = 0; g.insets.bottom = 24;
+ add(b); gb.setConstraints(l, g);
+ pack();
+ show();
+ }
+}
+
+class AnagPanel extends Panel {
+ TextField word;
+ java.awt.List list;
+
+ void splat(String gripe) {
+ new Whinge(gripe);
+ }
+
+ void getlist(String tag) {
+ try {
+ Vector v = new Vector();
+ String[] vv;
+ v.addElement("anag");
+ v.addElement(tag);
+ v.addElement(word.getText());
+ vv = new String[v.size()];
+ v.copyInto(vv);
+ Process p = Runtime.getRuntime().exec(vv);
+ LineNumberReader fout =
+ new LineNumberReader(new InputStreamReader(p.getInputStream()));
+ LineNumberReader ferr =
+ new LineNumberReader(new InputStreamReader(p.getErrorStream()));
+
+ String l;
+ v = new Vector();
+ while ((l = fout.readLine()) != null)
+ v.addElement(l);
+ StringBuffer d = new StringBuffer();
+ while ((l = ferr.readLine()) != null)
+ d.append(l).append("\n");
+ l = d.toString();
+ if (l.length() > 0)
+ splat(l);
+ else {
+ list.removeAll();
+ int i;
+ vv = new String[v.size()];
+ v.copyInto(vv);
+ for (i = 0; i < vv.length; i++)
+ list.add(vv[i]);
+ }
+ } catch (IOException e) {
+ splat(e.toString());
+ }
+ }
+
+ public AnagPanel() {
+ super();
+ GridBagLayout gb = new GridBagLayout();
+ setLayout(gb);
+ Button b;
+
+ GridBagConstraints g = new GridBagConstraints();
+ g.gridx = g.gridy = GridBagConstraints.RELATIVE;
+ g.gridwidth = g.gridheight = 1;
+ g.weightx = 1; g.weighty = 0;
+
+ word = new TextField(40);
+ g.fill = GridBagConstraints.HORIZONTAL;
+ g.insets = new Insets(8, 8, 8, 8);
+ add(word); gb.setConstraints(word, g);
+
+ g.fill = GridBagConstraints.NONE;
+ g.weightx = g.weighty = 0;
+ g.insets.left = 0;
+ b = new Button("Anagram");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { getlist("-anagram"); }
+ });
+ add(b); gb.setConstraints(b, g);
+ b = new Button("Subgram");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { getlist("-subgram"); }
+ });
+ add(b); gb.setConstraints(b, g);
+ b = new Button("Wildcard");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { getlist("-wildcard"); }
+ });
+ add(b); gb.setConstraints(b, g);
+ b = new Button("Trackword");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { getlist("-trackword"); }
+ });
+ g.gridwidth = GridBagConstraints.REMAINDER;
+ add(b); gb.setConstraints(b, g);
+
+ list = new java.awt.List(20);
+ g.fill = GridBagConstraints.BOTH;
+ g.insets.left = 8; g.insets.top = 0;
+ g.gridwidth = 5;
+ g.weightx = g.weighty = 1;
+ add(list); gb.setConstraints(list, g);
+ }
+}
+
+/*----- Program or applet -------------------------------------------------*/
+
+public class AnagGUI extends Applet {
+ public static void main(String[] argv) {
+ Frame f = new Frame("Anagram solver");
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) { System.exit(0); }
+ });
+ AnagPanel p = new AnagPanel();
+ f.add(p);
+ f.pack();
+ f.show();
+ }
+ public AnagGUI() { super(); setLayout(new BorderLayout()); }
+ public void init() { add(new AnagPanel()); }
+ public void destroy() { removeAll(); }
+};
+
+/*----- That's all, folks -------------------------------------------------*/