Updated the Java Web Interface to allow passwords. If a user has no password
[spider.git] / spider-web / spiderframe.java
1 import java.awt.*;
2 import java.applet.*;
3 import java.io.*;
4 import java.net.*;
5 import java.util.*;
6
7 public class spiderframe extends Frame {
8
9
10         public spiderframe(spiderclient parent) {
11                 
12                 super("Spider DX Cluster");
13                 this.parent = parent;
14                 this.setFont(OutFont);
15
16                 menubar = new MenuBar();
17                 file = new Menu("File");
18                 file.add(connect_menuitem);
19                 file.add(new MenuItem("About"));
20                 file.add(new MenuItem("Quit"));
21                 if (Call.equals("NOCALL")) connect_menuitem.disable();
22                 menubar.add(file);
23                 
24                 edit = new Menu("Edit");
25                 edit.add(copy_menuitem);
26                 edit.add(paste_menuitem);
27                 copy_menuitem.disable();
28                 paste_menuitem.disable();
29 menubar.add(edit);
30                 
31                 
32
33 //              settings = new Menu("Preferences");
34 //              settings.add(new MenuItem("Personal preferences ..."));
35 // menubar.add(settings);
36                 
37                 
38                 
39                 commands = new Menu("Commands");
40                 commands.add(new MenuItem("Help"));
41                 commands.add(new MenuItem("Bye"));
42 menubar.add(commands);
43                 
44                 show = new Menu("Show");
45                 show.add(new MenuItem("Show Last DX"));
46                 show.add(new MenuItem("Show Beam Direction"));
47                             show.add(new MenuItem("Show wwv"));
48                             show.add(new MenuItem("Search DX"));
49                 show.add(new MenuItem("Search Address"));
50                             show.add(new MenuItem("Search QSL Manager"));
51                 show.add(new MenuItem("Search QSL Info"));
52                 show.add(new MenuItem("Search DXCC"));
53                 show.add(new MenuItem("Status"));
54 menubar.add(show);
55
56
57                 set = new Menu("Settings");
58                 set.add(new MenuItem("Set Beep"));
59                 set.add(new MenuItem("Set QTH / City"));
60                 set.add(new MenuItem("Set Name"));
61                 set.add(new MenuItem("Set Locator"));
62                 set.add(new MenuItem("Show Personal Settings"));
63 menubar.add(set); 
64
65
66                 dxann = new Menu("DXannounce");
67                 dxann.add(new MenuItem("DXannounce"));
68 menubar.add(dxann);     
69
70                 mailbox = new Menu("Mailbox");
71                 mailbox.add(new MenuItem("Last 50 Msgs"));
72                 mailbox.add(new MenuItem("List DX Bulletins"));
73 menubar.add(mailbox); 
74
75
76
77
78
79
80
81                 this.setMenuBar(menubar);
82
83                 setLayout(new BorderLayout());
84                 
85                 Panel p1 = new Panel();
86                 p1.setLayout(new BorderLayout());
87                 
88                 output = new TextArea();
89                 output.setEditable(false);
90
91                 p1.add("Center", output);
92                 input = new TextArea(2,80);
93                 input.setEditable(false);
94                 p1.add("South", input);
95                 add("Center", p1);
96                 
97                 
98                 Panel p2 = new Panel();
99                 p2.setLayout(new FlowLayout());
100                 connectButton.enable();
101                 p2.add(connectButton);
102                                                 
103                 disconnectButton.disable();
104                 p2.add(disconnectButton);
105                 add("South", p2);
106                 
107
108                 Panel p3 = new Panel();
109                 GridBagLayout gbl = new GridBagLayout();
110                 p3.setLayout(gbl);
111                 
112                 GridBagConstraints gbc = new GridBagConstraints();
113                 gbc.weightx = 20;
114                 gbc.weighty = 100;
115                 gbc.fill = GridBagConstraints.HORIZONTAL;
116                 gbc.anchor = GridBagConstraints.CENTER;
117                 
118                 add(p3,DateLabel,gbl, gbc, 0, 0, 1, 1);
119                 add(p3,IdleLabel, gbl, gbc, 2, 0, 2, 1);
120                 add(p3,connectState,gbl, gbc, 4, 0, 2, 1);
121                 
122                 add("North",p3);
123                                 
124                 setColors();
125                 setFonts();
126                 
127                 setDate time = new setDate(this);
128                 idle = new idleTime(this);
129                 
130         }
131
132
133         private void add(Panel p,Component c, GridBagLayout gbl,
134                 GridBagConstraints gbc,
135                 int x, int y, int w, int h) {
136                 
137                 gbc.gridx = x;
138                 gbc.gridy = y;
139                 gbc.gridwidth = w;
140                 gbc.gridheight = h;
141                 gbl.setConstraints(c, gbc);
142                 p.add(c);
143         }
144
145         public void setColors() {
146                 output.setBackground(OutBackgroundColor);
147                 output.setForeground(OutForegroundColor);
148                 input.setBackground(InBackgroundColor);
149                 input.setForeground(InForegroundColor);
150         }
151         
152         public void setFonts() {
153                 output.setFont(OutFont);
154                 input.setFont(InFont);
155         }
156         
157         public void initPrintStream(PrintStream out) {
158                 this.out = out;
159         }
160         
161         public void setText(String s) {
162                 int i;
163                 
164                  for (i=0; i < s.length(); i++) {
165                         if (s.charAt(i) == '\007')
166                                 parent.beep();
167                  }
168                 output.appendText(s +'\n');
169                  idle.resetTimer();
170         }
171         
172         public void setCall(String s) {
173                 Call = s;
174         }
175
176     public void setPassword(String s) {
177         Password = s ;
178     }
179
180         public void setPrefix(String s) {
181                 Prefix = s;
182                 }
183         
184         
185
186         public void setCall2(String s) {
187                 Call2 = s;
188                 }
189         
190       public void setFreq(String s) {
191                 Freq = s;
192                 }
193         
194
195       public void setRemarks(String s) {
196                 Remarks = s;
197                 }
198         
199
200
201         
202         public void setTime(String s) {
203                 DateLabel.setText(s);
204         }
205
206         public void setIdle(String s) {
207                 IdleLabel.setText(s);
208         }
209         
210         public String getCall() {
211                 return Call;
212         }
213         
214     public String getPassword() {
215         return Password;
216     }
217     
218         public String setPrefix(){
219                return Prefix;
220                }
221         
222         public String setCall2(){
223                return Call2;
224                }
225         
226         public String setFreq(){
227                return Freq;
228                }
229         
230         public String setRemarks(){
231                return Remarks;
232                }
233         
234         
235         
236         
237         
238         public void setFullname(String s) {
239                 Fullname = s;
240                 if (Call.equals("NOCALL")) 
241                         connect_menuitem.disable();
242                 else
243                         connect_menuitem.enable();
244         }
245         
246         public String getFullname() {
247                 return Fullname;
248         }
249         
250         public void setHostname(String s) {
251                 Hostname = s;
252         }
253                 
254         public String getHostname() {
255                 return Hostname;
256         }
257         
258         public void setPort(String s) {
259                 Port = s;
260         }
261         
262         public String getPort() {
263                 return Port;
264         }
265
266         public void setChannel(String s) {
267                 Channel = s;
268         }
269         
270         public String getChannel() {
271                 return Channel;
272         }
273         
274 //      public void login() {
275 //              PersonalPreferences pp = new PersonalPreferences(this, Call, Fullname, OutFont);
276 //      }
277         
278         public void antrichtung () {
279                 beam pp = new beam (this, Prefix,OutFont);
280         }
281         
282                 public void dxannounce () {
283                 dxannounce pp = new dxannounce (this, Call2, Freq, Remarks, OutFont);
284         }
285         
286
287         
288         
289         
290                 
291         public boolean handleEvent(Event evt) {
292                 if (evt.id == Event.KEY_PRESS) {
293                         if (evt.key == '\n') {
294                                 
295                                 
296                                 
297                                 idle.resetTimer();
298                                 output.appendText(input.getText()+'\n');
299                                 out.println(input.getText());
300                                                 
301
302                                 if (MaxInputPos < 255) {
303                                         InputPos++;                     
304                                         
305                                         MaxInputPos++;
306                                 }
307                                 else {
308                                         for(int i=0; i < 254; i++) {
309                                                 InputBuffer[i] = new String(InputBuffer[i+1]);
310                                         }
311                                         
312                                                          InputPos = 255;
313                                 }
314                                 InputBuffer[InputPos-1] = new String(input.getText());
315                                 input.setText("");
316                                 return true;
317                         }
318                 } else if (evt.id == Event.KEY_ACTION) {
319                         if (evt.key == Event.UP) {
320                                 if (InputPos > 0) {
321                                  InputPos--;
322                                         input.setText(InputBuffer[InputPos]);
323                                 }
324                                 return true;
325                         }
326                         else if (evt.key == Event.DOWN) {
327                                 if (InputPos < MaxInputPos) {
328                                         InputPos++;
329                                         input.setText(InputBuffer[InputPos]);
330                                 }
331                                 else {
332                                         input.setText("");      
333                                 }
334                                 
335                         } 
336                         return true;
337                 }
338                 
339                 return super.handleEvent(evt);
340         }
341
342         public synchronized void show() {
343                 move(50, 50);
344                 super.show();
345         }       
346         
347         public void setUserColor(Color c, String whichColor) {
348                 if (whichColor.equals("Output Background ...")) {
349                         OutBackgroundColor = c;
350                 }
351                 else if (whichColor.equals("Output Foreground ...")) {
352                         OutForegroundColor = c;
353                 } else  if (whichColor.equals("Input Background ...")) {
354                         InBackgroundColor = c;
355                 }
356                 else if (whichColor.equals("Input Foreground ...")) {
357                         InForegroundColor = c;
358                 } else if (whichColor.equals("Output own text ...")) {
359                         OutOwnColor = c;
360                 } 
361
362                 setColors();
363         }
364         
365         
366         public void connected() {
367                 connect_menuitem.setLabel("Disconnect");
368                 connectState.setText("Connected to "+Hostname+":"+Port);
369                 input.setEditable(true);
370                 copy_menuitem.enable();
371                 Connected = true;
372                 connectButton.disable();
373                 disconnectButton.enable();
374         }
375         
376         public void disconnected() {
377                 Connected = false;
378                 connect_menuitem.setLabel("Connect");
379                 connectState.setText("Disconnected from "+Hostname);
380                 input.setEditable(false);
381                 copy_menuitem.disable();
382                 paste_menuitem.disable();
383                 connectButton.enable();
384                 disconnectButton.disable();
385         }
386         
387         public void setUserFont(String name, int size, int style, 
388                                 String whichFont) {
389                 if (whichFont.equals("Area ...")) {
390                         OutFont = new Font(name, style, size);
391                 }
392                 else if (whichFont.equals("Input Line ...")) {
393                         InFont = new Font(name, style, size);
394                 }
395                 
396                 setFonts();
397         }
398         
399         
400         public void getSelectedText() {
401                 CopyPaste = new String(output.getSelectedText());
402                 paste_menuitem.enable();
403         }
404         
405         public boolean action(Event evt, Object arg) {
406                 if (evt.target instanceof MenuItem) {
407                         if (arg.equals("Quit")) {
408                                 this.hide();
409                 //      } else if (arg.equals("Personal preferences ...")) {
410                 //              PersonalPreferences pp = new PersonalPreferences(this,
411                 //                      Call, Fullname, OutFont);
412                         } else if (arg.equals("Connect")) {
413                                 parent.doconnect();
414                         } else if (arg.equals("Disconnect")) {
415                                 parent.dodisconnect();
416                         } else if (arg.equals("About")) {
417                                 InfoDialog id = new InfoDialog(this, "About", 
418                                 "JAVA Spider Webclient 0.6b\nPA4AB\n" +
419                                 "pa4ab@pa4ab.net \n" +
420                                 "April 2001\n" +
421                                 "Based on source of the CLX Client from dl6dbh" );
422                                 
423                          id.resize(500,300);
424                                 id.show();
425                         } else if (arg.equals("Copy")) {
426                                 getSelectedText();
427                         } else if (arg.equals("Paste")) {
428                                 input.insertText(CopyPaste,input.getSelectionStart());
429                         } else if (arg.equals("Bye")) {
430                                 if (Connected) out.println("bye");
431                         } else if (arg.equals("Help")) {
432                                 if (Connected) out.println("help overview");
433                         } else if (arg.equals("Show Last DX")) {
434                                 if (Connected) out.println("sh/dx");
435                         } else if (arg.equals("Status")) {
436                                 if (Connected) out.println("sh/conf");
437                         } else if (arg.equals("Show WWV")) {
438                                 if (Connected) out.println("sh/wwv");
439                         } else if (arg.equals("Show Beam Direction")) {
440                                 beam pp = new beam(this, Prefix, OutFont);
441                                 if (Connected) out.println ("sh/heading " + Prefix );
442                         } else if (arg.equals("search DX")) {
443                                 beam pp = new beam(this, Prefix, OutFont);
444                                 if (Connected) out.println ("sh/dx " + Prefix );
445                         
446                         } else if (arg.equals("Search QSL Info")) {
447                                 beam pp = new beam(this, Prefix, OutFont);
448                                 if (Connected) out.println ("sh/qsl " + Prefix );
449                          
450
451                         } else if (arg.equals("search Adress")) {
452                                 beam pp = new beam(this, Prefix, OutFont);
453                                 if (Connected) out.println ("sh/qrz " + Prefix );
454                         
455
456                         } else if (arg.equals("search qsl Manager")) {
457                                 beam pp = new beam(this, Prefix, OutFont);
458                                 if (Connected) out.println ("sh/qsl " + Prefix );
459                         
460
461                         } else if (arg.equals("search DXCC")) {
462                                 beam pp = new beam(this, Prefix, OutFont);
463                                 if (Connected) out.println ("sh/dxcc " + Prefix );
464                         
465                         // buttom settings
466
467                         } else if (arg.equals("Set Beep")) {
468                                 if (Connected) out.println("set/Beep");
469                         
470                         }else if (arg.equals("Set QTH / City")) {
471                                 beam pp = new beam(this, Prefix, OutFont);
472                                 if (Connected) out.println ("set/qth " + Prefix );
473                         
474
475                         }else if (arg.equals("Set Name")) {
476                                 beam pp = new beam(this, Prefix, OutFont);
477                                 if (Connected) out.println ("set/name " + Prefix );
478                         
479                         }
480                         else if (arg.equals("Set Locator")) {
481                                 beam pp = new beam(this, Prefix, OutFont);
482                                 if (Connected) out.println ("set/loc " + Prefix );
483                         
484
485                         }
486                         else if (arg.equals("Show Personal Settings")) {
487                                 if (Connected) out.println ("show/sta " + Call );
488                         
489
490                         }
491
492                         // dx announce
493
494                         else if (arg.equals("DXannounce")) {
495                                 dxannounce pp = new dxannounce(this, Call2, Freq, Remarks, OutFont);
496                                 if (Connected) out.println ("dx " + Call2 + " " + Freq + " " + Remarks );
497         
498                         }
499                         // mailbox 
500                          else if (arg.equals("last 50 Msgs")) {
501                                 if (Connected) out.println ("dir/50 " );
502                          }
503                          else if (arg.equals("list DX Bulletins")) {
504                                 if (Connected) out.println ("dir/bul " );
505                          }
506                          else if (arg.equals("new Msgs")) {
507                                 if (Connected) out.println ("dir/new " );
508                          }
509                          else if (arg.equals("own Msgs")) {
510                                 if (Connected) out.println ("dir/own " );
511                          }
512                                 
513
514
515                         else return false;
516                 }
517                 else if (evt.target instanceof Button) {
518                         if (arg.equals("Connect")) {
519                                 if (!Connected) {
520                                         parent.doconnect();
521                                 } else return false;
522                         } else if (arg.equals("Disconnect")) {
523                                 if (Connected) {
524                                         parent.dodisconnect();
525                                 } else return false;
526                         }
527                 
528                         else return false;
529                 }
530                 
531                 return true;
532         }
533
534         private idleTime idle;
535
536         private TextArea input;
537         private TextArea output;
538         private MenuBar menubar;
539         private Menu file;
540         private Menu edit;
541         private Menu settings;
542         private Menu colors;
543         private Menu fonts;
544         private Menu commands;
545         private Menu show;
546         private Menu set;
547         private Menu dxann;
548         private Menu mailbox;
549
550
551         private MenuItem connect_menuitem = new MenuItem("Connect");
552         private MenuItem copy_menuitem = new MenuItem("Copy");
553         private MenuItem paste_menuitem = new MenuItem("Paste");
554
555         private Button connectButton = new java.awt.Button("Connect");
556         private Button disconnectButton = new java.awt.Button("Disconnect");
557
558         private Date today = new Date();
559         private Label DateLabel = new Label(today.toLocaleString());
560         private Label IdleLabel = new Label("00:00");
561         private Label connectState = new Label("not connected");
562         
563  
564         private Color OutBackgroundColor = new Color(0,0,66);
565         private Color OutForegroundColor = new Color(255,255,0);
566         private Color OutOwnColor = Color.red;
567         private Color InBackgroundColor = new Color(234,199,135);
568         private Color InForegroundColor = Color.red;
569         
570         private Font OutFont = new Font("Courier", Font.PLAIN, 13);
571         private Font InFont = new Font("Courier", Font.BOLD, 13);
572         
573         private String Call = new String("NOCALL");
574         private String Password = new String();
575         private String Fullname = new String("NOBODY");
576         private String Hostname = new String("localhost");
577         private String Port = new String("3600");
578         private String Channel = new String("0");
579
580
581         private String Prefix = new String ("");        
582         private String Call2 = new String ("");        
583         private String Freq = new String ("");        
584         private String Remarks = new String ("");        
585
586
587
588
589
590
591
592         private PrintStream out = null;
593         
594         private String InputBuffer[] = new String[256];
595         private int InputPos = 0;
596         private int MaxInputPos = 0;
597         
598         private String CopyPaste; 
599         
600         private boolean Connected;
601         
602         private spiderclient parent;
603
604 }
605
606 class setDate extends Thread {
607
608         spiderframe cf;
609         
610         public setDate(spiderframe cf) {
611                 this.cf = cf;
612                 this.start();
613         }
614
615         public void run() {
616                 for(;;) {
617                         try { sleep(1000); } catch (InterruptedException e) {}
618                         today = new Date();
619                         cf.setTime(today.toLocaleString());
620                 }
621         }
622         
623         private Date today = new Date();
624         
625 }
626
627
628 class idleTime extends Thread {
629
630         spiderframe cf;
631         int count;
632         
633         public idleTime(spiderframe cf) {
634                 this.cf = cf;
635                 this.start();
636                 count = 0;
637         }
638
639         public void resetTimer() {
640                 count=0;
641         }
642
643         public void run() {
644                 
645                 for(;;) {
646                         try { sleep(1000); } catch (InterruptedException e) {}
647                         count++;
648                         String sec = new Format("%02d").form(count % 60);
649                         String min = new Format("%02d").form(count / 60);
650                         cf.setIdle("Idle: "+min+":"+sec);
651                 }
652         }
653 }