1 /* JFileChooser.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.awt
.Component
;
42 import java
.awt
.event
.ActionListener
;
44 import java
.io
.IOException
;
45 import java
.io
.ObjectOutputStream
;
46 import java
.util
.Vector
;
48 import javax
.accessibility
.Accessible
;
49 import javax
.accessibility
.AccessibleContext
;
50 import javax
.accessibility
.AccessibleRole
;
51 import javax
.swing
.filechooser
.FileFilter
;
52 import javax
.swing
.filechooser
.FileSystemView
;
53 import javax
.swing
.filechooser
.FileView
;
54 import javax
.swing
.plaf
.FileChooserUI
;
58 * @author Andrew Selkirk
61 public class JFileChooser
extends JComponent
implements Accessible
{
63 private static final long serialVersionUID
= 3162921138695327837L;
66 * AccessibleJFileChooser
68 protected class AccessibleJFileChooser
extends AccessibleJComponent
70 private static final long serialVersionUID
= 8205148454060169244L;
73 * Constructor AccessibleJFileChooser
74 * @param component TODO
76 protected AccessibleJFileChooser()
82 * @return AccessibleRole
84 public AccessibleRole
getAccessibleRole()
86 return AccessibleRole
.FILE_CHOOSER
;
93 private static final String uiClassID
= "FileChooserUI";
98 public static final int OPEN_DIALOG
= 0;
103 public static final int SAVE_DIALOG
= 1;
108 public static final int CUSTOM_DIALOG
= 2;
113 public static final int CANCEL_OPTION
= 1;
118 public static final int APPROVE_OPTION
= 0;
123 public static final int ERROR_OPTION
= -1;
128 public static final int FILES_ONLY
= 0;
133 public static final int DIRECTORIES_ONLY
= 1;
136 * FILES_AND_DIRECTORIES
138 public static final int FILES_AND_DIRECTORIES
= 2;
143 public static final String CANCEL_SELECTION
= "CancelSelection";
148 public static final String APPROVE_SELECTION
= "ApproveSelection";
151 * APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
153 public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
= "ApproveButtonTextChangedProperty";
156 * APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
158 public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
= "ApproveButtonToolTipTextChangedProperty";
161 * APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
163 public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
= "ApproveButtonMnemonicChangedProperty";
166 * CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
168 public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
= "ControlButtonsAreShownChangedProperty";
171 * DIRECTORY_CHANGED_PROPERTY
173 public static final String DIRECTORY_CHANGED_PROPERTY
= "directoryChanged";
176 * SELECTED_FILE_CHANGED_PROPERTY
178 public static final String SELECTED_FILE_CHANGED_PROPERTY
= "SelectedFileChangedProperty";
181 * SELECTED_FILES_CHANGED_PROPERTY
183 public static final String SELECTED_FILES_CHANGED_PROPERTY
= "SelectedFilesChangedProperty";
186 * MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
188 public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
= "MultiSelectionEnabledChangedProperty";
191 * FILE_SYSTEM_VIEW_CHANGED_PROPERTY
193 public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
= "FileSystemViewChanged";
196 * FILE_VIEW_CHANGED_PROPERTY
198 public static final String FILE_VIEW_CHANGED_PROPERTY
= "fileViewChanged";
201 * FILE_HIDING_CHANGED_PROPERTY
203 public static final String FILE_HIDING_CHANGED_PROPERTY
= "FileHidingChanged";
206 * FILE_FILTER_CHANGED_PROPERTY
208 public static final String FILE_FILTER_CHANGED_PROPERTY
= "fileFilterChanged";
211 * FILE_SELECTION_MODE_CHANGED_PROPERTY
213 public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY
= "fileSelectionChanged";
216 * ACCESSORY_CHANGED_PROPERTY
218 public static final String ACCESSORY_CHANGED_PROPERTY
= "AccessoryChangedProperty";
221 * ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
223 public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
= "acceptAllFileFilterUsedChanged";
226 * DIALOG_TITLE_CHANGED_PROPERTY
228 public static final String DIALOG_TITLE_CHANGED_PROPERTY
= "DialogTitleChangedProperty";
231 * DIALOG_TYPE_CHANGED_PROPERTY
233 public static final String DIALOG_TYPE_CHANGED_PROPERTY
= "DialogTypeChangedProperty";
236 * CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
238 public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
= "ChoosableFileFilterChangedProperty";
243 private String dialogTitle
;
248 private String approveButtonText
;
251 * approveButtonToolTipText
253 private String approveButtonToolTipText
;
256 * approveButtonMnemonic
258 private int approveButtonMnemonic
;
263 private ActionListener actionListener
;
268 private Vector filters
;
273 private JDialog dialog
;
278 private int dialogType
;
283 private int returnValue
;
288 private JComponent accessory
;
293 private FileView fileView
;
298 private FileView uiFileView
;
303 private boolean controlsShown
;
308 private boolean useFileHiding
;
313 private int fileSelectionMode
;
316 * multiSelectionEnabled
318 private boolean multiSelectionEnabled
;
321 * useAcceptAllFileFilter
323 private boolean useAcceptAllFileFilter
;
328 private FileFilter fileFilter
;
333 private FileSystemView fileSystemView
;
338 private File currentDirectory
;
343 private File selectedFile
;
348 private File
[] selectedFiles
;
353 protected AccessibleContext accessibleContext
;
356 //-------------------------------------------------------------
357 // Initialization ---------------------------------------------
358 //-------------------------------------------------------------
361 * Constructor JFileChooser
363 public JFileChooser() {
368 * Constructor JFileChooser
369 * @param currentDirectoryPath TODO
371 public JFileChooser(String currentDirectoryPath
) {
376 * Constructor JFileChooser
377 * @param currentDirectory TODO
379 public JFileChooser(File currentDirectory
) {
384 * Constructor JFileChooser
387 public JFileChooser(FileSystemView fsv
) {
392 * Constructor JFileChooser
393 * @param currentDirectory TODO
396 public JFileChooser(File currentDirectory
, FileSystemView fsv
) {
401 * Constructor JFileChooser
402 * @param currentDirectoryPath TODO
405 public JFileChooser(String currentDirectoryPath
, FileSystemView fsv
) {
410 //-------------------------------------------------------------
411 // Methods ----------------------------------------------------
412 //-------------------------------------------------------------
417 * @exception IOException TODO
419 private void writeObject(ObjectOutputStream stream
) throws IOException
{
428 public String
getName(File file
) {
436 protected void setup(FileSystemView view
) {
445 public boolean accept(File file
) {
446 return false; // TODO
453 public File
getSelectedFile() {
455 } // getSelectedFile()
461 public void setSelectedFile(File file
) {
463 } // setSelectedFile()
469 public File
[] getSelectedFiles() {
471 } // getSelectedFiles()
477 public void setSelectedFiles(File
[] files
) {
479 } // setSelectedFiles()
482 * getCurrentDirectory
485 public File
getCurrentDirectory() {
487 } // getCurrentDirectory()
490 * setCurrentDirectory
491 * @param directory TODO
493 public void setCurrentDirectory(File directory
) {
495 } // setCurrentDirectory()
498 * changeToParentDirectory
500 public void changeToParentDirectory() {
502 } // changeToParentDirectory()
505 * rescanCurrentDirectory
507 public void rescanCurrentDirectory() {
509 } // rescanCurrentDirectory()
512 * ensureFileIsVisible
515 public void ensureFileIsVisible(File file
) {
517 } // ensureFileIsVisible()
524 public int showOpenDialog(Component parent
) {
526 } // showOpenDialog()
533 public int showSaveDialog(Component parent
) {
535 } // showSaveDialog()
540 * @param approveButtonText TODO
543 public int showDialog(Component parent
, String approveButtonText
) {
548 * getControlButtonsAreShown
551 public boolean getControlButtonsAreShown() {
552 return false; // TODO
553 } // getControlButtonsAreShown()
556 * setControlButtonsAreShown
559 public void setControlButtonsAreShown(boolean value
) {
561 } // setControlButtonsAreShown()
567 public int getDialogType() {
575 public void setDialogType(int type
) {
583 public void setDialogTitle(String title
) {
585 } // setDialogTitle()
591 public String
getDialogTitle() {
593 } // getDialogTitle()
596 * setApproveButtonToolTipText
599 public void setApproveButtonToolTipText(String text
) {
601 } // setApproveButtonToolTipText()
604 * getApproveButtonToolTipText
607 public String
getApproveButtonToolTipText() {
609 } // getApproveButtonToolTipText()
612 * getApproveButtonMnemonic
615 public int getApproveButtonMnemonic() {
617 } // getApproveButtonMnemonic()
620 * setApproveButtonMnemonic
621 * @param mnemonic TODO
623 public void setApproveButtonMnemonic(int mnemonic
) {
625 } // setApproveButtonMnemonic()
628 * setApproveButtonMnemonic
629 * @param mnemonic TODO
631 public void setApproveButtonMnemonic(char mnemonic
) {
633 } // setApproveButtonMnemonic()
636 * setApproveButtonText
639 public void setApproveButtonText(String text
) {
641 } // setApproveButtonText()
644 * getApproveButtonText
647 public String
getApproveButtonText() {
649 } // getApproveButtonText()
652 * getChoosableFileFilters
653 * @returns FileFilter[]
655 public FileFilter
[] getChoosableFileFilters() {
657 } // getChoosableFileFilters()
660 * addChoosableFileFilter
663 public void addChoosableFileFilter(FileFilter filter
) {
665 } // addChoosableFileFilter()
668 * removeChoosableFileFilter
672 public boolean removeChoosableFileFilter(FileFilter filter
) {
673 return false; // TODO
674 } // removeChoosableFileFilter()
677 * resetChoosableFileFilters
679 public void resetChoosableFileFilters() {
681 } // resetChoosableFileFilters()
684 * getAcceptAllFileFilter
685 * @returns FileFilter
687 public FileFilter
getAcceptAllFileFilter() {
689 } // getAcceptAllFileFilter()
692 * isAcceptAllFileFilterUsed
695 public boolean isAcceptAllFileFilterUsed() {
696 return false; // TODO
697 } // isAcceptAllFileFilterUsed()
700 * setAcceptAllFileFilterUsed
703 public void setAcceptAllFileFilterUsed(boolean value
) {
705 } // setAcceptAllFileFilterUsed()
709 * @returns JComponent
711 public JComponent
getAccessory() {
717 * @param accessory TODO
719 public void setAccessory(JComponent accessory
) {
724 * setFileSelectionMode
727 public void setFileSelectionMode(int mode
) {
729 } // setFileSelectionMode()
732 * getFileSelectionMode
735 public int getFileSelectionMode() {
737 } // getFileSelectionMode()
740 * isFileSelectionEnabled
743 public boolean isFileSelectionEnabled() {
744 return false; // TODO
745 } // isFileSelectionEnabled()
748 * isDirectorySelectionEnabled
751 public boolean isDirectorySelectionEnabled() {
752 return false; // TODO
753 } // isDirectorySelectionEnabled()
756 * isMultiSelectionEnabled
759 public boolean isMultiSelectionEnabled() {
760 return false; // TODO
761 } // isMultiSelectionEnabled()
764 * setMultiSelectionEnabled
765 * @param enabled TODO
767 public void setMultiSelectionEnabled(boolean enabled
) {
769 } // setMultiSelectionEnabled()
772 * isFileHidingEnabled
775 public boolean isFileHidingEnabled() {
776 return false; // TODO
777 } // isFileHidingEnabled()
780 * setFileHidingEnabled
781 * @param enabled TODO
783 public void setFileHidingEnabled(boolean enabled
) {
785 } // setFileHidingEnabled()
789 * @returns FileFilter
791 public FileFilter
getFileFilter() {
799 public void setFileFilter(FileFilter filter
) {
807 public FileView
getFileView() {
815 public void setFileView(FileView view
) {
824 public String
getDescription(File file
) {
826 } // getDescription()
833 public String
getTypeDescription(File file
) {
835 } // getTypeDescription()
842 public Icon
getIcon(File file
) {
851 public boolean isTraversable(File file
) {
852 return false; // TODO
857 * @returns FileSystemView
859 public FileSystemView
getFileSystemView() {
861 } // getFileSystemView()
867 public void setFileSystemView(FileSystemView fsv
) {
869 } // setFileSystemView()
874 public void approveSelection() {
876 } // approveSelection()
881 public void cancelSelection() {
883 } // cancelSelection()
887 * @param listener TODO
889 public void addActionListener(ActionListener listener
)
891 listenerList
.add (ActionListener
.class, listener
);
895 * removeActionListener
896 * @param listener TODO
898 public void removeActionListener(ActionListener listener
)
900 listenerList
.remove (ActionListener
.class, listener
);
903 public ActionListener
[] getActionListeners()
905 return (ActionListener
[]) listenerList
.getListeners (ActionListener
.class);
909 * fireActionPerformed
910 * @param command TODO
912 protected void fireActionPerformed(String command
) {
914 } // fireActionPerformed()
919 public void updateUI() {
920 setUI((FileChooserUI
) UIManager
.get(this));
928 public String
getUIClassID() {
934 * @returns FileChooserUI
936 public FileChooserUI
getUI() {
937 return (FileChooserUI
) ui
;
944 protected String
paramString() {
949 * getAccessibleContext
950 * @returns AccessibleContext
952 public AccessibleContext
getAccessibleContext()
954 if (accessibleContext
== null)
955 accessibleContext
= new AccessibleJFileChooser();
957 return accessibleContext
;