Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
SummaryPersonaPane.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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 obt ain 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  */
19 package org.sleuthkit.autopsy.communications.relationships;
20 
21 import java.awt.CardLayout;
22 import java.awt.Component;
23 import java.awt.GridLayout;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.logging.Level;
33 import javax.swing.Box;
34 import javax.swing.JButton;
35 import javax.swing.JPanel;
36 import org.openide.util.NbBundle;
46 import org.sleuthkit.datamodel.Account;
47 
51 public final class SummaryPersonaPane extends javax.swing.JPanel {
52 
53  private static final long serialVersionUID = 1L;
54 
55  private final static Logger logger = Logger.getLogger(SummaryPersonaPane.class.getName());
56 
57  private final Map<Component, Persona> personaMap;
60  private Account currentAccount = null;
61 
67  personaScrollPane.setViewportView(new JPanel());
68 
69  personaMap = new HashMap<>();
70  }
71 
75  void clearList() {
76  personaScrollPane.setViewportView(new JPanel());
77  personaMap.clear();
78  }
79 
83  void showMessagePanel() {
84  CardLayout layout = (CardLayout) getLayout();
85  layout.show(this, "message");
86  }
87 
93  void setMessage(String message) {
94  messageLabel.setText(message);
95  }
96 
102  void updatePersonaList(Account account, CentralRepoAccount crAccount, List<Persona> personaList) {
103  JPanel panel = new JPanel();
104  currentCRAccount = crAccount;
105  currentAccount = account;
106 
107  CardLayout layout = (CardLayout) getLayout();
108  if (personaList.isEmpty()) {
109  layout.show(this, "create");
110  } else {
111  panel.setLayout(new GridLayout(personaList.size() + 1, 1));
112  int maxWidth = 0;
113  List<PersonaPanel> panelList = new ArrayList<>();
114  for (Persona persona : personaList) {
115  PersonaPanel personaPanel = new PersonaPanel(persona);
116  JButton viewButton = personaPanel.getViewButton();
117  panel.add(personaPanel);
118 
119  personaMap.put(viewButton, persona);
120  viewButton.addActionListener(viewButtonHandler);
121 
122  panelList.add(personaPanel);
123  maxWidth = Math.max(personaPanel.getPersonaLabelPreferedWidth(), maxWidth);
124  }
125 
126  //Set the preferred width of the labeles to the buttons line up.
127  if (panelList.size() > 1) {
128  for (PersonaPanel ppanel : panelList) {
129  ppanel.setPersonalLabelPreferredWidth(maxWidth);
130  }
131  }
132 
133  panel.add(Box.createVerticalGlue());
134  personaScrollPane.setViewportView(panel);
135  layout.show(this, "persona");
136  }
137 
138  }
139 
144  final private class ViewButtonHandler implements ActionListener {
145 
146  @Override
147  public void actionPerformed(ActionEvent e) {
148  Persona persona = personaMap.get((Component) e.getSource());
151  }
152  }
153 
157  private final class PersonaViewCallbackImpl implements PersonaDetailsDialogCallback {
158 
159  @Override
160  public void callback(Persona persona) {
161  // nothing to do
162  }
163  }
164 
170 
171  @Override
172  public void callback(Persona persona) {
173  if (persona != null) {
174  List<Persona> list = new ArrayList<>();
175  list.add(persona);
176 
177  CentralRepoAccount crAccount = null;
178  Collection<PersonaAccount> personaAccounts = null;
179  try {
180  personaAccounts = persona.getPersonaAccounts();
181  } catch (CentralRepoException ex) {
182  logger.log(Level.WARNING, String.format("Failed to get cr account from person %s (%d)", persona.getName(), persona.getId()), ex);
183  }
184 
185  if (personaAccounts != null) {
186  Iterator<PersonaAccount> iterator = personaAccounts.iterator();
187  if (iterator.hasNext()) {
188  crAccount = iterator.next().getAccount();
189  }
190  }
191 
192  updatePersonaList(currentAccount, crAccount, list);
193  }
194  }
195  }
196 
202  @SuppressWarnings("unchecked")
203  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
204  private void initComponents() {
205  java.awt.GridBagConstraints gridBagConstraints;
206 
207  personaScrollPane = new javax.swing.JScrollPane();
208  messagePane = new javax.swing.JPanel();
209  messageLabel = new javax.swing.JLabel();
210  createPersonaPanel = new javax.swing.JPanel();
211  noPersonaLabel = new javax.swing.JLabel();
212  createButton = new javax.swing.JButton();
213 
214  setLayout(new java.awt.CardLayout());
215 
216  personaScrollPane.setBorder(null);
217  add(personaScrollPane, "persona");
218 
219  messagePane.setLayout(new java.awt.GridBagLayout());
220 
221  org.openide.awt.Mnemonics.setLocalizedText(messageLabel, org.openide.util.NbBundle.getMessage(SummaryPersonaPane.class, "SummaryPersonaPane.messageLabel.text")); // NOI18N
222  messageLabel.setEnabled(false);
223  gridBagConstraints = new java.awt.GridBagConstraints();
224  gridBagConstraints.gridx = 0;
225  gridBagConstraints.gridy = 0;
226  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
227  gridBagConstraints.weighty = 1.0;
228  messagePane.add(messageLabel, gridBagConstraints);
229 
230  add(messagePane, "message");
231 
232  createPersonaPanel.setPreferredSize(new java.awt.Dimension(200, 100));
233  createPersonaPanel.setLayout(new java.awt.GridBagLayout());
234 
235  org.openide.awt.Mnemonics.setLocalizedText(noPersonaLabel, org.openide.util.NbBundle.getMessage(SummaryPersonaPane.class, "SummaryPersonaPane.noPersonaLabel.text")); // NOI18N
236  gridBagConstraints = new java.awt.GridBagConstraints();
237  gridBagConstraints.gridx = 0;
238  gridBagConstraints.gridy = 0;
239  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
240  gridBagConstraints.weighty = 1.0;
241  gridBagConstraints.insets = new java.awt.Insets(7, 5, 0, 0);
242  createPersonaPanel.add(noPersonaLabel, gridBagConstraints);
243 
244  org.openide.awt.Mnemonics.setLocalizedText(createButton, org.openide.util.NbBundle.getMessage(SummaryPersonaPane.class, "SummaryPersonaPane.createButton.text")); // NOI18N
245  createButton.setMargin(new java.awt.Insets(0, 5, 0, 5));
246  createButton.addActionListener(new java.awt.event.ActionListener() {
247  public void actionPerformed(java.awt.event.ActionEvent evt) {
249  }
250  });
251  gridBagConstraints = new java.awt.GridBagConstraints();
252  gridBagConstraints.gridx = 1;
253  gridBagConstraints.gridy = 0;
254  gridBagConstraints.gridheight = 2;
255  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
256  gridBagConstraints.weightx = 1.0;
257  gridBagConstraints.weighty = 1.0;
258  gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
259  createPersonaPanel.add(createButton, gridBagConstraints);
260 
261  add(createPersonaPanel, "create");
262  }// </editor-fold>//GEN-END:initComponents
263 
264  @NbBundle.Messages({
265  "# {0} - accountIdentifer",
266  "SummaryPersonaPane_not_account_in_cr=Unable to find an account with identifier {0} in the Central Repository."
267  })
268 
269  private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed
270  PersonaDetailsDialog createPersonaDialog = new PersonaDetailsDialog(SummaryPersonaPane.this,
272 
273  // Pre populate the persona name and accounts if we have them.
274  PersonaDetailsPanel personaPanel = createPersonaDialog.getDetailsPanel();
275  if (currentCRAccount != null) {
276  personaPanel.addAccount(currentCRAccount, "", Persona.Confidence.HIGH);
277 
278  } else {
279  createPersonaDialog.setStartupPopupMessage(Bundle.SummaryPersonaPane_not_account_in_cr(currentAccount.getTypeSpecificID()));
280  }
281  personaPanel.setPersonaName(currentAccount.getTypeSpecificID());
282  // display the dialog now
283  createPersonaDialog.display();
284  }//GEN-LAST:event_createButtonActionPerformed
285 
286 
287  // Variables declaration - do not modify//GEN-BEGIN:variables
288  private javax.swing.JButton createButton;
289  private javax.swing.JPanel createPersonaPanel;
290  private javax.swing.JLabel messageLabel;
291  private javax.swing.JPanel messagePane;
292  private javax.swing.JLabel noPersonaLabel;
293  private javax.swing.JScrollPane personaScrollPane;
294  // End of variables declaration//GEN-END:variables
295 }
boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Mon Sep 26 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.