19 package org.sleuthkit.autopsy.discovery;
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;
36 class DocumentPanel
extends javax.swing.JPanel implements ListCellRenderer<DocumentWrapper> {
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;
54 @SuppressWarnings(
"unchecked")
56 private
void initComponents() {
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();
64 previewTextPane =
new AutoWrappingJTextPane();
66 setBorder(javax.swing.BorderFactory.createEtchedBorder());
68 isDeletedLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/file-icon-deleted.png")));
69 isDeletedLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(DocumentPanel.class,
"DocumentPanel.isDeletedLabel.toolTipText"));
74 scoreLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/red-circle-exclamation.png")));
75 scoreLabel.setToolTipText(
"");
80 fileSizeLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(DocumentPanel.class,
"DocumentPanel.fileSizeLabel.toolTipText"));
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));
88 previewTextPane.setEditable(
false);
89 previewTextPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
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()
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))))
114 layout.setVerticalGroup(
115 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
116 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
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))
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;
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"})
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);
160 if (nameText.length() > MAX_NAME_STRING) {
161 nameText =
"..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
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());
170 numberOfImagesLabel.setText(Bundle.DocumentPanel_numberOfImages_noImages());
171 sampleImageLabel.setIcon(null);
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());
183 public String getToolTipText(MouseEvent event) {
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()) {