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

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