Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
RejTreeView.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Copyright 2013 Willi Ballenthin
8  * Contact: willi.ballenthin <at> gmail <dot> com
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 package org.sleuthkit.autopsy.rejview;
23 
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;
40 
44 final class RejTreeView extends JScrollPane {
45 
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;
51 
57  @NbBundle.Messages({"RejTreeView.failureValueName.text=PARSE FAILED"})
58  RejTreeView(RegistryHive hive) {
59  DefaultMutableTreeNode rootNode;
60  this.nodeSelectionListeners = new CopyOnWriteArrayList<>();
61  try {
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()));
66  }
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);
72  // here's a bit of a hack to force the children to be loaded and shown
73  tree.collapsePath(new TreePath(rootNode.getPath()));
74  tree.expandPath(new TreePath(rootNode.getPath()));
75  setViewportView(tree);
76  setPreferredSize(new Dimension(350, 20));
77  }
78 
83  private DefaultMutableTreeNode getTreeNode(RejTreeNode node) {
84  DefaultMutableTreeNode ret;
85  ret = new DefaultMutableTreeNode(node);
86  ret.setAllowsChildren(node.hasChildren());
87  return ret;
88  }
89 
96  void addRejTreeNodeSelectionListener(RejTreeNodeSelectionListener selListener) {
97  this.nodeSelectionListeners.add(selListener);
98  }
99 
106  void removeRejTreeNodeSelectionListener(RejTreeNodeSelectionListener selListener) {
107  this.nodeSelectionListeners.remove(selListener);
108  }
109 
113  private class RejTreeViewListener implements TreeExpansionListener, TreeSelectionListener {
114 
115  @Override
116  public void treeExpanded(TreeExpansionEvent event) {
117  TreePath path = event.getPath();
118  DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
119 
120  if (node.getChildCount() == 0) {
121  RejTreeNode n = (RejTreeNode) node.getUserObject();
122  for (RejTreeNode rejTreeNode : n.getChildren()) {
123  node.add(getTreeNode(rejTreeNode));
124  }
125  treeModel.nodeStructureChanged(node);
126  }
127  }
128 
129  @Override
130  public void treeCollapsed(TreeExpansionEvent event) {
131  //Empty method
132  }
133 
134  @Override
135  public void valueChanged(TreeSelectionEvent e) {
136  TreePath path = e.getPath();
137  DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
138  this.triggerRejTreeNodeSelection((RejTreeNode) node.getUserObject());
139  }
140 
144  void triggerRejTreeNodeSelection(RejTreeNode n) {
146  for (RejTreeNodeSelectionListener listener : nodeSelectionListeners) {
147  listener.nodeSelected(e);
148  }
149  }
150  }
151 }
abstract List< RejTreeNode > getChildren()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Mon Sep 26 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.