1
2 package hep.wired.heprep.tree;
3
4 import java.awt.*;
5 import java.util.*;
6 import java.util.List;
7 import javax.swing.*;
8 import javax.swing.event.*;
9 import javax.swing.tree.*;
10
11 import hep.graphics.heprep.HepRepAttribute;
12 import hep.graphics.heprep.HepRepAttValue;
13
14 import hep.wired.util.DefaultTristateTreeNode;
15 import hep.wired.util.TristateTreeModel;
16 import hep.wired.util.TristateTreeNode;
17
18 import hep.wired.heprep.util.WiredHepRepUtil;
19
20 /***
21 * TriState TreeModel for HepRep TypeTree.
22 *
23 * @author Mark Donszelmann
24 * @version $Id: TypeTristateTreeModel.java 673 2005-03-08 00:16:25Z duns $
25 */
26 public class TypeTristateTreeModel extends TristateTreeModel {
27
28 public TypeTristateTreeModel() {
29 this(null);
30 }
31
32 public TypeTristateTreeModel(TypeTreeModel model) {
33 super(model);
34 }
35
36
37 public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
38 return model == null ? "" : ((TypeTreeModel)model).convertValueToText(value, selected, expanded, leaf, row, hasFocus);
39 }
40
41 public int getMaximumDepth() {
42 return model == null ? 0 : ((TypeTreeModel)model).getMaximumDepth();
43 }
44
45 public void setMaximumDepth(int depth) {
46 if (model != null) ((TypeTreeModel)model).setMaximumDepth(depth);
47 }
48
49
50
51
52
53
54 public Map
55 Map map = new HashMap();
56 TristateTreeNode root = (TristateTreeNode)getRoot();
57 if (root != null) {
58 TreePath rootPath = new TreePath(WiredHepRepUtil.getHepRepName(root.getUserObject()));
59 addType(map, rootPath, root);
60 }
61 return map;
62 }
63
64 private void addType(Map
65 int n = getChildCount(parent);
66 for (int i=0; i<n; i++) {
67 TristateTreeNode node = (TristateTreeNode)getChild(parent, i);
68 TreePath path = parentPath.pathByAddingChild(WiredHepRepUtil.getHepRepName(node.getUserObject()));
69 map.put(path, node);
70 addType(map, path, node);
71 }
72 }
73
74 protected TristateTreeNode createTreeNode(Object modelNode) {
75 if (modelNode instanceof HepRepAttribute) {
76 HepRepAttribute attribute = (HepRepAttribute)modelNode;
77 HepRepAttValue attValue = attribute.getAttValueFromNode("visibility");
78 return new DefaultTristateTreeNode(modelNode, attValue != null ? attValue.getBoolean() : true);
79 }
80 return super.createTreeNode(modelNode);
81 }
82 }