Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ConfigWizardPanel1.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.logicalimager.configuration;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
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.WizardValidationException;
30 import org.openide.util.HelpCtx;
31 
35 final class ConfigWizardPanel1 implements WizardDescriptor.ValidatingPanel<WizardDescriptor> {
36 
41  private ConfigVisualPanel1 component;
42  private boolean valid = false;
43 
44  // Get the visual component for the panel. In this template, the component
45  // is kept separate. This can be more efficient: if the wizard is created
46  // but never displayed, or not all panels are displayed, it is better to
47  // create only those which really need to be visible.
48  @Override
49  public ConfigVisualPanel1 getComponent() {
50  if (component == null) {
51  component = new ConfigVisualPanel1();
52  component.addPropertyChangeListener(new PropertyChangeListener() {
53  @Override
54  public void propertyChange(PropertyChangeEvent evt) {
55  if (evt.getPropertyName().equals(ConfigVisualPanel1.getUpdateEventName())) { // NON-NLS
56  valid = component.isPanelValid();
57  fireChangeEvent();
58  }
59  }
60  });
61 
62  }
63  return component;
64  }
65 
66  @Override
67  public HelpCtx getHelp() {
68  // Show no Help button for this panel:
69  return HelpCtx.DEFAULT_HELP;
70  // If you have context help:
71  // return new HelpCtx("help.key.here");
72  }
73 
74  @Override
75  public boolean isValid() {
76  return valid;
77  // If it depends on some condition (form filled out...) and
78  // this condition changes (last form field filled in...) then
79  // use ChangeSupport to implement add/removeChangeListener below.
80  // WizardDescriptor.ERROR/WARNING/INFORMATION_MESSAGE will also be useful.
81  }
82 
83  private final Set<ChangeListener> listeners = new HashSet<>(1); // or can use ChangeSupport in NB 6.0
84 
90  @Override
91  public void addChangeListener(ChangeListener l) {
92  synchronized (listeners) {
93  listeners.add(l);
94  }
95  }
96 
102  @Override
103  public void removeChangeListener(ChangeListener l) {
104  synchronized (listeners) {
105  listeners.remove(l);
106  }
107  }
108 
113  void fireChangeEvent() {
114  Iterator<ChangeListener> it;
115  synchronized (listeners) {
116  it = new HashSet<>(listeners).iterator();
117  }
118  ChangeEvent ev = new ChangeEvent(this);
119  while (it.hasNext()) {
120  it.next().stateChanged(ev);
121  }
122  }
123 
124  @Override
125  public void readSettings(WizardDescriptor wiz) {
126  // use wiz.getProperty to retrieve previous panel state
127  component.setConfigFilename((String) wiz.getProperty("configFilename")); // NON-NLS
128  }
129 
130  @Override
131  public void storeSettings(WizardDescriptor wiz) {
132  // use wiz.putProperty to remember current panel state
133  wiz.putProperty("configFilename", component.getConfigPath()); // NON-NLS
134  wiz.putProperty("config", component.getConfig()); // NON-NLS
135  }
136 
137  @Override
138  public void validate() throws WizardValidationException {
139  valid = component.isPanelValid();
140  }
141 
142 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.