forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAnnotations.java
More file actions
1914 lines (1764 loc) · 94.4 KB
/
Annotations.java
File metadata and controls
1914 lines (1764 loc) · 94.4 KB
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
/*
* Copyright 2006-2009, 2017, 2020 United States Government, as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All rights reserved.
*
* The NASA World Wind Java (WWJ) platform is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* NASA World Wind Java (WWJ) also contains the following 3rd party Open Source
* software:
*
* Jackson Parser – Licensed under Apache 2.0
* GDAL – Licensed under MIT
* JOGL – Licensed under Berkeley Software Distribution (BSD)
* Gluegen – Licensed under Berkeley Software Distribution (BSD)
*
* A complete listing of 3rd Party software notices and licenses included in
* NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party
* notices and licenses PDF found in code directory.
*/
package gov.nasa.worldwindx.examples;
import gov.nasa.worldwind.*;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.layers.*;
import gov.nasa.worldwind.pick.*;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.util.*;
import gov.nasa.worldwindx.examples.util.PowerOfTwoPaddedImage;
import com.jogamp.opengl.*;
import com.jogamp.opengl.util.awt.TextRenderer;
import javax.swing.*;
import javax.swing.Box;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.URL;
/**
* Illustrates how to use a WorldWind <code>{@link Annotation}</code> to display on-screen information to the user in
* the form of a text label with an optional image. Annotations may be attached to a geographic position or a point on
* the screen. They provide support for multi-line text, simple HTML text markup, and many styling attributes such as
* font face, size and colors, background shape and background image.
*
* @author Patrick Murris
* @version $Id: Annotations.java 2109 2014-06-30 16:52:38Z tgaskins $
*/
public class Annotations extends ApplicationTemplate
{
@SuppressWarnings("unchecked")
private static class AppFrame extends ApplicationTemplate.AppFrame
{
// Above mean sea level globe annotation
private class AMSLGlobeAnnotation extends GlobeAnnotation
{
public AMSLGlobeAnnotation(String text, Position position)
{
super(text, position);
}
public Vec4 getAnnotationDrawPoint(DrawContext dc)
{
return dc.getGlobe().computePointFromPosition(this.getPosition().getLatitude(),
this.getPosition().getLongitude(),
this.getPosition().getElevation() * dc.getVerticalExaggeration());
}
}
private AnnotationLayer layer;
private Annotation currentAnnotation;
// Static
private final static PowerOfTwoPaddedImage IMAGE_WWJ_SPLASH =
PowerOfTwoPaddedImage.fromPath("images/400x230-splash-nww.png");
private final static PowerOfTwoPaddedImage IMAGE_NASA =
PowerOfTwoPaddedImage.fromPath("images/32x32-icon-nasa.png");
private final static PowerOfTwoPaddedImage IMAGE_EARTH =
PowerOfTwoPaddedImage.fromPath("images/32x32-icon-earth.png");
// UI components
private JTextArea inputTextArea;
private JCheckBox cbAdjustWidth;
private JSlider widthSlider, heightSlider;
private JSlider scaleSlider, opacitySlider, cornerRadiusSlider, borderWidthSlider, stippleFactorSlider;
private JComboBox cbFontName, cbFontStyle, cbFontSize, cbTextAlign, cbShape, cbLeader;
private JComboBox cbImage, cbImageRepeat, cbTextEffect;
private JSlider leaderGapWidthSlider;
private JSlider imageOpacitySlider, imageScaleSlider, imageOffsetXSlider, imageOffsetYSlider;
private JSlider offsetXSlider, offsetYSlider;
private JSlider distanceMinScaleSlider, distanceMaxScaleSlider, distanceMinOpacitySlider;
private JSlider highlightScaleSlider;
private JSpinner insetsTop, insetsRight, insetsBottom, insetsLeft;
private JButton btTextColor, btBackColor, btBorderColor;
private JComboBox cbTextColorAlpha, cbBackColorAlpha, cbBorderColorAlpha;
private JButton btApply, btRemove;
private boolean suspendUpdate = false;
private Color savedBorderColor;
private BufferedImage savedImage;
private Annotation lastPickedObject;
public AppFrame()
{
// Create example annotations
this.setupAnnotations();
// Add control panel
this.getControlPanel().add(makeControlPanel(), BorderLayout.SOUTH);
this.enableControlPanel(false);
// Add a select listener to select or highlight annotations on rollover
this.setupSelection();
}
private void setupAnnotations()
{
GlobeAnnotation ga;
// Create a renderable layer
RenderableLayer rl = new RenderableLayer();
rl.setName("Annotations (stand alone)");
insertBeforeCompass(this.getWwd(), rl);
// Add above ground level annotation with fixed height in real world
ga = new GlobeAnnotation("AGL Annotation\nElev 1000m", Position.fromDegrees(10, 25, 1000));
ga.setHeightInMeter(10e3); // ten kilometer hight
rl.addRenderable(ga);
// Add above mean sea level annotation with fixed height in real world
AMSLGlobeAnnotation amsla = new AMSLGlobeAnnotation("AMSL Annotation\nAlt 1000m",
Position.fromDegrees(10, 20, 1000));
amsla.setHeightInMeter(10e3); // ten kilometer hight
rl.addRenderable(amsla);
// Create an annotation with an image and some text below it
ga = this.makeTopImageBottomTextAnnotation(IMAGE_WWJ_SPLASH, "Text below image",
Position.fromDegrees(0, -40, 0));
rl.addRenderable(ga);
// Create an AnnotationLayer with lots of annotations
this.layer = new AnnotationLayer();
// Create default attributes
AnnotationAttributes defaultAttributes = new AnnotationAttributes();
defaultAttributes.setCornerRadius(10);
defaultAttributes.setInsets(new Insets(8, 8, 8, 8));
defaultAttributes.setBackgroundColor(new Color(0f, 0f, 0f, .5f));
defaultAttributes.setTextColor(Color.WHITE);
defaultAttributes.setDrawOffset(new Point(25, 25));
defaultAttributes.setDistanceMinScale(.5);
defaultAttributes.setDistanceMaxScale(2);
defaultAttributes.setDistanceMinOpacity(.5);
defaultAttributes.setLeaderGapWidth(14);
defaultAttributes.setDrawOffset(new Point(20, 40));
// Add some annotations to the layer
// NOTE: use unicode for annotation text
// Towns
AnnotationAttributes townAttr = new AnnotationAttributes();
townAttr.setDefaults(defaultAttributes);
townAttr.setFont(Font.decode("Arial-BOLD-12"));
layer.addAnnotation(new GlobeAnnotation("MONACO", Position.fromDegrees(43.7340, 7.4211, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("NICE", Position.fromDegrees(43.696, 7.27, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("ANTIBES", Position.fromDegrees(43.5810, 7.1248, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("CANNES", Position.fromDegrees(43.5536, 7.0171, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("GRASSE", Position.fromDegrees(43.6590, 6.9240, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("FREJUS", Position.fromDegrees(43.4326, 6.7356, 0), townAttr));
layer.addAnnotation(
new GlobeAnnotation("SAINTE MAXIME", Position.fromDegrees(43.3087, 6.6353, 0), townAttr));
layer.addAnnotation(
new GlobeAnnotation("SAINT TROPEZ", Position.fromDegrees(43.2710, 6.6386, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("TOULON", Position.fromDegrees(43.1264, 5.9126, 0), townAttr));
layer.addAnnotation(new GlobeAnnotation("MARSEILLE", Position.fromDegrees(43.2904, 5.3806, 0), townAttr));
layer.addAnnotation(
new GlobeAnnotation("AIX EN PROVENCE", Position.fromDegrees(43.5286, 5.4485, 0), townAttr));
// Special places
AnnotationAttributes spAttr = new AnnotationAttributes();
spAttr.setDefaults(defaultAttributes);
spAttr.setFont(Font.decode("Arial-BOLDITALIC-10"));
spAttr.setTextColor(Color.YELLOW);
layer.addAnnotation(new GlobeAnnotation("A\u00e9roport International\nNice C\u00f4te d'Azur",
Position.fromDegrees(43.6582, 7.2167, 0), spAttr));
layer.addAnnotation(new GlobeAnnotation("Sophia Antipolis",
Position.fromDegrees(43.6222, 7.0474, 0), spAttr));
// Geographical features - use a common default AnnotationAttributes object
AnnotationAttributes geoAttr = new AnnotationAttributes();
geoAttr.setDefaults(defaultAttributes);
geoAttr.setFrameShape(AVKey.SHAPE_NONE); // No frame
geoAttr.setFont(Font.decode("Arial-ITALIC-12"));
geoAttr.setTextColor(Color.GREEN);
geoAttr.setTextAlign(AVKey.CENTER);
geoAttr.setDrawOffset(new Point(0, 5)); // centered just above
geoAttr.setEffect(AVKey.TEXT_EFFECT_OUTLINE); // Black outline
geoAttr.setBackgroundColor(Color.BLACK);
layer.addAnnotation(new GlobeAnnotation("Mont Chauve\nFort militaire\nAlt: 853m",
Position.fromDegrees(43.7701, 7.2544, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Mont Agel\nFort militaire\nAlt: 1148m",
Position.fromDegrees(43.7704, 7.4203, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Cap Ferrat",
Position.fromDegrees(43.6820, 7.3290, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Gorges du Loup",
Position.fromDegrees(43.7351, 6.9988, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Cap d'Antibes",
Position.fromDegrees(43.5526, 7.1297, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Iles de L\u00e9rins",
Position.fromDegrees(43.5125, 7.0467, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Montagne du Cheiron\nAlt: 1778m",
Position.fromDegrees(43.8149, 6.9669, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Giens",
Position.fromDegrees(43.0394, 6.1384, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Iles de Porquerolles",
Position.fromDegrees(42.9974, 6.2147, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Ile du Levent",
Position.fromDegrees(43.0315, 6.4702, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Ile de Port Cros",
Position.fromDegrees(43.0045, 6.3959, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Montagne Sainte Victoire\nAlt: 1010m",
Position.fromDegrees(43.5319, 5.6120, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Sainte Baume\nAlt: 1147m",
Position.fromDegrees(43.3373, 5.8008, 0), geoAttr));
layer.addAnnotation(new GlobeAnnotation("Pic de l'Ours\nAlt: 496m",
Position.fromDegrees(43.4763, 6.9042, 0), geoAttr));
// Water bodies - ellipse shape and centered text
AnnotationAttributes waterAttr = new AnnotationAttributes();
waterAttr.setDefaults(defaultAttributes);
waterAttr.setFrameShape(AVKey.SHAPE_ELLIPSE);
waterAttr.setTextAlign(AVKey.CENTER);
waterAttr.setFont(Font.decode("Arial-ITALIC-12"));
waterAttr.setTextColor(Color.CYAN);
waterAttr.setInsets(new Insets(8, 12, 9, 12));
layer.addAnnotation(new GlobeAnnotation("Lac de Sainte Croix",
Position.fromDegrees(43.7720, 6.1879, 0), waterAttr));
layer.addAnnotation(new GlobeAnnotation("Lac de Castillon",
Position.fromDegrees(43.9008, 6.5348, 0), waterAttr));
layer.addAnnotation(new GlobeAnnotation("Lac de Serre Pon\u00e7on",
Position.fromDegrees(44.5081, 6.3242, 0), waterAttr));
// Longer text, custom colors and text align
ga = new GlobeAnnotation("Transition Permien-Trias\nDate: 251Ma \nPlus grand \u00e9pisode "
+ "d'extinction massive.",
Position.fromDegrees(44.0551, 7.1215, 0), Font.decode("Arial-ITALIC-12"), Color.DARK_GRAY);
ga.getAttributes().setTextAlign(AVKey.RIGHT);
ga.getAttributes().setBackgroundColor(new Color(.8f, .8f, .8f, .7f));
ga.getAttributes().setBorderColor(Color.BLACK);
layer.addAnnotation(ga);
// With HTML tags and background image no repeat
ga = new GlobeAnnotation("<p>\n<b><font color=\"#664400\">LA CLAPI\u00c8RE</font></b><br />\n<i>Alt: "
+ "1100-1700m</i>\n</p>\n<p>\n<b>Glissement de terrain majeur</b> dans la haute Tin\u00e9e, sur "
+ "un flanc du <a href=\"http://www.mercantour.eu\">Parc du Mercantour</a>, Alpes Maritimes.\n</p>\n"
+ "<p>\nRisque aggrav\u00e9 d'<b>inondation</b> du village de <i>Saint \u00c9tienne de Tin\u00e9e</i> "
+ "juste en amont.\n</p>",
Position.fromDegrees(44.2522, 6.9424, 0), Font.decode("Serif-PLAIN-14"), Color.DARK_GRAY);
ga.setMinActiveAltitude(10e3);
ga.setMaxActiveAltitude(1e6);
ga.getAttributes().setTextAlign(AVKey.RIGHT);
ga.getAttributes().setBackgroundColor(new Color(1f, 1f, 1f, .7f));
ga.getAttributes().setBorderColor(Color.BLACK);
ga.getAttributes().setSize(
new Dimension(220, 0)); // Preferred max width, no length limit (default max width is 160)
ga.getAttributes().setImageSource(IMAGE_EARTH.getPowerOfTwoImage());
ga.getAttributes().setImageRepeat(AVKey.REPEAT_NONE);
ga.getAttributes().setImageOpacity(.6);
ga.getAttributes().setImageScale(.7);
ga.getAttributes().setImageOffset(new Point(7, 7));
layer.addAnnotation(ga);
// With some border stippling, width and antialias
ga = new GlobeAnnotation("Latitude: 44.0 N\nLongitude: 7.0 W",
Position.fromDegrees(44.0000, 7.000, 0), Font.decode("Arial-ITALIC-12"), Color.DARK_GRAY);
ga.getAttributes().setTextAlign(AVKey.CENTER);
ga.getAttributes().setBackgroundColor(new Color(.9f, .9f, .8f, .7f));
ga.getAttributes().setBorderColor(Color.BLACK);
ga.getAttributes().setBorderWidth(2);
ga.getAttributes().setBorderStippleFactor(3);
layer.addAnnotation(ga);
// With background texture repeat Y
ga = new GlobeAnnotation("SAHARA DESERT\n\nThe Sahara is technically the world's second largest desert "
+ "after Antarctica.\n\nAt over 9,000,000 square kilometres (3,500,000 sq mi), it covers most parts "
+ "of northern Africa. ", Position.fromDegrees(22, 12, 0), Font.decode("Arial-BOLD-12"));
ga.getAttributes().setDefaults(defaultAttributes);
ga.getAttributes().setImageSource(IMAGE_NASA.getPowerOfTwoImage());
ga.getAttributes().setImageRepeat(AVKey.REPEAT_Y);
ga.getAttributes().setImageOpacity(.6);
ga.getAttributes().setImageScale(.7);
ga.getAttributes().setImageOffset(new Point(1, 1));
ga.getAttributes().setInsets(new Insets(6, 28, 6, 6));
layer.addAnnotation(ga);
// Splash screen with NPOT background texture
ga = new GlobeAnnotation("Java SDK", Position.fromDegrees(20, 0, 0), Font.decode("Arial-BOLD-14"));
ga.getAttributes().setTextAlign(AVKey.RIGHT);
ga.getAttributes().setImageSource(IMAGE_WWJ_SPLASH.getPowerOfTwoImage());
ga.getAttributes().setImageRepeat(AVKey.REPEAT_NONE);
ga.getAttributes().setImageScale(.5); // scale texture to half size
ga.getAttributes().setSize(new Dimension(200, 115)); // use this dimensions (half texture)
ga.getAttributes().setAdjustWidthToText(
AVKey.SIZE_FIXED); // use strict dimension - dont follow text width
ga.getAttributes().setCornerRadius(0);
layer.addAnnotation(ga);
// With background pattern and forced height
AnnotationAttributes patternAttr = new AnnotationAttributes();
patternAttr.setDefaults(defaultAttributes);
patternAttr.setFont(Font.decode("Arial-BOLD-16"));
patternAttr.setTextColor(Color.GRAY);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(10, 100, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_VLINEAR,
new Dimension(32, 128), 1f, Color.WHITE, new Color(0f, 0f, 0f, 0f))); // White to transparent
ga.getAttributes().setSize(new Dimension(200, 128)); // force height to 128
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(10, 110, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_VLINEAR,
new Dimension(32, 64), 1f, Color.LIGHT_GRAY, Color.WHITE)); // gray/white
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(10, 120, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_DIAGONAL_UP,
Color.YELLOW)); // yellow stripes
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(0, 100, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_HLINEAR,
new Dimension(256, 32), 1f, Color.WHITE, new Color(0f, 0f, 0f, 0f))); // White to transparent
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(0, 110, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_HLINEAR,
new Dimension(32, 64), 1f, Color.LIGHT_GRAY, Color.WHITE)); // gray/white
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(0, 120, 0), patternAttr);
ga.getAttributes().setImageSource(
PatternFactory.createPattern(PatternFactory.PATTERN_SQUARES, Color.YELLOW)); // yellow circles
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(-10, 100, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_HLINEAR,
new Dimension(16, 16), 1f, Color.BLACK, Color.WHITE)); // Black to white
ga.getAttributes().setImageRepeat(AVKey.REPEAT_Y);
ga.getAttributes().setBackgroundColor(Color.WHITE);
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(-10, 110, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_VLINEAR,
new Dimension(16, 16), 1f, Color.BLACK, Color.WHITE)); // Black to white
ga.getAttributes().setImageRepeat(AVKey.REPEAT_X);
ga.getAttributes().setBackgroundColor(Color.WHITE);
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(-10, 120, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_HVLINE,
.15f, Color.GREEN)); // green + lines
ga.getAttributes().setImageScale(.4);
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
// Shows pattern scale effect on circles pattern
for (int i = 1; i <= 10; i++)
{
ga = new GlobeAnnotation("Pattern scale:" + (float) i / 10,
Position.fromDegrees(-20, 97 + i * 3, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_CIRCLES,
(float) i / 10, Color.LIGHT_GRAY));
ga.getAttributes().setImageScale(.4);
ga.getAttributes().setSize(new Dimension(160, 60));
layer.addAnnotation(ga);
}
// Using a GlobeAnnotation subclass to override drawing
class SimpleGlobeAnnotation extends GlobeAnnotation
{
Font font = Font.decode("Arial-PLAIN-12");
public SimpleGlobeAnnotation(String text, Position position)
{
super(text, position);
}
protected void applyScreenTransform(DrawContext dc, int x, int y, int width, int height, double scale)
{
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
gl.glTranslated(x, y, 0);
gl.glScaled(scale, scale, 1);
}
protected void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
if (dc.isPickingMode())
return;
TextRenderer textRenderer = this.getTextRenderer(dc, this.font);
// Draw text centered just above the screen point - use annotation's colors
String text = getText().split("\n")[0]; // First line only
int textWidth = (int) textRenderer.getBounds(text).getWidth();
Color textColor = this.modulateColorOpacity(this.getAttributes().getTextColor(), opacity);
Color backColor = this.modulateColorOpacity(this.getAttributes().getBackgroundColor(), opacity);
textRenderer.begin3DRendering();
textRenderer.setColor(backColor);
textRenderer.draw(text, -textWidth / 2 + 1, 12 - 1); // Background 'shadow'
textRenderer.setColor(textColor);
textRenderer.draw(text, -textWidth / 2, 12); // Foreground text
textRenderer.end3DRendering();
// Draw little square around screen point - use annotation's color
Color borderColor = this.getAttributes().getBorderColor();
this.applyColor(dc, borderColor, opacity, false);
// Draw 3x3 shape from its bottom left corner
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
gl.glDisable(GL.GL_LINE_SMOOTH);
gl.glDisable(GL2.GL_LINE_STIPPLE);
gl.glLineWidth(1);
gl.glTranslated(-1, -1, 0);
FrameFactory.drawShape(dc, AVKey.SHAPE_RECTANGLE, 3, 3, GL.GL_LINE_STRIP, 0);
}
}
ga = new SimpleGlobeAnnotation("Mount Rainier\nAlt: 4392m", Position.fromDegrees(46.8534, -121.7609, 0));
layer.addAnnotation(ga);
ga = new SimpleGlobeAnnotation("Mount Adams\nAlt: 3742m", Position.fromDegrees(46.2018, -121.4931, 0));
layer.addAnnotation(ga);
ga = new SimpleGlobeAnnotation("Mount Saint Helens\nAlt: 4392m",
Position.fromDegrees(46.1991, -122.1882, 0));
layer.addAnnotation(ga);
// Using an anonymous subclass to change annotation text on the fly
ga = new GlobeAnnotation("DRAG ME!", Position.fromDegrees(42, -118, 0), Font.decode("Arial-BOLD-18"))
{
public void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
// if annotation has moved, set its text
if (getPosition().getLatitude().degrees != 42 || getPosition().getLongitude().degrees != -118)
setText(String.format("Lat %7.4f\u00B0\nLon %7.4f\u00B0", getPosition().getLatitude().degrees,
getPosition().getLongitude().degrees));
// Keep rendering
super.doDraw(dc, width, height, opacity, pickPosition);
}
};
layer.addAnnotation(ga);
// Using post drawing code in an anonymous subclass
ga = new GlobeAnnotation("Annotation with extra frames drawn by a render delegate.",
Position.fromDegrees(40, -116, 0), Font.decode("Serif-BOLD-18"), Color.DARK_GRAY)
{
public void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
// Let normal rendering happen
super.doDraw(dc, width, height, opacity, pickPosition);
java.awt.Rectangle insetBounds = this.computeInsetBounds(width, height);
java.awt.Rectangle freeBounds = this.computeFreeBounds(dc, width, height);
// Draw second light gray frame outside draw rectangle
// Refers to scaleFactor, alphaFactor, drawRectangle and freeRectangle which have been
// set during drawing.
this.applyColor(dc, Color.BLACK, 0.5 * opacity, true);
// Translate to draw area bottom left corner, 3 pixels outside
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
gl.glTranslated(insetBounds.x - 3, insetBounds.y - 3, 0);
FrameFactory.drawShape(dc, AVKey.SHAPE_RECTANGLE, insetBounds.width + 6,
insetBounds.height + 6, GL.GL_LINE_STRIP, 4);
// Draw another frame in the free space if any
if (freeBounds.height > 0)
{
gl.glTranslated(+3, +3, 0);
FrameFactory.drawShape(dc, AVKey.SHAPE_ELLIPSE, freeBounds.width,
freeBounds.height, GL.GL_TRIANGLE_FAN, 0);
}
}
};
ga.getAttributes().setTextAlign(AVKey.CENTER);
ga.getAttributes().setBackgroundColor(new Color(1f, 1f, 1f, .7f));
ga.getAttributes().setBorderColor(Color.BLACK);
ga.getAttributes().setSize(new Dimension(160, 200));
layer.addAnnotation(ga);
// Using a ScreenAnnotation
ScreenAnnotation sa = new ScreenAnnotation("Fixed position annotation", new Point(20, 50));
sa.getAttributes().setDefaults(defaultAttributes);
sa.getAttributes().setCornerRadius(0);
sa.getAttributes().setSize(new Dimension(200, 0));
sa.getAttributes().setAdjustWidthToText(AVKey.SIZE_FIXED); // use strict dimension width - 200
sa.getAttributes().setDrawOffset(new Point(100, 0)); // screen point is annotation bottom left corner
sa.getAttributes().setHighlightScale(1); // No highlighting either
layer.addAnnotation(sa);
makeRelativeAnnotations(layer);
// Add layer to the layer list and update the layer panel
insertBeforeCompass(this.getWwd(), layer);
}
public void makeRelativeAnnotations(AnnotationLayer layer)
{
AnnotationAttributes defaultAttributes = new AnnotationAttributes();
defaultAttributes.setBackgroundColor(new Color(0f, 0f, 0f, 0f));
defaultAttributes.setTextColor(Color.YELLOW);
defaultAttributes.setLeaderGapWidth(14);
defaultAttributes.setCornerRadius(0);
defaultAttributes.setSize(new Dimension(300, 0));
defaultAttributes.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT); // use strict dimension width - 200
defaultAttributes.setFont(Font.decode("Arial-BOLD-24"));
defaultAttributes.setBorderWidth(0);
defaultAttributes.setHighlightScale(1); // No highlighting either
defaultAttributes.setCornerRadius(0);
ScreenRelativeAnnotation lowerLeft = new ScreenRelativeAnnotation("Lower Left", .1, 0.01);
lowerLeft.setKeepFullyVisible(true);
lowerLeft.setXMargin(5);
lowerLeft.setYMargin(5);
lowerLeft.getAttributes().setDefaults(defaultAttributes);
ScreenRelativeAnnotation upperLeft = new ScreenRelativeAnnotation("Upper Left", 0.1, 0.99);
upperLeft.setKeepFullyVisible(true);
upperLeft.setXMargin(5);
upperLeft.setYMargin(5);
upperLeft.getAttributes().setDefaults(defaultAttributes);
ScreenRelativeAnnotation upperRight = new ScreenRelativeAnnotation("Upper Right", 0.99, 0.99);
upperRight.setKeepFullyVisible(true);
upperRight.setXMargin(5);
upperRight.setYMargin(5);
upperRight.getAttributes().setDefaults(defaultAttributes);
ScreenRelativeAnnotation lowerRight = new ScreenRelativeAnnotation("Lower Right", 0.99, 0.01);
lowerRight.setKeepFullyVisible(true);
lowerRight.setXMargin(5);
lowerRight.setYMargin(5);
lowerRight.getAttributes().setDefaults(defaultAttributes);
ScreenRelativeAnnotation center = new ScreenRelativeAnnotation("Center", 0.5, 0.5);
center.setKeepFullyVisible(true);
center.setXMargin(5);
center.setYMargin(5);
center.getAttributes().setDefaults(defaultAttributes);
layer.addAnnotation(lowerLeft);
layer.addAnnotation(upperLeft);
layer.addAnnotation(upperRight);
layer.addAnnotation(lowerRight);
layer.addAnnotation(center);
}
public GlobeAnnotation makeTopImageBottomTextAnnotation(PowerOfTwoPaddedImage image, String text,
Position position)
{
// Create annotation
GlobeAnnotation ga = new GlobeAnnotation(text, position);
int inset = 10; // pixels
ga.getAttributes().setInsets(new Insets(image.getOriginalHeight() + inset * 2, inset, inset, inset));
ga.getAttributes().setImageSource(image.getPowerOfTwoImage());
ga.getAttributes().setImageOffset(new Point(inset, inset));
ga.getAttributes().setImageRepeat(AVKey.REPEAT_NONE);
ga.getAttributes().setImageOpacity(1);
ga.getAttributes().setSize(new Dimension(image.getOriginalWidth() + inset * 2, 0));
ga.getAttributes().setAdjustWidthToText(AVKey.SIZE_FIXED);
ga.getAttributes().setBackgroundColor(Color.WHITE);
ga.getAttributes().setTextColor(Color.BLACK);
ga.getAttributes().setBorderColor(Color.BLACK);
return ga;
}
// --- Selection ---------------------------------------
private void setupSelection()
{
// Add a select listener to select or highlight annotations on rollover
this.getWwd().addSelectListener(new SelectListener()
{
private BasicDragger dragger = new BasicDragger(getWwd());
public void selected(SelectEvent event)
{
if (event.hasObjects() && event.getTopObject() instanceof Annotation)
{
// Handle cursor change on hyperlink
if (event.getTopPickedObject().getValue(AVKey.URL) != null)
((Component) getWwd()).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
else
((Component) getWwd()).setCursor(Cursor.getDefaultCursor());
}
// Select/unselect on left click on annotations
if (event.getEventAction().equals(SelectEvent.LEFT_CLICK))
{
if (event.hasObjects())
{
if (event.getTopObject() instanceof Annotation)
{
// Check for text or url
PickedObject po = event.getTopPickedObject();
if (po.getValue(AVKey.TEXT) != null)
{
System.out.println("Text: \"" + po.getValue(AVKey.TEXT) + "\" Hyperlink: "
+ po.getValue(AVKey.URL));
if (po.getValue(AVKey.URL) != null)
{
// Try to launch a browser with the clicked URL
try
{
BrowserOpener.browse(new URL((String) po.getValue(AVKey.URL)));
}
catch (Exception ignore)
{
}
}
if (AppFrame.this.currentAnnotation == event.getTopObject())
return;
}
// Left click on an annotation - select
if (AppFrame.this.currentAnnotation != null)
{
// Unselect current
//AppFrame.this.currentAnnotation.getAttributes().setHighlighted(false);
AppFrame.this.currentAnnotation.getAttributes().setBorderColor(
AppFrame.this.savedBorderColor);
}
if (AppFrame.this.currentAnnotation != event.getTopObject())
{
// Select new one if not current one already
AppFrame.this.currentAnnotation = (Annotation) event.getTopObject();
//AppFrame.this.currentAnnotation.getAttributes().setHighlighted(true);
AppFrame.this.savedBorderColor = AppFrame.this.currentAnnotation
.getAttributes().getBorderColor();
AppFrame.this.savedImage = AppFrame.this.currentAnnotation.getAttributes()
.getImageSource() instanceof BufferedImage ?
(BufferedImage) AppFrame.this.currentAnnotation.getAttributes().getImageSource()
: null;
AppFrame.this.currentAnnotation.getAttributes().setBorderColor(Color.YELLOW);
}
else
{
// Clear current annotation
AppFrame.this.currentAnnotation = null; // switch off
}
// Update control panel
AppFrame.this.updateControlPanel();
}
else
System.out.println("Left click on " + event.getTopObject());
}
}
// Highlight on rollover
else if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !this.dragger.isDragging())
{
AppFrame.this.highlight(event.getTopObject());
}
// Have drag events drag the selected object.
else if (event.getEventAction().equals(SelectEvent.DRAG_END)
|| event.getEventAction().equals(SelectEvent.DRAG))
{
if (event.hasObjects())
{
// If selected annotation delegate dragging computations to a dragger.
if (event.getTopObject() == AppFrame.this.currentAnnotation)
this.dragger.selected(event);
}
// We missed any roll-over events while dragging, so highlight any under the cursor now,
// or de-highlight the dragged shape if it's no longer under the cursor.
if (event.getEventAction().equals(SelectEvent.DRAG_END))
{
PickedObjectList pol = getWwd().getObjectsAtCurrentPosition();
if (pol != null)
{
AppFrame.this.highlight(pol.getTopObject());
AppFrame.this.getWwd().redraw();
}
}
}
}
});
}
private void highlight(Object o)
{
// Manage highlighting of Annotations.
if (this.lastPickedObject == o)
return; // same thing selected
// Turn off highlight if on.
if (this.lastPickedObject != null) // && this.lastPickedObject != this.currentAnnotation)
{
this.lastPickedObject.getAttributes().setHighlighted(false);
this.lastPickedObject = null;
}
// Turn on highlight if object selected.
if (o != null && o instanceof Annotation)
{
this.lastPickedObject = (Annotation) o;
this.lastPickedObject.getAttributes().setHighlighted(true);
}
}
// -- Control panel ---------------------------------------------------------------
private JPanel makeControlPanel()
{
//-- Annotation text area. ----------------------------------------------
this.inputTextArea = new JTextArea();
this.inputTextArea.setFont(new Font("Sans_Serif", Font.PLAIN, 16));
this.inputTextArea.setLineWrap(true);
this.inputTextArea.setWrapStyleWord(true);
JScrollPane textScrollPane = new JScrollPane(this.inputTextArea);
textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
textScrollPane.setPreferredSize(new Dimension(200, 100));
textScrollPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
//-- Width panel --------------------------------------------------------
JPanel sizePanel = new JPanel(new GridLayout(0, 1, 0, 0));
sizePanel.setBorder(
new CompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), new TitledBorder("Width and Height")));
this.widthSlider = new JSlider(JSlider.HORIZONTAL, 0, 800, 160);
this.widthSlider.setMajorTickSpacing(100);
this.widthSlider.setMinorTickSpacing(10);
//this.widthSlider.setPaintTicks(true);
this.widthSlider.setPaintLabels(true);
this.widthSlider.setToolTipText("Preferred annotation width");
this.widthSlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
sizePanel.add(this.widthSlider);
this.heightSlider = new JSlider(JSlider.HORIZONTAL, 0, 800, 0);
this.heightSlider.setMajorTickSpacing(100);
this.heightSlider.setMinorTickSpacing(10);
//this.widthSlider.setPaintTicks(true);
this.heightSlider.setPaintLabels(true);
this.heightSlider.setToolTipText("Preferred annotation height, zero = no limit");
this.heightSlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
sizePanel.add(this.heightSlider);
//-- Corner radius panel ----------------------------------------------------
JPanel cornerRadiusPanel = new JPanel();
cornerRadiusPanel.setLayout(new BoxLayout(cornerRadiusPanel, BoxLayout.X_AXIS));
cornerRadiusPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
cornerRadiusPanel.add(new JLabel("Corner radius:"));
cornerRadiusPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.cornerRadiusSlider = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);
this.cornerRadiusSlider.setMajorTickSpacing(10);
this.cornerRadiusSlider.setMinorTickSpacing(1);
//this.cornerRadiusSlider.setPaintTicks(true);
this.cornerRadiusSlider.setPaintLabels(true);
this.cornerRadiusSlider.setToolTipText("Rounded corners radius");
this.cornerRadiusSlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
cornerRadiusPanel.add(this.cornerRadiusSlider);
//-- Insets panel ----------------------------------------------------
JPanel insetsPanel = new JPanel();
insetsPanel.setLayout(new BoxLayout(insetsPanel, BoxLayout.X_AXIS));
insetsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
insetsPanel.add(new JLabel("Insets:"));
insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.insetsTop = new JSpinner();
this.insetsTop.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
this.insetsRight = new JSpinner();
this.insetsRight.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
this.insetsBottom = new JSpinner();
this.insetsBottom.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
this.insetsLeft = new JSpinner();
this.insetsLeft.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
insetsPanel.add(this.insetsTop);
insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
insetsPanel.add(this.insetsRight);
insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
insetsPanel.add(this.insetsBottom);
insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
insetsPanel.add(this.insetsLeft);
//-- Border width panel ----------------------------------------------------
JPanel borderWidthPanel = new JPanel();
borderWidthPanel.setLayout(new BoxLayout(borderWidthPanel, BoxLayout.X_AXIS));
borderWidthPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
borderWidthPanel.add(new JLabel("Border width:"));
borderWidthPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.borderWidthSlider = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);
this.borderWidthSlider.setMajorTickSpacing(10);
this.borderWidthSlider.setMinorTickSpacing(1);
//this.borderWidthSlider.setPaintTicks(true);
this.borderWidthSlider.setPaintLabels(true);
this.borderWidthSlider.setToolTipText("Border width 1/10th");
this.borderWidthSlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
borderWidthPanel.add(this.borderWidthSlider);
//-- Stipple factor panel ----------------------------------------------------
JPanel stippleFactorPanel = new JPanel();
stippleFactorPanel.setLayout(new BoxLayout(stippleFactorPanel, BoxLayout.X_AXIS));
stippleFactorPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
stippleFactorPanel.add(new JLabel("Stipple factor:"));
stippleFactorPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.stippleFactorSlider = new JSlider(JSlider.HORIZONTAL, 0, 10, 0);
this.stippleFactorSlider.setMajorTickSpacing(1);
this.stippleFactorSlider.setPaintLabels(true);
this.stippleFactorSlider.setToolTipText("Border line pattern repeat factor");
this.stippleFactorSlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
stippleFactorPanel.add(this.stippleFactorSlider);
//-- Scale and opacity panel ----------------------------------------------------
JPanel scalePanel = new JPanel(new GridLayout(0, 1, 0, 0));
scalePanel.setBorder(
new CompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), new TitledBorder("Scale and Opacity")));
this.scaleSlider = new JSlider(JSlider.HORIZONTAL, 0, 30, 10);
this.scaleSlider.setMajorTickSpacing(10);
this.scaleSlider.setMinorTickSpacing(1);
//this.scaleSlider.setPaintTicks(true);
this.scaleSlider.setPaintLabels(true);
this.scaleSlider.setToolTipText("Annotation scaling");
this.scaleSlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
scalePanel.add(this.scaleSlider);
this.opacitySlider = new JSlider(JSlider.HORIZONTAL, 0, 10, 10);
this.opacitySlider.setMajorTickSpacing(1);
//this.opacitySlider.setMinorTickSpacing(1);
//this.opacitySlider.setPaintTicks(true);
this.opacitySlider.setPaintLabels(true);
this.opacitySlider.setToolTipText("Annotation opacity");
this.opacitySlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
scalePanel.add(this.opacitySlider);
// -- Font --------------------------------------------------------------
JPanel fontPanel = new JPanel();
fontPanel.setLayout(new BoxLayout(fontPanel, BoxLayout.X_AXIS));
fontPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
fontPanel.add(new JLabel("Font"));
fontPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.cbFontName = new JComboBox(new String[] {"Arial", "SansSerif", "Serif", "Courier", "Times",
"Helvetica", "Trebuchet", "Tahoma"});
this.cbFontName.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
fontPanel.add(this.cbFontName);
fontPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.cbFontStyle = new JComboBox(new String[] {"Plain", "Bold", "Italic", "BoldItalic"});
this.cbFontStyle.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
fontPanel.add(this.cbFontStyle);
fontPanel.add(Box.createRigidArea(new Dimension(10, 0)));
this.cbFontSize = new JComboBox(new String[] {"10", "12", "14", "16", "18", "20", "24", "28", "34",
"48", "64"});
this.cbFontSize.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
if (currentAnnotation != null)
{
updateAnnotation();
}
}
});
fontPanel.add(this.cbFontSize);
//fontPanel.add(Box.createRigidArea(new Dimension(10, 0)));
// -- Text align panel -------------------------------------------------------
final JPanel alignPanel = new JPanel(new GridLayout(0, 3, 5, 5));
alignPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
alignPanel.add(new JLabel("Align & Effect:"));
this.cbTextAlign = new JComboBox(new String[] {"Left", "Center", "Right"});
this.cbTextAlign.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
if (currentAnnotation != null)
{
updateAnnotation();
}