]> scm.dxcluster.org Git - spider.git/blob - spider-web/spiderframe.java
remove typo in dxprothandle
[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("Show WCY"));
49                 show.add(new MenuItem("Search DX"));
50                 show.add(new MenuItem("Search Address"));
51                 show.add(new MenuItem("Search QSL Manager"));
52                 show.add(new MenuItem("Search QSL Info"));
53                 show.add(new MenuItem("Search DXCC"));
54                 show.add(new MenuItem("Status"));
55 menubar.add(show);
56
57
58                 set = new Menu("Settings");
59                 set.add(new MenuItem("Set Beep"));
60                 set.add(new MenuItem("Set No Beep"));
61                 set.add(new MenuItem("Set QTH / City"));
62                 set.add(new MenuItem("Set Name"));
63                 set.add(new MenuItem("Set Locator"));
64                 set.add(new MenuItem("Set HomeNode"));
65                 set.add(new MenuItem("Set DX-Grid"));
66                 set.add(new MenuItem("Set No DX-Grid"));
67                 set.add(new MenuItem("Show Personal Settings"));
68 menubar.add(set); 
69
70
71                 dxann = new Menu("DXannounce");
72                 dxann.add(new MenuItem("DXannounce"));
73 menubar.add(dxann);     
74
75                 mailbox = new Menu("Mailbox");
76                 mailbox.add(new MenuItem("Last 10 Msgs"));
77                 mailbox.add(new MenuItem("Last 50 Msgs"));
78                 mailbox.add(new MenuItem("New Messages"));
79                 mailbox.add(new MenuItem("Own Messages"));
80 menubar.add(mailbox); 
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 setNodecall(String s) {
180                 Nodecall = s ;
181                 }
182                 
183         public void setPassword(String s) {
184                 Password = s ;
185                 }
186
187         public void setPrefix(String s) {
188                 Prefix = s;
189                 }
190                 
191         public void setCall2(String s) {
192                 Call2 = s;
193                 }
194         
195         public void setFreq(String s) {
196                 Freq = s;
197                 }
198         
199         public void setRemarks(String s) {
200                 Remarks = s;
201                 }
202         
203         public void setTime(String s) {
204                 DateLabel.setText(s);
205                 }
206
207         public void setIdle(String s) {
208                 IdleLabel.setText(s);
209                 }
210         
211         public String getCall() {
212                 return Call;
213                 }
214         
215         public String getPassword() {
216                 return Password;
217                 }
218     
219         public String setPrefix(){
220                 return Prefix;
221                 }
222         
223         public String setCall2(){
224                 return Call2;
225                 }
226         
227         public String setFreq(){
228                 return Freq;
229                 }
230         
231         public String setRemarks(){
232                 return Remarks;
233                 }
234         
235         public void setFullname(String s) {
236                 Fullname = s;
237                 if (Call.equals("NOCALL")) 
238                         connect_menuitem.disable();
239                 else
240                         connect_menuitem.enable();
241                 }
242         
243         public String getFullname() {
244                 return Fullname;
245                 }
246         
247         public void setHostname(String s) {
248                 Hostname = s;
249                 }
250                 
251         public String getHostname() {
252                 return Hostname;
253                 }
254         
255         public void setPort(String s) {
256                 Port = s;
257                 }
258         
259         public String getPort() {
260                 return Port;
261                 }
262
263         public void setChannel(String s) {
264                 Channel = s;
265                 }
266         
267         public String getChannel() {
268                 return Channel;
269                 }
270         
271 //      public void login() {
272 //              PersonalPreferences pp = new PersonalPreferences(this, Call, Fullname, OutFont);
273 //      }
274         
275         public void antrichtung () {
276                 beam pp = new beam (this, Prefix,OutFont);
277                 }
278         
279 //              public void dxannounce () {
280 //              dxannounce pp = new dxannounce (this, Call2, Freq, Remarks, OutFont);
281 //      }
282         
283
284         public boolean handleEvent(Event evt) {
285                 if (evt.id == Event.KEY_PRESS) {
286                         if (evt.key == '\n') {
287                                 
288                                 idle.resetTimer();
289                                 output.appendText(input.getText()+'\n');
290                                 out.println(input.getText());
291
292                                 if (MaxInputPos < 255) {
293                                         InputPos++;                     
294                                         
295                                         MaxInputPos++;
296                                 }
297                                 else {
298                                         for(int i=0; i < 254; i++) {
299                                                 InputBuffer[i] = new String(InputBuffer[i+1]);
300                                         }
301                                         
302                                                          InputPos = 255;
303                                 }
304                                 InputBuffer[InputPos-1] = new String(input.getText());
305                                 input.setText("");
306                                 return true;
307                         }
308                 } else if (evt.id == Event.KEY_ACTION) {
309                         if (evt.key == Event.UP) {
310                                 if (InputPos > 0) {
311                                  InputPos--;
312                                         input.setText(InputBuffer[InputPos]);
313                                 }
314                                 return true;
315                         }
316                         else if (evt.key == Event.DOWN) {
317                                 if (InputPos < MaxInputPos) {
318                                         InputPos++;
319                                         input.setText(InputBuffer[InputPos]);
320                                 }
321                                 else {
322                                         input.setText("");      
323                                 }
324                         } 
325                         return true;
326                 }
327                 return super.handleEvent(evt);
328         }
329
330         public synchronized void show() {
331                 move(50, 50);
332                 super.show();
333         }       
334         
335         public void setUserColor(Color c, String whichColor) {
336                 if (whichColor.equals("Output Background ...")) {
337                         OutBackgroundColor = c;
338                 }
339                 else if (whichColor.equals("Output Foreground ...")) {
340                         OutForegroundColor = c;
341                 } else  if (whichColor.equals("Input Background ...")) {
342                         InBackgroundColor = c;
343                 }
344                 else if (whichColor.equals("Input Foreground ...")) {
345                         InForegroundColor = c;
346                 } else if (whichColor.equals("Output own text ...")) {
347                         OutOwnColor = c;
348                 } 
349
350                 setColors();
351         }
352         
353         
354         public void connected() {
355                 connect_menuitem.setLabel("Disconnect");
356                 connectState.setText("Connected to " + Nodecall);
357                 input.setEditable(true);
358                 copy_menuitem.enable();
359                 Connected = true;
360                 connectButton.disable();
361                 disconnectButton.enable();
362         }
363         
364         public void disconnected() {
365                 Connected = false;
366                 connect_menuitem.setLabel("Connect");
367                 connectState.setText("Disconnected from " + Nodecall);
368                 input.setEditable(false);
369                 copy_menuitem.disable();
370                 paste_menuitem.disable();
371                 connectButton.enable();
372                 disconnectButton.disable();
373         }
374         
375         public void setUserFont(String name, int size, int style, 
376                                 String whichFont) {
377                 if (whichFont.equals("Area ...")) {
378                         OutFont = new Font(name, style, size);
379                 }
380                 else if (whichFont.equals("Input Line ...")) {
381                         InFont = new Font(name, style, size);
382                 }
383                 
384                 setFonts();
385         }
386         
387         
388         public void getSelectedText() {
389                 CopyPaste = new String(output.getSelectedText());
390                 paste_menuitem.enable();
391         }
392         
393         public boolean action(Event evt, Object arg) {
394                 
395                 Prefix =  ""; // Make sure that the following variables are empty !
396                 Call2 = "";
397                 Freq = "";
398                 Remarks = "";
399                 
400                 if (evt.target instanceof MenuItem) {
401                         if (arg.equals("Quit")) {
402                                 this.hide();
403                 //      } else if (arg.equals("Personal preferences ...")) {
404                 //              PersonalPreferences pp = new PersonalPreferences(this,
405                 //                      Call, Fullname, OutFont);
406                         } else if (arg.equals("Connect")) {
407                                 parent.doconnect();
408                         } else if (arg.equals("Disconnect")) {
409                                 parent.dodisconnect();
410                         } else if (arg.equals("About")) {
411                                 InfoDialog id = new InfoDialog(this, "About", 
412                                 "JAVA Spider Webclient 1.0\n\nModified by PA4AB, M0AZM and OZ1LQH\n" +
413                                 "\n" +
414                                 "January 2002\n" +
415                                 "Based on source of the CLX Client from DL6DBH" );
416                                 
417                          id.resize(500,300);
418                                 id.show();
419                         } else if (arg.equals("Copy")) {
420                                 getSelectedText();
421                         } else if (arg.equals("Paste")) {
422                                 input.insertText(CopyPaste,input.getSelectionStart());
423                         } else if (arg.equals("Bye")) {
424                                 if (Connected) out.println("bye");
425                         } else if (arg.equals("Help")) {
426                                 if (Connected) out.println("? all");
427                         } else if (arg.equals("Show Last DX")) {
428                                 if (Connected) out.println("sh/dx");
429                         } else if (arg.equals("Status")) {
430                                 if (Connected) out.println("sh/c");
431                         } else if (arg.equals("Show WWV")) {
432                                 if (Connected) out.println("sh/wwv");
433                         } else if (arg.equals("Show WCY")) {
434                                 if (Connected) out.println("sh/wcy");
435                         } else if (arg.equals("Show Beam Direction")) {
436                                 beam pp = new beam(this, Prefix, OutFont);
437                                 if ((Connected) && !(Prefix.equals(""))) out.println ("sh/heading " + Prefix );
438                         } else if (arg.equals("Search DX")) {
439                                 beam pp = new beam(this, Prefix, OutFont);
440                                 if ((Connected) && !(Prefix.equals(""))) out.println ("sh/dx " + Prefix );
441                         
442                         } else if (arg.equals("Search QSL Info")) {
443                                 beam pp = new beam(this, Prefix, OutFont);
444                                 if ((Connected) && !(Prefix.equals(""))) out.println ("sh/qsl " + Prefix );
445                          
446
447                         } else if (arg.equals("Search Address")) {
448                                 beam pp = new beam(this, Prefix, OutFont);
449                                 if ((Connected) && !(Prefix.equals(""))) out.println ("sh/qrz " + Prefix );
450                         
451
452                         } else if (arg.equals("Search QSL Manager")) {
453                                 beam pp = new beam(this, Prefix, OutFont);
454                                 if ((Connected) && !(Prefix.equals(""))) out.println ("sh/qsl " + Prefix );
455                         
456
457                         } else if (arg.equals("Search DXCC")) {
458                                 beam pp = new beam(this, Prefix, OutFont);
459                                 if ((Connected) && !(Prefix.equals(""))) out.println ("sh/pr " + Prefix );
460                         
461                         // button settings
462
463                         } else if (arg.equals("Set Beep")) {
464                                 if (Connected) out.println("set/beep");
465                         
466                         } else if (arg.equals("Set No Beep")) {
467                                 if (Connected) out.println("set/nobeep");
468                         
469                         } else if (arg.equals("Set QTH / City")) {
470                                 beam pp = new beam(this, Prefix, OutFont);
471                                 if ((Connected) && !(Prefix.equals(""))) out.println ("set/qth " + Prefix );
472                                 
473                         } else if (arg.equals("Set Name")) {
474                                 beam pp = new beam(this, Prefix, OutFont);
475                                 if ((Connected) && !(Prefix.equals(""))) out.println ("set/name " + Prefix );
476                         
477                         } else if (arg.equals("Set Locator")) {
478                                 beam pp = new beam(this, Prefix, OutFont);
479                                 if ((Connected) && !(Prefix.equals(""))) out.println ("set/qra " + Prefix );
480                         
481                         } else if (arg.equals("Set HomeNode")) {
482                                 beam pp = new beam(this, Prefix, OutFont);
483                                 if ((Connected) && !(Prefix.equals(""))) out.println ("set/homenode " + Prefix );
484
485                         } else if (arg.equals("Set DX-Grid")) {
486                                 if (Connected) out.println("set/dxgrid");
487                         
488                         } else if (arg.equals("Set No DX-Grid")) {
489                                 if (Connected) out.println("set/nodxgrid");
490                         
491                         } else if (arg.equals("Show Personal Settings")) {
492                                 if (Connected) out.println ("sh/sta " + Call );
493                         }
494
495                         // dx announce
496
497                         else if (arg.equals("DXannounce")) {
498                                 dxannounce pp = new dxannounce(this, Call2, Freq, Remarks, OutFont);
499                                 if ((Connected) && !(Call2.equals(""))) out.println ("dx " + Freq + " " + Call2 + " " + Remarks );
500                         }
501                         
502                         // mailbox
503                         
504                          else if (arg.equals("Last 10 Msgs")) {
505                                 if (Connected) out.println ("dir" );
506                         } else if (arg.equals("Last 50 Msgs")) {
507                                 if (Connected) out.println ("dir/50" );
508                         } else if (arg.equals("New Messages")) {
509                                 if (Connected) out.println ("dir/new" );
510                         } else if (arg.equals("Own Messages")) {
511                                 if (Connected) out.println ("dir/own" );
512                         }                       
513                         else return false;
514                 }
515                 else if (evt.target instanceof Button) {
516                         if (arg.equals("Connect")) {
517                                 if (!Connected) {
518                                         parent.doconnect();
519                                 } else return false;
520                         } else if (arg.equals("Disconnect")) {
521                                 if (Connected) {
522                                         parent.dodisconnect();
523                                 } else return false;
524                         }
525                         else return false;
526                 }
527                 return true;
528         }
529
530         private idleTime idle;
531
532         private TextArea input;
533         private TextArea output;
534         private MenuBar menubar;
535         private Menu file;
536         private Menu edit;
537         private Menu settings;
538         private Menu colors;
539         private Menu fonts;
540         private Menu commands;
541         private Menu show;
542         private Menu set;
543         private Menu dxann;
544         private Menu mailbox;
545
546
547         private MenuItem connect_menuitem = new MenuItem("Connect");
548         private MenuItem copy_menuitem = new MenuItem("Copy");
549         private MenuItem paste_menuitem = new MenuItem("Paste");
550
551         private Button connectButton = new java.awt.Button("Connect");
552         private Button disconnectButton = new java.awt.Button("Disconnect");
553
554         private Date today = new Date();
555         private Label DateLabel = new Label(today.toLocaleString());
556         private Label IdleLabel = new Label("00:00");
557         private Label connectState = new Label("not connected");
558         
559  
560         private Color OutBackgroundColor = Color.black;
561         private Color OutForegroundColor = Color.yellow;
562         private Color OutOwnColor = Color.red;
563         private Color InBackgroundColor = new Color(234,199,135);
564         private Color InForegroundColor = Color.red;
565         
566         private Font OutFont = new Font("Courier", Font.PLAIN, 13);
567         private Font InFont = new Font("Courier", Font.BOLD, 13);
568         
569         private String Call = new String("NOCALL");
570         private String Password = new String();
571         private String Fullname = new String("NOBODY");
572         private String Hostname = new String("localhost");
573         private String Port = new String("3600");
574         private String Channel = new String("0");
575         private String Nodecall = new String("nodecall");
576
577         private String Prefix = new String ("");        
578         private String Call2 = new String ("");        
579         private String Freq = new String ("");        
580         private String Remarks = new String ("");        
581
582
583         private PrintStream out = null;
584         
585         private String InputBuffer[] = new String[256];
586         private int InputPos = 0;
587         private int MaxInputPos = 0;
588         
589         private String CopyPaste; 
590         
591         private boolean Connected;
592         
593         private spiderclient parent;
594 }
595
596 class setDate extends Thread {
597
598         spiderframe cf;
599         
600         public setDate(spiderframe cf) {
601                 this.cf = cf;
602                 this.start();
603         }
604
605         public void run() {
606                 for(;;) {
607                         try { sleep(1000); } catch (InterruptedException e) {}
608                         today = new Date();
609                         cf.setTime(today.toLocaleString());
610                 }
611         }
612         private Date today = new Date();
613 }
614
615 class idleTime extends Thread {
616
617         spiderframe cf;
618         int count;
619         
620         public idleTime(spiderframe cf) {
621                 this.cf = cf;
622                 this.start();
623                 count = 0;
624         }
625
626         public void resetTimer() {
627                 count=0;
628         }
629
630         public void run() {
631                 for(;;) {
632                         try { sleep(1000); } catch (InterruptedException e) {}
633                         count++;
634                         String sec = new Format("%02d").form(count % 60);
635                         String min = new Format("%02d").form(count / 60);
636                         cf.setIdle("Idle: "+min+":"+sec);
637                 }
638         }
639 }