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

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.