1 19 20 package de.gulden.util.swing; 21 22 import java.util.*; 23 import javax.swing.InputVerifier ; 24 import javax.swing.JComponent ; 25 26 32 public class InputVerifierFile extends InputVerifier { 33 34 38 41 protected boolean directory; 42 43 44 48 51 public InputVerifierFile() { 52 this(false); 53 } 54 55 58 public InputVerifierFile(boolean directory) { 59 super(); 60 setDirectory(directory); 61 } 62 63 64 68 public boolean verify(JComponent input) { 69 javax.swing.text.JTextComponent textComponent=(javax.swing.text.JTextComponent )input; 71 String path=textComponent.getText().trim(); 72 if (path.length()>0) { 73 java.io.File f=new java.io.File (path); 74 try { 75 f.getCanonicalPath(); 76 return true; 77 } catch (java.io.IOException ioe) { 78 return false; 79 } 80 } else { return true; 82 } 83 } 84 85 public boolean isDirectory() { 86 return directory; 87 } 88 89 92 public void setDirectory(boolean _directory) { 93 directory = _directory; 94 } 95 96 } | Popular Tags |