5776611 [rkeene@sledge /home/rkeene/archive/floydssh/telnet]$ cat -n FuncParamsDlg.java
  1 package telnet;

  2 
  3 /* This file is part of "Telnet Floyd".
  4  *
  5  * (c) Radek Polak 2003-2004. All Rights Reserved.
  6  *
  7  * Please visit project homepage at http://phoenix.inf.upol.cz/~polakr
  8  *
  9  * --LICENSE NOTICE--
 10  * This program is free software; you can redistribute it and/or
 11  * modify it under the terms of the GNU General Public License
 12  * as published by the Free Software Foundation; either version 2
 13  * of the License, or (at your option) any later version.
 14  *
 15  * This program is distributed in the hope that it will be useful,
 16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  * GNU General Public License for more details.
 19  *
 20  * You should have received a copy of the GNU General Public License
 21  * along with this program; if not, write to the Free Software
 22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 23  * --LICENSE NOTICE--
 24  *
 25  */
 26 
 27 import javax.microedition.lcdui.*;

 28 
 29 /**
 30  * Dialog where user can specify parameters for given action. Action type is
 31  * specified by calling function setAction. E.g to set up parameters for new
 32  * connection use this code:
 33  *     ActionDlg dlg = new ActionDlg();
 34  *     Telnet.setDisplay(dlg);
 35  *     dlg.setAction(Action.CONNECT);
 36  */
 37 
 38 public class FuncParamsDlg
 39     extends Form
 40     implements CommandListener {
 41 
 42   String funct;
 43   TextField tfArg0;
 44   TextField tfArg1;
 45   TextField tfArg2;
 46 
 47   private final String LINES_TO_SCROLL = "lines to scroll";
 48 
 49   public FuncParamsDlg() {
 50     super("Function args");
 51     setCommandListener(this);
 52     addCommand(new Command("OK", Command.OK, 1));
 53   }
 54 
 55   public void setAction( String funct )
 56   {
 57     this.funct = funct;
 58 
 59     switch (funct.hashCode()) {
 60 
 61       case Action.BG_COLOR_HASH:
 62         add3("r", "g", "b",  "255", "255", "255");
 63         break;
 64       case Action.CONNECT_HASH:
 65         add3("host", "login", "password", "158.194.80.13", "polakr", "pwd");
 66         break;
 67       case Action.ENTER_STRING_HASH:
 68         add1("string to enter", "");
 69         break;
 70       case Action.FG_COLOR_HASH:
 71         add3("r", "g", "b", "0", "0", "0");
 72         break;
 73       case Action.INPUT_DIALOG_HASH:
 74         add1("default text", "" );
 75         break;
 76       case Action.KEEP_CONNECTION_TIME_HASH:
 77         add1("seconds after it dies", "300");
 78         break;
 79       case Action.KEY_PRESSED_HASH:
 80         add3("keycode", "keychar", "modifiers", "37", "65535", "8");
 81         break;
 82       case Action.KEY_TYPED_HASH:
 83         add3("key or code", "(keychar)", "(modifiers)", "ctrl+c", "", "");
 84         break;
 85       case Action.SCOLLBACK_DOWN_HASH:
 86         add1( LINES_TO_SCROLL, "5" );
 87         break;
 88       case Action.SCOLLBACK_UP_HASH:
 89         add1( LINES_TO_SCROLL, "5" );
 90         break;
 91       case Action.SCROLL_DOWN_HASH:
 92         add1( LINES_TO_SCROLL, "5" );
 93         break;
 94       case Action.SCROLL_LEFT_HASH:
 95         add1( LINES_TO_SCROLL, "5" );
 96         break;
 97       case Action.SCROLL_RIGH_HASH:
 98         add1( LINES_TO_SCROLL, "5" );
 99         break;
100       case Action.SCROLL_UP_HASH:
101         add1( LINES_TO_SCROLL, "5" );
102         break;
103       case Action.SET_SCOLLBACK_SIZE_HASH:
104         add1( LINES_TO_SCROLL, "100" );
105         break;
106       case Action.SET_SCREEN_SIZE_HASH:
107         add2( "width", "height", "80", "24" );
108         break;
109       case Action.SET_SLEEP_TIME_HASH:
110         add1( "time in ms", "1000" );
111         break;
112       case Action.TYPE_STRING_HASH:
113         add1( "string", "" );
114         break;
115       default:
116         done();
117     }
118   }
119 
120   private void add1(String label0, String val0) {
121     tfArg0 = new TextField(label0, val0, 64, TextField.ANY);
122     append(tfArg0);
123   }
124 
125   private void add2(String label0, String label1, String val0, String val1) {
126     add1( label0, val0 );
127     tfArg1 = new TextField(label1, val1, 64, TextField.ANY);
128     append(tfArg1);
129   }
130 
131   private void add3(String label0, String label1, String label2, String val0,
132                     String val1, String val2) {
133     add2( label0, label1, val0, val1 );
134     tfArg2 = new TextField(label2, val2, 64, TextField.ANY);
135     append(tfArg2);
136   }
137 
138   private void done() {
139     Action action = null;
140 
141     if (tfArg0 == null) {
142       action = new Action(funct);
143     }
144     else
145     if (tfArg1 == null) {
146       action = new Action(funct, tfArg0.getString());
147     }
148     else
149     if (tfArg2 == null) {
150       action = new Action(funct, tfArg0.getString(), tfArg1.getString());
151     }
152     else {
153       action = new Action(funct, tfArg0.getString(), tfArg1.getString(),
154                  tfArg2.getString());
155     }
156 
157     Telnet.setDisplay( (Displayable)new BindKey(action));
158   }
159 
160   public void commandAction(Command command, Displayable displayable) {
161     done();
162   }
163 }
164 
5776612 [rkeene@sledge /home/rkeene/archive/floydssh/telnet]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2004-03-07 01:16:36