19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.awt.Dimension;
22 import java.awt.GridBagConstraints;
23 import java.awt.GridBagLayout;
24 import java.awt.Insets;
25 import java.awt.Toolkit;
26 import java.awt.datatransfer.StringSelection;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.ArrayList;
30 import java.util.List;
31 import javax.swing.JLabel;
32 import javax.swing.JMenuItem;
33 import javax.swing.JComponent;
34 import javax.swing.JPanel;
35 import javax.swing.JPopupMenu;
36 import javax.swing.JTextPane;
37 import javax.swing.SwingUtilities;
38 import org.openide.util.NbBundle;
47 final class CommunicationArtifactViewerHelper {
50 private final static int MAX_COLS = 4;
55 private CommunicationArtifactViewerHelper() {
70 static JLabel addHeader(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints,
int topSpacing, String headerString) {
72 Insets savedInsets = constraints.insets;
75 javax.swing.JLabel headingLabel =
new javax.swing.JLabel();
79 constraints.gridx = 0;
82 constraints.gridwidth = MAX_COLS;
83 constraints.anchor = GridBagConstraints.LINE_START;
84 constraints.fill = GridBagConstraints.NONE;
86 constraints.insets =
new Insets(topSpacing, 0, ContentViewerDefaults.getLineSpacing(), 0);
89 headingLabel.setText(headerString.trim());
92 headingLabel.setFont(ContentViewerDefaults.getHeaderFont());
95 gridbagLayout.setConstraints(headingLabel, constraints);
96 panel.add(headingLabel);
99 constraints.gridwidth = 1;
102 addLineEndGlue(panel, gridbagLayout, constraints);
105 constraints.insets = savedInsets;
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);
137 static void addComponent(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, JComponent component) {
140 gridbagLayout.setConstraints(component, constraints);
141 panel.add(component);
152 static void addLineEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
154 constraints.gridx = MAX_COLS;
156 double savedWeightX = constraints.weightx;
157 int savedFill = constraints.fill;
159 constraints.weightx = 1.0;
160 constraints.fill = GridBagConstraints.HORIZONTAL;
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);
167 constraints.fill = savedFill;
168 constraints.weightx = savedWeightX;
179 static void addPageEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
181 constraints.gridx = 0;
184 double savedWeighty = constraints.weighty;
185 int savedFill = constraints.fill;
187 constraints.weighty = 1.0;
188 constraints.fill = GridBagConstraints.VERTICAL;
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);
195 constraints.weighty = savedWeighty;
196 constraints.fill = savedFill;
209 static JLabel addKey(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString) {
210 return addKeyAtCol(panel, gridbagLayout, constraints, keyString, 0);
224 static JLabel addKeyAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString,
int gridx) {
227 javax.swing.JLabel keyLabel =
new javax.swing.JLabel();
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);
235 String preppedKeyString = keyString == null ? null : keyString.trim() +
":";
236 keyLabel.setText(preppedKeyString);
239 gridbagLayout.setConstraints(keyLabel, constraints);
255 static JTextPane addValue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString) {
256 return addValueAtCol(panel, gridbagLayout, constraints, valueString, 1);
270 static JTextPane addValueAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString,
int gridx) {
272 JTextPane valueField =
new JTextPane();
273 valueField.setEditable(
false);
274 valueField.setOpaque(
false);
275 valueField.setMargin(
new Insets(0,0,0,0));
277 constraints.gridx = gridx < MAX_COLS ? gridx : MAX_COLS - 1;
279 GridBagConstraints cloneConstraints = (GridBagConstraints) constraints.clone();
282 cloneConstraints.gridwidth = 2;
283 constraints.anchor = GridBagConstraints.LINE_START;
284 cloneConstraints.insets =
new Insets(0, ContentViewerDefaults.getColumnSpacing(), ContentViewerDefaults.getLineSpacing(), 0);
287 valueField.setText(valueString);
290 valueField.addMouseListener(
new java.awt.event.MouseAdapter() {
292 public void mouseClicked(java.awt.event.MouseEvent evt) {
293 valueLabelMouseClicked(evt, valueField);
298 gridbagLayout.setConstraints(valueField, cloneConstraints);
299 panel.add(valueField);
302 addLineEndGlue(panel, gridbagLayout, constraints);
319 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, Insets insets, GridBagConstraints constraints, String messageString) {
320 return addMessageRow(panel, gridbagLayout, constraints, insets, messageString, 0);
337 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, Insets insets, String messageString,
int gridx) {
340 javax.swing.JLabel messageLabel =
new javax.swing.JLabel();
343 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
344 constraints.insets = insets == null
345 ?
new Insets(0, 0, ContentViewerDefaults.getLineSpacing(), 0) :
347 constraints.anchor = GridBagConstraints.LINE_START;
349 int savedGridwidth = constraints.gridwidth;
351 constraints.gridwidth = 3;
354 messageLabel.setText(messageString == null ? null : messageString.trim());
355 messageLabel.setFont(ContentViewerDefaults.getMessageFont());
358 gridbagLayout.setConstraints(messageLabel, constraints);
359 panel.add(messageLabel);
361 addLineEndGlue(panel, gridbagLayout, constraints);
364 constraints.gridwidth = savedGridwidth;
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"
393 static List<AccountPersonaSearcherData> addPersonaRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String accountIdentifier) {
394 List<AccountPersonaSearcherData> dataList =
new ArrayList<>();
397 constraints.gridx = 1;
399 Insets savedInsets = constraints.insets;
402 constraints.insets =
new java.awt.Insets(0, ContentViewerDefaults.getColumnSpacing(), ContentViewerDefaults.getLineSpacing(), 0);
403 constraints.anchor = GridBagConstraints.LINE_START;
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());
412 personaLabel.setText(personaLabelText == null ? null : personaLabelText.trim());
415 gridbagLayout.setConstraints(personaLabel, constraints);
416 panel.add(personaLabel);
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);
426 gridbagLayout.setConstraints(personaButton, constraints);
427 panel.add(personaButton);
429 if (CentralRepository.isEnabled()) {
431 dataList.add(
new AccountPersonaSearcherData(accountIdentifier, personaLabel, personaButton));
433 personaLabel.setEnabled(
false);
437 constraints.insets = savedInsets;
439 addLineEndGlue(panel, gridbagLayout, constraints);
455 "# {0} - contact name",
456 "CommunicationArtifactViewerHelper_contact_label=Contact: {0}",
457 "CommunicationArtifactViewerHelper_contact_label_unknown=Unknown"
459 static JComponent addContactRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String contactId) {
463 GridBagConstraints indentedConstraints = (GridBagConstraints) constraints.clone();
466 indentedConstraints.insets =
new java.awt.Insets(0, ContentViewerDefaults.getSectionIndent(), ContentViewerDefaults.getLineSpacing(), 0);
468 String contactInfo = Bundle.CommunicationArtifactViewerHelper_contact_label(contactId != null && !contactId.isEmpty() ? contactId : Bundle.CommunicationArtifactViewerHelper_contact_label_unknown());
470 return addValueAtCol(panel, gridbagLayout, indentedConstraints, contactInfo, 1);
481 "CommunicationArtifactViewerHelper_menuitem_copy=Copy"
483 private static void valueLabelMouseClicked(java.awt.event.MouseEvent evt, JTextPane valueLabel) {
484 if (SwingUtilities.isRightMouseButton(evt)) {
485 JPopupMenu popup =
new JPopupMenu();
487 JMenuItem copyMenu =
new JMenuItem(Bundle.CommunicationArtifactViewerHelper_menuitem_copy());
488 copyMenu.addActionListener(
new ActionListener() {
490 public void actionPerformed(ActionEvent e) {
491 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(valueLabel.getText()), null);
496 popup.show(valueLabel, evt.getX(), evt.getY());