KickJava   Java API By Example, From Geeks To Geeks.

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


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 //
17
// DESCRIPTION
18
//
19
// Peter Pilgrim
20
// Sun Jan 17 22:01:06 GMT 1999
21
//
22
// RCS HEADER ``BasicInstaller.java''
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29

30 package ixenon.free.install;
31
32 import java.awt.*;
33 import java.awt.event.*;
34 import java.beans.*;
35 import java.util.*;
36 import java.io.*;
37
38 import javax.swing.*; // for JTree
39
import javax.swing.event.*; // for TreeSelectionModel
40
import javax.swing.border.*; // for EmptyBorder
41

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

44 import ixenon.free.util.*; // for ApplicationResources
45
import ixenon.free.swing.*; // for PagerDialog, Pager
46
import ixenon.free.nodes.*; // for InstallMultipleFile, InstallException
47
import ixenon.free.uninstall.*; // for DefaultUninstaller
48

49 // HINT: UNCOMMENT THE NEXT LINE FOR CUSTOM INSTALLER
50
// import ixenon.free.install.*; // for PackageInstallable
51

52 /**
53  *
54  *
55  * Here is a basic installer which installs the free installer
56  * software itself. The free installer application accepts this a
57  * class name as one of the parameters. This object class
58  * <I>`ixenon.free.install.BasicInstaller'</I> is dynamically loaded by
59  * name using <B>Class.forName()</B> method. Once the class is loaded
60  * a single object is instantiated. The software vendor company name
61  * and product name as retrieved from the object. After the operator
62  * decides to install the package by clicking the [INSTALL] on the
63  * installer frame GUI, the method <B>installPackage</B> is install.
64  * <P>
65  *
66  * The method @see #installPackage performs the entire installation.
67  * For the BasicInstaller, a tree of @see Installable objects is
68  * created. Since @see AbstractInstallable objects are subclass of
69  * @see javax.swing.tree.DefaultMutableTreeNode then the method
70  * preorderEnumeration() can be called. Thus the installation is
71  * actually performed by interating (or rather enumerating over the
72  * tree) calling the <B>install()</B> on each tree node.
73  * <P>
74  *
75  * Sun Jan 24 20:33:01 GMT 1999
76  * @author Peter Pilgrim
77  * @version $Id$
78  *
79  */

80 public class BasicInstaller
81 implements PackageInstallable, Runnable JavaDoc
82 {
83     protected FreeInstallerApplication theApp;
84     protected ApplicationResources appres;
85     
86     protected PrefixRoot prefixRoot;
87     protected File prefix;
88     protected Locale locale;
89     protected int installMode;
90     protected String JavaDoc endMessage;
91     protected DefaultUninstaller uninstaller;
92     
93     protected File currentDir;
94     protected File sourceDir;
95     protected File sourceImagesDir;
96     protected File sourceAudioDir;
97     protected File targetBinDir;
98     protected File targetLibDir;
99     protected File targetDataDir;
100     protected File targetClassesDir;
101     protected File targetImagesDir;
102     protected File targetAudioDir;
103
104
105     /** A default constructor is required because this class is
106      * instantiated dynamically with <B>java.lang.Class.forName()</B>
107      * method
108      */

109     public BasicInstaller()
110     {
111     }
112
113     /** Retrieves the company name
114      * Ideally, the name should not have spaces, thinking of UNIX
115      */

116     public String JavaDoc getCompanyName()
117     {
118     return "Xenonsoft";
119     }
120     
121     /** Retrieves the product name
122      * Ideally, the name should not have spaces, thinking of UNIX
123      */

124     public String JavaDoc getProductName()
125     {
126     return "FreeInstaller";
127     }
128  
129     /** Retrieves the long company name */
130     public String JavaDoc getCompanyLongName()
131     {
132     return "Xenonsoft, South London, England";
133     }
134     
135     /** Retrieves the long product name */
136     public String JavaDoc getProductLongName()
137     {
138     return "FreeInstaller (Example BasicInstaller) 1999";
139     }
140  
141     /** Install the software package */
142     public void installPackage()
143     {
144     theApp = FreeInstallerApplication.getInstance();
145     appres = ApplicationResources.getInstance();
146
147     String JavaDoc dlgRes = "packageInstaller.basicDialog";
148     
149     String JavaDoc cancelButtonText =
150         appres.getResourceString( dlgRes+".cancelButton.label", "Cancel" );
151     String JavaDoc approveButtonText =
152         appres.getResourceString( dlgRes+".approveButton.label", "Install" );
153     String JavaDoc prevButtonText =
154         appres.getResourceString( dlgRes+".prevButton.label", "<Back" );
155     String JavaDoc nextButtonText =
156         appres.getResourceString( dlgRes+".nextButton.label", "Next>" );
157
158     String JavaDoc exampleHtml =
159         appres.getResourceString( dlgRes+".exampleDocURL", "appres/docs/Example.html" );
160     
161     PagerDialog dialog =
162         new PagerDialog( theApp.getMainFrame(),
163                  "Pre-Installation Sheet Dialog" );
164     dialog.setCancelButtonText(cancelButtonText);
165     dialog.setApproveButtonText(approveButtonText);
166
167     Pager pager = dialog.getPagerPane();
168     pager.setPrevButtonText(prevButtonText);
169     pager.setNextButtonText(nextButtonText);
170     
171     HTMLViewerPane htmlPane = new HTMLViewerPane();
172     String JavaDoc urlPath = appres.resolvePathname( "docs", exampleHtml, null );
173     File file = new File(urlPath);
174     if ( file.exists() )
175         urlPath = "file:"+file.getAbsolutePath();
176     try {
177         htmlPane.setPage( urlPath );
178     }
179     catch (IOException ioe ) {
180         System.err.println(ioe);
181     }
182
183     // Create the installation sheet
184
createInstallationSheet();
185
186     //
187
// Create the single pane and side label for dialog pager
188
//
189
Image image = appres.getImage( "images", "appres/images/biz-logo.gif", null );
190     JLabel label = new JLabel( new ImageIcon( image ));
191     label.setPreferredSize( new Dimension( 250, 375 ));
192     label.setBorder( new EmptyBorder( 10,30,10,30 ));
193     // label.setBorder( new BevelBorder( BevelBorder.RAISED ));
194
dialog.getPagerPane().addCenterSideComponent( label, BorderLayout.WEST );
195     
196     dialog.addPage(htmlPane);
197     dialog.pack(); // !!!
198
Dimension size = new Dimension(dialog.getSize());
199     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
200     
201     if (screen.width > 1100 ) {
202         // For hires screens.
203
size.width = 950;
204         size.height = 850;
205     }
206     int x = (screen.width-size.width)/2;
207     int y = (screen.height-size.height)/2;
208     dialog.setBounds(x, y, size.width, size.height);
209     int answer = dialog.showDialog();
210     if (answer == PagerDialog.APPROVE_BUTTON ) {
211         // Start a separate thread to install the software.
212
// FIXME: May need to another method in `PackageInstallable'
213
// to customise on the type of installation ie BASIC, CUSTOM,
214
// and COMPACT
215
Thread JavaDoc t1 = new Thread JavaDoc(this);
216         t1.start();
217         theApp.getProgressFrame().setVisible(true);
218     }
219     else {
220         // The user cancel the selection. Okay be clever now:
221
// unmap the progress frame and remap the main frame
222
// again.
223
theApp.getMainFrame().setVisible(true);
224         theApp.getProgressFrame().setVisible(false);
225     }
226     }
227     
228     
229     /** Create the installation sheet of the software package */
230     protected void createInstallationSheet()
231     {
232     String JavaDoc osname = System.getProperty("os.name");
233     String JavaDoc fileSep = System.getProperty("file.separator");
234     String JavaDoc pathSep = System.getProperty("path.separator");
235     String JavaDoc userHome = System.getProperty("user.home");
236
237     final InstallerFrame mainFrame = theApp.getMainFrame();
238     
239     prefix = mainFrame.getPrefix();
240     locale = mainFrame.getLocale();
241     installMode = mainFrame.getInstallMode();
242
243     //
244
// Create the uninstaller object that knows how to write
245
// a script or executable to install the software package.
246
//
247
uninstaller = new DefaultUninstaller( prefix, "Uninstall-FreeInstaller" );
248     
249     // Source
250
currentDir = new File( System.getProperty("user.dir") );
251     sourceImagesDir =
252         InstallUtilities.createNormalizedFile( currentDir, "appres/images" );
253     sourceAudioDir =
254         InstallUtilities.createNormalizedFile( currentDir, "appres/audio" );
255
256     // Target
257
//
258
// `targetBinDir'
259
// `targetLibDir'
260
// `targetDataDir'
261
// `targetClassesDir' are NOT used by this BasicInstaller, there are
262
// purely for demonstration purpose only. Since this Package Installable
263
// just copies the source distribution avoid the `.classes' files!!
264
// *PP* Fri Mar 26 10:44:25 BST 1999
265
//
266
targetBinDir =
267         InstallUtilities.createNormalizedFile( prefix, "bin" );
268     targetLibDir =
269         InstallUtilities.createNormalizedFile( prefix, "lib" );
270     targetClassesDir =
271         InstallUtilities.createNormalizedFile( prefix, "lib/classes" );
272     targetDataDir =
273         InstallUtilities.createNormalizedFile( prefix, "lib/FreeInstaller" );
274     targetImagesDir =
275         InstallUtilities.createNormalizedFile( prefix, "appres/images" );
276     targetAudioDir =
277         InstallUtilities.createNormalizedFile( prefix, "appres/audio" );
278     
279     prefixRoot = new PrefixRoot( "top directory", prefix );
280     
281     // UNCOMMENT THE NEXT 3 LINES TO SEE WHAT IT DOES.
282
// //
283
// // Check for superuser
284
// //
285
// CheckSuperuser checker = new CheckSuperuser(
286
// "Checking for superuser permissions & access right" );
287
// prefixRoot.add(checker);
288

289     //
290
// Install a launcher
291
//
292
InstallMultipleFile installLauncher = new InstallMultipleFile(
293         "FreeInstaller launcher (shell script) ",
294         InstallConstants.INST_EXE_PERMS,
295         currentDir, prefix, "FreeInstaller" );
296     prefixRoot.add(installLauncher);
297     
298     //
299
// Install base files
300
//
301
InstallMultipleFile installBase = new InstallMultipleFile(
302         "FreeInstaller (basic) ",
303         InstallConstants.INST_RDONLY_PERMS,
304         currentDir, prefix,
305         new String JavaDoc [] { "README", "TODO", "CHANGES", "Makefile", "LICENSE-XPeL.txt" } );
306     prefixRoot.add(installBase);
307     
308     //
309
// Exercise Simple File Copier
310
//
311
SimpleCopyFile simple1 = new SimpleCopyFile(
312         "Exercise the simple file copier",
313         InstallConstants.INST_RDONLY_PERMS,
314         InstallUtilities.createNormalizedFile( currentDir, "README"),
315         InstallUtilities.createNormalizedFile( prefix, "copy_of_README" ) );
316     prefixRoot.add(simple1);
317
318     //
319
// Install properties files
320
//
321
InstallFilterFile installProperties = new InstallFilterFile(
322         "Install Properties Files",
323         InstallConstants.INST_RDONLY_PERMS,
324         currentDir, prefix,
325         new SimpleFilenameFilter(".properties") );
326     prefixRoot.add(installProperties);
327     
328     //
329
// Install Jar and Zip files
330
//
331
InstallMultipleFile installJars = new InstallMultipleFile(
332         "FreeInstaller (Java Archive) ",
333         InstallConstants.INST_RDWR_PERMS,
334         currentDir, prefix,
335         new String JavaDoc [] { "freeinst.jar" } );
336     installJars.setPedantic(false);
337     prefixRoot.add(installJars);
338
339     //
340
// Install scripts files
341
//
342
InstallFilterFile installScripts = new InstallFilterFile(
343         "Shell scripts",
344         InstallConstants.INST_RDONLY_PERMS,
345         currentDir, prefix,
346         new SimpleFilenameFilter(".sh") );
347     prefixRoot.add(installScripts);
348     
349     //
350
// Install image files
351
//
352
InstallFilterFile installImages1 = new InstallFilterFile(
353         "GIF / JPEG images (*.gif, *.jpg, *.jpeg)",
354         InstallConstants.INST_RDONLY_PERMS,
355         sourceImagesDir, targetImagesDir,
356         new SimpleFilenameFilter(
357         new String JavaDoc [] { ".gif", ".jpg", ".jpeg" } ));
358     prefixRoot.add(installImages1);
359     
360
361     InstallFilterFile installAudio1 = new InstallFilterFile(
362         "Audio files (*.au, *.wav, *.aiff)",
363         InstallConstants.INST_RDONLY_PERMS,
364         sourceAudioDir, targetAudioDir,
365         new SimpleFilenameFilter(
366         new String JavaDoc [] { ".au", ".raw", "*.wav", "*.aiff" } ));
367     prefixRoot.add(installAudio1);
368     
369     // Install web documentation
370
InstallFilterFile installDoc1 = new InstallFilterFile(
371         "Documentation (*.html, *.html, *.txt)",
372         InstallConstants.INST_RDONLY_PERMS,
373         InstallUtilities.createNormalizedFile( currentDir, "appres/docs"),
374         InstallUtilities.createNormalizedFile( prefix, "appres/docs" ),
375         new SimpleFilenameFilter(
376         new String JavaDoc [] { ".html", ".htm", ".txt", ".doc" } ));
377     prefixRoot.add(installDoc1);
378
379     InstallFilterFile installImages2 = new InstallFilterFile(
380         "Doc GIF/JPEG images (*.gif, *.jpg, *.jpeg)",
381         InstallConstants.INST_RDONLY_PERMS,
382         InstallUtilities.createNormalizedFile( currentDir, "appres/docs/images"),
383         InstallUtilities.createNormalizedFile( prefix, "appres/docs/images" ),
384         new SimpleFilenameFilter(
385         new String JavaDoc [] { ".gif", ".jpg", ".jpeg" } ));
386     prefixRoot.add(installImages2);
387
388     //
389
// Install java source files
390
//
391
InstallFilterFile installJava1 = new InstallFilterFile(
392         "Java Source Files #1",
393         InstallConstants.INST_RDONLY_PERMS,
394         InstallUtilities.createNormalizedFile( currentDir, "ixenon/free/install"),
395         InstallUtilities.createNormalizedFile( prefix, "ixenon/free/install" ),
396         new SimpleFilenameFilter(".java"));
397     prefixRoot.add(installJava1);
398
399     InstallFilterFile installJava2 = new InstallFilterFile(
400         "Java Source Files #2",
401         InstallConstants.INST_RDONLY_PERMS,
402         InstallUtilities.createNormalizedFile( currentDir, "ixenon/free/util"),
403         InstallUtilities.createNormalizedFile( prefix, "ixenon/free/util" ),
404         new SimpleFilenameFilter(".java"));
405     prefixRoot.add(installJava2);
406     
407     InstallFilterFile installJava3 = new InstallFilterFile(
408         "Java Source Files #3",
409         InstallConstants.INST_RDONLY_PERMS,
410         InstallUtilities.createNormalizedFile( currentDir,"ixenon/free/swing"),
411         InstallUtilities.createNormalizedFile( prefix, "ixenon/free/swing" ),
412         new SimpleFilenameFilter(".java"));
413     prefixRoot.add(installJava3);
414     
415     InstallFilterFile installJava4 = new InstallFilterFile(
416         "Java Source Files #4",
417         InstallConstants.INST_RDONLY_PERMS,
418         InstallUtilities.createNormalizedFile( currentDir, "ixenon/free/uninstall"),
419         InstallUtilities.createNormalizedFile( prefix, "ixenon/free/uninstall" ),
420         new SimpleFilenameFilter(".java"));
421     prefixRoot.add(installJava4);
422     
423     InstallFilterFile installJava5 = new InstallFilterFile(
424         "Java Source Files #5",
425         InstallConstants.INST_RDONLY_PERMS,
426         InstallUtilities.createNormalizedFile( currentDir, "ixenon/free/nodes"),
427         InstallUtilities.createNormalizedFile( prefix, "ixenon/free/nodes" ),
428         new SimpleFilenameFilter(".java"));
429     prefixRoot.add(installJava5);
430     
431     //
432
// Create Windows/DOS and Shell script launcher for application
433
//
434
String JavaDoc [] jarFiles1 = new String JavaDoc[3];
435     /* IN REALITY: jarFiles1[0] = targetBinDir.getAbsolutePath(); */
436     jarFiles1[0] = prefix.getAbsolutePath(); // TESTING ONLY
437
jarFiles1[1] = prefix.getAbsolutePath() + fileSep + "freeinst.jar";
438     CreateRuntimeBatch createBatch1 = new CreateRuntimeBatch(
439         "Creating Batch Launcher Scripts",
440         prefix, prefix /* IN REALITY: targetBinDir*/,
441         "FREE_INSTALLER_HOME", "FreeInstaller",
442         "ixenon.free.install.FreeInstaller" ,
443         jarFiles1 );
444     prefixRoot.add(createBatch1);
445
446     // Create a second batch script, which refers to the current
447
// directory, so that we have one to distribute with the
448
// release archive.
449
String JavaDoc [] jarFiles2 = new String JavaDoc[3];
450     jarFiles2[0] = currentDir.getAbsolutePath(); // TESTING ONLY
451
jarFiles2[1] = currentDir.getAbsolutePath() + fileSep + "freeinst.jar";
452     CreateRuntimeBatch createBatch2 = new CreateRuntimeBatch(
453         "Creating Batch Launcher Scripts for the binary distribution",
454         currentDir, currentDir,
455         "FREE_INSTALLER_HOME", "FreeInstaller",
456         "ixenon.free.install.FreeInstaller" ,
457         jarFiles2 );
458
459     // We also don't want to generate an uninstaller stub for it!!!
460
createBatch2.setGenerateUninstall(false);
461
462     prefixRoot.add(createBatch2);
463
464     //
465
// Create default property file for the environment and
466
// install it the home directory
467
//
468
String JavaDoc propFilename;
469     String JavaDoc appClassName="FreeInstaller";
470     if ( osname.startsWith("Windows 95") ||
471          osname.startsWith("Windows 98") ||
472          osname.startsWith("Windows NT") ||
473          osname.startsWith("Windows 2000") ||
474          osname.startsWith("OS/2") )
475         // e.g. C:\_FreeInstaller\FreeInstaller.properties
476
propFilename = "_"+appClassName+fileSep+appClassName+".properties";
477     else
478         // e.g. /home/peterp/.FreeInstaller/FreeInstaller.properties
479
propFilename = "."+appClassName+fileSep+appClassName+".properties";
480
481     CreateDefaultPropertyFile createProperty1 =
482         new CreateDefaultPropertyFile(
483         "Creating default properties file (#1)",
484         userHome+fileSep+propFilename,
485         prefix.getPath(), null,
486         targetImagesDir.getPath(),
487         targetAudioDir.getPath(),
488         null );
489     prefixRoot.add(createProperty1);
490
491     CreateDefaultPropertyFile createProperty2 =
492         new CreateDefaultPropertyFile(
493         "Creating default properties file (#2)",
494         new File( targetLibDir, appClassName+".properties" ).getPath(),
495         prefix.getPath(), null,
496         targetImagesDir.getPath(),
497         targetAudioDir.getPath(),
498         null );
499     prefixRoot.add(createProperty2);
500
501     endMessage =
502         "Just a message to let you know that the installation has now completed.\n"+
503         "\nVENDOR: "+ getCompanyName() +
504         "\nPRODUCT: "+ getProductName() +
505         "\n\nThe software has been installed in `"+prefix.getPath()+"'.\n"+
506         "The source distribution has been copied successfully.\n"+
507         "To uninstall the software, simply run `"+
508         uninstaller.getTargetFilename()+"'\n";
509     
510     endMessage +=
511         "Be sure to read the log file:`"+
512         theApp.getLogFile().getFilename()+"'\n"+
513         "\n*** NOTE: Please ignore the rest of this text ***\n"+
514         "You will find executables stored in `"+targetBinDir.getPath()+"'.\n"+
515         "You will find libraries stored in `"+targetLibDir.getPath()+"'.\n"+
516         "You will also find properties stored in `"+propFilename+"'.\n"+
517         "and you will also find text files in `"+targetDataDir.getPath()+"'.\n"+
518         "\n\tEnjoy\n";
519     }
520     
521     /** This is public method only by way of implementation */
522     public synchronized void run()
523     {
524     // Install the package: *WARNING* this is not the event queue
525
// thread.
526

527     final InstallerFrame mainFrame = theApp.getMainFrame();
528
529     theApp.printInfo( "Beginning installation ..." );
530     theApp.printInfo( "COMPANY:"+getCompanyName() );
531     theApp.printInfo( "PRODUCT:"+getProductName() );
532
533     theApp.printWarning( "This package installer currently ignores any installation type setting.");
534     theApp.printWarning( "This package installer currently ignores any locale setting.");
535     
536     try { Thread.sleep(3000); } catch (InterruptedException JavaDoc ie) { ; }
537
538     //
539
// The really clever bit involves enumerating over the tree of
540
// installable tree node asking each object to `install'.
541
//
542
Enumeration etor = prefixRoot.preorderEnumeration();
543     Installable installable;
544         
545     while ( etor.hasMoreElements() ) {
546         //
547
// Set the locale and the installation mode for each installable object
548
//
549
installable = (Installable)etor.nextElement();
550         installable.setLocale(locale);
551         installable.setInstallMode(installMode);
552         installable.setUninstaller(uninstaller); /* !!! */
553         
554         // Perform installation
555
try {
556         theApp.printInfo( "" );
557         theApp.printInfo( "INSTALLING: "+installable.getNodeName() );
558         installable.install();
559         }
560         catch (InstallException ie ) {
561         theApp.printError( "installation exception message: "+ie.getMessage() );
562         uninstaller.generateScript(); /*!*/
563
564         final String JavaDoc message = "**** INSTALL EXCEPTION ****\n\n" + ie.getMessage();
565         SwingUtilities.invokeLater( new Runnable JavaDoc() {
566             public void run() {
567             InstallerFrame.popupErrorDialog(
568                 mainFrame, "installExceptionDialog",
569                 "Install Exception Dialog", message );
570             System.exit(1);
571             }
572         });
573
574         // Return immediately and therefore terminate the thread,
575
// because installation failed at this point.
576
// Also avoid quirky JFC1.2 Beta exceptions as well.
577
return;
578         }
579     }
580     
581     // Ask the uninstaller to generate script and tell operator
582
// The installation completed
583
uninstaller.generateScript();
584     
585     theApp.printInfo( "" );
586     theApp.printInfo( "Installation completed." );
587
588     SwingUtilities.invokeLater( new Runnable JavaDoc() {
589         public void run() {
590         InstallerFrame.popupInfoDialog(
591             theApp.getProgressFrame(),
592             "informationDialog", "Information Dialog", endMessage );
593         // WE HALT THE PROGRAM HERE!!
594
System.exit(0);
595         }
596     });
597
598     //
599
// Play some rock music in the background to demonstrate media content
600
// You make your PackageInstallable do what ever you want.
601
// So it is possible to use, for example, Java Media Framework and
602
// MPEG or perhaps native Quicktime player if you want to.
603
//
604
// The media content I played is a set of no-name funk/rock
605
// rifs that I wrote on my Ibanez RG505 Gold Guitar and AX1G
606
// Sound FX Unit in one evening.
607
//
608
// Peter Pilgrim Thu Jan 27 11:29:30 GMT 1999
609
//
610
String JavaDoc temp;
611     String JavaDoc audioClip1 = appres.getResourceString( "BasicInstaller.audioClip1", "rock-fill.au" );
612     String JavaDoc audioClip2 = appres.getResourceString( "BasicInstaller.audioClip2", "rock-verse.au" );
613     String JavaDoc audioClip3 = appres.getResourceString( "BasicInstaller.audioClip3", "rock-frettap7.au" );
614
615     temp = appres.resolvePathname( "appres/audio", audioClip1, null );
616     if (temp != null) audioClip1=temp;
617     temp = appres.resolvePathname( "appres/audio", audioClip2, null );
618     if (temp != null) audioClip2=temp;
619     temp = appres.resolvePathname( "appres/audio", audioClip3, null );
620     if (temp != null) audioClip3=temp;
621
622     try {
623         // This is dumb ass code, basically we maintaining a list of
624
// audio file pointers in the stream to each audio clip.
625
// Trust me, it makes sense that JavaSoft wrote it this way!
626
AudioStream [] audioStream = new AudioStream[16];
627         int n=0;
628         audioStream[n++] = new AudioStream( new FileInputStream( audioClip1 ));
629         audioStream[n++] = new AudioStream( new FileInputStream( audioClip2 ));
630         audioStream[n++] = new AudioStream( new FileInputStream( audioClip2 ));
631         audioStream[n++] = new AudioStream( new FileInputStream( audioClip3 ));
632         audioStream[n++] = new AudioStream( new FileInputStream( audioClip1 ));
633         audioStream[n++] = new AudioStream( new FileInputStream( audioClip2 ));
634         audioStream[n++] = new AudioStream( new FileInputStream( audioClip2 ));
635         audioStream[n++] = new AudioStream( new FileInputStream( audioClip2 ));
636         audioStream[n++] = new AudioStream( new FileInputStream( audioClip1 ));
637         audioStream[n++] = new AudioStream( new FileInputStream( audioClip1 ));
638         audioStream[n++] = new AudioStream( new FileInputStream( audioClip2 ));
639         audioStream[n++] = new AudioStream( new FileInputStream( audioClip3 ));
640
641         // Force garbage collection now if possible
642
System.gc();
643     
644         // Create the audio stream sequence object
645
Vector v = new Vector();
646         for (int q=0; q<audioStream.length; ++q )
647         if ( audioStream[q] != null )
648             v.addElement(audioStream[q]);
649
650         AudioStreamSequence audiostream = new AudioStreamSequence(v.elements());
651         try { Thread.sleep(2500); } catch (InterruptedException JavaDoc ie) { ; }
652         theApp.getAudioPlayer().play( audiostream );
653     }
654     catch (IOException ioe) {
655     }
656
657     }
658 }
659
660 // fini
661
Popular Tags