Ver código fonte

New installer UI

tags/0.6.3m1rc1
Gregory Holmes 15 anos atrás
pai
commit
7e09c651ed

+ 33
- 40
src/com/dmdirc/installer/DefaultSettings.java Ver arquivo

@@ -24,49 +24,42 @@ package com.dmdirc.installer;
24 24
 
25 25
 import com.dmdirc.installer.cliparser.CLIParser;
26 26
 
27
+/**
28
+ * Default settings for the installer.
29
+ */
27 30
 public class DefaultSettings implements Settings {
28
-	/**
29
-	 * Returns the state of the shortcutMenu checkbox.
30
-	 *
31
-	 * @return shortcutMenu checkbox state
32
-	 */
33
-	public boolean getShortcutMenuState() {
34
-		return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-menu") == 0);
35
-	}
36 31
 
37
-	/**
38
-	 * Returns the state of the shortcutDesktop checkbox.
39
-	 *
40
-	 * @return shortcutDesktop checkbox state
41
-	 */
42
-	public boolean getShortcutDesktopState() {
43
-		return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-desktop") == 0);
44
-	}
32
+    /** {@inheritDoc} */
33
+    @Override
34
+    public boolean getShortcutMenuState() {
35
+        return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-menu") ==
36
+                0);
37
+    }
38
+
39
+    /** {@inheritDoc} */
40
+    @Override
41
+    public boolean getShortcutDesktopState() {
42
+        return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-desktop") ==
43
+                0);
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the state of the shortcutDesktop checkbox.
48
-	 *
49
-	 * @return shortcutDesktop checkbox state
50
-	 */
51
-	public boolean getShortcutQuickState() {
52
-		return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-quicklaunch") == 0);
53
-	}
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public boolean getShortcutQuickState() {
49
+        return (CLIParser.getCLIParser().getParamNumber(
50
+                "-no-shortcut-quicklaunch") == 0);
51
+    }
54 52
 
55
-	/**
56
-	 * Returns the state of the shortcutProtocol checkbox.
57
-	 *
58
-	 * @return shortcutDesktop checkbox state
59
-	 */
60
-	public boolean getShortcutProtocolState() {
61
-		return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-protocol") == 0);
62
-	}
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public boolean getShortcutProtocolState() {
56
+        return (CLIParser.getCLIParser().getParamNumber("-no-shortcut-protocol") ==
57
+                0);
58
+    }
63 59
 
64
-	/**
65
-	 * Returns the location chosen for installation.
66
-	 *
67
-	 * @return location chosen for installation.
68
-	 */
69
-	public String getInstallLocation() {
70
-		return Main.getInstaller().defaultInstallLocation();
71
-	}
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    public String getInstallLocation() {
63
+        return Main.getInstaller().defaultInstallLocation();
64
+    }
72 65
 }

+ 219
- 212
src/com/dmdirc/installer/Installer.java Ver arquivo

@@ -33,218 +33,225 @@ import java.nio.channels.FileChannel;
33 33
 
34 34
 /**
35 35
  * Installs DMDirc.
36
- *
37
- * @author Shane Mc Cormack
38 36
  */
39 37
 public abstract class Installer extends Thread {
40
-	
41
-	/** Types of shortcut. */
42
-	public static enum ShortcutType {
43
-		/** Desktop shortcut. */
44
-		DESKTOP,
45
-		/** Menu (start/k/etc) shortcut. */
46
-		MENU,
47
-		/** Quick launch shortcut. */
48
-		QUICKLAUNCH,
49
-		/** The actual uninstaller (not a shortcut, as far as I can tell). */
50
-		UNINSTALLER,
51
-		/** Associate DMDirc with the irc:// protocol (not a shortcut). */
52
-		PROTOCOL;
53
-	}
54
-	
55
-	/** Step where the installation output should be. */
56
-	protected TextStep step;
57
-	
58
-	/**
59
-	 * Create a new Installer.
60
-	 */
61
-	public Installer() {
62
-		super("Installer-Thread");
63
-	}
64
-	
65
-	/**
66
-	 * Get the default install location.
67
-	 *
68
-	 * @return The default install location
69
-	 */
70
-	public abstract String defaultInstallLocation();
71
-	
72
-	/**
73
-	 * This is what helps actually perform the installation in run().
74
-	 * This is a hack to keep the installing and the GUI separate.
75
-	 *
76
-	 * @param step The step that called this
77
-	 */
78
-	public final void setInstallStep(final TextStep step) {
79
-		this.step = step;
80
-	}
81
-		
82
-	/**
83
-	 * This performs the installation
84
-	 */
85
-	@Override
86
-	public final void run() {
87
-		step.setText("Beginning Install..\n");
88
-		
89
-		final boolean isUnattended = (CLIParser.getCLIParser().getParamNumber("-unattended") != 0);
90
-		final Settings settings = (isUnattended) ? new DefaultSettings() : ((Settings) Main.getWizardFrame().getStep(1));
91
-		
92
-		final String location = settings.getInstallLocation();
93
-		step.addText("Installing files to: "+location);
94
-		if (!doSetup(location)) {
95
-			step.addText("");
96
-			step.addText("Installation failed\n");
97
-			Main.getWizardFrame().enableNextStep(true);
98
-			return;
99
-		}
100
-
101
-		if (Main.getInstaller().supportsShortcut(ShortcutType.MENU)) {
102
-			if (settings.getShortcutMenuState()) {
103
-				step.addText("Setting up "+Main.getInstaller().getMenuName()+" shortcut");
104
-				setupShortcut(location, ShortcutType.MENU);
105
-			} else {
106
-				step.addText("Not setting up "+Main.getInstaller().getMenuName()+" shortcut");
107
-			}
108
-		}
109
-
110
-		if (Main.getInstaller().supportsShortcut(ShortcutType.DESKTOP)) {
111
-			if (settings.getShortcutDesktopState()) {
112
-				step.addText("Setting up Desktop shortcut");
113
-				setupShortcut(location, ShortcutType.DESKTOP);
114
-			} else {
115
-				step.addText("Not setting up Desktop shortcut");
116
-			}
117
-		}
118
-
119
-		if (Main.getInstaller().supportsShortcut(ShortcutType.QUICKLAUNCH)) {
120
-			if (settings.getShortcutQuickState()) {
121
-				step.addText("Setting up Quick Launch shortcut");
122
-				setupShortcut(location, ShortcutType.QUICKLAUNCH);
123
-			} else {
124
-				step.addText("Not setting up Quick Launch shortcut");
125
-			}
126
-		}
127
-
128
-		if (Main.getInstaller().supportsShortcut(ShortcutType.UNINSTALLER)) {
129
-			step.addText("Creating uninstaller");
130
-			setupShortcut(location, ShortcutType.UNINSTALLER);
131
-		}
132
-
133
-		if (Main.getInstaller().supportsShortcut(ShortcutType.PROTOCOL)) {
134
-			if (settings.getShortcutProtocolState()) {
135
-				step.addText("Setting up irc:// handler");
136
-				setupShortcut(location, ShortcutType.PROTOCOL);
137
-			} else {
138
-				step.addText("Not setting up irc:// handler");
139
-			}
140
-		}
141
-
142
-		postInstall(location);
143
-
144
-		step.addText("");
145
-		step.addText("Installation finished\n");
146
-		Main.getWizardFrame().enableNextStep(true);
147
-	}
148
-	
149
-	/**
150
-	 * Is the given file name vaild to copy to the installation directory?
151
-	 *
152
-	 * @param filename File to check
153
-	 * @return true If the file should be copied, else false.
154
-	 */
155
-	public abstract boolean validFile(final String filename);
156
-	
157
-	/**
158
-	 * Main Setup stuff.
159
-	 *
160
-	 * @param location Location where app will be installed to.
161
-	 * @return True if installation passed, else false
162
-	 */
163
-	public boolean doSetup(final String location) {
164
-		// Create the directory
165
-		final File directory = new File(location);
166
-		if (!directory.exists()) { directory.mkdir(); }
167
-	
168
-		try {
169
-			final File dir = new File(".");
170
-			final FilenameFilter filter = new FilenameFilter() {
171
-				/** {@inheritDoc} */
172
-				@Override
173
-				public boolean accept(final File dir, final String name) {
174
-					return name.charAt(0) != '.' && validFile(name);
175
-				}
176
-			};
177
-			final String[] children = dir.list(filter);
178
-			if (children != null) {
179
-				for (String filename : children) {
180
-					step.addText("Copying " + filename);
181
-					copyFile(filename, location + File.separator + filename);
182
-				}
183
-			}
184
-		} catch (IOException e) {
185
-			step.addText("Error copying files: " + e.getMessage());
186
-			return false;
187
-		}
188
-		step.addText("File Copying Complete.");
189
-		return true;
190
-	}
191
-	
192
-	/**
193
-	 * Check if this OS supports a given shortcut Type.
194
-	 *
195
-	 * @param shortcutType Type of shortcut to check
196
-	 * @return True if this OS supports a given shortcut Type
197
-	 */
198
-	public boolean supportsShortcut(final ShortcutType shortcutType) {
199
-		return false;
200
-	}
201
-	
202
-	/**
203
-	 * Check what name to show for the menu shortcut
204
-	 *
205
-	 * @return Name for menu shortcutType
206
-	 */
207
-	public String getMenuName() {
208
-		return "menu";
209
-	}
210
-	
211
-	/**
212
-	 * Setup shortcut.
213
-	 *
214
-	 * @param location Location where app will be installed to.
215
-	 * @param shortcutType Type of shortcut to add.
216
-	 */
217
-	protected abstract void setupShortcut(final String location, final ShortcutType shortcutType);
218
-	
219
-	/**
220
-	 * Copy a file from one location to another.
221
-	 * Based on http://www.exampledepot.com/egs/java.io/CopyFile.html
222
-	 *
223
-	 * @param srcFile Original file
224
-	 * @param dstFile New file
225
-	 * @throws java.io.IOException If an exception occurs while copying
226
-	 */
227
-	protected final void copyFile(final String srcFile, final String dstFile) throws IOException {
228
-		if (new File(srcFile).exists()) {
229
-			final FileChannel srcChannel = new FileInputStream(srcFile).getChannel();
230
-			final FileChannel dstChannel = new FileOutputStream(dstFile).getChannel();
231
-			
232
-			dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
233
-			
234
-			srcChannel.close();
235
-			dstChannel.close();
236
-		} else {
237
-			throw new IOException(srcFile + " does not exist.");
238
-		}
239
-	}
240
-	
241
-	
242
-	/**
243
-	 * Any post-install tasks should be done here.
244
-	 *
245
-	 * @param location Location where app was installed to.
246
-	 */
247
-	public void postInstall(final String location) {
248
-		// Nothing to do by default, installers may override
249
-	}
38
+
39
+    /** Types of shortcut. */
40
+    public static enum ShortcutType {
41
+
42
+        /** Desktop shortcut. */
43
+        DESKTOP,
44
+        /** Menu (start/k/etc) shortcut. */
45
+        MENU,
46
+        /** Quick launch shortcut. */
47
+        QUICKLAUNCH,
48
+        /** The actual uninstaller (not a shortcut, as far as I can tell). */
49
+        UNINSTALLER,
50
+        /** Associate DMDirc with the irc:// protocol (not a shortcut). */
51
+        PROTOCOL;
52
+    }
53
+
54
+    /** Step where the installation output should be. */
55
+    protected TextStep step;
56
+
57
+    /**
58
+     * Create a new Installer.
59
+     */
60
+    public Installer() {
61
+        super("Installer-Thread");
62
+    }
63
+
64
+    /**
65
+     * Get the default install location.
66
+     *
67
+     * @return The default install location
68
+     */
69
+    public abstract String defaultInstallLocation();
70
+
71
+    /**
72
+     * This is what helps actually perform the installation in run().
73
+     * This is a hack to keep the installing and the GUI separate.
74
+     *
75
+     * @param step The step that called this
76
+     */
77
+    public final void setInstallStep(final TextStep step) {
78
+        this.step = step;
79
+    }
80
+
81
+    /** {@inheritDoc} */
82
+    @Override
83
+    public final void run() {
84
+        step.setText("Beginning Install..\n");
85
+
86
+        final boolean isUnattended = (CLIParser.getCLIParser().getParamNumber(
87
+                "-unattended") != 0);
88
+        final Settings settings = (isUnattended) ? new DefaultSettings() : ((Settings) Main.getWizardFrame().
89
+                getStep(1));
90
+
91
+        final String location = settings.getInstallLocation();
92
+        step.addText("Installing files to: " + location);
93
+        if (!doSetup(location)) {
94
+            step.addText("");
95
+            step.addText("Installation failed\n");
96
+            Main.getWizardFrame().enableNextStep(true);
97
+            return;
98
+        }
99
+
100
+        if (Main.getInstaller().supportsShortcut(ShortcutType.MENU)) {
101
+            if (settings.getShortcutMenuState()) {
102
+                step.addText("Setting up " + Main.getInstaller().getMenuName() +
103
+                             " shortcut");
104
+                setupShortcut(location, ShortcutType.MENU);
105
+            } else {
106
+                step.addText("Not setting up " +
107
+                             Main.getInstaller().getMenuName() + " shortcut");
108
+            }
109
+        }
110
+
111
+        if (Main.getInstaller().supportsShortcut(ShortcutType.DESKTOP)) {
112
+            if (settings.getShortcutDesktopState()) {
113
+                step.addText("Setting up Desktop shortcut");
114
+                setupShortcut(location, ShortcutType.DESKTOP);
115
+            } else {
116
+                step.addText("Not setting up Desktop shortcut");
117
+            }
118
+        }
119
+
120
+        if (Main.getInstaller().supportsShortcut(ShortcutType.QUICKLAUNCH)) {
121
+            if (settings.getShortcutQuickState()) {
122
+                step.addText("Setting up Quick Launch shortcut");
123
+                setupShortcut(location, ShortcutType.QUICKLAUNCH);
124
+            } else {
125
+                step.addText("Not setting up Quick Launch shortcut");
126
+            }
127
+        }
128
+
129
+        if (Main.getInstaller().supportsShortcut(ShortcutType.UNINSTALLER)) {
130
+            step.addText("Creating uninstaller");
131
+            setupShortcut(location, ShortcutType.UNINSTALLER);
132
+        }
133
+
134
+        if (Main.getInstaller().supportsShortcut(ShortcutType.PROTOCOL)) {
135
+            if (settings.getShortcutProtocolState()) {
136
+                step.addText("Setting up irc:// handler");
137
+                setupShortcut(location, ShortcutType.PROTOCOL);
138
+            } else {
139
+                step.addText("Not setting up irc:// handler");
140
+            }
141
+        }
142
+
143
+        postInstall(location);
144
+
145
+        step.addText("");
146
+        step.addText("Installation finished\n");
147
+        Main.getWizardFrame().enableNextStep(true);
148
+    }
149
+
150
+    /**
151
+     * Is the given file name vaild to copy to the installation directory?
152
+     *
153
+     * @param filename File to check
154
+     * @return true If the file should be copied, else false.
155
+     */
156
+    public abstract boolean validFile(final String filename);
157
+
158
+    /**
159
+     * Main Setup stuff.
160
+     *
161
+     * @param location Location where app will be installed to.
162
+     * @return True if installation passed, else false
163
+     */
164
+    public boolean doSetup(final String location) {
165
+        // Create the directory
166
+        final File directory = new File(location);
167
+        if (!directory.exists()) {
168
+            directory.mkdir();
169
+        }
170
+
171
+        try {
172
+            final File dir = new File(".");
173
+            final FilenameFilter filter = new FilenameFilter() {
174
+
175
+                /** {@inheritDoc} */
176
+                @Override
177
+                public boolean accept(final File dir, final String name) {
178
+                    return name.charAt(0) != '.' && validFile(name);
179
+                }
180
+            };
181
+            final String[] children = dir.list(filter);
182
+            if (children != null) {
183
+                for (String filename : children) {
184
+                    step.addText("Copying " + filename);
185
+                    copyFile(filename, location + File.separator + filename);
186
+                }
187
+            }
188
+        } catch (IOException e) {
189
+            step.addText("Error copying files: " + e.getMessage());
190
+            return false;
191
+        }
192
+        step.addText("File Copying Complete.");
193
+        return true;
194
+    }
195
+
196
+    /**
197
+     * Check if this OS supports a given shortcut Type.
198
+     *
199
+     * @param shortcutType Type of shortcut to check
200
+     * @return True if this OS supports a given shortcut Type
201
+     */
202
+    public boolean supportsShortcut(final ShortcutType shortcutType) {
203
+        return false;
204
+    }
205
+
206
+    /**
207
+     * Check what name to show for the menu shortcut
208
+     *
209
+     * @return Name for menu shortcutType
210
+     */
211
+    public String getMenuName() {
212
+        return "menu";
213
+    }
214
+
215
+    /**
216
+     * Setup shortcut.
217
+     *
218
+     * @param location Location where app will be installed to.
219
+     * @param shortcutType Type of shortcut to add.
220
+     */
221
+    protected abstract void setupShortcut(final String location,
222
+                                          final ShortcutType shortcutType);
223
+
224
+    /**
225
+     * Copy a file from one location to another.
226
+     * Based on http://www.exampledepot.com/egs/java.io/CopyFile.html
227
+     *
228
+     * @param srcFile Original file
229
+     * @param dstFile New file
230
+     * @throws java.io.IOException If an exception occurs while copying
231
+     */
232
+    protected final void copyFile(final String srcFile, final String dstFile)
233
+            throws IOException {
234
+        if (new File(srcFile).exists()) {
235
+            final FileChannel srcChannel = new FileInputStream(srcFile).
236
+                    getChannel();
237
+            final FileChannel dstChannel = new FileOutputStream(dstFile).
238
+                    getChannel();
239
+
240
+            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
241
+
242
+            srcChannel.close();
243
+            dstChannel.close();
244
+        } else {
245
+            throw new IOException(srcFile + " does not exist.");
246
+        }
247
+    }
248
+
249
+    /**
250
+     * Any post-install tasks should be done here.
251
+     *
252
+     * @param location Location where app was installed to.
253
+     */
254
+    public void postInstall(final String location) {
255
+        // Nothing to do by default, installers may override
256
+    }
250 257
 }

+ 131
- 0
src/com/dmdirc/installer/InstallerListener.java Ver arquivo

@@ -0,0 +1,131 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer;
25
+
26
+import com.dmdirc.installer.Installer.ShortcutType;
27
+import com.dmdirc.installer.ui.InstallerDialog;
28
+
29
+/**
30
+ * Listeners to all wizard and step changes and responds accordingly.
31
+ */
32
+public class InstallerListener implements WizardListener, StepListener {
33
+
34
+    private Main main;
35
+
36
+    /**
37
+     * Instantiates a new installer listener.
38
+     *
39
+     * @param main Installer entry point
40
+     */
41
+    public InstallerListener(final Main main) {
42
+        this.main = main;
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public void wizardFinished() {
48
+        main.disposeOfInstaller();
49
+        Main.getWizardFrame().dispose();
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public void wizardCancelled() {
55
+        if (!"Install".equals(Main.getWizardFrame().getCurrentStepName()) && Main.getWizardFrame().
56
+                showCancelConfirmation()) {
57
+            Main.getWizardFrame().dispose();
58
+        }
59
+    }
60
+
61
+    /** {@inheritDoc} */
62
+    @Override
63
+    public void stepAboutToDisplay(final Step step) {
64
+        if ("Install".equals(step.getStepName())) {
65
+            installerToBeDisplayed(step);
66
+        } else if ("Confirm".equals(step.getStepName())) {
67
+            confirmToBeDisplayed((TextStep) step);
68
+        }
69
+    }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public void stepHidden(final Step step) {
74
+        //Ignore
75
+    }
76
+
77
+    private void installerToBeDisplayed(final Step step) {
78
+        final InstallerDialog dialog = Main.getWizardFrame();
79
+        dialog.enableNextStep(false);
80
+        dialog.enablePreviousStep(false);
81
+        Main.getInstaller().setInstallStep((TextStep) dialog.getStep("Install"));
82
+        Main.getInstaller().start();
83
+    }
84
+
85
+    private void confirmToBeDisplayed(final TextStep step) {
86
+        String shortcutText = "";
87
+
88
+        final Settings settings = (Settings) Main.getWizardFrame().getStep(1);
89
+
90
+        if (Main.getInstaller().supportsShortcut(ShortcutType.MENU) && settings.
91
+                getShortcutMenuState()) {
92
+            shortcutText = shortcutText + " - Create " + Main.getInstaller().
93
+                    getMenuName() + " shortcut\n";
94
+        }
95
+
96
+        if (Main.getInstaller().supportsShortcut(ShortcutType.DESKTOP) &&
97
+            settings.getShortcutDesktopState()) {
98
+            shortcutText = shortcutText + " - Create desktop shortcut\n";
99
+        }
100
+
101
+        if (Main.getInstaller().supportsShortcut(ShortcutType.QUICKLAUNCH) &&
102
+            settings.getShortcutQuickState()) {
103
+            shortcutText = shortcutText + " - Create Quick Launch shortcut\n";
104
+        }
105
+
106
+        if (Main.getInstaller().supportsShortcut(ShortcutType.PROTOCOL) &&
107
+            settings.getShortcutProtocolState()) {
108
+            shortcutText = shortcutText +
109
+                           " - Make DMDirc handle irc:// links\n";
110
+        }
111
+
112
+
113
+        final String installLocation = settings.getInstallLocation();
114
+
115
+
116
+        if (installLocation.isEmpty()) {
117
+            step.setText(
118
+                    "You have chosen an invalid install location\n\n" +
119
+                    "Please press the \"Previous\" button to go back and correct it.");
120
+            Main.getWizardFrame().enableNextStep(false);
121
+        } else {
122
+            step.setText(
123
+                    "Please review your chosen settings:\n\n" +
124
+                    " - Install Location:\n" + "    " + installLocation +
125
+                    "\n" + shortcutText + "\n" +
126
+                    "If you wish to change any of these settings, press the \"Previous\" button," +
127
+                    "otherwise click \"Next\" to begin the installation");
128
+            Main.getWizardFrame().enableNextStep(true);
129
+        }
130
+    }
131
+}

+ 6
- 23
src/com/dmdirc/installer/LinuxInstaller.java Ver arquivo

@@ -41,12 +41,7 @@ public class LinuxInstaller extends Installer {
41 41
 		return (CLIParser.getCLIParser().getParamNumber("-isroot") > 0);
42 42
 	}
43 43
 	
44
-	/**
45
-	 * Is the given file name vaild to copy to the installation directory?
46
-	 *
47
-	 * @param filename File to check
48
-	 * @return true If the file should be copied, else false.
49
-	 */
44
+	/** {@inheritDoc} */
50 45
 	@Override
51 46
 	public boolean validFile(final String filename) {
52 47
 		return (!filename.equalsIgnoreCase("setup.sh") &&
@@ -74,12 +69,7 @@ public class LinuxInstaller extends Installer {
74 69
 		return result;
75 70
 	}
76 71
 
77
-	/**
78
-	 * Check if this OS supports a given shortcut Type
79
-	 *
80
-	 * @param shortcutType Type of shortcut to check
81
-	 * @return True if this OS supports a given shortcut Type
82
-	 */
72
+	/** {@inheritDoc} */
83 73
 	@Override
84 74
 	public boolean supportsShortcut(final ShortcutType shortcutType) {
85 75
 		switch (shortcutType) {
@@ -100,12 +90,8 @@ public class LinuxInstaller extends Installer {
100 90
 		}
101 91
 	}
102 92
 
103
-	/**
104
-	 * Setup shortcut.
105
-	 *
106
-	 * @param location Location where app will be installed to.
107
-	 * @param shortcutType Type of shortcut to add.
108
-	 */
93
+	/** {@inheritDoc} */
94
+	@Override
109 95
 	public void setupShortcut(final String location, final ShortcutType shortcutType) {
110 96
 		if (!supportsShortcut(shortcutType)) {
111 97
 			step.addText(" - Error creating shortcut. Not applicable to this Operating System");
@@ -397,11 +383,8 @@ public class LinuxInstaller extends Installer {
397 383
 		writer.println("Type=Application");
398 384
 	}
399 385
 
400
-	/**
401
-	 * Any post-install tasks should be done here.
402
-	 *
403
-	 * @param location Location where app was installed to.
404
-	 */
386
+	/** {@inheritDoc} */
387
+	@Override
405 388
 	public void postInstall(final String location) {
406 389
 		new File(location+"/DMDirc.sh").setExecutable(true, !isRoot());
407 390
 	}

+ 140
- 157
src/com/dmdirc/installer/Main.java Ver arquivo

@@ -25,165 +25,148 @@ package com.dmdirc.installer;
25 25
 import com.dmdirc.installer.cliparser.BooleanParam;
26 26
 import com.dmdirc.installer.cliparser.CLIParser;
27 27
 import com.dmdirc.installer.cliparser.StringParam;
28
-import com.dmdirc.ui.IconManager;
29
-import com.dmdirc.addons.ui_swing.UIUtilities;
30
-import com.dmdirc.addons.ui_swing.dialogs.wizard.Step;
31
-import com.dmdirc.addons.ui_swing.dialogs.wizard.WizardFrame;
32
-import com.dmdirc.addons.ui_swing.dialogs.wizard.WizardListener;
33 28
 
34
-import com.dmdirc.addons.ui_swing.installer.StepWelcome;
35
-import com.dmdirc.addons.ui_swing.installer.StepError;
36
-import com.dmdirc.addons.ui_swing.installer.StepSettings;
37
-import com.dmdirc.addons.ui_swing.installer.StepConfirm;
38
-import com.dmdirc.addons.ui_swing.installer.StepInstall;
39
-
40
-import java.awt.Dimension;
41
-import java.util.ArrayList;
42
-
43
-import javax.swing.JOptionPane;
29
+import com.dmdirc.installer.ui.InstallerDialog;
30
+import com.dmdirc.installer.ui.StepWelcome;
31
+import com.dmdirc.installer.ui.StepError;
32
+import com.dmdirc.installer.ui.StepSettings;
33
+import com.dmdirc.installer.ui.StepConfirm;
34
+import com.dmdirc.installer.ui.StepInstall;
44 35
 
45 36
 /**
46
- * Main installer window.
47
- *
48
- * @author Shane Mc Cormack
37
+ * Main installer entry point.
49 38
  */
50
-public final class Main implements WizardListener {
51
-	
52
-	/** Wizard dialog. */
53
-	private static WizardFrame wizardDialog;
54
-	
55
-	/** Installer. */
56
-	private static Installer myInstaller;
57
-	
58
-	/** CLI Parser. */
59
-	private static CLIParser cli = CLIParser.getCLIParser();
60
-	
61
-	/**
62
-	 * Creates and Displays the Installer wizard.
63
-	 */
64
-	private Main() {
65
-		try {
66
-			UIUtilities.initUISettings();
67
-		} catch (UnsupportedOperationException ex) {
68
-			//Ignore, revert to default
69
-		}
70
-		
71
-		String releaseName = "DMDirc";
72
-		if (cli.getParamNumber("-release") > 0) {
73
-			releaseName = releaseName + " " + cli.getParam("-release").getStringValue();
74
-		}
75
-		
76
-		setWizardFrame(new WizardFrame(releaseName + " Installer", new ArrayList<Step>(), this));
77
-		wizardDialog.setIconImage(IconManager.getIconManager().getImage("icon"));
78
-		wizardDialog.setPreferredSize(new Dimension(400, 350));
79
-		wizardDialog.setMaximumSize(new Dimension(400, 350));
80
-		wizardDialog.addWizardListener(this);
81
-
82
-		final String osName = System.getProperty("os.name");
83
-		wizardDialog.addStep(new StepWelcome(releaseName));
84
-		if (osName.startsWith("Mac OS")) {
85
-			wizardDialog.addStep(new StepError("Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
86
-		} else {
87
-			if (CLIParser.getCLIParser().getParamNumber("-unattended") == 0) {
88
-				wizardDialog.addStep(new StepSettings());
89
-				wizardDialog.addStep(new StepConfirm(wizardDialog));
90
-			}
91
-			wizardDialog.addStep(new StepInstall(wizardDialog));
92
-		}
93
-	}
94
-		
95
-	/**
96
-	 * Called when the wizard finishes.
97
-	 */
98
-	@Override
99
-	public void wizardFinished() {
100
-		final Thread temp = myInstaller;
101
-		myInstaller = null;
102
-		if (temp != null) { temp.interrupt(); }
103
-		wizardDialog.dispose();
104
-	}
105
-	
106
-	/**
107
-	 * Called when the wizard is cancelled.
108
-	 */
109
-	@Override
110
-	public void wizardCancelled() {	
111
-		if (wizardDialog.getCurrentStep() != 3 && JOptionPane.showConfirmDialog(wizardDialog, "Are you sure you want to cancel?", "Cancel confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
112
-			wizardDialog.dispose();
113
-		}
114
-	}
115
-	
116
-	/**
117
-	 * Get the Installer object for this OS.
118
-	 *
119
-	 * @return The installer for this OS
120
-	 */
121
-	public static synchronized Installer getInstaller() {
122
-		if (myInstaller == null) {
123
-			final String osName = System.getProperty("os.name");
124
-			if (osName.startsWith("Mac OS")) {
125
-				// myInstaller = new MacInstaller();
126
-			} else if (osName.startsWith("Windows")) {
127
-				myInstaller = new WindowsInstaller();
128
-			} else {
129
-				myInstaller = new LinuxInstaller();
130
-			}
131
-		}
132
-		
133
-		return myInstaller;
134
-	}
135
-
136
-	/**
137
-	 * Setup the cli parser.
138
-	 * This clears the current CLIParser params and creates new ones.
139
-	 */
140
-	private static void setupCLIParser() {
141
-		cli.clear();
142
-		cli.add(new StringParam('h', "help", "Get Help"));
143
-		cli.setHelp(cli.getParam("-help"));
144
-		cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
145
-		cli.add(new StringParam('r', "release", "Release Name"));
146
-		cli.add(new StringParam('d', "directory", "Default install directory"));
147
-		cli.add(new BooleanParam('u', "unattended", "Perform an unattended installation"));
148
-		cli.add(new BooleanParam((char) 0, "no-shortcut-desktop", "Don't offer a desktop shortcut as the default"));
149
-		cli.add(new BooleanParam((char) 0, "no-shortcut-menu", "Don't offer a menu shortcut as the default"));
150
-		cli.add(new BooleanParam((char) 0, "no-shortcut-quicklaunch", "Don't offer a quick launch shortcut as the default"));
151
-		cli.add(new BooleanParam((char) 0, "no-shortcut-protocol", "Don't offer to handle irc:// links as the default"));
152
-	}
153
-	
154
-	/**
155
-	 * Get the WizardFrame.
156
-	 *
157
-	 * @return The current wizardDialog
158
-	 */
159
-	public static synchronized WizardFrame getWizardFrame() {
160
-		if (wizardDialog == null) {
161
-			new Main();
162
-		}
163
-		return wizardDialog;
164
-	}
165
-	
166
-	/**
167
-	 * Set the WizardFrame.
168
-	 *
169
-	 * @param dialog The new WizardDialog
170
-	 */
171
-	private static void setWizardFrame(final WizardFrame dialog) {
172
-		wizardDialog = dialog;
173
-	}
174
-
175
-	/**
176
-	 * Run the installer.
177
-	 *
178
-	 * @param args Command line arguments
179
-	 */
180
-	public static void main(final String[] args) {
181
-		setupCLIParser();
182
-		if (cli.wantsHelp(args)) {
183
-			cli.showHelp("DMDirc installer Help", "[options [--]]");
184
-			System.exit(0);
185
-		}
186
-		cli.parseArgs(args, false);
187
-		getWizardFrame().display();
188
-	}
39
+public final class Main {
40
+
41
+    /** Wizard dialog. */
42
+    private static InstallerDialog wizardDialog;
43
+    /** Installer. */
44
+    private static Installer myInstaller;
45
+    /** CLI Parser. */
46
+    private static CLIParser cli = CLIParser.getCLIParser();
47
+
48
+    /**
49
+     * Creates and Displays the Installer wizard.
50
+     */
51
+    private Main() {
52
+        try {
53
+            InstallerDialog.initUISettings();
54
+        } catch (UnsupportedOperationException ex) {
55
+            //Ignore, revert to default
56
+        }
57
+
58
+        String releaseName = "DMDirc";
59
+        if (cli.getParamNumber("-release") > 0) {
60
+            releaseName = releaseName + " " + cli.getParam("-release").
61
+                    getStringValue();
62
+        }
63
+
64
+        setWizardFrame(new InstallerDialog(releaseName + " Installer"));
65
+        getWizardFrame().addWizardListener(new InstallerListener(this));
66
+        getWizardFrame().addStepListener(new InstallerListener(this));
67
+
68
+        final String osName = System.getProperty("os.name");
69
+        wizardDialog.addStep(new StepWelcome(releaseName));
70
+        if (osName.startsWith("Mac OS")) {
71
+            wizardDialog.addStep(
72
+                    new StepError(
73
+                    "Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
74
+        } else {
75
+            if (CLIParser.getCLIParser().getParamNumber("-unattended") == 0) {
76
+                wizardDialog.addStep(new StepSettings());
77
+                wizardDialog.addStep(new StepConfirm());
78
+            }
79
+            wizardDialog.addStep(new StepInstall());
80
+        }
81
+    }
82
+
83
+    /**
84
+     * Disposes of the current installer.
85
+     */
86
+    public void disposeOfInstaller() {
87
+        final Thread temp = myInstaller;
88
+        myInstaller = null;
89
+        if (temp != null) {
90
+            temp.interrupt();
91
+        }
92
+    }
93
+
94
+    /**
95
+     * Get the Installer object for this OS.
96
+     *
97
+     * @return The installer for this OS
98
+     */
99
+    public static synchronized Installer getInstaller() {
100
+        if (myInstaller == null) {
101
+            final String osName = System.getProperty("os.name");
102
+            if (osName.startsWith("Mac OS")) {
103
+                // myInstaller = new MacInstaller();
104
+            } else if (osName.startsWith("Windows")) {
105
+                myInstaller = new WindowsInstaller();
106
+            } else {
107
+                myInstaller = new LinuxInstaller();
108
+            }
109
+        }
110
+
111
+        return myInstaller;
112
+    }
113
+
114
+    /**
115
+     * Setup the cli parser.
116
+     * This clears the current CLIParser params and creates new ones.
117
+     */
118
+    private static void setupCLIParser() {
119
+        cli.clear();
120
+        cli.add(new StringParam('h', "help", "Get Help"));
121
+        cli.setHelp(cli.getParam("-help"));
122
+        cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
123
+        cli.add(new StringParam('r', "release", "Release Name"));
124
+        cli.add(new StringParam('d', "directory", "Default install directory"));
125
+        cli.add(new BooleanParam('u', "unattended",
126
+                                 "Perform an unattended installation"));
127
+        cli.add(new BooleanParam((char) 0, "no-shortcut-desktop",
128
+                                 "Don't offer a desktop shortcut as the default"));
129
+        cli.add(new BooleanParam((char) 0, "no-shortcut-menu",
130
+                                 "Don't offer a menu shortcut as the default"));
131
+        cli.add(new BooleanParam((char) 0, "no-shortcut-quicklaunch",
132
+                                 "Don't offer a quick launch shortcut as the default"));
133
+        cli.add(new BooleanParam((char) 0, "no-shortcut-protocol",
134
+                                 "Don't offer to handle irc:// links as the default"));
135
+    }
136
+
137
+    /**
138
+     * Get the WizardFrame.
139
+     *
140
+     * @return The current wizardDialog
141
+     */
142
+    public static synchronized InstallerDialog getWizardFrame() {
143
+        if (wizardDialog == null) {
144
+            new Main();
145
+        }
146
+        return wizardDialog;
147
+    }
148
+
149
+    /**
150
+     * Set the WizardFrame.
151
+     *
152
+     * @param dialog The new WizardDialog
153
+     */
154
+    private static void setWizardFrame(final InstallerDialog dialog) {
155
+        wizardDialog = dialog;
156
+    }
157
+
158
+    /**
159
+     * Run the installer.
160
+     *
161
+     * @param args Command line arguments
162
+     */
163
+    public static void main(final String[] args) {
164
+        setupCLIParser();
165
+        if (cli.wantsHelp(args)) {
166
+            cli.showHelp("DMDirc installer Help", "[options [--]]");
167
+            System.exit(0);
168
+        }
169
+        cli.parseArgs(args, false);
170
+        getWizardFrame().display();
171
+    }
189 172
 }

+ 34
- 30
src/com/dmdirc/installer/Settings.java Ver arquivo

@@ -22,39 +22,43 @@
22 22
 
23 23
 package com.dmdirc.installer;
24 24
 
25
+/**
26
+ * Simple interface describing available settings for the installer.
27
+ */
25 28
 public interface Settings {
26
-	/**
27
-	 * Returns the state of the shortcutMenu checkbox.
28
-	 *
29
-	 * @return shortcutMenu checkbox state
30
-	 */
31
-	public boolean getShortcutMenuState();
32 29
 
33
-	/**
34
-	 * Returns the state of the shortcutDesktop checkbox.
35
-	 *
36
-	 * @return shortcutDesktop checkbox state
37
-	 */
38
-	public boolean getShortcutDesktopState();
30
+    /**
31
+     * Returns the state of the shortcutMenu checkbox.
32
+     *
33
+     * @return shortcutMenu checkbox state
34
+     */
35
+    public boolean getShortcutMenuState();
36
+
37
+    /**
38
+     * Returns the state of the shortcutDesktop checkbox.
39
+     *
40
+     * @return shortcutDesktop checkbox state
41
+     */
42
+    public boolean getShortcutDesktopState();
39 43
 
40
-	/**
41
-	 * Returns the state of the shortcutDesktop checkbox.
42
-	 *
43
-	 * @return shortcutDesktop checkbox state
44
-	 */
45
-	public boolean getShortcutQuickState();
44
+    /**
45
+     * Returns the state of the shortcutDesktop checkbox.
46
+     *
47
+     * @return shortcutDesktop checkbox state
48
+     */
49
+    public boolean getShortcutQuickState();
46 50
 
47
-	/**
48
-	 * Returns the state of the shortcutProtocol checkbox.
49
-	 *
50
-	 * @return shortcutDesktop checkbox state
51
-	 */
52
-	public boolean getShortcutProtocolState();
51
+    /**
52
+     * Returns the state of the shortcutProtocol checkbox.
53
+     *
54
+     * @return shortcutDesktop checkbox state
55
+     */
56
+    public boolean getShortcutProtocolState();
53 57
 
54
-	/**
55
-	 * Returns the location chosen for installation.
56
-	 *
57
-	 * @return location chosen for installation.
58
-	 */
59
-	public String getInstallLocation();
58
+    /**
59
+     * Returns the location chosen for installation.
60
+     *
61
+     * @return location chosen for installation.
62
+     */
63
+    public String getInstallLocation();
60 64
 }

+ 37
- 0
src/com/dmdirc/installer/Step.java Ver arquivo

@@ -0,0 +1,37 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer;
25
+
26
+/**
27
+ * Simple step interface.
28
+ */
29
+public interface Step {
30
+
31
+    /**
32
+     * Returns the name of this step.
33
+     * 
34
+     * @return Step name
35
+     */
36
+    public abstract String getStepName();
37
+}

+ 44
- 0
src/com/dmdirc/installer/StepListener.java Ver arquivo

@@ -0,0 +1,44 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer;
25
+
26
+/**
27
+ * Step listeners, listens for changes regarding steps.
28
+ */
29
+public interface StepListener {
30
+
31
+    /**
32
+     * Called when a step is about to be displayed.
33
+     * 
34
+     * @param step Step to be displayed
35
+     */
36
+    void stepAboutToDisplay(final Step step);
37
+
38
+    /**
39
+     * Called when a step is hidden.
40
+     * 
41
+     * @param step
42
+     */
43
+    void stepHidden(final Step step);
44
+}

+ 85
- 81
src/com/dmdirc/installer/StreamReader.java Ver arquivo

@@ -27,87 +27,91 @@ import java.io.IOException;
27 27
 import java.io.InputStream;
28 28
 import java.io.InputStreamReader;
29 29
 
30
+/**
31
+ * Simple stream reader to read a stream and add it to a text step
32
+ */
30 33
 public class StreamReader extends Thread {
31
-	
32
-	/** This is the Input Stream we are reading */
33
-	private final InputStream stream;
34
-	
35
-	/** This is the output Prefix */
36
-	private String prefix = null;
37
-	
38
-	/** This is the StringBuffer to store data in if wanted */
39
-	private StringBuffer data = null;
40
-	
41
-	/** This is the Step we are outputting to, */
42
-	private TextStep step = null;
43
-	
44
-	/**
45
-	 * Create a new Stream Reader
46
-	 *
47
-	 * @param stream The stream to read
48
-	 */
49
-	public StreamReader(final InputStream stream) {
50
-		this.stream = stream;
51
-	}
52
-	
53
-	/**
54
-	 * Create a new Stream Reader that saves what it reads
55
-	 *
56
-	 * @param stream The stream to read
57
-	 * @param data The stringbuffer to store the output in
58
-	 * @since 0.6
59
-	 */
60
-	public StreamReader(final InputStream stream, final StringBuffer data) {
61
-		this.stream = stream;
62
-		this.data = data;
63
-	}
64
-	
65
-	/**
66
-	 * Create a new Stream Reader that outputs what it reads
67
-	 *
68
-	 * @param stream The stream to read
69
-	 * @param prefix Prefix of outputed messages
70
-	 * @param step Step to output to (null = console)
71
-	 */
72
-	public StreamReader(final InputStream stream, final String prefix, final TextStep step) {
73
-		this.stream = stream;
74
-		this.prefix = prefix;
75
-		this.step = step;
76
-		
77
-		if (step == null) {
78
-			System.out.printf("[%s] Started%n", prefix);
79
-		} else {
80
-			step.addText(String.format(" - -[%s] Started", prefix));
81
-		}
82
-	}
83 34
 
84
-	/** {@inheritDoc} */
85
-	@Override
86
-	public void run() {
87
-		final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
88
-		try {
89
-			String line;
90
-			while ((line = reader.readLine()) != null) {
91
-				if (data != null) {
92
-					if (data.length() > 0) { data.append("\n"); }
93
-					data.append(line);
94
-				}
95
-				if (prefix != null) {
96
-					if (step == null) {
97
-						System.out.printf("[%s] %s%n", prefix, line);
98
-					} else {
99
-						step.addText(String.format(" - -[%s] %s", prefix, line));
100
-					}
101
-				}
102
-			}
103
-		} catch (IOException e) {
104
-			e.printStackTrace();
105
-		} finally {
106
-			try {
107
-				stream.close();
108
-			} catch (IOException e) {
109
-				e.printStackTrace();
110
-			}
111
-		}
112
-	}
35
+    /** This is the Input Stream we are reading */
36
+    private final InputStream stream;
37
+    /** This is the output Prefix */
38
+    private String prefix = null;
39
+    /** This is the StringBuffer to store data in if wanted */
40
+    private StringBuffer data = null;
41
+    /** This is the Step we are outputting to, */
42
+    private TextStep step = null;
43
+
44
+    /**
45
+     * Create a new Stream Reader
46
+     *
47
+     * @param stream The stream to read
48
+     */
49
+    public StreamReader(final InputStream stream) {
50
+        this.stream = stream;
51
+    }
52
+
53
+    /**
54
+     * Create a new Stream Reader that saves what it reads
55
+     *
56
+     * @param stream The stream to read
57
+     * @param data The stringbuffer to store the output in
58
+     * @since 0.6
59
+     */
60
+    public StreamReader(final InputStream stream, final StringBuffer data) {
61
+        this.stream = stream;
62
+        this.data = data;
63
+    }
64
+
65
+    /**
66
+     * Create a new Stream Reader that outputs what it reads
67
+     *
68
+     * @param stream The stream to read
69
+     * @param prefix Prefix of outputed messages
70
+     * @param step Step to output to (null = console)
71
+     */
72
+    public StreamReader(final InputStream stream, final String prefix,
73
+                        final TextStep step) {
74
+        this.stream = stream;
75
+        this.prefix = prefix;
76
+        this.step = step;
77
+
78
+        if (step == null) {
79
+            System.out.printf("[%s] Started%n", prefix);
80
+        } else {
81
+            step.addText(String.format(" - -[%s] Started", prefix));
82
+        }
83
+    }
84
+
85
+    /** {@inheritDoc} */
86
+    @Override
87
+    public void run() {
88
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(
89
+                stream));
90
+        try {
91
+            String line;
92
+            while ((line = reader.readLine()) != null) {
93
+                if (data != null) {
94
+                    if (data.length() > 0) {
95
+                        data.append("\n");
96
+                    }
97
+                    data.append(line);
98
+                }
99
+                if (prefix != null) {
100
+                    if (step == null) {
101
+                        System.out.printf("[%s] %s%n", prefix, line);
102
+                    } else {
103
+                        step.addText(String.format(" - -[%s] %s", prefix, line));
104
+                    }
105
+                }
106
+            }
107
+        } catch (IOException e) {
108
+            e.printStackTrace();
109
+        } finally {
110
+            try {
111
+                stream.close();
112
+            } catch (IOException e) {
113
+                e.printStackTrace();
114
+            }
115
+        }
116
+    }
113 117
 }

+ 3
- 0
src/com/dmdirc/installer/TextStep.java Ver arquivo

@@ -22,6 +22,9 @@
22 22
 
23 23
 package com.dmdirc.installer;
24 24
 
25
+/**
26
+ * Quick access methods for a step to have a controllable text field.
27
+ */
25 28
 public interface TextStep {
26 29
 	/**
27 30
 	 * Add text to the infolabel on this step

+ 275
- 259
src/com/dmdirc/installer/WindowsInstaller.java Ver arquivo

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.installer;
24 24
 
25 25
 import com.dmdirc.installer.cliparser.CLIParser;
26
+
26 27
 import java.io.File;
27 28
 import java.io.IOException;
28 29
 import java.util.ArrayList;
@@ -33,283 +34,298 @@ import java.util.ArrayList;
33 34
  * @author Shane Mc Cormack
34 35
  */
35 36
 public class WindowsInstaller extends Installer {
36
-	/**
37
-	 * Get the default install location
38
-	 */
39
-	public String defaultInstallLocation() {
40
-		String result = "";
41
-		if (CLIParser.getCLIParser().getParamNumber("-directory") > 0) {
42
-			result = CLIParser.getCLIParser().getParam("-directory").getStringValue();
43
-		}
44
-		if (result.isEmpty()) {
45
-			String filename = System.getenv("PROGRAMFILES");
46
-			if (filename == null) {
47
-				if (isVista()) {
48
-					filename = System.getProperty("user.home")+"\\Desktop\\DMDirc";
49
-				} else {
50
-					filename = "C:\\Program Files";
51
-				}
52
-			}
53
-			result = filename+"\\DMDirc";
54
-		}
55
-		return result;
56
-	}
57
-	
58
-	/**
59
-	 * Is the given file name vaild to copy to the installation directory?
60
-	 *
61
-	 * @param filename File to check
62
-	 * @return true If the file should be copied, else false.
63
-	 */
64
-	public boolean validFile(final String filename) {
65
-		return (!filename.equalsIgnoreCase("setup.exe") &&
66
-		        !filename.equalsIgnoreCase("jre.exe") &&
67
-		        !filename.equalsIgnoreCase("wget.exe") &&
68
-		        !filename.equalsIgnoreCase("wgetoutput") &&
69
-		        !filename.equalsIgnoreCase("shortcut.exe"));
70
-	}
71 37
 
72
-	/**
73
-	 * Are we running vista? -_-
74
-	 *
75
-	 * @return True if this is vista.
76
-	 */
77
-	public boolean isVista() {
78
-		return System.getProperty("os.name").indexOf("Vista") >= 0;
79
-	}
38
+    /** {@inheritDoc} */
39
+    @Override
40
+    public String defaultInstallLocation() {
41
+        String result = "";
42
+        if (CLIParser.getCLIParser().getParamNumber("-directory") > 0) {
43
+            result = CLIParser.getCLIParser().getParam("-directory").
44
+                    getStringValue();
45
+        }
46
+        if (result.isEmpty()) {
47
+            String filename = System.getenv("PROGRAMFILES");
48
+            if (filename == null) {
49
+                if (isVista()) {
50
+                    filename = System.getProperty("user.home") +
51
+                               "\\Desktop\\DMDirc";
52
+                } else {
53
+                    filename = "C:\\Program Files";
54
+                }
55
+            }
56
+            result = filename + "\\DMDirc";
57
+        }
58
+        return result;
59
+    }
60
+
61
+    /** {@inheritDoc} */
62
+    @Override
63
+    public boolean validFile(final String filename) {
64
+        return (!filename.equalsIgnoreCase("setup.exe") &&
65
+                !filename.equalsIgnoreCase("jre.exe") &&
66
+                !filename.equalsIgnoreCase("wget.exe") &&
67
+                !filename.equalsIgnoreCase("wgetoutput") &&
68
+                !filename.equalsIgnoreCase("shortcut.exe"));
69
+    }
70
+
71
+    /**
72
+     * Are we running vista? -_-
73
+     *
74
+     * @return True if this is vista.
75
+     */
76
+    public boolean isVista() {
77
+        return System.getProperty("os.name").indexOf("Vista") >= 0;
78
+    }
79
+
80
+    /**
81
+     * Are we running NT?
82
+     *
83
+     * @return True if this is NT.
84
+     */
85
+    public boolean isNT() {
86
+        final String osName = System.getProperty("os.name");
87
+        return (osName.indexOf("NT") >= 0 || osName.indexOf("2000") >= 0 ||
88
+                osName.indexOf("2003") >= 0 || osName.indexOf("XP") >= 0);
89
+    }
90
+
91
+    /** {@inheritDoc} */
92
+    @Override
93
+    public boolean supportsShortcut(final ShortcutType shortcutType) {
94
+        switch (shortcutType) {
95
+            case QUICKLAUNCH:
96
+                // Only windows 95 doesn't have quick launch
97
+                return !(System.getProperty("os.name").indexOf("95") >= 0);
98
+            case DESKTOP:
99
+            case MENU:
100
+            case UNINSTALLER:
101
+            case PROTOCOL:
102
+                // All versions of windows have desktop, menu, uninstaller and protocol
103
+                return true;
104
+            default:
105
+                // Anything else that gets added should be false until the relevent
106
+                // code is added
107
+                return false;
108
+        }
109
+    }
110
+
111
+    /** {@inheritDoc} */
112
+    @Override
113
+    public String getMenuName() {
114
+        return "Start menu";
115
+    }
116
+
117
+    /**
118
+     * Add a registry key.
119
+     *
120
+     * @param key Key to add.
121
+     */
122
+    public void addRegistryKey(final String key) {
123
+        step.addText(" - Adding Key: " + key);
124
+        final String[] addKey = new String[]{"reg.exe", "add", key, "/f"};
125
+        execAndWait(addKey);
126
+    }
80 127
 
81
-	/**
82
-	 * Are we running NT?
83
-	 *
84
-	 * @return True if this is NT.
85
-	 */
86
-	public boolean isNT() {
87
-		final String osName = System.getProperty("os.name");
88
-		return (osName.indexOf("NT") >= 0  || osName.indexOf("2000") >= 0 || osName.indexOf("2003") >= 0 || osName.indexOf("XP") >= 0);
89
-	}
128
+    /**
129
+     * Modify a registry value.
130
+     *
131
+     * @param key Key to use.
132
+     * @param value Value to modify.
133
+     * @param data Data for key.
134
+     */
135
+    public void editRegistryValue(final String key, final String value,
136
+                                  final String data) {
137
+        editRegistryValue(key, value, "REG_SZ", data);
138
+    }
90 139
 
91
-	/**
92
-	 * Check if this OS supports a given shortcut Type
93
-	 *
94
-	 * @param shortcutType Type of shortcut to check
95
-	 * @return True if this OS supports a given shortcut Type
96
-	 */
97
-	public boolean supportsShortcut(final ShortcutType shortcutType) {
98
-		switch (shortcutType) {
99
-			case QUICKLAUNCH:
100
-				// Only windows 95 doesn't have quick launch
101
-				return !(System.getProperty("os.name").indexOf("95") >= 0);
102
-			case DESKTOP:
103
-			case MENU:
104
-			case UNINSTALLER:
105
-			case PROTOCOL:
106
-				// All versions of windows have desktop, menu, uninstaller and protocol
107
-				return true;
108
-			default:
109
-				// Anything else that gets added should be false until the relevent
110
-				// code is added
111
-				return false;
112
-		}
113
-	}
114
-	
115
-	/**
116
-	 * Check what name to show for the menu shortcut
117
-	 *
118
-	 * @return Name for menu shortcutType
119
-	 */
120
-	public String getMenuName() {
121
-		return "Start menu";
122
-	}
140
+    /**
141
+     * Modify a registry value.
142
+     *
143
+     * @param key Key to use.
144
+     * @param value Value to modify.
145
+     * @param type Type of data.
146
+     * @param data Data for key.
147
+     */
148
+    public void editRegistryValue(final String key, final String value,
149
+                                  final String type, final String data) {
150
+        final ArrayList<String> params = new ArrayList<String>();
151
+        step.addText(" - Editing value: " + key + "\\" + value);
152
+        params.add("reg.exe");
153
+        params.add("add");
154
+        params.add(key);
155
+        params.add("/f");
156
+        if (value.isEmpty()) {
157
+            params.add("/ve");
158
+        } else {
159
+            params.add("/v");
160
+            params.add(value);
161
+        }
162
+        params.add("/t");
163
+        params.add(type);
164
+        if (!data.isEmpty()) {
165
+            params.add("/d");
166
+            params.add(data);
167
+        }
123 168
 
124
-	/**
125
-	 * Add a registry key.
126
-	 *
127
-	 * @param key Key to add.
128
-	 */
129
-	public void addRegistryKey(final String key) {
130
-		step.addText(" - Adding Key: "+key);
131
-		final String[] addKey = new String[] {"reg.exe", "add", key, "/f"};
132
-		execAndWait(addKey);
133
-	}
169
+        execAndWait(params.toArray(new String[params.size()]));
170
+    }
134 171
 
135
-	/**
136
-	 * Modify a registry value.
137
-	 *
138
-	 * @param key Key to use.
139
-	 * @param value Value to modify.
140
-	 * @param data Data for key.
141
-	 */
142
-	public void editRegistryValue(final String key, final String value, final String data) {
143
-		editRegistryValue(key, value, "REG_SZ", data);
144
-	}
172
+    /**
173
+     * Execute and wait for the requested command
174
+     *
175
+     * @param cmd Command array to execute/
176
+     * @return return value from command, or -1 if there was an error.
177
+     */
178
+    private int execAndWait(final String cmd[]) {
179
+        try {
180
+            final Process myProcess = Runtime.getRuntime().exec(cmd);
181
+            new StreamReader(myProcess.getInputStream()).start();
182
+            new StreamReader(myProcess.getErrorStream()).start();
183
+            try {
184
+                myProcess.waitFor();
185
+            } catch (InterruptedException e) {
186
+            }
187
+            if (myProcess.exitValue() != 0) {
188
+                step.addText("\t - Error: Unknown Reason");
189
+            }
190
+            return myProcess.exitValue();
191
+        } catch (SecurityException e) {
192
+            step.addText("\t - Error: " + e.getMessage());
193
+        } catch (IOException e) {
194
+            step.addText("\t - Error: " + e.getMessage());
195
+        }
145 196
 
146
-	/**
147
-	 * Modify a registry value.
148
-	 *
149
-	 * @param key Key to use.
150
-	 * @param value Value to modify.
151
-	 * @param type Type of data.
152
-	 * @param data Data for key.
153
-	 */
154
-	public void editRegistryValue(final String key, final String value, final String type, final String data) {
155
-		final ArrayList<String> params = new ArrayList<String>();
156
-		step.addText(" - Editing value: "+key+"\\"+value);
157
-		params.add("reg.exe");
158
-		params.add("add");
159
-		params.add(key);
160
-		params.add("/f");
161
-		if (value.isEmpty()) {
162
-			params.add("/ve");
163
-		} else {
164
-			params.add("/v");
165
-			params.add(value);
166
-		}
167
-		params.add("/t");
168
-		params.add(type);
169
-		if (!data.isEmpty()) {
170
-			params.add("/d");
171
-			params.add(data);
172
-		}
173
-		
174
-		execAndWait(params.toArray(new String[params.size()]));
175
-	}
176
-	
177
-	/**
178
-	 * Execute and wait for the requested command
179
-	 *
180
-	 * @param cmd Command array to execute/
181
-	 * @return return value from command, or -1 if there was an error.
182
-	 */
183
-	private int execAndWait(final String cmd[]) {
184
-		try {
185
-			final Process myProcess = Runtime.getRuntime().exec(cmd);
186
-			new StreamReader(myProcess.getInputStream()).start();
187
-			new StreamReader(myProcess.getErrorStream()).start();
188
-			try {
189
-				myProcess.waitFor();
190
-			} catch (InterruptedException e) { }
191
-			if (myProcess.exitValue() != 0) {
192
-				step.addText("\t - Error: Unknown Reason");
193
-			}
194
-			return myProcess.exitValue();
195
-		} catch (SecurityException e) {
196
-			step.addText("\t - Error: "+e.getMessage());
197
-		} catch (IOException e) {
198
-			step.addText("\t - Error: "+e.getMessage());
199
-		}
200
-		
201
-		return -1;
202
-	}
197
+        return -1;
198
+    }
203 199
 
204
-	/**
205
-	 * Setup shortcut
206
-	 *
207
-	 * @param location Location where app will be installed to.
208
-	 * @param shortcutType Type of shortcut to add.
209
-	 */
210
-	public void setupShortcut(final String location, final ShortcutType shortcutType) {
211
-		// Shortcut.exe is from http://www.optimumx.com/download/#Shortcut
200
+    /** {@inheritDoc} */
201
+    @Override
202
+    public void setupShortcut(final String location,
203
+                              final ShortcutType shortcutType) {
204
+        // Shortcut.exe is from http://www.optimumx.com/download/#Shortcut
212 205
 
213
-		if (!supportsShortcut(shortcutType)) {
214
-			step.addText(" - Error creating shortcut. Not applicable to this Operating System");
215
-			return;
216
-		}
206
+        if (!supportsShortcut(shortcutType)) {
207
+            step.addText(
208
+                    " - Error creating shortcut. Not applicable to this Operating System");
209
+            return;
210
+        }
217 211
 
218
-		if (new File("Shortcut.exe").exists()) {
219
-			String filename = "";
220
-			File dir;
212
+        if (new File("Shortcut.exe").exists()) {
213
+            String filename = "";
214
+            File dir;
221 215
 
222
-			switch (shortcutType) {
223
-				case DESKTOP:
224
-					if (isNT() || isVista()) {
225
-						filename = System.getProperty("user.home")+"\\Desktop";
226
-					} else {
227
-						filename = System.getenv("WINDIR")+"\\Desktop";
228
-					}
229
-					break;
216
+            switch (shortcutType) {
217
+                case DESKTOP:
218
+                    if (isNT() || isVista()) {
219
+                        filename = System.getProperty("user.home") + "\\Desktop";
220
+                    } else {
221
+                        filename = System.getenv("WINDIR") + "\\Desktop";
222
+                    }
223
+                    break;
230 224
 
231
-				case MENU:
232
-					if (isVista()) {
233
-						filename = System.getenv("APPDATA")+"\\Microsoft\\Windows";
234
-					} else {
235
-						filename = System.getProperty("user.home");
236
-					}
237
-					filename = filename+"\\Start Menu\\Programs\\DMDirc";
238
-					break;
225
+                case MENU:
226
+                    if (isVista()) {
227
+                        filename = System.getenv("APPDATA") +
228
+                                   "\\Microsoft\\Windows";
229
+                    } else {
230
+                        filename = System.getProperty("user.home");
231
+                    }
232
+                    filename = filename + "\\Start Menu\\Programs\\DMDirc";
233
+                    break;
239 234
 
240
-				case QUICKLAUNCH:
241
-					if (isVista()) {
242
-						filename = System.getProperty("user.home")+"\\AppData\\Roaming\\Microsoft\\Internet Explorer\\Quick Launch";
243
-					} else {
244
-						filename = System.getProperty("user.home")+"\\Application Data\\Microsoft\\Internet Explorer\\Quick Launch";
245
-					}
246
-					break;
235
+                case QUICKLAUNCH:
236
+                    if (isVista()) {
237
+                        filename =
238
+                        System.getProperty("user.home") +
239
+                        "\\AppData\\Roaming\\Microsoft\\Internet Explorer\\Quick Launch";
240
+                    } else {
241
+                        filename =
242
+                        System.getProperty("user.home") +
243
+                        "\\Application Data\\Microsoft\\Internet Explorer\\Quick Launch";
244
+                    }
245
+                    break;
247 246
 
248
-				case UNINSTALLER:
249
-					// Registry hax!
250
-					final String key = "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\DMDirc";
251
-					addRegistryKey(key);
252
-					editRegistryValue(key, "Comments", "DMDirc IRC Client");
253
-					editRegistryValue(key, "DisplayName", "DMDirc IRC Client");
254
-					editRegistryValue(key, "DisplayIcon", location+"\\icon.ico");
255
-					editRegistryValue(key, "UninstallString", location+"\\Uninstaller.exe");
256
-					editRegistryValue(key, "Publisher", "DMDirc.com");
257
-					editRegistryValue(key, "URLInfoAbout", "http://www.DMDirc.com/");
258
-					editRegistryValue(key, "URLUpdateInfo", "http://www.DMDirc.com/");
259
-					editRegistryValue(key, "InstallDir", location);
260
-					editRegistryValue(key, "InstalledTime", String.valueOf(System.currentTimeMillis()));
261
-					return;
247
+                case UNINSTALLER:
248
+                    // Registry hax!
249
+                    final String key =
250
+                                 "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\DMDirc";
251
+                    addRegistryKey(key);
252
+                    editRegistryValue(key, "Comments", "DMDirc IRC Client");
253
+                    editRegistryValue(key, "DisplayName", "DMDirc IRC Client");
254
+                    editRegistryValue(key, "DisplayIcon", location +
255
+                                                          "\\icon.ico");
256
+                    editRegistryValue(key, "UninstallString",
257
+                                      location + "\\Uninstaller.exe");
258
+                    editRegistryValue(key, "Publisher", "DMDirc.com");
259
+                    editRegistryValue(key, "URLInfoAbout",
260
+                                      "http://www.DMDirc.com/");
261
+                    editRegistryValue(key, "URLUpdateInfo",
262
+                                      "http://www.DMDirc.com/");
263
+                    editRegistryValue(key, "InstallDir", location);
264
+                    editRegistryValue(key, "InstalledTime", String.valueOf(
265
+                            System.currentTimeMillis()));
266
+                    return;
262 267
 
263
-				case PROTOCOL:
264
-					// Add needed keys.
265
-					addRegistryKey("HKCR\\irc");
266
-					addRegistryKey("HKCR\\irc\\DefaultIcon");
267
-					addRegistryKey("HKCR\\irc\\Shell");
268
-					addRegistryKey("HKCR\\irc\\Shell\\open");
269
-					addRegistryKey("HKCR\\irc\\Shell\\open\\command");
270
-					// Now the values
271
-					editRegistryValue("HKCR\\irc", "", "URL:IRC Protocol");
272
-					editRegistryValue("HKCR\\irc", "URL Protocol", "");
273
-					editRegistryValue("HKCR\\irc", "EditFlags", "REG_BINARY", "02000000");
274
-					editRegistryValue("HKCR\\irc\\DefaultIcon", "", location+"\\icon.ico");
275
-					editRegistryValue("HKCR\\irc\\Shell\\open\\command", "", "\\\""+location+"\\DMDirc.exe\\\" -e -c %1");
276
-					return;
268
+                case PROTOCOL:
269
+                    // Add needed keys.
270
+                    addRegistryKey("HKCR\\irc");
271
+                    addRegistryKey("HKCR\\irc\\DefaultIcon");
272
+                    addRegistryKey("HKCR\\irc\\Shell");
273
+                    addRegistryKey("HKCR\\irc\\Shell\\open");
274
+                    addRegistryKey("HKCR\\irc\\Shell\\open\\command");
275
+                    // Now the values
276
+                    editRegistryValue("HKCR\\irc", "", "URL:IRC Protocol");
277
+                    editRegistryValue("HKCR\\irc", "URL Protocol", "");
278
+                    editRegistryValue("HKCR\\irc", "EditFlags", "REG_BINARY",
279
+                                      "02000000");
280
+                    editRegistryValue("HKCR\\irc\\DefaultIcon", "", location +
281
+                                                                    "\\icon.ico");
282
+                    editRegistryValue("HKCR\\irc\\Shell\\open\\command", "",
283
+                                      "\\\"" + location +
284
+                                      "\\DMDirc.exe\\\" -e -c %1");
285
+                    return;
277 286
 
278
-				default:
279
-					step.addText(" - Error creating shortcut. Not applicable to this Operating System");
280
-					return;
281
-			}
287
+                default:
288
+                    step.addText(
289
+                            " - Error creating shortcut. Not applicable to this Operating System");
290
+                    return;
291
+            }
282 292
 
283
-			if (filename.length() == 0) {
284
-				step.addText(" - Error creating shortcut. Not applicable to this System");
285
-				return;
286
-			}
293
+            if (filename.length() == 0) {
294
+                step.addText(
295
+                        " - Error creating shortcut. Not applicable to this System");
296
+                return;
297
+            }
287 298
 
288
-			// Check the dir exists
289
-			dir = new File(filename);
290
-			if (!dir.exists()) { dir.mkdir(); }
299
+            // Check the dir exists
300
+            dir = new File(filename);
301
+            if (!dir.exists()) {
302
+                dir.mkdir();
303
+            }
291 304
 
292
-			// Delete an older shortcut
293
-			final File oldFile = new File(filename+"\\DMDirc.lnk");
294
-			if (oldFile.exists()) { oldFile.delete(); }
305
+            // Delete an older shortcut
306
+            final File oldFile = new File(filename + "\\DMDirc.lnk");
307
+            if (oldFile.exists()) {
308
+                oldFile.delete();
309
+            }
295 310
 
296 311
 //			final String thisDirName = new File("").getAbsolutePath();
297
-			final String[] command = new String[] {
298
-//			                      thisDirName+"/Shortcut.exe",
299
-			                      "Shortcut.exe",
300
-			                      "/F:"+filename+"\\DMDirc.lnk",
301
-			                      "/A:C",
302
-//			                      "/T:"+location+"\\DMDirc.bat",
303
-//			                      "/T:javaw.exe",
304
-//			                      "/P:-jar DMDirc.jar",
305
-			                      "/T:"+location+"\\DMDirc.exe",
306
-			                      "/W:"+location,
307
-			                      "/I:"+location+"\\icon.ico",
308
-			                      "/D:DMDirc IRC Client"
309
-			                      };
310
-				execAndWait(command);
311
-		} else {
312
-			step.addText(" - Error creating shortcut: Unable to find Shortcut.exe");
313
-		}
314
-	}
312
+            final String[] command = new String[]{
313
+                //			                      thisDirName+"/Shortcut.exe",
314
+                "Shortcut.exe",
315
+                "/F:" + filename + "\\DMDirc.lnk",
316
+                "/A:C",
317
+                //			                      "/T:"+location+"\\DMDirc.bat",
318
+                //			                      "/T:javaw.exe",
319
+                //			                      "/P:-jar DMDirc.jar",
320
+                "/T:" + location + "\\DMDirc.exe",
321
+                "/W:" + location,
322
+                "/I:" + location + "\\icon.ico",
323
+                "/D:DMDirc IRC Client"
324
+            };
325
+            execAndWait(command);
326
+        } else {
327
+            step.addText(
328
+                    " - Error creating shortcut: Unable to find Shortcut.exe");
329
+        }
330
+    }
315 331
 }

+ 39
- 0
src/com/dmdirc/installer/WizardListener.java Ver arquivo

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer;
24
+
25
+/**
26
+ * Wizard interface, notifications on change of step and closing.
27
+ */
28
+public interface WizardListener {
29
+    
30
+    /** 
31
+     * Called when the wizard finishes. 
32
+     */
33
+    void wizardFinished();
34
+    
35
+    /**
36
+     * Called when the wizard is cancelled.
37
+     */
38
+    void wizardCancelled();
39
+}

+ 99
- 0
src/com/dmdirc/installer/ui/EtchedLineBorder.java Ver arquivo

@@ -0,0 +1,99 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ * 
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ * 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import java.awt.Component;
26
+import java.awt.Graphics;
27
+
28
+import javax.swing.border.EtchedBorder;
29
+
30
+/**
31
+ * An etched line border.
32
+ */
33
+public class EtchedLineBorder extends EtchedBorder {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 1;
41
+    /** Border side. */
42
+    private final BorderSide side;
43
+
44
+    /** Border side. */
45
+    public enum BorderSide {
46
+
47
+        /** Creates a border at the top. */
48
+        TOP,
49
+        /** Creates a border at the bottom. */
50
+        BOTTOM,
51
+    };
52
+
53
+    /**
54
+     * Creates a new etched line border.
55
+     * 
56
+     * @param type Etch type
57
+     * @param side Border side
58
+     */
59
+    public EtchedLineBorder(final int type, final BorderSide side) {
60
+        super(type);
61
+
62
+        this.side = side;
63
+    }
64
+
65
+    /** {@inheritDoc} */
66
+    @Override
67
+    public void paintBorder(final Component c, final Graphics g, final int x,
68
+                            final int y, final int width, final int height) {
69
+        g.translate(x, y);
70
+
71
+        g.setColor(
72
+                etchType == LOWERED ? getShadowColor(c) : getHighlightColor(c));
73
+        switch (side) {
74
+            case TOP:
75
+                g.drawLine(0, 0, width - 2, 0);
76
+                break;
77
+            case BOTTOM:
78
+                g.drawLine(0, height - 1, width - 2, height - 1);
79
+                break;
80
+            default:
81
+                break;
82
+        }
83
+
84
+        g.setColor(
85
+                etchType == LOWERED ? getHighlightColor(c) : getShadowColor(c));
86
+        switch (side) {
87
+            case TOP:
88
+                g.drawLine(0, 1, width - 2, 1);
89
+                break;
90
+            case BOTTOM:
91
+                g.drawLine(0, height, width - 2, height);
92
+                break;
93
+            default:
94
+                break;
95
+        }
96
+
97
+        g.translate(-x, -y);
98
+    }
99
+}

+ 339
- 0
src/com/dmdirc/installer/ui/InstallerDialog.java Ver arquivo

@@ -0,0 +1,339 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer.ui;
25
+
26
+import com.dmdirc.installer.Step;
27
+import com.dmdirc.installer.StepListener;
28
+import com.dmdirc.installer.WizardListener;
29
+import com.dmdirc.util.ListenerList;
30
+
31
+import java.awt.BorderLayout;
32
+import java.awt.Dimension;
33
+
34
+import java.awt.event.ActionEvent;
35
+import java.awt.event.ActionListener;
36
+import java.awt.event.WindowAdapter;
37
+import java.awt.event.WindowEvent;
38
+import java.util.ArrayList;
39
+import java.util.List;
40
+import javax.swing.JFrame;
41
+import javax.swing.JOptionPane;
42
+import javax.swing.UIManager;
43
+import javax.swing.UnsupportedLookAndFeelException;
44
+
45
+/**
46
+ *
47
+ */
48
+public class InstallerDialog extends JFrame implements ActionListener {
49
+
50
+    private static final long serialVersionUID = -2001827768443747849L;
51
+    private final TitlePanel title;
52
+    private final WizardPanel wizard;
53
+    private final WizardControlPanel control;
54
+    private final ListenerList listeners;
55
+
56
+    /**
57
+     *
58
+     * @param dialogTitle
59
+     */
60
+    public InstallerDialog(final String dialogTitle) {
61
+        title = new TitlePanel(dialogTitle);
62
+        wizard = new WizardPanel(this);
63
+        control = new WizardControlPanel();
64
+        listeners = new ListenerList();
65
+
66
+        setLayout(new BorderLayout());
67
+
68
+        add(title, BorderLayout.NORTH);
69
+        add(wizard, BorderLayout.CENTER);
70
+        add(control, BorderLayout.SOUTH);
71
+
72
+        //setIconImage(IconManager.getIconManager().getImage("icon"));
73
+        setPreferredSize(new Dimension(400, 350));
74
+        setMaximumSize(new Dimension(400, 350));
75
+
76
+        control.getPrevButton().addActionListener(this);
77
+        control.getNextButton().addActionListener(this);
78
+    }
79
+
80
+    /**
81
+     *
82
+     * 
83
+     * @param step
84
+     */
85
+    public void addStep(final SwingStep step) {
86
+        wizard.addStep(step);
87
+    }
88
+
89
+    /**
90
+     *
91
+     */
92
+    public void display() {
93
+        wizard.display();
94
+        control.setTotal(wizard.getTotalSteps());
95
+        control.setProgress(wizard.getCurrentStepIndex());
96
+        addWindowListener(new WindowAdapter() {
97
+
98
+            /** {@inheritDoc} */
99
+            @Override
100
+            public void windowClosing(final WindowEvent e) {
101
+                fireWizardCancelled();
102
+            }
103
+        });
104
+
105
+        pack();
106
+        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
107
+        setVisible(true);
108
+        fireStepAboutToBeDisplayed(wizard.getStep(wizard.getCurrentStepIndex()));
109
+    }
110
+
111
+    /**
112
+     *
113
+     * @param steps 
114
+     */
115
+    public void display(final List<Step> steps) {
116
+        final List<SwingStep> swingSteps = new ArrayList<SwingStep>();
117
+        for (Step step : steps) {
118
+            if (step instanceof SwingStep) {
119
+                swingSteps.add((SwingStep) step);
120
+            }
121
+        }
122
+        display();
123
+    }
124
+
125
+    /**
126
+     *
127
+     *
128
+     * @param enable
129
+     */
130
+    public void enableNextStep(final boolean enable) {
131
+        control.getNextButton().setEnabled(enable);
132
+    }
133
+
134
+    /**
135
+     *
136
+     *
137
+     * @param enable
138
+     */
139
+    public void enablePreviousStep(final boolean enable) {
140
+        control.getPrevButton().setEnabled(enable);
141
+    }
142
+
143
+    /**
144
+     *
145
+     * 
146
+     * @return
147
+     */
148
+    public boolean showCancelConfirmation() {
149
+        return JOptionPane.showConfirmDialog(this,
150
+                                             "Are you sure you want to cancel?",
151
+                                             "Cancel confirmation",
152
+                                             JOptionPane.YES_NO_OPTION,
153
+                                             JOptionPane.WARNING_MESSAGE) ==
154
+               JOptionPane.YES_OPTION;
155
+    }
156
+
157
+    /**
158
+     *
159
+     *
160
+     * @param step
161
+     * @return
162
+     */
163
+    public Step getStep(final int step) {
164
+        return wizard.getStep(step);
165
+    }
166
+
167
+    /**
168
+     *
169
+     * @param name
170
+     * @return
171
+     */
172
+    public Step getStep(final String name) {
173
+        return wizard.getStep(name);
174
+    }
175
+
176
+    /**
177
+     *
178
+     *
179
+     * @return
180
+     */
181
+    public Step getCurrentStep() {
182
+        return wizard.getCurrentStep();
183
+    }
184
+
185
+    /**
186
+     *
187
+     *
188
+     * @return
189
+     */
190
+    public int getCurrentStepIndex() {
191
+        return wizard.getCurrentStepIndex();
192
+    }
193
+
194
+    /**
195
+     *
196
+     *
197
+     * @return
198
+     */
199
+    public String getCurrentStepName() {
200
+        return wizard.getCurrentStepName();
201
+    }
202
+
203
+    /**
204
+     *
205
+     *
206
+     * @param step
207
+     */
208
+    void fireStepAboutToBeDisplayed(final Step step) {
209
+        for (StepListener listener : listeners.get(StepListener.class)) {
210
+            listener.stepAboutToDisplay(step);
211
+        }
212
+    }
213
+
214
+    /**
215
+     *
216
+     * 
217
+     * @param step
218
+     */
219
+    void fireStepHidden(final Step step) {
220
+        for (StepListener listener : listeners.get(StepListener.class)) {
221
+            listener.stepHidden(step);
222
+        }
223
+    }
224
+
225
+    /**
226
+     *
227
+     * 
228
+     * @param listener
229
+     */
230
+    public void addStepListener(final StepListener listener) {
231
+        listeners.add(StepListener.class, listener);
232
+    }
233
+
234
+    /**
235
+     *
236
+     *
237
+     * @param listener
238
+     */
239
+    public void removeStepListener(final StepListener listener) {
240
+        listeners.remove(StepListener.class, listener);
241
+
242
+    }
243
+
244
+    /**
245
+     *
246
+     */
247
+    void fireWizardCancelled() {
248
+        for (WizardListener listener : listeners.get(WizardListener.class)) {
249
+            listener.wizardCancelled();
250
+        }
251
+    }
252
+
253
+    /**
254
+     * 
255
+     */
256
+    void fireWizardFinished() {
257
+        for (WizardListener listener : listeners.get(WizardListener.class)) {
258
+            listener.wizardFinished();
259
+        }
260
+    }
261
+
262
+    /**
263
+     *
264
+     *
265
+     * @param listener
266
+     */
267
+    public void addWizardListener(final WizardListener listener) {
268
+        listeners.add(WizardListener.class, listener);
269
+    }
270
+
271
+    /**
272
+     *
273
+     * 
274
+     * @param listener
275
+     */
276
+    public void removeWizardListener(final WizardListener listener) {
277
+        listeners.remove(WizardListener.class, listener);
278
+    }
279
+
280
+    /**
281
+     * Initialises any settings required by this UI (this is always called
282
+     * before any aspect of the UI is instansiated).
283
+     *
284
+     * @throws UnsupportedOperationException If unable to switch to the system
285
+     * look and feel
286
+     */
287
+    public static void initUISettings() {
288
+
289
+        try {
290
+            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
291
+        } catch (InstantiationException ex) {
292
+            throw new UnsupportedOperationException("Unable to switch to the " +
293
+                                                    "system look and feel", ex);
294
+        } catch (ClassNotFoundException ex) {
295
+            throw new UnsupportedOperationException("Unable to switch to the " +
296
+                                                    "system look and feel", ex);
297
+        } catch (UnsupportedLookAndFeelException ex) {
298
+            throw new UnsupportedOperationException("Unable to switch to the " +
299
+                                                    "system look and feel", ex);
300
+        } catch (IllegalAccessException ex) {
301
+            throw new UnsupportedOperationException("Unable to switch to the " +
302
+                                                    "system look and feel", ex);
303
+        }
304
+
305
+        UIManager.put("swing.useSystemFontSettings", true);
306
+        UIManager.put("swing.boldMetal", false);
307
+    }
308
+
309
+    @Override
310
+    public void actionPerformed(ActionEvent e) {
311
+        final int currentStep = wizard.getCurrentStepIndex();
312
+        Step hiddenStep = null;
313
+        Step shownStep = null;
314
+        if (e.getSource() == control.getPrevButton()) {
315
+            wizard.previousStep();
316
+            hiddenStep = wizard.getStep(currentStep);
317
+            shownStep = wizard.getStep(currentStep - 1);
318
+        } else if (e.getSource() == control.getNextButton()) {
319
+            if ("Finish".equals(control.getNextButton().getText())) {
320
+                fireWizardFinished();
321
+                shownStep = wizard.getStep(currentStep);
322
+                dispose();
323
+            } else {
324
+                wizard.nextStep();
325
+                hiddenStep = wizard.getStep(currentStep);
326
+                shownStep = wizard.getStep(currentStep + 1);
327
+            }
328
+        } else {
329
+            return;
330
+        }
331
+        if (shownStep != null) {
332
+            fireStepAboutToBeDisplayed(shownStep);
333
+        }
334
+        if (hiddenStep != null) {
335
+            fireStepHidden(hiddenStep);
336
+        }
337
+        control.setProgress(wizard.getCurrentStepIndex());
338
+    }
339
+}

+ 82
- 0
src/com/dmdirc/installer/ui/StepConfirm.java Ver arquivo

@@ -0,0 +1,82 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import com.dmdirc.installer.TextStep;
26
+
27
+import java.awt.BorderLayout;
28
+import javax.swing.SwingUtilities;
29
+
30
+/**
31
+ * This confirms the settings chosen in the previous step
32
+ */
33
+public final class StepConfirm extends SwingStep implements TextStep {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 2;
41
+    /** Text area showing the install information */
42
+    private final TextLabel infoLabel = new TextLabel("");
43
+
44
+    /**
45
+     * Creates a new instance of StepConfirm.
46
+     */
47
+    public StepConfirm() {
48
+        super();
49
+        setLayout(new BorderLayout());
50
+        add(infoLabel, BorderLayout.CENTER);
51
+    }
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public String getStepName() {
56
+        return "Confirm";
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public void addText(final String text) {
62
+        SwingUtilities.invokeLater(new Runnable() {
63
+
64
+            @Override
65
+            public void run() {
66
+                infoLabel.setText(infoLabel.getText() + text);
67
+            }
68
+        });
69
+    }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public void setText(final String text) {
74
+        SwingUtilities.invokeLater(new Runnable() {
75
+
76
+            @Override
77
+            public void run() {
78
+                infoLabel.setText(text);
79
+            }
80
+        });
81
+    }
82
+}

+ 62
- 0
src/com/dmdirc/installer/ui/StepError.java Ver arquivo

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import java.awt.BorderLayout;
26
+
27
+/**
28
+ * This step shows an unable to install error
29
+ */
30
+public final class StepError extends SwingStep {
31
+
32
+    /**
33
+     * A version number for this class. It should be changed whenever the class
34
+     * structure is changed (or anything else that would prevent serialized
35
+     * objects being unserialized with the new class).
36
+     */
37
+    private static final long serialVersionUID = 2;
38
+
39
+    /**
40
+     * Creates a new instance of StepError with a default error message.
41
+     */
42
+    public StepError() {
43
+        this("Sorry, it is not possible to install DMDirc on this system at this time.\n\n");
44
+    }
45
+
46
+    /**
47
+     * Creates a new instance of StepError with a given error message.
48
+     *
49
+     * @param message Error message to show.
50
+     */
51
+    public StepError(final String message) {
52
+        super();
53
+        setLayout(new BorderLayout());
54
+        add(new TextLabel(message), BorderLayout.CENTER);
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public String getStepName() {
60
+        return "Error";
61
+    }
62
+}

+ 89
- 0
src/com/dmdirc/installer/ui/StepInstall.java Ver arquivo

@@ -0,0 +1,89 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import com.dmdirc.installer.TextStep;
26
+
27
+import java.awt.BorderLayout;
28
+
29
+import javax.swing.JScrollPane;
30
+import javax.swing.SwingUtilities;
31
+
32
+/**
33
+ * This confirms the settings chosen in the previous step
34
+ */
35
+public final class StepInstall extends SwingStep implements TextStep {
36
+
37
+    /**
38
+     * A version number for this class. It should be changed whenever the class
39
+     * structure is changed (or anything else that would prevent serialized
40
+     * objects being unserialized with the new class).
41
+     */
42
+    private static final long serialVersionUID = 2;
43
+    /** Text area showing the install information */
44
+    private final TextLabel infoLabel = new TextLabel("Beginning Install");
45
+    /** Scroll pane holding text area */
46
+    final JScrollPane scrollPane;
47
+
48
+    /**
49
+     * Creates a new instance of StepInstall.
50
+     */
51
+    public StepInstall() {
52
+        super();
53
+        setLayout(new BorderLayout());
54
+        scrollPane = new JScrollPane(infoLabel,
55
+                                     JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
56
+                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
57
+        add(scrollPane, BorderLayout.CENTER);
58
+    }
59
+
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    public String getStepName() {
63
+        return "Install";
64
+    }
65
+
66
+    /** {@inheritDoc} */
67
+    @Override
68
+    public synchronized void addText(final String text) {
69
+        SwingUtilities.invokeLater(new Runnable() {
70
+
71
+            @Override
72
+            public void run() {
73
+                infoLabel.setText(infoLabel.getText() + text + "\n");
74
+            }
75
+        });
76
+    }
77
+
78
+    /** {@inheritDoc} */
79
+    @Override
80
+    public synchronized void setText(final String text) {
81
+        SwingUtilities.invokeLater(new Runnable() {
82
+
83
+            @Override
84
+            public void run() {
85
+                infoLabel.setText(text);
86
+            }
87
+        });
88
+    }
89
+}

+ 426
- 0
src/com/dmdirc/installer/ui/StepLayout.java Ver arquivo

@@ -0,0 +1,426 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import com.dmdirc.installer.Step;
26
+
27
+import java.awt.Component;
28
+import java.awt.Container;
29
+import java.awt.Dimension;
30
+import java.awt.Insets;
31
+import java.awt.LayoutManager2;
32
+import java.io.Serializable;
33
+import java.util.ArrayList;
34
+import java.util.List;
35
+
36
+/**
37
+ * Adjusted Card layout.
38
+ */
39
+public class StepLayout implements LayoutManager2, Serializable {
40
+
41
+    /**
42
+     * A version number for this class. It should be changed whenever the class
43
+     * structure is changed (or anything else that would prevent serialized
44
+     * objects being unserialized with the new class).
45
+     */
46
+    private static final long serialVersionUID = 2;
47
+    /** Parent container. */
48
+    private Container parent;
49
+    /** Cards vector. */
50
+    private final List<SwingStep> steps;
51
+    /** Current step. */
52
+    private int currentStep;
53
+    /** Vertical gap. */
54
+    private int vGap;
55
+    /** Horiontal gap. */
56
+    private int hGap;
57
+
58
+    /**
59
+     * Instantiates a new step layout.
60
+     */
61
+    public StepLayout() {
62
+        this(0, 0);
63
+    }
64
+
65
+    /**
66
+     * Instantiates a new step layout.
67
+     * 
68
+     * @param parent Parent component
69
+     */
70
+    public StepLayout(final Container parent) {
71
+        this(0, 0, parent);
72
+    }
73
+
74
+    /**
75
+     * Instantiates a new step layout with the specified gaps.
76
+     * 
77
+     * @param hGap Horizontal gap
78
+     * @param vGap Vertical gap
79
+     */
80
+    public StepLayout(final int hGap, final int vGap) {
81
+        this(hGap, vGap, null);
82
+    }
83
+
84
+    /**
85
+     * Instantiates a new step layout with the specified gaps.
86
+     * 
87
+     * @param hGap Horizontal gap
88
+     * @param vGap Vertical gap
89
+     * @param parent Parent component
90
+     */
91
+    public StepLayout(final int hGap, final int vGap, final Container parent) {
92
+        steps = new ArrayList<SwingStep>();
93
+        currentStep = -1;
94
+        this.hGap = hGap;
95
+        this.vGap = vGap;
96
+        this.parent = parent;
97
+    }
98
+
99
+    /**
100
+     * Returns the number of steps in the layout.
101
+     * 
102
+     * @return number of steps >= 0
103
+     */
104
+    public int size() {
105
+        return steps.size();
106
+    }
107
+
108
+    /**
109
+     * Checks if the layout is empty
110
+     * 
111
+     * @return true iif the layout has no steps
112
+     */
113
+    public boolean isEmpty() {
114
+        return steps.isEmpty();
115
+    }
116
+
117
+    /**
118
+     * Returns the specified step from the layout.
119
+     * 
120
+     * @param index Step to retrieve
121
+     * 
122
+     * @return Step
123
+     */
124
+    public Step getStep(final int index) {
125
+        return steps.get(index);
126
+    }
127
+
128
+    /**
129
+     * Returns the step list.
130
+     * 
131
+     * @return List of steps
132
+     */
133
+    public List<SwingStep> getSteps() {
134
+        return steps;
135
+    }
136
+
137
+    /**
138
+     * Returns the current step index.
139
+     *
140
+     * @return Current step index
141
+     */
142
+    public int getCurrentStepIndex() {
143
+        return currentStep;
144
+    }
145
+
146
+    /**
147
+     * Returns the current step name.
148
+     *
149
+     * @return Current step name
150
+     */
151
+    public String getCurrentStepName() {
152
+        return steps.get(currentStep).getStepName();
153
+    }
154
+
155
+    /**
156
+     * Returns the current step name.
157
+     *
158
+     * @return Current step name
159
+     */
160
+    public Step getCurrentStep() {
161
+        return steps.get(currentStep);
162
+    }
163
+
164
+    /**
165
+     * Show the first step.
166
+     * 
167
+     * @param parent Parent container
168
+     */
169
+    public void first(final Container parent) {
170
+        show(0, parent);
171
+    }
172
+
173
+    /**
174
+     * Show the last step.
175
+     * 
176
+     * @param parent Parent container
177
+     */
178
+    public void last(final Container parent) {
179
+        show(parent.getComponentCount() - 1, parent);
180
+    }
181
+
182
+    /**
183
+     * Show the next step.
184
+     * 
185
+     * @param parent Parent container
186
+     */
187
+    public void next(final Container parent) {
188
+        show(currentStep + 1, parent);
189
+    }
190
+
191
+    /** 
192
+     * Show the previous step.
193
+     * 
194
+     * @param parent Parent container
195
+     */
196
+    public void previous(final Container parent) {
197
+        show(currentStep - 1, parent);
198
+    }
199
+
200
+    /**
201
+     * Show the specified step.
202
+     * 
203
+     * @param step Step to show
204
+     * @param parent Parent container
205
+     */
206
+    public void show(final Step step, final Container parent) {
207
+        show(steps.indexOf(step), parent);
208
+    }
209
+
210
+    /**
211
+     * Show the step at the specified index.
212
+     * 
213
+     * @param step Step to show
214
+     * @param parent Parent container
215
+     */
216
+    public void show(final int step, final Container parent) {
217
+        int stepNumber = step;
218
+        if (stepNumber == -1) {
219
+            if (stepNumber >= steps.size()) {
220
+                stepNumber = steps.size() - 1;
221
+            } else {
222
+                stepNumber = 0;
223
+            }
224
+        }
225
+        synchronized (parent.getTreeLock()) {
226
+            int componentCount = parent.getComponentCount();
227
+            for (int i = 0; i < componentCount; i++) {
228
+                Component comp = parent.getComponent(i);
229
+                if (comp.isVisible()) {
230
+                    comp.setVisible(false);
231
+                    break;
232
+                }
233
+            }
234
+            if (componentCount > 0) {
235
+                currentStep = stepNumber;
236
+                parent.getComponent(currentStep).setVisible(true);
237
+                parent.validate();
238
+            }
239
+        }
240
+    }
241
+
242
+    /** {@inheritDoc} */
243
+    @Override
244
+    public void addLayoutComponent(final Component comp,
245
+                                   final Object constraints) {
246
+        if (!(comp instanceof Step)) {
247
+            throw new IllegalArgumentException(
248
+                    "Component must be an instance of Step");
249
+        }
250
+        addLayoutComponent((SwingStep) comp);
251
+    }
252
+
253
+    /** 
254
+     * {@inheritDoc}
255
+     * 
256
+     * @deprecated Use addLayoutComponent(Component, Object) or 
257
+     * addLayoutComponent(Component)
258
+     * 
259
+     * @see addLayoutComponent(Component)
260
+     * @see addLayoutComponent(Component, Object)
261
+     */
262
+    @Override
263
+    @Deprecated
264
+    public void addLayoutComponent(final String name, final Component comp) {
265
+        if (!(comp instanceof Step)) {
266
+            throw new IllegalArgumentException(
267
+                    "Component must be an instance of Step");
268
+        }
269
+        addLayoutComponent((SwingStep) comp);
270
+    }
271
+
272
+    /**
273
+     * Adds a component to the layout.
274
+     * 
275
+     * @param step Component to add
276
+     */
277
+    public void addLayoutComponent(final SwingStep step) {
278
+        synchronized (step.getTreeLock()) {
279
+            if (!steps.isEmpty()) {
280
+                step.setVisible(false);
281
+            }
282
+            steps.add(step);
283
+        }
284
+    }
285
+
286
+    /** {@inheritDoc} */
287
+    @Override
288
+    public void removeLayoutComponent(final Component comp) {
289
+        synchronized (comp.getTreeLock()) {
290
+            if (comp.isVisible()) {
291
+                comp.setVisible(false);
292
+            }
293
+            next(comp.getParent());
294
+            steps.remove(comp);
295
+        }
296
+    }
297
+
298
+    /** 
299
+     * {@inheritDoc}
300
+     * 
301
+     * @return Returns the preferred size of the container
302
+     */
303
+    @Override
304
+    public Dimension preferredLayoutSize(final Container parent) {
305
+        synchronized (parent.getTreeLock()) {
306
+            Insets insets = parent.getInsets();
307
+            int componentCount = parent.getComponentCount();
308
+            int width = 0;
309
+            int height = 0;
310
+
311
+            for (int i = 0; i < componentCount; i++) {
312
+                Component comp = parent.getComponent(i);
313
+                Dimension preferredDimension = comp.getPreferredSize();
314
+                if (preferredDimension.width > width) {
315
+                    width = preferredDimension.width;
316
+                }
317
+                if (preferredDimension.height > height) {
318
+                    height = preferredDimension.height;
319
+                }
320
+            }
321
+            return new Dimension(insets.left + insets.right + width + hGap * 2,
322
+                                 insets.top + insets.bottom + height + vGap * 2);
323
+        }
324
+    }
325
+
326
+    /** 
327
+     * {@inheritDoc}
328
+     * 
329
+     * @return Returns the minimum size of the container
330
+     */
331
+    @Override
332
+    public Dimension minimumLayoutSize(final Container parent) {
333
+        synchronized (parent.getTreeLock()) {
334
+            Insets insets = parent.getInsets();
335
+            int componentCount = parent.getComponentCount();
336
+            int width = 0;
337
+            int height = 0;
338
+
339
+            for (int i = 0; i < componentCount; i++) {
340
+                Component comp = parent.getComponent(i);
341
+                Dimension minimumDimension = comp.getMinimumSize();
342
+                if (minimumDimension.width > width) {
343
+                    width = minimumDimension.width;
344
+                }
345
+                if (minimumDimension.height > height) {
346
+                    height = minimumDimension.height;
347
+                }
348
+            }
349
+            return new Dimension(insets.left + insets.right + width + hGap * 2,
350
+                                 insets.top + insets.bottom + height + vGap * 2);
351
+        }
352
+    }
353
+
354
+    /** 
355
+     * {@inheritDoc}
356
+     * 
357
+     * @param parent Container to get the size for
358
+     * 
359
+     * @return Returns the maximum size of the container
360
+     */
361
+    @Override
362
+    public Dimension maximumLayoutSize(final Container parent) {
363
+        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
364
+    }
365
+
366
+    /** 
367
+     * {@inheritDoc}
368
+     * 
369
+     * @param target Container to get the alignment from
370
+     * 
371
+     * @return Alignment
372
+     */
373
+    @Override
374
+    public float getLayoutAlignmentX(final Container target) {
375
+        return 0.5f;
376
+    }
377
+
378
+    /** 
379
+     * {@inheritDoc}
380
+     * 
381
+     * @param target Container to get the alignment from
382
+     * 
383
+     * @return Alignment
384
+     */
385
+    @Override
386
+    public float getLayoutAlignmentY(final Container target) {
387
+        return 0.5f;
388
+    }
389
+
390
+    /** 
391
+     * {@inheritDoc}
392
+     * 
393
+     * @param target  Container to invalidate
394
+     */
395
+    @Override
396
+    public void invalidateLayout(final Container target) {
397
+        //Ignore
398
+    }
399
+
400
+    /** {@inheritDoc} */
401
+    @Override
402
+    public void layoutContainer(final Container parent) {
403
+        synchronized (parent.getTreeLock()) {
404
+            Insets insets = parent.getInsets();
405
+            int componentCount = parent.getComponentCount();
406
+            Component comp = null;
407
+            boolean currentFound = false;
408
+
409
+            for (int i = 0; i < componentCount; i++) {
410
+                comp = parent.getComponent(i);
411
+                comp.setBounds(hGap + insets.left, vGap + insets.top,
412
+                               parent.getWidth() - (hGap * 2 + insets.left +
413
+                                                    insets.right), parent.
414
+                        getHeight() - (vGap * 2 +
415
+                                       insets.top + insets.bottom));
416
+                if (comp.isVisible()) {
417
+                    currentFound = true;
418
+                }
419
+            }
420
+
421
+            if (!currentFound && componentCount > 0) {
422
+                parent.getComponent(0).setVisible(true);
423
+            }
424
+        }
425
+    }
426
+}

+ 130
- 0
src/com/dmdirc/installer/ui/StepSettings.java Ver arquivo

@@ -0,0 +1,130 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import com.dmdirc.installer.Main;
26
+import com.dmdirc.installer.Settings;
27
+import com.dmdirc.installer.DefaultSettings;
28
+import com.dmdirc.installer.Installer.ShortcutType;
29
+
30
+import javax.swing.Box;
31
+import javax.swing.BoxLayout;
32
+import javax.swing.JCheckBox;
33
+import javax.swing.JTextField;
34
+
35
+/**
36
+ * Queries the user for where to install dmdirc, and if they want to setup shortcuts
37
+ */
38
+public final class StepSettings extends SwingStep implements Settings {
39
+
40
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 3;
46
+    /** Menu Shorcuts checkbox. */
47
+    private final JCheckBox shortcutMenu = new JCheckBox("Create " + Main.
48
+            getInstaller().getMenuName() + " shortcut");
49
+    /** Desktop Shorcuts checkbox. */
50
+    private final JCheckBox shortcutDesktop = new JCheckBox(
51
+            "Create desktop shortcut");
52
+    /** Quick-Launch Shorcuts checkbox. */
53
+    private final JCheckBox shortcutQuick = new JCheckBox(
54
+            "Create Quick Launch shortcut");
55
+    /** Register IRC:// protocol. */
56
+    private final JCheckBox shortcutProtocol = new JCheckBox(
57
+            "Make DMDirc handle irc:// links");
58
+    /** Install Location input. */
59
+    private final JTextField location = new JTextField(Main.getInstaller().
60
+            defaultInstallLocation(), 20);
61
+
62
+    /**
63
+     * Creates a new instance of StepSettings.
64
+     */
65
+    public StepSettings() {
66
+        super();
67
+
68
+        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
69
+
70
+        DefaultSettings defaultSettings = new DefaultSettings();
71
+        shortcutMenu.setSelected(defaultSettings.getShortcutMenuState());
72
+        shortcutDesktop.setSelected(defaultSettings.getShortcutDesktopState());
73
+        shortcutQuick.setSelected(defaultSettings.getShortcutQuickState());
74
+        shortcutProtocol.setSelected(defaultSettings.getShortcutProtocolState());
75
+
76
+        add(new TextLabel("Here you can choose options for the install." +
77
+                          "\n\nInstall Location: \n"));
78
+        add(location);
79
+
80
+        if (Main.getInstaller().supportsShortcut(ShortcutType.MENU)) {
81
+            add(shortcutMenu);
82
+        }
83
+        if (Main.getInstaller().supportsShortcut(ShortcutType.DESKTOP)) {
84
+            add(shortcutDesktop);
85
+        }
86
+        if (Main.getInstaller().supportsShortcut(ShortcutType.QUICKLAUNCH)) {
87
+            add(shortcutQuick);
88
+        }
89
+        if (Main.getInstaller().supportsShortcut(ShortcutType.PROTOCOL)) {
90
+            add(shortcutProtocol);
91
+        }
92
+        add(Box.createVerticalGlue());
93
+    }
94
+
95
+    /** {@inheritDoc} */
96
+    @Override
97
+    public String getStepName() {
98
+        return "Settings";
99
+    }
100
+
101
+    /** {@inheritDoc} */
102
+    @Override
103
+    public boolean getShortcutMenuState() {
104
+        return shortcutMenu.isSelected();
105
+    }
106
+
107
+    /** {@inheritDoc} */
108
+    @Override
109
+    public boolean getShortcutDesktopState() {
110
+        return shortcutDesktop.isSelected();
111
+    }
112
+
113
+    /** {@inheritDoc} */
114
+    @Override
115
+    public boolean getShortcutQuickState() {
116
+        return shortcutQuick.isSelected();
117
+    }
118
+
119
+    /** {@inheritDoc} */
120
+    @Override
121
+    public boolean getShortcutProtocolState() {
122
+        return shortcutProtocol.isSelected();
123
+    }
124
+
125
+    /** {@inheritDoc} */
126
+    @Override
127
+    public String getInstallLocation() {
128
+        return location.getText().trim();
129
+    }
130
+}

+ 64
- 0
src/com/dmdirc/installer/ui/StepWelcome.java Ver arquivo

@@ -0,0 +1,64 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import java.awt.BorderLayout;
26
+
27
+/**
28
+ * Tells the user what this application does
29
+ */
30
+public final class StepWelcome extends SwingStep {
31
+
32
+    /**
33
+     * A version number for this class. It should be changed whenever the class
34
+     * structure is changed (or anything else that would prevent serialized
35
+     * objects being unserialized with the new class).
36
+     */
37
+    private static final long serialVersionUID = 2;
38
+
39
+    /**
40
+     * Creates a new instance of StepWelcome.
41
+     *
42
+     * @param releaseName 
43
+     */
44
+    public StepWelcome(final String releaseName) {
45
+        super();
46
+
47
+        setLayout(new BorderLayout());
48
+
49
+        add(new TextLabel(
50
+                "Welcome to the " + releaseName + " installer. This program " +
51
+                "will install DMDirc on this computer.\n\nDMDirc is a " +
52
+                "cross-platform IRC client developed by Chris Smith, Shane " +
53
+                "Mc Cormack and Gregory Holmes. DMDirc is released for free " +
54
+                "under the MIT license; for more information, please visit " +
55
+                "www.DMDirc.com.\n\nClick \"Next\" to continue, or close " +
56
+                "this program to cancel the installation."), BorderLayout.CENTER);
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public String getStepName() {
62
+        return "Welcome";
63
+    }
64
+}

+ 34
- 0
src/com/dmdirc/installer/ui/SwingStep.java Ver arquivo

@@ -0,0 +1,34 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer.ui;
25
+
26
+import com.dmdirc.installer.Step;
27
+
28
+import javax.swing.JPanel;
29
+
30
+/**
31
+ * Extention of basic Step to make it a JPanel.
32
+ */
33
+public abstract class SwingStep extends JPanel implements Step {
34
+}

+ 74
- 0
src/com/dmdirc/installer/ui/TextLabel.java Ver arquivo

@@ -0,0 +1,74 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.installer.ui;
24
+
25
+import java.awt.Insets;
26
+
27
+import javax.swing.JTextPane;
28
+import javax.swing.text.DefaultStyledDocument;
29
+
30
+/**
31
+ * Dyamnic text label.
32
+ */
33
+public class TextLabel extends JTextPane {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the
37
+     * class structure is changed (or anything else that would prevent
38
+     * serialized objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 1;
41
+
42
+    /**
43
+     * Creates a new instance of TextLabel.
44
+     */
45
+    public TextLabel() {
46
+        this(null, true);
47
+    }
48
+
49
+    /**
50
+     * Creates a new instance of TextLabel.
51
+     *
52
+     * @param text Text to display
53
+     */
54
+    public TextLabel(final String text) {
55
+        this(text, true);
56
+    }
57
+
58
+    /**
59
+     * Creates a new instance of TextLabel.
60
+     *
61
+     * @param text Text to display
62
+     * @param justified Justify the text?
63
+     */
64
+    public TextLabel(final String text, final boolean justified) {
65
+        super(new DefaultStyledDocument());
66
+
67
+        setOpaque(false);
68
+        setEditable(false);
69
+        setHighlighter(null);
70
+        setMargin(new Insets(0, 0, 0, 0));
71
+
72
+        setText(text);
73
+    }
74
+}

+ 69
- 0
src/com/dmdirc/installer/ui/TitlePanel.java Ver arquivo

@@ -0,0 +1,69 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer.ui;
25
+
26
+import com.dmdirc.installer.ui.EtchedLineBorder.BorderSide;
27
+
28
+import java.awt.BorderLayout;
29
+import java.awt.Color;
30
+
31
+import javax.swing.BorderFactory;
32
+import javax.swing.JLabel;
33
+import javax.swing.JPanel;
34
+import javax.swing.border.EtchedBorder;
35
+
36
+/**
37
+ * Simple title panel for a wizard.
38
+ */
39
+public class TitlePanel extends JPanel {
40
+
41
+    private static final long serialVersionUID = 7173184984913948951L;
42
+    private final JLabel title;
43
+
44
+    /**
45
+     * Instantiates a new title panel.
46
+     * 
47
+     * @param titleText Initial title text
48
+     */
49
+    public TitlePanel(final String titleText) {
50
+        super(new BorderLayout());
51
+        title = new JLabel(titleText);
52
+
53
+        title.setFont(title.getFont().deriveFont((float) (title.getFont().
54
+                getSize() * 1.5)));
55
+        add(title, BorderLayout.CENTER);
56
+        setBackground(Color.WHITE);
57
+        setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
58
+        setBorder(new EtchedLineBorder(EtchedBorder.LOWERED, BorderSide.BOTTOM));
59
+    }
60
+
61
+    /**
62
+     * Sets the title text.
63
+     *
64
+     * @param titleText new title text
65
+     */
66
+    public void setText(final String titleText) {
67
+        title.setText(titleText);
68
+    }
69
+}

+ 129
- 0
src/com/dmdirc/installer/ui/WizardControlPanel.java Ver arquivo

@@ -0,0 +1,129 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer.ui;
25
+
26
+import javax.swing.Box;
27
+import javax.swing.JButton;
28
+import javax.swing.JLabel;
29
+import javax.swing.JPanel;
30
+
31
+/**
32
+ * Simple Panel representing the control buttons for a wizard.
33
+ */
34
+public class WizardControlPanel extends JPanel {
35
+
36
+    private static final long serialVersionUID = 7903362315297158222L;
37
+    private final JButton prev;
38
+    private final JButton next;
39
+    private final JLabel progress;
40
+    private int total;
41
+    private int step;
42
+
43
+    /**
44
+     * Instantiates a new wizard control panel.
45
+     */
46
+    public WizardControlPanel() {
47
+        this(0);
48
+    }
49
+
50
+    /**
51
+     * Instantiates a new wizard control panel using the specified number of
52
+     * steps.
53
+     * 
54
+     * @param total Total number of steps
55
+     */
56
+    public WizardControlPanel(final int total) {
57
+        this.total = total;
58
+        this.step = 0;
59
+        
60
+        prev = new JButton("\u00AB Previous");
61
+        next = new JButton("Next \u00BB");
62
+        progress = new JLabel();
63
+        updateProgressLabel();
64
+
65
+        add(progress);
66
+        add(Box.createHorizontalGlue());
67
+        add(prev);
68
+        add(next);
69
+    }
70
+
71
+    /**
72
+     * Returns the previous button.
73
+     *
74
+     * @return Previous button
75
+     */
76
+    public JButton getPrevButton() {
77
+        return prev;
78
+    }
79
+
80
+    /**
81
+     * Returns the next button.
82
+     * 
83
+     * @return Next button
84
+     */
85
+    public JButton getNextButton() {
86
+        return next;
87
+    }
88
+
89
+    /**
90
+     * Returns the progress label.
91
+     * 
92
+     * @return Progress Label
93
+     */
94
+    public JLabel getProgressLabel() {
95
+        return progress;
96
+    }
97
+
98
+    /**
99
+     * Updates the progress label.
100
+     */
101
+    public void updateProgressLabel() {
102
+        progress.setText("Step " + step + " of " + total);
103
+    }
104
+
105
+    /**
106
+     * Sets the new total number of steps.
107
+     * 
108
+     * @param total New total number of steps
109
+     */
110
+    public void setTotal(final int total) {
111
+        this.total = total;
112
+        updateProgressLabel();
113
+    }
114
+
115
+    /**
116
+     * Sets the current progress step.
117
+     * 
118
+     * @param step Progress step
119
+     */
120
+    public void setProgress(final int step) {
121
+        this.step = step + 1;
122
+        updateProgressLabel();
123
+        if (step + 1 == total) {
124
+            next.setText("Finish");
125
+        } else {
126
+            next.setText("Next \u00BB");
127
+        }
128
+    }
129
+}

+ 181
- 0
src/com/dmdirc/installer/ui/WizardPanel.java Ver arquivo

@@ -0,0 +1,181 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.installer.ui;
25
+
26
+import com.dmdirc.installer.Step;
27
+
28
+import java.util.List;
29
+import javax.swing.JPanel;
30
+
31
+/**
32
+ * Wizard panel, displays and controls the flow of steps.
33
+ */
34
+public class WizardPanel extends JPanel {
35
+
36
+    private static final long serialVersionUID = 7903362315297158222L;
37
+    private final StepLayout layout;
38
+    private final InstallerDialog dialog;
39
+
40
+    /**
41
+     * Instantiates a new wizard panel.
42
+     *
43
+     * @param dialog Parent installer dialog
44
+     */
45
+    public WizardPanel(final InstallerDialog dialog) {
46
+        super();
47
+
48
+        this.dialog = dialog;
49
+        layout = new StepLayout();
50
+        setLayout(layout);
51
+    }
52
+
53
+    /**
54
+     * Displays this panel with the specified steps.
55
+     * 
56
+     * @param steps Steps to display
57
+     */
58
+    public void display(final List<SwingStep> steps) {
59
+       for (SwingStep step : steps) {
60
+           addStep(step);
61
+       }
62
+       display();
63
+    }
64
+
65
+    /**
66
+     * Displays this panel with the existing steps.
67
+     */
68
+    public void display() {
69
+        showFirst();
70
+    }
71
+
72
+    /**
73
+     * Returns the step specified.
74
+     *
75
+     * @param step Step index
76
+     * 
77
+     * @return Step
78
+     */
79
+    public Step getStep(final int step) {
80
+        return layout.getStep(step);
81
+    }
82
+
83
+    /**
84
+     * Returns the step specified.
85
+     *
86
+     * @param stepName Step name
87
+     *
88
+     * @return Step
89
+     */
90
+    public Step getStep(final String stepName) {
91
+        Step step = null;
92
+        for (SwingStep loopStep : layout.getSteps()) {
93
+            if (stepName.equals(loopStep.getStepName())) {
94
+                return loopStep;
95
+            }
96
+        }
97
+        return step;
98
+    }
99
+
100
+    /**
101
+     * Returns the current Step.
102
+     *
103
+     * @return Current step index
104
+     */
105
+    public int getCurrentStepIndex() {
106
+        return layout.getCurrentStepIndex();
107
+    }
108
+
109
+    /**
110
+     * Returns the current Step.
111
+     *
112
+     * @return Current step index
113
+     */
114
+    public String getCurrentStepName() {
115
+        return layout.getCurrentStepName();
116
+    }
117
+
118
+    /**
119
+     * Returns the current Step.
120
+     *
121
+     * @return Current step index
122
+     */
123
+    public Step getCurrentStep() {
124
+        return layout.getCurrentStep();
125
+    }
126
+
127
+    /**
128
+     * Returns the total number of steps.
129
+     *
130
+     * @return Total number of steps
131
+     */
132
+    public int getTotalSteps() {
133
+        return layout.getSteps().size();
134
+    }
135
+
136
+    /**
137
+     * Adds a step to this panel.
138
+     *
139
+     * @param step Step to add
140
+     */
141
+    public void addStep(final SwingStep step) {
142
+        add(step, step.getStepName());
143
+    }
144
+
145
+    /**
146
+     * Shows the first step.
147
+     */
148
+    public void showFirst() {
149
+        layout.first(this);
150
+    }
151
+
152
+    /**
153
+     * Shows the last step.
154
+     */
155
+    public void showLast() {
156
+        layout.last(this);
157
+    }
158
+
159
+    /**
160
+     * Shows the next step.
161
+     */
162
+    public void nextStep() {
163
+        layout.next(this);
164
+    }
165
+
166
+    /**
167
+     * Shows the previous step.
168
+     */
169
+    public void previousStep() {
170
+        layout.previous(this);
171
+    }
172
+
173
+    /**
174
+     * Shows the specified step.
175
+     * 
176
+     * @param step Step index
177
+     */
178
+    public void showStep(final int step) {
179
+        layout.show(step, this);
180
+    }
181
+}

Carregando…
Cancelar
Salvar