Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageThumbnailPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 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;
32 
36 final class ImageThumbnailPanel extends javax.swing.JPanel implements ListCellRenderer<ImageThumbnailWrapper> {
37 
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;
41 
45  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
46  ImageThumbnailPanel() {
47  initComponents();
48  }
49 
55  @SuppressWarnings("unchecked")
56  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
57  private void initComponents() {
58 
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();
65 
66  setToolTipText("");
67 
68  thumbnailPanel.setToolTipText("");
69  thumbnailPanel.setLayout(new java.awt.GridBagLayout());
70  thumbnailPanel.add(thumbnailLabel, new java.awt.GridBagConstraints());
71 
72  fileSizeLabel.setToolTipText("");
73 
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));
78 
79  isDeletedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/file-icon-deleted.png"))); // NOI18N
80  isDeletedLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ImageThumbnailPanel.class, "ImageThumbnailPanel.isDeletedLabel.toolTipText")); // NOI18N
81  isDeletedLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize()));
82  isDeletedLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize()));
83  isDeletedLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize()));
84 
85  scoreLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/red-circle-exclamation.png"))); // NOI18N
86  scoreLabel.setToolTipText("");
87  scoreLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize()));
88  scoreLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize()));
89  scoreLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.ui.DiscoveryUiUtils.getIconSize()));
90 
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()
96  .addContainerGap()
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)))
107  .addContainerGap())
108  );
109  layout.setVerticalGroup(
110  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111  .addGroup(layout.createSequentialGroup()
112  .addContainerGap()
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))
121  .addContainerGap())
122  );
123  }// </editor-fold>//GEN-END:initComponents
124 
125 
126  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
132  // End of variables declaration//GEN-END:variables
133 
134  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
135  @NbBundle.Messages({
136  "# {0} - otherInstanceCount",
137  "ImageThumbnailPanel.nameLabel.more.text= and {0} more",
138  "ImageThumbnailPanel.isDeleted.text=All instances of file are deleted."})
139  @Override
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);
145  }
146  if (nameText.length() > MAX_NAME_STRING) {
147  nameText = "..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
148  }
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());
154 
155  return this;
156  }
157 
158  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
159  @Override
160  public String getToolTipText(MouseEvent event) {
161  if (event != null) {
162  //gets tooltip of internal panel item mouse is over
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()) {
168  return null;
169  } else {
170  return toolTip;
171  }
172  }
173  }
174  }
175  return null;
176  }
177 
178 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.