+ class Settings extends Frame {
+ TextField name;
+
+ public Settings() {
+ super("AnagGUI settings");
+ Button b;
+ GridBagConstraints g = new GridBagConstraints();
+ this.setLayout(new GridBagLayout());
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) { dispose(); sb = null; }
+ });
+ g.gridx = g.gridy = GridBagConstraints.RELATIVE;
+ g.gridheight = 1;
+ g.weighty = 0;
+ g.fill = GridBagConstraints.NONE;
+ g.gridwidth = 1; g.weightx = 0;
+ g.insets = new Insets(8, 8, 8, 8);
+ this.add(new Label("Word list"), g);
+ g.fill = GridBagConstraints.HORIZONTAL;
+ g.gridwidth = GridBagConstraints.REMAINDER; g.weightx = 1;
+ g.insets.left = 0;
+ name = new TextField(20);
+ name.setText(file);
+ this.add(name, g);
+ g.insets.left = 8; g.insets.top = 0; g.gridwidth = 1;
+ g.weightx = 0; this.add(new Panel(), g);
+ g.weightx = 1; this.add(new Panel(), g);
+ g.weightx = 0;
+ g.insets.left = 0;
+ b = new Button("Cancel");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { dispose(); sb = null; }
+ });
+ this.add(b, g);
+ b = new Button("OK");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ file = name.getText(); dispose(); sb = null;
+ }
+ });
+ this.add(b, g);
+ this.pack();
+ this.show();
+ }
+ };
+
+ void splat(String gripe) { new Whinge(gripe); }
+ void settings() { if (sb != null) sb.toFront(); else sb = new Settings(); }
+
+ void listen(Process p) throws IOException {
+ BufferedReader fout =
+ new BufferedReader(new InputStreamReader(p.getInputStream()));
+ BufferedReader ferr =
+ new BufferedReader(new InputStreamReader(p.getErrorStream()));
+
+ String l;
+ Vector 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;
+ String[] vv = new String[v.size()];
+ v.copyInto(vv);
+ for (i = 0; i < vv.length; i++)
+ list.add(vv[i]);
+ }
+ }
+
+ void run() {
+ try {
+ StringBuffer b = new StringBuffer();
+ b.append("anag -file ")
+ .append(file)
+ .append(" ")
+ .append(word.getText());
+ Process p = Runtime.getRuntime().exec(b.toString());
+ listen(p);
+ } catch (IOException e) {
+ splat(e.toString());
+ }