src/share/classes/javax/swing/JFileChooser.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, 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


  71  *    chooser.setFileFilter(filter);
  72  *    int returnVal = chooser.showOpenDialog(parent);
  73  *    if(returnVal == JFileChooser.APPROVE_OPTION) {
  74  *       System.out.println("You chose to open this file: " +
  75  *            chooser.getSelectedFile().getName());
  76  *    }
  77  * </pre>
  78  * <p>
  79  * <strong>Warning:</strong> Swing is not thread safe. For more
  80  * information see <a
  81  * href="package-summary.html#threading">Swing's Threading
  82  * Policy</a>.
  83  *
  84  * @beaninfo
  85  *   attribute: isContainer false
  86  * description: A component which allows for the interactive selection of a file.
  87  *
  88  * @author Jeff Dinkins
  89  *
  90  */

  91 public class JFileChooser extends JComponent implements Accessible {
  92 
  93     /**
  94      * @see #getUIClassID
  95      * @see #readObject
  96      */
  97     private static final String uiClassID = "FileChooserUI";
  98 
  99     // ************************
 100     // ***** Dialog Types *****
 101     // ************************
 102 
 103     /**
 104      * Type value indicating that the <code>JFileChooser</code> supports an
 105      * "Open" file operation.
 106      */
 107     public static final int OPEN_DIALOG = 0;
 108 
 109     /**
 110      * Type value indicating that the <code>JFileChooser</code> supports a


1979      * For file choosers, the AccessibleContext takes the form of an
1980      * AccessibleJFileChooser.
1981      * A new AccessibleJFileChooser instance is created if necessary.
1982      *
1983      * @return an AccessibleJFileChooser that serves as the
1984      *         AccessibleContext of this JFileChooser
1985      */
1986     public AccessibleContext getAccessibleContext() {
1987         if (accessibleContext == null) {
1988             accessibleContext = new AccessibleJFileChooser();
1989         }
1990         return accessibleContext;
1991     }
1992 
1993     /**
1994      * This class implements accessibility support for the
1995      * <code>JFileChooser</code> class.  It provides an implementation of the
1996      * Java Accessibility API appropriate to file chooser user-interface
1997      * elements.
1998      */

1999     protected class AccessibleJFileChooser extends AccessibleJComponent {
2000 
2001         /**
2002          * Gets the role of this object.
2003          *
2004          * @return an instance of AccessibleRole describing the role of the
2005          * object
2006          * @see AccessibleRole
2007          */
2008         public AccessibleRole getAccessibleRole() {
2009             return AccessibleRole.FILE_CHOOSER;
2010         }
2011 
2012     } // inner class AccessibleJFileChooser
2013 
2014 }
   1 /*
   2  * Copyright (c) 1997, 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


  71  *    chooser.setFileFilter(filter);
  72  *    int returnVal = chooser.showOpenDialog(parent);
  73  *    if(returnVal == JFileChooser.APPROVE_OPTION) {
  74  *       System.out.println("You chose to open this file: " +
  75  *            chooser.getSelectedFile().getName());
  76  *    }
  77  * </pre>
  78  * <p>
  79  * <strong>Warning:</strong> Swing is not thread safe. For more
  80  * information see <a
  81  * href="package-summary.html#threading">Swing's Threading
  82  * Policy</a>.
  83  *
  84  * @beaninfo
  85  *   attribute: isContainer false
  86  * description: A component which allows for the interactive selection of a file.
  87  *
  88  * @author Jeff Dinkins
  89  *
  90  */
  91 @SuppressWarnings("serial") // Superclass is not serializable across versions
  92 public class JFileChooser extends JComponent implements Accessible {
  93 
  94     /**
  95      * @see #getUIClassID
  96      * @see #readObject
  97      */
  98     private static final String uiClassID = "FileChooserUI";
  99 
 100     // ************************
 101     // ***** Dialog Types *****
 102     // ************************
 103 
 104     /**
 105      * Type value indicating that the <code>JFileChooser</code> supports an
 106      * "Open" file operation.
 107      */
 108     public static final int OPEN_DIALOG = 0;
 109 
 110     /**
 111      * Type value indicating that the <code>JFileChooser</code> supports a


1980      * For file choosers, the AccessibleContext takes the form of an
1981      * AccessibleJFileChooser.
1982      * A new AccessibleJFileChooser instance is created if necessary.
1983      *
1984      * @return an AccessibleJFileChooser that serves as the
1985      *         AccessibleContext of this JFileChooser
1986      */
1987     public AccessibleContext getAccessibleContext() {
1988         if (accessibleContext == null) {
1989             accessibleContext = new AccessibleJFileChooser();
1990         }
1991         return accessibleContext;
1992     }
1993 
1994     /**
1995      * This class implements accessibility support for the
1996      * <code>JFileChooser</code> class.  It provides an implementation of the
1997      * Java Accessibility API appropriate to file chooser user-interface
1998      * elements.
1999      */
2000     @SuppressWarnings("serial") // Superclass is not serializable across versions
2001     protected class AccessibleJFileChooser extends AccessibleJComponent {
2002 
2003         /**
2004          * Gets the role of this object.
2005          *
2006          * @return an instance of AccessibleRole describing the role of the
2007          * object
2008          * @see AccessibleRole
2009          */
2010         public AccessibleRole getAccessibleRole() {
2011             return AccessibleRole.FILE_CHOOSER;
2012         }
2013 
2014     } // inner class AccessibleJFileChooser
2015 
2016 }