KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > install > FreeInstallerApplication


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPeL.txt"
14  */

15
16 // InstallerFrame.java
17

18 // Description:
19
// Installer frame for free installer application
20
//
21
// Author:
22
// Peter Pilgrim
23
// Mon Jan 11 23:50:46 GMT 1999
24
//
25
// RCS HEADER
26
//
27
// $Author$
28
// $Date$
29
// $Source$
30
// $Revision$ $State$ $Locker$
31
//
32
// History
33
// ================================================================================
34
// $Log$
35

36 package ixenon.free.install;
37
38 import java.awt.*;
39 import java.awt.event.*;
40 import java.beans.*;
41 import java.util.*;
42 import java.io.*;
43
44 import javax.swing.*; // for JTree
45
import javax.swing.event.*; // for TreeSelectionModel
46
import javax.swing.tree.*; // for MutableTreeNode
47

48 import sun.audio.*; // WARNING: Sun audio classes are non-standard!
49

50 import ixenon.free.util.*;
51
52
53 /**
54  * Basic free installer application implementation as a SINGLETON
55  * object
56  */

57 public class FreeInstallerApplication
58 implements PropertyChangeListener {
59
60     /** the name of the application */
61     public final static String JavaDoc APPLICATION_NAME="FreeInstaller";
62     
63     /** the name of the company */
64     public final static String JavaDoc COMPANY_NAME="Xenonsoft";
65
66     /** the credit name */
67     public final static String JavaDoc CREDITS =
68     "Designed and implemented by Peter Pilgrim.\n"+
69     "XeNoNSoFT Limited, South London, England [c] January 1999.\n"+
70     "FreeInstaller is distributed as free software under a license\n"+
71     "compatible with the open source model.\n";
72
73     /** Single audio player */
74     protected static SingleAudioPlayer audioPlayer = new SingleAudioPlayer();
75
76     protected ResourceBundle globalBundle;
77
78     /** the main installer frame GUI */
79     protected InstallerFrame mainFrame;
80
81     /** the progress installation frame GUI */
82     protected ProgressFrame progressFrame;
83
84     /** the package installer class */
85     private Class JavaDoc packageInstallerClass;
86     
87     // the package installer object
88
private PackageInstallable packageInstaller;
89
90     // the log file object
91
private LogFile logFile;
92     
93     /**
94      * internal singleton application
95      * @see #createInstance
96      * @see #getInstance
97      */

98     private static FreeInstallerApplication singleton=null;
99
100     
101
102     /** private method, because this is a SINGLETON class
103      *
104      * @param packageInstallerName the class name of the package
105      * installable object
106      * @param args the array of arguments
107      */

108     private FreeInstallerApplication( String JavaDoc packageInstallerName, String JavaDoc [] args )
109     {
110     // Print out credits
111
System.out.println( "**** "+APPLICATION_NAME+" V" + ApplicationVersion.getVersionString() + " ****");
112     System.out.println( CREDITS );
113     System.out.println( "Please read the license file. `LICENSE-XPeL.txt'\n" );
114     
115     //
116
// Create the application resources for this application
117
//
118
globalBundle = ResourceBundle.getBundle( "InstallerBundle" );
119     ApplicationResources appres =
120         ApplicationResources.createInstance( globalBundle, "FreeInstaller" );
121
122     ApplicationResources.getDefaultApplicationSearchPath(); // FIXME:
123

124     //
125
// Try to create log file
126
//
127
String JavaDoc filename = "freeinst.log";
128     try {
129         System.out.println("Creating a log file:`"+filename+"'");
130         System.out.println("os.version = "+System.getProperty("os.version"));
131         System.out.println("os.arch = "+System.getProperty("os.arch"));
132         System.out.println("os.name = "+System.getProperty("os.name"));
133         System.out.println("user.name = "+System.getProperty("user.name"));
134         System.out.println("user.home = "+System.getProperty("user.home"));
135         System.out.println("java.home = "+System.getProperty("java.home"));
136         System.out.println("java.version = "+System.getProperty("java.version"));
137         logFile = new LogFile( filename );
138         logFile.dtprintln();
139         logFile.println( "**** "+APPLICATION_NAME+" V" + ApplicationVersion.getVersionString() + " ****");
140         logFile.println( CREDITS );
141         logFile.println( "Please read the license file, \"Available as free software\".\n" );
142         logFile.println("os.version = "+System.getProperty("os.version"));
143         logFile.println("os.arch = "+System.getProperty("os.arch"));
144         logFile.println("os.name = "+System.getProperty("os.name"));
145         logFile.println("user.name = "+System.getProperty("user.name"));
146         logFile.println("user.home = "+System.getProperty("user.home"));
147         logFile.println("java.home = "+System.getProperty("java.home"));
148         logFile.println("java.version = "+System.getProperty("java.version"));
149     }
150     catch (IOException ioe) {
151         System.err.println("failured to create log filename:"+filename);
152         System.err.println("I/O Exception:"+ioe.getMessage() );
153         System.exit(3);
154     }
155
156     //
157
// Load package installer class dynamically. This enables us to
158
// have different package installers as long they implement
159
// the `PackageInstallable' interface.
160
//
161
try {
162         packageInstallerClass = Class.forName(packageInstallerName);
163     }
164     catch ( ClassNotFoundException JavaDoc ce ) {
165         writeErrorLog( APPLICATION_NAME+" cannot load class:`"+packageInstallerName+"'" );
166         System.exit(1);
167     }
168
169     try {
170         // Now create ONE package installer object
171
packageInstaller = (PackageInstallable)packageInstallerClass.newInstance();
172     }
173     catch (InstantiationException JavaDoc ie ) {
174         writeErrorLog( APPLICATION_NAME+" cannot instantiate the class:`"+packageInstallerName+"'" );
175         System.exit(1);
176         
177     }
178     catch (IllegalAccessException JavaDoc iae ) {
179         writeErrorLog( APPLICATION_NAME+" illegal access during instantiation of class:`"+packageInstallerName+"'" );
180         System.exit(1);
181     }
182     catch (ClassCastException JavaDoc cce) {
183         writeErrorLog( APPLICATION_NAME+" class cast exception for a class:`"+packageInstallerName+"'" );
184         System.exit(1);
185     }
186
187     //
188
// Print off some output, just in case!
189
//
190
System.out.println( "Successfully loaded package installer:`"+packageInstallerName+"'" );
191     System.out.println( "Company Name: " + getCompanyName() );
192     System.out.println( "Product Name: " + getProductName() );
193     logFile.dtprintln( "Successfully loaded package installer:`"+packageInstallerName+"'" );
194     logFile.dtprintln( " + Company Name: " + getCompanyLongName() );
195     logFile.dtprintln( " + Product Name: " + getProductLongName() );
196
197     //
198
// Get the application resources
199
//
200
String JavaDoc mainTitle = appres.getResourceString( "mainFrame.title", "FreeInstaller from XeNoN" );
201     mainTitle += " V" + ApplicationVersion.getVersionString()+" ( "+getProductName() + " )";
202     
203     String JavaDoc welcomeAudioClip = appres.getResourceString( "welcome.audioClip", "appres/audio/welcome-reverb.au" );
204     String JavaDoc temp = appres.resolvePathname( "audio", welcomeAudioClip, null );
205     if (temp != null) welcomeAudioClip=temp;
206
207     //
208
// WARNING: COMPLIANCE WITH THE LICENSE
209
// Show the default splash image
210
//
211
SplashScreen2.showSplash( 9950, "default.splashImage", "appres/docs/images/FreeInstaller.jpg" );
212     
213     try {
214         AudioStream audioStream =
215         new AudioStream( new FileInputStream( welcomeAudioClip ));
216         AudioData audioData = audioStream.getData();
217         if (audioData != null)
218         getAudioPlayer().play( audioData );
219         Thread.sleep(1000);
220     }
221     catch (IOException ioe) {
222     }
223     catch (InterruptedException JavaDoc ie) {
224     }
225
226     //
227
// Create the installer frame GUI and progress frame GUI
228
// and centre them both on the screen.
229
//
230
mainFrame =
231         new InstallerFrame(
232         mainTitle, "appres/images/M16Crop.jpg",
233         getCompanyName(), getProductName() );
234
235     mainFrame.addPropertyChangeListener(this);
236     mainFrame.pack();
237     mainFrame.setVisible(true);
238
239     String JavaDoc progressTitle =
240         appres.getResourceString( "progessFrame.title", "Installation Progress" );
241     progressFrame = new ProgressFrame( progressTitle );
242     progressFrame.pack();
243     progressFrame.setVisible(false);
244
245     }
246     
247     /**
248      * get the application free installer instance or creates singleton
249      * if it did not exist.
250      *
251      * @param pkgInstName the class name of the package
252      * installable object
253      * @param args the array of arguments
254      */

255     public static FreeInstallerApplication createInstance(
256     String JavaDoc pkgInstName,
257     String JavaDoc [] args )
258     {
259     // Only one object can be created.
260
if (singleton == null)
261         singleton = new FreeInstallerApplication( pkgInstName, args );
262     return (singleton);
263     }
264
265     /** Retrieves the singleton instance: there can only be one
266      * application resource per program.
267      *
268      * @return the singleton application resources.
269      */

270     public static FreeInstallerApplication getInstance()
271     {
272     // Only one object can be created.
273
if (singleton == null)
274         throw new NullPointerException JavaDoc( "no singleton was ever created!" );
275     return (singleton);
276     }
277
278     /** returns the main frame instance */
279     public InstallerFrame getMainFrame()
280     {
281     return (mainFrame);
282     }
283     
284     /** returns the progress frame instance */
285     public ProgressFrame getProgressFrame()
286     {
287     return (progressFrame);
288     }
289     
290     /** print information message convenience method to progress frame */
291     public void printInfo( String JavaDoc msg )
292     {
293     getProgressFrame().printInfo(msg);
294     logFile.dtprintln( msg );
295     }
296     
297     /** print warning message convenience method to progress frame */
298     public void printWarning( String JavaDoc msg )
299     {
300     getProgressFrame().printWarning(msg);
301     logFile.dtprintln( msg );
302    }
303     
304     /** print error message convenience method to progress frame */
305     public void printError( String JavaDoc msg )
306     {
307     getProgressFrame().printError(msg);
308     logFile.dtprintln( msg );
309     }
310
311     /** returns the global resource bundle for application */
312     public ResourceBundle getResourceBundle()
313     {
314     return (globalBundle);
315     }
316
317     /** the property change listener */
318     public void propertyChange( PropertyChangeEvent e )
319     {
320     String JavaDoc propertyName = e.getPropertyName();
321     // System.out.println("DEBUG: property name = "+propertyName );
322

323     if (propertyName.equals(InstallerFrame.QUIT_BUTTON_PRESSED_PROPERTY )) {
324         System.out.println( APPLICATION_NAME+" goodbye." );
325         System.exit(0);
326     }
327     else if (propertyName.equals(InstallerFrame.INSTALL_BUTTON_PRESSED_PROPERTY )) {
328         // Begin installation of this package. But first we must
329
// show the progress frame GUI and hide the main frame
330
// GUI.
331
//
332
// PLEASE NOTE: The package installer is now responsible
333
// for showing the progress frame GUI.
334
//
335
// progressFrame.setVisible(true);
336
mainFrame.setVisible(false);
337         
338         packageInstaller.installPackage();
339     }
340     }
341     
342     /** a convenience method that returns the company name from the package installable */
343     public String JavaDoc getCompanyName()
344     {
345     return packageInstaller.getCompanyName();
346     }
347     
348     /** a convenience method that returns the product name from the package installable */
349     public String JavaDoc getProductName()
350     {
351     return packageInstaller.getProductName();
352     }
353     
354     /** a convenience method that returns the company long name
355      * from the package installable */

356     public String JavaDoc getCompanyLongName()
357     {
358     return packageInstaller.getCompanyLongName();
359     }
360     
361     /** a convenience method that returns the product long name
362      * from the package installable */

363     public String JavaDoc getProductLongName()
364     {
365     return packageInstaller.getProductLongName();
366     }
367
368     /** returns the log file object */
369     public LogFile getLogFile()
370     {
371     return (logFile);
372     }
373
374     /** a convenience method that writes a text string to the log file object */
375     public void writeLog( String JavaDoc text )
376     {
377     logFile.dtprintln( text );
378     }
379
380     /** Returns a reference to the single audio player object */
381     public SingleAudioPlayer getAudioPlayer()
382     {
383     return audioPlayer;
384     }
385     
386     /** a convenience method that writes a text string to the log file */
387     public void writeErrorLog( String JavaDoc text )
388     {
389     System.err.println( text );
390     logFile.dtprintln( text );
391     }
392 }
393
394 // fini
395
Popular Tags