Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
OccurrencePanel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2019-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.centralrepository.contentviewer;
20 
22 import java.awt.Color;
23 import java.awt.Font;
24 import java.util.ArrayList;
25 import java.util.Map;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Set;
30 import java.util.logging.Level;
31 import org.openide.util.NbBundle.Messages;
35 import org.sleuthkit.datamodel.TskData;
37 
41 final class OccurrencePanel extends javax.swing.JPanel {
42 
43  private static final Logger LOGGER = Logger.getLogger(OccurrencePanel.class.getName());
44  private static final int LEFT_INSET = 10;
45  private static final int RIGHT_INSET = 10;
46  private static final int TOP_INSET = 10;
47  private static final int BOTTOM_INSET = 10;
48  private static final int VERTICAL_GAP = 6;
49  private static final int HORIZONTAL_GAP = 4;
50  private static final long serialVersionUID = 1L;
51 
52  private int gridY = 0;
53  private final List<NodeData> nodeDataList;
54  private final Map<String, String> caseNamesAndDates = new HashMap<>();
55  private final Set<String> dataSourceNames = new HashSet<>();
56  private final Set<String> filePaths = new HashSet<>();
57 
61  OccurrencePanel() {
62  nodeDataList = new ArrayList<>();
63  customizeComponents();
64  }
65 
72  OccurrencePanel(String caseName, String caseCreatedDate) {
73  nodeDataList = new ArrayList<>();
74  caseNamesAndDates.put(caseName, caseCreatedDate);
75  customizeComponents();
76  }
77 
86  OccurrencePanel(String caseName, String caseCreatedDate, String dataSourceName) {
87  nodeDataList = new ArrayList<>();
88  caseNamesAndDates.put(caseName, caseCreatedDate);
89  dataSourceNames.add(dataSourceName);
90  customizeComponents();
91  }
92 
100  OccurrencePanel(List<NodeData> nodeDataList) {
101  this.nodeDataList = nodeDataList;
102  customizeComponents();
103  }
104 
109  private void customizeComponents() {
110  initComponents();
111  if (!this.nodeDataList.isEmpty()) {
112  //if addInstanceDetails is going to be called it should be called
113  // before addFileDetails, addDataSourceDetails, and addCaseDetails
114  //because it also collects the information they display
115  addInstanceDetails();
116  if (!filePaths.isEmpty()) {
117  addFileDetails();
118  }
119  }
120  if (!dataSourceNames.isEmpty()) {
121  addDataSourceDetails();
122  }
123  if (!caseNamesAndDates.keySet().isEmpty()) {
124  addCaseDetails();
125  }
126  //add filler to keep everything else at the top
127  addItemToBag(gridY, 0, 0, 0, new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)));
128  }
129 
130  @Messages({
131  "OccurrencePanel.commonProperties.text=Common Properties",
132  "OccurrencePanel.commonPropertyTypeLabel.text=Type:",
133  "OccurrencePanel.commonPropertyValueLabel.text=Value:",
134  "OccurrencePanel.commonPropertyKnownStatusLabel.text=Known Status:",
135  "OccurrencePanel.commonPropertyCommentLabel.text=Comment:"
136  })
144  private void addInstanceDetails() {
145  javax.swing.JLabel commonPropertiesLabel = new javax.swing.JLabel();
146  org.openide.awt.Mnemonics.setLocalizedText(commonPropertiesLabel, Bundle.OccurrencePanel_commonProperties_text());
147  commonPropertiesLabel.setFont(commonPropertiesLabel.getFont().deriveFont(Font.BOLD, commonPropertiesLabel.getFont().getSize()));
148  addItemToBag(gridY, 0, TOP_INSET, 0, commonPropertiesLabel);
149  gridY++;
150  //for each other occurrence
151  for (NodeData occurrence : nodeDataList) {
152  if (occurrence instanceof NodeData) {
153  String type = occurrence.getType();
154  if (!type.isEmpty()) {
155  javax.swing.JLabel typeLabel = new javax.swing.JLabel();
156  org.openide.awt.Mnemonics.setLocalizedText(typeLabel, Bundle.OccurrencePanel_commonPropertyTypeLabel_text());
157  addItemToBag(gridY, 0, VERTICAL_GAP, 0, typeLabel);
158  javax.swing.JLabel typeFieldValue = new javax.swing.JLabel();
159  typeFieldValue.setText(type);
160  addItemToBag(gridY, 1, VERTICAL_GAP, 0, typeFieldValue);
161  gridY++;
162  }
163  String value = occurrence.getValue();
164  if (!value.isEmpty()) {
165  javax.swing.JLabel valueLabel = new javax.swing.JLabel();
166  org.openide.awt.Mnemonics.setLocalizedText(valueLabel, Bundle.OccurrencePanel_commonPropertyValueLabel_text());
167  addItemToBag(gridY, 0, 0, 0, valueLabel);
168  javax.swing.JLabel valueFieldValue = new javax.swing.JLabel();
169  valueFieldValue.setText(value);
170  addItemToBag(gridY, 1, 0, 0, valueFieldValue);
171  gridY++;
172  }
173  TskData.FileKnown knownStatus = occurrence.getKnown();
174  javax.swing.JLabel knownStatusLabel = new javax.swing.JLabel();
175  org.openide.awt.Mnemonics.setLocalizedText(knownStatusLabel, Bundle.OccurrencePanel_commonPropertyKnownStatusLabel_text());
176  addItemToBag(gridY, 0, 0, 0, knownStatusLabel);
177  javax.swing.JLabel knownStatusValue = new javax.swing.JLabel();
178  knownStatusValue.setText(knownStatus.getName());
179  if (knownStatus == TskData.FileKnown.BAD) {
180  knownStatusValue.setForeground(Color.RED);
181  }
182  addItemToBag(gridY, 1, 0, 0, knownStatusValue);
183  gridY++;
184  String comment = occurrence.getComment();
185  if (!comment.isEmpty()) {
186  javax.swing.JLabel commentLabel = new javax.swing.JLabel();
187  org.openide.awt.Mnemonics.setLocalizedText(commentLabel, Bundle.OccurrencePanel_commonPropertyCommentLabel_text());
188  addItemToBag(gridY, 0, 0, VERTICAL_GAP, commentLabel);
189  javax.swing.JTextArea commentValue = new javax.swing.JTextArea();
190  commentValue.setText(comment);
191  commentValue.setEditable(false);
192  commentValue.setColumns(20);
193  commentValue.setLineWrap(true);
194  commentValue.setRows(3);
195  commentValue.setTabSize(4);
196  commentValue.setWrapStyleWord(true);
197  commentValue.setBorder(javax.swing.BorderFactory.createEtchedBorder());
198  commentValue.setBackground(javax.swing.UIManager.getDefaults().getColor("TextArea.disabledBackground"));
199  addItemToBag(gridY, 1, 0, VERTICAL_GAP, commentValue);
200  gridY++;
201  }
202  String caseDate = "";
203  try {
204  if (CentralRepository.isEnabled()) {
205  CorrelationCase partialCase = occurrence.getCorrelationAttributeInstance().getCorrelationCase();
206  caseDate = CentralRepository.getInstance().getCaseByUUID(partialCase.getCaseUUID()).getCreationDate();
207  }
208  } catch (CentralRepoException ex) {
209  LOGGER.log(Level.WARNING, "Error getting case created date for other occurrence content viewer", ex);
210  }
211  //Collect the data that is necessary for the other sections
212  caseNamesAndDates.put(occurrence.getCaseName(), caseDate);
213  dataSourceNames.add(occurrence.getDataSourceName());
214  filePaths.add(occurrence.getFilePath());
215  }
216  }
217  //end for each
218  }
219 
220  @Messages({
221  "OccurrencePanel.fileDetails.text=File Details",
222  "OccurrencePanel.filePathLabel.text=File Path:"
223  })
227  private void addFileDetails() {
228  String filePath = filePaths.size() > 1 ? "" : filePaths.iterator().next();
229  if (!filePath.isEmpty()) {
230  javax.swing.JLabel fileDetailsLabel = new javax.swing.JLabel();
231  org.openide.awt.Mnemonics.setLocalizedText(fileDetailsLabel, Bundle.OccurrencePanel_fileDetails_text());
232  fileDetailsLabel.setFont(fileDetailsLabel.getFont().deriveFont(Font.BOLD, fileDetailsLabel.getFont().getSize()));
233  addItemToBag(gridY, 0, TOP_INSET, 0, fileDetailsLabel);
234  gridY++;
235  javax.swing.JLabel filePathLabel = new javax.swing.JLabel();
236  org.openide.awt.Mnemonics.setLocalizedText(filePathLabel, Bundle.OccurrencePanel_filePathLabel_text());
237  addItemToBag(gridY, 0, VERTICAL_GAP, VERTICAL_GAP, filePathLabel);
238  javax.swing.JTextArea filePathValue = new javax.swing.JTextArea();
239  filePathValue.setText(filePath);
240  filePathValue.setEditable(false);
241  filePathValue.setColumns(20);
242  filePathValue.setLineWrap(true);
243  filePathValue.setRows(3);
244  filePathValue.setTabSize(4);
245  filePathValue.setWrapStyleWord(true);
246  filePathValue.setBorder(javax.swing.BorderFactory.createEtchedBorder());
247  filePathValue.setBackground(javax.swing.UIManager.getDefaults().getColor("TextArea.disabledBackground"));
248  addItemToBag(gridY, 1, VERTICAL_GAP, VERTICAL_GAP, filePathValue);
249  gridY++;
250  }
251  }
252 
253  @Messages({
254  "OccurrencePanel.dataSourceDetails.text=Data Source Details",
255  "OccurrencePanel.dataSourceNameLabel.text=Name:"
256  })
261  private void addDataSourceDetails() {
262  String dataSourceName = dataSourceNames.size() > 1 ? "" : dataSourceNames.iterator().next();
263  if (!dataSourceName.isEmpty()) {
264  javax.swing.JLabel dataSourceDetailsLabel = new javax.swing.JLabel();
265  org.openide.awt.Mnemonics.setLocalizedText(dataSourceDetailsLabel, Bundle.OccurrencePanel_dataSourceDetails_text());
266  dataSourceDetailsLabel.setFont(dataSourceDetailsLabel.getFont().deriveFont(Font.BOLD, dataSourceDetailsLabel.getFont().getSize()));
267  addItemToBag(gridY, 0, TOP_INSET, 0, dataSourceDetailsLabel);
268  gridY++;
269  javax.swing.JLabel dataSourceNameLabel = new javax.swing.JLabel();
270  org.openide.awt.Mnemonics.setLocalizedText(dataSourceNameLabel, Bundle.OccurrencePanel_dataSourceNameLabel_text());
271  addItemToBag(gridY, 0, VERTICAL_GAP, VERTICAL_GAP, dataSourceNameLabel);
272  javax.swing.JLabel dataSourceNameValue = new javax.swing.JLabel();
273  dataSourceNameValue.setText(dataSourceName);
274  addItemToBag(gridY, 1, VERTICAL_GAP, VERTICAL_GAP, dataSourceNameValue);
275  gridY++;
276  }
277  }
278 
279  @Messages({
280  "OccurrencePanel.caseDetails.text=Case Details",
281  "OccurrencePanel.caseNameLabel.text=Name:",
282  "OccurrencePanel.caseCreatedDateLabel.text=Created Date:"
283  })
287  private void addCaseDetails() {
288  javax.swing.JLabel caseDetailsLabel = new javax.swing.JLabel();
289  org.openide.awt.Mnemonics.setLocalizedText(caseDetailsLabel, Bundle.OccurrencePanel_caseDetails_text());
290  caseDetailsLabel.setFont(caseDetailsLabel.getFont().deriveFont(Font.BOLD, caseDetailsLabel.getFont().getSize()));
291  addItemToBag(gridY, 0, TOP_INSET, 0, caseDetailsLabel);
292  gridY++;
293  String caseName = caseNamesAndDates.keySet().size() > 1 ? "" : caseNamesAndDates.keySet().iterator().next();
294  if (!caseName.isEmpty()) {
295  javax.swing.JLabel caseNameLabel = new javax.swing.JLabel();
296  org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, Bundle.OccurrencePanel_caseNameLabel_text());
297  addItemToBag(gridY, 0, VERTICAL_GAP, 0, caseNameLabel);
298  javax.swing.JLabel caseNameValue = new javax.swing.JLabel();
299  caseNameValue.setText(caseName);
300  addItemToBag(gridY, 1, VERTICAL_GAP, 0, caseNameValue);
301  gridY++;
302  }
303  String caseCreatedDate = caseNamesAndDates.keySet().size() > 1 ? "" : caseNamesAndDates.get(caseName);
304  if (caseCreatedDate != null && !caseCreatedDate.isEmpty()) {
305  javax.swing.JLabel caseCreatedLabel = new javax.swing.JLabel();
306  org.openide.awt.Mnemonics.setLocalizedText(caseCreatedLabel, Bundle.OccurrencePanel_caseCreatedDateLabel_text());
307  addItemToBag(gridY, 0, 0, BOTTOM_INSET, caseCreatedLabel);
308  javax.swing.JLabel caseCreatedValue = new javax.swing.JLabel();
309  caseCreatedValue.setText(caseCreatedDate);
310  addItemToBag(gridY, 1, 0, BOTTOM_INSET, caseCreatedValue);
311  gridY++;
312  }
313  }
314 
325  private void addItemToBag(int gridYLocation, int gridXLocation, int topInset, int bottomInset, javax.swing.JComponent item) {
326  java.awt.GridBagConstraints gridBagConstraints;
327  gridBagConstraints = new java.awt.GridBagConstraints();
328  gridBagConstraints.gridx = gridXLocation;
329  gridBagConstraints.gridy = gridYLocation;
330  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
331  gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
332  int leftInset = LEFT_INSET;
333  int rightInset = HORIZONTAL_GAP;
334  //change formating a bit if it is the value instead of the label
335  if (gridXLocation == 1) {
336  leftInset = 0;
337  rightInset = RIGHT_INSET;
338  gridBagConstraints.weightx = 0.1;
339  gridBagConstraints.gridwidth = 2;
340  }
341  gridBagConstraints.insets = new java.awt.Insets(topInset, leftInset, bottomInset, rightInset);
342  //if the item is a filler item ensure it will resize vertically
343  if (item instanceof javax.swing.Box.Filler) {
344  gridBagConstraints.weighty = 0.1;
345  }
346  add(item, gridBagConstraints);
347  }
348 
354  @SuppressWarnings("unchecked")
355  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
356  private void initComponents() {
357 
358  setMinimumSize(new java.awt.Dimension(50, 30));
359  setPreferredSize(null);
360  setLayout(new java.awt.GridBagLayout());
361  }// </editor-fold>//GEN-END:initComponents
362 
363  // Variables declaration - do not modify//GEN-BEGIN:variables
364  // End of variables declaration//GEN-END:variables
365 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.