home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / FileChooser.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.9 KB  |  110 lines  |  [TEXT/CWIE]

  1. // FileChooser.java
  2. // By Ned Etcode
  3. // Copyright 1995, 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9. /** Object subclass allowing the user to select a file.  FileChooser creates
  10.   * a a modal window, blocking the calling thread and remaining onscreen until
  11.   * the user dismisses it.
  12.   */
  13. public class FileChooser extends Object {
  14.     java.awt.FileDialog         awtDialog;
  15.     int                         type;
  16.  
  17.     /** Type used to create a FileChooser that loads files. */
  18.     public final static int     LOAD_TYPE = 0;
  19.     /** Type used to create a FileChooser that saves files. */
  20.     public final static int     SAVE_TYPE = 1;
  21.  
  22.  
  23.  
  24. /* constructors */
  25.  
  26.     /** Constructs a FileChooser associated with the RootView
  27.       * <b>rootView</b>, with title <b>title</b> and type <b>type</b>.
  28.       * @see RootView
  29.       * @see Application
  30.       */
  31.     public FileChooser(RootView rootView, String title, int type) {
  32.         int     mode;
  33.  
  34.         if (rootView == null) {
  35.             throw new InconsistencyException("No rootView for FileChooser");
  36.         }
  37.  
  38.         this.type = type;
  39.         if (type == SAVE_TYPE) {
  40.             mode = java.awt.FileDialog.SAVE;
  41.         } else {
  42.             mode = java.awt.FileDialog.LOAD;
  43.         }
  44.  
  45.         awtDialog = new java.awt.FileDialog(rootView.panel().frame(),
  46.                                             title, mode);
  47.     }
  48.  
  49. /* actions */
  50.  
  51.     /** Returns the FileChooser's type, either LOAD_TYPE or SAVE_TYPE. */
  52.     public int type() {
  53.         return type;
  54.     }
  55.  
  56.     /** Sets the FileChooser to the specified directory. */
  57.     public void setDirectory(String directory) {
  58.         awtDialog.setDirectory(directory);
  59.     }
  60.  
  61.     /** Returns the FileChooser's current directory.
  62.       * @see #setDirectory
  63.       */
  64.     public String directory() {
  65.         return awtDialog.getDirectory();
  66.     }
  67.  
  68.     /** Sets the FileChooser to the specified file. */
  69.     public void setFile(String filePath) {
  70.         awtDialog.setFile(filePath);
  71.     }
  72.  
  73.     /** Returns the FileChooser's current file.
  74.       * @see #setFile
  75.       */
  76.     public String file() {
  77.         return awtDialog.getFile();
  78.     }
  79.  
  80.     /** Sets the filename filter.
  81.       */
  82.     public void setFilenameFilter(java.io.FilenameFilter aFilter) {
  83.         awtDialog.setFilenameFilter(aFilter);
  84.     }
  85.  
  86.     /** Returns the filename filter.
  87.       * @see #setFilenameFilter
  88.       */
  89.     public java.io.FilenameFilter filenameFilter() {
  90.         return awtDialog.getFilenameFilter();
  91.     }
  92.  
  93.     /** Sets the FileChooser's Window's title. */
  94.     public void setTitle(String title) {
  95.         awtDialog.setTitle(title);
  96.     }
  97.  
  98.     /** Returns the FileChooser's Window's title.
  99.       * @see #setTitle
  100.       */
  101.     public String title() {
  102.         return awtDialog.getTitle();
  103.     }
  104.  
  105.     /** Brings the FileChooser onscreen. */
  106.     public void showModally() {
  107.         awtDialog.show();
  108.     }
  109. }
  110.