19 package org.sleuthkit.autopsy.report;
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;
29 import java.io.IOException;
30 import java.util.logging.Level;
36 @SuppressWarnings(
"PMD.SingularField")
39 private static final long serialVersionUID = 1L;
41 private static final Color GREEN =
new Color(50, 205, 50);
42 private static final Color RED =
new Color(178, 34, 34);
44 private static final int MAX_STATUS_LENGTH = 500;
45 private static final String ELIPSIS =
"...";
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",})
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());
68 this.displayName = displayName;
82 if (message == null) {
84 }
else if (message.length() > MAX_STATUS_LENGTH) {
85 message = message.substring(0, MAX_STATUS_LENGTH) + ELIPSIS;
87 this.statusMessageLabel.setText(message);
95 reportProgressBar.setIndeterminate(
true);
96 reportProgressBar.setMaximum(100);
97 setStatusText(Bundle.ReportProgressPanel_progress_queuing());
99 reportLabel.setText(
"");
100 pathLabel.setText(
"");
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>");
113 pathLabel.setToolTipText(reportPath);
114 String linkPath = reportPath;
115 pathLabel.addMouseListener(
new MouseListener() {
118 public void mouseClicked(MouseEvent mouseEvent) {
125 public void mousePressed(MouseEvent mouseEvent) {
132 public void mouseReleased(MouseEvent mouseEvent) {
133 File file =
new File(linkPath);
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);
141 Desktop.getDesktop().open(file.getParentFile());
142 }
catch (IOException ioEx2) {
143 logger.log(Level.SEVERE,
"Error opening report file parent", ioEx2);
149 public void mouseEntered(MouseEvent e3) {
150 pathLabel.setForeground(Color.DARK_GRAY);
151 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
155 public void mouseExited(MouseEvent e4) {
156 pathLabel.setForeground(Color.BLACK);
157 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
161 pathLabel.setText(NbBundle.getMessage(
this.getClass(),
"ReportProgressPanel.initPathLabel.noFile"));
180 this.status = status;
187 EventQueue.invokeLater(() -> {
188 setStatusText(NbBundle.getMessage(
this.getClass(),
"ReportProgressPanel.start.progress.text"));
199 EventQueue.invokeLater(() -> {
201 reportProgressBar.setMaximum(max);
211 EventQueue.invokeLater(() -> {
213 reportProgressBar.setValue(reportProgressBar.getValue() + 1);
224 EventQueue.invokeLater(() -> {
226 reportProgressBar.setValue(value);
239 EventQueue.invokeLater(() -> {
241 reportProgressBar.setIndeterminate(indeterminate);
254 EventQueue.invokeLater(() -> {
256 setStatusText(statusMessage);
269 switch (reportStatus) {
271 complete(reportStatus, NbBundle.getMessage(
this.getClass(),
"ReportProgressPanel.complete.processLbl.text"));
274 complete(reportStatus, NbBundle.getMessage(
this.getClass(),
"ReportProgressPanel.complete.processLb2.text"));
277 complete(reportStatus,
"");
290 EventQueue.invokeLater(() -> {
291 reportProgressBar.setIndeterminate(
false);
293 switch (reportStatus) {
297 statusMessageLabel.setForeground(Color.BLACK);
298 setStatusText(statusMessage);
299 reportProgressBar.setValue(reportProgressBar.getMaximum());
300 reportProgressBar.setStringPainted(
true);
301 reportProgressBar.setForeground(GREEN);
309 statusMessageLabel.setForeground(RED);
310 setStatusText(statusMessage);
311 reportProgressBar.setValue(reportProgressBar.getMaximum());
312 reportProgressBar.setStringPainted(
true);
313 reportProgressBar.setForeground(RED);
341 reportProgressBar.setIndeterminate(
false);
342 reportProgressBar.setValue(0);
343 reportProgressBar.setStringPainted(
true);
344 reportProgressBar.setForeground(RED);
347 statusMessageLabel.setForeground(RED);
348 setStatusText(NbBundle.getMessage(
this.getClass(),
"ReportProgressPanel.cancel.procLbl.text"));
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));
374 @SuppressWarnings(
"unchecked")
376 private
void initComponents() {
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();
384 setMinimumSize(
new java.awt.Dimension(486, 68));
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"));
389 org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
org.openide.util.NbBundle.getMessage(
ReportProgressPanel.class,
"ReportProgressPanel.pathLabel.text"));
390 pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
392 org.openide.awt.Mnemonics.setLocalizedText(separationLabel,
org.openide.util.NbBundle.getMessage(
ReportProgressPanel.class,
"ReportProgressPanel.separationLabel.text"));
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"));
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));
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()
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)))
424 layout.setVerticalGroup(
425 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
426 .addGroup(layout.createSequentialGroup()
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)
461 setLabels(reportName, reportPath);
final void setLabels(String reportName, String reportPath)
ReportProgressPanel(String reportName, String reportPath)
void setStatus(ReportStatus status)
void complete(ReportStatus reportStatus)
javax.swing.JLabel reportLabel
javax.swing.JLabel separationLabel
void setIndeterminate(boolean indeterminate)
javax.swing.JLabel pathLabel
void setStatusText(String message)
void setMaximumProgress(int max)
void complete(ReportStatus reportStatus, String statusMessage)
volatile ReportStatus status
ReportStatus(String displayName)
synchronized static Logger getLogger(String name)
javax.swing.JTextArea statusMessageLabel
void updateStatusLabel(String statusMessage)
String shortenPath(String path)
javax.swing.JProgressBar reportProgressBar
void setProgress(int value)