19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.awt.Dimension;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.Toolkit;
27 import java.awt.datatransfer.StringSelection;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.util.ArrayList;
31 import java.util.List;
32 import javax.swing.JLabel;
33 import javax.swing.JMenuItem;
34 import javax.swing.JComponent;
35 import javax.swing.JPanel;
36 import javax.swing.JPopupMenu;
37 import javax.swing.JTextPane;
38 import javax.swing.SwingUtilities;
39 import org.openide.util.NbBundle;
47 final class CommunicationArtifactViewerHelper {
50 private final static int MAX_COLS = 4;
52 final static int LEFT_INSET = 12;
57 private CommunicationArtifactViewerHelper() {
71 static JLabel addHeader(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String headerString) {
73 Insets savedInsets = constraints.insets;
76 javax.swing.JLabel headingLabel =
new javax.swing.JLabel();
80 if (constraints.gridy != 0) {
81 addBlankLine(panel, gridbagLayout, constraints);
84 constraints.gridx = 0;
87 constraints.gridwidth = MAX_COLS;
88 constraints.insets =
new Insets(0, 0, 0, 0);
91 headingLabel.setText(headerString);
94 headingLabel.setFont(headingLabel.getFont().deriveFont(Font.BOLD, headingLabel.getFont().getSize() + 2));
97 gridbagLayout.setConstraints(headingLabel, constraints);
98 panel.add(headingLabel);
101 constraints.gridwidth = 1;
104 addLineEndGlue(panel, gridbagLayout, constraints);
107 constraints.insets = savedInsets;
124 static void addNameValueRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString, String valueString) {
125 addKey(panel, gridbagLayout, constraints, keyString);
126 addValue(panel, gridbagLayout, constraints, valueString);
139 static void addComponent(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, JComponent component) {
142 gridbagLayout.setConstraints(component, constraints);
143 panel.add(component);
154 static void addLineEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
156 constraints.gridx = MAX_COLS;
158 double savedWeightX = constraints.weightx;
159 int savedFill = constraints.fill;
161 constraints.weightx = 1.0;
162 constraints.fill = GridBagConstraints.BOTH;
164 javax.swing.Box.Filler horizontalFiller =
new javax.swing.Box.Filler(
new Dimension(0, 0),
new Dimension(0, 0),
new Dimension(32767, 0));
165 gridbagLayout.setConstraints(horizontalFiller, constraints);
166 panel.add(horizontalFiller);
169 constraints.fill = savedFill;
170 constraints.weightx = savedWeightX;
181 static void addPageEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
183 constraints.gridx = 0;
185 double savedWeighty = constraints.weighty;
186 int savedFill = constraints.fill;
188 constraints.weighty = 1.0;
189 constraints.fill = GridBagConstraints.VERTICAL;
191 javax.swing.Box.Filler vertFiller =
new javax.swing.Box.Filler(
new Dimension(0, 0),
new Dimension(0, 0),
new Dimension(0, 32767));
192 gridbagLayout.setConstraints(vertFiller, constraints);
193 panel.add(vertFiller, constraints);
196 constraints.weighty = savedWeighty;
197 constraints.fill = savedFill;
207 static void addBlankLine(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
209 constraints.gridx = 0;
211 javax.swing.JLabel filler =
new javax.swing.JLabel(
" ");
212 gridbagLayout.setConstraints(filler, constraints);
215 addLineEndGlue(panel, gridbagLayout, constraints);
228 static JLabel addKey(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString) {
229 return addKeyAtCol(panel, gridbagLayout, constraints, keyString, 0);
243 static JLabel addKeyAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString,
int gridx) {
246 javax.swing.JLabel keyLabel =
new javax.swing.JLabel();
249 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
252 keyLabel.setText(keyString +
": ");
255 gridbagLayout.setConstraints(keyLabel, constraints);
271 static JTextPane addValue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString) {
272 return addValueAtCol(panel, gridbagLayout, constraints, valueString, 1);
286 static JTextPane addValueAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString,
int gridx) {
288 JTextPane valueField =
new JTextPane();
289 valueField.setEditable(
false);
290 valueField.setOpaque(
false);
292 constraints.gridx = gridx < MAX_COLS ? gridx : MAX_COLS - 1;
294 GridBagConstraints cloneConstraints = (GridBagConstraints) constraints.clone();
297 cloneConstraints.gridwidth = 2;
298 cloneConstraints.fill = GridBagConstraints.BOTH;
301 valueField.setText(valueString);
304 valueField.addMouseListener(
new java.awt.event.MouseAdapter() {
306 public void mouseClicked(java.awt.event.MouseEvent evt) {
307 valueLabelMouseClicked(evt, valueField);
312 gridbagLayout.setConstraints(valueField, cloneConstraints);
313 panel.add(valueField);
316 addLineEndGlue(panel, gridbagLayout, constraints);
333 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String messageString) {
334 return addMessageRow(panel, gridbagLayout, constraints, messageString, 0);
349 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String messageString,
int gridx) {
352 javax.swing.JLabel messageLabel =
new javax.swing.JLabel();
355 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
357 int savedGridwidth = constraints.gridwidth;
359 constraints.gridwidth = 3;
362 messageLabel.setText(messageString);
365 gridbagLayout.setConstraints(messageLabel, constraints);
366 panel.add(messageLabel);
368 addLineEndGlue(panel, gridbagLayout, constraints);
371 constraints.gridwidth = savedGridwidth;
393 "CommunicationArtifactViewerHelper_persona_label=Persona: ",
394 "CommunicationArtifactViewerHelper_persona_searching=Searching...",
395 "CommunicationArtifactViewerHelper_persona_unknown=Unknown",
396 "CommunicationArtifactViewerHelper_persona_button_view=View",
397 "CommunicationArtifactViewerHelper_persona_button_create=Create"
400 static List<AccountPersonaSearcherData> addPersonaRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String accountIdentifier) {
401 List<AccountPersonaSearcherData> dataList =
new ArrayList<>();
404 constraints.gridx = 1;
406 Insets savedInsets = constraints.insets;
409 constraints.insets =
new java.awt.Insets(0, 2 * LEFT_INSET, 0, 0);
412 javax.swing.JLabel personaLabel =
new javax.swing.JLabel();
413 String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
414 personaLabelText = personaLabelText.concat(CentralRepository.isEnabled()
415 ? Bundle.CommunicationArtifactViewerHelper_persona_searching()
416 : Bundle.CommunicationArtifactViewerHelper_persona_unknown());
418 personaLabel.setText(personaLabelText);
421 gridbagLayout.setConstraints(personaLabel, constraints);
422 panel.add(personaLabel);
425 constraints.insets = savedInsets;
430 javax.swing.JButton personaButton =
new javax.swing.JButton();
431 personaButton.setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
432 personaButton.setMargin(
new Insets(0, 5, 0, 5));
433 personaButton.setEnabled(
false);
435 gridbagLayout.setConstraints(personaButton, constraints);
436 panel.add(personaButton);
438 if (CentralRepository.isEnabled()) {
440 dataList.add(
new AccountPersonaSearcherData(accountIdentifier, personaLabel, personaButton));
442 personaLabel.setEnabled(
false);
445 addLineEndGlue(panel, gridbagLayout, constraints);
461 "# {0} - contact name",
462 "CommunicationArtifactViewerHelper_contact_label=Contact: {0}",
463 "CommunicationArtifactViewerHelper_contact_label_unknown=Unknown"
465 static JComponent addContactRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String contactId) {
469 GridBagConstraints indentedConstraints = (GridBagConstraints) constraints.clone();
472 indentedConstraints.insets =
new java.awt.Insets(0, 2 * LEFT_INSET, 0, 0);
474 String contactInfo = Bundle.CommunicationArtifactViewerHelper_contact_label(contactId != null && !contactId.isEmpty() ? contactId : Bundle.CommunicationArtifactViewerHelper_contact_label_unknown());
476 return addValueAtCol(panel, gridbagLayout, indentedConstraints, contactInfo, 1);
487 "CommunicationArtifactViewerHelper_menuitem_copy=Copy"
489 private static void valueLabelMouseClicked(java.awt.event.MouseEvent evt, JTextPane valueLabel) {
490 if (SwingUtilities.isRightMouseButton(evt)) {
491 JPopupMenu popup =
new JPopupMenu();
493 JMenuItem copyMenu =
new JMenuItem(Bundle.CommunicationArtifactViewerHelper_menuitem_copy());
494 copyMenu.addActionListener(
new ActionListener() {
496 public void actionPerformed(ActionEvent e) {
497 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(valueLabel.getText()), null);
502 popup.show(valueLabel, evt.getX(), evt.getY());