-
Notifications
You must be signed in to change notification settings - Fork 1
/
OrbitViewer.java
1500 lines (1358 loc) · 44 KB
/
OrbitViewer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Orbit Projector
*
* Example (Comet)
*
* <APPLET CODE="OrbitViewer" WIDTH=510 HEIGHT=400>
* <PARAM NAME="Name" VALUE="1P/Halley">
* <PARAM NAME="T" VALUE="19860209.7695">
* <PARAM NAME="e" VALUE="0.967267">
* <PARAM NAME="q" VALUE="0.587096">
* <PARAM NAME="Peri" VALUE="111.8466">
* <PARAM NAME="Node" VALUE=" 58.1440">
* <PARAM NAME="Incl" VALUE="162.2393">
* <PARAM NAME="Eqnx" VALUE="1950.0">
* </APPLET>
*
* Example (Minor Planet)
*
* <APPLET CODE="OrbitViewer" WIDTH=510 HEIGHT=400>
* <PARAM NAME="Name" VALUE="Ceres(1)">
* <PARAM NAME="Epoch" VALUE="19991118.5">
* <PARAM NAME="M" VALUE="356.648434">
* <PARAM NAME="e" VALUE="0.07831587">
* <PARAM NAME="a" VALUE="2.76631592">
* <PARAM NAME="Peri" VALUE=" 73.917708">
* <PARAM NAME="Node" VALUE=" 80.495123">
* <PARAM NAME="Incl" VALUE=" 10.583393">
* <PARAM NAME="Eqnx" VALUE="2000.0">
* </APPLET>
*
* Optional paramter "Date" specifies initial date to display.
* If "Date" parameter omitted, it start with current date.
*
* <PARAM NAME="Date" VALUE="19860209.7695">
*
*/
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.math.*;
import astro.*;
/**
* Main Applet Class
*/
public class OrbitViewer extends java.applet.Applet {
/**
* Components
*/
private Scrollbar scrollHorz;
private Scrollbar scrollVert;
private Scrollbar scrollZoom;
private OrbitCanvas orbitCanvas;
private Button buttonDate;
private Button buttonRevPlay;
private Button buttonRevStep;
private Button buttonStop;
private Button buttonForStep;
private Button buttonForPlay;
private Choice choiceTimeStep;
private Choice choiceCenterObject;
private Choice choiceOrbitObject;
private Checkbox checkPlanetName;
private Checkbox checkObjectName;
private Checkbox checkDistanceLabel;
private Checkbox checkDateLabel;
private DateDialog dateDialog = null;
/**
* Player thread
*/
private OrbitPlayer orbitPlayer;
Thread playerThread = null;
/**
* Current Time Setting
*/
private ATime atime;
/**
* Time step
*/
static final int timeStepCount = 8;
static final String timeStepLabel[] = {
"1 Hour",
"1 Day", "3 Days", "10 Days",
"1 Month", "3 Months", "6 Months",
"1 Year"
};
static final TimeSpan timeStepSpan[] = {
new TimeSpan(0, 0, 0, 1, 0, 0.0),
new TimeSpan(0, 0, 1, 0, 0, 0.0),
new TimeSpan(0, 0, 3, 0, 0, 0.0),
new TimeSpan(0, 0, 10, 0, 0, 0.0),
new TimeSpan(0, 1, 0, 0, 0, 0.0),
new TimeSpan(0, 3, 0, 0, 0, 0.0),
new TimeSpan(0, 6, 0, 0, 0, 0.0),
new TimeSpan(1, 0, 0, 0, 0, 0.0),
};
public TimeSpan timeStep = timeStepSpan[1];
public int playDirection = ATime.F_INCTIME;
/**
* Centered Object
*/
static final int CenterObjectCount = 11;
static final String CenterObjectLabel[] = {
"Sun", "Asteroid/Comet", "Mercury", "Venus", "Earth",
"Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
};
public int CenterObjectSelected = 0;
/**
* Orbits Displayed
*/
static final int OrbitDisplayCount = 14;
static final String OrbitDisplayLabel[] = {
"Default Orbits", "All Orbits", "No Orbits", "------",
"Asteroid/Comet", "Mercury", "Venus", "Earth",
"Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
};
public int OrbitCount = 11;
public boolean OrbitDisplay[] = {false, true, true, true, true, true, true,
false, false, false, false };
public boolean OrbitDisplayDefault[] = {false, true, true, true, true, true, true,
false, false, false, false };
/**
* Limit of ATime
*/
// private ATime minATime = new ATime(-30000,1,1,0,0,0.0,0.0);
private ATime minATime = new ATime( 1600,1,1,0,0,0.0,0.0);
private ATime maxATime = new ATime( 2200,1,1,0,0,0.0,0.0);
/**
* Initial Settings
*/
static final int initialScrollVert = 90+40;
static final int initialScrollHorz = 255;
static final int initialScrollZoom = 67;
static final int fontSize = 16;
/**
* Applet information
*/
public String getAppletInfo() {
return "OrbitViewer v1.3 Copyright(C) 1996-2001 by O.Ajiki/R.Baalke";
}
/**
* Parameter Information
*/
public String[][] getParameterInfo() {
String info[][] = {
{ "Name",
"String", "Name of the object ex. 1P/Halley" },
{ "T",
"double", "Time of perihelion passage ex. 19860209.7695" },
{ "e",
"double", "Eccentricity ex. 0.967267" },
{ "q",
"double", "Perihelion distance AU ex. 0.587096" },
{ "Peri",
"double", "Argument of perihelion deg. ex. 111.8466" },
{ "Node",
"double", "Ascending node deg. ex. 58.1440" },
{ "Incl",
"double", "Inclination deg. ex. 162.2393" },
{ "Eqnx",
"double", "Year of equinox ex. 1950.0" },
{ "Epoch",
"double", "Year/Month/Day of epoch ex. 19991118.5" },
{ "M",
"double", "Mean anomaly deg. ex. 356.648434" },
{ "a",
"double", "Semimajor axis AU ex. 2.76631592" },
{ "Date",
"double", "Initial date ex. 19860209.7695" },
};
return info;
}
/**
* Convert time in format "YYYYMMDD.D" to ATime
*/
private ATime ymdStringToAtime(String strYmd) {
double fYmd = Double.valueOf(strYmd).doubleValue();
int nYear = (int)Math.floor(fYmd / 10000.0);
fYmd -= (double)nYear * 10000.0;
int nMonth = (int)Math.floor(fYmd / 100.0);
double fDay = fYmd - (double)nMonth * 100.0;
return new ATime(nYear, nMonth, fDay, 0.0);
}
/**
* Get required double parameter
*/
private double getRequiredParameter(String strName) {
String strValue = getParameter(strName);
if (strValue == null) {
throw new Error("Required parameter '"
+ strName + "' not found.");
}
return Double.valueOf(strValue).doubleValue();
}
/**
* Get orbital elements of the object from applet parameter
*/
private Comet getObject() {
String strName = getParameter("Name");
if (strName == null) {
strName = "Object";
}
double e, q;
ATime T;
String strParam;
if ((strParam = getParameter("e")) == null) {
throw new Error("required parameter 'e' not found.");
}
e = Double.valueOf(strParam).doubleValue();
if ((strParam = getParameter("T")) != null) {
T = ymdStringToAtime(strParam);
if ((strParam = getParameter("q")) != null) {
q = Double.valueOf(strParam).doubleValue();
} else if ((strParam = getParameter("a")) != null) {
double a = Double.valueOf(strParam).doubleValue();
if (Math.abs(e - 1.0) < 1.0e-15) {
throw new Error("Orbit is parabolic, but 'q' not found.");
}
q = a * (1.0 - e);
} else {
throw new Error("Required parameter 'q' or 'a' not found.");
}
} else if ((strParam = getParameter("Epoch")) != null) {
ATime Epoch = ymdStringToAtime(strParam);
if (e > 0.95) {
throw new
Error("Orbit is nearly parabolic, but 'T' not found.");
}
double a;
if ((strParam = getParameter("a")) != null) {
a = Double.valueOf(strParam).doubleValue();
q = a * (1.0 - e);
} else if ((strParam = getParameter("q")) != null) {
q = Double.valueOf(strParam).doubleValue();
a = q / (1.0 - e);
} else {
throw new Error("Required parameter 'q' or 'a' not found.");
}
if (q < 1.0e-15) {
throw new Error("Too small perihelion distance.");
}
double n = Astro.GAUSS / (a * Math.sqrt(a));
if ((strParam = getParameter("M")) == null) {
throw new Error("Required parameter 'M' not found.");
}
double M = Double.valueOf(strParam).doubleValue()
* Math.PI / 180.0;
if (M < Math.PI) {
T = new ATime(Epoch.getJd() - M / n, 0.0);
} else {
T = new ATime(Epoch.getJd() + (Math.PI*2.0 - M) / n, 0.0);
}
} else {
throw new Error("Required parameter 'T' or 'Epoch' not found.");
}
return new Comet(strName, T.getJd(), e, q,
getRequiredParameter("Peri")*Math.PI/180.0,
getRequiredParameter("Node")*Math.PI/180.0,
getRequiredParameter("Incl")*Math.PI/180.0,
getRequiredParameter("Eqnx"));
}
/**
* Limit ATime between minATime and maxATime
*/
private ATime limitATime(ATime atime) {
if (atime.getJd() <= minATime.getJd()) {
return new ATime(minATime);
} else if (maxATime.getJd() <= atime.getJd()) {
return new ATime(maxATime);
}
return atime;
}
/**
* Set date and redraw canvas
*/
private void setNewDate() {
this.atime = limitATime(this.atime);
orbitCanvas.setDate(this.atime);
orbitCanvas.repaint();
}
/**
* OrbitPlayer interface
*/
public ATime getAtime() {
return atime;
}
public void setNewDate(ATime atime) {
this.atime = limitATime(atime);
orbitCanvas.setDate(this.atime);
orbitCanvas.repaint();
}
/**
* Initialization of applet
*/
public void init() {
this.setBackground(Color.white);
//
// Main Panel
//
Panel mainPanel = new Panel();
GridBagLayout gblMainPanel = new GridBagLayout();
GridBagConstraints gbcMainPanel = new GridBagConstraints();
gbcMainPanel.fill = GridBagConstraints.BOTH;
mainPanel.setLayout(gblMainPanel);
// Orbit Canvas
Comet object = getObject();
String strParam;
if ((strParam = getParameter("Date")) != null) {
this.atime = ymdStringToAtime(strParam);
} else {
Date date = new Date();
this.atime = new ATime(date.getYear() + 1900, date.getMonth() + 1,
(double)date.getDate(), 0.0);
}
orbitCanvas = new OrbitCanvas(object, this.atime);
gbcMainPanel.weightx = 1.0;
gbcMainPanel.weighty = 1.0;
gbcMainPanel.gridwidth = GridBagConstraints.RELATIVE;
gblMainPanel.setConstraints(orbitCanvas, gbcMainPanel);
mainPanel.add(orbitCanvas);
// Vertical Scrollbar
scrollVert = new Scrollbar(Scrollbar.VERTICAL,
initialScrollVert, 12, 0, 180+12);
gbcMainPanel.weightx = 0.0;
gbcMainPanel.weighty = 0.0;
gbcMainPanel.gridwidth = GridBagConstraints.REMAINDER;
gblMainPanel.setConstraints(scrollVert, gbcMainPanel);
mainPanel.add(scrollVert);
orbitCanvas.setRotateVert(180 - scrollVert.getValue());
// Horizontal Scrollbar
scrollHorz = new Scrollbar(Scrollbar.HORIZONTAL,
initialScrollHorz, 15, 0, 360+15);
gbcMainPanel.weightx = 1.0;
gbcMainPanel.weighty = 0.0;
gbcMainPanel.gridwidth = 1;
gblMainPanel.setConstraints(scrollHorz, gbcMainPanel);
mainPanel.add(scrollHorz);
orbitCanvas.setRotateHorz(270 - scrollHorz.getValue());
// Right-Bottom Corner Rectangle
Panel cornerPanel = new Panel();
gbcMainPanel.weightx = 0.0;
gbcMainPanel.weighty = 0.0;
gbcMainPanel.gridwidth = GridBagConstraints.REMAINDER;
gblMainPanel.setConstraints(cornerPanel, gbcMainPanel);
mainPanel.add(cornerPanel);
//
// Control Panel
//
Panel ctrlPanel = new Panel();
GridBagLayout gblCtrlPanel = new GridBagLayout();
GridBagConstraints gbcCtrlPanel = new GridBagConstraints();
gbcCtrlPanel.fill = GridBagConstraints.BOTH;
ctrlPanel.setLayout(gblCtrlPanel);
ctrlPanel.setBackground(Color.white);
// Set Date Button
buttonDate = new Button(" Date ");
buttonDate.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 0;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 1.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 2;
gbcCtrlPanel.insets = new Insets(0, 0, 0, 12);
gblCtrlPanel.setConstraints(buttonDate, gbcCtrlPanel);
ctrlPanel.add(buttonDate);
// Reverse-Play Button
buttonRevPlay = new Button("<<");
buttonRevPlay.setFont(new Font("Dialog", Font.BOLD, fontSize-2));
gbcCtrlPanel.gridx = 1;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 3, 0);
gblCtrlPanel.setConstraints(buttonRevPlay, gbcCtrlPanel);
ctrlPanel.add(buttonRevPlay);
// Reverse-Step Button
buttonRevStep = new Button("|<");
buttonRevStep.setFont(new Font("Dialog", Font.BOLD, fontSize-2));
gbcCtrlPanel.gridx = 2;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 3, 0);
gblCtrlPanel.setConstraints(buttonRevStep, gbcCtrlPanel);
ctrlPanel.add(buttonRevStep);
// Stop Button
buttonStop = new Button("||");
buttonStop.setFont(new Font("Dialog", Font.BOLD, fontSize-2));
gbcCtrlPanel.gridx = 3;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 3, 0);
gblCtrlPanel.setConstraints(buttonStop, gbcCtrlPanel);
ctrlPanel.add(buttonStop);
// Step Button
buttonForStep = new Button(">|");
buttonForStep.setFont(new Font("Dialog", Font.BOLD, fontSize-2));
gbcCtrlPanel.gridx = 4;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 3, 0);
gblCtrlPanel.setConstraints(buttonForStep, gbcCtrlPanel);
ctrlPanel.add(buttonForStep);
// Play Button
buttonForPlay = new Button(">>");
buttonForPlay.setFont(new Font("Dialog", Font.BOLD, fontSize-2));
gbcCtrlPanel.gridx = 5;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 3, 0);
gblCtrlPanel.setConstraints(buttonForPlay, gbcCtrlPanel);
ctrlPanel.add(buttonForPlay);
// Step choice box
choiceTimeStep = new Choice();
choiceTimeStep.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 1;
gbcCtrlPanel.gridy = 1;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 5;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 0, 0);
gblCtrlPanel.setConstraints(choiceTimeStep, gbcCtrlPanel);
ctrlPanel.add(choiceTimeStep);
for (int i = 0; i < timeStepCount; i++) {
choiceTimeStep.addItem(timeStepLabel[i]);
choiceTimeStep.select(timeStepLabel[1]);
}
// Center Object Label
Label centerLabel = new Label("Center:");
centerLabel.setAlignment(Label.LEFT);
centerLabel.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 0;
gbcCtrlPanel.gridy = 2;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 1.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 0, 0);
gblCtrlPanel.setConstraints(centerLabel, gbcCtrlPanel);
ctrlPanel.add(centerLabel);
// Center Object choice box
choiceCenterObject = new Choice();
choiceCenterObject.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 1;
gbcCtrlPanel.gridy = 2;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 5;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 0, 0);
gblCtrlPanel.setConstraints(choiceCenterObject, gbcCtrlPanel);
ctrlPanel.add(choiceCenterObject);
for (int i = 0; i < CenterObjectCount; i++) {
choiceCenterObject.addItem(CenterObjectLabel[i]);
}
orbitCanvas.SelectCenterObject(0);
// Display Orbits Label
Label orbitLabel = new Label("Orbits:");
orbitLabel.setAlignment(Label.LEFT);
orbitLabel.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 0;
gbcCtrlPanel.gridy = 3;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 1.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 0, 0);
gblCtrlPanel.setConstraints(orbitLabel, gbcCtrlPanel);
ctrlPanel.add(orbitLabel);
// Display Orbit choice box
choiceOrbitObject = new Choice();
choiceOrbitObject.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 1;
gbcCtrlPanel.gridy = 3;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 5;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 0, 0, 0);
gblCtrlPanel.setConstraints(choiceOrbitObject, gbcCtrlPanel);
ctrlPanel.add(choiceOrbitObject);
for (int i = 0; i < OrbitDisplayCount; i++) {
choiceOrbitObject.addItem(OrbitDisplayLabel[i]);
}
for (int i = 0; i < OrbitCount; i++) {
OrbitDisplay[i] = OrbitDisplayDefault[i];
}
orbitCanvas.SelectOrbits(OrbitDisplay, OrbitCount);
// Date Label Checkbox
checkDateLabel = new Checkbox("Date Label");
checkDateLabel.setState(true);
checkDateLabel.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 6;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 12, 0, 0);
gblCtrlPanel.setConstraints(checkDateLabel, gbcCtrlPanel);
ctrlPanel.add(checkDateLabel);
orbitCanvas.switchPlanetName(checkDateLabel.getState());
// Planet Name Checkbox
checkPlanetName = new Checkbox("Planet Labels");
checkPlanetName.setState(true);
checkPlanetName.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 7;
gbcCtrlPanel.gridy = 0;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 12, 0, 0);
gblCtrlPanel.setConstraints(checkPlanetName, gbcCtrlPanel);
ctrlPanel.add(checkPlanetName);
orbitCanvas.switchPlanetName(checkPlanetName.getState());
// Distance Label Checkbox
checkDistanceLabel = new Checkbox("Distance");
checkDistanceLabel.setState(true);
checkDistanceLabel.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 6;
gbcCtrlPanel.gridy = 1;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 12, 0, 0);
gblCtrlPanel.setConstraints(checkDistanceLabel, gbcCtrlPanel);
ctrlPanel.add(checkDistanceLabel);
orbitCanvas.switchPlanetName(checkDistanceLabel.getState());
// Object Name Checkbox
checkObjectName = new Checkbox("Object Label");
checkObjectName.setState(true);
checkObjectName.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 7;
gbcCtrlPanel.gridy = 1;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 0.0;
gbcCtrlPanel.gridwidth = 1;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 12, 0, 0);
gblCtrlPanel.setConstraints(checkObjectName, gbcCtrlPanel);
ctrlPanel.add(checkObjectName);
orbitCanvas.switchObjectName(checkObjectName.getState());
// Zoom Label
Label zoomLabel = new Label("Zoom:");
zoomLabel.setAlignment(Label.LEFT);
zoomLabel.setFont(new Font("Dialog", Font.PLAIN, fontSize));
gbcCtrlPanel.gridx = 6;
gbcCtrlPanel.gridy = 2;
gbcCtrlPanel.weightx = 0.0;
gbcCtrlPanel.weighty = 1.0;
gbcCtrlPanel.gridwidth = 2;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(10, 12, 0, 0);
gblCtrlPanel.setConstraints(zoomLabel, gbcCtrlPanel);
ctrlPanel.add(zoomLabel);
// Zoom Scrollbar
scrollZoom = new Scrollbar(Scrollbar.HORIZONTAL,
initialScrollZoom, 15, 5, 450);
gbcCtrlPanel.gridx = 6;
gbcCtrlPanel.gridy = 3;
gbcCtrlPanel.weightx = 1.0;
gbcCtrlPanel.weighty = 1.0;
gbcCtrlPanel.gridwidth = 2;
gbcCtrlPanel.gridheight = 1;
gbcCtrlPanel.insets = new Insets(0, 12, 6, 2);
gblCtrlPanel.setConstraints(scrollZoom, gbcCtrlPanel);
ctrlPanel.add(scrollZoom);
orbitCanvas.setZoom(scrollZoom.getValue());
//
// Applet Layout
//
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
setLayout(gbl);
gbc.fill = GridBagConstraints.BOTH;
// Main Panel
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints(mainPanel, gbc);
add(mainPanel);
// Control Panel
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridheight = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(6, 0, 0, 0);
gbl.setConstraints(ctrlPanel, gbc);
add(ctrlPanel);
// Player Thread
orbitPlayer = new OrbitPlayer(this);
playerThread = null;
}
/**
* Override Function start()
*/
public void start() {
// if you want, you can initialize date here
}
/**
* Override Function stop()
*/
public void stop() {
if (dateDialog != null) {
dateDialog.dispose();
endDateDialog(null);
}
if (playerThread != null) {
playerThread.stop();
playerThread = null;
buttonDate.enable();
}
}
/**
* Destroy the applet
*/
public void destroy() {
removeAll();
}
/**
* Event Handler
*/
public boolean handleEvent(Event evt) {
switch (evt.id) {
case Event.SCROLL_ABSOLUTE:
case Event.SCROLL_LINE_DOWN:
case Event.SCROLL_LINE_UP:
case Event.SCROLL_PAGE_UP:
case Event.SCROLL_PAGE_DOWN:
if (evt.target == scrollHorz) {
orbitCanvas.setRotateHorz(270 - scrollHorz.getValue());
} else if (evt.target == scrollVert) {
orbitCanvas.setRotateVert(180 - scrollVert.getValue());
} else if (evt.target == scrollZoom) {
orbitCanvas.setZoom(scrollZoom.getValue());
} else {
return false;
}
orbitCanvas.repaint();
return true;
case Event.ACTION_EVENT:
if (evt.target == buttonDate) { // Set Date
dateDialog = new DateDialog(this, atime);
buttonDate.disable();
return true;
} else if (evt.target == buttonForPlay) { // ForPlay
if (playerThread != null
&& playDirection != ATime.F_INCTIME) {
playerThread.stop();
playerThread = null;
}
if (playerThread == null) {
buttonDate.disable();
playDirection = ATime.F_INCTIME;
playerThread = new Thread(orbitPlayer);
playerThread.setPriority(Thread.MIN_PRIORITY);
playerThread.start();
}
} else if (evt.target == buttonRevPlay) { // RevPlay
if (playerThread != null
&& playDirection != ATime.F_DECTIME) {
playerThread.stop();
playerThread = null;
}
if (playerThread == null) {
buttonDate.disable();
playDirection = ATime.F_DECTIME;
playerThread = new Thread(orbitPlayer);
playerThread.setPriority(Thread.MIN_PRIORITY);
playerThread.start();
}
} else if (evt.target == buttonStop) { // Stop
if (playerThread != null) {
playerThread.stop();
playerThread = null;
buttonDate.enable();
}
} else if (evt.target == buttonForStep) { // +1 Step
atime.changeDate(timeStep, ATime.F_INCTIME);
setNewDate();
return true;
} else if (evt.target == buttonRevStep) { // -1 Step
atime.changeDate(timeStep, ATime.F_DECTIME);
setNewDate();
return true;
} else if (evt.target == checkPlanetName) { // Planet Name
orbitCanvas.switchPlanetName(checkPlanetName.getState());
orbitCanvas.repaint();
return true;
} else if (evt.target == checkObjectName) { // Object Name
orbitCanvas.switchObjectName(checkObjectName.getState());
orbitCanvas.repaint();
return true;
} else if (evt.target == checkDistanceLabel) { // Distance
orbitCanvas.switchDistanceLabel(checkDistanceLabel.getState());
orbitCanvas.repaint();
return true;
} else if (evt.target == checkDateLabel) { // Date
orbitCanvas.switchDateLabel(checkDateLabel.getState());
orbitCanvas.repaint();
return true;
} else if (evt.target == choiceTimeStep) { // Time Step
for (int i = 0; i < timeStepCount; i++) {
if ((String)evt.arg == timeStepLabel[i]) {
timeStep = timeStepSpan[i];
break;
}
}
} else if (evt.target == choiceCenterObject) { // Center Object
for (int i = 0; i < CenterObjectCount; i++) {
if ((String)evt.arg == CenterObjectLabel[i]) {
CenterObjectSelected = i;
orbitCanvas.SelectCenterObject(i);
orbitCanvas.repaint();
break;
}
}
} else if (evt.target == choiceOrbitObject) { // Orbit Display
for (int i = 0; i < OrbitDisplayCount; i++) {
if ((String)evt.arg == OrbitDisplayLabel[i]) {
if (i == 1) {
for (int j = 0; j < OrbitCount; j++) {
OrbitDisplay[j] = true;
}
}
else if (i == 2) {
for (int j = 0; j < OrbitCount; j++) {
OrbitDisplay[j] = false;
}
}
else if (i == 0) {
for (int j = 0; j < OrbitCount; j++) {
OrbitDisplay[j] = OrbitDisplayDefault[j];
}
}
else if (i > 3) {
if (OrbitDisplay[i-3]) {
OrbitDisplay[i-3] = false;
}
else {
OrbitDisplay[i-3] = true;
}
}
evt.arg = OrbitDisplayLabel[0];
orbitCanvas.SelectOrbits(OrbitDisplay, OrbitCount);
orbitCanvas.repaint();
break;
}
}
}
return false;
default:
return false;
}
}
/**
* message sent by DateDialog (when disposed)
*/
public void endDateDialog(ATime atime) {
dateDialog = null;
buttonDate.enable();
if (atime != null) {
this.atime = limitATime(atime);
orbitCanvas.setDate(atime);
orbitCanvas.repaint();
}
}
}
/**
* Player Class
*/
class OrbitPlayer implements Runnable {
OrbitViewer orbitViewer;
/**
* Constructor
*/
public OrbitPlayer(OrbitViewer orbitViewer) {
this.orbitViewer = orbitViewer;
}
/**
* Play forever
*/
public void run() {
while (true) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
ATime atime = orbitViewer.getAtime();
atime.changeDate(orbitViewer.timeStep, orbitViewer.playDirection);
orbitViewer.setNewDate(atime);
}
}
}
/**
* Orbit Canvas
*/
class OrbitCanvas extends Canvas {
/**
* Orbital Element (Initialized in Constructor)
*/
private Comet object;
/**
* Orbital Curve Class (Initialized in Constructor)
*/
private CometOrbit objectOrbit;
private PlanetOrbit planetOrbit[];
private double epochPlanetOrbit;
/**
* Date
*/
private ATime atime;
/**
* Position of the Object and Planets
*/
private Xyz objectPos;
private Xyz planetPos[];
private int CenterObjectSelected;
private boolean OrbitDisplay[];
/**
* Projection Parameters
*/
private double fRotateH = 0.0;
private double fRotateV = 0.0;
private double fZoom = 5.0;
/**
* Rotation Matrix
*/
private Matrix mtxToEcl;
private double epochToEcl;
private Matrix mtxRotate;
private int nX0, nY0; // Origin
/**
* Size of Canvas
*/
private Dimension sizeCanvas;
/**
* Colors
*/
private Color colorObjectOrbitUpper = new Color(0x00f5ff);
private Color colorObjectOrbitLower = new Color(0x0000ff);
private Color colorObject = new Color(0x00ffff);
private Color colorObjectName = new Color(0x00cccc);
private Color colorPlanetOrbitUpper = new Color(0xffffff);
private Color colorPlanetOrbitLower = new Color(0x808080);
private Color colorPlanet = new Color(0x00ff00);
private Color colorPlanetName = new Color(0x00aa00);
private Color colorSun = new Color(0xd04040);
private Color colorAxisPlus = new Color(0xffff00);
private Color colorAxisMinus = new Color(0x555500);
private Color colorInformation = new Color(0xffffff);
/**
* Fonts
*/
private Font fontObjectName = new Font("Helvetica", Font.BOLD, 14);
private Font fontPlanetName = new Font("Helvetica", Font.PLAIN, 14);
private Font fontInformation = new Font("Helvetica", Font.BOLD, 14);
/**
* off-screen Image
*/
Image offscreen;
/**
* Object Name Drawing Flag
*/
boolean bPlanetName;
boolean bObjectName;
boolean bDistanceLabel;
boolean bDateLabel;
/**
* Constructor
*/
public OrbitCanvas(Comet object, ATime atime) {
planetPos = new Xyz[9];
OrbitDisplay = new boolean[11];
this.object = object;
this.objectOrbit = new CometOrbit(object, 120);
this.planetOrbit = new PlanetOrbit[9];
updatePlanetOrbit(atime);
updateRotationMatrix(atime);
// Set Initial Date
this.atime = atime;
setDate(this.atime);
// no offscreen image
offscreen = null;
// no name labels
bPlanetName = false;
bObjectName = false;
bDistanceLabel = true;
bDateLabel = true;
repaint();
}
/**
* Make Planet Orbit
*/
private void updatePlanetOrbit(ATime atime) {
for (int i = Planet.MERCURY; i <= Planet.PLUTO; i++) {
this.planetOrbit[i - Planet.MERCURY]
= new PlanetOrbit(i, atime, 48);
}
this.epochPlanetOrbit = atime.getJd();
}
/**
* Rotation Matrix Equatorial(2000)->Ecliptic(DATE)
*/
private void updateRotationMatrix(ATime atime) {
Matrix mtxPrec = Matrix.PrecMatrix(Astro.JD2000, atime.getJd());
Matrix mtxEqt2Ecl = Matrix.RotateX(ATime.getEp(atime.getJd()));
this.mtxToEcl = mtxEqt2Ecl.Mul(mtxPrec);
this.epochToEcl = atime.getJd();
}