Autopsy  4.0
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-2016 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.*;
23 import java.awt.event.MouseEvent;
24 import java.awt.event.MouseListener;
25 import java.beans.PropertyChangeListener;
26 import java.beans.PropertyChangeSupport;
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.logging.Level;
31 
35 public class ReportProgressPanel extends javax.swing.JPanel {
36 
37  private static final long serialVersionUID = 1L;
38  private static final Logger logger = Logger.getLogger(ReportProgressPanel.class.getName());
39  private static final Color GREEN = new Color(50, 205, 50);
40  private static final Color RED = new Color(178, 34, 34);
41  private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
43 
48  public enum ReportStatus {
49 
54  ERROR
55  }
56 
63  public ReportProgressPanel(String reportName, String reportPath) {
65  reportProgressBar.setIndeterminate(true);
66  reportProgressBar.setMaximum(100);
67  reportLabel.setText(reportName);
68  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing"));
69  status = ReportStatus.QUEUING;
70  if (null != reportPath) {
71  pathLabel.setText("<html><u>" + shortenPath(reportPath) + "</u></html>"); //NON-NLS
72  pathLabel.setToolTipText(reportPath);
73  String linkPath = reportPath;
74  pathLabel.addMouseListener(new MouseListener() {
75 
76  @Override
77  public void mouseClicked(MouseEvent mouseEvent) {
78  }
79 
80  @Override
81  public void mousePressed(MouseEvent mouseEvent) {
82  }
83 
84  @Override
85  public void mouseReleased(MouseEvent mouseEvent) {
86  File file = new File(linkPath);
87  try {
88  Desktop.getDesktop().open(file);
89  } catch (IOException ioex) {
90  logger.log(Level.SEVERE, "Error opening report file", ioex);
91  } catch (IllegalArgumentException iaEx) {
92  logger.log(Level.SEVERE, "Error opening report file", iaEx);
93  try {
94  Desktop.getDesktop().open(file.getParentFile());
95  } catch (IOException ioEx2) {
96  logger.log(Level.SEVERE, "Error opening report file parent", ioEx2);
97  }
98  }
99  }
100 
101  @Override
102  public void mouseEntered(MouseEvent e3) {
103  pathLabel.setForeground(Color.DARK_GRAY);
104  setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
105  }
106 
107  @Override
108  public void mouseExited(MouseEvent e4) {
109  pathLabel.setForeground(Color.BLACK);
110  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
111  }
112  });
113  } else {
114  pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile"));
115  }
116  }
117 
123  @Override
124  public void addPropertyChangeListener(PropertyChangeListener listener) {
125  this.pcs.addPropertyChangeListener(listener);
126  }
127 
133  @Override
134  public void removePropertyChangeListener(PropertyChangeListener listener) {
135  this.pcs.removePropertyChangeListener(listener);
136  }
137 
144  return status;
145  }
146 
150  public void start() {
151  EventQueue.invokeLater(() -> {
152  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text"));
153  status = ReportStatus.RUNNING;
154  });
155  }
156 
162  public void setMaximumProgress(int max) {
163  EventQueue.invokeLater(() -> {
164  if (status != ReportStatus.CANCELED) {
165  reportProgressBar.setMaximum(max);
166  }
167  });
168  }
169 
174  public void increment() {
175  EventQueue.invokeLater(() -> {
176  if (status != ReportStatus.CANCELED) {
177  reportProgressBar.setValue(reportProgressBar.getValue() + 1);
178  }
179  });
180  }
181 
187  public void setProgress(int value) {
188  EventQueue.invokeLater(() -> {
189  if (status != ReportStatus.CANCELED) {
190  reportProgressBar.setValue(value);
191  }
192  });
193  }
194 
202  public void setIndeterminate(boolean indeterminate) {
203  EventQueue.invokeLater(() -> {
204  if (status != ReportStatus.CANCELED) {
205  reportProgressBar.setIndeterminate(indeterminate);
206  }
207  });
208  }
209 
217  public void updateStatusLabel(String statusMessage) {
218  EventQueue.invokeLater(() -> {
219  if (status != ReportStatus.CANCELED) {
220  statusMessageLabel.setText(statusMessage);
221  }
222  });
223  }
224 
231  public void complete(ReportStatus reportStatus) {
232  EventQueue.invokeLater(() -> {
233  reportProgressBar.setIndeterminate(false);
234  if (status != ReportStatus.CANCELED) {
235  switch (reportStatus) {
236  case COMPLETE: {
237  ReportStatus oldValue = status;
238  status = ReportStatus.COMPLETE;
239  statusMessageLabel.setForeground(Color.BLACK);
240  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text"));
241  reportProgressBar.setValue(reportProgressBar.getMaximum());
242  reportProgressBar.setStringPainted(true);
243  reportProgressBar.setForeground(GREEN);
244  reportProgressBar.setString("Complete"); //NON-NLS
245  pcs.firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
246  break;
247  }
248  case ERROR: {
249  ReportStatus oldValue = status;
250  status = ReportStatus.ERROR;
251  statusMessageLabel.setForeground(RED);
252  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text"));
253  reportProgressBar.setValue(reportProgressBar.getMaximum());
254  reportProgressBar.setStringPainted(true);
255  reportProgressBar.setForeground(RED);
256  reportProgressBar.setString("Error"); //NON-NLS
257  pcs.firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
258  break;
259  }
260  default: {
261  break;
262  }
263  }
264  }
265  });
266  }
267 
272  void cancel() {
273  switch (status) {
274  case COMPLETE:
275  break;
276  case CANCELED:
277  break;
278  case ERROR:
279  break;
280  default:
281  ReportStatus oldValue = status;
282  status = ReportStatus.CANCELED;
283  reportProgressBar.setIndeterminate(false);
284  reportProgressBar.setValue(0);
285  reportProgressBar.setStringPainted(true);
286  reportProgressBar.setForeground(RED); // Red
287  reportProgressBar.setString("Cancelled"); //NON-NLS
288  pcs.firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status);
289  statusMessageLabel.setForeground(RED);
290  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text"));
291  break;
292  }
293  }
294 
302  private String shortenPath(String path) {
303  if (path.length() > 100) {
304  return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
305  + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator));
306  } else {
307  return path;
308  }
309  }
310 
316  @SuppressWarnings("unchecked")
317  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
318  private void initComponents() {
319 
320  reportProgressBar = new javax.swing.JProgressBar();
321  reportLabel = new javax.swing.JLabel();
322  pathLabel = new javax.swing.JLabel();
323  separationLabel = new javax.swing.JLabel();
324  statusMessageLabel = new javax.swing.JLabel();
325 
326  setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
327  setMinimumSize(new java.awt.Dimension(486, 68));
328 
329  reportProgressBar.setFont(reportProgressBar.getFont().deriveFont(reportProgressBar.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
330 
331  reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD, 11));
332  org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N
333 
334  pathLabel.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
335  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N
336  pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
337 
338  separationLabel.setFont(separationLabel.getFont().deriveFont(separationLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
339  org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N
340 
341  org.openide.awt.Mnemonics.setLocalizedText(statusMessageLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.statusMessageLabel.text")); // NOI18N
342 
343  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
344  this.setLayout(layout);
345  layout.setHorizontalGroup(
346  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347  .addGroup(layout.createSequentialGroup()
348  .addContainerGap()
349  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
350  .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
351  .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
352  .addGroup(layout.createSequentialGroup()
353  .addComponent(reportLabel)
354  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
355  .addComponent(separationLabel)
356  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
357  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)))
358  .addContainerGap())
359  );
360  layout.setVerticalGroup(
361  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
362  .addGroup(layout.createSequentialGroup()
363  .addContainerGap()
364  .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
365  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
366  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
367  .addComponent(reportLabel)
368  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
369  .addComponent(separationLabel))
370  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371  .addComponent(statusMessageLabel)
372  .addGap(13, 13, 13))
373  );
374  }// </editor-fold>//GEN-END:initComponents
375 
376 
377  // Variables declaration - do not modify//GEN-BEGIN:variables
378  private javax.swing.JLabel pathLabel;
379  private javax.swing.JLabel reportLabel;
380  private javax.swing.JProgressBar reportProgressBar;
381  private javax.swing.JLabel separationLabel;
382  private javax.swing.JLabel statusMessageLabel;
383  // End of variables declaration//GEN-END:variables
384 
391  @Deprecated
392  public void complete() {
394  }
395 
396 }
ReportProgressPanel(String reportName, String reportPath)
void removePropertyChangeListener(PropertyChangeListener listener)
void addPropertyChangeListener(PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

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