Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AnnotationsContentViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers;
20 
21 import java.awt.Component;
22 import java.util.concurrent.ExecutionException;
23 import java.util.logging.Level;
24 import javax.swing.SwingWorker;
25 
26 import static org.openide.util.NbBundle.Messages;
27 import org.openide.nodes.Node;
28 import org.openide.util.lookup.ServiceProvider;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 import org.sleuthkit.datamodel.TskCoreException;
35 import org.jsoup.nodes.Document;
37 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 @ServiceProvider(service = DataContentViewer.class, position = 9)
43 @Messages({
44  "AnnotationsContentViewer.title=Annotations",
45  "AnnotationsContentViewer.toolTip=Displays tags and comments associated with the selected content.",
46  "AnnotationsContentViewer.onEmpty=No annotations were found for this particular item."
47 })
48 public class AnnotationsContentViewer extends javax.swing.JPanel implements DataContentViewer {
49 
50  private static final long serialVersionUID = 1L;
51  private static final Logger logger = Logger.getLogger(AnnotationsContentViewer.class.getName());
52 
54 
59  initComponents();
61  }
62 
63  @Override
64  public void setNode(Node node) {
65  resetComponent();
66 
67  if(worker != null) {
68  worker.cancel(true);
69  worker = null;
70  }
71 
72  if(node == null) {
73  return;
74  }
75 
76  worker = new AnnotationWorker(node);
77  worker.execute();
78  }
79 
80 
86  @SuppressWarnings("unchecked")
87  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
88  private void initComponents() {
89 
90  javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane();
91  textPanel = new javax.swing.JTextPane();
92 
93  setPreferredSize(new java.awt.Dimension(100, 58));
94 
95  textPanel.setEditable(false);
96  textPanel.setName(""); // NOI18N
97  textPanel.setPreferredSize(new java.awt.Dimension(600, 52));
98  scrollPane.setViewportView(textPanel);
99 
100  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
101  this.setLayout(layout);
102  layout.setHorizontalGroup(
103  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104  .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
105  );
106  layout.setVerticalGroup(
107  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
108  .addComponent(scrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
109  );
110  }// </editor-fold>//GEN-END:initComponents
111 
112  // Variables declaration - do not modify//GEN-BEGIN:variables
113  private javax.swing.JTextPane textPanel;
114  // End of variables declaration//GEN-END:variables
115 
116  @Override
117  public String getTitle() {
118  return Bundle.AnnotationsContentViewer_title();
119  }
120 
121  @Override
122  public String getToolTip() {
123  return Bundle.AnnotationsContentViewer_toolTip();
124  }
125 
126  @Override
128  return new AnnotationsContentViewer();
129  }
130 
131  @Override
132  public boolean isSupported(Node node) {
133  return node != null && node.getLookup().lookup(AbstractFile.class) != null;
134  }
135 
136  @Override
137  public int isPreferred(Node node) {
138  return 1;
139  }
140 
141  @Override
142  public Component getComponent() {
143  return this;
144  }
145 
146  @Override
147  public void resetComponent() {
148  textPanel.setText("");
149  }
150 
155  private class AnnotationWorker extends SwingWorker<String, Void> {
156  private final Node node;
157 
158  AnnotationWorker(Node node) {
159  this.node = node;
160  }
161 
162  @Override
163  protected String doInBackground() throws Exception {
164  Document doc = Annotations.buildDocument(node);
165 
166  if(isCancelled()) {
167  return null;
168  }
169 
170  if(doc != null) {
171  return doc.html();
172  } else {
173  return "<span class='" + ContentViewerHtmlStyles.getMessageClassName() + "'>" + Bundle.AnnotationsContentViewer_onEmpty() + "</span>";
174  }
175  }
176 
177  @Override
178  public void done() {
179  if (isCancelled()) {
180  return;
181  }
182 
183  try {
184  String text = get();
186  textPanel.setText(text);
187  textPanel.setCaretPosition(0);
188  } catch (InterruptedException | ExecutionException ex) {
189  logger.log(Level.SEVERE, "Failed to get annotation information for node", ex);
190  }
191  }
192 
193  }
194 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.