19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.awt.Dimension;
22 import java.awt.Insets;
23 import java.awt.Toolkit;
24 import java.awt.datatransfer.StringSelection;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.MouseAdapter;
28 import java.awt.event.MouseEvent;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.List;
32 import java.util.concurrent.CancellationException;
33 import java.util.concurrent.ExecutionException;
34 import java.util.logging.Level;
35 import javax.swing.GroupLayout;
36 import javax.swing.GroupLayout.Alignment;
37 import javax.swing.GroupLayout.ParallelGroup;
38 import javax.swing.GroupLayout.SequentialGroup;
39 import javax.swing.JButton;
40 import javax.swing.JLabel;
41 import javax.swing.JMenuItem;
42 import javax.swing.JPanel;
43 import javax.swing.JPopupMenu;
44 import javax.swing.JTextPane;
45 import javax.swing.LayoutStyle.ComponentPlacement;
46 import javax.swing.SwingUtilities;
47 import javax.swing.SwingWorker;
48 import javax.swing.border.EmptyBorder;
49 import org.openide.util.NbBundle;
50 import org.openide.util.NbBundle.Messages;
68 import org.
sleuthkit.datamodel.InvalidAccountIDException;
76 final class MessageAccountPanel
extends JPanel {
78 private static final long serialVersionUID = 1L;
79 private final static Logger logger = Logger.getLogger(MessageAccountPanel.class.getName());
81 private AccountFetcher currentFetcher = null;
88 MessageAccountPanel() {
89 this.setBorder(
new EmptyBorder(ContentViewerDefaults.getPanelInsets()));
99 void setArtifact(BlackboardArtifact artifact) {
104 if (artifact == null) {
108 if (currentFetcher != null && !currentFetcher.isDone()) {
109 currentFetcher.cancel(
true);
112 currentFetcher =
new AccountFetcher(artifact);
113 currentFetcher.execute();
119 class AccountFetcher
extends SwingWorker<List<AccountContainer>, Void> {
121 private final BlackboardArtifact artifact;
128 AccountFetcher(BlackboardArtifact artifact) {
129 this.artifact = artifact;
133 protected List<AccountContainer> doInBackground() throws Exception {
134 List<AccountContainer> dataList =
new ArrayList<>();
136 CommunicationsManager commManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
137 List<Account> accountList = commManager.getAccountsRelatedToArtifact(artifact);
138 for (Account account : accountList) {
140 return new ArrayList<>();
143 if (!((DataSource) (artifact.getDataSource())).getDeviceId().equals(account.getTypeSpecificID())) {
144 List<BlackboardArtifact> contactList = ContactCache.getContacts(account);
145 BlackboardArtifact contact = null;
147 if (contactList != null && !contactList.isEmpty()) {
148 contact = contactList.get(0);
151 if (CentralRepository.isEnabled()) {
152 Collection<PersonaAccount> personAccounts = PersonaAccount.getPersonaAccountsForAccount(account);
153 if (personAccounts != null && !personAccounts.isEmpty()) {
154 for (PersonaAccount personaAccount : PersonaAccount.getPersonaAccountsForAccount(account)) {
155 dataList.add(
new AccountContainer(account, personaAccount, contact));
158 dataList.add(
new AccountContainer(account, null, contact));
161 dataList.add(
new AccountContainer(account, null, contact));
170 "MessageAccountPanel_no_matches=No matches found.",})
172 protected void done() {
174 List<AccountContainer> dataList =
get();
176 if (!dataList.isEmpty()) {
177 dataList.forEach(container -> {
178 container.initalizeSwingControls();
181 GroupLayout layout =
new GroupLayout(MessageAccountPanel.this);
182 layout.setHorizontalGroup(
183 layout.createParallelGroup(Alignment.LEADING)
184 .addGroup(layout.createSequentialGroup()
185 .addGroup(getMainHorizontalGroup(layout, dataList))));
187 layout.setVerticalGroup(getMainVerticalGroup(layout, dataList));
192 JPanel messagePanel =
new javax.swing.JPanel();
193 JLabel messageLabel =
new javax.swing.JLabel();
195 messagePanel.setLayout(
new java.awt.BorderLayout());
197 messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
198 messageLabel.setText(Bundle.MessageAccountPanel_no_matches());
199 messageLabel.setFont(ContentViewerDefaults.getMessageFont());
200 messageLabel.setEnabled(
false);
201 messagePanel.add(messageLabel, java.awt.BorderLayout.CENTER);
203 setLayout(
new javax.swing.OverlayLayout(MessageAccountPanel.this));
208 }
catch (CancellationException ex) {
209 logger.log(Level.INFO,
"MessageAccoutPanel thread cancelled", ex);
210 }
catch (InterruptedException | ExecutionException ex) {
211 logger.log(Level.WARNING,
"Failed to get account list for MessageAccountPanel", ex);
221 private ParallelGroup getMainHorizontalGroup(GroupLayout layout, List<AccountContainer> data) {
222 ParallelGroup group = layout.createParallelGroup(Alignment.LEADING);
223 for (AccountContainer o : data) {
224 group.addComponent(o.getAccountLabel());
226 group.addGroup(getPersonaHorizontalGroup(layout, data));
235 private ParallelGroup getMainVerticalGroup(GroupLayout layout, List<AccountContainer> data) {
236 SequentialGroup group = layout.createSequentialGroup();
237 for (AccountContainer o : data) {
238 group.addComponent(o.getAccountLabel())
239 .addGroup(o.getContactLineVerticalGroup(layout))
240 .addGroup(o.getPersonLineVerticalGroup(layout));
241 group.addGap(ContentViewerDefaults.getSectionSpacing());
244 return layout.createParallelGroup().addGroup(group);
254 private ParallelGroup getButtonGroup(GroupLayout layout, List<AccountContainer> data) {
255 ParallelGroup group = layout.createParallelGroup(Alignment.LEADING);
256 for (AccountContainer o : data) {
257 group.addComponent(o.getButton());
268 private SequentialGroup getPersonaHorizontalGroup(GroupLayout layout, List<AccountContainer> data) {
269 SequentialGroup group = layout.createSequentialGroup();
270 ParallelGroup pgroup = layout.createParallelGroup(Alignment.LEADING);
271 for (AccountContainer o : data) {
272 pgroup.addGroup(o.getPersonaSequentialGroup(layout));
273 pgroup.addGroup(o.getContactSequentialGroup(layout));
275 group.addGap(ContentViewerDefaults.getSectionIndent())
277 .addPreferredGap(ComponentPlacement.RELATED)
278 .addGroup(getButtonGroup(layout, data));
305 JPopupMenu contactPopupMenu =
new JPopupMenu();
306 JPopupMenu personaPopupMenu =
new JPopupMenu();
307 JPopupMenu accountPopupMenu =
new JPopupMenu();
316 if (contactArtifact != null && contactArtifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT.getTypeID()) {
317 throw new IllegalArgumentException(
"Failed to create AccountContainer object, passed in artifact was not a TSK_CONTACT");
321 this.persona = personaAccount != null ? personaAccount.getPersona() : null;
326 "MessageAccountPanel_persona_label=Persona:",
327 "MessageAccountPanel_unknown_label=Unknown",
328 "MessageAccountPanel_button_view_label=View",
329 "MessageAccountPanel_button_create_label=Create",
330 "MessageAccountPanel_contact_label=Contact:",
331 "MessageAccountPanel_copy_label=Copy"
337 accountLabel =
new JTextPane();
338 accountLabel.setEditable(
false);
339 accountLabel.setOpaque(
false);
340 personaHeader =
new JLabel(Bundle.MessageAccountPanel_persona_label());
341 contactHeader =
new JLabel(Bundle.MessageAccountPanel_contact_label());
342 personaDisplayName =
new JTextPane();
343 personaDisplayName.setOpaque(
false);
344 personaDisplayName.setEditable(
false);
345 personaDisplayName.setPreferredSize(
new Dimension(100, 26));
346 personaDisplayName.setMaximumSize(
new Dimension(100, 26));
347 contactDisplayName =
new JTextPane();
348 contactDisplayName.setOpaque(
false);
349 contactDisplayName.setEditable(
false);
350 contactDisplayName.setPreferredSize(
new Dimension(100, 26));
351 button =
new JButton();
354 accountLabel.setMargin(
new Insets(0, 0, 0, 0));
355 accountLabel.setText(account.getTypeSpecificID());
357 contactDisplayName.setText(contactName);
358 personaDisplayName.setText(persona != null ? persona.
getName() : Bundle.MessageAccountPanel_unknown_label());
361 personaDisplayName.setMaximumSize((
new JLabel(personaDisplayName.getText()).getMaximumSize()));
362 contactDisplayName.setMaximumSize((
new JLabel(contactDisplayName.getText()).getMaximumSize()));
363 accountLabel.setMaximumSize((
new JLabel(accountLabel.getText()).getMaximumSize()));
365 button.setText(persona != null ? Bundle.MessageAccountPanel_button_view_label() : Bundle.MessageAccountPanel_button_create_label());
374 contactCopyMenuItem =
new JMenuItem(Bundle.MessageAccountPanel_copy_label());
375 personaCopyMenuItem =
new JMenuItem(Bundle.MessageAccountPanel_copy_label());
376 accountCopyMenuItem =
new JMenuItem(Bundle.MessageAccountPanel_copy_label());
377 personaPopupMenu.add(personaCopyMenuItem);
378 contactPopupMenu.add(contactCopyMenuItem);
379 accountPopupMenu.add(accountCopyMenuItem);
381 personaDisplayName.addMouseListener(
new MouseAdapter() {
383 public void mouseClicked(MouseEvent evt) {
384 if (SwingUtilities.isRightMouseButton(evt)) {
385 personaPopupMenu.show(personaDisplayName, evt.getX(), evt.getY());
390 personaCopyMenuItem.addActionListener(
new ActionListener() {
392 public void actionPerformed(ActionEvent e) {
393 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(personaDisplayName.getText()), null);
397 contactDisplayName.addMouseListener(
new MouseAdapter() {
399 public void mouseClicked(MouseEvent evt) {
400 if (SwingUtilities.isRightMouseButton(evt)) {
401 contactPopupMenu.show(contactDisplayName, evt.getX(), evt.getY());
406 contactCopyMenuItem.addActionListener(
new ActionListener() {
408 public void actionPerformed(ActionEvent e) {
409 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(contactDisplayName.getText()), null);
413 accountLabel.addMouseListener(
new MouseAdapter() {
415 public void mouseClicked(MouseEvent evt) {
416 if (SwingUtilities.isRightMouseButton(evt)) {
417 accountPopupMenu.show(accountLabel, evt.getX(), evt.getY());
422 accountCopyMenuItem.addActionListener(
new ActionListener() {
424 public void actionPerformed(ActionEvent e) {
425 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(accountLabel.getText()), null);
432 if (contactArtifact != null) {
433 BlackboardAttribute attribute = contactArtifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME));
434 if (attribute != null) {
435 return attribute.getValueString();
439 return Bundle.MessageAccountPanel_unknown_label();
451 SwingUtilities.invokeLater(
new Runnable() {
454 personaDisplayName.setText(persona != null ? persona.
getName() : Bundle.MessageAccountPanel_unknown_label());
455 button.setText(persona != null ? Bundle.MessageAccountPanel_button_view_label() : Bundle.MessageAccountPanel_button_create_label());
458 personaDisplayName.setMaximumSize((
new JLabel(personaDisplayName.getText()).getMaximumSize()));
509 SequentialGroup group = layout.createSequentialGroup();
512 .addComponent(personaHeader)
513 .addPreferredGap(ComponentPlacement.RELATED)
514 .addComponent(personaDisplayName);
520 SequentialGroup group = layout.createSequentialGroup();
523 .addComponent(contactHeader)
524 .addPreferredGap(ComponentPlacement.RELATED)
525 .addComponent(contactDisplayName);
538 return layout.createParallelGroup(Alignment.CENTER)
539 .addComponent(personaHeader)
540 .addComponent(personaDisplayName)
541 .addComponent(button);
552 return layout.createParallelGroup(Alignment.CENTER)
553 .addComponent(contactHeader)
554 .addComponent(contactDisplayName);
575 "MessageAccountPanel.account.justification=Account found in Message artifact",
576 "# {0} - accountIdentifer",
577 "MessageAccountPanel_id_not_found_in_cr=Unable to find an account with identifier {0} in the Central Repository."
582 if (persona == null) {
584 MessageAccountPanel.this,
599 boolean showErrorMessage =
true;
605 if (account != null) {
607 showErrorMessage =
false;
609 }
catch (InvalidAccountIDException ex2) {
613 if(showErrorMessage) {
617 logger.log(Level.SEVERE,
"Error looking up account types in the central repository", ex);
boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
String getNameFromContactArtifact(BlackboardArtifact contactArtifact)
void callback(Persona persona)
void setStartupPopupMessage(String message)
JMenuItem contactCopyMenuItem
JMenuItem accountCopyMenuItem
CentralRepoAccount getAccount(CentralRepoAccount.CentralRepoAccountType crAccountType, String accountUniqueID)
PersonaDetailsPanel getDetailsPanel()
Collection< CentralRepoAccountType > getAllAccountTypes()
JTextPane getAccountLabel()
JMenuItem personaCopyMenuItem
SequentialGroup getPersonaSequentialGroup(GroupLayout layout)
void actionPerformed(ActionEvent e)
void initalizeSwingControls()
static Font getHeaderFont()
JTextPane contactDisplayName
SequentialGroup getContactSequentialGroup(GroupLayout layout)
final AccountContainer accountContainer
void initalizePopupMenus()
JTextPane personaDisplayName
void setPersonaName(String name)
ParallelGroup getContactLineVerticalGroup(GroupLayout layout)
final AccountContainer accountContainer
ParallelGroup getPersonLineVerticalGroup(GroupLayout layout)
void setPersona(Persona persona)
static CentralRepository getInstance()