-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayerForm.java
1023 lines (873 loc) · 41 KB
/
LayerForm.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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on 10-nov-2009, 2.07.17
*/
package freimapgsoc;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JSlider;
import javax.swing.event.MouseInputAdapter;
import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.jdesktop.swingx.mapviewer.TileFactory;
import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
import org.jdesktop.swingx.mapviewer.Waypoint;
import org.jdesktop.swingx.mapviewer.WaypointPainter;
import org.jdesktop.swingx.painter.CompoundPainter;
import org.jdesktop.swingx.painter.Painter;
/**
*
* @author stefanopilla
*/
public class LayerForm extends javax.swing.JFrame implements DataSource {
/** Creates new form NewJFrame */
public LayerForm() {
//public TileFactoryInfo(int minimumZoomLevel,int maximumZoomLevel,int totalMapZoom,int tileSize,boolean xr2l,boolean yt2b,String baseURL,String xparam,String yparam,String zparam)(
TileFactoryInfo info = new TileFactoryInfo(0, maxzoomlevel, totalmapzoom, 256, false, false, "http://tile.openstreetmap.org", "x", "y", "z") {
public String getTileUrl(int x, int y, int zoom) {
zoom = maxzoomlevel - zoom;
return this.baseURL + "/" + zoom + "/" + x + "/" + y + ".png";
}
};
//In a future: possibilty to change this with settings menu parameters; now is in Italy Rome
tf = new DefaultTileFactory(info);
initComponents();
initMapComponents();
printDateTime();
}
public LayerForm(Layer l1) {
this.l = l1;
//public TileFactoryInfo(int minimumZoomLevel,int maximumZoomLevel,int totalMapZoom,int tileSize,boolean xr2l,boolean yt2b,String baseURL,String xparam,String yparam,String zparam)(
TileFactoryInfo info = new TileFactoryInfo(0, maxzoomlevel, totalmapzoom, 256, false, false, "http://tile.openstreetmap.org", "x", "y", "z") {
public String getTileUrl(int x, int y, int zoom) {
zoom = maxzoomlevel - zoom;
return this.baseURL + "/" + zoom + "/" + x + "/" + y + ".png";
}
};
//In a future: possibilty to change this with settings menu parameters; now is in Italy Rome
tf = new DefaultTileFactory(info);
System.out.println("Now Initialing Components....");
initComponents();
System.out.println("Now Initialing MAP Components....");
initMapComponents();
System.out.println("Now PRINT DATE....");
printDateTime();
layercount++;
initData(l1);
System.out.println();
System.out.println(l1.currentDs.getNodeList().size());
}
public void initData(Layer l1) {
for (int i = 0; i < l1.currentDs.getNodeList().size(); i++) {
System.out.println("node name:" + l1.currentDs.getNodeList().elementAt(i));
listOfNodes.addItem(l1.currentDs.getNodeList().elementAt(i));
}
for (int i = 0; i < l1.links.size(); i++) {
System.out.println("____________________________");
System.out.println("LINK FROM: " + l1.links.get(i).source.ip + "TO: " + l1.links.get(i).dest.ip);
System.out.println("HNA:" + l1.links.get(i).HNA);
System.out.println("ETX:" + l1.links.get(i).etx);
System.out.println("LQ:" + l1.links.get(i).lq);
System.out.println("NLQ:" + l1.links.get(i).nlq);
System.out.println("TCP:" + l1.links.get(i).tcp);
System.out.println("UDP:" + l1.links.get(i).udp);
System.out.println("PACKETS:" + l1.links.get(i).packets);
System.out.println("ICMP:" + l1.links.get(i).icmp);
System.out.println("OTHER:" + l1.links.get(i).other);
System.out.println("SOURCE:" + l1.links.get(i).source.name);
System.out.println("DEST:" + l1.links.get(i).dest.name);
System.out.println("BYTES:" + l1.links.get(i).bytes);
}
for (int i = 0; i < l1.nodes.size(); i++) {
System.out.println("____________________");
System.out.println("ID:" + l1.nodes.get(i).name);
System.out.println("IP:" + l1.nodes.get(i).ip);
System.out.println("NAME:" + l1.nodes.get(i).name);
System.out.println("LAT:" + l1.nodes.get(i).lat);
System.out.println("LON:" + l1.nodes.get(i).lon);
}
}
public void printDateTime() {
Format formatter = new SimpleDateFormat("EEE, dd/MM/yyyy");
String today = formatter.format(new Date());
SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
Date now = new Date();
String strTime = sdfTime.format(now);
dateInfo.setText(today + " - " + strTime);
// dateInfo.setText("Today : " + today + " - " + strTime);
}
public void addNodeOnMap() {
//OPEN A DIALOG Where ask lat/lon and eventually icon for the new node!
}
public void findNode() {
new FindNode().setVisible(true);
}
public void goHere() {
new goHere(mainMap).setVisible(true);
}
public void showNodes() {
//Hide-Show All nodes on the map
}
public void showLatLon() {
if (ShowLatLon.isSelected()) {
latLonLabel.setVisible(false);
} else {
latLonLabel.setVisible(true);
}
}
public void showZoomButton() {
if (zoomButtonIn.isVisible()) {
zoomButtonIn.setVisible(false);
zoomButtonOut.setVisible(false);
} else {
zoomButtonIn.setVisible(true);
zoomButtonOut.setVisible(true);
}
}
public void showSlider() {
if (ShowZoomSlider.isSelected()) {
setZoomSliderVisible(true);
} else {
setZoomSliderVisible(false);
}
}
public void showMiniMap() {
if (miniMap.isVisible()) {
miniMap.setVisible(false);
} else {
miniMap.setVisible(true);
}
}
/**
* This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
* @return
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
mainMap = new org.jdesktop.swingx.JXMapViewer();
miniMap = new org.jdesktop.swingx.JXMapViewer();
zoomSlider = new javax.swing.JSlider();
zoomButtonIn = new javax.swing.JButton();
zoomButtonOut = new javax.swing.JButton();
listOfNodes = new javax.swing.JComboBox();
dateInfo = new javax.swing.JLabel();
leftPanel = new javax.swing.JPanel();
takescrshtButton = new javax.swing.JButton();
addNodeButton = new javax.swing.JButton();
latLonLabel = new javax.swing.JLabel();
xValue = new javax.swing.JLabel();
yValue = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
File = new javax.swing.JMenu();
OpenFile = new javax.swing.JMenu();
recentFileMenu = new javax.swing.JMenu();
jSeparator1 = new javax.swing.JSeparator();
jMenuItem3 = new javax.swing.JMenuItem();
jSeparator3 = new javax.swing.JSeparator();
Close = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
ShowMiniMap = new javax.swing.JCheckBoxMenuItem();
ShowNodes = new javax.swing.JCheckBoxMenuItem();
ShowLinks = new javax.swing.JCheckBoxMenuItem();
ShowZoomButton = new javax.swing.JCheckBoxMenuItem();
ShowZoomSlider = new javax.swing.JCheckBoxMenuItem();
ShowLatLon = new javax.swing.JCheckBoxMenuItem();
jSeparator2 = new javax.swing.JSeparator();
GoHere = new javax.swing.JMenuItem();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
mainMap.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
mainMap.setName("mainMap"); // NOI18N
mainMap.setTileFactory(tf
);
mainMap.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
mainMapMouseMoved(evt);
}
});
mainMap.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
miniMap.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
miniMap.setName("miniMap"); // NOI18N
miniMap.setTileFactory(tf);
javax.swing.GroupLayout miniMapLayout = new javax.swing.GroupLayout(miniMap);
miniMap.setLayout(miniMapLayout);
miniMapLayout.setHorizontalGroup(
miniMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
miniMapLayout.setVerticalGroup(
miniMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
mainMap.add(miniMap, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 300, -1, -1));
zoomSlider.setMaximum(14);
zoomSlider.setOrientation(javax.swing.JSlider.VERTICAL);
zoomSlider.setValue(13);
zoomSlider.setInverted(true);
zoomSlider.setName("zoomSlider"); // NOI18N
zoomSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
zoomSliderStateChanged(evt);
}
});
mainMap.add(zoomSlider, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 190, -1, -1));
zoomButtonIn.setText("+");
zoomButtonIn.setName("zoomButtonIn"); // NOI18N
zoomButtonIn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zoomButtonInActionPerformed(evt);
}
});
mainMap.add(zoomButtonIn, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 160, -1, -1));
zoomButtonOut.setText("-");
zoomButtonOut.setName("zoomButtonOut"); // NOI18N
zoomButtonOut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zoomButtonOutActionPerformed(evt);
}
});
mainMap.add(zoomButtonOut, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 380, -1, -1));
listOfNodes.setName("listOfNodes"); // NOI18N
dateInfo.setText(" ");
dateInfo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
dateInfo.setName("dateInfo"); // NOI18N
leftPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
leftPanel.setName("leftPanel"); // NOI18N
takescrshtButton.setText("Take ScreenShot");
takescrshtButton.setName("takescrshtButton"); // NOI18N
takescrshtButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
takescrshtButtonActionPerformed(evt);
}
});
addNodeButton.setText("Add Node");
addNodeButton.setName("addNodeButton"); // NOI18N
addNodeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addNodeButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
leftPanel.setLayout(leftPanelLayout);
leftPanelLayout.setHorizontalGroup(
leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(leftPanelLayout.createSequentialGroup()
.addGap(61, 61, 61)
.addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(addNodeButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(takescrshtButton, javax.swing.GroupLayout.Alignment.LEADING))
.addContainerGap(122, Short.MAX_VALUE))
);
leftPanelLayout.setVerticalGroup(
leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftPanelLayout.createSequentialGroup()
.addContainerGap(280, Short.MAX_VALUE)
.addComponent(addNodeButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(takescrshtButton)
.addGap(198, 198, 198))
);
latLonLabel.setFont(new java.awt.Font("Lucida Grande", 0, 10));
latLonLabel.setText(" ");
latLonLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
latLonLabel.setName("latLonLabel"); // NOI18N
xValue.setFont(new java.awt.Font("Lucida Grande", 0, 10));
xValue.setText(" ");
xValue.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
xValue.setName("xValue"); // NOI18N
yValue.setFont(new java.awt.Font("Lucida Grande", 0, 10));
yValue.setText(" ");
yValue.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
yValue.setName("yValue"); // NOI18N
jMenuBar1.setName("jMenuBar1"); // NOI18N
File.setText("File");
File.setFont(new java.awt.Font("Lucida Grande", 0, 12));
File.setName("File"); // NOI18N
OpenFile.setText("Open File");
OpenFile.setFont(new java.awt.Font("Lucida Grande", 0, 12));
OpenFile.setName("OpenFile"); // NOI18N
File.add(OpenFile);
recentFileMenu.setText("Open Recent Files");
recentFileMenu.setFont(new java.awt.Font("Lucida Grande", 0, 12));
recentFileMenu.setName("recentFileMenu"); // NOI18N
File.add(recentFileMenu);
jSeparator1.setName("jSeparator1"); // NOI18N
File.add(jSeparator1);
jMenuItem3.setFont(new java.awt.Font("Lucida Grande", 0, 12));
jMenuItem3.setText("Preferences");
jMenuItem3.setName("jMenuItem3"); // NOI18N
File.add(jMenuItem3);
jSeparator3.setName("jSeparator3"); // NOI18N
File.add(jSeparator3);
Close.setFont(new java.awt.Font("Lucida Grande", 0, 12));
Close.setText("Exit");
Close.setName("Close"); // NOI18N
Close.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseActionPerformed(evt);
}
});
File.add(Close);
jMenuBar1.add(File);
jMenu2.setText("Edit");
jMenu2.setFont(new java.awt.Font("Lucida Grande", 0, 12));
jMenu2.setName("jMenu2"); // NOI18N
ShowMiniMap.setFont(new java.awt.Font("Lucida Grande", 0, 12));
ShowMiniMap.setSelected(true);
ShowMiniMap.setText("Show MiniMap");
ShowMiniMap.setName("ShowMiniMap"); // NOI18N
jMenu2.add(ShowMiniMap);
ShowNodes.setFont(new java.awt.Font("Lucida Grande", 0, 12));
ShowNodes.setSelected(true);
ShowNodes.setText("Show Nodes");
ShowNodes.setName("ShowNodes"); // NOI18N
ShowNodes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ShowNodesActionPerformed(evt);
}
});
jMenu2.add(ShowNodes);
ShowLinks.setFont(new java.awt.Font("Lucida Grande", 0, 12));
ShowLinks.setSelected(true);
ShowLinks.setText("Show Links");
ShowLinks.setName("ShowLinks"); // NOI18N
jMenu2.add(ShowLinks);
ShowZoomButton.setFont(new java.awt.Font("Lucida Grande", 0, 12));
ShowZoomButton.setSelected(true);
ShowZoomButton.setText("Show Zoom Button");
ShowZoomButton.setName("ShowZoomButton"); // NOI18N
jMenu2.add(ShowZoomButton);
ShowZoomSlider.setFont(new java.awt.Font("Lucida Grande", 0, 12));
ShowZoomSlider.setSelected(true);
ShowZoomSlider.setText("Show Zoom Slider");
ShowZoomSlider.setName("ShowZoomSlider"); // NOI18N
jMenu2.add(ShowZoomSlider);
ShowLatLon.setFont(new java.awt.Font("Lucida Grande", 0, 12));
ShowLatLon.setSelected(true);
ShowLatLon.setText("Show Lat Lon Label");
ShowLatLon.setName("ShowLatLon"); // NOI18N
jMenu2.add(ShowLatLon);
jSeparator2.setName("jSeparator2"); // NOI18N
jMenu2.add(jSeparator2);
GoHere.setFont(new java.awt.Font("Lucida Grande", 0, 12));
GoHere.setText("Go Here");
GoHere.setName("GoHere"); // NOI18N
jMenu2.add(GoHere);
jMenuItem1.setFont(new java.awt.Font("Lucida Grande", 0, 12));
jMenuItem1.setText("Search");
jMenuItem1.setName("jMenuItem1"); // NOI18N
jMenu2.add(jMenuItem1);
jMenuBar1.add(jMenu2);
jMenu1.setText("About");
jMenu1.setFont(new java.awt.Font("Lucida Grande", 0, 12));
jMenu1.setName("jMenu1"); // NOI18N
jMenuItem2.setFont(new java.awt.Font("Lucida Grande", 0, 12));
jMenuItem2.setText("About Freimap");
jMenuItem2.setName("jMenuItem2"); // NOI18N
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(dateInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(14, 14, 14)
.addComponent(leftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(latLonLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(64, 64, 64)
.addComponent(xValue, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38)
.addComponent(yValue, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
.addComponent(listOfNodes, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(mainMap, javax.swing.GroupLayout.DEFAULT_SIZE, 852, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(listOfNodes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(latLonLabel)
.addComponent(xValue)
.addComponent(yValue)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mainMap, javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
.addComponent(leftPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(dateInfo)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void zoomButtonOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomButtonOutActionPerformed
setZoom(mainMap.getZoom() + 1);
}//GEN-LAST:event_zoomButtonOutActionPerformed
private void zoomButtonInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomButtonInActionPerformed
setZoom(mainMap.getZoom() - 1);
}//GEN-LAST:event_zoomButtonInActionPerformed
private void zoomSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_zoomSliderStateChanged
if (!zoomChanging) {
mainMap.setZoom(zoomSlider.getValue());
}
}//GEN-LAST:event_zoomSliderStateChanged
private void CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseActionPerformed
this.dispose();
}//GEN-LAST:event_CloseActionPerformed
private void ShowNodesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowNodesActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ShowNodesActionPerformed
private void takescrshtButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_takescrshtButtonActionPerformed
try {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Point p = new Point(mainMap.getLocationOnScreen());
Dimension d = new Dimension(mainMap.getSize());
Rectangle mapPosition = new Rectangle(p, d);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(mapPosition);
ImageIO.write(image, "jpg", new File("/tmp/freimapSnapShot.jpg"));
new InfoPopUp("Screenshot is in /tmp/ directory", "APPROVE").setVisible(true);
} catch (Exception e) {
log.append(e.getMessage());
}
}//GEN-LAST:event_takescrshtButtonActionPerformed
private void addNodeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNodeButtonActionPerformed
new addNode(l).setVisible(true);
initData(l);
}//GEN-LAST:event_addNodeButtonActionPerformed
private void mainMapMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mainMapMouseMoved
GeoPosition gp = mainMap.convertPointToGeoPosition(new Point2D.Double(evt.getX(), evt.getY()));
DecimalFormat fmt = new DecimalFormat("#00.00000");
latLonLabel.setText(fmt.format(gp.getLatitude()) + "/" + fmt.format(gp.getLongitude()));
xValue.setText(String.format("%.3f", mainMap.getTileFactory().geoToPixel(gp, mainMap.getZoom()).getX()));
yValue.setText(String.format("%.3f", mainMap.getTileFactory().geoToPixel(gp, mainMap.getZoom()).getY()));
}//GEN-LAST:event_mainMapMouseMoved
//MAP COMPONENTS
public void initMapComponents() {
mainMap.setCenterPosition(new GeoPosition(0, 0));
miniMap.setCenterPosition(new GeoPosition(0, 0));
mainMap.setRestrictOutsidePanning(true);
miniMap.setRestrictOutsidePanning(true);
Set<Waypoint> wps = new HashSet<Waypoint>();
WaypointPainter wp = new WaypointPainter();
wp.setWaypoints(wps);
mainMap.setOverlayPainter(new CompoundPainter(new Painter<JXMapViewer>() {
public void paint(Graphics2D g, JXMapViewer map, int width, int height) {
g.setPaint(Color.WHITE);
g.drawString(" ", 50, map.getHeight() - 10);
}
}, wp));
// adapter to move the minimap after the main map has moved
MouseInputAdapter ma = new MouseInputAdapter() {
public void mousePressed(MouseEvent evt) {
String nodeName = "";
Point pt = evt.getPoint();
GeoPosition gp = mainMap.convertPointToGeoPosition(new Point2D.Double(evt.getX(), evt.getY()));
//Se la posizione del mouse è uguale a una presente nel vettore latlon allora prendi il nome e visualizzalo
coor.add(String.format("%.2f", gp.getLatitude()));
coor.add(String.format("%.2f", gp.getLongitude()));
//System.out.println("latlon.get(coor): " + latlon.get(coor));
//System.out.println("evt.getPoint():" + evt.getPoint());
//System.out.println("pt:" + pt);
Point2D gp_pt = mainMap.getTileFactory().geoToPixel(gp, mainMap.getZoom());
Rectangle rect = mainMap.getViewportBounds();
Point converted_gp_pt = new Point((int) pt.getX() - rect.x, (int) pt.getY() - rect.y);
}
public void mouseReleased(MouseEvent e) {
miniMap.setCenterPosition(mapCenterPosition);
}
};
mainMap.addMouseMotionListener(ma);
mainMap.addMouseListener(ma);
mainMap.addPropertyChangeListener("center", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
Point2D mapCenter = (Point2D) evt.getNewValue();
TileFactory tf = mainMap.getTileFactory();
GeoPosition mapPos = tf.pixelToGeo(mapCenter, mainMap.getZoom());
miniMap.setCenterPosition(mapPos);
}
});
mainMap.addPropertyChangeListener("centerPosition", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
mapCenterPosition = (GeoPosition) evt.getNewValue();
miniMap.setCenterPosition(mapCenterPosition);
Point2D pt = miniMap.getTileFactory().geoToPixel(mapCenterPosition, miniMap.getZoom());
miniMap.setCenter(pt);
miniMap.repaint();
}
});
mainMap.addPropertyChangeListener("zoom", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
zoomSlider.setValue(mainMap.getZoom());
}
});
miniMap.setOverlayPainter(new Painter<JXMapViewer>() {
public void paint(Graphics2D g, JXMapViewer map, int width, int height) {
// get the viewport rect of the main map
Rectangle mainMapBounds = mainMap.getViewportBounds();
// convert to Point2Ds
Point2D upperLeft2D = mainMapBounds.getLocation();
Point2D lowerRight2D = new Point2D.Double(upperLeft2D.getX() + mainMapBounds.getWidth(),
upperLeft2D.getY() + mainMapBounds.getHeight());
// convert to GeoPostions
GeoPosition upperLeft = mainMap.getTileFactory().pixelToGeo(upperLeft2D, mainMap.getZoom());
GeoPosition lowerRight = mainMap.getTileFactory().pixelToGeo(lowerRight2D, mainMap.getZoom());
// convert to Point2Ds on the mini-map
upperLeft2D =
map.getTileFactory().geoToPixel(upperLeft, map.getZoom());
lowerRight2D =
map.getTileFactory().geoToPixel(lowerRight, map.getZoom());
g =
(Graphics2D) g.create();
Rectangle rect = map.getViewportBounds();
//p("rect = " + rect);
g.translate(-rect.x, -rect.y);
Point2D centerpos = map.getTileFactory().geoToPixel(mapCenterPosition, map.getZoom());
//p("center pos = " + centerpos);
g.setPaint(Color.RED);
//g.drawRect((int)centerpos.getX()-30,(int)centerpos.getY()-30,60,60);
g.drawRect((int) upperLeft2D.getX(), (int) upperLeft2D.getY(),
(int) (lowerRight2D.getX() - upperLeft2D.getX()),
(int) (lowerRight2D.getY() - upperLeft2D.getY()));
g.setPaint(new Color(255, 0, 0, 50));
g.fillRect((int) upperLeft2D.getX(), (int) upperLeft2D.getY(),
(int) (lowerRight2D.getX() - upperLeft2D.getX()),
(int) (lowerRight2D.getY() - upperLeft2D.getY()));
//g.drawOval((int)lowerRight2D.getX(),(int)lowerRight2D.getY(),1,1);
g.dispose();
}
});
setZoom(12);// HACK joshy: hack, i shouldn't need this here
this.setCenterPosition(new GeoPosition(0, 0));
}//OK
//END OF INITMAPCOMPONENTS()
//MAP METHODS ##################################
public void setZoom(int zoom) {
zoomChanging = true;
mainMap.setZoom(zoom);
miniMap.setZoom(mainMap.getZoom() + 4);
if (sliderReversed) {
zoomSlider.setValue(zoomSlider.getMaximum() - zoom);
} else {
zoomSlider.setValue(zoom);
mainMap.repaint();
}
zoomChanging = false;
} //OK
/**
* Indicates if the mini-map is currently visible
* @return the current value of the mini-map property
*/
public boolean isMiniMapVisible() {
return miniMapVisible;
}//OK
/**
* Sets if the mini-map should be visible
* @param miniMapVisible a new value for the miniMap property
*/
public void setMiniMapVisible(boolean miniMapVisible) {
boolean old = this.isMiniMapVisible();
this.miniMapVisible = miniMapVisible;
miniMap.setVisible(miniMapVisible);
}//OK
/**
* Indicates if the zoom slider is currently visible
* @return the current value of the zoomSliderVisible property
*/
public boolean isZoomSliderVisible() {
return zoomSliderVisible;
}//OK
/**
* Sets if the zoom slider should be visible
* @param zoomSliderVisible the new value of the zoomSliderVisible property
*/
public void setZoomSliderVisible(boolean zoomSliderVisible) {
boolean old = this.isZoomSliderVisible();
this.zoomSliderVisible = zoomSliderVisible;
zoomSlider.setVisible(zoomSliderVisible);
}//OK
/**
* Indicates if the zoom buttons are visible. This is a bound property
* and can be listed for using a PropertyChangeListener
* @return current value of the zoomButtonsVisible property
*/
public boolean isZoomButtonsVisible() {
return zoomButtonsVisible;
}//OK
/**
* Sets if the zoom buttons should be visible. This ia bound property.
* Changes can be listened for using a PropertyChaneListener
* @param zoomButtonsVisible new value of the zoomButtonsVisible property
*/
public void setZoomButtonsVisible(boolean zoomButtonsVisible) {
boolean old = this.isZoomButtonsVisible();
this.zoomButtonsVisible = zoomButtonsVisible;
//zoomInButton.setVisible(zoomButtonsVisible);
//zoomOutButton.setVisible(zoomButtonsVisible);
}//OK
/**
* Sets the tile factory for both embedded JXMapViewer components.
* Calling this method will also reset the center and zoom levels
* of both maps, as well as the bounds of the zoom slider.
* @param fact the new TileFactory
*/
public void setTileFactory(TileFactory fact) {
mainMap.setTileFactory(fact);
mainMap.setZoom(fact.getInfo().getDefaultZoomLevel());
mainMap.setCenterPosition(new GeoPosition(0, 0));
miniMap.setTileFactory(fact);
miniMap.setZoom(fact.getInfo().getDefaultZoomLevel() + 3);
miniMap.setCenterPosition(new GeoPosition(0, 0));
zoomSlider.setMinimum(fact.getInfo().getMinimumZoomLevel());
zoomSlider.setMaximum(fact.getInfo().getMaximumZoomLevel());
}//OK
public void setCenterPosition(GeoPosition pos) {
mainMap.setCenterPosition(pos);
miniMap.setCenterPosition(pos);
}//OK
/**
* Returns a reference to the main embedded JXMapViewer component
* @return the main map
*/
public JXMapViewer getMainMap() {
return this.mainMap;
}//OK
/**
* Returns a reference to the mini embedded JXMapViewer component
* @return the minimap JXMapViewer component
*/
public JXMapViewer getMiniMap() {
return this.miniMap;
}//OK
/**
* returns a reference to the zoom in button
* @return a jLabel
*/
public JButton getZoomInButton() {
return this.zoomButtonIn;
}//OK
/**
* returns a reference to the zoom out button
* @return a jLabel
*/
public JButton getZoomOutButton() {
return this.zoomButtonOut;
}//OK
/**
* returns a reference to the zoom slider
* @return a jslider
*/
public JSlider getZoomSlider() {
return this.zoomSlider;
}//OK
//Get String Latitude from the Map
private String getLat(GeoPosition pos) {
Double lat = pos.getLatitude();
return lat.toString();
}
//Get String Longitude from the Map
private String getLon(GeoPosition pos) {
Double lon = pos.getLatitude();
return lon.toString();
}
public void goToDefaultPosition() {
mainMap.setAddressLocation(def);
}
public void takeScreenShot() throws AWTException, IOException {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Point p = new Point(mainMap.getLocationOnScreen());
Dimension d = new Dimension(mainMap.getSize());
Rectangle mapPosition = new Rectangle(p, d);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(mapPosition);
ImageIO.write(image, "jpg", new File("/tmp/freimapSnapShot.jpg"));
//new InfoPopUp("Screenshot is in /tmp/ directory", "APPROVE").setVisible(true);
}
//END OF MAP METHODS################################
//MainMap and Minimap Variables
private GeoPosition def;//OK
private TileFactory tf; //OK
private boolean zoomChanging = false;//OK
private JLabel nodeLabel = new JLabel();
final List<GeoPosition> region = new ArrayList<GeoPosition>();
public static boolean miniMapVisible = true;//OK
public static boolean zoomSliderVisible = true;//OK
public static boolean zoomButtonsVisible = true;//OK
public static final boolean sliderReversed = false;//OK
private static WaypointPainter painter = new WaypointPainter();//OK
private static Set<Waypoint> waypoints = new HashSet<Waypoint>();//OK
private static WaypointPainter linkpainter = new WaypointPainter();//OK
private static Set<Waypoint> linkwaypoints = new HashSet<Waypoint>();//OK
private MapNode uplink = new MapNode("0.0.0.0/0.0.0.0");//OK
private Point2D mapCenter = new Point2D.Double(0, 0);//OK
private GeoPosition mapCenterPosition = new GeoPosition(0, 0);//OK
Vector coor = new Vector();
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LayerForm(new Layer(new LatLonJsDataSource("file:///var/run/latlon.js"))).setVisible(true);
}
});
}
public Vector<MapNode> getNodeList() {
throw new UnsupportedOperationException("Not supported yet.");
}
public Hashtable<String, Float> getNodeAvailability(long time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public long getFirstUpdateTime() {
throw new UnsupportedOperationException("Not supported yet.");
}
public long getLastUpdateTime() {
throw new UnsupportedOperationException("Not supported yet.");
}
public long getLastAvailableTime() {
throw new UnsupportedOperationException("Not supported yet.");
}
public long getFirstAvailableTime() {
throw new UnsupportedOperationException("Not supported yet.");
}
public long getClosestUpdateTime(long time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public MapNode getNodeByName(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
public MapNode getNodeById(String id) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Vector<Link> getLinks(long time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Vector<Link> getLinksFromSource(String id) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Vector<Link> getLinksFromDest(String id) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void addDataSourceListener(DataSourceListener dsl) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void getLinkProfile(Link link, LinkInfo info) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void getLinkCountProfile(MapNode node, NodeInfo info) {
throw new UnsupportedOperationException("Not supported yet.");
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem Close;
private javax.swing.JMenu File;
private javax.swing.JMenuItem GoHere;
private javax.swing.JMenu OpenFile;
private javax.swing.JCheckBoxMenuItem ShowLatLon;
private javax.swing.JCheckBoxMenuItem ShowLinks;
private javax.swing.JCheckBoxMenuItem ShowMiniMap;
private javax.swing.JCheckBoxMenuItem ShowNodes;
private javax.swing.JCheckBoxMenuItem ShowZoomButton;
private javax.swing.JCheckBoxMenuItem ShowZoomSlider;
private javax.swing.JButton addNodeButton;
private javax.swing.JLabel dateInfo;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JLabel latLonLabel;
private javax.swing.JPanel leftPanel;
private javax.swing.JComboBox listOfNodes;
private org.jdesktop.swingx.JXMapViewer mainMap;
private org.jdesktop.swingx.JXMapViewer miniMap;
private javax.swing.JMenu recentFileMenu;
private javax.swing.JButton takescrshtButton;
private javax.swing.JLabel xValue;
private javax.swing.JLabel yValue;
private javax.swing.JButton zoomButtonIn;
private javax.swing.JButton zoomButtonOut;
private javax.swing.JSlider zoomSlider;
// End of variables declaration//GEN-END:variables
private final int maxzoomlevel = 14;
private final int totalmapzoom = 14;
private Layer l;
private int layercount = 0;
private Vector<Layer> layers = new Vector<Layer>();
public static JMenuItem recentMenuItem;
public MapNode getNodeByIp(String ip) {