KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > util > swing > InputVerifierFile


1 /*
2  * Project: Gulden Utilies
3  * Class: de.gulden.util.swing.InputVerifierFile
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the Gulden Utilities,
9  * it is not released as a seperate version.
10  *
11  * Note: Contains auto-generated Javadoc comments created by BeautyJ.
12  *
13  * This is licensed under the GNU Lesser General Public License (LGPL)
14  * and comes with NO WARRANTY.
15  *
16  * Author: Jens Gulden
17  * Email: amoda@jensgulden.de
18  */

19
20 package de.gulden.util.swing;
21
22 import java.util.*;
23 import javax.swing.InputVerifier JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25
26 /**
27  * Class InputVerifierFile.
28  *
29  * @author Jens Gulden
30  * @version snapshot-beautyj-1.1
31  */

32 public class InputVerifierFile extends InputVerifier JavaDoc {
33
34     // ------------------------------------------------------------------------
35
// --- field ---
36
// ------------------------------------------------------------------------
37

38     /**
39      * The directory.
40      */

41     protected boolean directory;
42
43
44     // ------------------------------------------------------------------------
45
// --- constructors ---
46
// ------------------------------------------------------------------------
47

48     /**
49      * Creates a new instance of InputVerifierFile.
50      */

51     public InputVerifierFile() {
52         this(false);
53     }
54
55     /**
56      * Creates a new instance of InputVerifierFile.
57      */

58     public InputVerifierFile(boolean directory) {
59         super();
60         setDirectory(directory);
61     }
62
63
64     // ------------------------------------------------------------------------
65
// --- methods ---
66
// ------------------------------------------------------------------------
67

68     public boolean verify(JComponent JavaDoc input) {
69         // can only verify JTextComponent
70
javax.swing.text.JTextComponent JavaDoc textComponent=(javax.swing.text.JTextComponent JavaDoc)input;
71         String JavaDoc path=textComponent.getText().trim();
72         if (path.length()>0) {
73             java.io.File JavaDoc f=new java.io.File JavaDoc(path);
74             try {
75                 f.getCanonicalPath();
76                 return true;
77             } catch (java.io.IOException JavaDoc ioe) {
78                 return false;
79             }
80         } else { // allow empty
81
return true;
82         }
83     }
84
85     public boolean isDirectory() {
86         return directory;
87     }
88
89     /**
90      * Sets the directory.
91      */

92     public void setDirectory(boolean _directory) {
93         directory = _directory;
94     }
95
96 } // end InputVerifierFile
97
Popular Tags