19 package org.sleuthkit.autopsy.discovery.ui;
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;
37 class DocumentPanel
extends javax.swing.JPanel implements ListCellRenderer<DocumentWrapper> {
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;
55 @SuppressWarnings(
"unchecked")
57 private
void initComponents() {
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();
67 setBorder(javax.swing.BorderFactory.createEtchedBorder());
69 isDeletedLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/file-icon-deleted.png")));
70 isDeletedLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(DocumentPanel.class,
"DocumentPanel.isDeletedLabel.toolTipText"));
75 scoreLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/red-circle-exclamation.png")));
76 scoreLabel.setToolTipText(
"");
81 fileSizeLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(DocumentPanel.class,
"DocumentPanel.fileSizeLabel.toolTipText"));
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));
89 previewTextPane.setEditable(
false);
90 previewTextPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
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()
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))))
115 layout.setVerticalGroup(
116 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
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))
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;
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"})
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);
161 if (nameText.length() > MAX_NAME_STRING) {
162 nameText =
"..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
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());
171 numberOfImagesLabel.setText(Bundle.DocumentPanel_numberOfImages_noImages());
172 sampleImageLabel.setIcon(null);
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());
184 public String getToolTipText(MouseEvent event) {
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()) {