Example usage for java.awt FileDialog setVisible

List of usage examples for java.awt FileDialog setVisible

Introduction

In this page you can find the example usage for java.awt FileDialog setVisible.

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Dialog depending on the value of parameter b .

Usage

From source file:Main.java

/**
 * Select the file path via {@linkplain FileDialog}.
 * //ww  w .  j  a va2 s  .  c o  m
 * @param parent
 *            the parent of {@linkplain FileDialog}
 * @param title
 *            the title of {@linkplain FileDialog}
 * @return the selected path
 */
public static String selectPath(Frame parent, String title) {
    FileDialog dialog = new FileDialog(parent, title, FileDialog.LOAD);
    dialog.setVisible(true);
    String dir = dialog.getDirectory();
    dialog.dispose();
    return dir;
}

From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java

private static String createAndShowSdkChooser() {
    String sdk;/*from w  ww  .  ja v  a 2s  . co  m*/
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
    FileDialog d = new FileDialog(new JFrame());
    d.setVisible(true);
    System.setProperty("apple.awt.fileDialogForDirectories", "false");
    sdk = d.getDirectory();
    return sdk;
}

From source file:Main.java

/**
 * @param jFrame/*from  www  .j  a va 2s  .  com*/
 * @param currentDirectory
 * @return You can get the filename with fileDialog.getFile(),
 * and you can get the directory with fileDialog.getDirectory().
 * String filename = fileDialog.getDirectory() + System.getProperty("file.separator") + fileDialog.getFile();
 * 
 */
public static FileDialog letUserChooseFile(JFrame jFrame, String currentDirectory) {
    FileDialog fileDialog = new FileDialog(jFrame);
    fileDialog.setModal(true);
    fileDialog.setMode(FileDialog.LOAD);
    fileDialog.setTitle("Open a File");
    if (currentDirectory != null && !currentDirectory.trim().equals("")) {
        fileDialog.setDirectory(currentDirectory);
    }
    fileDialog.setVisible(true);
    return fileDialog;
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

private static Path openDirectoryDialog(String title) throws Exception, Error {
    // set system property to choose directories
    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    FileDialog chooser = new FileDialog(MainWindow.getFrame(), title);
    if (lastDir != null) {
        chooser.setDirectory(lastDir.toFile().getAbsolutePath());
    }/* ww w .  j  a va2s .c o m*/
    chooser.setVisible(true);

    // reset system property
    System.setProperty("apple.awt.fileDialogForDirectories", "false");

    if (StringUtils.isNotEmpty(chooser.getFile())) {
        lastDir = Paths.get(chooser.getDirectory());
        return Paths.get(chooser.getDirectory(), chooser.getFile());
    } else {
        return null;
    }
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

private static Path openFileDialog(String title, int mode, String filename) throws Exception, Error {
    FileDialog chooser = new FileDialog(MainWindow.getFrame(), title, mode);
    if (lastDir != null) {
        chooser.setDirectory(lastDir.toFile().getAbsolutePath());
    }//from w  w  w  .  j a va  2  s.  c o m
    if (mode == FileDialog.SAVE) {
        chooser.setFile(filename);
    }
    chooser.setVisible(true);

    if (StringUtils.isNotEmpty(chooser.getFile())) {
        lastDir = Paths.get(chooser.getDirectory());
        return Paths.get(chooser.getDirectory(), chooser.getFile());
    } else {
        return null;
    }
}

From source file:com.stacksync.desktop.util.FileUtil.java

private static File showBrowseDialogMac(BrowseType type) {
    // AWT looks best on Mac:
    // http://today.java.net/pub/a/today/2004/01/29/swing.html

    String title = "";
    if (type == BrowseType.DIRECTORIES_ONLY) {
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        title = "Choose Folder";
    } else if (type == BrowseType.FILES_ONLY) {
        System.setProperty("apple.awt.fileDialogForDirectories", "false");
        title = "Choose File";
    }//from   w w  w  .j  ava 2s. c  o m

    FileDialog dialog = new FileDialog(new Frame(), title);
    dialog.setVisible(true);

    String path = dialog.getDirectory() + dialog.getFile();
    return new File(path);
}

From source file:phex.gui.common.FileDialogHandler.java

private static File openMacDirectoryChooser(String title, String notifyPopupTitle,
        String notifyPopupShortMessage) {
    // create folder dialog through other class this prevents 
    // NoClassDefFoundError on Windows systems since the import of the
    // required OS X classes is elsewhere.
    FileDialog dia = MacOsxGUIUtils.createFolderDialog();
    dia.setTitle(title);//  www  .  ja  va 2s . c  om

    // unfortunatly its not possible to display notification popup
    // besides heavy weight dialog.
    //if ( notifyPopupTitle != null || notifyPopupShortMessage != null )
    //{
    //displayMacNotificationPopup( dia, notifyPopupTitle, 
    //    notifyPopupShortMessage );
    //}

    DirectoryOnlyFileFilter filter = new DirectoryOnlyFileFilter();
    dia.setFilenameFilter(new FileFilterWrapper(filter));
    dia.setVisible(true);
    String dirStr = dia.getDirectory();
    String fileStr = dia.getFile();

    if (dirStr == null || fileStr == null) {
        return null;
    }
    File file = new File(dirStr, fileStr);
    // validate filter
    if (!filter.accept(file)) {
        return null;
    }
    return file;
}

From source file:org.neo4j.desktop.ui.BrowseForDatabaseActionListener.java

private File macFileSelection() {
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
    FileDialog fileDialog = new FileDialog(frame);

    fileDialog.setDirectory(directoryDisplay.getText());
    fileDialog.setVisible(true);

    File selectedFile = new File(fileDialog.getDirectory(), fileDialog.getFile());
    System.setProperty("apple.awt.fileDialogForDirectories", "false");

    return selectedFile;
}

From source file:ustc.sse.rjava.RJavaInterface.java

public String rChooseFile(Rengine re, int newFile) {
    FileDialog fd = new FileDialog(new Frame(), (newFile == 0) ? "Select a file" : "Select a new file",
            (newFile == 0) ? FileDialog.LOAD : FileDialog.SAVE);
    fd.setVisible(true);
    String res = null;//from   ww w . j  a  va  2 s  .  c  om
    if (fd.getDirectory() != null)
        res = fd.getDirectory();
    if (fd.getFile() != null)
        res = (res == null) ? fd.getFile() : (res + fd.getFile());
    return res;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.actions.querycrud.core.actions.SaveQueryToFileTask.java

/**
 * Do in background.//from w w w . jav a2  s .com
 * 
 * @return the void
 * 
 * @throws Exception the exception
 */
@Override
protected Boolean doInBackground() throws Exception {

    boolean result = false;
    QueryStatement query = queryService.getActiveQuery();
    // open file dialog to get save location
    FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(),
            "Select location to save", FileDialog.SAVE);
    fd.setVisible(true);

    String selectedFile = fd.getFile();
    String selectedDirectory = fd.getDirectory();
    fileSelected = fd.getFile();
    if (selectedDirectory != null && selectedFile != null) {
        // save to selected location
        File physicalLocation = new File(selectedDirectory, selectedFile);
        query.setPhysicalLocation(physicalLocation.toURI());
        queryExpressionFileOutputter.save(query, physicalLocation.toURI());

        // notify query has changed
        queryService.queryChanged(query, this);
        // change result to true
        result = true;
    }

    return result;
}