jdk/src/solaris/classes/sun/awt/X11/XFileDialogPeer.java
author dcherepanov
Wed, 16 May 2012 13:15:27 +0400
changeset 12653 07d5ca30e79e
parent 7668 d4a77089c587
child 16839 d0f2e97b7359
permissions -rw-r--r--
7124337: [macosx] FileDialog fails to select multiple files Reviewed-by: anthony, swingler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2010, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.java.swing.plaf.motif.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedAction;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2458
diff changeset
    39
import sun.util.logging.PlatformLogger;
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
    40
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
class XFileDialogPeer extends XDialogPeer implements FileDialogPeer, ActionListener, ItemListener, KeyEventDispatcher, XChoicePeerListener {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2458
diff changeset
    43
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XFileDialogPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    FileDialog  target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // This variable holds value exactly the same as value of the 'target.file' variable except:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // 1) is changed to null after quit (see handleQuitButton())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // 2) keep the same value if 'target.file' is incorrect (see setFile())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // It's not clear HOW we used it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // We should think about existence of this variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    String      file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    String      dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    String      title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    int         mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    FilenameFilter  filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final int PATH_CHOICE_WIDTH = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // Seems that the purpose of this variable is cashing of 'target.file' variable in order to help method show()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // We should think about using 'target.file' instead of 'savedFile'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Perhaps, 'target.file' just more correct (see target.setFile())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    String      savedFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Holds value of the directory which was chosen before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // We use it in order to restore previously selected directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // at the time of the next showing of the file dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    String      savedDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Holds value of the system property 'user.dir'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // in order to init current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    String      userDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    Dialog      fileDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    GridBagLayout       gbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    GridBagLayout       gblButtons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    GridBagConstraints  gbc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // ************** Components in the fileDialogWindow ***************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    TextField   filterField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // This variable holds the current text of the file which user select through the navigation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // It's important that updating of this variable must be correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // since this value is used at the time of the file dialog closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Namely, we invoke target.setFile() and then user can get this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // We update this field in cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // - ITEM_STATE_CHANGED was triggered on the file list component: set to the current selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // - at the time of the 'show': set to savedFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // - at the time of the programmatically setting: set to new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    TextField   selectionField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    List        directoryList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // This is the list component which is used for the showing of the file list of the current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    List        fileList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    Panel       buttons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    Button      openButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    Button      filterButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    Button      cancelButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    Choice      pathChoice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    TextField   pathField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    Panel       pathPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    String cancelButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    String enterFileNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    String filesLabelText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    String foldersLabelText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    String pathLabelText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    String filterLabelText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    String openButtonText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    String saveButtonText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    String actionButtonText= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    void installStrings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Locale l = target.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        UIDefaults uid = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        cancelButtonText = uid.getString("FileChooser.cancelButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        enterFileNameLabelText = uid.getString("FileChooser.enterFileNameLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        filesLabelText = uid.getString("FileChooser.filesLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        foldersLabelText = uid.getString("FileChooser.foldersLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        pathLabelText = uid.getString("FileChooser.pathLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        filterLabelText = uid.getString("FileChooser.filterLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        openButtonText = uid.getString("FileChooser.openButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        saveButtonText  = uid.getString("FileChooser.saveButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    XFileDialogPeer(FileDialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        super((Dialog)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private void init(FileDialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        fileDialog = target; //new Dialog(target, target.getTitle(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        this.title = target.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.mode = target.getMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        this.filter = target.getFilenameFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        savedFile = target.getFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        savedDir = target.getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // Shouldn't save 'user.dir' to 'savedDir'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // since getDirectory() will be incorrect after handleCancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        userDir = (String)AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    return System.getProperty("user.dir");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        installStrings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        gbl = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        gblButtons = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        gbc = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        fileDialog.setLayout(gbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // create components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        buttons = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        buttons.setLayout(gblButtons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        actionButtonText = (target.getMode() == FileDialog.SAVE) ? saveButtonText : openButtonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        openButton = new Button(actionButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        filterButton = new Button(filterLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        cancelButton = new Button(cancelButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        directoryList = new List();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        fileList = new List();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        filterField = new TextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        selectionField = new TextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   175
        boolean isMultipleMode =
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   176
            AWTAccessor.getFileDialogAccessor().isMultipleMode(target);
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   177
        fileList.setMultipleMode(isMultipleMode);
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   178
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // the insets used by the components in the fileDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        Insets noInset = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        Insets textFieldInset = new Insets(0, 8, 0, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        Insets leftListInset = new Insets(0, 8, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Insets rightListInset = new Insets(0, 4, 0, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        Insets separatorInset = new Insets(8, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Insets labelInset = new Insets(0, 8, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Insets buttonsInset = new Insets(10, 8, 10, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // add components to GridBagLayout "gbl"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        Font f = new Font(Font.DIALOG, Font.PLAIN, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Label label = new Label(pathLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        label.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        addComponent(label, gbl, gbc, 0, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                     1, 0, GridBagConstraints.NONE, labelInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // Fixed 6260650: FileDialog.getDirectory() does not return null when file dialog is cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // After showing we should display 'user.dir' as current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // if user didn't set directory programatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        pathField = new TextField(savedDir != null ? savedDir : userDir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        pathChoice = new Choice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    return new Dimension(PATH_CHOICE_WIDTH, pathField.getPreferredSize().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        pathPanel = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        pathPanel.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        pathPanel.add(pathField,BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        pathPanel.add(pathChoice,BorderLayout.EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        //addComponent(pathField, gbl, gbc, 0, 1, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        //             GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        //             1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        //addComponent(pathChoice, gbl, gbc, 1, 1, GridBagConstraints.RELATIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         //            GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
          //           1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        addComponent(pathPanel, gbl, gbc, 0, 1, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                   1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        label = new Label(filterLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        label.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        addComponent(label, gbl, gbc, 0, 2, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                     1, 0, GridBagConstraints.NONE, labelInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        addComponent(filterField, gbl, gbc, 0, 3, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                     1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        label = new Label(foldersLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        label.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        addComponent(label, gbl, gbc, 0, 4, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                     1, 0, GridBagConstraints.NONE, labelInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        label = new Label(filesLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        label.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        addComponent(label, gbl, gbc, 1, 4, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                     1, 0, GridBagConstraints.NONE, labelInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        addComponent(directoryList, gbl, gbc, 0, 5, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                     1, 1, GridBagConstraints.BOTH, leftListInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        addComponent(fileList, gbl, gbc, 1, 5, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                     1, 1, GridBagConstraints.BOTH, rightListInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        label = new Label(enterFileNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        label.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        addComponent(label, gbl, gbc, 0, 6, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                     1, 0, GridBagConstraints.NONE, labelInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        addComponent(selectionField, gbl, gbc, 0, 7, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                     1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        addComponent(new Separator(fileDialog.size().width, 2, Separator.HORIZONTAL), gbl, gbc, 0, 8, 15,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                     1, 0, GridBagConstraints.HORIZONTAL, separatorInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // add buttons to GridBagLayout Buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        addComponent(openButton, gblButtons, gbc, 0, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                     GridBagConstraints.WEST, (Container)buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                     1, 0, GridBagConstraints.NONE, noInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        addComponent(filterButton, gblButtons, gbc, 1, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                     GridBagConstraints.CENTER, (Container)buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                     1, 0, GridBagConstraints.NONE, noInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        addComponent(cancelButton, gblButtons, gbc, 2, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                     GridBagConstraints.EAST, (Container)buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                     1, 0, GridBagConstraints.NONE, noInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // add ButtonPanel to the GridBagLayout of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        addComponent(buttons, gbl, gbc, 0, 9, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                     GridBagConstraints.WEST, (Container)fileDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                     1, 0, GridBagConstraints.HORIZONTAL, buttonsInset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        fileDialog.setSize(400, 400);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // Update choice's popup width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        choicePeer.setDrawSelectedItem(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        choicePeer.setAlignUnder(pathField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        filterField.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        selectionField.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        directoryList.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        directoryList.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        fileList.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        fileList.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        openButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        filterButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        cancelButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        pathChoice.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        pathField.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // b6227750 FileDialog is not disposed when clicking the 'close' (X) button on the top right corner, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        target.addWindowListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            new WindowAdapter(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                public void windowClosing(WindowEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    handleCancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // 6259434 PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        pathChoice.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public void updateIconImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (winAttr.icons == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            winAttr.iconsInherited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            winAttr.icons = getDefaultIconInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            setIconHints(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * add Component comp to the container cont.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * add the component to the correct GridBagLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    void addComponent(Component comp, GridBagLayout gb, GridBagConstraints c, int gridx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                      int gridy, int gridwidth, int anchor, Container cont, int weightx, int weighty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                      int fill, Insets in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        c.gridx = gridx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        c.gridy = gridy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        c.gridwidth = gridwidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        c.anchor = anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        c.weightx = weightx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        c.weighty = weighty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        c.fill = fill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        c.insets = in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        gb.setConstraints(comp, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        cont.add(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * get fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    String getFileName(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int index = str.lastIndexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return str.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /** handleFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    void handleFilter(String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        setFilterEntry(dir,f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // Fixed within 6259434: PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        // Here we restoring Motif behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        directoryList.select(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (fileList.getItemCount() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            fileList.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            directoryList.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * handle the selection event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    void handleSelection(String file) {
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   388
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   389
        int index = file.lastIndexOf(java.io.File.separatorChar);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            savedDir = this.dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            savedFile = file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            savedDir = file.substring(0, index+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            savedFile = file.substring(index+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   398
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   399
        String[] fileNames = fileList.getSelectedItems();
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   400
        int filesNumber = (fileNames != null) ? fileNames.length : 0;
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   401
        File[] files = new File[filesNumber];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   402
        for (int i = 0; i < filesNumber; i++) {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   403
            files[i] = new File(savedDir, fileNames[i]);
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   404
        }
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   405
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   406
        AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   407
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   408
        fileDialogAccessor.setDirectory(target, savedDir);
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   409
        fileDialogAccessor.setFile(target, savedFile);
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   410
        fileDialogAccessor.setFiles(target, files);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * handle the cancel event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    void handleCancel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            .removeKeyEventDispatcher(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        setSelectionField(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        setFilterField(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        directoryList.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        fileList.clear();
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   424
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   425
        AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   426
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   427
        fileDialogAccessor.setDirectory(target, null);
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   428
        fileDialogAccessor.setFile(target, null);
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 7668
diff changeset
   429
        fileDialogAccessor.setFiles(target, null);
4913
9b3caa50afcf 6705345: Enable multiple file selection in AWT FileDialog
dcherepanov
parents: 3938
diff changeset
   430
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        handleQuitButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * handle the quit event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    void handleQuitButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        dir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        target.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * set the entry of the new dir with f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    void setFilterEntry(String d, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        File fe = new File(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (fe.isDirectory() && fe.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            // Fixed 6260659: File Name set programmatically in FileDialog is overridden during navigation, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            // Here we restoring Motif behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            setSelectionField(target.getFile());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (f.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                f = "*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                setFilterField(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                setFilterField(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            String l[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (f.equals("*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                l = fe.list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                // REMIND: fileDialogFilter is not implemented yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                FileDialogFilter ff = new FileDialogFilter(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                l = fe.list(ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // Fixed 6358953: handling was added in case of I/O error happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                this.dir = getParentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            directoryList.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            fileList.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            directoryList.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            fileList.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            directoryList.addItem("..");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            Arrays.sort(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            for (int i = 0 ; i < l.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                File file = new File(d + l[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                if (file.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    directoryList.addItem(l[i] + "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    if (filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        if (filter.accept(new File(l[i]),l[i]))  fileList.addItem(l[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    else fileList.addItem(l[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            this.dir = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            pathField.setText(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            // Some code was removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            // Now we do updating of the pathChoice at the time of the choice opening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            target.setDirectory(this.dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            directoryList.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            fileList.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    String[] getDirList(String dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        if (!dir.endsWith("/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            dir = dir + "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        char[] charr = dir.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        int numSlashes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        for (int i=0;i<charr.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
           if (charr[i] == '/')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
               numSlashes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        String[] starr =  new String[numSlashes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        int j=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        for (int i=charr.length-1;i>=0;i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            if (charr[i] == '/')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                starr[j++] = new String(charr,0,i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return starr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * set the text in the selectionField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    void setSelectionField(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        selectionField.setText(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * set the text in the filterField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    void setFilterField(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        filterField.setText(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @see java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * ItemEvent.ITEM_STATE_CHANGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void itemStateChanged(ItemEvent itemEvent){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (itemEvent.getID() != ItemEvent.ITEM_STATE_CHANGED ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            itemEvent.getStateChange() == ItemEvent.DESELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        Object source = itemEvent.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (source == pathChoice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
             * Update the selection ('folder name' text field) after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
             * the current item changing in the unfurled choice by the arrow keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
             * See 6259434, 6240074 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            String dir = pathChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            pathField.setText(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        } else if (directoryList == source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            setFilterField(getFileName(filterField.getText()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        } else if (fileList == source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            String file = fileList.getItem((Integer)itemEvent.getItem());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            setSelectionField(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Updates the current directory only if directoryList-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * action occurred. Returns false if the forward directory is inaccessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    boolean updateDirectoryByUserAction(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        String dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (str.equals("..")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            dir = getParentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            dir = this.dir + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        File fe = new File(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (fe.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            this.dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    String getParentDirectory(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        String parent = this.dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (!this.dir.equals("/"))   // If the current directory is "/" leave it alone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if (dir.endsWith("/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                parent = parent.substring(0,parent.lastIndexOf("/"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            parent = parent.substring(0,parent.lastIndexOf("/")+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public void actionPerformed( ActionEvent actionEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        String actionCommand = actionEvent.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        Object source = actionEvent.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (actionCommand.equals(actionButtonText)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            handleSelection( selectionField.getText() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            handleQuitButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        } else if (actionCommand.equals(filterLabelText)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            handleFilter( filterField.getText() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        } else if (actionCommand.equals(cancelButtonText)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            handleCancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        } else if ( source instanceof TextField ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if ( selectionField == ((TextField)source) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                // Fixed within 6259434: PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                // We should handle the action based on the selection field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                // Looks like mistake
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                handleSelection(selectionField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                handleQuitButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            } else if (filterField == ((TextField)source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                handleFilter(filterField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            } else if (pathField == ((TextField)source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                target.setDirectory(pathField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        } else if (source instanceof List) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            if (directoryList == ((List)source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                //handleFilter( actionCommand + getFileName( filterField.getText() ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                if (updateDirectoryByUserAction(actionCommand)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    handleFilter( getFileName( filterField.getText() ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            } else if (fileList == ((List)source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                handleSelection( actionCommand );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                handleQuitButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        int id = keyEvent.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        int keyCode = keyEvent.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        if (id == KeyEvent.KEY_PRESSED && keyCode == KeyEvent.VK_ESCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            synchronized (target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                Component comp = (Component) keyEvent.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                while (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    // Fix for 6240084 Disposing a file dialog when the drop-down is active does not dispose the dropdown menu, on Xtoolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    // See also 6259493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    if (comp == pathChoice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                        XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                        if (choicePeer.isUnfurled()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    if (comp.getPeer() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                        handleCancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    comp = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * set the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public void setFile(String file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            this.file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (this.dir == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            String d = "./";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            File f = new File(d, file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            if (f.isFile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                this.file = file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                setDirectory(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            File f = new File(this.dir, file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (f.isFile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                this.file = file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        setSelectionField(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * set the directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * FIXME: we should update 'savedDir' after programmatically 'setDirectory'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * Otherwise, SavedDir will be not null before second showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * So the current directory of the file dialog will be incorrect after second showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * since 'setDirectory' will be ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * We cann't update savedDir here now since it used very often
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public void setDirectory(String dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        if (dir == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            this.dir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (dir.equals(this.dir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if ((i=dir.indexOf("~")) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            dir = dir.substring(0,i) + System.getProperty("user.home") + dir.substring(i+1,dir.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        File fe = new File(dir).getAbsoluteFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        log.fine("Current directory : " + fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        if (!fe.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            dir = "./";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            fe = new File(dir).getAbsoluteFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            if (!fe.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            dir = this.dir = fe.getCanonicalPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        } catch (java.io.IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            dir = this.dir = fe.getAbsolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        pathField.setText(this.dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (dir.endsWith("/")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            this.dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            handleFilter("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            this.dir = dir + "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            handleFilter("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        // Some code was removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        // Now we do updating of the pathChoice at the time of the choice opening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        // Fixed problem:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        // The exception java.awt.IllegalComponentStateException will be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        // if the user invoke setDirectory after the closing of the file dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * set filenameFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public void setFilenameFilter(FilenameFilter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        this.filter = filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
2458
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   764
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   765
    public void dispose() {
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   766
        FileDialog fd = (FileDialog)fileDialog;
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   767
        if (fd != null) {
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   768
            fd.removeAll();
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   769
        }
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   770
        super.dispose();
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   771
    }
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   772
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   773
    // 03/02/2005 b5097243 Pressing 'ESC' on a file dlg does not dispose the dlg on Xtoolkit
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   774
    public void setVisible(boolean b){
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if (fileDialog == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            init((FileDialog)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        if (savedDir != null || userDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            setDirectory(savedDir != null ? savedDir : userDir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        if (savedFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            // Actually in Motif implementation lost file value which was saved after prevously showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            // Seems we shouldn't restore Motif behaviour in this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            setFile(savedFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (b == true){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            // See 6240074 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            choicePeer.addXChoicePeerListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            // See 6240074 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            choicePeer.removeXChoicePeerListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
2458
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   801
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 715
diff changeset
   802
        selectionField.requestFocusInWindow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Adding items to the path choice based on the text string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * See 6240074 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    public void addItemsToPathChoice(String text){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        String dirList[] = getDirList(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        for (int i = 0; i < dirList.length; i++) pathChoice.addItem(dirList[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Refresh the unfurled choice at the time of the opening choice according to the text of the path field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * See 6240074 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    public void unfurledChoiceOpening(ListHelper choiceHelper){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        // When the unfurled choice is opening the first time, we need only to add elements, otherwise we've got exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if (choiceHelper.getItemCount() == 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            addItemsToPathChoice(pathField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        // If the set of the directories the exactly same as the used to be then dummy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        if (pathChoice.getItem(0).equals(pathField.getText()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        pathChoice.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        addItemsToPathChoice(pathField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * Refresh the file dialog at the time of the closing choice according to the selected item of the choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * See 6240074 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    public void unfurledChoiceClosing(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
          // This is the exactly same code as invoking later at the time of the itemStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
          // Here is we restore Windows behaviour: change current directory if user press 'ESC'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
          String dir = pathChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
          target.setDirectory(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
class Separator extends Canvas {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    public final static int HORIZONTAL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    public final static int VERTICAL = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    public Separator(int length, int thickness, int orient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        orientation = orient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (orient == HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            resize(length, thickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            // VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            resize(thickness, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        int x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        Rectangle bbox = bounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        Color c = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        Color brighter = c.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        Color darker = c.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        if (orientation == HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            x1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            x2 = bbox.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            y1 = y2 = bbox.height/2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            // VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            x1 = x2 = bbox.width/2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            y1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            y2 = bbox.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        g.setColor(darker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        g.drawLine(x1, y2, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        g.setColor(brighter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        if (orientation == HORIZONTAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            g.drawLine(x1, y2+1, x2, y2+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            g.drawLine(x1+1, y2, x2+1, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
 * Motif file dialogs let the user specify a filter that controls the files that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
 * are displayed in the dialog. This filter is generally specified as a regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
 * expression. The class is used to implement Motif-like filtering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
class FileDialogFilter implements FilenameFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    String filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    public FileDialogFilter(String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        filter = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * Tells whether or not the specified file should be included in a file list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    public boolean accept(File dir, String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        File f = new File(dir, fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        if (f.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            return matches(fileName, filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * Tells whether or not the input string matches the given filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    private boolean matches(String input, String filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        String regex = convert(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        return input.matches(regex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * Converts the filter into the form which is acceptable by Java's regexps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    private String convert(String filter) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   929
        String regex = "^" + filter + "$";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        regex = regex.replaceAll("\\.", "\\\\.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        regex = regex.replaceAll("\\?", ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        regex = regex.replaceAll("\\*", ".*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        return regex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
}