Autopsy  4.14.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.filequery;
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;
31 
35 public class ImageThumbnailPanel extends javax.swing.JPanel implements ListCellRenderer<ImageThumbnailWrapper> {
36 
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;
40 
46  }
47 
53  @SuppressWarnings("unchecked")
54  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
55  private void initComponents() {
56 
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();
63 
64  setToolTipText("");
65 
66  thumbnailPanel.setToolTipText("");
67  thumbnailPanel.setLayout(new java.awt.GridBagLayout());
68  thumbnailPanel.add(thumbnailLabel, new java.awt.GridBagConstraints());
69 
70  fileSizeLabel.setToolTipText("");
71 
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));
76 
77  isDeletedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/file-icon-deleted.png"))); // NOI18N
78  isDeletedLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ImageThumbnailPanel.class, "ImageThumbnailPanel.isDeletedLabel.toolTipText")); // NOI18N
79  isDeletedLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
80  isDeletedLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
81  isDeletedLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
82 
83  scoreLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/red-circle-exclamation.png"))); // NOI18N
84  scoreLabel.setToolTipText("");
85  scoreLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
86  scoreLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
87  scoreLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.filequery.DiscoveryUiUtils.getIconSize()));
88 
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()
94  .addContainerGap()
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)))
105  .addContainerGap())
106  );
107  layout.setVerticalGroup(
108  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
109  .addGroup(layout.createSequentialGroup()
110  .addContainerGap()
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))
119  .addContainerGap())
120  );
121  }// </editor-fold>//GEN-END:initComponents
122 
123 
124  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
130  // End of variables declaration//GEN-END:variables
131 
132  @NbBundle.Messages({
133  "# {0} - otherInstanceCount",
134  "ImageThumbnailPanel.nameLabel.more.text= and {0} more",
135  "ImageThumbnailPanel.isDeleted.text=All instances of file are deleted."})
136  @Override
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);
142  }
143  if (nameText.length() > MAX_NAME_STRING) {
144  nameText = "..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
145  }
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());
151 
152  return this;
153  }
154 
155  @Override
156  public String getToolTipText(MouseEvent event) {
157  if (event != null) {
158  //gets tooltip of internal panel item mouse is over
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()) {
164  return null;
165  } else {
166  return toolTip;
167  }
168  }
169  }
170  }
171  return null;
172  }
173 
174 }
Component getListCellRendererComponent(JList<?extends ImageThumbnailWrapper > list, ImageThumbnailWrapper value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.