1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
304 * Responds to a File Name completion request (e.g. Tab)
305 */
306 @SuppressWarnings("serial") // JDK-implementation class
307 private class FileNameCompletionAction extends AbstractAction {
308 protected FileNameCompletionAction() {
309 super("fileNameCompletion");
310 }
311
312 public void actionPerformed(ActionEvent e) {
313 JFileChooser chooser = getFileChooser();
314
315 String fileName = getFileName();
316
317 if (fileName != null) {
318 // Remove whitespace from beginning and end of filename
319 fileName = fileName.trim();
320 }
321
322 resetGlobFilter();
323
324 if (fileName == null || fileName.equals("") ||
325 (chooser.isMultiSelectionEnabled() && fileName.startsWith("\""))) {
326 return;
327 }
328
329 FileFilter currentFilter = chooser.getFileFilter();
330 if (globFilter == null) {
331 globFilter = new GlobFilter();
332 }
333 try {
334 globFilter.setPattern(!isGlobPattern(fileName) ? fileName + "*" : fileName);
335 if (!(currentFilter instanceof GlobFilter)) {
336 actualFileFilter = currentFilter;
337 }
338 chooser.setFileFilter(null);
339 chooser.setFileFilter(globFilter);
340 fileNameCompletionString = fileName;
341 } catch (PatternSyntaxException pse) {
342 // Not a valid glob pattern. Abandon filter.
343 }
344 }
|
1 /*
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
304 * Responds to a File Name completion request (e.g. Tab)
305 */
306 @SuppressWarnings("serial") // JDK-implementation class
307 private class FileNameCompletionAction extends AbstractAction {
308 protected FileNameCompletionAction() {
309 super("fileNameCompletion");
310 }
311
312 public void actionPerformed(ActionEvent e) {
313 JFileChooser chooser = getFileChooser();
314
315 String fileName = getFileName();
316
317 if (fileName != null) {
318 // Remove whitespace from beginning and end of filename
319 fileName = fileName.trim();
320 }
321
322 resetGlobFilter();
323
324 if (fileName == null || fileName.isEmpty() ||
325 (chooser.isMultiSelectionEnabled() && fileName.startsWith("\""))) {
326 return;
327 }
328
329 FileFilter currentFilter = chooser.getFileFilter();
330 if (globFilter == null) {
331 globFilter = new GlobFilter();
332 }
333 try {
334 globFilter.setPattern(!isGlobPattern(fileName) ? fileName + "*" : fileName);
335 if (!(currentFilter instanceof GlobFilter)) {
336 actualFileFilter = currentFilter;
337 }
338 chooser.setFileFilter(null);
339 chooser.setFileFilter(globFilter);
340 fileNameCompletionString = fileName;
341 } catch (PatternSyntaxException pse) {
342 // Not a valid glob pattern. Abandon filter.
343 }
344 }
|