Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
GeneralPurposeArtifactViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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.artifactviewers;
20 
21 import java.awt.Component;
22 import java.awt.Dimension;
23 import java.awt.Font;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.Toolkit;
28 import java.awt.datatransfer.StringSelection;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.logging.Level;
37 import javax.swing.JLabel;
38 import javax.swing.JMenuItem;
39 import javax.swing.JPopupMenu;
40 import javax.swing.JTextPane;
41 import javax.swing.SwingUtilities;
42 import org.apache.commons.lang.StringUtils;
43 import org.openide.util.NbBundle;
44 import org.openide.util.lookup.ServiceProvider;
49 import org.sleuthkit.datamodel.BlackboardArtifact;
50 import org.sleuthkit.datamodel.BlackboardAttribute;
51 import org.sleuthkit.datamodel.TimeUtilities;
52 import org.sleuthkit.datamodel.TskCoreException;
53 
57 @ServiceProvider(service = ArtifactContentViewer.class)
59 
60  private static final long serialVersionUID = 1L;
61  private static final Logger logger = Logger.getLogger(GeneralPurposeArtifactViewer.class.getName());
62  // Number of columns in the gridbag layout.
63  private final static int MAX_COLS = 4;
64  private final static Insets ROW_INSETS = new java.awt.Insets(0, 12, 0, 0);
65  private final static Insets HEADER_INSETS = new java.awt.Insets(0, 0, 0, 0);
66  private final static double GLUE_WEIGHT_X = 1.0;
67  private final static double TEXT_WEIGHT_X = 0.0;
68  private final static int LABEL_COLUMN = 0;
69  private final static int VALUE_COLUMN = 1;
70  private final static int VALUE_WIDTH = 2;
71  private final static int LABEL_WIDTH = 1;
72  private static final Integer[] DEFAULT_ORDERING = new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(),
73  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
74  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(),
75  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID(),
76  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID(),
77  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID(),
78  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID(),
79  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_HEADERS.getTypeID()};
80  private static final List<Integer> TYPES_WITH_DATE_SECTION = Arrays.asList(new Integer[]{BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID()});
81  private final GridBagLayout gridBagLayout = new GridBagLayout();
82  private final GridBagConstraints gridBagConstraints = new GridBagConstraints();
83  private final Map<Integer, Integer[]> orderingMap = new HashMap<>();
84  private final javax.swing.JPanel detailsPanel = new javax.swing.JPanel();
85 
91  addOrderings();
92  initComponents();
93  gridBagConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
94  detailsPanel.setLayout(gridBagLayout);
95  }
96 
101  private void addOrderings() {
102  orderingMap.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID(), new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(),
103  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE.getTypeID(),
104  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
105  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(),
106  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID(),
107  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID()});
108  orderingMap.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID(), new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(),
109  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID(),
110  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
111  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(),
112  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_HEADERS.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID(),
113  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID()});
114  orderingMap.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID(), new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(),
115  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID(),
116  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
117  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(),
118  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID(),
119  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID()});
120  orderingMap.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_SEARCH_QUERY.getTypeID(), new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID(),
121  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
122  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(),
123  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(),
124  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID()});
125  orderingMap.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID(), new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE.getTypeID(),
126  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_USER_NAME.getTypeID(),
127  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
128  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(),
129  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID(),
130  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER.getTypeID(),
131  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID()});
132  orderingMap.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID(), new Integer[]{BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(),
133  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID(),
134  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(),
135  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE.getTypeID(),
136  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID()});
137  }
138 
140  @NbBundle.Messages({"GeneralPurposeArtifactViewer.unknown.text=Unknown"})
141  @Override
142  public void setArtifact(BlackboardArtifact artifact) {
143  resetComponent();
144  if (artifact != null) {
145  String dataSourceName = Bundle.GeneralPurposeArtifactViewer_unknown_text();
146  String sourceFileName = Bundle.GeneralPurposeArtifactViewer_unknown_text();
147  Map<Integer, List<BlackboardAttribute>> attributeMap = new HashMap<>();
148  try {
149  // Get all the attributes and group them by the attributeType
150  for (BlackboardAttribute bba : artifact.getAttributes()) {
151  List<BlackboardAttribute> attrList = attributeMap.get(bba.getAttributeType().getTypeID());
152  if (attrList == null) {
153  attrList = new ArrayList<>();
154  }
155  attrList.add(bba);
156  attributeMap.put(bba.getAttributeType().getTypeID(), attrList);
157  }
158  dataSourceName = artifact.getDataSource().getName();
159  sourceFileName = artifact.getParent().getUniquePath();
160  } catch (TskCoreException ex) {
161  logger.log(Level.WARNING, "Unable to get attributes for artifact " + artifact.getArtifactID(), ex);
162  }
163  updateView(artifact, attributeMap, dataSourceName, sourceFileName);
164  }
165  detailsScrollPane.setViewportView(detailsPanel);
166  detailsScrollPane.revalidate();
167  revalidate();
168  }
169 
174  private void resetComponent() {
175  // clear the panel
176  detailsPanel.removeAll();
177  detailsPanel.setLayout(gridBagLayout);
178  detailsPanel.revalidate();
179  gridBagConstraints.gridy = 0;
180  gridBagConstraints.gridx = LABEL_COLUMN;
181  gridBagConstraints.weighty = 0.0;
182  gridBagConstraints.weightx = TEXT_WEIGHT_X; // keep components fixed horizontally.
183  gridBagConstraints.fill = GridBagConstraints.NONE;
184  gridBagConstraints.insets = ROW_INSETS;
185  }
186 
188  @Override
189  public boolean isSupported(BlackboardArtifact artifact) {
190  return (artifact != null)
191  && (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID()
192  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_SEARCH_QUERY.getTypeID()
193  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID()
194  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID()
195  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID()
196  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID()
197  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_ACCOUNT_TYPE.getTypeID()
198  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_ADDRESS.getTypeID()
199  || artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_AUTOFILL.getTypeID());
200  }
201 
202  @NbBundle.Messages({"GeneralPurposeArtifactViewer.details.attrHeader=Details",
203  "GeneralPurposeArtifactViewer.details.sourceHeader=Source",
204  "GeneralPurposeArtifactViewer.details.dataSource=Data Source",
205  "GeneralPurposeArtifactViewer.details.file=File",
206  "GeneralPurposeArtifactViewer.details.datesHeader=Dates"})
212  @SuppressWarnings("unchecked")
213  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
214  private void initComponents() {
215 
216  detailsScrollPane = new javax.swing.JScrollPane();
217 
218  detailsScrollPane.setPreferredSize(new java.awt.Dimension(300, 0));
219 
220  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
221  this.setLayout(layout);
222  layout.setHorizontalGroup(
223  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224  .addComponent(detailsScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
225  );
226  layout.setVerticalGroup(
227  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addGroup(layout.createSequentialGroup()
229  .addComponent(detailsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
230  .addGap(0, 0, 0))
231  );
232  }// </editor-fold>//GEN-END:initComponents
233 
244  @NbBundle.Messages({"GeneralPurposeArtifactViewer.dates.created=Created",
245  "GeneralPurposeArtifactViewer.dates.start=Start",
246  "GeneralPurposeArtifactViewer.dates.end=End",
247  "GeneralPurposeArtifactViewer.dates.time=Time",
248  "GeneralPurposeArtifactViewer.term.label=Term",
249  "GeneralPurposeArtifactViewer.details.otherHeader=Other",
250  "GeneralPurposeArtifactViewer.noFile.text= (no longer exists)"})
252  private void updateView(BlackboardArtifact artifact, Map<Integer, List<BlackboardAttribute>> attributeMap, String dataSourceName, String sourceFilePath) {
253  final Integer artifactTypeId = artifact.getArtifactTypeID();
254  if (!(artifactTypeId < 1 || artifactTypeId >= Integer.MAX_VALUE)) {
255  JTextPane firstTextPane = addDetailsHeader(artifactTypeId);
256  Integer[] orderingArray = orderingMap.get(artifactTypeId);
257  if (orderingArray == null) {
258  orderingArray = DEFAULT_ORDERING;
259  }
260  for (Integer attrId : orderingArray) {
261  List<BlackboardAttribute> attrList = attributeMap.remove(attrId);
262  if (attrList != null) {
263  for (BlackboardAttribute bba : attrList) {
264  if (bba.getAttributeType().getTypeName().startsWith("TSK_DATETIME")) {
265  if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_SEARCH_QUERY.getTypeID()) {
266  addNameValueRow(Bundle.GeneralPurposeArtifactViewer_dates_time(), TimeUtilities.epochToTime(bba.getValueLong(), ContentUtils.getTimeZone(artifact)));
267  } else {
268  addNameValueRow(bba.getAttributeType().getDisplayName(), TimeUtilities.epochToTime(bba.getValueLong(), ContentUtils.getTimeZone(artifact)));
269  }
270  } else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID() && artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_SEARCH_QUERY.getTypeID()) {
271  addNameValueRow(Bundle.GeneralPurposeArtifactViewer_term_label(), bba.getDisplayString());
272  } else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID()) {
273  String displayString = bba.getDisplayString();
274  if (!attributeMap.containsKey(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID())) {
275  displayString += Bundle.GeneralPurposeArtifactViewer_noFile_text();
276  }
277  addNameValueRow(bba.getAttributeType().getDisplayName(), displayString);
278  } else {
279  addNameValueRow(bba.getAttributeType().getDisplayName(), bba.getDisplayString());
280  }
281  }
282  }
283  }
284  if (TYPES_WITH_DATE_SECTION.contains(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID())) {
285  boolean headerAdded = false;
286  headerAdded = addDates(Bundle.GeneralPurposeArtifactViewer_dates_created(), attributeMap.remove(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID()), headerAdded);
287  headerAdded = addDates(Bundle.GeneralPurposeArtifactViewer_dates_start(), attributeMap.remove(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID()), headerAdded);
288  headerAdded = addDates(Bundle.GeneralPurposeArtifactViewer_dates_end(), attributeMap.remove(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID()), headerAdded);
289  addDates(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getDisplayName(), attributeMap.remove(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID()), headerAdded);
290  }
291  if (!attributeMap.keySet().isEmpty()) {
292  addHeader(Bundle.GeneralPurposeArtifactViewer_details_otherHeader());
293  for (int key : attributeMap.keySet()) {
294  for (BlackboardAttribute bba : attributeMap.get(key)) {
295  if (bba.getAttributeType().getTypeName().startsWith("TSK_DATETIME")) {
296  addNameValueRow(bba.getAttributeType().getDisplayName(), TimeUtilities.epochToTime(bba.getValueLong(), ContentUtils.getTimeZone(artifact)));
297  } else {
298  addNameValueRow(bba.getAttributeType().getDisplayName(), bba.getDisplayString());
299  }
300  }
301  }
302  }
303  addHeader(Bundle.GeneralPurposeArtifactViewer_details_sourceHeader());
304  addNameValueRow(Bundle.GeneralPurposeArtifactViewer_details_dataSource(), dataSourceName);
305  addNameValueRow(Bundle.GeneralPurposeArtifactViewer_details_file(), sourceFilePath);
306  // add veritcal glue at the end
307  addPageEndGlue();
308  if (firstTextPane != null) {
309  firstTextPane.setCaretPosition(0);
310  }
311  }
312  detailsPanel.revalidate();
313  }
314 
325  private boolean addDates(String label, List<BlackboardAttribute> attrList, boolean headerExists) {
326  boolean headerAdded = headerExists;
327  if (attrList != null) {
328  if (!headerAdded) {
329  addHeader(Bundle.GeneralPurposeArtifactViewer_details_datesHeader());
330  headerAdded = true;
331  }
332  String labelToUse = label;
333  for (BlackboardAttribute bba : attrList) {
334  if (StringUtils.isBlank(label)) {
335  labelToUse = bba.getAttributeType().getDisplayName();
336  }
337  addNameValueRow(labelToUse, bba.getDisplayString());
338  }
339  }
340  return headerAdded;
341  }
342 
348  @NbBundle.Messages({"GeneralPurposeArtifactViewer.details.bookmarkHeader=Bookmark Details",
349  "GeneralPurposeArtifactViewer.details.historyHeader=Visit Details",
350  "GeneralPurposeArtifactViewer.details.downloadHeader=Downloaded File",
351  "GeneralPurposeArtifactViewer.details.searchHeader=Web Search",
352  "GeneralPurposeArtifactViewer.details.cachedHeader=Cached File",
353  "GeneralPurposeArtifactViewer.details.cookieHeader=Cookie Details",})
354  private JTextPane addDetailsHeader(int artifactTypeId) {
355  String header;
356  if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID()) {
357  header = Bundle.GeneralPurposeArtifactViewer_details_historyHeader();
358  } else if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID()) {
359  header = Bundle.GeneralPurposeArtifactViewer_details_bookmarkHeader();
360  } else if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID()) {
361  header = Bundle.GeneralPurposeArtifactViewer_details_cachedHeader();
362  } else if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID()) {
363  header = Bundle.GeneralPurposeArtifactViewer_details_cookieHeader();
364  } else if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID()) {
365  header = Bundle.GeneralPurposeArtifactViewer_details_downloadHeader();
366  } else if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_SEARCH_QUERY.getTypeID()) {
367  header = Bundle.GeneralPurposeArtifactViewer_details_searchHeader();
368  } else {
369  header = Bundle.GeneralPurposeArtifactViewer_details_attrHeader();
370  }
371  return addHeader(header);
372  }
373 
382  private JTextPane addHeader(String headerString) {
383  // create label for heading
384  javax.swing.JTextPane headingLabel = new javax.swing.JTextPane();
385  headingLabel.setOpaque(false);
386  headingLabel.setFocusable(false);
387  headingLabel.setEditable(false);
388  // add a blank line before the start of new section, unless it's
389  // the first section
390  if (gridBagConstraints.gridy != 0) {
391  gridBagConstraints.gridy++;
392  // add to panel
393  addToPanel(new javax.swing.JLabel(" "));
394  addLineEndGlue();
395  headingLabel.setFocusable(false);
396  }
397  gridBagConstraints.gridy++;
398  gridBagConstraints.gridx = LABEL_COLUMN;;
399  // let the header span all of the row
400  gridBagConstraints.gridwidth = MAX_COLS;
401  gridBagConstraints.insets = HEADER_INSETS;
402  // set text
403  headingLabel.setText(headerString);
404  // make it large and bold
405  headingLabel.setFont(headingLabel.getFont().deriveFont(Font.BOLD, headingLabel.getFont().getSize() + 2));
406  // add to panel
407  addToPanel(headingLabel);
408  // reset constraints to normal
409  gridBagConstraints.gridwidth = LABEL_WIDTH;
410  // add line end glue
411  addLineEndGlue();
412  gridBagConstraints.insets = ROW_INSETS;
413  return headingLabel;
414  }
415 
423  private JTextPane addNameValueRow(String keyString, String valueString) {
424  addKeyAtCol(keyString);
425  return addValueAtCol(valueString);
426  }
427 
432  private void addLineEndGlue() {
433  // Place the filler just past the last column.
434  gridBagConstraints.gridx = MAX_COLS;
435  gridBagConstraints.weightx = GLUE_WEIGHT_X; // take up all the horizontal space
436  gridBagConstraints.fill = GridBagConstraints.BOTH;
437  javax.swing.Box.Filler horizontalFiller = new javax.swing.Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(32767, 0));
438  // add to panel
439  addToPanel(horizontalFiller);
440  // restore fill & weight
441  gridBagConstraints.fill = GridBagConstraints.NONE;
442  gridBagConstraints.weightx = TEXT_WEIGHT_X;
443  }
444 
449  private void addPageEndGlue() {
450  gridBagConstraints.weighty = 1.0; // take up all the vertical space
451  gridBagConstraints.fill = GridBagConstraints.VERTICAL;
452  javax.swing.Box.Filler vertFiller = new javax.swing.Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(0, 32767));
453  // add to panel
454  addToPanel(vertFiller);
455  }
456 
464  private JLabel addKeyAtCol(String keyString) {
465  // create label
466  javax.swing.JLabel keyLabel = new javax.swing.JLabel();
467  keyLabel.setFocusable(false);
468  gridBagConstraints.gridy++;
469  gridBagConstraints.gridx = LABEL_COLUMN;
470  gridBagConstraints.gridwidth = LABEL_WIDTH;
471  // set text
472  keyLabel.setText(keyString + ": ");
473  // add to panel
474  addToPanel(keyLabel);
475  return keyLabel;
476  }
477 
478  private void addToPanel(Component comp) {
479  detailsPanel.add(comp, gridBagConstraints);
480  detailsPanel.revalidate();
481  }
482 
490  private JTextPane addValueAtCol(String valueString) {
491  // create label,
492  JTextPane valueField = new JTextPane();
493  valueField.setFocusable(false);
494  valueField.setEditable(false);
495  valueField.setOpaque(false);
496  gridBagConstraints.gridx = VALUE_COLUMN;
497  GridBagConstraints cloneConstraints = (GridBagConstraints) gridBagConstraints.clone();
498  // let the value span 2 cols
499  cloneConstraints.gridwidth = VALUE_WIDTH;
500  cloneConstraints.fill = GridBagConstraints.BOTH;
501  // set text
502  valueField.setText(valueString);
503  // attach a right click menu with Copy option
504  valueField.addMouseListener(new java.awt.event.MouseAdapter() {
505  @Override
506  public void mouseClicked(java.awt.event.MouseEvent evt) {
507  valueLabelMouseClicked(evt, valueField);
508  }
509  });
510  // add label to panel with cloned contraintsF
511  detailsPanel.add(valueField, cloneConstraints);
512  revalidate();
513  // end the line
514  addLineEndGlue();
515  return valueField;
516  }
517 
525  @NbBundle.Messages({
526  "GeneralPurposeArtifactViewer_menuitem_copy=Copy"
527  })
528  private void valueLabelMouseClicked(java.awt.event.MouseEvent evt, JTextPane valueLabel) {
529  if (SwingUtilities.isRightMouseButton(evt)) {
530  JPopupMenu popup = new JPopupMenu();
531  JMenuItem copyMenu = new JMenuItem(Bundle.CommunicationArtifactViewerHelper_menuitem_copy()); // NON-NLS
532  copyMenu.addActionListener(new ActionListener() {
533  @Override
534  public void actionPerformed(ActionEvent e) {
535  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(valueLabel.getText()), null);
536  }
537  });
538  popup.add(copyMenu);
539  popup.show(valueLabel, evt.getX(), evt.getY());
540  }
541  }
542 
543 
544  // Variables declaration - do not modify//GEN-BEGIN:variables
545  private javax.swing.JScrollPane detailsScrollPane;
546  // End of variables declaration//GEN-END:variables
547 }
void updateView(BlackboardArtifact artifact, Map< Integer, List< BlackboardAttribute >> attributeMap, String dataSourceName, String sourceFilePath)
boolean addDates(String label, List< BlackboardAttribute > attrList, boolean headerExists)
static TimeZone getTimeZone(Content content)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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