19 package org.sleuthkit.autopsy.centralrepository.contentviewer;
22 import java.awt.Color;
24 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
30 import java.util.logging.Level;
31 import org.openide.util.NbBundle.Messages;
42 final class OccurrencePanel
extends javax.swing.JPanel {
44 private static final Logger LOGGER = Logger.getLogger(OccurrencePanel.class.getName());
45 private static final int LEFT_INSET = 10;
46 private static final int RIGHT_INSET = 10;
47 private static final int TOP_INSET = 10;
48 private static final int BOTTOM_INSET = 10;
49 private static final int VERTICAL_GAP = 6;
50 private static final int HORIZONTAL_GAP = 4;
51 private static final long serialVersionUID = 1L;
53 private int gridY = 0;
54 private final List<NodeData> nodeDataList;
55 private final Map<String, String> caseNamesAndDates =
new HashMap<>();
56 private final Set<String> dataSourceNames =
new HashSet<>();
57 private final Set<String> filePaths =
new HashSet<>();
63 nodeDataList =
new ArrayList<>();
64 customizeComponents();
73 OccurrencePanel(String caseName, String caseCreatedDate) {
74 nodeDataList =
new ArrayList<>();
75 caseNamesAndDates.put(caseName, caseCreatedDate);
76 customizeComponents();
87 OccurrencePanel(String caseName, String caseCreatedDate, String dataSourceName) {
88 nodeDataList =
new ArrayList<>();
89 caseNamesAndDates.put(caseName, caseCreatedDate);
90 dataSourceNames.add(dataSourceName);
91 customizeComponents();
101 OccurrencePanel(List<NodeData> nodeDataList) {
102 this.nodeDataList = nodeDataList;
103 customizeComponents();
110 private void customizeComponents() {
112 if (!this.nodeDataList.isEmpty()) {
116 addInstanceDetails();
117 if (!filePaths.isEmpty()) {
121 if (!dataSourceNames.isEmpty()) {
122 addDataSourceDetails();
124 if (!caseNamesAndDates.keySet().isEmpty()) {
128 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)));
132 "OccurrencePanel.commonProperties.text=Common Properties",
133 "OccurrencePanel.commonPropertyTypeLabel.text=Type:",
134 "OccurrencePanel.commonPropertyValueLabel.text=Value:",
135 "OccurrencePanel.commonPropertyKnownStatusLabel.text=Known Status:",
136 "OccurrencePanel.commonPropertyCommentLabel.text=Comment:"
145 private void addInstanceDetails() {
146 javax.swing.JLabel commonPropertiesLabel =
new javax.swing.JLabel();
147 org.openide.awt.Mnemonics.setLocalizedText(commonPropertiesLabel, Bundle.OccurrencePanel_commonProperties_text());
148 commonPropertiesLabel.setFont(commonPropertiesLabel.getFont().deriveFont(Font.BOLD, commonPropertiesLabel.getFont().getSize()));
149 addItemToBag(gridY, 0, TOP_INSET, 0, commonPropertiesLabel);
152 for (NodeData occurrence : nodeDataList) {
153 if (occurrence instanceof NodeData) {
154 String type = occurrence.getType();
155 if (!type.isEmpty()) {
156 javax.swing.JLabel typeLabel =
new javax.swing.JLabel();
157 org.openide.awt.Mnemonics.setLocalizedText(typeLabel, Bundle.OccurrencePanel_commonPropertyTypeLabel_text());
158 addItemToBag(gridY, 0, VERTICAL_GAP, 0, typeLabel);
159 javax.swing.JLabel typeFieldValue =
new javax.swing.JLabel();
160 typeFieldValue.setText(type);
161 addItemToBag(gridY, 1, VERTICAL_GAP, 0, typeFieldValue);
164 String value = occurrence.getValue();
165 if (!value.isEmpty()) {
166 javax.swing.JLabel valueLabel =
new javax.swing.JLabel();
167 org.openide.awt.Mnemonics.setLocalizedText(valueLabel, Bundle.OccurrencePanel_commonPropertyValueLabel_text());
168 addItemToBag(gridY, 0, 0, 0, valueLabel);
169 javax.swing.JLabel valueFieldValue =
new javax.swing.JLabel();
170 valueFieldValue.setText(value);
171 addItemToBag(gridY, 1, 0, 0, valueFieldValue);
174 TskData.FileKnown knownStatus = occurrence.getKnown();
175 javax.swing.JLabel knownStatusLabel =
new javax.swing.JLabel();
176 org.openide.awt.Mnemonics.setLocalizedText(knownStatusLabel, Bundle.OccurrencePanel_commonPropertyKnownStatusLabel_text());
177 addItemToBag(gridY, 0, 0, 0, knownStatusLabel);
178 javax.swing.JLabel knownStatusValue =
new javax.swing.JLabel();
179 knownStatusValue.setText(knownStatus.getName());
180 if (knownStatus == TskData.FileKnown.BAD) {
181 knownStatusValue.setForeground(Color.RED);
183 addItemToBag(gridY, 1, 0, 0, knownStatusValue);
185 String comment = occurrence.getComment();
186 if (!comment.isEmpty()) {
187 javax.swing.JLabel commentLabel =
new javax.swing.JLabel();
188 org.openide.awt.Mnemonics.setLocalizedText(commentLabel, Bundle.OccurrencePanel_commonPropertyCommentLabel_text());
189 addItemToBag(gridY, 0, 0, VERTICAL_GAP, commentLabel);
190 javax.swing.JTextArea commentValue =
new javax.swing.JTextArea();
191 commentValue.setText(comment);
192 commentValue.setEditable(
false);
193 commentValue.setColumns(20);
194 commentValue.setLineWrap(
true);
195 commentValue.setRows(3);
196 commentValue.setTabSize(4);
197 commentValue.setWrapStyleWord(
true);
198 commentValue.setBorder(javax.swing.BorderFactory.createEtchedBorder());
199 commentValue.setBackground(javax.swing.UIManager.getDefaults().getColor(
"TextArea.disabledBackground"));
200 addItemToBag(gridY, 1, 0, VERTICAL_GAP, commentValue);
203 String caseDate =
"";
205 if (occurrence.isCentralRepoNode()) {
206 if (CentralRepository.isEnabled()) {
207 CorrelationCase partialCase = occurrence.getCorrelationAttributeInstance().getCorrelationCase();
208 caseDate = CentralRepository.getInstance().getCaseByUUID(partialCase.getCaseUUID()).getCreationDate();
211 caseDate = Case.getCurrentCase().getCreatedDate();
213 }
catch (CentralRepoException ex) {
214 LOGGER.log(Level.WARNING,
"Error getting case created date for other occurrence content viewer", ex);
217 caseNamesAndDates.put(occurrence.getCaseName(), caseDate);
218 dataSourceNames.add(occurrence.getDataSourceName());
219 filePaths.add(occurrence.getFilePath());
226 "OccurrencePanel.fileDetails.text=File Details",
227 "OccurrencePanel.filePathLabel.text=File Path:"
232 private void addFileDetails() {
233 String filePath = filePaths.size() > 1 ?
"" : filePaths.iterator().next();
234 if (!filePath.isEmpty()) {
235 javax.swing.JLabel fileDetailsLabel =
new javax.swing.JLabel();
236 org.openide.awt.Mnemonics.setLocalizedText(fileDetailsLabel, Bundle.OccurrencePanel_fileDetails_text());
237 fileDetailsLabel.setFont(fileDetailsLabel.getFont().deriveFont(Font.BOLD, fileDetailsLabel.getFont().getSize()));
238 addItemToBag(gridY, 0, TOP_INSET, 0, fileDetailsLabel);
240 javax.swing.JLabel filePathLabel =
new javax.swing.JLabel();
241 org.openide.awt.Mnemonics.setLocalizedText(filePathLabel, Bundle.OccurrencePanel_filePathLabel_text());
242 addItemToBag(gridY, 0, VERTICAL_GAP, VERTICAL_GAP, filePathLabel);
243 javax.swing.JTextArea filePathValue =
new javax.swing.JTextArea();
244 filePathValue.setText(filePath);
245 filePathValue.setEditable(
false);
246 filePathValue.setColumns(20);
247 filePathValue.setLineWrap(
true);
248 filePathValue.setRows(3);
249 filePathValue.setTabSize(4);
250 filePathValue.setWrapStyleWord(
true);
251 filePathValue.setBorder(javax.swing.BorderFactory.createEtchedBorder());
252 filePathValue.setBackground(javax.swing.UIManager.getDefaults().getColor(
"TextArea.disabledBackground"));
253 addItemToBag(gridY, 1, VERTICAL_GAP, VERTICAL_GAP, filePathValue);
259 "OccurrencePanel.dataSourceDetails.text=Data Source Details",
260 "OccurrencePanel.dataSourceNameLabel.text=Name:"
266 private void addDataSourceDetails() {
267 String dataSourceName = dataSourceNames.size() > 1 ?
"" : dataSourceNames.iterator().next();
268 if (!dataSourceName.isEmpty()) {
269 javax.swing.JLabel dataSourceDetailsLabel =
new javax.swing.JLabel();
270 org.openide.awt.Mnemonics.setLocalizedText(dataSourceDetailsLabel, Bundle.OccurrencePanel_dataSourceDetails_text());
271 dataSourceDetailsLabel.setFont(dataSourceDetailsLabel.getFont().deriveFont(Font.BOLD, dataSourceDetailsLabel.getFont().getSize()));
272 addItemToBag(gridY, 0, TOP_INSET, 0, dataSourceDetailsLabel);
274 javax.swing.JLabel dataSourceNameLabel =
new javax.swing.JLabel();
275 org.openide.awt.Mnemonics.setLocalizedText(dataSourceNameLabel, Bundle.OccurrencePanel_dataSourceNameLabel_text());
276 addItemToBag(gridY, 0, VERTICAL_GAP, VERTICAL_GAP, dataSourceNameLabel);
277 javax.swing.JLabel dataSourceNameValue =
new javax.swing.JLabel();
278 dataSourceNameValue.setText(dataSourceName);
279 addItemToBag(gridY, 1, VERTICAL_GAP, VERTICAL_GAP, dataSourceNameValue);
285 "OccurrencePanel.caseDetails.text=Case Details",
286 "OccurrencePanel.caseNameLabel.text=Name:",
287 "OccurrencePanel.caseCreatedDateLabel.text=Created Date:"
292 private void addCaseDetails() {
293 javax.swing.JLabel caseDetailsLabel =
new javax.swing.JLabel();
294 org.openide.awt.Mnemonics.setLocalizedText(caseDetailsLabel, Bundle.OccurrencePanel_caseDetails_text());
295 caseDetailsLabel.setFont(caseDetailsLabel.getFont().deriveFont(Font.BOLD, caseDetailsLabel.getFont().getSize()));
296 addItemToBag(gridY, 0, TOP_INSET, 0, caseDetailsLabel);
298 String caseName = caseNamesAndDates.keySet().size() > 1 ?
"" : caseNamesAndDates.keySet().iterator().next();
299 if (!caseName.isEmpty()) {
300 javax.swing.JLabel caseNameLabel =
new javax.swing.JLabel();
301 org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, Bundle.OccurrencePanel_caseNameLabel_text());
302 addItemToBag(gridY, 0, VERTICAL_GAP, 0, caseNameLabel);
303 javax.swing.JLabel caseNameValue =
new javax.swing.JLabel();
304 caseNameValue.setText(caseName);
305 addItemToBag(gridY, 1, VERTICAL_GAP, 0, caseNameValue);
308 String caseCreatedDate = caseNamesAndDates.keySet().size() > 1 ?
"" : caseNamesAndDates.get(caseName);
309 if (caseCreatedDate != null && !caseCreatedDate.isEmpty()) {
310 javax.swing.JLabel caseCreatedLabel =
new javax.swing.JLabel();
311 org.openide.awt.Mnemonics.setLocalizedText(caseCreatedLabel, Bundle.OccurrencePanel_caseCreatedDateLabel_text());
312 addItemToBag(gridY, 0, 0, BOTTOM_INSET, caseCreatedLabel);
313 javax.swing.JLabel caseCreatedValue =
new javax.swing.JLabel();
314 caseCreatedValue.setText(caseCreatedDate);
315 addItemToBag(gridY, 1, 0, BOTTOM_INSET, caseCreatedValue);
330 private void addItemToBag(
int gridYLocation,
int gridXLocation,
int topInset,
int bottomInset, javax.swing.JComponent item) {
331 java.awt.GridBagConstraints gridBagConstraints;
332 gridBagConstraints =
new java.awt.GridBagConstraints();
333 gridBagConstraints.gridx = gridXLocation;
334 gridBagConstraints.gridy = gridYLocation;
335 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
336 gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
337 int leftInset = LEFT_INSET;
338 int rightInset = HORIZONTAL_GAP;
340 if (gridXLocation == 1) {
342 rightInset = RIGHT_INSET;
343 gridBagConstraints.weightx = 0.1;
344 gridBagConstraints.gridwidth = 2;
346 gridBagConstraints.insets =
new java.awt.Insets(topInset, leftInset, bottomInset, rightInset);
348 if (item instanceof javax.swing.Box.Filler) {
349 gridBagConstraints.weighty = 0.1;
351 add(item, gridBagConstraints);
359 @SuppressWarnings(
"unchecked")
361 private
void initComponents() {
363 setMinimumSize(
new java.awt.Dimension(50, 30));
364 setPreferredSize(null);
365 setLayout(
new java.awt.GridBagLayout());