Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardAddingProgressPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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.casemodule;
20 
21 import java.awt.Color;
22 import java.awt.EventQueue;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Set;
26 import javax.swing.event.ChangeEvent;
27 import javax.swing.event.ChangeListener;
28 import org.openide.WizardDescriptor;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.Lookup;
31 import org.openide.util.NbBundle;
33 
42 class AddImageWizardAddingProgressPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
43 
48  private boolean imgAdded = false;
53  private AddImageWizardAddingProgressVisual component;
54  private final Set<ChangeListener> listeners = new HashSet<>(1); // or can use ChangeSupport in NB 6.0
55 
56  private DSPProgressMonitorImpl dspProgressMonitorImpl = new DSPProgressMonitorImpl();
57 
58  public DSPProgressMonitorImpl getDSPProgressMonitorImpl() {
59  return dspProgressMonitorImpl;
60  }
61 
63 
64  @Override
65  public void setIndeterminate(final boolean indeterminate) {
66  // update the progress bar asynchronously
67  EventQueue.invokeLater(new Runnable() {
68  @Override
69  public void run() {
70  getComponent().getProgressBar().setIndeterminate(indeterminate);
71  }
72  });
73  }
74 
75  @Override
76  public void setProgress(final int progress) {
77  // update the progress bar asynchronously
78  EventQueue.invokeLater(new Runnable() {
79  @Override
80  public void run() {
81  getComponent().getProgressBar().setValue(progress);
82  }
83  });
84  }
85 
86  @Override
87  public void setProgressText(final String text) {
88  // update the progress UI asynchronously
89  EventQueue.invokeLater(new Runnable() {
90  @Override
91  public void run() {
92  getComponent().setProgressMsgText(text);
93  }
94  });
95  }
96 
97  }
98 
109  @Override
110  public AddImageWizardAddingProgressVisual getComponent() {
111  if (component == null) {
112  component = new AddImageWizardAddingProgressVisual();
113  }
114  return component;
115  }
116 
123  @Override
124  public HelpCtx getHelp() {
125  // Show no Help button for this panel:
126  return HelpCtx.DEFAULT_HELP;
127  }
128 
135  @Override
136  public boolean isValid() {
137  // set the focus to the next button of the wizard dialog if it's enabled
138  if (imgAdded) {
139  Lookup.getDefault().lookup(AddImageAction.class).requestFocusButton(
140  NbBundle.getMessage(this.getClass(), "AddImageWizardAddingProgressPanel.isValid.focusNext"));
141  }
142 
143  return imgAdded;
144  }
145 
149  void setStateStarted() {
150  component.getProgressBar().setIndeterminate(true);
151  component.setProgressBarTextAndColor(
152  NbBundle.getMessage(this.getClass(), "AddImageWizardAddingProgressPanel.stateStarted.progressBarText"), 0, Color.black);
153  }
154 
158  void setStateFinished() {
159  imgAdded = true;
160  getComponent().setStateFinished();
161  fireChangeEvent();
162  }
163 
169  @Override
170  public final void addChangeListener(ChangeListener l) {
171  synchronized (listeners) {
172  listeners.add(l);
173  }
174  }
175 
181  @Override
182  public final void removeChangeListener(ChangeListener l) {
183  synchronized (listeners) {
184  listeners.remove(l);
185  }
186  }
187 
192  protected final void fireChangeEvent() {
193  Iterator<ChangeListener> it;
194  synchronized (listeners) {
195  it = new HashSet<ChangeListener>(listeners).iterator();
196  }
197  ChangeEvent ev = new ChangeEvent(this);
198  while (it.hasNext()) {
199  it.next().stateChanged(ev);
200  }
201  }
202 
209  @Override
210  public void readSettings(WizardDescriptor settings) {
211  settings.setOptions(new Object[]{WizardDescriptor.PREVIOUS_OPTION, WizardDescriptor.NEXT_OPTION, WizardDescriptor.FINISH_OPTION, WizardDescriptor.CANCEL_OPTION});
212  if (imgAdded) {
213  getComponent().setStateFinished();
214  }
215  }
216 
223  @Override
224  public void storeSettings(WizardDescriptor settings) {
225  //why did we do this? -jm
226  // getComponent().resetInfoPanel();
227  }
228 
238  void addErrors(String errorString, boolean critical) {
239  getComponent().showErrors(errorString, critical);
240  }
241 
242  @Override
243  public boolean isFinishPanel() {
244  return true;
245  }
246 }

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