]> code.citadel.org Git - citadel.git/commitdiff
changed the way pop-up prompt frames work so it's easier to program
authorChilly <chilly@uncensored.citadel.org>
Thu, 29 Jul 1999 20:06:35 +0000 (20:06 +0000)
committerChilly <chilly@uncensored.citadel.org>
Thu, 29 Jul 1999 20:06:35 +0000 (20:06 +0000)
shaggy/gotoPrompt.java [new file with mode: 0644]
shaggy/passwordWindow.java [deleted file]
shaggy/promptCmd.java [new file with mode: 0644]
shaggy/promptWindow.java [new file with mode: 0644]
shaggy/roomPassPrompt.java [new file with mode: 0644]
shaggy/zapPrompt.java [new file with mode: 0644]

diff --git a/shaggy/gotoPrompt.java b/shaggy/gotoPrompt.java
new file mode 100644 (file)
index 0000000..083a2ff
--- /dev/null
@@ -0,0 +1,20 @@
+/* gotoPrompt.java
+ * prmoptWindow stuff for .goto
+ */
+
+public class gotoPrompt extends promptCmd {
+  public String        def;
+
+  public gotoPrompt( String def ) {
+  }
+
+  public void one_field( String name ) {
+    citadel.me.enterRoom( name );
+  }
+
+  public int getType() { return promptWindow.ONE_FIELD; }
+  public String getPrompt() { return "Room name"; }
+  public String getTitle() { return "Goto a room"; }
+
+  public String firstPrompt() { return "Room:"; }
+}
diff --git a/shaggy/passwordWindow.java b/shaggy/passwordWindow.java
deleted file mode 100644 (file)
index 01b677b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* passwordWindow.java
- * Prompt user for room password
- */
-
-import java.awt.*;
-
-public class passwordWindow extends Frame {
-  String       room;
-  TextField    text;
-
-  public passwordWindow( String room ) {
-    super( "Password for: " + room );
-
-    this.room = room;
-
-    setLayout( new BorderLayout() );
-    add( "North", new Label( "Please enter password for " + room ) );
-
-    PairPanel  pp = new PairPanel();
-    pp.addLeft( new Label ( "Password: " ) );
-    pp.addRight( text = new TextField() );
-    text.setEchoCharacter( '.' );
-
-    add( "South", new Button( "Goto!" ) );
-
-    resize( 250, 150 );
-    show();
-  }
-
-  public boolean handleEvent( Event e ) {
-    if( e.id == Event.WINDOW_DESTROY ) {
-      dispose();
-    }
-    return super.handleEvent( e );
-  }
-
-  public boolean action( Event e, Object o ) {
-    if( (e.target == text) || (e.target instanceof Button) ) {
-      String   s = text.getText();
-      dispose();
-      citadel.me.enterRoom( room, s );
-    }
-    return super.action( e, o );
-  }
-}
diff --git a/shaggy/promptCmd.java b/shaggy/promptCmd.java
new file mode 100644 (file)
index 0000000..6b78226
--- /dev/null
@@ -0,0 +1,31 @@
+/* promptCmd.java
+ * interface to make easy prompt windows
+ */
+
+public abstract class promptCmd {
+  public abstract String getTitle();   /* Return the title of the window */
+  public abstract String getPrompt();  /* Return the text for label */
+  public abstract int getType();       /* Get type of query */
+
+  /* actions */
+  // type == YES_NO
+  public void yes() {}
+  // type == ONE_FIELD
+  public void one_field( String s ) {}
+  // type == TWO_FIELD
+  public void two_fields( String s1, String s2 ) {}
+
+  /* Override these as necessary */
+
+  /* type == ONE_FIELD || TWO_FIELD */
+  public String firstPrompt() { return ""; }
+  public boolean firstEcho() { return true; }
+
+  /* type == TWO_FIELD */
+  public String secondPrompt() { return ""; }
+  public boolean secondEcho() { return true; }
+
+  /* type == YES_NO */
+  public String affirm() { return "Yes"; }
+  public String negate() { return "No"; }
+}
diff --git a/shaggy/promptWindow.java b/shaggy/promptWindow.java
new file mode 100644 (file)
index 0000000..652215b
--- /dev/null
@@ -0,0 +1,89 @@
+/* promptWindow.java
+ * Generic framework for prompting users for stuff
+ */
+
+import java.awt.*;
+
+public class promptWindow extends Frame {
+  public static int    ONE_FIELD=1, TWO_FIELD=2, YES_NO=3;
+
+  promptCmd    cmd;
+
+  /* fields */
+  TextField    text1, text2;
+  Button       go, stop;
+
+  /* Yes/No */
+  Button       yes, no;
+
+  public promptWindow( promptCmd       cmd ) {
+    super( cmd.getTitle() );
+
+    this.cmd = cmd;
+
+    go = stop = yes = no = null;
+    text1 = text2 = null;
+
+    setLayout( new BorderLayout() );
+    add( "North", new Label( cmd.getPrompt() ) );
+
+    Panel      p = new Panel();
+
+    if( cmd.getType() != YES_NO ) {
+      PairPanel pp = new PairPanel();
+      add( "Center", pp );
+      pp.addLeft( new Label( cmd.firstPrompt() ) );
+      pp.addRight( text1 = new TextField(10) );
+      if( !cmd.firstEcho() )
+       text1.setEchoCharacter( '.' );
+      if( cmd.getType() == TWO_FIELD ) {
+       pp.addLeft( new Label( cmd.secondPrompt() ) );
+       pp.addRight( text2 = new TextField(10) );
+       if( cmd.secondEcho() )
+         text2.setEchoCharacter( '.' );
+      }
+
+      p.add( go = new Button( cmd.affirm() ) );
+      p.add( stop = new Button( cmd.negate() )  );
+      add( "South", p );
+    } else {
+      p.add( yes = new Button( "Yes" ) );
+      p.add( no = new Button( "No" ) );
+      add( "Center", p );
+    }
+
+    resize( 250, 150 );
+    show();
+  }
+
+  public boolean handleEvent( Event e ) {
+    if( e.id == Event.WINDOW_DESTROY ) {
+      dispose();
+    }
+    return super.handleEvent( e );
+  }
+
+  public boolean action( Event e, Object o ) {
+    if( (e.target == stop) || (e.target == no) ) {
+      dispose();
+
+    } else  if (e.target == yes ) {
+      dispose();
+      if( cmd.getType() == YES_NO )
+       cmd.yes();
+
+    } else if( e.target == go ) {
+      String   t1 = null, t2 = null;
+
+      if( text1 != null ) t1 = text1.getText();
+      else if( text2 != null ) t2 = text2.getText();
+
+      dispose();
+      if( cmd.getType() == ONE_FIELD )
+       cmd.one_field( t1 );
+      else
+       cmd.two_fields( t1, t2 );
+    }
+    return super.action( e, o );
+  }
+}
diff --git a/shaggy/roomPassPrompt.java b/shaggy/roomPassPrompt.java
new file mode 100644 (file)
index 0000000..216af0d
--- /dev/null
@@ -0,0 +1,22 @@
+/* roomPassPrompt.java
+ * when a room has a password
+ */
+
+public class roomPassPrompt extends promptCmd {
+  String       room;
+
+  public roomPassPrompt( String room ) {
+    this.room = room;
+  }
+
+  public int getType() { return promptWindow.ONE_FIELD; }
+  public String getTitle() { return "Password for \"" + room + "\""; }
+  public String getPrompt() { return room+ "'s password"; }
+
+  public String firstPrompt() { return  "Password:"; };
+  public boolean firstEcho() { return false; }
+
+  public void one_field( String pass ) {
+    citadel.me.enterRoom( room, pass );
+  }
+}
diff --git a/shaggy/zapPrompt.java b/shaggy/zapPrompt.java
new file mode 100644 (file)
index 0000000..cadc41c
--- /dev/null
@@ -0,0 +1,26 @@
+/* zapPrompt.java
+ * yes/no do you really want to zap this room?
+ */
+
+public class zapPrompt extends promptCmd {
+  String       name;
+
+  public zapPrompt( String name ) {
+    this.name = name;
+  }
+
+  public int getType() { return promptWindow.YES_NO; }
+  public String getPrompt() { 
+    return "Are you sure you want to zap " + name + "?";
+  }
+
+  public String getTitle() {
+    return "Zap Confirmation";
+  }
+
+  public void yes() {
+    citReply   r = citadel.me.getReply( "FORG" );
+    if( r.ok() )
+      citadel.me.nextNewRoom();
+  }
+}