Autopsy  4.4.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-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.io.File;
26 import java.io.IOException;
27 import java.util.logging.Level;
29 
33 public class ReportProgressPanel extends javax.swing.JPanel {
34 
35  private static final long serialVersionUID = 1L;
36  private static final Logger logger = Logger.getLogger(ReportProgressPanel.class.getName());
37  private static final Color GREEN = new Color(50, 205, 50);
38  private static final Color RED = new Color(178, 34, 34);
40 
45  public enum ReportStatus {
46 
51  ERROR
52  }
53 
60  public ReportProgressPanel(String reportName, String reportPath) {
62  reportProgressBar.setIndeterminate(true);
63  reportProgressBar.setMaximum(100);
64  reportLabel.setText(reportName);
65  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing"));
66  status = ReportStatus.QUEUING;
67  if (null != reportPath) {
68  pathLabel.setText("<html><u>" + shortenPath(reportPath) + "</u></html>"); //NON-NLS
69  pathLabel.setToolTipText(reportPath);
70  String linkPath = reportPath;
71  pathLabel.addMouseListener(new MouseListener() {
72 
73  @Override
74  public void mouseClicked(MouseEvent mouseEvent) {
75  }
76 
77  @Override
78  public void mousePressed(MouseEvent mouseEvent) {
79  }
80 
81  @Override
82  public void mouseReleased(MouseEvent mouseEvent) {
83  File file = new File(linkPath);
84  try {
85  Desktop.getDesktop().open(file);
86  } catch (IOException ioex) {
87  logger.log(Level.SEVERE, "Error opening report file", ioex);
88  } catch (IllegalArgumentException iaEx) {
89  logger.log(Level.SEVERE, "Error opening report file", iaEx);
90  try {
91  Desktop.getDesktop().open(file.getParentFile());
92  } catch (IOException ioEx2) {
93  logger.log(Level.SEVERE, "Error opening report file parent", ioEx2);
94  }
95  }
96  }
97 
98  @Override
99  public void mouseEntered(MouseEvent e3) {
100  pathLabel.setForeground(Color.DARK_GRAY);
101  setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
102  }
103 
104  @Override
105  public void mouseExited(MouseEvent e4) {
106  pathLabel.setForeground(Color.BLACK);
107  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
108  }
109  });
110  } else {
111  pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile"));
112  }
113  }
114 
121  return status;
122  }
123 
127  public void start() {
128  EventQueue.invokeLater(() -> {
129  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text"));
130  status = ReportStatus.RUNNING;
131  });
132  }
133 
139  public void setMaximumProgress(int max) {
140  EventQueue.invokeLater(() -> {
141  if (status != ReportStatus.CANCELED) {
142  reportProgressBar.setMaximum(max);
143  }
144  });
145  }
146 
151  public void increment() {
152  EventQueue.invokeLater(() -> {
153  if (status != ReportStatus.CANCELED) {
154  reportProgressBar.setValue(reportProgressBar.getValue() + 1);
155  }
156  });
157  }
158 
164  public void setProgress(int value) {
165  EventQueue.invokeLater(() -> {
166  if (status != ReportStatus.CANCELED) {
167  reportProgressBar.setValue(value);
168  }
169  });
170  }
171 
179  public void setIndeterminate(boolean indeterminate) {
180  EventQueue.invokeLater(() -> {
181  if (status != ReportStatus.CANCELED) {
182  reportProgressBar.setIndeterminate(indeterminate);
183  }
184  });
185  }
186 
194  public void updateStatusLabel(String statusMessage) {
195  EventQueue.invokeLater(() -> {
196  if (status != ReportStatus.CANCELED) {
197  statusMessageLabel.setText(statusMessage);
198  }
199  });
200  }
201 
208  public void complete(ReportStatus reportStatus) {
209  EventQueue.invokeLater(() -> {
210  reportProgressBar.setIndeterminate(false);
211  if (status != ReportStatus.CANCELED) {
212  switch (reportStatus) {
213  case COMPLETE: {
214  ReportStatus oldValue = status;
215  status = ReportStatus.COMPLETE;
216  statusMessageLabel.setForeground(Color.BLACK);
217  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text"));
218  reportProgressBar.setValue(reportProgressBar.getMaximum());
219  reportProgressBar.setStringPainted(true);
220  reportProgressBar.setForeground(GREEN);
221  reportProgressBar.setString("Complete"); //NON-NLS
222  firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
223  break;
224  }
225  case ERROR: {
226  ReportStatus oldValue = status;
227  status = ReportStatus.ERROR;
228  statusMessageLabel.setForeground(RED);
229  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text"));
230  reportProgressBar.setValue(reportProgressBar.getMaximum());
231  reportProgressBar.setStringPainted(true);
232  reportProgressBar.setForeground(RED);
233  reportProgressBar.setString("Error"); //NON-NLS
234  firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
235  break;
236  }
237  default: {
238  break;
239  }
240  }
241  }
242  });
243  }
244 
249  void cancel() {
250  switch (status) {
251  case COMPLETE:
252  break;
253  case CANCELED:
254  break;
255  case ERROR:
256  break;
257  default:
258  ReportStatus oldValue = status;
259  status = ReportStatus.CANCELED;
260  reportProgressBar.setIndeterminate(false);
261  reportProgressBar.setValue(0);
262  reportProgressBar.setStringPainted(true);
263  reportProgressBar.setForeground(RED); // Red
264  reportProgressBar.setString("Cancelled"); //NON-NLS
265  firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status);
266  statusMessageLabel.setForeground(RED);
267  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text"));
268  break;
269  }
270  }
271 
279  private String shortenPath(String path) {
280  if (path.length() > 100) {
281  return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
282  + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator));
283  } else {
284  return path;
285  }
286  }
287 
293  @SuppressWarnings("unchecked")
294  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
295  private void initComponents() {
296 
297  reportProgressBar = new javax.swing.JProgressBar();
298  reportLabel = new javax.swing.JLabel();
299  pathLabel = new javax.swing.JLabel();
300  separationLabel = new javax.swing.JLabel();
301  statusMessageLabel = new javax.swing.JLabel();
302 
303  setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
304  setMinimumSize(new java.awt.Dimension(486, 68));
305 
306  reportProgressBar.setFont(reportProgressBar.getFont().deriveFont(reportProgressBar.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
307 
308  reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD, 11));
309  org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N
310 
311  pathLabel.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
312  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N
313  pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
314 
315  separationLabel.setFont(separationLabel.getFont().deriveFont(separationLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
316  org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N
317 
318  org.openide.awt.Mnemonics.setLocalizedText(statusMessageLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.statusMessageLabel.text")); // NOI18N
319 
320  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
321  this.setLayout(layout);
322  layout.setHorizontalGroup(
323  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324  .addGroup(layout.createSequentialGroup()
325  .addContainerGap()
326  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
327  .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
328  .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
329  .addGroup(layout.createSequentialGroup()
330  .addComponent(reportLabel)
331  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
332  .addComponent(separationLabel)
333  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
334  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)))
335  .addContainerGap())
336  );
337  layout.setVerticalGroup(
338  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
339  .addGroup(layout.createSequentialGroup()
340  .addContainerGap()
341  .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
342  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
343  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
344  .addComponent(reportLabel)
345  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
346  .addComponent(separationLabel))
347  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
348  .addComponent(statusMessageLabel)
349  .addGap(13, 13, 13))
350  );
351  }// </editor-fold>//GEN-END:initComponents
352 
353 
354  // Variables declaration - do not modify//GEN-BEGIN:variables
355  private javax.swing.JLabel pathLabel;
356  private javax.swing.JLabel reportLabel;
357  private javax.swing.JProgressBar reportProgressBar;
358  private javax.swing.JLabel separationLabel;
359  private javax.swing.JLabel statusMessageLabel;
360  // End of variables declaration//GEN-END:variables
361 
368  @Deprecated
369  public void complete() {
371  }
372 
373 }
ReportProgressPanel(String reportName, String reportPath)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.