Autopsy  4.19.3
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-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.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  @NbBundle.Messages({
50  "ReportProgressPanel.progress.queuing=Queuing...",
51  "ReportProgressPanel.progress.running=Running...",
52  "ReportProgressPanel.progress.complete=Complete",
53  "ReportProgressPanel.progress.canceled=Canceled",
54  "ReportProgressPanel.progress.error=Error",})
55  public enum ReportStatus {
56 
57  QUEUING(Bundle.ReportProgressPanel_progress_queuing()),
58  RUNNING(Bundle.ReportProgressPanel_progress_running()),
59  COMPLETE(Bundle.ReportProgressPanel_progress_complete()),
60  CANCELED(Bundle.ReportProgressPanel_progress_canceled()),
61  ERROR(Bundle.ReportProgressPanel_progress_error());
62 
63  private final String displayName;
64 
65  ReportStatus(String displayName) {
66  this.displayName = displayName;
67  }
68 
74  public String getDisplayName() {
75  return displayName;
76  }
77  }
78 
83  initComponents();
84  reportProgressBar.setIndeterminate(true);
85  reportProgressBar.setMaximum(100);
86  statusMessageLabel.setText(Bundle.ReportProgressPanel_progress_queuing());
87  status = ReportStatus.QUEUING;
88  reportLabel.setText("");
89  pathLabel.setText(""); //NON-NLS
90  }
91 
98  public final void setLabels(String reportName, String reportPath) {
99  reportLabel.setText(reportName);
100  if (null != reportPath) {
101  pathLabel.setText("<html><u>" + shortenPath(reportPath) + "</u></html>"); //NON-NLS
102  pathLabel.setToolTipText(reportPath);
103  String linkPath = reportPath;
104  pathLabel.addMouseListener(new MouseListener() {
105 
106  @Override
107  public void mouseClicked(MouseEvent mouseEvent) {
108  /*
109  * Do nothing for this event.
110  */
111  }
112 
113  @Override
114  public void mousePressed(MouseEvent mouseEvent) {
115  /*
116  * Do nothing for this event.
117  */
118  }
119 
120  @Override
121  public void mouseReleased(MouseEvent mouseEvent) {
122  File file = new File(linkPath);
123  try {
124  Desktop.getDesktop().open(file);
125  } catch (IOException ioex) {
126  logger.log(Level.SEVERE, "Error opening report file", ioex);
127  } catch (IllegalArgumentException iaEx) {
128  logger.log(Level.SEVERE, "Error opening report file", iaEx);
129  try {
130  Desktop.getDesktop().open(file.getParentFile());
131  } catch (IOException ioEx2) {
132  logger.log(Level.SEVERE, "Error opening report file parent", ioEx2);
133  }
134  }
135  }
136 
137  @Override
138  public void mouseEntered(MouseEvent e3) {
139  pathLabel.setForeground(Color.DARK_GRAY);
140  setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
141  }
142 
143  @Override
144  public void mouseExited(MouseEvent e4) {
145  pathLabel.setForeground(Color.BLACK);
146  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
147  }
148  });
149  } else {
150  pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile"));
151  }
152  }
153 
160  return status;
161  }
162 
168  protected void setStatus(ReportStatus status) {
169  this.status = status;
170  }
171 
175  public void start() {
176  EventQueue.invokeLater(() -> {
177  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text"));
178  status = ReportStatus.RUNNING;
179  });
180  }
181 
187  public void setMaximumProgress(int max) {
188  EventQueue.invokeLater(() -> {
189  if (status != ReportStatus.CANCELED) {
190  reportProgressBar.setMaximum(max);
191  }
192  });
193  }
194 
199  public void increment() {
200  EventQueue.invokeLater(() -> {
201  if (status != ReportStatus.CANCELED) {
202  reportProgressBar.setValue(reportProgressBar.getValue() + 1);
203  }
204  });
205  }
206 
212  public void setProgress(int value) {
213  EventQueue.invokeLater(() -> {
214  if (status != ReportStatus.CANCELED) {
215  reportProgressBar.setValue(value);
216  }
217  });
218  }
219 
227  public void setIndeterminate(boolean indeterminate) {
228  EventQueue.invokeLater(() -> {
229  if (status != ReportStatus.CANCELED) {
230  reportProgressBar.setIndeterminate(indeterminate);
231  }
232  });
233  }
234 
242  public void updateStatusLabel(String statusMessage) {
243  EventQueue.invokeLater(() -> {
244  if (status != ReportStatus.CANCELED) {
245  statusMessageLabel.setText(statusMessage);
246  }
247  });
248  }
249 
256  public void complete(ReportStatus reportStatus) {
257 
258  switch (reportStatus) {
259  case COMPLETE:
260  complete(reportStatus, NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text"));
261  break;
262  case ERROR:
263  complete(reportStatus, NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text"));
264  break;
265  default:
266  complete(reportStatus, "");
267  break;
268  }
269  }
270 
278  public void complete(ReportStatus reportStatus, String statusMessage) {
279  EventQueue.invokeLater(() -> {
280  reportProgressBar.setIndeterminate(false);
281  if (status != ReportStatus.CANCELED) {
282  switch (reportStatus) {
283  case COMPLETE: {
284  ReportStatus oldValue = status;
285  status = ReportStatus.COMPLETE;
286  statusMessageLabel.setForeground(Color.BLACK);
287  statusMessageLabel.setText(statusMessage);
288  reportProgressBar.setValue(reportProgressBar.getMaximum());
289  reportProgressBar.setStringPainted(true);
290  reportProgressBar.setForeground(GREEN);
291  reportProgressBar.setString(ReportStatus.COMPLETE.getDisplayName());
292  firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
293  break;
294  }
295  case ERROR: {
296  ReportStatus oldValue = status;
297  status = ReportStatus.ERROR;
298  statusMessageLabel.setForeground(RED);
299  statusMessageLabel.setText(statusMessage);
300  reportProgressBar.setValue(reportProgressBar.getMaximum());
301  reportProgressBar.setStringPainted(true);
302  reportProgressBar.setForeground(RED);
303  reportProgressBar.setString(ReportStatus.ERROR.getDisplayName());
304  firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
305  break;
306  }
307  default: {
308  break;
309  }
310  }
311  }
312  });
313  }
314 
319  public void cancel() {
320  switch (status) {
321  case COMPLETE:
322  break;
323  case CANCELED:
324  break;
325  case ERROR:
326  break;
327  default:
328  ReportStatus oldValue = status;
329  status = ReportStatus.CANCELED;
330  reportProgressBar.setIndeterminate(false);
331  reportProgressBar.setValue(0);
332  reportProgressBar.setStringPainted(true);
333  reportProgressBar.setForeground(RED); // Red
334  reportProgressBar.setString(ReportStatus.CANCELED.getDisplayName());
335  firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status);
336  statusMessageLabel.setForeground(RED);
337  statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text"));
338  break;
339  }
340  }
341 
349  private String shortenPath(String path) {
350  if (path.length() > 100) {
351  return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
352  + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator));
353  } else {
354  return path;
355  }
356  }
357 
363  @SuppressWarnings("unchecked")
364  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
365  private void initComponents() {
366 
367  reportProgressBar = new javax.swing.JProgressBar();
368  reportLabel = new javax.swing.JLabel();
369  pathLabel = new javax.swing.JLabel();
370  separationLabel = new javax.swing.JLabel();
371  statusMessageLabel = new javax.swing.JLabel();
372 
373  setMinimumSize(new java.awt.Dimension(486, 68));
374 
375  reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD));
376  org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N
377 
378  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N
379  pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
380 
381  org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N
382 
383  org.openide.awt.Mnemonics.setLocalizedText(statusMessageLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.statusMessageLabel.text")); // NOI18N
384 
385  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
386  this.setLayout(layout);
387  layout.setHorizontalGroup(
388  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
389  .addGroup(layout.createSequentialGroup()
390  .addContainerGap()
391  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
392  .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
393  .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
394  .addGroup(layout.createSequentialGroup()
395  .addComponent(reportLabel)
396  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
397  .addComponent(separationLabel)
398  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
399  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)))
400  .addContainerGap())
401  );
402  layout.setVerticalGroup(
403  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
404  .addGroup(layout.createSequentialGroup()
405  .addContainerGap()
406  .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
407  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
408  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
409  .addComponent(reportLabel)
410  .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
411  .addComponent(separationLabel))
412  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
413  .addComponent(statusMessageLabel)
414  .addGap(13, 13, 13))
415  );
416  }// </editor-fold>//GEN-END:initComponents
417 
418 
419  // Variables declaration - do not modify//GEN-BEGIN:variables
420  private javax.swing.JLabel pathLabel;
421  private javax.swing.JLabel reportLabel;
422  private javax.swing.JProgressBar reportProgressBar;
423  private javax.swing.JLabel separationLabel;
424  private javax.swing.JLabel statusMessageLabel;
425  // End of variables declaration//GEN-END:variables
426 
436  @Deprecated
437  public ReportProgressPanel(String reportName, String reportPath) {
438  this();
439  setLabels(reportName, reportPath);
440  }
441 
448  @Deprecated
449  public void complete() {
450  complete(ReportStatus.COMPLETE);
451  }
452 
453 }
final void setLabels(String reportName, String reportPath)
ReportProgressPanel(String reportName, String reportPath)
void complete(ReportStatus reportStatus, String statusMessage)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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