/* -*-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.*;
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;
});
this.add(b, g);
this.pack();
- this.show();
+ this.setVisible(true);
}
};
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();
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) {
}
}
+ 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);
GridBagConstraints g = new GridBagConstraints();
Button b;
- file = "/usr/dict/words";
sb = null;
g.gridx = g.gridy = GridBagConstraints.RELATIVE;
});
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"); }
});
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(); }
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 -------------------------------------------------*/