1 7 package java.awt; 8 9 import java.awt.peer.FileDialogPeer; 10 import java.io.FilenameFilter ; 11 import java.io.IOException ; 12 import java.io.ObjectInputStream ; 13 14 30 public class FileDialog extends Dialog { 31 32 36 public static final int LOAD = 0; 37 38 42 public static final int SAVE = 1; 43 44 56 int mode; 57 58 66 String dir; 67 68 77 String file; 78 79 90 FilenameFilter filter; 91 92 private static final String base = "filedlg"; 93 private static int nameCounter = 0; 94 95 98 private static final long serialVersionUID = 5035145889651310422L; 99 100 101 static { 102 103 Toolkit.loadLibraries(); 104 if (!GraphicsEnvironment.isHeadless()) { 105 initIDs(); 106 } 107 } 108 109 113 private static native void initIDs(); 114 115 123 public FileDialog(Frame parent) { 124 this(parent, "", LOAD); 125 } 126 127 136 public FileDialog(Frame parent, String title) { 137 this(parent, title, LOAD); 138 } 139 140 159 public FileDialog(Frame parent, String title, int mode) { 160 super(parent, title, true); 161 this.setMode(mode); 162 setLayout(null); 163 } 164 165 181 public FileDialog(Dialog parent) { 182 this(parent, "", LOAD); 183 } 184 185 205 public FileDialog(Dialog parent, String title) { 206 this(parent, title, LOAD); 207 } 208 209 239 public FileDialog(Dialog parent, String title, int mode) { 240 super(parent, title, true); 241 this.setMode(mode); 242 setLayout(null); 243 } 244 245 249 String constructComponentName() { 250 synchronized (getClass()) { 251 return base + nameCounter++; 252 } 253 } 254 255 259 public void addNotify() { 260 synchronized(getTreeLock()) { 261 if (parent != null && parent.getPeer() == null) { 262 parent.addNotify(); 263 } 264 if (peer == null) 265 peer = getToolkit().createFileDialog(this); 266 super.addNotify(); 267 } 268 } 269 270 281 public int getMode() { 282 return mode; 283 } 284 285 300 public void setMode(int mode) { 301 switch (mode) { 302 case LOAD: 303 case SAVE: 304 this.mode = mode; 305 break; 306 default: 307 throw new IllegalArgumentException ("illegal file dialog mode"); 308 } 309 } 310 311 318 public String getDirectory() { 319 return dir; 320 } 321 322 336 public void setDirectory(String dir) { 337 this.dir = (dir != null && dir.equals("")) ? null : dir; 338 FileDialogPeer peer = (FileDialogPeer)this.peer; 339 if (peer != null) { 340 peer.setDirectory(this.dir); 341 } 342 } 343 344 352 public String getFile() { 353 return file; 354 } 355 356 368 public void setFile(String file) { 369 this.file = (file != null && file.equals("")) ? null : file; 370 FileDialogPeer peer = (FileDialogPeer)this.peer; 371 if (peer != null) { 372 peer.setFile(this.file); 373 } 374 } 375 376 386 public FilenameFilter getFilenameFilter() { 387 return filter; 388 } 389 390 400 public synchronized void setFilenameFilter(FilenameFilter filter) { 401 this.filter = filter; 402 FileDialogPeer peer = (FileDialogPeer)this.peer; 403 if (peer != null) { 404 peer.setFilenameFilter(filter); 405 } 406 } 407 408 416 private void readObject(ObjectInputStream s) 417 throws ClassNotFoundException , IOException 418 { 419 s.defaultReadObject(); 420 421 if (dir != null && dir.equals("")) { 423 dir = null; 424 } 425 if (file != null && file.equals("")) { 426 file = null; 427 } 428 } 429 430 439 protected String paramString() { 440 String str = super.paramString(); 441 str += ",dir= " + dir; 442 str += ",file= " + file; 443 return str + ((mode == LOAD) ? ",load" : ",save"); 444 } 445 446 boolean postsOldMouseEvents() { 447 return false; 448 } 449 } 450 | Popular Tags |