1 /*
2 * Copyright (c) 2002, 2008, 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
416
417 protected MouseListener createDoubleClickListener(JFileChooser fc, JList list) {
418 return new DoubleClickListener(list);
419 }
420
421
422
423 protected class SelectionListener implements ListSelectionListener {
424 public void valueChanged(ListSelectionEvent e) {
425 if (!e.getValueIsAdjusting()) {
426 JFileChooser chooser = getFileChooser();
427 JList list = (JList) e.getSource();
428
429 if (chooser.isMultiSelectionEnabled()) {
430 File[] files = null;
431 Object[] objects = list.getSelectedValues();
432 if (objects != null) {
433 if (objects.length == 1
434 && ((File)objects[0]).isDirectory()
435 && chooser.isTraversable(((File)objects[0]))
436 && (chooser.getFileSelectionMode() != chooser.DIRECTORIES_ONLY
437 || !chooser.getFileSystemView().isFileSystem(((File)objects[0])))) {
438 setDirectorySelected(true);
439 setDirectory(((File)objects[0]));
440 } else {
441 ArrayList<File> fList = new ArrayList<File>(objects.length);
442 for (Object object : objects) {
443 File f = (File) object;
444 if ((chooser.isFileSelectionEnabled() && f.isFile())
445 || (chooser.isDirectorySelectionEnabled() && f.isDirectory())) {
446 fList.add(f);
447 }
448 }
449 if (fList.size() > 0) {
450 files = fList.toArray(new File[fList.size()]);
451 }
452 setDirectorySelected(false);
453 }
454 }
455 chooser.setSelectedFiles(files);
456 } else {
457 File file = (File)list.getSelectedValue();
458 if (file != null
459 && file.isDirectory()
460 && chooser.isTraversable(file)
461 && (chooser.getFileSelectionMode() == chooser.FILES_ONLY
462 || !chooser.getFileSystemView().isFileSystem(file))) {
463
464 setDirectorySelected(true);
465 setDirectory(file);
466 } else {
467 setDirectorySelected(false);
468 if (file != null) {
469 chooser.setSelectedFile(file);
470 }
471 }
472 }
473 }
474 }
475 }
476
477
478 //
479 // ComponentUI Interface Implementation methods
480 //
481 public static ComponentUI createUI(JComponent c) {
|
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
416
417 protected MouseListener createDoubleClickListener(JFileChooser fc, JList list) {
418 return new DoubleClickListener(list);
419 }
420
421
422
423 protected class SelectionListener implements ListSelectionListener {
424 public void valueChanged(ListSelectionEvent e) {
425 if (!e.getValueIsAdjusting()) {
426 JFileChooser chooser = getFileChooser();
427 JList list = (JList) e.getSource();
428
429 if (chooser.isMultiSelectionEnabled()) {
430 File[] files = null;
431 Object[] objects = list.getSelectedValues();
432 if (objects != null) {
433 if (objects.length == 1
434 && ((File)objects[0]).isDirectory()
435 && chooser.isTraversable(((File)objects[0]))
436 && (chooser.getFileSelectionMode() != JFileChooser.DIRECTORIES_ONLY
437 || !chooser.getFileSystemView().isFileSystem(((File)objects[0])))) {
438 setDirectorySelected(true);
439 setDirectory(((File)objects[0]));
440 } else {
441 ArrayList<File> fList = new ArrayList<File>(objects.length);
442 for (Object object : objects) {
443 File f = (File) object;
444 if ((chooser.isFileSelectionEnabled() && f.isFile())
445 || (chooser.isDirectorySelectionEnabled() && f.isDirectory())) {
446 fList.add(f);
447 }
448 }
449 if (fList.size() > 0) {
450 files = fList.toArray(new File[fList.size()]);
451 }
452 setDirectorySelected(false);
453 }
454 }
455 chooser.setSelectedFiles(files);
456 } else {
457 File file = (File)list.getSelectedValue();
458 if (file != null
459 && file.isDirectory()
460 && chooser.isTraversable(file)
461 && (chooser.getFileSelectionMode() == JFileChooser.FILES_ONLY
462 || !chooser.getFileSystemView().isFileSystem(file))) {
463
464 setDirectorySelected(true);
465 setDirectory(file);
466 } else {
467 setDirectorySelected(false);
468 if (file != null) {
469 chooser.setSelectedFile(file);
470 }
471 }
472 }
473 }
474 }
475 }
476
477
478 //
479 // ComponentUI Interface Implementation methods
480 //
481 public static ComponentUI createUI(JComponent c) {
|