Autopsy  3.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 2012 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 
23 import java.awt.*;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.MouseListener;
26 import java.io.File;
27 import java.io.IOException;
28 import java.util.logging.Level;
30 
31 public class ReportProgressPanel extends javax.swing.JPanel {
32  private static final Logger logger = Logger.getLogger(ReportProgressPanel.class.getName());
34 
35  // Enum to represent if a report is waiting,
36  // running, done, or has been canceled
37  public enum ReportStatus {
42  ERROR
43  }
44 
48  public ReportProgressPanel(String reportName, String reportPath) {
50  customInit(reportName, reportPath);
51  }
52 
53  private void customInit(String reportName, String reportPath) {
54  reportProgressBar.setIndeterminate(true);
55  reportProgressBar.setMaximum(100);
56 
57  reportLabel.setText(reportName);
58  processingLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing"));
59  STATUS = ReportStatus.QUEUING;
60 
61  if (reportPath != null) {
62  pathLabel.setText("<html><u>" + shortenPath(reportPath) + "</u></html>"); //NON-NLS
63  pathLabel.setToolTipText(reportPath);
64 
65  // Add the "link" effect to the pathLabel
66  final String linkPath = reportPath;
67  pathLabel.addMouseListener(new MouseListener() {
68 
69  @Override
70  public void mouseClicked(MouseEvent e) {
71  }
72 
73  @Override
74  public void mousePressed(MouseEvent e) {
75  }
76 
77  @Override
78  public void mouseReleased(MouseEvent e) {
79  File file = new File(linkPath);
80  try {
81  Desktop.getDesktop().open(file);
82  } catch (IOException ex) {
83  } catch (IllegalArgumentException ex) {
84  try {
85  // try to open the parent path if the file doens't exist
86  Desktop.getDesktop().open(file.getParentFile());
87  } catch (IOException ex1) {
88  }
89  }
90  }
91 
92  @Override
93  public void mouseEntered(MouseEvent e) {
94  pathLabel.setForeground(Color.DARK_GRAY);
95  setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
96  }
97 
98  @Override
99  public void mouseExited(MouseEvent e) {
100  pathLabel.setForeground(Color.BLACK);
101  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
102  }
103 
104  });
105  }
106  else {
107  pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile"));
108  }
109  }
110 
114  private String shortenPath(String path) {
115  if (path.length() > 100) {
116  path = path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
117  + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator));
118  }
119  return path;
120  }
121 
128  return STATUS;
129  }
130 
137  public void start() {
138  EventQueue.invokeLater(new Runnable() {
139  @Override
140  public void run() {
141  processingLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text"));
142  STATUS = ReportStatus.RUNNING;
143  }
144  });
145  }
146 
152  public void setMaximumProgress(final int max) {
153  EventQueue.invokeLater(new Runnable() {
154  @Override
155  public void run() {
156  if (STATUS != ReportStatus.CANCELED) {
157  reportProgressBar.setMaximum(max);
158  }
159  }
160  });
161  }
162 
166  public void increment() {
167  EventQueue.invokeLater(new Runnable() {
168  @Override
169  public void run() {
170  if (STATUS != ReportStatus.CANCELED) {
171  reportProgressBar.setValue(reportProgressBar.getValue() + 1);
172  }
173  }
174  });
175  }
176 
182  public void setProgress(final int value) {
183  EventQueue.invokeLater(new Runnable() {
184  @Override
185  public void run() {
186  if (STATUS != ReportStatus.CANCELED) {
187  reportProgressBar.setValue(value);
188  }
189  }
190  });
191  }
192 
198  public void setIndeterminate(final boolean indeterminate) {
199  EventQueue.invokeLater(new Runnable() {
200  @Override
201  public void run() {
202  if (STATUS != ReportStatus.CANCELED) {
203  reportProgressBar.setIndeterminate(indeterminate);
204  }
205  }
206  });
207  }
208 
217  public void updateStatusLabel(final String status) {
218  EventQueue.invokeLater(new Runnable() {
219  @Override
220  public void run() {
221  if (STATUS != ReportStatus.CANCELED) {
222  processingLabel.setText(status);
223  }
224  }
225  });
226  }
227 
234  @Deprecated
235  public void complete() {
237  }
244  public void complete(ReportStatus reportStatus) {
245  EventQueue.invokeLater(new Runnable() {
246  @Override
247  public void run() {
248  if (STATUS != ReportStatus.CANCELED) {
249  switch (reportStatus) {
250  case COMPLETE: {
251  STATUS = ReportStatus.COMPLETE;
252  processingLabel.setForeground(Color.BLACK);
253  processingLabel.setText(
254  NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text"));
255  reportProgressBar.setValue(reportProgressBar.getMaximum());
256  reportProgressBar.setStringPainted(true);
257  // set reportProgressBar color as green.
258  reportProgressBar.setForeground(new Color(50,205,50));
259  reportProgressBar.setString("Complete"); //NON-NLS
260  break;
261  }
262  case ERROR: {
263  STATUS = ReportStatus.ERROR;
264  processingLabel.setForeground(new Color(178,34,34));
265  processingLabel.setText(
266  NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text"));
267  reportProgressBar.setValue(reportProgressBar.getMaximum());
268  reportProgressBar.setStringPainted(true);
269  // set reportProgressBar color as red.
270  reportProgressBar.setForeground(new Color(178,34,34));
271  reportProgressBar.setString("Error"); //NON-NLS
272  break;
273  }
274  // add finer grained result codes here.
275  default: {
276  logger.log(Level.SEVERE, "Invalid ReportStatus code {0}", reportStatus); //NON-NLS
277  break;
278  }
279  }
280  }
281  }
282  });
283  // Do something with the button to change the icon and make not clickable
284  }
290  @SuppressWarnings("unchecked")
291  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
292  private void initComponents() {
293 
294  reportProgressBar = new javax.swing.JProgressBar();
295  reportLabel = new javax.swing.JLabel();
296  pathLabel = new javax.swing.JLabel();
297  processingLabel = new javax.swing.JLabel();
298  separationLabel = new javax.swing.JLabel();
299 
300  setMinimumSize(new java.awt.Dimension(486, 68));
301 
302  reportLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
303  org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N
304 
305  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N
306 
307  processingLabel.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
308  org.openide.awt.Mnemonics.setLocalizedText(processingLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.processingLabel.text")); // NOI18N
309 
310  org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N
311 
312  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
313  this.setLayout(layout);
314  layout.setHorizontalGroup(
315  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316  .addGroup(layout.createSequentialGroup()
317  .addContainerGap()
318  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
319  .addComponent(processingLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
320  .addGroup(layout.createSequentialGroup()
321  .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
322  .addGap(58, 58, 58))
323  .addGroup(layout.createSequentialGroup()
324  .addComponent(reportLabel)
325  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
326  .addComponent(separationLabel)
327  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
328  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)))
329  .addContainerGap())
330  );
331  layout.setVerticalGroup(
332  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
333  .addGroup(layout.createSequentialGroup()
334  .addContainerGap()
335  .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
336  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
338  .addComponent(reportLabel)
339  .addComponent(pathLabel)
340  .addComponent(separationLabel))
341  .addGap(0, 0, 0)
342  .addComponent(processingLabel)
343  .addContainerGap(20, Short.MAX_VALUE))
344  );
345  }// </editor-fold>//GEN-END:initComponents
346 
351  void cancel() {
352  switch(STATUS) {
353  case COMPLETE:
354  break;
355  case CANCELED:
356  break;
357  case ERROR:
358  break;
359  default:
360  STATUS = ReportStatus.CANCELED;
361  reportProgressBar.setIndeterminate(false);
362  reportProgressBar.setValue(0);
363  reportProgressBar.setStringPainted(true);
364  // set reportProgressBar color as red.
365  reportProgressBar.setForeground(new Color(178,34,34));
366  reportProgressBar.setString("Cancelled"); //NON-NLS
367  processingLabel.setForeground(new Color(178,34,34));
368  processingLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text"));
369  break;
370  }
371  }
372 
373  // Variables declaration - do not modify//GEN-BEGIN:variables
374  private javax.swing.JLabel pathLabel;
375  private javax.swing.JLabel processingLabel;
376  private javax.swing.JLabel reportLabel;
377  private javax.swing.JProgressBar reportProgressBar;
378  private javax.swing.JLabel separationLabel;
379  // End of variables declaration//GEN-END:variables
380 }
ReportProgressPanel(String reportName, String reportPath)
void customInit(String reportName, String reportPath)
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.