source: other-projects/trunk/realistic-books/packages/AntInstaller/src/org/tp23/antinstaller/Installer.java@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 7.4 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller;
17
18import java.util.List;
19import java.util.MissingResourceException;
20import java.util.ResourceBundle;
21import java.util.Vector;
22
23import org.tp23.antinstaller.input.OutputField;
24import org.tp23.antinstaller.input.ResultContainer;
25import org.tp23.antinstaller.page.Page;
26import org.tp23.antinstaller.renderer.swing.SizeConstants;
27import org.tp23.antinstaller.runtime.IfPropertyHelper;
28import org.tp23.antinstaller.runtime.VersionHelper;
29import org.tp23.antinstaller.runtime.exe.ExecuteRunnerFilter.AbortException;
30
31
32
33/**
34 * <p>Object representation of the Installer element in the config. </p>
35 * <p>This object holds the reference to all the Pages which in tern hold references
36 * to the InputFields, All the properties in the Installer element are held at this level
37 * as is the ResultContainer</p>
38 * @author Paul Hinds
39 * @version $Id: Installer.java,v 1.9 2007/01/28 08:44:41 teknopaul Exp $
40 */
41public class Installer {
42
43
44 // i18n support
45 private static ResourceBundle langPack = null;
46 static{
47 try {
48 langPack = ResourceBundle.getBundle("resources.LanguagePack");
49 } catch (MissingResourceException e) {
50 // ignore, signifies no lang packs installed
51 }
52 }
53
54 private String name;
55 private String minJavaVersion = "1.4";
56 private String ui;// permitted UI override values
57 private boolean verbose;
58 private boolean debug;
59 private String lookAndFeel;
60 private String wide;
61 private String windowIcon;
62 private String defaultImageResource;
63 private String finishButtonText = "Install";
64 private String antialiased;
65 private String loadDefaults;
66 private String version = "0.0";
67
68 private Page[] pages;
69 private ResultContainer resultContainer = new ResultContainer();
70
71 public Installer() {
72 }
73
74 public String getName() {
75 return name;
76 }
77
78 public void setName(String name) {
79 this.name = name;
80 }
81
82
83 public String getMinJavaVersion() {
84 return minJavaVersion;
85 }
86
87 public void setMinJavaVersion(String minJavaVersion) throws AbortException {
88 if(minJavaVersion != null && ! "".equals(minJavaVersion) ) {
89 VersionHelper helper = new VersionHelper();
90 if( ! helper.equalOrHigher(System.getProperty("java.version"), minJavaVersion, true) ) {
91 throw new AbortException("Incorrect Java version, installer requires: " + minJavaVersion);
92 }
93 }
94 this.minJavaVersion = minJavaVersion;
95 }
96
97 public Page[] getPages() {
98 return pages;
99 }
100
101 public void setPages(Page[] pages) {
102 this.pages = pages;
103 }
104
105 /**
106 * returns full ui attribute with spaces removed (the string is not parsed into tokens).
107 * e.g. "text,swint,swing-auto"
108 * @return
109 */
110 public String getUi() {
111 return ui;
112 }
113
114 /**
115 * Sets the ui attrribute removing any whitespace
116 * @param ui
117 */
118 public void setUi(String ui) {
119 this.ui = ui.replaceAll("\\s", "");
120 }
121
122 public boolean supportsAutoBuild(){
123 return ui != null && ui.indexOf("-auto") > -1;
124 }
125
126 public boolean isVerbose() {
127 return verbose;
128 }
129 public void setVerbose(boolean verbose) {
130 this.verbose = verbose;
131 }
132 public void setVerbose(String strVerbose) {
133 this.verbose = OutputField.isTrue(strVerbose);
134 }
135
136 public boolean isDebug() {
137 return debug;
138 }
139 public void setDebug(boolean debug) {
140 this.debug = debug;
141 }
142 public void setDebug(String strDebug) {
143 this.debug = OutputField.isTrue(strDebug);
144 }
145
146
147 public String getLookAndFeel() {
148 return lookAndFeel;
149 }
150
151 public void setLookAndFeel(String lookAndFeel) {
152 this.lookAndFeel = lookAndFeel;
153 }
154
155 public String getWindowIcon() {
156 return windowIcon;
157 }
158
159 public void setWindowIcon(String windowIcon) {
160 this.windowIcon = windowIcon;
161 }
162
163 public String getDefaultImageResource() {
164 return defaultImageResource;
165 }
166
167 public void setDefaultImageResource(String defaultImageResource) {
168 this.defaultImageResource = defaultImageResource;
169 }
170
171 public String getFinishButtonText() {
172 if(langPack != null){
173 return langPack.getString("finishButtonText");
174 }
175 return finishButtonText;
176 }
177
178 public void setFinishButtonText(String finishButtonText) {
179 this.finishButtonText = finishButtonText;
180 }
181
182 public ResultContainer getResultContainer() {
183 return resultContainer;
184 }
185
186 public String getAntialiased() {
187 return antialiased;
188 }
189
190 public void setAntialiased(String antialiased) {
191 this.antialiased = antialiased;
192 }
193
194 public String getWide() {
195 return wide;
196 }
197
198 public void setWide(String wide) {
199 try {
200 this.wide = wide;
201 parseWideValue(wide);
202 } catch (Exception e) {
203 // ignore use defaults
204 }
205 }
206 public void parseWideValue(String wide) throws NumberFormatException, StringIndexOutOfBoundsException{
207 int pageWidth = Integer.parseInt(wide.substring(0, wide.indexOf(':')));
208 int labelWidth = Integer.parseInt(wide.substring(wide.indexOf(':') + 1, wide.length()));
209 SizeConstants.PAGE_WIDTH = pageWidth;
210 SizeConstants.LABEL_WIDTH = labelWidth;
211 }
212
213 public String getLoadDefaults() {
214 return loadDefaults;
215 }
216
217 public void setLoadDefaults(String loadDefaults) {
218 this.loadDefaults = loadDefaults;
219 }
220
221 /**
222 * Returns the list of selected targets from the installer obeying
223 * page order. This method is
224 * probably only usefull after the UI screens have finished. Using prior to that
225 * bear in mind that the user in the Swing GUI can go back and reselect
226 * targets that were not selected previously.
227 * Page targets for pages that were not shown are not returned in the list
228 * @return Returns a Vector since Ant requires this for the Project class (Should be a List)
229 * @throws InstallException
230 */
231 public Vector getTargets(InstallerContext ctx){
232 Vector argsList = new Vector();
233 for (int i = 0; i < getPages().length; i++) {
234 Page page = getPages()[i];
235 List pageTargets = page.getPageTargets();
236 boolean shown = conditionalDisplay(page, ctx);
237 for (int pt = 0; pt < pageTargets.size(); pt++) {
238 Page.IndexedTarget target = (Page.IndexedTarget)pageTargets.get(pt);
239 if( ! argsList.contains(target.getTarget()) &&
240 shown){
241 argsList.add(target.getTarget());
242 }
243 }
244 List elementTargets = page.getElementTargets();
245 for (int pt = 0; pt < elementTargets.size(); pt++) {
246 Page.IndexedTarget target = (Page.IndexedTarget)elementTargets.get(pt);
247 if( ! argsList.contains(target.getTarget()) ){
248 argsList.add(target.getTarget());
249 }
250 }
251 }
252 return argsList;
253 }
254
255 /**
256 * @return boolean true if the page was to be shown
257 * @throws InstallException
258 */
259 private boolean conditionalDisplay(Page page, InstallerContext ctx){
260 try {
261 IfPropertyHelper helper = new IfPropertyHelper(ctx);
262 return helper.ifProperty(page) && helper.ifTarget(page, ctx.getInstaller().getPages());
263 } catch (InstallException e) {
264 throw new RuntimeException("ifProperty runtime exception");
265 }
266 }
267
268 public String getVersion() {
269 return version;
270 }
271
272 public void setVersion(String version) {
273 this.version = version;
274 }
275
276
277}
Note: See TracBrowser for help on using the repository browser.