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;
36 final class ImageThumbnailPanel
extends javax.swing.JPanel implements ListCellRenderer<ImageThumbnailWrapper> {
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 = 30;
45 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
46 ImageThumbnailPanel() {
55 @SuppressWarnings(
"unchecked")
57 private
void initComponents() {
59 javax.swing.JPanel thumbnailPanel =
new javax.swing.JPanel();
60 thumbnailLabel =
new javax.swing.JLabel();
61 fileSizeLabel =
new javax.swing.JLabel();
62 nameLabel =
new javax.swing.JLabel();
63 isDeletedLabel =
new javax.swing.JLabel();
64 scoreLabel =
new javax.swing.JLabel();
68 thumbnailPanel.setToolTipText(
"");
69 thumbnailPanel.setLayout(
new java.awt.GridBagLayout());
70 thumbnailPanel.add(thumbnailLabel,
new java.awt.GridBagConstraints());
72 fileSizeLabel.setToolTipText(
"");
74 nameLabel.setToolTipText(
"");
75 nameLabel.setMaximumSize(
new java.awt.Dimension(159, 12));
76 nameLabel.setMinimumSize(
new java.awt.Dimension(159, 12));
77 nameLabel.setPreferredSize(
new java.awt.Dimension(159, 12));
79 isDeletedLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/file-icon-deleted.png")));
80 isDeletedLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(ImageThumbnailPanel.class,
"ImageThumbnailPanel.isDeletedLabel.toolTipText"));
85 scoreLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/red-circle-exclamation.png")));
86 scoreLabel.setToolTipText(
"");
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.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
100 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
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.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
105 .addComponent(nameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
106 .addComponent(thumbnailPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)))
109 layout.setVerticalGroup(
110 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111 .addGroup(layout.createSequentialGroup()
113 .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
114 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
115 .addComponent(thumbnailPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
116 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
117 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118 .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
119 .addComponent(isDeletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
120 .addComponent(fileSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
127 private javax.swing.JLabel fileSizeLabel;
128 private javax.swing.JLabel isDeletedLabel;
129 private javax.swing.JLabel nameLabel;
130 private javax.swing.JLabel scoreLabel;
131 private javax.swing.JLabel thumbnailLabel;
134 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
136 "# {0} - otherInstanceCount",
137 "ImageThumbnailPanel.nameLabel.more.text= and {0} more",
138 "ImageThumbnailPanel.isDeleted.text=All instances of file are deleted."})
140 public Component getListCellRendererComponent(JList<? extends ImageThumbnailWrapper> list, ImageThumbnailWrapper value,
int index,
boolean isSelected,
boolean cellHasFocus) {
141 fileSizeLabel.setText(DiscoveryUiUtils.getFileSizeString(value.getResultFile().getFirstInstance().getSize()));
142 String nameText = value.getResultFile().getFirstInstance().getParentPath() + value.getResultFile().getFirstInstance().getName();
143 if (value.getResultFile().getAllInstances().size() > 1) {
144 nameText += Bundle.ImageThumbnailPanel_nameLabel_more_text(value.getResultFile().getAllInstances().size() - 1);
146 if (nameText.length() > MAX_NAME_STRING) {
147 nameText =
"..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
149 nameLabel.setText(nameText);
150 thumbnailLabel.setIcon(
new ImageIcon(value.getThumbnail()));
151 DiscoveryUiUtils.setDeletedIcon(value.getResultFile().isDeleted(), isDeletedLabel);
152 DiscoveryUiUtils.setScoreIcon(value.getResultFile(), scoreLabel);
153 setBackground(isSelected ? SELECTION_COLOR : list.getBackground());
158 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
160 public String getToolTipText(MouseEvent event) {
163 Point point =
event.getPoint();
164 for (Component comp : getComponents()) {
165 if (DiscoveryUiUtils.isPointOnIcon(comp, point)) {
166 String toolTip = ((JComponent) comp).getToolTipText();
167 if (toolTip == null || toolTip.isEmpty()) {