001/* 002 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.stage; 027 028import com.sun.javafx.tk.Toolkit; 029import java.io.File; 030import javafx.beans.property.ObjectProperty; 031import javafx.beans.property.SimpleObjectProperty; 032import javafx.beans.property.SimpleStringProperty; 033import javafx.beans.property.StringProperty; 034 035// PENDING_DOC_REVIEW 036/** 037 * Provides support for standard directory chooser dialogs. These dialogs have 038 * look and feel of the platform UI components which is independent of JavaFX. 039 * 040 * On some platforms where file access may be restricted or not part of the user 041 * model (for example, on some mobile or embedded devices), opening a directory 042 * dialog may always result in a no-op (that is, null file being returned). 043 * 044 * @since JavaFX 2.1 045 */ 046public final class DirectoryChooser { 047 /** 048 * The title of the displayed dialog. 049 */ 050 private StringProperty title; 051 052 public final void setTitle(final String value) { 053 titleProperty().set(value); 054 } 055 056 public final String getTitle() { 057 return (title != null) ? title.get() : null; 058 } 059 060 public final StringProperty titleProperty() { 061 if (title == null) { 062 title = new SimpleStringProperty(this, "title"); 063 } 064 065 return title; 066 } 067 068 /** 069 * The initial directory for the displayed dialog. 070 */ 071 private ObjectProperty<File> initialDirectory; 072 073 public final void setInitialDirectory(final File value) { 074 initialDirectoryProperty().set(value); 075 } 076 077 public final File getInitialDirectory() { 078 return (initialDirectory != null) ? initialDirectory.get() : null; 079 } 080 081 public final ObjectProperty<File> initialDirectoryProperty() { 082 if (initialDirectory == null) { 083 initialDirectory = 084 new SimpleObjectProperty<File>(this, "initialDirectory"); 085 } 086 087 return initialDirectory; 088 } 089 090 /** 091 * Shows a new directory selection dialog. The method doesn't return until 092 * the displayed dialog is dismissed. The return value specifies the 093 * directory chosen by the user or {@code null} if no selection has been 094 * made. If the owner window for the directory selection dialog is set, 095 * input to all windows in the dialog's owner chain is blocked while the 096 * dialog is being shown. 097 * 098 * @param ownerWindow the owner window of the displayed dialog 099 * @return the selected directory or {@code null} if no directory has been 100 * selected 101 */ 102 public File showDialog(final Window ownerWindow) { 103 return Toolkit.getToolkit().showDirectoryChooser( 104 (ownerWindow != null) ? ownerWindow.impl_getPeer() : null, 105 getTitle(), 106 getInitialDirectory()); 107 } 108}