Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportProgressPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.report;
20 
21 import org.openide.util.NbBundle;
22 import java.awt.Color;
23 import java.awt.Cursor;
24 import java.awt.Desktop;
25 import java.awt.EventQueue;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseListener;
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.logging.Level;
32 
36 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
37 public class ReportProgressPanel extends javax.swing.JPanel {
38 
39  private static final long serialVersionUID = 1L;
40  private static final Logger logger = Logger.getLogger(ReportProgressPanel.class.getName());
41  private static final Color GREEN = new Color(50, 205, 50);
42  private static final Color RED = new Color(178, 34, 34);
43  private volatile ReportStatus status;
44 
49  public enum ReportStatus {
50 
55  ERROR
56  }
57 
64  public ReportProgressPanel(String reportName, String reportPath) {
65  initComponents();
66  reportProgressBar.setIndeterminate(true);
67  reportProgressBar.setMaximum(100);
68  reportLabel.setText(reportName);
69  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing"));
70  status = ReportStatus.QUEUING;
71  if (null != reportPath) {
72  pathLabel.setText("<html><u>" + shortenPath(reportPath) + "</u></html>"); //NON-NLS
73  pathLabel.setToolTipText(reportPath);
74  String linkPath = reportPath;
75  pathLabel.addMouseListener(new MouseListener() {
76 
77  @Override
78  public void mouseClicked(MouseEvent mouseEvent) {
79  }
80 
81  @Override
82  public void mousePressed(MouseEvent mouseEvent) {
83  }
84 
85  @Override
86  public void mouseReleased(MouseEvent mouseEvent) {
87  File file = new File(linkPath);
88  try {
89  Desktop.getDesktop().open(file);
90  } catch (IOException ioex) {
91  logger.log(Level.SEVERE, "Error opening report file", ioex);
92  } catch (IllegalArgumentException iaEx) {
93  logger.log(Level.SEVERE, "Error opening report file", iaEx);
94  try {
95  Desktop.getDesktop().open(file.getParentFile());
96  } catch (IOException ioEx2) {
97  logger.log(Level.SEVERE, "Error opening report file parent", ioEx2);
98  }
99  }
100  }
101 
102  @Override
103  public void mouseEntered(MouseEvent e3) {
104  pathLabel.setForeground(Color.DARK_GRAY);
105  setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
106  }
107 
108  @Override
109  public void mouseExited(MouseEvent e4) {
110  pathLabel.setForeground(Color.BLACK);
111  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
112  }
113  });
114  } else {
115  pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile"));
116  }
117  }
118 
125  return status;
126  }
127 
131  public void start() {
132  EventQueue.invokeLater(() -> {
133  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text"));
134  status = ReportStatus.RUNNING;
135  });
136  }
137 
143  public void setMaximumProgress(int max) {
144  EventQueue.invokeLater(() -> {
145  if (status != ReportStatus.CANCELED) {
146  reportProgressBar.setMaximum(max);
147  }
148  });
149  }
150 
155  public void increment() {
156  EventQueue.invokeLater(() -> {
157  if (status != ReportStatus.CANCELED) {
158  reportProgressBar.setValue(reportProgressBar.getValue() + 1);
159  }
160  });
161  }
162 
168  public void setProgress(int value) {
169  EventQueue.invokeLater(() -> {
170  if (status != ReportStatus.CANCELED) {
171  reportProgressBar.setValue(value);
172  }
173  });
174  }
175 
183  public void setIndeterminate(boolean indeterminate) {
184  EventQueue.invokeLater(() -> {
185  if (status != ReportStatus.CANCELED) {
186  reportProgressBar.setIndeterminate(indeterminate);
187  }
188  });
189  }
190 
198  public void updateStatusLabel(String statusMessage) {
199  EventQueue.invokeLater(() -> {
200  if (status != ReportStatus.CANCELED) {
201  statusMessageLabel.setText(statusMessage);
202  }
203  });
204  }
205 
212  public void complete(ReportStatus reportStatus) {
213  EventQueue.invokeLater(() -> {
214  reportProgressBar.setIndeterminate(false);
215  if (status != ReportStatus.CANCELED) {
216  switch (reportStatus) {
217  case COMPLETE: {
218  ReportStatus oldValue = status;
219  status = ReportStatus.COMPLETE;
220  statusMessageLabel.setForeground(Color.BLACK);
221  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text"));
222  reportProgressBar.setValue(reportProgressBar.getMaximum());
223  reportProgressBar.setStringPainted(true);
224  reportProgressBar.setForeground(GREEN);
225  reportProgressBar.setString("Complete"); //NON-NLS
226  firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
227  break;
228  }
229  case ERROR: {
230  ReportStatus oldValue = status;
231  status = ReportStatus.ERROR;
232  statusMessageLabel.setForeground(RED);
233  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text"));
234  reportProgressBar.setValue(reportProgressBar.getMaximum());
235  reportProgressBar.setStringPainted(true);
236  reportProgressBar.setForeground(RED);
237  reportProgressBar.setString("Error"); //NON-NLS
238  firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
239  break;
240  }
241  default: {
242  break;
243  }
244  }
245  }
246  });
247  }
248 
253  void cancel() {
254  switch (status) {
255  case COMPLETE:
256  break;
257  case CANCELED:
258  break;
259  case ERROR:
260  break;
261  default:
262  ReportStatus oldValue = status;
263  status = ReportStatus.CANCELED;
264  reportProgressBar.setIndeterminate(false);
265  reportProgressBar.setValue(0);
266  reportProgressBar.setStringPainted(true);
267  reportProgressBar.setForeground(RED); // Red
268  reportProgressBar.setString("Cancelled"); //NON-NLS
269  firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status);
270  statusMessageLabel.setForeground(RED);
271  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text"));
272  break;
273  }
274  }
275 
283  private String shortenPath(String path) {
284  if (path.length() > 100) {
285  return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
286  + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator));
287  } else {
288  return path;
289  }
290  }
291 
297  @SuppressWarnings("unchecked")
298  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
299  private void initComponents() {
300 
301  reportProgressBar = new javax.swing.JProgressBar();
302  reportLabel = new javax.swing.JLabel();
303  pathLabel = new javax.swing.JLabel();
304  separationLabel = new javax.swing.JLabel();
305  statusMessageLabel = new javax.swing.JLabel();
306 
307  setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
308  setMinimumSize(new java.awt.Dimension(486, 68));
309 
310  reportProgressBar.setFont(reportProgressBar.getFont().deriveFont(reportProgressBar.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
311 
312  reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD, 11));
313  org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N
314 
315  pathLabel.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
316  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N
317  pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
318 
319  separationLabel.setFont(separationLabel.getFont().deriveFont(separationLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
320  org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N
321 
322  org.openide.awt.Mnemonics.setLocalizedText(statusMessageLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.statusMessageLabel.text")); // NOI18N
323 
324  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
325  this.setLayout(layout);
326  layout.setHorizontalGroup(
327  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
328  .addGroup(layout.createSequentialGroup()
329  .addContainerGap()
330  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331  .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
332  .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
333  .addGroup(layout.createSequentialGroup()
334  .addComponent(reportLabel)
335  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
336  .addComponent(separationLabel)
337  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
338  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)))
339  .addContainerGap())
340  );
341  layout.setVerticalGroup(
342  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
343  .addGroup(layout.createSequentialGroup()
344  .addContainerGap()
345  .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
346  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
347  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
348  .addComponent(reportLabel)
349  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
350  .addComponent(separationLabel))
351  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
352  .addComponent(statusMessageLabel)
353  .addGap(13, 13, 13))
354  );
355  }// </editor-fold>//GEN-END:initComponents
356 
357 
358  // Variables declaration - do not modify//GEN-BEGIN:variables
359  private javax.swing.JLabel pathLabel;
360  private javax.swing.JLabel reportLabel;
361  private javax.swing.JProgressBar reportProgressBar;
362  private javax.swing.JLabel separationLabel;
363  private javax.swing.JLabel statusMessageLabel;
364  // End of variables declaration//GEN-END:variables
365 
372  @Deprecated
373  public void complete() {
374  complete(ReportStatus.COMPLETE);
375  }
376 
377 }
ReportProgressPanel(String reportName, String reportPath)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.