947cd0ad9dee8119eafdff1a9bc872688e6f1ca8
[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                 mailbox.add(new MenuItem("New Messages"));
74                 mailbox.add(new MenuItem("Own Messages"));
75 menubar.add(mailbox); 
76
77
78
79
80
81
82
83                 this.setMenuBar(menubar);
84
85                 setLayout(new BorderLayout());
86                 
87                 Panel p1 = new Panel();
88                 p1.setLayout(new BorderLayout());
89                 
90                 output = new TextArea();
91                 output.setEditable(false);
92
93                 p1.add("Center", output);
94                 input = new TextArea(2,80);
95                 input.setEditable(false);
96                 p1.add("South", input);
97                 add("Center", p1);
98                 
99                 
100                 Panel p2 = new Panel();
101                 p2.setLayout(new FlowLayout());
102                 connectButton.enable();
103                 p2.add(connectButton);
104                                                 
105                 disconnectButton.disable();
106                 p2.add(disconnectButton);
107                 add("South", p2);
108                 
109
110                 Panel p3 = new Panel();
111                 GridBagLayout gbl = new GridBagLayout();
112                 p3.setLayout(gbl);
113                 
114                 GridBagConstraints gbc = new GridBagConstraints();
115                 gbc.weightx = 20;
116                 gbc.weighty = 100;
117                 gbc.fill = GridBagConstraints.HORIZONTAL;
118                 gbc.anchor = GridBagConstraints.CENTER;
119                 
120                 add(p3,DateLabel,gbl, gbc, 0, 0, 1, 1);
121                 add(p3,IdleLabel, gbl, gbc, 2, 0, 2, 1);
122                 add(p3,connectState,gbl, gbc, 4, 0, 2, 1);
123                 
124                 add("North",p3);
125                                 
126                 setColors();
127                 setFonts();
128                 
129                 setDate time = new setDate(this);
130                 idle = new idleTime(this);
131                 
132         }
133
134
135         private void add(Panel p,Component c, GridBagLayout gbl,
136                 GridBagConstraints gbc,
137                 int x, int y, int w, int h) {
138                 
139                 gbc.gridx = x;
140                 gbc.gridy = y;
141                 gbc.gridwidth = w;
142                 gbc.gridheight = h;
143                 gbl.setConstraints(c, gbc);
144                 p.add(c);
145         }
146
147         public void setColors() {
148                 output.setBackground(OutBackgroundColor);
149                 output.setForeground(OutForegroundColor);
150                 input.setBackground(InBackgroundColor);
151                 input.setForeground(InForegroundColor);
152         }
153         
154         public void setFonts() {
155                 output.setFont(OutFont);
156                 input.setFont(InFont);
157         }
158         
159         public void initPrintStream(PrintStream out) {
160                 this.out = out;
161         }
162         
163         public void setText(String s) {
164                 int i;
165                 
166                  for (i=0; i < s.length(); i++) {
167                         if (s.charAt(i) == '\007')
168                                 parent.beep();
169                  }
170                 output.appendText(s +'\n');
171                  idle.resetTimer();
172         }
173         
174         public void setCall(String s) {
175                 Call = s;
176         }
177
178     public void setPassword(String s) {
179         Password = s ;
180     }
181
182         public void setPrefix(String s) {
183                 Prefix = s;
184                 }
185         
186         
187
188         public void setCall2(String s) {
189                 Call2 = s;
190                 }
191         
192       public void setFreq(String s) {
193                 Freq = s;
194                 }
195         
196
197       public void setRemarks(String s) {
198                 Remarks = s;
199                 }
200         
201
202
203         
204         public void setTime(String s) {
205                 DateLabel.setText(s);
206         }
207
208         public void setIdle(String s) {
209                 IdleLabel.setText(s);
210         }
211         
212         public String getCall() {
213                 return Call;
214         }
215         
216     public String getPassword() {
217         return Password;
218     }
219     
220         public String setPrefix(){
221                return Prefix;
222                }
223         
224         public String setCall2(){
225                return Call2;
226                }
227         
228         public String setFreq(){
229                return Freq;
230                }
231         
232         public String setRemarks(){
233                return Remarks;
234                }
235         
236         
237         
238         
239         
240         public void setFullname(String s) {
241                 Fullname = s;
242                 if (Call.equals("NOCALL")) 
243                         connect_menuitem.disable();
244                 else
245                         connect_menuitem.enable();
246         }
247         
248         public String getFullname() {
249                 return Fullname;
250         }
251         
252         public void setHostname(String s) {
253                 Hostname = s;
254         }
255                 
256         public String getHostname() {
257                 return Hostname;
258         }
259         
260         public void setPort(String s) {
261                 Port = s;
262         }
263         
264         public String getPort() {
265                 return Port;
266         }
267
268         public void setChannel(String s) {
269                 Channel = s;
270         }
271         
272         public String getChannel() {
273                 return Channel;
274         }
275         
276 //      public void login() {
277 //              PersonalPreferences pp = new PersonalPreferences(this, Call, Fullname, OutFont);
278 //      }
279         
280         public void antrichtung () {
281                 beam pp = new beam (this, Prefix,OutFont);
282         }
283         
284                 public void dxannounce () {
285                 dxannounce pp = new dxannounce (this, Call2, Freq, Remarks, OutFont);
286         }
287         
288
289         
290         
291         
292                 
293         public boolean handleEvent(Event evt) {
294                 if (evt.id == Event.KEY_PRESS) {
295                         if (evt.key == '\n') {
296                                 
297                                 
298                                 
299                                 idle.resetTimer();
300                                 output.appendText(input.getText()+'\n');
301                                 out.println(input.getText());
302                                                 
303
304                                 if (MaxInputPos < 255) {
305                                         InputPos++;                     
306                                         
307                                         MaxInputPos++;
308                                 }
309                                 else {
310                                         for(int i=0; i < 254; i++) {
311                                                 InputBuffer[i] = new String(InputBuffer[i+1]);
312                                         }
313                                         
314                                                          InputPos = 255;
315                                 }
316                                 InputBuffer[InputPos-1] = new String(input.getText());
317                                 input.setText("");
318                                 return true;
319                         }
320                 } else if (evt.id == Event.KEY_ACTION) {
321                         if (evt.key == Event.UP) {
322                                 if (InputPos > 0) {
323                                  InputPos--;
324                                         input.setText(InputBuffer[InputPos]);
325                                 }
326                                 return true;
327                         }
328                         else if (evt.key == Event.DOWN) {
329                                 if (InputPos < MaxInputPos) {
330                                         InputPos++;
331                                         input.setText(InputBuffer[InputPos]);
332                                 }
333                                 else {
334                                         input.setText("");      
335                                 }
336                                 
337                         } 
338                         return true;
339                 }
340                 
341                 return super.handleEvent(evt);
342         }
343
344         public synchronized void show() {
345                 move(50, 50);
346                 super.show();
347         }       
348         
349         public void setUserColor(Color c, String whichColor) {
350                 if (whichColor.equals("Output Background ...")) {
351                         OutBackgroundColor = c;
352                 }
353                 else if (whichColor.equals("Output Foreground ...")) {
354                         OutForegroundColor = c;
355                 } else  if (whichColor.equals("Input Background ...")) {
356                         InBackgroundColor = c;
357                 }
358                 else if (whichColor.equals("Input Foreground ...")) {
359                         InForegroundColor = c;
360                 } else if (whichColor.equals("Output own text ...")) {
361                         OutOwnColor = c;
362                 } 
363
364                 setColors();
365         }
366         
367         
368         public void connected() {
369                 connect_menuitem.setLabel("Disconnect");
370                 connectState.setText("Connected to "+Hostname+":"+Port);
371                 input.setEditable(true);
372                 copy_menuitem.enable();
373                 Connected = true;
374                 connectButton.disable();
375                 disconnectButton.enable();
376         }
377         
378         public void disconnected() {
379                 Connected = false;
380                 connect_menuitem.setLabel("Connect");
381                 connectState.setText("Disconnected from "+Hostname);
382                 input.setEditable(false);
383                 copy_menuitem.disable();
384                 paste_menuitem.disable();
385                 connectButton.enable();
386                 disconnectButton.disable();
387         }
388         
389         public void setUserFont(String name, int size, int style, 
390                                 String whichFont) {
391                 if (whichFont.equals("Area ...")) {
392                         OutFont = new Font(name, style, size);
393                 }
394                 else if (whichFont.equals("Input Line ...")) {
395                         InFont = new Font(name, style, size);
396                 }
397                 
398                 setFonts();
399         }
400         
401         
402         public void getSelectedText() {
403                 CopyPaste = new String(output.getSelectedText());
404                 paste_menuitem.enable();
405         }
406         
407         public boolean action(Event evt, Object arg) {
408                 if (evt.target instanceof MenuItem) {
409                         if (arg.equals("Quit")) {
410                                 this.hide();
411                 //      } else if (arg.equals("Personal preferences ...")) {
412                 //              PersonalPreferences pp = new PersonalPreferences(this,
413                 //                      Call, Fullname, OutFont);
414                         } else if (arg.equals("Connect")) {
415                                 parent.doconnect();
416                         } else if (arg.equals("Disconnect")) {
417                                 parent.dodisconnect();
418                         } else if (arg.equals("About")) {
419                                 InfoDialog id = new InfoDialog(this, "About", 
420                                 "JAVA Spider Webclient 0.6b\nPA4AB\n" +
421                                 "pa4ab@pa4ab.net \n" +
422                                 "April 2001\n" +
423                                 "Based on source of the CLX Client from dl6dbh" );
424                                 
425                          id.resize(500,300);
426                                 id.show();
427                         } else if (arg.equals("Copy")) {
428                                 getSelectedText();
429                         } else if (arg.equals("Paste")) {
430                                 input.insertText(CopyPaste,input.getSelectionStart());
431                         } else if (arg.equals("Bye")) {
432                                 if (Connected) out.println("bye");
433                         } else if (arg.equals("Help")) {
434                                 if (Connected) out.println("? all");
435                         } else if (arg.equals("Show Last DX")) {
436                                 if (Connected) out.println("sh/dx");
437                         } else if (arg.equals("Status")) {
438                                 if (Connected) out.println("sh/c");
439                         } else if (arg.equals("Show WWV")) {
440                                 if (Connected) out.println("sh/wwv");
441                         } else if (arg.equals("Show Beam Direction")) {
442                                 beam pp = new beam(this, Prefix, OutFont);
443                                 if (Connected) out.println ("sh/heading " + Prefix );
444                         } else if (arg.equals("Search DX")) {
445                                 beam pp = new beam(this, Prefix, OutFont);
446                                 if (Connected) out.println ("sh/dx " + Prefix );
447                         
448                         } else if (arg.equals("Search QSL Info")) {
449                                 beam pp = new beam(this, Prefix, OutFont);
450                                 if (Connected) out.println ("sh/qsl " + Prefix );
451                          
452
453                         } else if (arg.equals("Search Address")) {
454                                 beam pp = new beam(this, Prefix, OutFont);
455                                 if (Connected) out.println ("sh/qrz " + Prefix );
456                         
457
458                         } else if (arg.equals("Search QSL Manager")) {
459                                 beam pp = new beam(this, Prefix, OutFont);
460                                 if (Connected) out.println ("sh/qsl " + Prefix );
461                         
462
463                         } else if (arg.equals("Search DXCC")) {
464                                 beam pp = new beam(this, Prefix, OutFont);
465                                 if (Connected) out.println ("sh/pr " + Prefix );
466                         
467                         // buttom settings
468
469                         } else if (arg.equals("Set Beep")) {
470                                 if (Connected) out.println("set/Beep");
471                         
472                         }else if (arg.equals("Set QTH / City")) {
473                                 beam pp = new beam(this, Prefix, OutFont);
474                                 if (Connected) out.println ("set/qth " + Prefix );
475                         
476
477                         }else if (arg.equals("Set Name")) {
478                                 beam pp = new beam(this, Prefix, OutFont);
479                                 if (Connected) out.println ("set/name " + Prefix );
480                         
481                         }
482                         else if (arg.equals("Set Locator")) {
483                                 beam pp = new beam(this, Prefix, OutFont);
484                                 if (Connected) out.println ("set/qra " + Prefix );
485                         
486                         }
487                         else if (arg.equals("Show Personal Settings")) {
488                                 if (Connected) out.println ("sh/sta " + Call );
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 " + Freq + " " + Call2 + " " + 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 Messages")) {
507                                 if (Connected) out.println ("dir/new" );
508                          }
509                          else if (arg.equals("Own Messages")) {
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 }