Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommunicationArtifactViewerHelper.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2020-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 */
19package org.sleuthkit.autopsy.contentviewers.artifactviewers;
20
21import java.awt.Dimension;
22import java.awt.GridBagConstraints;
23import java.awt.GridBagLayout;
24import java.awt.Insets;
25import java.awt.Toolkit;
26import java.awt.datatransfer.StringSelection;
27import java.awt.event.ActionEvent;
28import java.awt.event.ActionListener;
29import java.util.ArrayList;
30import java.util.List;
31import javax.swing.JLabel;
32import javax.swing.JMenuItem;
33import javax.swing.JComponent;
34import javax.swing.JPanel;
35import javax.swing.JPopupMenu;
36import javax.swing.JTextPane;
37import javax.swing.SwingUtilities;
38import org.openide.util.NbBundle;
39import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
40import org.sleuthkit.autopsy.contentviewers.layout.ContentViewerDefaults;
41
47final class CommunicationArtifactViewerHelper {
48
49 // Number of columns in the gridbag layout.
50 private final static int MAX_COLS = 4;
51
55 private CommunicationArtifactViewerHelper() {
56
57 }
58
70 static JLabel addHeader(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, int topSpacing, String headerString) {
71
72 Insets savedInsets = constraints.insets;
73
74 // create label for heading
75 javax.swing.JLabel headingLabel = new javax.swing.JLabel();
76
77
78 constraints.gridy++;
79 constraints.gridx = 0;
80
81 // let the header span all of the row
82 constraints.gridwidth = MAX_COLS;
83 constraints.anchor = GridBagConstraints.LINE_START;
84 constraints.fill = GridBagConstraints.NONE;
85
86 constraints.insets = new Insets(topSpacing, 0, ContentViewerDefaults.getLineSpacing(), 0);
87
88 // set text
89 headingLabel.setText(headerString.trim());
90
91 // make it large and bold
92 headingLabel.setFont(ContentViewerDefaults.getHeaderFont());
93
94 // add to panel
95 gridbagLayout.setConstraints(headingLabel, constraints);
96 panel.add(headingLabel);
97
98 // reset constraints to normal
99 constraints.gridwidth = 1;
100
101 // add line end glue
102 addLineEndGlue(panel, gridbagLayout, constraints);
103
104 //restore insets
105 constraints.insets = savedInsets;
106
107 return headingLabel;
108 }
109
122 static void addNameValueRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString, String valueString) {
123 addKey(panel, gridbagLayout, constraints, keyString);
124 addValue(panel, gridbagLayout, constraints, valueString);
125 }
126
137 static void addComponent(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, JComponent component) {
138
139 // add to panel
140 gridbagLayout.setConstraints(component, constraints);
141 panel.add(component);
142 }
143
152 static void addLineEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
153 // Place the filler just past the last column.
154 constraints.gridx = MAX_COLS;
155
156 double savedWeightX = constraints.weightx;
157 int savedFill = constraints.fill;
158
159 constraints.weightx = 1.0; // take up all the horizontal space
160 constraints.fill = GridBagConstraints.HORIZONTAL;
161
162 javax.swing.Box.Filler horizontalFiller = new javax.swing.Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(32767, 0));
163 gridbagLayout.setConstraints(horizontalFiller, constraints);
164 panel.add(horizontalFiller);
165
166 // restore fill & weight
167 constraints.fill = savedFill;
168 constraints.weightx = savedWeightX;
169 }
170
179 static void addPageEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
180
181 constraints.gridx = 0;
182 constraints.gridy++;
183
184 double savedWeighty = constraints.weighty;
185 int savedFill = constraints.fill;
186
187 constraints.weighty = 1.0; // take up all the vertical space
188 constraints.fill = GridBagConstraints.VERTICAL;
189
190 javax.swing.Box.Filler vertFiller = new javax.swing.Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(0, 32767));
191 gridbagLayout.setConstraints(vertFiller, constraints);
192 panel.add(vertFiller, constraints);
193
194 //Resore weight & fill
195 constraints.weighty = savedWeighty;
196 constraints.fill = savedFill;
197 }
198
209 static JLabel addKey(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString) {
210 return addKeyAtCol(panel, gridbagLayout, constraints, keyString, 0);
211 }
212
224 static JLabel addKeyAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString, int gridx) {
225
226 // create label
227 javax.swing.JLabel keyLabel = new javax.swing.JLabel();
228
229 constraints.gridy++;
230 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
231 constraints.anchor = GridBagConstraints.LINE_START;
232 constraints.insets = new Insets(0, ContentViewerDefaults.getSectionIndent(), ContentViewerDefaults.getLineSpacing(), 0);
233
234 // set text
235 String preppedKeyString = keyString == null ? null : keyString.trim() + ":";
236 keyLabel.setText(preppedKeyString);
237
238 // add to panel
239 gridbagLayout.setConstraints(keyLabel, constraints);
240 panel.add(keyLabel);
241
242 return keyLabel;
243 }
244
255 static JTextPane addValue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString) {
256 return addValueAtCol(panel, gridbagLayout, constraints, valueString, 1);
257 }
258
270 static JTextPane addValueAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString, int gridx) {
271 // create label,
272 JTextPane valueField = new JTextPane();
273 valueField.setEditable(false);
274 valueField.setOpaque(false);
275 valueField.setMargin(new Insets(0,0,0,0));
276
277 constraints.gridx = gridx < MAX_COLS ? gridx : MAX_COLS - 1;
278
279 GridBagConstraints cloneConstraints = (GridBagConstraints) constraints.clone();
280
281 // let the value span 2 cols
282 cloneConstraints.gridwidth = 2;
283 constraints.anchor = GridBagConstraints.LINE_START;
284 cloneConstraints.insets = new Insets(0, ContentViewerDefaults.getColumnSpacing(), ContentViewerDefaults.getLineSpacing(), 0);
285
286 // set text
287 valueField.setText(valueString);
288
289 // attach a right click menu with Copy option
290 valueField.addMouseListener(new java.awt.event.MouseAdapter() {
291 @Override
292 public void mouseClicked(java.awt.event.MouseEvent evt) {
293 valueLabelMouseClicked(evt, valueField);
294 }
295 });
296
297 // add label to panel
298 gridbagLayout.setConstraints(valueField, cloneConstraints);
299 panel.add(valueField);
300
301 // end the line
302 addLineEndGlue(panel, gridbagLayout, constraints);
303
304 return valueField;
305 }
306
319 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, Insets insets, GridBagConstraints constraints, String messageString) {
320 return addMessageRow(panel, gridbagLayout, constraints, insets, messageString, 0);
321 }
322
337 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, Insets insets, String messageString, int gridx) {
338
339 // create label
340 javax.swing.JLabel messageLabel = new javax.swing.JLabel();
341
342 constraints.gridy++;
343 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
344 constraints.insets = insets == null
345 ? new Insets(0, 0, ContentViewerDefaults.getLineSpacing(), 0) :
346 insets;
347 constraints.anchor = GridBagConstraints.LINE_START;
348
349 int savedGridwidth = constraints.gridwidth;
350
351 constraints.gridwidth = 3;
352
353 // set text
354 messageLabel.setText(messageString == null ? null : messageString.trim());
355 messageLabel.setFont(ContentViewerDefaults.getMessageFont());
356
357 // add to panel
358 gridbagLayout.setConstraints(messageLabel, constraints);
359 panel.add(messageLabel);
360
361 addLineEndGlue(panel, gridbagLayout, constraints);
362
363 // restore constraints
364 constraints.gridwidth = savedGridwidth;
365
366 return messageLabel;
367 }
368
385 @NbBundle.Messages({
386 "CommunicationArtifactViewerHelper_persona_label=Persona: ",
387 "CommunicationArtifactViewerHelper_persona_searching=Searching...",
388 "CommunicationArtifactViewerHelper_persona_unknown=Unknown",
389 "CommunicationArtifactViewerHelper_persona_button_view=View",
390 "CommunicationArtifactViewerHelper_persona_button_create=Create"
391 })
392
393 static List<AccountPersonaSearcherData> addPersonaRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String accountIdentifier) {
394 List<AccountPersonaSearcherData> dataList = new ArrayList<>();
395
396 constraints.gridy++;
397 constraints.gridx = 1;
398
399 Insets savedInsets = constraints.insets;
400
401 // extra Indent in
402 constraints.insets = new java.awt.Insets(0, ContentViewerDefaults.getColumnSpacing(), ContentViewerDefaults.getLineSpacing(), 0);
403 constraints.anchor = GridBagConstraints.LINE_START;
404
405 // create label
406 javax.swing.JLabel personaLabel = new javax.swing.JLabel();
407 String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
408 personaLabelText = personaLabelText.concat(CentralRepository.isEnabled()
409 ? Bundle.CommunicationArtifactViewerHelper_persona_searching()
410 : Bundle.CommunicationArtifactViewerHelper_persona_unknown());
411
412 personaLabel.setText(personaLabelText == null ? null : personaLabelText.trim());
413
414 // add to panel
415 gridbagLayout.setConstraints(personaLabel, constraints);
416 panel.add(personaLabel);
417
418 constraints.gridx++;
419
420 // Place a button as place holder. It will be enabled when persona is available.
421 javax.swing.JButton personaButton = new javax.swing.JButton();
422 personaButton.setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
423 personaButton.setMargin(new Insets(0, 5, 0, 5));
424 personaButton.setEnabled(false);
425
426 gridbagLayout.setConstraints(personaButton, constraints);
427 panel.add(personaButton);
428
430 // kick off a task to find the persona for this account
431 dataList.add(new AccountPersonaSearcherData(accountIdentifier, personaLabel, personaButton));
432 } else {
433 personaLabel.setEnabled(false);
434 }
435
436 // restore constraint
437 constraints.insets = savedInsets;
438
439 addLineEndGlue(panel, gridbagLayout, constraints);
440
441 return dataList;
442 }
443
454 @NbBundle.Messages({
455 "# {0} - contact name",
456 "CommunicationArtifactViewerHelper_contact_label=Contact: {0}",
457 "CommunicationArtifactViewerHelper_contact_label_unknown=Unknown"
458 })
459 static JComponent addContactRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String contactId) {
460 // Increase the y value because we are not calling the addKey
461 constraints.gridy++;
462 //Don't change the origian constraints, just make a copy to modify
463 GridBagConstraints indentedConstraints = (GridBagConstraints) constraints.clone();
464
465 // Add an indent to match persona labels
466 indentedConstraints.insets = new java.awt.Insets(0, ContentViewerDefaults.getSectionIndent(), ContentViewerDefaults.getLineSpacing(), 0);
467
468 String contactInfo = Bundle.CommunicationArtifactViewerHelper_contact_label(contactId != null && !contactId.isEmpty() ? contactId : Bundle.CommunicationArtifactViewerHelper_contact_label_unknown());
469
470 return addValueAtCol(panel, gridbagLayout, indentedConstraints, contactInfo, 1);
471 }
472
480 @NbBundle.Messages({
481 "CommunicationArtifactViewerHelper_menuitem_copy=Copy"
482 })
483 private static void valueLabelMouseClicked(java.awt.event.MouseEvent evt, JTextPane valueLabel) {
484 if (SwingUtilities.isRightMouseButton(evt)) {
485 JPopupMenu popup = new JPopupMenu();
486
487 JMenuItem copyMenu = new JMenuItem(Bundle.CommunicationArtifactViewerHelper_menuitem_copy()); // NON-NLS
488 copyMenu.addActionListener(new ActionListener() {
489 @Override
490 public void actionPerformed(ActionEvent e) {
491 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(valueLabel.getText()), null);
492 }
493 });
494
495 popup.add(copyMenu);
496 popup.show(valueLabel, evt.getX(), evt.getY());
497 }
498 }
499}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.