Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DocumentPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
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 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.filequery;
20 
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.Point;
25 import java.awt.event.MouseEvent;
26 import javax.swing.ImageIcon;
27 import javax.swing.JComponent;
28 import javax.swing.JList;
29 import javax.swing.ListCellRenderer;
30 import org.openide.util.NbBundle.Messages;
32 
36 public class DocumentPanel extends javax.swing.JPanel implements ListCellRenderer<DocumentWrapper> {
37 
38  private static final long serialVersionUID = 1L;
39  private static final Color SELECTION_COLOR = new Color(0, 120, 215);
40  private static final int MAX_NAME_STRING = 90;
41 
45  public DocumentPanel() {
47  }
48 
54  @SuppressWarnings("unchecked")
55  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
56  private void initComponents() {
57 
58  isDeletedLabel = new javax.swing.JLabel();
59  scoreLabel = new javax.swing.JLabel();
60  fileSizeLabel = new javax.swing.JLabel();
61  nameLabel = new javax.swing.JLabel();
62  sampleImageLabel = new javax.swing.JLabel();
63  numberOfImagesLabel = new javax.swing.JLabel();
65 
66  setBorder(javax.swing.BorderFactory.createEtchedBorder());
67 
68  isDeletedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/file-icon-deleted.png"))); // NOI18N
69  isDeletedLabel.setToolTipText(org.openide.util.NbBundle.getMessage(DocumentPanel.class, "DocumentPanel.isDeletedLabel.toolTipText")); // NOI18N
70  isDeletedLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
71  isDeletedLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
72  isDeletedLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
73 
74  scoreLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/red-circle-exclamation.png"))); // NOI18N
75  scoreLabel.setToolTipText("");
76  scoreLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
77  scoreLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
78  scoreLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
79 
80  fileSizeLabel.setToolTipText(org.openide.util.NbBundle.getMessage(DocumentPanel.class, "DocumentPanel.fileSizeLabel.toolTipText")); // NOI18N
81 
82  sampleImageLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
83  sampleImageLabel.setIconTextGap(0);
84  sampleImageLabel.setMaximumSize(new java.awt.Dimension(100, 100));
85  sampleImageLabel.setMinimumSize(new java.awt.Dimension(100, 100));
86  sampleImageLabel.setPreferredSize(new java.awt.Dimension(100, 100));
87 
88  previewTextPane.setEditable(false);
89  previewTextPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
90 
91  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
92  this.setLayout(layout);
93  layout.setHorizontalGroup(
94  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95  .addGroup(layout.createSequentialGroup()
96  .addContainerGap()
97  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
98  .addGroup(layout.createSequentialGroup()
99  .addComponent(fileSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
100  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
101  .addComponent(isDeletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
102  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
103  .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
104  .addGroup(layout.createSequentialGroup()
105  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
106  .addComponent(nameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
107  .addComponent(previewTextPane, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE))
108  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
109  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
110  .addComponent(numberOfImagesLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
111  .addComponent(sampleImageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
112  .addContainerGap())
113  );
114  layout.setVerticalGroup(
115  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
116  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
117  .addContainerGap()
118  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
119  .addComponent(numberOfImagesLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
120  .addComponent(nameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
121  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
122  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123  .addComponent(sampleImageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
124  .addComponent(previewTextPane, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
125  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
126  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127  .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
128  .addComponent(isDeletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
129  .addComponent(fileSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
130  .addContainerGap())
131  );
132  }// </editor-fold>//GEN-END:initComponents
133 
134 
135  // Variables declaration - do not modify//GEN-BEGIN:variables
136  private javax.swing.JLabel fileSizeLabel;
137  private javax.swing.JLabel isDeletedLabel;
138  private javax.swing.JLabel nameLabel;
139  private javax.swing.JLabel numberOfImagesLabel;
140  private javax.swing.JTextPane previewTextPane;
141  private javax.swing.JLabel sampleImageLabel;
142  private javax.swing.JLabel scoreLabel;
143  // End of variables declaration//GEN-END:variables
144 
145  @Messages({
146  "# {0} - otherInstanceCount",
147  "DocumentPanel.nameLabel.more.text= and {0} more",
148  "# {0} - numberOfImages",
149  "DocumentPanel.numberOfImages.text=1 of {0} images",
150  "DocumentPanel.numberOfImages.noImages=No images",
151  "DocumentPanel.noImageExtraction.text=0 of ? images"})
152 
153  @Override
154  public Component getListCellRendererComponent(JList<? extends DocumentWrapper> list, DocumentWrapper value, int index, boolean isSelected, boolean cellHasFocus) {
155  fileSizeLabel.setText(DiscoveryUiUtils.getFileSizeString(value.getResultFile().getFirstInstance().getSize()));
156  String nameText = value.getResultFile().getFirstInstance().getParentPath() + value.getResultFile().getFirstInstance().getName();
157  if (value.getResultFile().getAllInstances().size() > 1) {
158  nameText += Bundle.DocumentPanel_nameLabel_more_text(value.getResultFile().getAllInstances().size() - 1);
159  }
160  if (nameText.length() > MAX_NAME_STRING) {
161  nameText = "..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
162  }
163  if (value.getSummary().getNumberOfImages() > 0) {
164  numberOfImagesLabel.setText(Bundle.DocumentPanel_numberOfImages_text(value.getSummary().getNumberOfImages()));
165  sampleImageLabel.setIcon(new ImageIcon(value.getSummary().getSampleImage()));
166  } else if (FileSearchData.getDocTypesWithoutImageExtraction().contains(value.getResultFile().getFirstInstance().getMIMEType())) {
167  numberOfImagesLabel.setText(Bundle.DocumentPanel_noImageExtraction_text());
168  sampleImageLabel.setIcon(DiscoveryUiUtils.getUnsupportedImageThumbnail());
169  } else {
170  numberOfImagesLabel.setText(Bundle.DocumentPanel_numberOfImages_noImages());
171  sampleImageLabel.setIcon(null);
172  }
173  nameLabel.setText(nameText);
174  previewTextPane.setText(value.getSummary().getSummaryText());
175  previewTextPane.setCaretPosition(0);
176  DiscoveryUiUtils.setDeletedIcon(value.getResultFile().isDeleted(), isDeletedLabel);
177  DiscoveryUiUtils.setScoreIcon(value.getResultFile(), scoreLabel);
178  setBackground(isSelected ? SELECTION_COLOR : list.getBackground());
179  return this;
180  }
181 
182  @Override
183  public String getToolTipText(MouseEvent event) {
184  if (event != null) {
185  //gets tooltip of internal panel item mouse is over
186  Point point = event.getPoint();
187  for (Component comp : getComponents()) {
188  if (DiscoveryUiUtils.isPointOnIcon(comp, point)) {
189  String toolTip = ((JComponent) comp).getToolTipText();
190  if (toolTip == null || toolTip.isEmpty()) {
191  return null;
192  } else {
193  return toolTip;
194  }
195  }
196  }
197  }
198  return null;
199  }
200 
201 }
Component getListCellRendererComponent(JList<?extends DocumentWrapper > list, DocumentWrapper value, int index, boolean isSelected, boolean cellHasFocus)

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.