Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ModalDialogProgressIndicator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.framework;
20 
21 import java.awt.Dialog;
22 import java.awt.Frame;
23 import java.awt.event.ActionListener;
24 import javax.swing.JDialog;
25 import javax.swing.SwingUtilities;
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.util.HelpCtx;
29 
35 public final class ModalDialogProgressIndicator implements ProgressIndicator {
36 
37  private final Frame parent;
38  private final ProgressPanel progressPanel;
39  private final Dialog dialog;
40  private final ActionListener buttonListener;
41 
54  public ModalDialogProgressIndicator(Frame parent, String title, Object[] buttonLabels, Object focusedButtonLabel, ActionListener buttonListener) {
55  this.parent = parent;
56  progressPanel = new ProgressPanel();
57  DialogDescriptor dialogDescriptor = new DialogDescriptor(
58  progressPanel,
59  title,
60  true,
61  buttonLabels,
62  focusedButtonLabel,
63  DialogDescriptor.BOTTOM_ALIGN,
64  HelpCtx.DEFAULT_HELP,
65  buttonListener);
66  dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
67  this.buttonListener = buttonListener;
68  }
69 
77  public ModalDialogProgressIndicator(Frame parent, String title) {
78  this.parent = parent;
79  progressPanel = new ProgressPanel();
80  dialog = new JDialog(parent, title, true);
81  dialog.add(progressPanel);
82  dialog.pack();
83  buttonListener = null;
84  }
85 
91  public void setVisible(boolean isVisible) {
92  if (isVisible) {
93  dialog.setLocationRelativeTo(parent);
94  }
95  this.dialog.setVisible(isVisible);
96  }
97 
103  public ActionListener getButtonListener() {
104  return buttonListener;
105  }
106 
114  @Override
115  public void start(String message, int totalWorkUnits) {
116  SwingUtilities.invokeLater(new Runnable() {
117  @Override
118  public void run() {
119  progressPanel.setInderminate(false);
120  progressPanel.setMessage(message);
121  progressPanel.setMaximum(totalWorkUnits);
122  }
123  });
124  }
125 
132  @Override
133  public void start(String message) {
134  SwingUtilities.invokeLater(new Runnable() {
135  @Override
136  public void run() {
137  progressPanel.setInderminate(true);
138  progressPanel.setMessage(message);
139  }
140  });
141  }
142 
149  @Override
150  public void switchToIndeterminate(String message) {
151  SwingUtilities.invokeLater(new Runnable() {
152  @Override
153  public void run() {
154  progressPanel.setInderminate(true);
155  progressPanel.setMessage(message);
156  }
157  });
158  }
159 
168  @Override
169  public void switchToDeterminate(String message, int workUnitsCompleted, int totalWorkUnits) {
170  SwingUtilities.invokeLater(new Runnable() {
171  @Override
172  public void run() {
173  progressPanel.setInderminate(false);
174  progressPanel.setMessage(message);
175  progressPanel.setMaximum(totalWorkUnits);
176  progressPanel.setCurrent(workUnitsCompleted);
177  }
178  });
179  }
180 
186  @Override
187  public void progress(String message) {
188  SwingUtilities.invokeLater(new Runnable() {
189  @Override
190  public void run() {
191  progressPanel.setMessage(message);
192  }
193  });
194  }
195 
203  @Override
204  public void progress(int workUnitsCompleted) {
205  SwingUtilities.invokeLater(new Runnable() {
206  @Override
207  public void run() {
208  progressPanel.setCurrent(workUnitsCompleted);
209  }
210  });
211  }
212 
221  @Override
222  public void progress(String message, int workUnitsCompleted) {
223  SwingUtilities.invokeLater(new Runnable() {
224  @Override
225  public void run() {
226  progressPanel.setMessage(message);
227  progressPanel.setCurrent(workUnitsCompleted);
228  }
229  });
230  }
231 
237  @Override
238  public void finish(String message) {
239  SwingUtilities.invokeLater(new Runnable() {
240  @Override
241  public void run() {
242  progressPanel.setMessage(message);
243  }
244  });
245  }
246 
247 }
void switchToDeterminate(String message, int workUnitsCompleted, int totalWorkUnits)
ModalDialogProgressIndicator(Frame parent, String title, Object[] buttonLabels, Object focusedButtonLabel, ActionListener buttonListener)

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