1 /* JFileChooser.java --
2 Copyright (C) 2002 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
;
47 import javax
.accessibility
.Accessible
;
48 import javax
.accessibility
.AccessibleContext
;
49 import javax
.accessibility
.AccessibleRole
;
50 import javax
.swing
.filechooser
.FileFilter
;
51 import javax
.swing
.filechooser
.FileSystemView
;
52 import javax
.swing
.filechooser
.FileView
;
53 import javax
.swing
.plaf
.FileChooserUI
;
57 * @author Andrew Selkirk
60 public class JFileChooser
extends JComponent
implements Accessible
{
62 //-------------------------------------------------------------
63 // Classes ----------------------------------------------------
64 //-------------------------------------------------------------
67 * AccessibleJFileChooser
69 protected class AccessibleJFileChooser
extends AccessibleJComponent
{
71 //-------------------------------------------------------------
72 // Variables --------------------------------------------------
73 //-------------------------------------------------------------
76 //-------------------------------------------------------------
77 // Initialization ---------------------------------------------
78 //-------------------------------------------------------------
81 * Constructor AccessibleJFileChooser
82 * @param component TODO
84 protected AccessibleJFileChooser(JFileChooser component
) {
87 } // AccessibleJFileChooser()
90 //-------------------------------------------------------------
91 // Methods ----------------------------------------------------
92 //-------------------------------------------------------------
96 * @returns AccessibleRole
98 public AccessibleRole
getAccessibleRole() {
99 return AccessibleRole
.FILE_CHOOSER
;
100 } // getAccessibleRole()
103 } // AccessibleJFileChooser
106 //-------------------------------------------------------------
107 // Variables --------------------------------------------------
108 //-------------------------------------------------------------
113 private static final String uiClassID
= "FileChooserUI";
118 public static final int OPEN_DIALOG
= 0;
123 public static final int SAVE_DIALOG
= 1;
128 public static final int CUSTOM_DIALOG
= 2;
133 public static final int CANCEL_OPTION
= 1;
138 public static final int APPROVE_OPTION
= 0;
143 public static final int ERROR_OPTION
= -1;
148 public static final int FILES_ONLY
= 0;
153 public static final int DIRECTORIES_ONLY
= 1;
156 * FILES_AND_DIRECTORIES
158 public static final int FILES_AND_DIRECTORIES
= 2;
163 public static final String CANCEL_SELECTION
= "CancelSelection";
168 public static final String APPROVE_SELECTION
= "ApproveSelection";
171 * APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
173 public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
= "ApproveButtonTextChangedProperty";
176 * APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
178 public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
= "ApproveButtonToolTipTextChangedProperty";
181 * APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
183 public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
= "ApproveButtonMnemonicChangedProperty";
186 * CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
188 public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
= "ControlButtonsAreShownChangedProperty";
191 * DIRECTORY_CHANGED_PROPERTY
193 public static final String DIRECTORY_CHANGED_PROPERTY
= "directoryChanged";
196 * SELECTED_FILE_CHANGED_PROPERTY
198 public static final String SELECTED_FILE_CHANGED_PROPERTY
= "SelectedFileChangedProperty";
201 * SELECTED_FILES_CHANGED_PROPERTY
203 public static final String SELECTED_FILES_CHANGED_PROPERTY
= "SelectedFilesChangedProperty";
206 * MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
208 public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
= "MultiSelectionEnabledChangedProperty";
211 * FILE_SYSTEM_VIEW_CHANGED_PROPERTY
213 public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
= "FileSystemViewChanged";
216 * FILE_VIEW_CHANGED_PROPERTY
218 public static final String FILE_VIEW_CHANGED_PROPERTY
= "fileViewChanged";
221 * FILE_HIDING_CHANGED_PROPERTY
223 public static final String FILE_HIDING_CHANGED_PROPERTY
= "FileHidingChanged";
226 * FILE_FILTER_CHANGED_PROPERTY
228 public static final String FILE_FILTER_CHANGED_PROPERTY
= "fileFilterChanged";
231 * FILE_SELECTION_MODE_CHANGED_PROPERTY
233 public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY
= "fileSelectionChanged";
236 * ACCESSORY_CHANGED_PROPERTY
238 public static final String ACCESSORY_CHANGED_PROPERTY
= "AccessoryChangedProperty";
241 * ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
243 public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
= "acceptAllFileFilterUsedChanged";
246 * DIALOG_TITLE_CHANGED_PROPERTY
248 public static final String DIALOG_TITLE_CHANGED_PROPERTY
= "DialogTitleChangedProperty";
251 * DIALOG_TYPE_CHANGED_PROPERTY
253 public static final String DIALOG_TYPE_CHANGED_PROPERTY
= "DialogTypeChangedProperty";
256 * CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
258 public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
= "ChoosableFileFilterChangedProperty";
263 private String dialogTitle
;
268 private String approveButtonText
;
271 * approveButtonToolTipText
273 private String approveButtonToolTipText
;
276 * approveButtonMnemonic
278 private int approveButtonMnemonic
;
283 private ActionListener actionListener
;
288 private Vector filters
;
293 private JDialog dialog
;
298 private int dialogType
;
303 private int returnValue
;
308 private JComponent accessory
;
313 private FileView fileView
;
318 private FileView uiFileView
;
323 private boolean controlsShown
;
328 private boolean useFileHiding
;
333 private int fileSelectionMode
;
336 * multiSelectionEnabled
338 private boolean multiSelectionEnabled
;
341 * useAcceptAllFileFilter
343 private boolean useAcceptAllFileFilter
;
348 private FileFilter fileFilter
;
353 private FileSystemView fileSystemView
;
358 private File currentDirectory
;
363 private File selectedFile
;
368 private File
[] selectedFiles
;
373 protected AccessibleContext accessibleContext
;
376 //-------------------------------------------------------------
377 // Initialization ---------------------------------------------
378 //-------------------------------------------------------------
381 * Constructor JFileChooser
383 public JFileChooser() {
388 * Constructor JFileChooser
389 * @param currentDirectoryPath TODO
391 public JFileChooser(String currentDirectoryPath
) {
396 * Constructor JFileChooser
397 * @param currentDirectory TODO
399 public JFileChooser(File currentDirectory
) {
404 * Constructor JFileChooser
407 public JFileChooser(FileSystemView fsv
) {
412 * Constructor JFileChooser
413 * @param currentDirectory TODO
416 public JFileChooser(File currentDirectory
, FileSystemView fsv
) {
421 * Constructor JFileChooser
422 * @param currentDirectoryPath TODO
425 public JFileChooser(String currentDirectoryPath
, FileSystemView fsv
) {
430 //-------------------------------------------------------------
431 // Methods ----------------------------------------------------
432 //-------------------------------------------------------------
437 * @exception IOException TODO
439 private void writeObject(ObjectOutputStream stream
) throws IOException
{
448 public String
getName(File file
) {
456 protected void setup(FileSystemView view
) {
465 public boolean accept(File file
) {
466 return false; // TODO
473 public File
getSelectedFile() {
475 } // getSelectedFile()
481 public void setSelectedFile(File file
) {
483 } // setSelectedFile()
489 public File
[] getSelectedFiles() {
491 } // getSelectedFiles()
497 public void setSelectedFiles(File
[] files
) {
499 } // setSelectedFiles()
502 * getCurrentDirectory
505 public File
getCurrentDirectory() {
507 } // getCurrentDirectory()
510 * setCurrentDirectory
511 * @param directory TODO
513 public void setCurrentDirectory(File directory
) {
515 } // setCurrentDirectory()
518 * changeToParentDirectory
520 public void changeToParentDirectory() {
522 } // changeToParentDirectory()
525 * rescanCurrentDirectory
527 public void rescanCurrentDirectory() {
529 } // rescanCurrentDirectory()
532 * ensureFileIsVisible
535 public void ensureFileIsVisible(File file
) {
537 } // ensureFileIsVisible()
544 public int showOpenDialog(Component parent
) {
546 } // showOpenDialog()
553 public int showSaveDialog(Component parent
) {
555 } // showSaveDialog()
560 * @param approveButtonText TODO
563 public int showDialog(Component parent
, String approveButtonText
) {
568 * getControlButtonsAreShown
571 public boolean getControlButtonsAreShown() {
572 return false; // TODO
573 } // getControlButtonsAreShown()
576 * setControlButtonsAreShown
579 public void setControlButtonsAreShown(boolean value
) {
581 } // setControlButtonsAreShown()
587 public int getDialogType() {
595 public void setDialogType(int type
) {
603 public void setDialogTitle(String title
) {
605 } // setDialogTitle()
611 public String
getDialogTitle() {
613 } // getDialogTitle()
616 * setApproveButtonToolTipText
619 public void setApproveButtonToolTipText(String text
) {
621 } // setApproveButtonToolTipText()
624 * getApproveButtonToolTipText
627 public String
getApproveButtonToolTipText() {
629 } // getApproveButtonToolTipText()
632 * getApproveButtonMnemonic
635 public int getApproveButtonMnemonic() {
637 } // getApproveButtonMnemonic()
640 * setApproveButtonMnemonic
641 * @param mnemonic TODO
643 public void setApproveButtonMnemonic(int mnemonic
) {
645 } // setApproveButtonMnemonic()
648 * setApproveButtonMnemonic
649 * @param mnemonic TODO
651 public void setApproveButtonMnemonic(char mnemonic
) {
653 } // setApproveButtonMnemonic()
656 * setApproveButtonText
659 public void setApproveButtonText(String text
) {
661 } // setApproveButtonText()
664 * getApproveButtonText
667 public String
getApproveButtonText() {
669 } // getApproveButtonText()
672 * getChoosableFileFilters
673 * @returns FileFilter[]
675 public FileFilter
[] getChoosableFileFilters() {
677 } // getChoosableFileFilters()
680 * addChoosableFileFilter
683 public void addChoosableFileFilter(FileFilter filter
) {
685 } // addChoosableFileFilter()
688 * removeChoosableFileFilter
692 public boolean removeChoosableFileFilter(FileFilter filter
) {
693 return false; // TODO
694 } // removeChoosableFileFilter()
697 * resetChoosableFileFilters
699 public void resetChoosableFileFilters() {
701 } // resetChoosableFileFilters()
704 * getAcceptAllFileFilter
705 * @returns FileFilter
707 public FileFilter
getAcceptAllFileFilter() {
709 } // getAcceptAllFileFilter()
712 * isAcceptAllFileFilterUsed
715 public boolean isAcceptAllFileFilterUsed() {
716 return false; // TODO
717 } // isAcceptAllFileFilterUsed()
720 * setAcceptAllFileFilterUsed
723 public void setAcceptAllFileFilterUsed(boolean value
) {
725 } // setAcceptAllFileFilterUsed()
729 * @returns JComponent
731 public JComponent
getAccessory() {
737 * @param accessory TODO
739 public void setAccessory(JComponent accessory
) {
744 * setFileSelectionMode
747 public void setFileSelectionMode(int mode
) {
749 } // setFileSelectionMode()
752 * getFileSelectionMode
755 public int getFileSelectionMode() {
757 } // getFileSelectionMode()
760 * isFileSelectionEnabled
763 public boolean isFileSelectionEnabled() {
764 return false; // TODO
765 } // isFileSelectionEnabled()
768 * isDirectorySelectionEnabled
771 public boolean isDirectorySelectionEnabled() {
772 return false; // TODO
773 } // isDirectorySelectionEnabled()
776 * isMultiSelectionEnabled
779 public boolean isMultiSelectionEnabled() {
780 return false; // TODO
781 } // isMultiSelectionEnabled()
784 * setMultiSelectionEnabled
785 * @param enabled TODO
787 public void setMultiSelectionEnabled(boolean enabled
) {
789 } // setMultiSelectionEnabled()
792 * isFileHidingEnabled
795 public boolean isFileHidingEnabled() {
796 return false; // TODO
797 } // isFileHidingEnabled()
800 * setFileHidingEnabled
801 * @param enabled TODO
803 public void setFileHidingEnabled(boolean enabled
) {
805 } // setFileHidingEnabled()
809 * @returns FileFilter
811 public FileFilter
getFileFilter() {
819 public void setFileFilter(FileFilter filter
) {
827 public FileView
getFileView() {
835 public void setFileView(FileView view
) {
844 public String
getDescription(File file
) {
846 } // getDescription()
853 public String
getTypeDescription(File file
) {
855 } // getTypeDescription()
862 public Icon
getIcon(File file
) {
871 public boolean isTraversable(File file
) {
872 return false; // TODO
877 * @returns FileSystemView
879 public FileSystemView
getFileSystemView() {
881 } // getFileSystemView()
887 public void setFileSystemView(FileSystemView fsv
) {
889 } // setFileSystemView()
894 public void approveSelection() {
896 } // approveSelection()
901 public void cancelSelection() {
903 } // cancelSelection()
907 * @param listener TODO
909 public void addActionListener(ActionListener listener
) {
911 } // addActionListener()
914 * removeActionListener
915 * @param listener TODO
917 public void removeActionListener(ActionListener listener
) {
919 } // removeActionListener()
922 * fireActionPerformed
923 * @param command TODO
925 protected void fireActionPerformed(String command
) {
927 } // fireActionPerformed()
932 public void updateUI() {
933 setUI((FileChooserUI
) UIManager
.get(this));
941 public String
getUIClassID() {
947 * @returns FileChooserUI
949 public FileChooserUI
getUI() {
950 return (FileChooserUI
) ui
;
957 protected String
paramString() {
962 * getAccessibleContext
963 * @returns AccessibleContext
965 public AccessibleContext
getAccessibleContext() {
966 if (accessibleContext
== null) {
967 accessibleContext
= new AccessibleJFileChooser(this);
969 return accessibleContext
;
970 } // getAccessibleContext()