< prev index next >

src/java.desktop/share/classes/java/awt/FileDialog.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 130     private static final String base = "filedlg";
 131     private static int nameCounter = 0;
 132 
 133     /*
 134      * JDK 1.1 serialVersionUID
 135      */
 136      private static final long serialVersionUID = 5035145889651310422L;
 137 
 138 
 139     static {
 140         /* ensure that the necessary native libraries are loaded */
 141         Toolkit.loadLibraries();
 142         if (!GraphicsEnvironment.isHeadless()) {
 143             initIDs();
 144         }
 145     }
 146 
 147     static {
 148         AWTAccessor.setFileDialogAccessor(
 149             new AWTAccessor.FileDialogAccessor() {
 150                 public void setFiles(FileDialog fileDialog, File files[]) {
 151                     fileDialog.setFiles(files);
 152                 }
 153                 public void setFile(FileDialog fileDialog, String file) {
 154                     fileDialog.file = ("".equals(file)) ? null : file;
 155                 }
 156                 public void setDirectory(FileDialog fileDialog, String directory) {
 157                     fileDialog.dir = ("".equals(directory)) ? null : directory;
 158                 }
 159                 public boolean isMultipleMode(FileDialog fileDialog) {
 160                     synchronized (fileDialog.getObjectLock()) {
 161                         return fileDialog.multipleMode;
 162                     }
 163                 }
 164             });
 165     }
 166 
 167     /**
 168      * Initialize JNI field and method IDs for fields that may be
 169        accessed from C.
 170      */


 480             if (files != null) {
 481                 return files.clone();
 482             } else {
 483                 return new File[0];
 484             }
 485         }
 486     }
 487 
 488     /**
 489      * Stores the names of all the files that the user selects.
 490      *
 491      * Note that the method is private and it's intended to be used
 492      * by the peers through the AWTAccessor API.
 493      *
 494      * @param files     the array that contains the short names of
 495      *                  all the files that the user selects.
 496      *
 497      * @see #getFiles
 498      * @since 1.7
 499      */
 500     private void setFiles(File files[]) {
 501         synchronized (getObjectLock()) {
 502             this.files = files;
 503         }
 504     }
 505 
 506     /**
 507      * Sets the selected file for this file dialog window to be the
 508      * specified file. This file becomes the default file if it is set
 509      * before the file dialog window is first shown.
 510      * <p>
 511      * When the dialog is shown, the specified file is selected. The kind of
 512      * selection depends on the file existence, the dialog type, and the native
 513      * platform. E.g., the file could be highlighted in the file list, or a
 514      * file name editbox could be populated with the file name.
 515      * <p>
 516      * This method accepts either a full file path, or a file name with an
 517      * extension if used together with the {@code setDirectory} method.
 518      * <p>
 519      * Specifying "" as the file is exactly equivalent to specifying
 520      * {@code null} as the file.


   1 /*
   2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 130     private static final String base = "filedlg";
 131     private static int nameCounter = 0;
 132 
 133     /*
 134      * JDK 1.1 serialVersionUID
 135      */
 136      private static final long serialVersionUID = 5035145889651310422L;
 137 
 138 
 139     static {
 140         /* ensure that the necessary native libraries are loaded */
 141         Toolkit.loadLibraries();
 142         if (!GraphicsEnvironment.isHeadless()) {
 143             initIDs();
 144         }
 145     }
 146 
 147     static {
 148         AWTAccessor.setFileDialogAccessor(
 149             new AWTAccessor.FileDialogAccessor() {
 150                 public void setFiles(FileDialog fileDialog, File[] files) {
 151                     fileDialog.setFiles(files);
 152                 }
 153                 public void setFile(FileDialog fileDialog, String file) {
 154                     fileDialog.file = ("".equals(file)) ? null : file;
 155                 }
 156                 public void setDirectory(FileDialog fileDialog, String directory) {
 157                     fileDialog.dir = ("".equals(directory)) ? null : directory;
 158                 }
 159                 public boolean isMultipleMode(FileDialog fileDialog) {
 160                     synchronized (fileDialog.getObjectLock()) {
 161                         return fileDialog.multipleMode;
 162                     }
 163                 }
 164             });
 165     }
 166 
 167     /**
 168      * Initialize JNI field and method IDs for fields that may be
 169        accessed from C.
 170      */


 480             if (files != null) {
 481                 return files.clone();
 482             } else {
 483                 return new File[0];
 484             }
 485         }
 486     }
 487 
 488     /**
 489      * Stores the names of all the files that the user selects.
 490      *
 491      * Note that the method is private and it's intended to be used
 492      * by the peers through the AWTAccessor API.
 493      *
 494      * @param files     the array that contains the short names of
 495      *                  all the files that the user selects.
 496      *
 497      * @see #getFiles
 498      * @since 1.7
 499      */
 500     private void setFiles(File[] files) {
 501         synchronized (getObjectLock()) {
 502             this.files = files;
 503         }
 504     }
 505 
 506     /**
 507      * Sets the selected file for this file dialog window to be the
 508      * specified file. This file becomes the default file if it is set
 509      * before the file dialog window is first shown.
 510      * <p>
 511      * When the dialog is shown, the specified file is selected. The kind of
 512      * selection depends on the file existence, the dialog type, and the native
 513      * platform. E.g., the file could be highlighted in the file list, or a
 514      * file name editbox could be populated with the file name.
 515      * <p>
 516      * This method accepts either a full file path, or a file name with an
 517      * extension if used together with the {@code setDirectory} method.
 518      * <p>
 519      * Specifying "" as the file is exactly equivalent to specifying
 520      * {@code null} as the file.


< prev index next >