chiark / gitweb /
Quick lick of paint before we really get started.
[anag] / AnagGUI.java
index ccae5914554e144062e32699459bd3ddcfb1eab0..dde7b2f99df93e454ab348820519b214290c9b77 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-java-*-
- *
- * $Id: AnagGUI.java,v 1.2 2001/02/07 09:10:04 mdw Exp $
  *
  * Front-end GUI
  *
  * (c) 2001 Mark Wooding
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Anag: a simple wordgame helper.
  *
  * 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.2  2001/02/07 09:10:04  mdw
- * Add a settings panel (currently only allows the wordlist to be
- * changed).  Move the buttons down the right-hand side of the list.  Add a
- * `Run' button which passes arguments through directly.
- *
- * Revision 1.1  2001/02/04 19:53:07  mdw
- * Simple GUI front-end in Java.
- *
- */
-
 /*----- Imports -----------------------------------------------------------*/
 
 import java.lang.*;
@@ -74,19 +59,21 @@ class Whinge extends Frame {
     g.insets.top = 0; g.insets.bottom = 24;
     add(b, g);
     pack();
-    show();    
+    setVisible(true);
   }
 };
 
 class AnagPanel extends Panel {
   TextField word;
   java.awt.List list;
-  String file;
   Settings sb;
+  String anag = System.getProperty("anag.program", "anag");
+  String file = System.getProperty("anag.dictionary",
+                                  "/usr/share/dict/words");
 
   class Settings extends Frame {
     TextField name;
-  
+
     public Settings() {
       super("AnagGUI settings");
       Button b;
@@ -126,7 +113,7 @@ class AnagPanel extends Panel {
       });
       this.add(b, g);
       this.pack();
-      this.show();
+      this.setVisible(true);
     }
   };
 
@@ -134,13 +121,13 @@ class AnagPanel extends Panel {
   void settings() { if (sb != null) sb.toFront(); else sb = new Settings(); }
 
   void listen(Process p) throws IOException {
-    LineNumberReader fout =
-      new LineNumberReader(new InputStreamReader(p.getInputStream()));
-    LineNumberReader ferr =
-      new LineNumberReader(new InputStreamReader(p.getErrorStream()));
+    BufferedReader fout =
+      new BufferedReader(new InputStreamReader(p.getInputStream()));
+    BufferedReader ferr =
+      new BufferedReader(new InputStreamReader(p.getErrorStream()));
 
     String l;
-    Vector v = new Vector();
+    Vector<String> v = new Vector<String>();
     while ((l = fout.readLine()) != null)
       v.addElement(l);
     StringBuffer d = new StringBuffer();
@@ -162,10 +149,9 @@ class AnagPanel extends Panel {
   void run() {
     try {
       StringBuffer b = new StringBuffer();
-      b.append("anag -file ")
-       .append(file)
-       .append(" ")
-       .append(word.getText());
+      b.append(anag)
+       .append(" -file ").append(file)
+       .append(" ").append(word.getText());
       Process p = Runtime.getRuntime().exec(b.toString());
       listen(p);
     } catch (IOException e) {
@@ -173,15 +159,24 @@ class AnagPanel extends Panel {
     }
   }
 
+  void help() {
+    try {
+      Process p = Runtime.getRuntime().exec(anag + " --help");
+      listen(p);
+    } catch (IOException e) {
+      splat(e.toString());
+    }
+  }
+
   void getlist(String tag) {
     try {
-      Vector v = new Vector();
+      Vector<String> v = new Vector<String>();
       String[] vv;
-      v.addElement("anag");
+      v.addElement(anag);
       v.addElement("-file");
       v.addElement(file);
       v.addElement(tag);
-      v.addElement(word.getText());
+      v.addElement(word.getText().toLowerCase());
       vv = new String[v.size()];
       v.copyInto(vv);
       Process p = Runtime.getRuntime().exec(vv);
@@ -197,7 +192,6 @@ class AnagPanel extends Panel {
     GridBagConstraints g = new GridBagConstraints();
     Button b;
 
-    file = "/usr/dict/words";
     sb = null;
 
     g.gridx = g.gridy = GridBagConstraints.RELATIVE;
@@ -243,6 +237,24 @@ class AnagPanel extends Panel {
     });
     add(b, g);
 
+    b = new Button("Regular expression");
+    b.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) { getlist("-regexp"); }
+    });
+    add(b, g);
+
+    b = new Button("Perl regexp");
+    b.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) { getlist("-pcre"); }
+    });
+    add(b, g);
+
+    b = new Button("Monoalphabetic");
+    b.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) { getlist("-mono"); }
+    });
+    add(b, g);
+
     b = new Button("Trackword");
     b.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) { getlist("-trackword"); }
@@ -255,6 +267,12 @@ class AnagPanel extends Panel {
     });
     add(b, g);
 
+    b = new Button("Help!");
+    b.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) { help(); }
+    });
+    add(b, g);
+
     b = new Button("Settings...");
     b.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) { settings(); }
@@ -269,16 +287,16 @@ 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); }
+      public void windowClosing(WindowEvent e) { System.exit(0); }
     });
     AnagPanel p = new AnagPanel();
     f.add(p);
     f.pack();
-    f.show();
+    f.setVisible(true);
   }
   public AnagGUI() { super(); setLayout(new BorderLayout()); }
-  public void init() { add(new AnagPanel()); }
-  public void destroy() { removeAll(); }
+  public void init() { /*add(new AnagPanel());*/ main(null); }
+  public void destroy() { /*removeAll();*/ }
 };
 
 /*----- That's all, folks -------------------------------------------------*/