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.SwingUtilities;
38 import org.openide.util.NbBundle;
46 final class CommunicationArtifactViewerHelper {
49 private final static int MAX_COLS = 4;
51 final static int LEFT_INSET = 12;
56 private CommunicationArtifactViewerHelper() {
70 static JLabel addHeader(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String headerString) {
72 Insets savedInsets = constraints.insets;
75 javax.swing.JLabel headingLabel =
new javax.swing.JLabel();
79 if (constraints.gridy != 0) {
80 addBlankLine(panel, gridbagLayout, constraints);
83 constraints.gridx = 0;
86 constraints.gridwidth = MAX_COLS;
87 constraints.insets =
new Insets(0, 0, 0, 0);
90 headingLabel.setText(headerString);
93 headingLabel.setFont(headingLabel.getFont().deriveFont(Font.BOLD, headingLabel.getFont().getSize() + 2));
96 gridbagLayout.setConstraints(headingLabel, constraints);
97 panel.add(headingLabel);
100 constraints.gridwidth = 1;
103 addLineEndGlue(panel, gridbagLayout, constraints);
106 constraints.insets = savedInsets;
121 static void addComponent(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, JComponent component) {
124 gridbagLayout.setConstraints(component, constraints);
125 panel.add(component);
136 static void addLineEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
138 constraints.gridx = MAX_COLS;
140 double savedWeightX = constraints.weightx;
141 int savedFill = constraints.fill;
143 constraints.weightx = 1.0;
144 constraints.fill = GridBagConstraints.BOTH;
146 javax.swing.Box.Filler horizontalFiller =
new javax.swing.Box.Filler(
new Dimension(0, 0),
new Dimension(0, 0),
new Dimension(32767, 0));
147 gridbagLayout.setConstraints(horizontalFiller, constraints);
148 panel.add(horizontalFiller);
151 constraints.fill = savedFill;
152 constraints.weightx = savedWeightX;
163 static void addPageEndGlue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
165 constraints.gridx = 0;
167 double savedWeighty = constraints.weighty;
168 int savedFill = constraints.fill;
170 constraints.weighty = 1.0;
171 constraints.fill = GridBagConstraints.VERTICAL;
173 javax.swing.Box.Filler vertFiller =
new javax.swing.Box.Filler(
new Dimension(0, 0),
new Dimension(0, 0),
new Dimension(0, 32767));
174 gridbagLayout.setConstraints(vertFiller, constraints);
175 panel.add(vertFiller, constraints);
178 constraints.weighty = savedWeighty;
179 constraints.fill = savedFill;
189 static void addBlankLine(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints) {
191 constraints.gridx = 0;
193 javax.swing.JLabel filler =
new javax.swing.JLabel(
" ");
194 gridbagLayout.setConstraints(filler, constraints);
197 addLineEndGlue(panel, gridbagLayout, constraints);
210 static JLabel addKey(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString) {
211 return addKeyAtCol(panel, gridbagLayout, constraints, keyString, 0);
225 static JLabel addKeyAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String keyString,
int gridx) {
228 javax.swing.JLabel keyLabel =
new javax.swing.JLabel();
231 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
234 keyLabel.setText(keyString +
": ");
237 gridbagLayout.setConstraints(keyLabel, constraints);
253 static JLabel addValue(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString) {
254 return addValueAtCol(panel, gridbagLayout, constraints, valueString, 1);
268 static JLabel addValueAtCol(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String valueString,
int gridx) {
270 javax.swing.JLabel valueField =
new javax.swing.JLabel();
272 constraints.gridx = gridx < MAX_COLS ? gridx : MAX_COLS - 1;
274 int savedGridwidth = constraints.gridwidth;
277 constraints.gridwidth = 2;
280 valueField.setText(valueString);
283 valueField.addMouseListener(
new java.awt.event.MouseAdapter() {
285 public void mouseClicked(java.awt.event.MouseEvent evt) {
286 valueLabelMouseClicked(evt, valueField);
291 gridbagLayout.setConstraints(valueField, constraints);
292 panel.add(valueField);
295 constraints.gridwidth = savedGridwidth;
298 addLineEndGlue(panel, gridbagLayout, constraints);
315 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String messageString) {
316 return addMessageRow(panel, gridbagLayout, constraints, messageString, 0);
331 static JLabel addMessageRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String messageString,
int gridx) {
334 javax.swing.JLabel messageLabel =
new javax.swing.JLabel();
337 constraints.gridx = gridx < MAX_COLS - 1 ? gridx : MAX_COLS - 2;
339 int savedGridwidth = constraints.gridwidth;
341 constraints.gridwidth = 3;
344 messageLabel.setText(messageString);
347 gridbagLayout.setConstraints(messageLabel, constraints);
348 panel.add(messageLabel);
350 addLineEndGlue(panel, gridbagLayout, constraints);
353 constraints.gridwidth = savedGridwidth;
375 "CommunicationArtifactViewerHelper_persona_label=Persona: ",
376 "CommunicationArtifactViewerHelper_persona_searching=Searching...",
377 "CommunicationArtifactViewerHelper_persona_unknown=Unknown",
378 "CommunicationArtifactViewerHelper_persona_button_view=View",
379 "CommunicationArtifactViewerHelper_persona_button_create=Create"
382 static List<AccountPersonaSearcherData> addPersonaRow(JPanel panel, GridBagLayout gridbagLayout, GridBagConstraints constraints, String accountIdentifier) {
383 List<AccountPersonaSearcherData> dataList =
new ArrayList<>();
386 constraints.gridx = 1;
388 Insets savedInsets = constraints.insets;
391 constraints.insets =
new java.awt.Insets(0, 2 * LEFT_INSET, 0, 0);
394 javax.swing.JLabel personaLabel =
new javax.swing.JLabel();
395 String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
396 personaLabelText = personaLabelText.concat(CentralRepository.isEnabled()
397 ? Bundle.CommunicationArtifactViewerHelper_persona_searching()
398 : Bundle.CommunicationArtifactViewerHelper_persona_unknown());
400 personaLabel.setText(personaLabelText);
403 gridbagLayout.setConstraints(personaLabel, constraints);
404 panel.add(personaLabel);
407 constraints.insets = savedInsets;
412 javax.swing.JButton personaButton =
new javax.swing.JButton();
413 personaButton.setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
414 personaButton.setMargin(
new Insets(0, 5, 0, 5));
415 personaButton.setEnabled(
false);
417 gridbagLayout.setConstraints(personaButton, constraints);
418 panel.add(personaButton);
420 if (CentralRepository.isEnabled()) {
422 dataList.add(
new AccountPersonaSearcherData(accountIdentifier, personaLabel, personaButton));
424 personaLabel.setEnabled(
false);
427 addLineEndGlue(panel, gridbagLayout, constraints);
440 "CommunicationArtifactViewerHelper_menuitem_copy=Copy"
442 private static void valueLabelMouseClicked(java.awt.event.MouseEvent evt, JLabel valueLabel) {
443 if (SwingUtilities.isRightMouseButton(evt)) {
444 JPopupMenu popup =
new JPopupMenu();
446 JMenuItem copyMenu =
new JMenuItem(Bundle.CommunicationArtifactViewerHelper_menuitem_copy());
447 copyMenu.addActionListener(
new ActionListener() {
449 public void actionPerformed(ActionEvent e) {
450 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(valueLabel.getText()), null);
456 popup.show(valueLabel, evt.getX(), evt.getY());