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;
35 final class ImageThumbnailPanel
extends javax.swing.JPanel implements ListCellRenderer<ImageThumbnailWrapper> {
37 private static final long serialVersionUID = 1L;
38 private static final Color SELECTION_COLOR =
new Color(0, 120, 215);
39 private static final int MAX_NAME_STRING = 30;
44 ImageThumbnailPanel() {
53 @SuppressWarnings(
"unchecked")
55 private
void initComponents() {
57 javax.swing.JPanel thumbnailPanel =
new javax.swing.JPanel();
58 thumbnailLabel =
new javax.swing.JLabel();
59 fileSizeLabel =
new javax.swing.JLabel();
60 nameLabel =
new javax.swing.JLabel();
61 isDeletedLabel =
new javax.swing.JLabel();
62 scoreLabel =
new javax.swing.JLabel();
66 thumbnailPanel.setToolTipText(
"");
67 thumbnailPanel.setLayout(
new java.awt.GridBagLayout());
68 thumbnailPanel.add(thumbnailLabel,
new java.awt.GridBagConstraints());
70 fileSizeLabel.setToolTipText(
"");
72 nameLabel.setToolTipText(
"");
73 nameLabel.setMaximumSize(
new java.awt.Dimension(159, 12));
74 nameLabel.setMinimumSize(
new java.awt.Dimension(159, 12));
75 nameLabel.setPreferredSize(
new java.awt.Dimension(159, 12));
77 isDeletedLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/file-icon-deleted.png")));
78 isDeletedLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(ImageThumbnailPanel.class,
"ImageThumbnailPanel.isDeletedLabel.toolTipText"));
83 scoreLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/red-circle-exclamation.png")));
84 scoreLabel.setToolTipText(
"");
89 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
90 this.setLayout(layout);
91 layout.setHorizontalGroup(
92 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93 .addGroup(layout.createSequentialGroup()
95 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
96 .addGroup(layout.createSequentialGroup()
97 .addComponent(fileSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
98 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
99 .addComponent(isDeletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
100 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
101 .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
102 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
103 .addComponent(nameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
104 .addComponent(thumbnailPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)))
107 layout.setVerticalGroup(
108 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
109 .addGroup(layout.createSequentialGroup()
111 .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
112 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
113 .addComponent(thumbnailPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
114 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
115 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
116 .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
117 .addComponent(isDeletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
118 .addComponent(fileSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
125 private javax.swing.JLabel fileSizeLabel;
126 private javax.swing.JLabel isDeletedLabel;
127 private javax.swing.JLabel nameLabel;
128 private javax.swing.JLabel scoreLabel;
129 private javax.swing.JLabel thumbnailLabel;
133 "# {0} - otherInstanceCount",
134 "ImageThumbnailPanel.nameLabel.more.text= and {0} more",
135 "ImageThumbnailPanel.isDeleted.text=All instances of file are deleted."})
137 public Component getListCellRendererComponent(JList<? extends ImageThumbnailWrapper> list, ImageThumbnailWrapper value,
int index,
boolean isSelected,
boolean cellHasFocus) {
138 fileSizeLabel.setText(DiscoveryUiUtils.getFileSizeString(value.getResultFile().getFirstInstance().getSize()));
139 String nameText = value.getResultFile().getFirstInstance().getParentPath() + value.getResultFile().getFirstInstance().getName();
140 if (value.getResultFile().getAllInstances().size() > 1) {
141 nameText += Bundle.ImageThumbnailPanel_nameLabel_more_text(value.getResultFile().getAllInstances().size() - 1);
143 if (nameText.length() > MAX_NAME_STRING) {
144 nameText =
"..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
146 nameLabel.setText(nameText);
147 thumbnailLabel.setIcon(
new ImageIcon(value.getThumbnail()));
148 DiscoveryUiUtils.setDeletedIcon(value.getResultFile().isDeleted(), isDeletedLabel);
149 DiscoveryUiUtils.setScoreIcon(value.getResultFile(), scoreLabel);
150 setBackground(isSelected ? SELECTION_COLOR : list.getBackground());
156 public String getToolTipText(MouseEvent event) {
159 Point point =
event.getPoint();
160 for (Component comp : getComponents()) {
161 if (DiscoveryUiUtils.isPointOnIcon(comp, point)) {
162 String toolTip = ((JComponent) comp).getToolTipText();
163 if (toolTip == null || toolTip.isEmpty()) {