Autopsy 4.22.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-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 */
19package org.sleuthkit.autopsy.report;
20
21import org.openide.util.NbBundle;
22import java.awt.Color;
23import java.awt.Cursor;
24import org.sleuthkit.autopsy.coreutils.Desktop;
25import java.awt.EventQueue;
26import java.awt.event.MouseEvent;
27import java.awt.event.MouseListener;
28import java.io.File;
29import java.io.IOException;
30import java.util.logging.Level;
31import org.sleuthkit.autopsy.coreutils.Logger;
32
36@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
37public 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 private static final int MAX_STATUS_LENGTH = 500;
45 private static final String ELIPSIS = "...";
46
51 @NbBundle.Messages({
52 "ReportProgressPanel.progress.queuing=Queuing...",
53 "ReportProgressPanel.progress.running=Running...",
54 "ReportProgressPanel.progress.complete=Complete",
55 "ReportProgressPanel.progress.canceled=Canceled",
56 "ReportProgressPanel.progress.error=Error",})
57 public enum ReportStatus {
58
59 QUEUING(Bundle.ReportProgressPanel_progress_queuing()),
60 RUNNING(Bundle.ReportProgressPanel_progress_running()),
61 COMPLETE(Bundle.ReportProgressPanel_progress_complete()),
62 CANCELED(Bundle.ReportProgressPanel_progress_canceled()),
63 ERROR(Bundle.ReportProgressPanel_progress_error());
64
65 private final String displayName;
66
68 this.displayName = displayName;
69 }
70
76 public String getDisplayName() {
77 return displayName;
78 }
79 }
80
81 private void setStatusText(String message) {
82 if (message == null) {
83 message = "";
84 } else if (message.length() > MAX_STATUS_LENGTH) {
85 message = message.substring(0, MAX_STATUS_LENGTH) + ELIPSIS;
86 }
87 this.statusMessageLabel.setText(message);
88 }
89
95 reportProgressBar.setIndeterminate(true);
96 reportProgressBar.setMaximum(100);
97 setStatusText(Bundle.ReportProgressPanel_progress_queuing());
99 reportLabel.setText("");
100 pathLabel.setText(""); //NON-NLS
101 }
102
109 public final void setLabels(String reportName, String reportPath) {
110 reportLabel.setText(reportName);
111 if (null != reportPath) {
112 pathLabel.setText("<html><u>" + shortenPath(reportPath) + "</u></html>"); //NON-NLS
113 pathLabel.setToolTipText(reportPath);
114 String linkPath = reportPath;
115 pathLabel.addMouseListener(new MouseListener() {
116
117 @Override
118 public void mouseClicked(MouseEvent mouseEvent) {
119 /*
120 * Do nothing for this event.
121 */
122 }
123
124 @Override
125 public void mousePressed(MouseEvent mouseEvent) {
126 /*
127 * Do nothing for this event.
128 */
129 }
130
131 @Override
132 public void mouseReleased(MouseEvent mouseEvent) {
133 File file = new File(linkPath);
134 try {
135 Desktop.getDesktop().open(file);
136 } catch (IOException ioex) {
137 logger.log(Level.SEVERE, "Error opening report file", ioex);
138 } catch (IllegalArgumentException iaEx) {
139 logger.log(Level.SEVERE, "Error opening report file", iaEx);
140 try {
141 Desktop.getDesktop().open(file.getParentFile());
142 } catch (IOException ioEx2) {
143 logger.log(Level.SEVERE, "Error opening report file parent", ioEx2);
144 }
145 }
146 }
147
148 @Override
149 public void mouseEntered(MouseEvent e3) {
150 pathLabel.setForeground(Color.DARK_GRAY);
151 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
152 }
153
154 @Override
155 public void mouseExited(MouseEvent e4) {
156 pathLabel.setForeground(Color.BLACK);
157 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
158 }
159 });
160 } else {
161 pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile"));
162 }
163 }
164
171 return status;
172 }
173
179 protected void setStatus(ReportStatus status) {
180 this.status = status;
181 }
182
186 public void start() {
187 EventQueue.invokeLater(() -> {
188 setStatusText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text"));
190 });
191 }
192
198 public void setMaximumProgress(int max) {
199 EventQueue.invokeLater(() -> {
201 reportProgressBar.setMaximum(max);
202 }
203 });
204 }
205
210 public void increment() {
211 EventQueue.invokeLater(() -> {
213 reportProgressBar.setValue(reportProgressBar.getValue() + 1);
214 }
215 });
216 }
217
223 public void setProgress(int value) {
224 EventQueue.invokeLater(() -> {
226 reportProgressBar.setValue(value);
227 }
228 });
229 }
230
238 public void setIndeterminate(boolean indeterminate) {
239 EventQueue.invokeLater(() -> {
241 reportProgressBar.setIndeterminate(indeterminate);
242 }
243 });
244 }
245
253 public void updateStatusLabel(String statusMessage) {
254 EventQueue.invokeLater(() -> {
256 setStatusText(statusMessage);
257 }
258 });
259 }
260
267 public void complete(ReportStatus reportStatus) {
268
269 switch (reportStatus) {
270 case COMPLETE:
271 complete(reportStatus, NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text"));
272 break;
273 case ERROR:
274 complete(reportStatus, NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text"));
275 break;
276 default:
277 complete(reportStatus, "");
278 break;
279 }
280 }
281
289 public void complete(ReportStatus reportStatus, String statusMessage) {
290 EventQueue.invokeLater(() -> {
291 reportProgressBar.setIndeterminate(false);
293 switch (reportStatus) {
294 case COMPLETE: {
295 ReportStatus oldValue = status;
297 statusMessageLabel.setForeground(Color.BLACK);
298 setStatusText(statusMessage);
299 reportProgressBar.setValue(reportProgressBar.getMaximum());
300 reportProgressBar.setStringPainted(true);
301 reportProgressBar.setForeground(GREEN);
302 reportProgressBar.setString(ReportStatus.COMPLETE.getDisplayName());
303 firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
304 break;
305 }
306 case ERROR: {
307 ReportStatus oldValue = status;
309 statusMessageLabel.setForeground(RED);
310 setStatusText(statusMessage);
311 reportProgressBar.setValue(reportProgressBar.getMaximum());
312 reportProgressBar.setStringPainted(true);
313 reportProgressBar.setForeground(RED);
314 reportProgressBar.setString(ReportStatus.ERROR.getDisplayName());
315 firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status);
316 break;
317 }
318 default: {
319 break;
320 }
321 }
322 }
323 });
324 }
325
330 public void cancel() {
331 switch (status) {
332 case COMPLETE:
333 break;
334 case CANCELED:
335 break;
336 case ERROR:
337 break;
338 default:
339 ReportStatus oldValue = status;
341 reportProgressBar.setIndeterminate(false);
342 reportProgressBar.setValue(0);
343 reportProgressBar.setStringPainted(true);
344 reportProgressBar.setForeground(RED); // Red
345 reportProgressBar.setString(ReportStatus.CANCELED.getDisplayName());
346 firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status);
347 statusMessageLabel.setForeground(RED);
348 setStatusText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text"));
349 break;
350 }
351 }
352
360 private String shortenPath(String path) {
361 if (path.length() > 100) {
362 return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
363 + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator));
364 } else {
365 return path;
366 }
367 }
368
374 @SuppressWarnings("unchecked")
375 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
376 private void initComponents() {
377
378 reportProgressBar = new javax.swing.JProgressBar();
379 reportLabel = new javax.swing.JLabel();
380 pathLabel = new javax.swing.JLabel();
381 separationLabel = new javax.swing.JLabel();
382 statusMessageLabel = new javax.swing.JTextArea();
383
384 setMinimumSize(new java.awt.Dimension(486, 68));
385
386 reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD));
387 org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N
388
389 org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N
390 pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
391
392 org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N
393
394 statusMessageLabel.setEditable(false);
395 statusMessageLabel.setBackground(null);
396 statusMessageLabel.setLineWrap(true);
397 statusMessageLabel.setRows(5);
398 statusMessageLabel.setTabSize(4);
399 statusMessageLabel.setText(org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.statusMessageLabel.text")); // NOI18N
400 statusMessageLabel.setWrapStyleWord(true);
401 statusMessageLabel.setBorder(null);
402 statusMessageLabel.setMaximumSize(new java.awt.Dimension(2147483647, 80));
403 statusMessageLabel.setMinimumSize(new java.awt.Dimension(101, 80));
404 statusMessageLabel.setOpaque(false);
405 statusMessageLabel.setPreferredSize(new java.awt.Dimension(2147483647, 80));
406
407 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
408 this.setLayout(layout);
409 layout.setHorizontalGroup(
410 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
411 .addGroup(layout.createSequentialGroup()
412 .addContainerGap()
413 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
414 .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
415 .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
416 .addGroup(layout.createSequentialGroup()
417 .addComponent(reportLabel)
418 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
419 .addComponent(separationLabel)
420 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
421 .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
422 .addContainerGap())
423 );
424 layout.setVerticalGroup(
425 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
426 .addGroup(layout.createSequentialGroup()
427 .addContainerGap()
428 .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
429 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
430 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
431 .addComponent(reportLabel)
432 .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
433 .addComponent(separationLabel))
434 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
435 .addComponent(statusMessageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
436 .addGap(13, 13, 13))
437 );
438 }// </editor-fold>//GEN-END:initComponents
439
440
441 // Variables declaration - do not modify//GEN-BEGIN:variables
442 private javax.swing.JLabel pathLabel;
443 private javax.swing.JLabel reportLabel;
444 private javax.swing.JProgressBar reportProgressBar;
445 private javax.swing.JLabel separationLabel;
446 private javax.swing.JTextArea statusMessageLabel;
447 // End of variables declaration//GEN-END:variables
448
458 @Deprecated
459 public ReportProgressPanel(String reportName, String reportPath) {
460 this();
461 setLabels(reportName, reportPath);
462 }
463
470 @Deprecated
471 public void complete() {
473 }
474
475}
synchronized static Logger getLogger(String name)
Definition Logger.java:124
ReportProgressPanel(String reportName, String reportPath)
final void setLabels(String reportName, String reportPath)
void complete(ReportStatus reportStatus, String statusMessage)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.