Example usage for java.awt FileDialog setMode

List of usage examples for java.awt FileDialog setMode

Introduction

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

Prototype

public void setMode(int mode) 

Source Link

Document

Sets the mode of the file dialog.

Usage

From source file:Main.java

/**
 * @param jFrame/*from   w w  w .  ja  v  a 2s  .  c  o m*/
 * @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:de.freese.base.swing.mac_os_x.MyApp.java

/**
 * @see//from www  .j  a  va2 s.c  o m
 * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
@Override
public void actionPerformed(final ActionEvent e) {
    Object source = e.getSource();

    if (source == this.quitMI) {
        quit();
    } else {
        if (source == this.optionsMI) {
            preferences();
        } else {
            if (source == this.aboutMI) {
                about();
            } else {
                if (source == this.openMI) {
                    // File:Open action shows a FileDialog for loading displayable images
                    FileDialog openDialog = new FileDialog(this);
                    openDialog.setMode(FileDialog.LOAD);
                    openDialog.setFilenameFilter(new FilenameFilter() {
                        /**
                         * @see java.io.FilenameFilter#accept(java.io.File,
                         * java.lang.String)
                         */
                        @Override
                        public boolean accept(final File dir, final String name) {
                            String[] supportedFiles = ImageIO.getReaderFormatNames();

                            for (String supportedFile : supportedFiles) {
                                if (name.endsWith(supportedFile)) {
                                    return true;
                                }
                            }

                            return false;
                        }
                    });

                    openDialog.setVisible(true);
                    String filePath = openDialog.getDirectory() + openDialog.getFile();

                    if (filePath.length() > 0) {
                        loadImageFile(filePath);
                    }
                }
            }
        }
    }
}

From source file:no.java.swing.SingleSelectionFileDialog.java

private Result showNativeDialog(Component target, boolean open) {
    Window window = target == null ? null : (Frame) SwingUtilities.getWindowAncestor(target);
    FileDialog dialog;
    if (window instanceof Frame) {
        dialog = new FileDialog((Frame) window);
    } else if (window instanceof Dialog) {
        dialog = new FileDialog((Dialog) window);
    } else {//from ww w. j  a va  2s.c  o  m
        throw new IllegalStateException("Unknown window type");
    }
    dialog.setDirectory(previousDirectory.getAbsolutePath());
    dialog.setMode(open ? FileDialog.LOAD : FileDialog.SAVE);
    dialog.setVisible(true);
    if (rememberPreviousLocation) {
        previousDirectory = new File(dialog.getDirectory());
    }
    if (dialog.getFile() == null) {
        return Result.CANCEL;
    }
    selected = new File(dialog.getFile());
    return Result.APPROVE;
}

From source file:org.broad.igv.hic.MainWindow.java

private void loadMenuItemActionPerformed(ActionEvent e) {
    FileDialog dlg = new FileDialog(this);
    dlg.setMode(FileDialog.LOAD);
    dlg.setVisible(true);//from w  w  w .j  av a 2s.  co m
    String file = dlg.getFile();
    if (file != null) {
        try {
            File f = new File(dlg.getDirectory(), dlg.getFile());
            load(f.getAbsolutePath());
        } catch (IOException e1) {
            e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }
}