src/java.desktop/share/classes/java/awt/FileDialog.java
author darcy
Tue, 24 Sep 2019 18:25:54 -0700
changeset 58309 c6f8b2c3dc66
parent 54871 c2e4aef5edf2
permissions -rw-r--r--
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54871
c2e4aef5edf2 8223237: Replace use of string.equals("") with isEmpty() in java.desktop
serb
parents: 52248
diff changeset
     2
 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4913
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4913
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4913
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4913
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4913
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.FileDialogPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.FilenameFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectInputStream;
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
    31
import java.io.File;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
    32
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    35
 * The {@code FileDialog} class displays a dialog window
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * from which the user can select a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Since it is a modal dialog, when the application calls
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    39
 * its {@code show} method to display the dialog,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * it blocks the rest of the application until the user has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * chosen a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see Window#show
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author      Arthur van Hoff
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21957
diff changeset
    47
 * @since       1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class FileDialog extends Dialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * This constant value indicates that the purpose of the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * dialog window is to locate a file from which to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final int LOAD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * This constant value indicates that the purpose of the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * dialog window is to locate a file to which to write.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static final int SAVE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /*
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    64
     * There are two {@code FileDialog} modes: {@code LOAD} and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    65
     * {@code SAVE}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * This integer will represent one or the other.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    67
     * If the mode is not specified it will default to {@code LOAD}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @see getMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @see setMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @see java.awt.FileDialog#LOAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @see java.awt.FileDialog#SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * The string specifying the directory to display
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    79
     * in the file dialog.  This variable may be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @see getDirectory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see setDirectory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    String dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * The string specifying the initial value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * filename text field in the file dialog.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
    90
     * This variable may be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see getFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see setFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    String file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
    98
    /**
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
    99
     * Contains the File instances for all the files that the user selects.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   100
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   101
     * @serial
7242
6e0aa78a24f6 6953894: docs build reports warning in java.awt.FileDialog
dcherepanov
parents: 5506
diff changeset
   102
     * @see #getFiles
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   103
     * @since 1.7
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   104
     */
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   105
    private File[] files;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   106
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   107
    /**
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   108
     * Represents whether the file dialog allows the multiple file selection.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   109
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   110
     * @serial
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   111
     * @see #setMultipleMode
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   112
     * @see #isMultipleMode
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   113
     * @since 1.7
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   114
     */
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   115
    private boolean multipleMode = false;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   116
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The filter used as the file dialog's filename filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * The file dialog will only be displaying files whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * names are accepted by this filter.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   121
     * This variable may be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see #getFilenameFilter()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see #setFilenameFilter()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see FileNameFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 54871
diff changeset
   128
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    FilenameFilter filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private static final String base = "filedlg";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     private static final long serialVersionUID = 5035145889651310422L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   148
    static {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   149
        AWTAccessor.setFileDialogAccessor(
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   150
            new AWTAccessor.FileDialogAccessor() {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   151
                public void setFiles(FileDialog fileDialog, File[] files) {
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   152
                    fileDialog.setFiles(files);
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   153
                }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   154
                public void setFile(FileDialog fileDialog, String file) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   155
                    fileDialog.file = ("".equals(file)) ? null : file;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   156
                }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   157
                public void setDirectory(FileDialog fileDialog, String directory) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   158
                    fileDialog.dir = ("".equals(directory)) ? null : directory;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   159
                }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   160
                public boolean isMultipleMode(FileDialog fileDialog) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   161
                    synchronized (fileDialog.getObjectLock()) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   162
                        return fileDialog.multipleMode;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   163
                    }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   164
                }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   165
            });
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   166
    }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   167
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
       accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Creates a file dialog for loading a file.  The title of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * file dialog is initially empty.  This is a convenience method for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   177
     * {@code FileDialog(parent, "", LOAD)}.
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   178
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   179
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   180
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   181
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   182
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   183
     * displayed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param parent the owner of the dialog
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21957
diff changeset
   186
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public FileDialog(Frame parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        this(parent, "", LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Creates a file dialog window with the specified title for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * a file. The files shown are those in the current directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * This is a convenience method for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   196
     * {@code FileDialog(parent, title, LOAD)}.
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   197
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   198
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   199
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   200
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   201
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   202
     * displayed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param     parent   the owner of the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param     title    the title of the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public FileDialog(Frame parent, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        this(parent, title, LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Creates a file dialog window with the specified title for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * or saving a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   215
     * If the value of {@code mode} is {@code LOAD}, then the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * file dialog is finding a file to read, and the files shown are those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * in the current directory.   If the value of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   218
     * {@code mode} is {@code SAVE}, the file dialog is finding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * a place to write a file.
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   220
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   221
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   222
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   223
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   224
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   225
     * displayed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param     parent   the owner of the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param     title   the title of the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param     mode   the mode of the dialog; either
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   230
     *            {@code FileDialog.LOAD} or {@code FileDialog.SAVE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @exception  IllegalArgumentException if an illegal file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *                 dialog mode is supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see       java.awt.FileDialog#LOAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see       java.awt.FileDialog#SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public FileDialog(Frame parent, String title, int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        super(parent, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        this.setMode(mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Creates a file dialog for loading a file.  The title of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * file dialog is initially empty.  This is a convenience method for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   245
     * {@code FileDialog(parent, "", LOAD)}.
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   246
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   247
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   248
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   249
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   250
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   251
     * displayed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param     parent   the owner of the dialog
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   254
     * @exception java.lang.IllegalArgumentException if the {@code parent}'s
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   255
     *            {@code GraphicsConfiguration}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *            is not from a screen device;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   257
     * @exception java.lang.IllegalArgumentException if {@code parent}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   258
     *            is {@code null}; this exception is always thrown when
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   259
     *            {@code GraphicsEnvironment.isHeadless}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   260
     *            returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public FileDialog(Dialog parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        this(parent, "", LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Creates a file dialog window with the specified title for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * a file. The files shown are those in the current directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * This is a convenience method for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   272
     * {@code FileDialog(parent, title, LOAD)}.
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   273
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   274
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   275
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   276
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   277
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   278
     * displayed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param     parent   the owner of the dialog
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   281
     * @param     title    the title of the dialog; a {@code null} value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *                     will be accepted without causing a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   283
     *                     {@code NullPointerException} to be thrown
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   284
     * @exception java.lang.IllegalArgumentException if the {@code parent}'s
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   285
     *            {@code GraphicsConfiguration}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *            is not from a screen device;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   287
     * @exception java.lang.IllegalArgumentException if {@code parent}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   288
     *            is {@code null}; this exception is always thrown when
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   289
     *            {@code GraphicsEnvironment.isHeadless}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   290
     *            returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public FileDialog(Dialog parent, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        this(parent, title, LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Creates a file dialog window with the specified title for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * or saving a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   302
     * If the value of {@code mode} is {@code LOAD}, then the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * file dialog is finding a file to read, and the files shown are those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * in the current directory.   If the value of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   305
     * {@code mode} is {@code SAVE}, the file dialog is finding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * a place to write a file.
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   307
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   308
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   309
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   310
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   311
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   312
     * displayed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param     parent   the owner of the dialog
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   315
     * @param     title    the title of the dialog; a {@code null} value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *                     will be accepted without causing a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   317
     *                     {@code NullPointerException} to be thrown
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param     mode     the mode of the dialog; either
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   319
     *                     {@code FileDialog.LOAD} or {@code FileDialog.SAVE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @exception java.lang.IllegalArgumentException if an illegal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *            file dialog mode is supplied;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   322
     * @exception java.lang.IllegalArgumentException if the {@code parent}'s
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   323
     *            {@code GraphicsConfiguration}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *            is not from a screen device;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   325
     * @exception java.lang.IllegalArgumentException if {@code parent}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   326
     *            is {@code null}; this exception is always thrown when
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   327
     *            {@code GraphicsEnvironment.isHeadless}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   328
     *            returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see       java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see       java.awt.FileDialog#LOAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @see       java.awt.FileDialog#SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public FileDialog(Dialog parent, String title, int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        super(parent, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        this.setMode(mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
33246
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   340
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   341
    /**
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   342
     * {@inheritDoc}
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   343
     * <p>
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   344
     * <strong>Note:</strong> Some platforms may not support
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   345
     * showing the user-specified title in a file dialog.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   346
     * In this situation, either no title will be displayed in the file dialog's
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   347
     * title bar or, on some systems, the file dialog's title bar will not be
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   348
     * displayed.
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   349
     */
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   350
    @Override
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   351
    public void setTitle(String title) {
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   352
        super.setTitle(title);
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   353
    }
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   354
d54eb15e19eb 8138674: Some platforms may not support showing the user-specified title in a file dialog
alexsch
parents: 30471
diff changeset
   355
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   357
     * Constructs a name for this component. Called by {@code getName()}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   358
     * when the name is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        synchronized (FileDialog.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Creates the file dialog's peer.  The peer allows us to change the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * of the file dialog without changing its functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        synchronized(getTreeLock()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   372
            if (parent != null && parent.peer == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                parent.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (peer == null)
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30469
diff changeset
   376
                peer = getComponentFactory().createFileDialog(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Indicates whether this file dialog box is for loading from a file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * or for saving to a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @return   the mode of this file dialog window, either
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   386
     *               {@code FileDialog.LOAD} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   387
     *               {@code FileDialog.SAVE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see      java.awt.FileDialog#LOAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @see      java.awt.FileDialog#SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @see      java.awt.FileDialog#setMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public int getMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   397
     * Sets the mode of the file dialog.  If {@code mode} is not
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   398
     * a legal value, an exception will be thrown and {@code mode}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * will not be set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @param      mode  the mode for this file dialog, either
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   402
     *                 {@code FileDialog.LOAD} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   403
     *                 {@code FileDialog.SAVE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see        java.awt.FileDialog#LOAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see        java.awt.FileDialog#SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @see        java.awt.FileDialog#getMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @exception  IllegalArgumentException if an illegal file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *                 dialog mode is supplied
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21957
diff changeset
   409
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public void setMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        switch (mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
          case LOAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
          case SAVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            this.mode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            throw new IllegalArgumentException("illegal file dialog mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Gets the directory of this file dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   425
     * @return  the (potentially {@code null} or invalid)
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   426
     *          directory of this {@code FileDialog}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see       java.awt.FileDialog#setDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public String getDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Sets the directory of this file dialog window to be the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   435
     * specified directory. Specifying a {@code null} or an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * invalid directory implies an implementation-defined default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * This default will not be realized, however, until the user
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   438
     * has selected a file. Until this point, {@code getDirectory()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * will return the value passed into this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Specifying "" as the directory is exactly equivalent to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   442
     * specifying {@code null} as the directory.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param     dir   the specified directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @see       java.awt.FileDialog#getDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public void setDirectory(String dir) {
54871
c2e4aef5edf2 8223237: Replace use of string.equals("") with isEmpty() in java.desktop
serb
parents: 52248
diff changeset
   448
        this.dir = (dir != null && dir.isEmpty()) ? null : dir;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        FileDialogPeer peer = (FileDialogPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            peer.setDirectory(this.dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Gets the selected file of this file dialog.  If the user
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   457
     * selected {@code CANCEL}, the returned file is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @return    the currently selected file of this file dialog window,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   460
     *                or {@code null} if none is selected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see       java.awt.FileDialog#setFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public String getFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   468
     * Returns files that the user selects.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   469
     * <p>
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   470
     * If the user cancels the file dialog,
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   471
     * then the method returns an empty array.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   472
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   473
     * @return    files that the user selects or an empty array
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   474
     *            if the user cancels the file dialog.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   475
     * @see       #setFile(String)
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   476
     * @see       #getFile
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   477
     * @since 1.7
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   478
     */
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   479
    public File[] getFiles() {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   480
        synchronized (getObjectLock()) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   481
            if (files != null) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   482
                return files.clone();
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   483
            } else {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   484
                return new File[0];
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   485
            }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   486
        }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   487
    }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   488
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   489
    /**
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   490
     * Stores the names of all the files that the user selects.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   491
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   492
     * Note that the method is private and it's intended to be used
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   493
     * by the peers through the AWTAccessor API.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   494
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   495
     * @param files     the array that contains the short names of
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   496
     *                  all the files that the user selects.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   497
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   498
     * @see #getFiles
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   499
     * @since 1.7
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   500
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   501
    private void setFiles(File[] files) {
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   502
        synchronized (getObjectLock()) {
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   503
            this.files = files;
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   504
        }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   505
    }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   506
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   507
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Sets the selected file for this file dialog window to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * specified file. This file becomes the default file if it is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * before the file dialog window is first shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <p>
20462
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   512
     * When the dialog is shown, the specified file is selected. The kind of
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   513
     * selection depends on the file existence, the dialog type, and the native
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   514
     * platform. E.g., the file could be highlighted in the file list, or a
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   515
     * file name editbox could be populated with the file name.
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   516
     * <p>
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   517
     * This method accepts either a full file path, or a file name with an
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   518
     * extension if used together with the {@code setDirectory} method.
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   519
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * Specifying "" as the file is exactly equivalent to specifying
20462
1b06fa1bb364 8000425: FileDialog documentation should be enhanced
bagiras
parents: 12653
diff changeset
   521
     * {@code null} as the file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param    file   the file being set
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   524
     * @see      #getFile
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   525
     * @see      #getFiles
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    public void setFile(String file) {
54871
c2e4aef5edf2 8223237: Replace use of string.equals("") with isEmpty() in java.desktop
serb
parents: 52248
diff changeset
   528
        this.file = (file != null && file.isEmpty()) ? null : file;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        FileDialogPeer peer = (FileDialogPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            peer.setFile(this.file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   536
     * Enables or disables multiple file selection for the file dialog.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   537
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   538
     * @param enable    if {@code true}, multiple file selection is enabled;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   539
     *                  {@code false} - disabled.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   540
     * @see #isMultipleMode
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   541
     * @since 1.7
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   542
     */
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   543
    public void setMultipleMode(boolean enable) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   544
        synchronized (getObjectLock()) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   545
            this.multipleMode = enable;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   546
        }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   547
    }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   548
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   549
    /**
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   550
     * Returns whether the file dialog allows the multiple file selection.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   551
     *
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   552
     * @return          {@code true} if the file dialog allows the multiple
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   553
     *                  file selection; {@code false} otherwise.
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   554
     * @see #setMultipleMode
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   555
     * @since 1.7
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   556
     */
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   557
    public boolean isMultipleMode() {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   558
        synchronized (getObjectLock()) {
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   559
            return multipleMode;
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   560
        }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   561
    }
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   562
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 2
diff changeset
   563
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * Determines this file dialog's filename filter. A filename filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * allows the user to specify which files appear in the file dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * window.  Filename filters do not function in Sun's reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * implementation for Microsoft Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @return    this file dialog's filename filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @see       java.io.FilenameFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see       java.awt.FileDialog#setFilenameFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public FilenameFilter getFilenameFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Sets the filename filter for this file dialog window to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * specified filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Filename filters do not function in Sun's reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * implementation for Microsoft Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @param   filter   the specified filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see     java.io.FilenameFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @see     java.awt.FileDialog#getFilenameFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public synchronized void setFilenameFilter(FilenameFilter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        this.filter = filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        FileDialogPeer peer = (FileDialogPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            peer.setFilenameFilter(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   596
     * Reads the {@code ObjectInputStream} and performs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * a backwards compatibility check by converting
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   598
     * either a {@code dir} or a {@code file}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   599
     * equal to an empty string to {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   601
     * @param s the {@code ObjectInputStream} to read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        // 1.1 Compatibility: "" is not converted to null in 1.1
54871
c2e4aef5edf2 8223237: Replace use of string.equals("") with isEmpty() in java.desktop
serb
parents: 52248
diff changeset
   609
        if (dir != null && dir.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            dir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
54871
c2e4aef5edf2 8223237: Replace use of string.equals("") with isEmpty() in java.desktop
serb
parents: 52248
diff changeset
   612
        if (file != null && file.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   618
     * Returns a string representing the state of this {@code FileDialog}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * window. This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * and the content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * implementations. The returned string may be empty but may not be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33246
diff changeset
   622
     * {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @return  the parameter string of this file dialog window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        String str = super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        str += ",dir= " + dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        str += ",file= " + file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        return str + ((mode == LOAD) ? ",load" : ",save");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    boolean postsOldMouseEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
}