Repository navigation
Expand file tree
/
Copy pathTreeViewERDC.java
More file actions
2007 lines (1690 loc) · 62.9 KB
/
Copy pathTreeViewERDC.java
File metadata and controls
2007 lines (1690 loc) · 62.9 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 by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF Java Products. The full HDF Java copyright *
* notice, including terms governing use, modification, and redistribution, *
* is contained in the file, COPYING. COPYING can be found at the root of *
* the source code distribution tree. You can also access it online at *
* http://www.hdfgroup.org/products/licenses.html. If you do not have *
* access to the file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package ext.erdc;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.JViewport;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import ncsa.hdf.object.Attribute;
import ncsa.hdf.object.CompoundDS;
import ncsa.hdf.object.Dataset;
import ncsa.hdf.object.FileFormat;
import ncsa.hdf.object.Group;
import ncsa.hdf.object.HObject;
import ncsa.hdf.object.ScalarDS;
import ncsa.hdf.view.DataView;
import ncsa.hdf.view.HDFView;
import ncsa.hdf.view.ImageView;
import ncsa.hdf.view.MetaDataView;
import ncsa.hdf.view.Tools;
import ncsa.hdf.view.TreeView;
import ncsa.hdf.view.ViewManager;
import ncsa.hdf.view.ViewProperties;
import org.jgraph.JGraph;
import org.jgraph.graph.AttributeMap;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
public class TreeViewERDC extends JPanel
implements TreeView, ActionListener, MouseListener, MouseMotionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
private final static int CELL_W = 80;
private final static int CELL_H = (int)(CELL_W/1.618);
private final static int SPACE_X = 20; // cell distance
private final static int SPACE_Y = 150; // level distance
private final static String CLASS_ELLIPS = "ext.erdc.JGraphEllipseView";
private final static String CLASS_DIAMOND = "ext.erdc.JGraphDiamondView";
private final static String MIME_XLS = "excel";
private final static String MIME_PDF = "pdf";
private final static String MIME_HDF = "hdf";
private final static String MIME_AUDIO = "audio";
private final static String MIME_VIDEO = "video";
private final static String MIME_JPG = "jpeg";
private final static String MIME_TXT = "text/plain";
private final static String MIME_HTML = "html";
private final static String MIME_XML = "xml";
private final static String MIME_SW = "S/W";
private final static String BASE_MAP = "BASE_MAP";
private final static String ID_TABLE = "ID_TABLE";
private final static String FOOTPRINT = "FOOTPRINT";
private final static int N_TOOLBAR_ELMS = 4;
private final static HashMap<String, ImageIcon> iconMap = new HashMap<String, ImageIcon>(20);
private static enum OBJ_TYPE {LEVEL1, LEVEL2, LEVEL3,
AUDIO, VIDEO, JPG, PDF, XLS, HTML, SW, XML, TEXT, GROUP, DATASET};
private final static int DISPLAY_TABLE = 0;
private final static int DISPLAY_IMAGE = 1;
private static enum LINK_TYPE
{
HARD, SOFT, EXT, UD;
public Color getLineColor() {
switch (this) {
case HARD: return Color.RED;
case SOFT: return Color.BLUE;
case EXT: return Color.BLUE;
case UD: return Color.MAGENTA;
default: return Color.DARK_GRAY;
}
}
public boolean isLineDahsed() {
switch (this) {
case HARD: return false;
case SOFT: return false;
case EXT: return true;
case UD: return true;
default: return true;
}
}
public int getLineWidth() {
switch (this) {
case HARD: return 2;
case SOFT: return 1;
case EXT: return 1;
case UD: return 1;
default: return 1;
}
}
};
private static enum ICON_TYPE
{
APPS, AUDIO, FEED, GENERIC, GRP1, GRP2, GRP3, HELP, MULTIMEDIA,
PDF, URL, VIDEO, XLS, JPG;
public String getName() {
switch (this) {
case APPS: return "apps.gif";
case AUDIO: return "audio.gif";
case FEED: return "feed.gif";
case GENERIC: return "generic.gif";
case GRP1: return "grp1.gif";
case GRP2: return "grp2.gif";
case GRP3: return "grp3.gif";
case HELP: return "help.gif";
case MULTIMEDIA: return "multimedia.gif";
case PDF: return "pdf.gif";
case URL: return "url.gif";
case VIDEO: return "video.gif";
case XLS: return "xls.gif";
case JPG: return "image.gif";
default: return "apps.gif";
}
}
public ImageIcon getIcon() {
return iconMap.get(getName());
}
}
private final FileFormat h5format;
private final JGraph jgraph;
private final DefaultGraphModel jmodel;
private final GraphLayoutCache jview;
private final List<FileFormat> fileList;
private final Hashtable<String, DefaultGraphCell> createdAttrs;
private final Hashtable<String, DefaultGraphCell> createdObjs;
private final JPopupMenu popupMenuHDF, popupMenuExt;
private final PopupFactory popupFactory;
private final JTextArea infoArea;
private final JButton[] tbButtons;
/** GUI component: window to show the Users' Guide */
private final JFrame helpWindow;
/** GUI component: editorPane to show the Users' Guide */
private final JEditorPane helpEditorPane;
/** popup to show information of data objects */
private Popup infoPopup = null;
/** the width of the window */
private int gWidth = 500;
/** The current selected node. */
private DefaultMutableTreeNode selectedNode;
/** the current selected object */
private Object selectedObject;
/** the base image */
private HObject baseImage, bldgFootprint, idTable;
private FileFormat currentFile = null;
/** the owner of this treeview */
private ViewManager viewer;
/** hashmap that hold building information */
private HashMap idMap;
public TreeViewERDC(ViewManager theView)
{
viewer = theView;
h5format = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
fileList = new Vector<FileFormat>();
createdAttrs = new Hashtable<String, DefaultGraphCell>();
createdObjs = new Hashtable<String, DefaultGraphCell>();
popupMenuHDF = createPopupMenuHDF();
popupMenuExt = createPopupMenuExt();
baseImage = null;
idMap = null;
idTable = null;
popupFactory = PopupFactory.getSharedInstance();
// setup the Users guide window
helpWindow = new JFrame("ERDC Concept Map");
helpEditorPane = new JEditorPane();
loadIcons();
infoArea = new JTextArea();
//infoArea.setPreferredSize(new Dimension(220, 60));
infoArea.setEditable(false);
infoArea.setForeground(Color.BLUE.brighter());
//infoArea.setWrapStyleWord(true);
//infoArea.setLineWrap(true);
infoArea.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createRaisedBevelBorder(),
BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5,5,5,5))));
infoArea.setBackground(Color.LIGHT_GRAY);
tbButtons = new JButton[N_TOOLBAR_ELMS];
jmodel = new DefaultGraphModel();
jview = new GraphLayoutCache(jmodel, new GPCellViewFactory());
jgraph = new JGraph(jmodel, jview);
jgraph.setEditable(true);
jgraph.setEdgeLabelsMovable(false);
//jgraph.setMoveable(false);
jgraph.addMouseListener(this);
jgraph.addMouseMotionListener(this);
setLayout(new BorderLayout());
add(createToolBar(), BorderLayout.NORTH);
add(jgraph, BorderLayout.CENTER);
createHelpPane();
((JFrame)viewer).setTitle(
"AGC HDFView Prototype - Data Management with HDF5 for Military Operations");
}
private final static void loadIcons()
{
URL u = null;
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
ICON_TYPE[] iconTypes = ICON_TYPE.values();
for (int i=0; i<iconTypes.length; i++) {
String name = iconTypes[i].getName();
u = classLoader.getResource("ext/erdc/"+name);
if (u != null)
iconMap.put(name, new ImageIcon(u));
}
}
private JToolBar createToolBar()
{
JToolBar tbar = new JToolBar();
tbar.setFloatable(true);
// home button
JButton button = new JButton(ICON_TYPE.HELP.getIcon()) ;
tbar.add( button );
button.setToolTipText( "Help" );
button.addActionListener( this );
button.setActionCommand( "Show help" );
button.setMargin( new Insets( 0, 0, 0, 0 ) );
for (int i=0; i<9; i++)
tbar.addSeparator();
Icon[] tbIcons = new Icon[N_TOOLBAR_ELMS];
tbIcons[0] = ICON_TYPE.GRP1.getIcon();
tbIcons[1] = ICON_TYPE.GRP2.getIcon();
tbIcons[2] = ICON_TYPE.GRP3.getIcon();
tbIcons[3] = ICON_TYPE.MULTIMEDIA.getIcon();
String[] tips = new String[N_TOOLBAR_ELMS];
tips[0] = "Add leve 1 object";
tips[1] = "Add leve 2 object";
tips[2] = "Add leve 3 object";
tips[3] = "Add media";
for (int i=0; i<N_TOOLBAR_ELMS; i++) {
tbButtons[i] = new JButton(tbIcons[i]);
tbButtons[i].setBackground(Color.WHITE);
tbButtons[i].setBorder(BorderFactory.createLineBorder(Color.WHITE));
tbButtons[i].setActionCommand("Create object "+(i+1));
tbButtons[i].addActionListener(this);
tbButtons[i].setToolTipText(tips[i]);
tbButtons[i].setMargin( new Insets( 0, 0, 0, 0 ) );
tbar.add(tbButtons[i]);
if (i==2) {
tbar.addSeparator();
tbar.addSeparator();
}
}
return tbar;
}
/** creates a popup menu for a right mouse click on a data object */
private JPopupMenu createPopupMenuHDF()
{
JPopupMenu menu = new JPopupMenu();
JMenuItem item;
item = new JMenuItem( "Open As Table");
item.setMnemonic(KeyEvent.VK_T);
item.addActionListener(this);
item.setActionCommand("Open data as table");
menu.add(item);
item = new JMenuItem( "Open As Image");
item.setMnemonic(KeyEvent.VK_I);
item.addActionListener(this);
item.setActionCommand("Open data as image");
menu.add(item);
item = new JMenuItem( "Show Metadata");
item.setMnemonic(KeyEvent.VK_M);
item.addActionListener(this);
item.setActionCommand("Show metadata");
menu.add(item);
return menu;
}
private JPopupMenu createPopupMenuExt()
{
JPopupMenu menu = new JPopupMenu();
JMenuItem item;
item = new JMenuItem( "Open Object");
item.setMnemonic(KeyEvent.VK_L);
item.addActionListener(this);
item.setActionCommand("Open ext link");
menu.add(item);
return menu;
}
/**
* Creates a new cell.
* @param graph the graph
* @param parent the parent cell
* @param name the name of the cell
* @param x The x coordinate of the cell
* @param y The y coordinate of the cell
* @param w The width of the cell
* @param h The height of the cell
* @param bg The background color of the cell
* @param raised True for raised style; otherwise, false.
* @param icon The image icon of the cell
* @param isDashedEdge True if the edge is a dashed line; otherwise, false.
* @param viewClass The name of the view class
* @return the new cell;
*/
private DefaultGraphCell createCell(JGraph graph, DefaultGraphCell parent,
Object obj, final String name, double x, double y, double w,
double h, Color bg, boolean raised, ImageIcon icon,
LINK_TYPE linkType, String viewClass)
{
// Create vertex with the given name
DefaultGraphCell cell = null;
if (y<0) y = 0;
if (x<0) x = 0;
if (name == null || name.length()<=0) {
cell = new DefaultGraphCell(obj);
} else {
cell = new DefaultGraphCell(obj) { public String toString() { return name; } };
}
AttributeMap map = cell.getAttributes();
// set cell view
if (viewClass != null)
GPCellViewFactory.setViewClass(map, viewClass);
if (bg != null) {
GraphConstants.setGradientColor(cell.getAttributes(), bg);
GraphConstants.setOpaque(cell.getAttributes(), true);
}
// set icon
if (icon !=null) {
GraphConstants.setIcon(map, icon);
GraphConstants.setBounds(map, new Rectangle2D.Double(x, y, icon.getIconWidth(), h+20));
} else {
GraphConstants.setBounds(map, new Rectangle2D.Double(x, y, w, h));
if (raised)
GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder());
else
GraphConstants.setBorderColor(map, Color.black);
}
Font f = GraphConstants.getFont(map);
f = new Font(f.getName(), Font.BOLD, f.getSize());
GraphConstants.setFont(map, f);
// Add a Port
cell.addPort();
GraphLayoutCache gCache = graph.getGraphLayoutCache();
gCache.insert(cell);
if (parent != null) {
DefaultEdge edge = createEdge(parent, cell, linkType);
gCache.insert(edge);
}
return cell;
}
private DefaultEdge createEdge(DefaultGraphCell src, DefaultGraphCell dst,
LINK_TYPE linkType)
{
if (src == null || dst == null)
return null;
DefaultEdge edge = new DefaultEdge()
{
@Override
public String toString() {
return null; // do not show anything on the link
}
};
Object port = src.getFirstChild();
if (port != null)
edge.setSource(port);
port = dst.getFirstChild();
if (port != null)
edge.setTarget(port);
int arrow = GraphConstants.ARROW_CLASSIC;
AttributeMap map = edge.getAttributes();
GraphConstants.setLineEnd(map, arrow);
GraphConstants.setEndFill(map, true);
GraphConstants.setLineWidth(map, linkType.getLineWidth());
GraphConstants.setBendable(map, false);
GraphConstants.setDisconnectable(map, false);
GraphConstants.setLineColor(map, linkType.getLineColor());
if (linkType.isLineDahsed())
GraphConstants.setDashPattern(map, new float[] {4, 4});
// set link popup information
String relation = null;
switch (linkType) {
case HARD:
relation = dst + " is part of " +src + "\nH5G_LINK_HARD";
String dstName = dst.toString();
String srcName = src.toString();
if ("IPB".equals(dstName) && "MDMP".equals(srcName))
relation = dst + " is a path to " +src + "\nH5G_LINK_HARD";
else if ("IPB".equals(srcName) && "OCOKA".equals(dstName))
relation = dst + " is tagged to " +src + "\nH5G_LINK_HARD";
break;
case SOFT:
relation = dst + " is referenced to " +src+ "\nH5G_LINK_SOFT";
break;
case EXT:
relation = dst + " is a connection to " +src+ "\nH5G_LINK_EXT";
break;
case UD:
relation = dst + " is a component of " +src+ "\nH5G_LINK_UD";
break;
}
edge.setUserObject(relation);
return edge;
}
/**
* Create a cell for an attribute.
*
* @param obj The HObject
* @param graph
* @param parent
* @param x The x coordinate of the cell
* @param y The y coordinate of the cell
* @param w The width of the cell
* @param h The height of the cell
* @return the new cell
*/
private DefaultGraphCell createExtCell(HObject obj, JGraph graph,
DefaultGraphCell parent)
{
int nAttrs=0, nCells=0;
List attrs=null;
ImageIcon icon=null;
String uri, name="";
OBJ_TYPE objType;
DefaultGraphCell cell=null;
double x, y;
int w = CELL_W, h=CELL_H;
if (obj==null)
return null;
Rectangle2D bound = GraphConstants.getBounds(parent.getAttributes());
double x0 = bound.getX();
double y0 = bound.getY();
x=x0;
y=y0;
try {
attrs = obj.getMetadata();
} catch (Exception ex) { attrs = null; }
if (attrs == null || (nAttrs=attrs.size())<=0)
return null;
nCells=0;
for (int i=0; i<nAttrs; i++) {
Attribute attr = (Attribute)attrs.get(i);
String attrName = attr.getName();
if (attrName.startsWith("URI")) {
int idx = -1;
try { idx = Integer.parseInt(attrName.substring(3).trim()); }
catch (Exception ex) {idx = -1; }
objType = getObjType(obj, idx);
name = getMime(objType);
if (name != null) {
icon = getIcon(objType);
LINK_TYPE linkType = LINK_TYPE.SOFT;
if (objType == OBJ_TYPE.DATASET) {
String attrValue = ((String[])attr.getValue())[0];
int tmpIdx = attrValue.lastIndexOf('/');
name = attrValue.substring(tmpIdx+1);
name = getNickName(name);
x = x0+(nCells)*(SPACE_X+CELL_W);
y = y0+SPACE_Y;
if (x0 < gWidth/2)
x -= (SPACE_X+CELL_W/2);
else if (x0>gWidth/2)
x += (SPACE_X+CELL_W/3);
if (createdAttrs.containsKey(name)){
cell = createdAttrs.get(name);
jview.insert(createEdge(parent, cell, linkType));
} else {
cell = createCell(graph, parent, attr, name, x, y,
w+15, h, null, false, null, linkType, CLASS_ELLIPS);
createdAttrs.put(name, cell);
nCells++;
}
} // if (objType == OBJ_TYPE.HDF)
else {
x = x0 + CELL_W+1.5*SPACE_X;
if (x0+SPACE_X <= gWidth/2)
x = x0 - CELL_W;
y = y0 + SPACE_Y/3-1.5*SPACE_Y/nAttrs*(i-1);
linkType = LINK_TYPE.EXT;
if (MIME_XML.equalsIgnoreCase(name)) {
name = "feed";
linkType = LINK_TYPE.UD;
x += 30;
y -= 20;
}
else if (MIME_JPG.equalsIgnoreCase(name)) {
name = "cmap";
x += 2*(CELL_W+SPACE_X);
y = CELL_H;
linkType = LINK_TYPE.UD;
DefaultGraphCell pcell = createdAttrs.get(MIME_SW);
if (pcell!= null) {
AttributeMap tmp_map = cell.getAttributes();
Rectangle2D bounds = GraphConstants.getBounds(tmp_map);
x = bounds.getX() - CELL_W +20;
y = bounds.getY() + SPACE_Y/5;
parent = pcell;
}
}
cell = createCell(graph, parent, attr, name, x, y,
w, h, null, false, icon, linkType, null);
createdAttrs.put(name, cell);
}
AttributeMap map = cell.getAttributes();
GraphConstants.setExtraLabels(map, new Object[] {objType});
Font f = GraphConstants.getFont(map);
Font newf = null;
if (f!= null && (linkType == LINK_TYPE.EXT || linkType == LINK_TYPE.UD)) {
newf = new java.awt.Font(f.getName(), Font.ITALIC, f.getSize());
GraphConstants.setFont(map, newf);
}
} // if (name != null) {
} // if (attrName.startsWith("URI"))
} // for (int i=0; i<nAttrs; i++)
return cell;
}
private String getNickName(String name) {
String retName = name;
if (name == null)
return null;
if (name.startsWith("bldg_footprint"))
retName = "Bldg_LIDAR";
else if (name.startsWith("Omni_ground-50ft"))
retName = "Omni-LOS";
else if (name.startsWith("ikonos_3band-1m"))
retName = "Img-IKONOS";
else if (name.startsWith("residential"))
retName = "Resd-UTP";
return retName;
}
/** Find the object type pointed by the idx-th attribute.
* Attributes are in pair of <MIMEx=mime_type, URIx=object_url>
*
* @param obj object that contains the attribute
* @param idx the index of the attribute
* @return the object type pointed by the URL.
*/
private OBJ_TYPE getObjType(HObject obj, int idx)
{
OBJ_TYPE objType=null;
List attrs=null;
int nAttrs=0;
if (obj==null)
return null;
try {
attrs = obj.getMetadata();
} catch (Exception ex) { attrs = null; }
if (attrs == null || (nAttrs=attrs.size())<=0)
return null;
for (int i=0; i<nAttrs; i++) {
Attribute attr = (Attribute)attrs.get(i);
String attrName = attr.getName();
if (attrName.startsWith("MIME")) {
int attrIdx = -1;
try {
// MIMEx index matches with URIx index (idx)
attrIdx = Integer.parseInt(attrName.substring(4).trim());
} catch (Exception ex) { attrIdx = -1; }
if ((idx <0 && attrIdx<0) || (idx==attrIdx)) {
String attrValue = ((String[])attr.getValue())[0];
if (attrValue.endsWith(MIME_XLS)) {
objType = OBJ_TYPE.XLS;
}
else if (attrValue.endsWith(MIME_PDF)) {
objType = OBJ_TYPE.PDF;
}
else if (attrValue.endsWith(MIME_HDF)) {
objType = OBJ_TYPE.DATASET;
}
else if (attrValue.startsWith(MIME_AUDIO)) {
objType = OBJ_TYPE.AUDIO;
}
else if (attrValue.startsWith(MIME_VIDEO)) {
objType = OBJ_TYPE.VIDEO;
}
else if (attrValue.startsWith(MIME_TXT)) {
objType = OBJ_TYPE.TEXT;
}
else if (attrValue.endsWith(MIME_HTML)) {
objType = OBJ_TYPE.HTML;
}
else if (attrValue.endsWith(MIME_XML)) {
objType = OBJ_TYPE.XML;
}
else if (attrValue.endsWith(MIME_JPG)) {
objType = OBJ_TYPE.JPG;
}
else {
objType = OBJ_TYPE.SW;
}
break;
}
} // if ((idx <0 && attrIdx<0) || (idx==attrIdx))
} // if (attrName.startsWith("MIME"))
return objType;
} // private String getObjType(HObject obj, int idx)
private ImageIcon getIcon(OBJ_TYPE type)
{
ImageIcon icon = null;
switch (type) {
case XLS: return ICON_TYPE.XLS.getIcon();
case PDF: return ICON_TYPE.PDF.getIcon();
case DATASET: return (ImageIcon)ViewProperties.getDatasetIcon();
case AUDIO: return ICON_TYPE.AUDIO.getIcon();
case VIDEO: return ICON_TYPE.VIDEO.getIcon();
case JPG: return ICON_TYPE.JPG.getIcon();
case TEXT: return (ImageIcon) ViewProperties.getTextIcon();
case HTML: return ICON_TYPE.URL.getIcon();
case XML: return ICON_TYPE.FEED.getIcon();
case SW: return ICON_TYPE.APPS.getIcon();
case LEVEL1: return ICON_TYPE.GRP1.getIcon();
case LEVEL2: return ICON_TYPE.GRP2.getIcon();
case LEVEL3: return ICON_TYPE.GRP3.getIcon();
}
return icon;
}
private boolean isExternal(OBJ_TYPE type)
{
boolean b = false;
switch (type) {
case XLS:
case PDF:
case DATASET:
case AUDIO:
case VIDEO:
case TEXT:
case HTML:
case XML:
case SW:
case LEVEL3:return true;
case LEVEL1:
case LEVEL2: return false;
}
return b;
}
private String getMime(OBJ_TYPE type)
{
String str = null;
switch (type) {
case XLS: return MIME_XLS;
case PDF: return MIME_PDF;
case DATASET: return MIME_HDF;
case AUDIO: return MIME_AUDIO;
case VIDEO: return MIME_VIDEO;
case JPG: return MIME_JPG;
case TEXT: return MIME_TXT;
case HTML: return MIME_HTML;
case XML: return MIME_XML;
case SW: return MIME_SW;
case LEVEL1: return "L1";
case LEVEL2: return "L2";
case LEVEL3: return "L3";
}
return str;
}
/**
* find the largest number of groups at the same level. It is used to
* estimate the width of graph.
*
* @param node the node to be searched.
* @return the largest number of groups.
*/
private int findMaxNumberOfGroups(DefaultMutableTreeNode node)
{
int max = 0;
if (node == null)
return 0;
Enumeration allNodes;
allNodes = node.breadthFirstEnumeration();
DefaultMutableTreeNode theNode;
// find the longest path
int level = 0;
while (allNodes.hasMoreElements()) {
theNode = (DefaultMutableTreeNode)allNodes.nextElement();
level = Math.max(theNode.getLevel(), level);
}
if (level <= 0)
return 0;
int counts[] = new int[level+1];
for (int i=0; i<counts.length; i++)
counts[i] = 0;
allNodes = node.depthFirstEnumeration();
while (allNodes.hasMoreElements()) {
theNode = (DefaultMutableTreeNode)allNodes.nextElement();
if (theNode.isLeaf())
continue; // only counts for groups
level = theNode.getLevel();
counts[level]++;
}
for (int i=0; i<counts.length; i++)
max = Math.max(max, counts[i]);
return max;
}
private void createObjCell(DefaultMutableTreeNode node, DefaultGraphCell pCell,
double x, double y)
{
TreeNode theNode;
DefaultGraphCell cell;
double _x=x, _y=y;
if (node == null)
return; // nothing to display
HObject obj = (HObject)node.getUserObject();
String key = String.valueOf((obj.getOID())[0]);
// search if cell exists
cell = createdObjs.get(key);
// cell does not exists, create a new one
if (cell == null) {
String cellClass = null;
Color color = null;
double w=CELL_W, h=CELL_H;
switch(node.getLevel()) {
case 1:
color = Color.GREEN;
_x -= (CELL_W+SPACE_X)/2;
break;
case 2:
color = Color.ORANGE;
cellClass = CLASS_DIAMOND;
break;
case 3:
color = Color.GRAY;
cellClass = CLASS_ELLIPS;
w = h = (CELL_W+CELL_H)/2;
break;
default:
break;
}
cell = createCell(jgraph, null, obj, obj.getName(), _x, y,
w, h, color, true, null, LINK_TYPE.HARD, cellClass);
createdObjs.put(key, cell);
// create cell for attribute
createExtCell(obj, jgraph, cell);
} // if (cell == null)
// create edge
DefaultEdge edge = createEdge(pCell, cell, LINK_TYPE.HARD);
if (edge != null)
jview.insert(edge);
// count for total number of groups
y += SPACE_Y;
int n = node.getChildCount();
int nCells = 0;
for (int i=0; i<n; i++) {
theNode = node.getChildAt(i);
if (!theNode.isLeaf())
nCells++;
}
int cellIdx=0;
double x0 = (nCells/2.0+1.0)*(CELL_W+SPACE_X);
x0 = Math.max(x0, x);
for (int i=0; i<n; i++) {
theNode = node.getChildAt(i);
if (theNode.isLeaf())
continue;
// Recessively create cells for subgroups
x = x0 + (cellIdx-nCells/2.0)*(CELL_W+SPACE_X);
createObjCell((DefaultMutableTreeNode)theNode, cell, x, y);
cellIdx++;
}
}
private void createGraph(FileFormat file)
{
double x=0, y=0;
DefaultMutableTreeNode fileRoot, theNode;
if (file == null)
return;
fileRoot = (DefaultMutableTreeNode)file.getRootNode();
if (fileRoot == null)
return;
int n = findMaxNumberOfGroups(fileRoot);
gWidth = Math.max(500, n*(CELL_W+SPACE_X));
n = fileRoot.getChildCount();
int nCells = 0;
for (int i=0; i<n; i++) {
theNode = (DefaultMutableTreeNode)fileRoot.getChildAt(i);
if (!theNode.isLeaf())
nCells++;
}
if (nCells <=0 )
return; // nothing to display
int cellIdx=0;
int space_x = gWidth/(nCells+1);
for (int i=0; i<n; i++) {
theNode = (DefaultMutableTreeNode)fileRoot.getChildAt(i);
if (theNode.isLeaf())
continue;
cellIdx++;
x = cellIdx*space_x-SPACE_X/2;
createObjCell(theNode, null, x, y);
}
}
private static void launchBrowser(String url) throws Exception {
String os = System.getProperty("os.name");
Runtime runtime=Runtime.getRuntime();
try{
// Block for Windows Platform
if (os.startsWith("Windows")){
String cmd = "rundll32 url.dll,FileProtocolHandler "+ url;
if (new File(url).exists())
cmd = "cmd /c start \"\" \""+url+"\"";
Process p = runtime.exec(cmd);
}
//Block for Mac OS
else if(os.startsWith("Mac OS")){
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
openURL.invoke(null, new Object[] {url});