]> code.citadel.org Git - citadel.git/blob - shaggy/promptWindow.java
improvement of the daily view of calendar, imcomplete...
[citadel.git] / shaggy / promptWindow.java
1 /* promptWindow.java
2  * Generic framework for prompting users for stuff
3  */
4
5 import java.awt.*;
6
7 public class promptWindow extends Frame {
8   public static int     ONE_FIELD=1, TWO_FIELD=2, YES_NO=3;
9
10   promptCmd     cmd;
11
12   /* fields */
13   TextField     text1, text2;
14   Button        go, stop;
15
16   /* Yes/No */
17   Button        yes, no;
18
19   public promptWindow( promptCmd        cmd ) {
20     super( cmd.getTitle() );
21
22     this.cmd = cmd;
23
24     go = stop = yes = no = null;
25     text1 = text2 = null;
26
27     setLayout( new BorderLayout() );
28     add( "North", new Label( cmd.getPrompt() ) );
29
30     Panel       p = new Panel();
31
32     if( cmd.getType() != YES_NO ) {
33       PairPanel pp = new PairPanel();
34       add( "Center", pp );
35       pp.addLeft( new Label( cmd.firstPrompt() ) );
36       pp.addRight( text1 = new TextField(10) );
37       if( !cmd.firstEcho() )
38         text1.setEchoCharacter( '.' );
39       if( cmd.getType() == TWO_FIELD ) {
40         pp.addLeft( new Label( cmd.secondPrompt() ) );
41         pp.addRight( text2 = new TextField(10) );
42         if( cmd.secondEcho() )
43           text2.setEchoCharacter( '.' );
44       }
45
46       p.add( go = new Button( cmd.affirm() ) );
47       p.add( stop = new Button( cmd.negate() )  );
48       add( "South", p );
49     } else {
50       p.add( yes = new Button( "Yes" ) );
51       p.add( no = new Button( "No" ) );
52       add( "Center", p );
53     }
54
55     resize( 250, 150 );
56     show();
57   }
58
59   public boolean handleEvent( Event e ) {
60     if( e.id == Event.WINDOW_DESTROY ) {
61       dispose();
62     }
63     return super.handleEvent( e );
64   }
65
66   public boolean action( Event e, Object o ) {
67     if( (e.target == stop) || (e.target == no) ) {
68       dispose();
69
70     } else  if (e.target == yes ) {
71       dispose();
72       if( cmd.getType() == YES_NO )
73         cmd.yes();
74
75     } else if( e.target == go ) {
76       String    t1 = null, t2 = null;
77
78       if( text1 != null ) t1 = text1.getText();
79       else if( text2 != null ) t2 = text2.getText();
80
81       dispose();
82       if( cmd.getType() == ONE_FIELD )
83         cmd.one_field( t1 );
84       else
85         cmd.two_fields( t1, t2 );
86     }
87     return super.action( e, o );
88   }
89 }