Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContactDetailsPane.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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 obtain 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.image.BufferedImage;
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.logging.Level;
25 import javax.imageio.ImageIO;
26 import javax.swing.ImageIcon;
27 import org.openide.explorer.ExplorerManager;
28 import org.openide.nodes.Node;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 import org.sleuthkit.datamodel.Content;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
38 public final class ContactDetailsPane extends javax.swing.JPanel implements ExplorerManager.Provider {
39 
40  private static final Logger logger = Logger.getLogger(ContactDetailsPane.class.getName());
41 
42  private final static String DEFAULT_IMAGE_PATH = "/org/sleuthkit/autopsy/communications/images/defaultContact.png";
43 
44  private final ExplorerManager explorerManager = new ExplorerManager();
45  private final ImageIcon defaultImage;
46 
50  public ContactDetailsPane() {
52  nameLabel.setText("");
53 
54  defaultImage = new ImageIcon(ContactDetailsPane.class.getResource(DEFAULT_IMAGE_PATH));
55  }
56 
62  public void setNode(Node[] nodes) {
63  if (nodes != null && nodes.length == 1) {
64  nameLabel.setText(nodes[0].getDisplayName());
65  nameLabel.setIcon(null);
66  propertySheet.setNodes(nodes);
67 
68  BlackboardArtifact n = nodes[0].getLookup().lookup(BlackboardArtifact.class);
69  if(n != null) {
70  nameLabel.setIcon(getImageFromArtifact(n));
71  }
72  } else {
73  nameLabel.setText("");
74  nameLabel.setIcon(null);
75  propertySheet.setNodes(null);
76  }
77  }
78 
79  @Override
80  public ExplorerManager getExplorerManager() {
81  return explorerManager;
82  }
83 
84  public ImageIcon getImageFromArtifact(BlackboardArtifact artifact){
85  ImageIcon imageIcon = defaultImage;
86 
87  if(artifact == null) {
88  return imageIcon;
89  }
90 
91  BlackboardArtifact.ARTIFACT_TYPE artifactType = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
92  if(artifactType != BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT) {
93  return imageIcon;
94  }
95 
96  try {
97  for(Content content: artifact.getChildren()) {
98  if(content instanceof AbstractFile) {
99  AbstractFile file = (AbstractFile)content;
100 
101  try {
102  BufferedImage image = ImageIO.read(new File(file.getLocalAbsPath()));
103  imageIcon = new ImageIcon(image);
104  break;
105  } catch (IOException ex) {
106  // ImageIO.read will through an IOException if file is not an image
107  // therefore we don't need to report this exception just try
108  // the next file.
109  }
110  }
111  }
112  } catch (TskCoreException ex) {
113  logger.log(Level.WARNING, String.format("Unable to load image for contact: %d", artifact.getId()), ex);
114  }
115 
116  return imageIcon;
117  }
118 
124  @SuppressWarnings("unchecked")
125  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
126  private void initComponents() {
127  java.awt.GridBagConstraints gridBagConstraints;
128 
129  nameLabel = new javax.swing.JLabel();
130  propertySheet = new org.openide.explorer.propertysheet.PropertySheet();
131 
132  setLayout(new java.awt.GridBagLayout());
133 
134  nameLabel.setFont(nameLabel.getFont().deriveFont(nameLabel.getFont().getSize()+13f));
135  org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(ContactDetailsPane.class, "ContactDetailsPane.nameLabel.text")); // NOI18N
136  gridBagConstraints = new java.awt.GridBagConstraints();
137  gridBagConstraints.gridx = 0;
138  gridBagConstraints.gridy = 0;
139  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140  gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
141  gridBagConstraints.weightx = 1.0;
142  gridBagConstraints.insets = new java.awt.Insets(16, 15, 15, 15);
143  add(nameLabel, gridBagConstraints);
144 
145  propertySheet.setDescriptionAreaVisible(false);
146  gridBagConstraints = new java.awt.GridBagConstraints();
147  gridBagConstraints.gridx = 0;
148  gridBagConstraints.gridy = 1;
149  gridBagConstraints.gridwidth = 2;
150  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
151  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
152  gridBagConstraints.weightx = 1.0;
153  gridBagConstraints.weighty = 1.0;
154  gridBagConstraints.insets = new java.awt.Insets(9, 15, 16, 15);
155  add(propertySheet, gridBagConstraints);
156  }// </editor-fold>//GEN-END:initComponents
157 
158 
159  // Variables declaration - do not modify//GEN-BEGIN:variables
160  private javax.swing.JLabel nameLabel;
161  private org.openide.explorer.propertysheet.PropertySheet propertySheet;
162  // End of variables declaration//GEN-END:variables
163 }
org.openide.explorer.propertysheet.PropertySheet propertySheet
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.