View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui;
21  
22  import java.awt.Component;
23  
24  import javax.swing.JOptionPane;
25  
26  import org.xnap.XNap;
27  import org.xnap.gui.component.DefaultWizardDialog;
28  import org.xnap.gui.wizard.FilesWizardPanel;
29  import org.xnap.gui.wizard.GeneralWizardPanel;
30  import org.xnap.gui.wizard.IntroWizardPanel;
31  import org.xnap.gui.wizard.LicenseWizardPanel;
32  import org.xnap.gui.wizard.NetworkWizardPanel;
33  import org.xnap.gui.wizard.NoteWizardPanel;
34  import org.xnap.gui.wizard.PluginWizardPanel;
35  import org.xnap.util.Preferences;
36  
37  public class StartupWizardDialog extends DefaultWizardDialog
38  {
39  
40      //--- Constant(s) ---
41  
42      //--- Data field(s) ---
43  
44      boolean startup;
45  
46  	boolean noteRead = false;
47  
48      //--- Constructor(s) ---
49  
50      public StartupWizardDialog(boolean startup)
51      {
52  		this.startup = startup;
53  
54  		setTitle(XNap.tr("XNap Setup Wizard"));
55  		setModal(true);
56  
57  		if (startup) {
58  			addPanel(new IntroWizardPanel(this));
59  			addPanel(new LicenseWizardPanel());
60  			addPanel(new NoteWizardPanel());
61  
62  			getFinishAction().setEnabled(false);
63  			getNextAction().setEnabled(false);
64  		}
65  		else {
66  			noteRead = true;
67  		}
68  
69  		addPanel(new GeneralWizardPanel());
70  		addPanel(new FilesWizardPanel());
71  		addPanel(new NetworkWizardPanel());
72  		addPanel(new PluginWizardPanel());
73      }
74  
75      //--- Method(s) ---
76  
77      public void close()
78      {
79  		if (!isOkay() && startup) {
80  			if (JOptionPane.showConfirmDialog
81  				(this, XNap.tr("This will close XNap. Are you sure?"), 
82  				 XNap.tr("Cancel"),
83  				 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
84  				== JOptionPane.YES_OPTION) {
85  				System.exit(0);
86  			}
87  		}
88  		else {
89  			if (startup) {
90  				Preferences.getInstance().setSeenStartupWizard(true);
91  			}
92  			dispose();
93  		}
94      }
95  
96  	public void setNoteRead(boolean noteRead)
97  	{
98  		this.noteRead = noteRead;
99  		getFinishAction().setEnabled(noteRead);
100 	}
101 
102     public static void showDialog(Component c, boolean startup)
103     {
104 		StartupWizardDialog me = new StartupWizardDialog(startup);
105 		me.show(c);
106     }
107 
108 	protected void panelChanged(SettingsPanel panel)
109 	{
110 		if (panel instanceof IntroWizardPanel) {
111 			((IntroWizardPanel)panel).shown();
112 		}
113 		else if (panel instanceof PluginWizardPanel) {
114 			((PluginWizardPanel)panel).shown();
115 		}
116 	}
117 
118 }