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