KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > nodes > InstallFilterFile


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-XPL.txt"
14  */

15
16 //
17
// DESCRIPTION
18
//
19
// Peter Pilgrim
20
// Sun Jan 17 22:01:06 GMT 1999
21
//
22
// RCS HEADER ``InstallFilterFile.java''
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29

30 package ixenon.free.nodes;
31
32 import java.io.*;
33 import java.util.*;
34 import java.awt.*;
35 import java.awt.event.*;
36
37 import javax.swing.*; // for JTree
38
import javax.swing.event.*; // for events
39
import javax.swing.tree.*; // MutableTreeNode
40

41 import ixenon.free.swing.*; // for `ResetProgressBar' & `UpdateProgressBar'
42
import ixenon.free.install.*; // for FreeInstallerApplication
43

44 /**
45  * An <code>Installable</code> tree node that install files by copying
46  * using a <code>FilenameFilter</code>.
47  */

48 public class InstallFilterFile extends AbstractInstallable
49 implements Installable
50 {
51     public final static int SLEEP_TIME=50; // Sleep time
52

53     /** the source directory */
54     protected File sourceDirectory;
55     /** the target directory */
56     protected File targetDirectory;
57     /** the filename filter for copying */
58     protected FilenameFilter filenameFilter;
59     /** the permissions */
60     protected int perms;
61     
62     /**
63      * Construct a installable
64      *
65      * @param nodeName the name of the installable node
66      * @param srcDir the source directory
67      * @param destDir the target directory
68      * @param filenameFilter the filename filter object
69      */

70     public InstallFilterFile( String JavaDoc nodeName,
71              int perms,
72              String JavaDoc srcDir,
73              String JavaDoc destDir,
74              FilenameFilter filenameFilter )
75     {
76     this( nodeName, perms, new File(srcDir), new File(destDir), filenameFilter );
77     }
78     
79     /**
80      * Construct a installable
81      *
82      * @param nodeName the name of the installable node
83      * @param srcDir the source directory
84      * @param destDir the target directory
85      * @param filenameFilter the filename filter object
86      */

87     public InstallFilterFile( String JavaDoc nodeName,
88                   int perms,
89                   File sourceDir,
90                   File targetDir,
91                   FilenameFilter filenameFilter )
92     {
93     super( nodeName, null, true /*allowsChildren*/ );
94     sourceDirectory = sourceDir;
95     targetDirectory = targetDir;
96     this.filenameFilter = filenameFilter;
97     this.perms = perms;
98     }
99     
100     /**
101      * create or retrieve the visual component of the installable
102      * if one exists. Otherwise return null.
103      */

104     public Component getVisualComponent()
105     {
106     return (null);
107     }
108     
109     /**
110      * create or retrieve the configurable component of the installable
111      * if one exists. Otherwise return null object.
112      */

113     public Component getConfigurableComponent()
114     {
115     return (null);
116     }
117
118     /**
119      * method to install by copying files from the source
120      * directory to target directory
121      *
122      * @exception <code>InstallException</code> if there is an
123      * problem trying to install the entity.
124      */

125     public void install() throws InstallException
126     {
127     FreeInstallerApplication theApp =
128         FreeInstallerApplication.getInstance();
129
130     if ( !sourceDirectory.isDirectory() )
131         throw new InstallException("no such source directory:`"+sourceDirectory.getAbsolutePath()+"'" );
132
133     if ( !targetDirectory.exists() )
134         targetDirectory.mkdirs();
135
136     if ( !targetDirectory.isDirectory() )
137         throw new InstallException(
138         "no such target directory:`"+targetDirectory.getAbsolutePath()+"'" );
139
140     // Add target directory to the uninstallable
141
uninstallable.addFile( targetDirectory );
142     // Get the selected files to copy
143
int j=0;
144     String JavaDoc [] selectedFiles = sourceDirectory.list( filenameFilter );
145
146     JProgressBar pbar = theApp.getProgressFrame().getProgressBarNode();
147     JProgressBar pbarFile = theApp.getProgressFrame().getProgressBarFile();
148     int numFiles = selectedFiles.length;
149     theApp.getProgressFrame().setStatusText( getNodeName() );
150
151     // // OLD CODE: Before multi threaded protection
152
// pbar.setMinimum(0);
153
// pbar.setMaximum(numFiles);
154
// pbar.setValue(0);
155
//
156
SwingUtilities.invokeLater( new ResetProgressBar( pbar, 0, numFiles, 0 ) );
157     
158     // Install all matching regular files
159
for (j=0; j<numFiles; ++j) {
160
161         // OLD CODE: pbar.setValue(j+1);
162
SwingUtilities.invokeLater( new UpdateProgressBar( pbar, j+1 ) );
163
164         try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException JavaDoc ie) { ; }
165
166         File srcFile = new File( sourceDirectory, selectedFiles[j] );
167         if ( !srcFile.exists() ) {
168         if (pedantic)
169             throw new InstallException(
170             "["+j+"] no such matched file:`" + srcFile.getPath()+"'" );
171         else
172             theApp.printWarning( "["+j+"] no such matched file:`" + srcFile.getPath()+"'" );
173         continue;
174         }
175         if ( srcFile.isFile() ) {
176         // Only copy normal files
177
File dstFile = new File( targetDirectory, selectedFiles[j] );
178         theApp.printInfo( "["+j+"] matched copying:`" + srcFile.getPath() + "' to `" + dstFile.getPath()+"'" );
179         InstallUtilities.copyFile( pbarFile, srcFile, dstFile, true );
180         InstallUtilities.setFilePermissions( dstFile, perms );
181
182         uninstallable.addFile( dstFile );
183         }
184     }
185     }
186
187     /**
188      * method to perform the cleanup of content if cancelled, or aborted
189      */

190     public void cleanup() throws InstallException
191     {
192     // empty
193
}
194
195 }
196
197 // fini
198

199
Popular Tags