22 package org.sleuthkit.autopsy.rejview;
24 import com.williballenthin.rejistry.RegistryHive;
25 import com.williballenthin.rejistry.RegistryParseException;
26 import java.awt.Dimension;
27 import javax.swing.event.TreeExpansionEvent;
28 import javax.swing.event.TreeExpansionListener;
29 import javax.swing.event.TreeSelectionEvent;
30 import javax.swing.event.TreeSelectionListener;
31 import javax.swing.tree.DefaultMutableTreeNode;
32 import javax.swing.tree.DefaultTreeModel;
33 import javax.swing.tree.TreePath;
34 import java.util.concurrent.CopyOnWriteArrayList;
35 import java.util.logging.Level;
36 import javax.swing.JScrollPane;
37 import javax.swing.JTree;
38 import org.openide.util.NbBundle;
44 final class RejTreeView
extends JScrollPane {
46 private static final Logger logger = Logger.
getLogger(HexView.class.getName());
47 private static final long serialVersionUID = 1L;
48 private final DefaultTreeModel treeModel;
49 private final RejTreeViewListener rejTreeViewListener =
new RejTreeViewListener();
50 private final CopyOnWriteArrayList<RejTreeNodeSelectionListener> nodeSelectionListeners;
57 @NbBundle.Messages({
"RejTreeView.failureValueName.text=PARSE FAILED"})
58 RejTreeView(RegistryHive hive) {
59 DefaultMutableTreeNode rootNode;
60 this.nodeSelectionListeners =
new CopyOnWriteArrayList<>();
62 rootNode = getTreeNode(
new RejTreeKeyNode(hive.getRoot()));
63 }
catch (RegistryParseException ex) {
64 logger.log(Level.WARNING,
"Failed to parse root key", ex);
65 rootNode =
new DefaultMutableTreeNode(
new RejTreeFailureNode(Bundle.RejTreeView_failureValueName_text()));
67 this.treeModel =
new DefaultTreeModel(rootNode);
68 this.treeModel.setAsksAllowsChildren(
true);
69 JTree tree =
new JTree(this.treeModel);
70 tree.addTreeExpansionListener(rejTreeViewListener);
71 tree.addTreeSelectionListener(rejTreeViewListener);
73 tree.collapsePath(
new TreePath(rootNode.getPath()));
74 tree.expandPath(
new TreePath(rootNode.getPath()));
75 setViewportView(tree);
76 setPreferredSize(
new Dimension(350, 20));
83 private DefaultMutableTreeNode getTreeNode(RejTreeNode node) {
84 DefaultMutableTreeNode ret;
85 ret =
new DefaultMutableTreeNode(node);
86 ret.setAllowsChildren(node.hasChildren());
96 void addRejTreeNodeSelectionListener(RejTreeNodeSelectionListener selListener) {
97 this.nodeSelectionListeners.add(selListener);
106 void removeRejTreeNodeSelectionListener(RejTreeNodeSelectionListener selListener) {
107 this.nodeSelectionListeners.remove(selListener);
117 TreePath path =
event.getPath();
118 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
120 if (node.getChildCount() == 0) {
123 node.add(getTreeNode(rejTreeNode));
125 treeModel.nodeStructureChanged(node);
136 TreePath path = e.getPath();
137 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
138 this.triggerRejTreeNodeSelection((
RejTreeNode) node.getUserObject());
147 listener.nodeSelected(e);
void treeCollapsed(TreeExpansionEvent event)
void valueChanged(TreeSelectionEvent e)
abstract List< RejTreeNode > getChildren()
synchronized static Logger getLogger(String name)
void treeExpanded(TreeExpansionEvent event)