source: trunk/hiptop/cognet++/org/twodot/cognet/LoginWindow.java@ 210

Last change on this file since 210 was 210, checked in by Nicholas Riley, 18 years ago

cognet++: Brian Swetland et al.'s generic proxied hiptop chat client.
Requires cognetd to function.

File size: 4.9 KB
Line 
1/*
2 * cognet chat app
3 *
4 * Copyright 2003, Brian Swetland <swetland@frotz.net>
5 * See LICENSE for redistribution terms
6 *
7 */
8package org.twodot.cognet;
9
10import danger.ui.ScreenWindow;
11import danger.ui.TextField;
12import danger.ui.StaticText;
13import danger.ui.StaticTextBox;
14import danger.ui.PasswordTextField;
15import danger.ui.Button;
16import danger.ui.DialogWindow;
17import danger.app.Resource;
18
19import danger.app.Event;
20
21public class LoginWindow extends ScreenWindow implements Resources, Events
22{
23 public LoginWindow(Engine e) {
24 super("Connect to Server", e.app.getBitmap(Resources.kPending));
25 StaticText st;
26
27 engine = e;
28 app = e.app;
29
30 int w = 60;
31 int h = 20;
32 int w2 = getWidth() - w - 20;
33 int y = 5;
34 int adj = 3;
35
36 st = new StaticText("Server ");
37 st.setAlignment(StaticText.HALIGN_RIGHT);
38 st.setPosition(0, y + adj);
39 st.setSize(w, h);
40 st.show();
41 addChild(st);
42
43 host = new TextField(false, false);
44 host.setPosition(w, y);
45 host.setSize(w2,h);
46 host.show();
47 addChild(host);
48
49 y += h + 2;
50
51 st = new StaticText("Port ");
52 st.setAlignment(StaticText.HALIGN_RIGHT);
53 st.setPosition(0, y + adj);
54 st.setSize(w, h);
55 st.show();
56 addChild(st);
57
58 port = new TextField(false, false);
59 port.setPosition(w, y);
60 port.setSize(w2,h);
61 port.show();
62 addChild(port);
63
64 y += h + 2;
65
66 st = new StaticText("Username ");
67 st.setAlignment(StaticText.HALIGN_RIGHT);
68 st.setPosition(0, y + adj);
69 st.setSize(w, h);
70 st.show();
71 addChild(st);
72
73 user = new TextField(false, false);
74 user.setPosition(w, y);
75 user.setSize(w2,h);
76 user.show();
77 addChild(user);
78
79 y += h + 2;
80
81 st = new StaticText("Password ");
82 st.setAlignment(StaticText.HALIGN_RIGHT);
83 st.setPosition(0, y + adj);
84 st.setSize(w, h);
85 st.show();
86 addChild(st);
87
88 passwd = new PasswordTextField();
89 passwd.setPosition(w, y);
90 passwd.setSize(w2,h);
91 passwd.show();
92 addChild(passwd);
93
94 y += h + 2;
95 Button aboutBtn = new Button(" About ");
96 aboutBtn.setPosition(w + 35,y);
97 aboutBtn.show();
98 addChild(aboutBtn);
99 aboutBtn.setEvent(this, 6000);
100
101 button = new Button(" Connect ");
102 button.setPosition(w,y);
103 button.setTop(y);
104 button.setRight(w + w2);
105 button.show();
106 addChild(button);
107 button.setEvent(this, 5038);
108
109 setFocusedChild(button);
110
111 host.setText(engine.HOST);
112 port.setText(Integer.toString(engine.PORT));
113 user.setText(engine.USER);
114 passwd.setText(engine.PASSWD);
115
116 }
117
118 public void show() {
119 engine.MakeActive(null);
120 super.show();
121 }
122
123 public void adjustActionMenuState() {
124 app.MakeMenu(getActionMenu(),null);
125 }
126
127 public boolean eventWidgetUp(int widget, Event event) {
128 switch(widget) {
129 case Event.DEVICE_BUTTON_BACK:
130 getApplication().returnToLauncher();
131 return true;
132 default:
133 return super.eventWidgetUp(widget,event);
134 }
135 }
136
137
138 public boolean receiveEvent(Event e) {
139 if(e.type == 5038){
140 switch(engine.state){
141 case Engine.OFFLINE:
142 engine.HOST = new String(host.getChars());
143 engine.PORT = Integer.parseInt(new String(port.getChars()));
144 engine.USER = new String(user.getChars());
145 engine.PASSWD = new String(passwd.getChars());
146 engine.login();
147 return true;
148
149 case Engine.CONNECTING:
150 return true;
151
152 case Engine.ONLINE:
153 engine.logout();
154 return true;
155
156 default:
157 return true;
158 }
159 }
160
161 if(e.type == 5039){
162 System.err.println("statecheck");
163 switch(engine.state){
164 case Engine.OFFLINE:
165 button.setTitle("Connect");
166 return true;
167 case Engine.CONNECTING:
168 button.setTitle("Cancel");
169 return true;
170 case Engine.ONLINE:
171 // save settings
172 System.out.println("cognet: commit settings");
173 app.cogSettings.setStringValue("host", engine.HOST);
174 app.cogSettings.setIntValue("port", engine.PORT);
175 app.cogSettings.setStringValue("user", engine.USER);
176 app.cogSettings.setStringValue("password", engine.PASSWD);
177
178 button.setTitle("Disconnect");
179 return true;
180 default:
181 return true;
182 }
183 }
184 if(e.type == 5040 && app.doAutoConnect){
185 System.err.println("autologin");
186 if (engine.PASSWD != null && engine.PASSWD.length()>0) {
187 hide();
188 engine.login();
189 }
190 return true;
191 }
192
193 if(e.type == 6000) {
194 DialogWindow w = app.getDialog(kAboutDialog, this);
195 StaticTextBox s = (StaticTextBox)w.getDescendantWithID(kID_AboutText);
196 Resource r = app.getResources().getResource(257, kLicense);
197 byte b[] = new byte[r.getSize()];
198 r.getBytes(b,0,r.getSize());
199 s.setText(new String(b));
200 w.show();
201 }
202
203 return super.receiveEvent(e);
204 }
205
206 void SendEvent(int e) {
207 sendEventToWindow(new Event(this,e));
208 }
209
210 public boolean eventShortcut(char c, Event e) {
211 if(c == 'n') {
212 if(engine.first != null){
213 engine.first.show();
214 }
215 return true;
216 }
217 return super.eventShortcut(c, e);
218 }
219
220 TextField host, port, user, passwd;
221 Button button;
222
223 Engine engine;
224 Cognet app;
225
226}
Note: See TracBrowser for help on using the repository browser.