home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / java / awt / FileDialog.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  4.2 KB  |  161 lines

  1. /*
  2.  * @(#)FileDialog.java    1.15 96/01/18 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1995-1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.FileDialogPeer;
  22. import java.io.FilenameFilter;
  23.  
  24. /**
  25.  * The File Dialog class displays a file selection dialog. It is a
  26.  * modal dialog and will block the calling thread when the show method
  27.  * is called to display it, until the user has chosen a file.
  28.  *
  29.  * @see Window#show
  30.  *
  31.  * @version     1.15, 01/18/96
  32.  * @author     Sami Shaio
  33.  * @author     Arthur van Hoff
  34.  */
  35. public class FileDialog extends Dialog {
  36.     
  37.     /**
  38.      * The file load variable.
  39.      */
  40.     public static final int LOAD = 0;
  41.  
  42.     /**
  43.      * The file save variable.
  44.      */
  45.     public static final int SAVE = 1;
  46.  
  47.     int mode;
  48.     String dir;
  49.     String file;
  50.     FilenameFilter filter;
  51.  
  52.     /**
  53.      * Creates a file dialog for loading a file.
  54.      * @param parent the owner of the dialog
  55.      * @param title the title of the Dialog
  56.      */
  57.     public FileDialog(Frame parent, String title) {
  58.     this(parent, title, LOAD);
  59.     }
  60.  
  61.     /**
  62.      * Creates a file dialog with the specified title and mode.
  63.      * @param parent the owner of the dialog
  64.      * @param title the title of the Dialog
  65.      * @param mode the mode of the Dialog
  66.      */
  67.     public FileDialog(Frame parent, String title, int mode) {
  68.     super(parent, title, true);
  69.     SecurityManager security = System.getSecurityManager();
  70.     if (security != null) {
  71.         security.checkFileDialog();
  72.     }
  73.     this.mode = mode;
  74.     setLayout(null);
  75.     }
  76.  
  77.     /**
  78.      * Creates the frame's peer.  The peer allows us to change the look
  79.      * of the file dialog without changing its functionality.
  80.      */
  81.     public synchronized void addNotify() {
  82.     peer = getToolkit().createFileDialog(this);
  83.     super.addNotify();
  84.     }
  85.  
  86.     /**
  87.      * Gets the mode of the file dialog.
  88.      */
  89.     public int getMode() {
  90.     return mode;
  91.     }
  92.  
  93.     /**
  94.      * Gets the directory of the Dialog.
  95.      */
  96.     public String getDirectory() {
  97.     return dir;
  98.     }
  99.  
  100.     /**
  101.      * Set the directory of the Dialog to the specified directory.
  102.      * @param dir the specific directory
  103.      */
  104.     public void setDirectory(String dir) {
  105.     this.dir = dir;
  106.     if (peer != null) {
  107.         ((FileDialogPeer)peer).setDirectory(dir);
  108.     }
  109.     }
  110.  
  111.     /**
  112.      * Gets the file of the Dialog.
  113.      */
  114.     public String getFile() {
  115.     return file;
  116.     }
  117.  
  118.     /**
  119.      * Sets the file for this dialog to the specified file. This will 
  120.      * become the default file if set before the dialog is shown.
  121.      * @param file the file being set
  122.      */
  123.     public void setFile(String file) {
  124.     this.file = file;
  125.     if (peer != null) {
  126.         ((FileDialogPeer)peer).setFile(file);
  127.     }
  128.     }
  129.     
  130.     /**
  131.      * Gets the filter.
  132.      */
  133.     public FilenameFilter getFilenameFilter() {
  134.     return filter;
  135.     }
  136.  
  137.     /**
  138.      * Sets the filter for this dialog to the specified filter.
  139.      * @param filter the specified filter
  140.      */
  141.     public void setFilenameFilter(FilenameFilter filter) {
  142.     this.filter = filter;
  143.     FileDialogPeer peer = (FileDialogPeer)this.peer;
  144.     if (peer != null) {
  145.         peer.setFilenameFilter(filter);
  146.     }
  147.     }
  148.  
  149.     /**
  150.      * Returns the parameter String of this file dialog.
  151.      * Parameter String.
  152.      */
  153.     protected String paramString() {
  154.     String str = super.paramString();
  155.     if (dir != null) {
  156.         str += ",dir= " + dir;
  157.     }
  158.     return str + ((mode == LOAD) ? ",load" : ",save");
  159.     }
  160. }
  161.