Cleaned up whitespace, fix DOS line endings
[nbgit.git] / src / org / nbgit / ui / custom / CustomWizardPanel.java
blob65679d1467c8a752fe7133955762802d05e35ad6
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2008 Jonas Fonseca <fonseca@diku.dk>
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html. See the License for the
12 * specific language governing permissions and limitations under the
13 * License. When distributing the software, include this License Header
14 * Notice in each file.
16 * This particular file is subject to the "Classpath" exception as provided
17 * by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the
19 * License Header, with the fields enclosed by brackets [] replaced by
20 * your own identifying information:
21 * "Portions Copyrighted [year] [name of copyright owner]"
23 * Contributor(s):
25 * If you wish your version of this file to be governed by only the CDDL
26 * or only the GPL Version 2, indicate your decision by adding
27 * "[Contributor] elects to include this software in this distribution
28 * under the [CDDL or GPL Version 2] license." If you do not indicate a
29 * single choice of license, a recipient has the option to distribute
30 * your version of this file under either the CDDL, the GPL Version 2 or
31 * to extend the choice of license to its licensees as provided above.
32 * However, if you add GPL Version 2 code and therefore, elected the GPL
33 * Version 2 license, then the option applies only if the new code is
34 * made subject to such option by the copyright holder.
36 package org.nbgit.ui.custom;
38 import java.awt.Component;
39 import java.util.HashSet;
40 import java.util.Set;
41 import javax.swing.event.ChangeEvent;
42 import javax.swing.event.ChangeListener;
43 import org.openide.WizardDescriptor;
44 import org.openide.util.HelpCtx;
46 public class CustomWizardPanel implements WizardDescriptor.Panel<WizardDescriptor> {
48 /**
49 * The visual component that displays this panel. If you need to access the
50 * component from this class, just use getComponent().
52 private Component component;
53 private CustomActionBuilder builder;
55 CustomWizardPanel(CustomActionBuilder builder) {
56 this.builder = builder;
59 // Get the visual component for the panel. In this template, the component
60 // is kept separate. This can be more efficient: if the wizard is created
61 // but never displayed, or not all panels are displayed, it is better to
62 // create only those which really need to be visible.
63 public Component getComponent() {
64 if (component == null) {
65 component = new CustomVisualPanel(this, builder);
67 return component;
70 public HelpCtx getHelp() {
71 // Show no Help button for this panel:
72 return HelpCtx.DEFAULT_HELP;
73 // If you have context help:
74 // return new HelpCtx(SampleWizardPanel.class);
77 public boolean isValid() {
78 return builder.isValid();
81 private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1); // or can use ChangeSupport in NB 6.0
83 public final void addChangeListener(ChangeListener l) {
84 synchronized (listeners) {
85 listeners.add(l);
89 public final void removeChangeListener(ChangeListener l) {
90 synchronized (listeners) {
91 listeners.remove(l);
95 public final void fireChangeEvent() {
96 HashSet<ChangeListener> copy;
97 synchronized (listeners) {
98 copy = new HashSet<ChangeListener>(listeners);
100 ChangeEvent ev = new ChangeEvent(this);
101 for (ChangeListener listener : copy) {
102 listener.stateChanged(ev);
106 // You can use a settings object to keep track of state. Normally the
107 // settings object will be the WizardDescriptor, so you can use
108 // WizardDescriptor.getProperty & putProperty to store information entered
109 // by the user.
110 public void readSettings(WizardDescriptor descriptor) {
113 public void storeSettings(WizardDescriptor descriptor) {