X-Git-Url: https://git.distorted.org.uk/~mdw/anag/blobdiff_plain/a10122de085ddf5c8bec6fc12c7164ad1dc1459c..HEAD:/AnagGUI.java diff --git a/AnagGUI.java b/AnagGUI.java index bf51835..dde7b2f 100644 --- a/AnagGUI.java +++ b/AnagGUI.java @@ -1,13 +1,11 @@ /* -*-java-*- * - * $Id: AnagGUI.java,v 1.5 2002/08/11 12:58:09 mdw Exp $ - * * Front-end GUI * * (c) 2001 Mark Wooding */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Anag: a simple wordgame helper. * @@ -15,40 +13,17 @@ * 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.5 2002/08/11 12:58:09 mdw - * Added support for regular expression matching, if supported by the C - * library. - * - * Revision 1.4 2001/02/19 19:19:11 mdw - * Add `help' button. Lowercase input to the command. - * - * Revision 1.3 2001/02/16 21:46:10 mdw - * Use a BufferedReader, not a LineNumberReader. - * - * 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.*; @@ -84,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; @@ -136,7 +113,7 @@ class AnagPanel extends Panel { }); this.add(b, g); this.pack(); - this.show(); + this.setVisible(true); } }; @@ -150,7 +127,7 @@ class AnagPanel extends Panel { new BufferedReader(new InputStreamReader(p.getErrorStream())); String l; - Vector v = new Vector(); + Vector v = new Vector(); while ((l = fout.readLine()) != null) v.addElement(l); StringBuffer d = new StringBuffer(); @@ -172,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) { @@ -185,7 +161,7 @@ class AnagPanel extends Panel { void help() { try { - Process p = Runtime.getRuntime().exec("anag --help"); + Process p = Runtime.getRuntime().exec(anag + " --help"); listen(p); } catch (IOException e) { splat(e.toString()); @@ -194,9 +170,9 @@ class AnagPanel extends Panel { void getlist(String tag) { try { - Vector v = new Vector(); + Vector v = new Vector(); String[] vv; - v.addElement("anag"); + v.addElement(anag); v.addElement("-file"); v.addElement(file); v.addElement(tag); @@ -216,7 +192,6 @@ class AnagPanel extends Panel { GridBagConstraints g = new GridBagConstraints(); Button b; - file = System.getProperty("anag.dictionary", "/usr/dict/words"); sb = null; g.gridx = g.gridy = GridBagConstraints.RELATIVE; @@ -262,12 +237,24 @@ class AnagPanel extends Panel { }); add(b, g); - b = new Button("Regexp"); + 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"); } @@ -300,12 +287,12 @@ 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());*/ main(null); }