01: /*
02: * Project: Gulden Utilies
03: * Class: de.gulden.util.swing.InputVerifierFile
04: * Version: snapshot-beautyj-1.1
05: *
06: * Date: 2004-09-29
07: *
08: * This is a snapshot version of the Gulden Utilities,
09: * 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;
24: import javax.swing.JComponent;
25:
26: /**
27: * Class InputVerifierFile.
28: *
29: * @author Jens Gulden
30: * @version snapshot-beautyj-1.1
31: */
32: public class InputVerifierFile extends InputVerifier {
33:
34: // ------------------------------------------------------------------------
35: // --- field ---
36: // ------------------------------------------------------------------------
37:
38: /**
39: * The directory.
40: */
41: protected boolean directory;
42:
43: // ------------------------------------------------------------------------
44: // --- constructors ---
45: // ------------------------------------------------------------------------
46:
47: /**
48: * Creates a new instance of InputVerifierFile.
49: */
50: public InputVerifierFile() {
51: this (false);
52: }
53:
54: /**
55: * Creates a new instance of InputVerifierFile.
56: */
57: public InputVerifierFile(boolean directory) {
58: super ();
59: setDirectory(directory);
60: }
61:
62: // ------------------------------------------------------------------------
63: // --- methods ---
64: // ------------------------------------------------------------------------
65:
66: public boolean verify(JComponent input) {
67: // can only verify JTextComponent
68: javax.swing.text.JTextComponent textComponent = (javax.swing.text.JTextComponent) input;
69: String path = textComponent.getText().trim();
70: if (path.length() > 0) {
71: java.io.File f = new java.io.File(path);
72: try {
73: f.getCanonicalPath();
74: return true;
75: } catch (java.io.IOException ioe) {
76: return false;
77: }
78: } else { // allow empty
79: return true;
80: }
81: }
82:
83: public boolean isDirectory() {
84: return directory;
85: }
86:
87: /**
88: * Sets the directory.
89: */
90: public void setDirectory(boolean _directory) {
91: directory = _directory;
92: }
93:
94: } // end InputVerifierFile
|