Search in sources :

Example 96 with JFileChooser

use of javax.swing.JFileChooser in project android_frameworks_base by crdroidandroid.

the class UI method showOpenDialog.

public File[] showOpenDialog(boolean multi) {
    // Hide the wait dialog...
    if (currentWaitDialog != null) {
        currentWaitDialog.setVisible(false);
    }
    try {
        if (jfc == null) {
            jfc = new JFileChooser();
        }
        jfc.setMultiSelectionEnabled(multi);
        int ret = jfc.showOpenDialog(this);
        if (ret == JFileChooser.APPROVE_OPTION) {
            return jfc.getSelectedFiles();
        } else {
            return null;
        }
    } finally {
        // And reshow it afterwards...
        if (currentWaitDialog != null) {
            showWaitDialogLater();
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 97 with JFileChooser

use of javax.swing.JFileChooser in project processdash by dtuma.

the class TeamDataDirPanel method actionPerformed.

/**
     *  Actions-handling method.
     *
     * @param  e  The event.
     */
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == textField) {
        parent.navigateNext();
    } else {
        // The user wants to browse its filesystem
        // Prepares the file chooser
        JFileChooser fc = new JFileChooser();
        fc.setCurrentDirectory(new File(textField.getText()));
        fc.setMultiSelectionEnabled(false);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
        // Shows it
        if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
            textField.setText(fc.getSelectedFile().getAbsolutePath());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 98 with JFileChooser

use of javax.swing.JFileChooser in project processdash by dtuma.

the class SaveBackupAction method getDestFile.

private File getDestFile(String defaultFilename) {
    JFileChooser fc = new JFileChooser();
    fc.setAcceptAllFileFilterUsed(false);
    fc.setSelectedFile(new File(getDefaultDirectory(fc), defaultFilename));
    fc.setDialogTitle(resources.getString("Save_Backup.Window_Title"));
    String defaultType = Settings.getVal(TYPE_PREF, ZIP);
    for (String type : BACKUP_FILE_TYPES) {
        ExampleFileFilter filter = makeFilter(type);
        fc.addChoosableFileFilter(filter);
        if (type.equalsIgnoreCase(defaultType))
            fc.setFileFilter(filter);
    }
    if (fc.showSaveDialog(null) != JFileChooser.APPROVE_OPTION)
        return null;
    File dest = fc.getSelectedFile();
    saveDefaultDirectory(dest);
    if (dest == null)
        return null;
    ExampleFileFilter ff = (ExampleFileFilter) fc.getFileFilter();
    File result = ff.maybeAppendExtension(dest);
    String resultType = ff.getExtension(result);
    if (StringUtils.hasValue(resultType))
        InternalSettings.set(TYPE_PREF, resultType);
    return result;
}
Also used : JFileChooser(javax.swing.JFileChooser) ExampleFileFilter(net.sourceforge.processdash.ui.lib.ExampleFileFilter) File(java.io.File)

Example 99 with JFileChooser

use of javax.swing.JFileChooser in project processdash by dtuma.

the class WBSSaveAsAction method getDestinationFile.

private File getDestinationFile() {
    // prompt the user to select a file to save to
    JFileChooser fileChooser = makeFileChooser();
    int userChoice = fileChooser.showSaveDialog(wbsEditor.frame);
    openAction.lastDirectory = fileChooser.getCurrentDirectory();
    if (userChoice != JFileChooser.APPROVE_OPTION)
        return null;
    // if they selected a file that did not end with the "zip" suffix,
    // append it
    File f = fileChooser.getSelectedFile();
    if (f != null && !f.getName().toLowerCase().endsWith(".zip"))
        f = new File(f.getParentFile(), f.getName() + ".zip");
    if (f.isFile()) {
        String title = resources.getString("Overwrite.Title");
        String message = resources.format("Overwrite.Message_FMT", f.getPath());
        userChoice = JOptionPane.showConfirmDialog(wbsEditor.frame, message, title, JOptionPane.OK_CANCEL_OPTION);
        if (userChoice != JOptionPane.OK_OPTION)
            f = null;
    }
    return f;
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 100 with JFileChooser

use of javax.swing.JFileChooser in project processdash by dtuma.

the class SaveAsExcelAction method getOutputFile.

private File getOutputFile() {
    if (fileChooser == null) {
        fileChooser = new JFileChooser();
        fileChooser.setDialogTitle(resources.getString("Dialog_Title"));
        fileChooser.setFileFilter(new ExcelFileFilter());
    }
    if (lastFileSelected != null)
        fileChooser.setSelectedFile(lastFileSelected);
    Component parent = SwingUtilities.getWindowAncestor(getWBSTabPanel());
    int userOption = fileChooser.showSaveDialog(parent);
    if (userOption != JFileChooser.APPROVE_OPTION)
        return null;
    File result = fileChooser.getSelectedFile();
    if (result == null)
        return null;
    String filename = result.getName();
    if (filename.indexOf('.') == -1) {
        filename = filename + EXCEL_SUFFIX;
        result = new File(result.getParentFile(), filename);
    }
    lastFileSelected = result;
    return result;
}
Also used : JFileChooser(javax.swing.JFileChooser) Component(java.awt.Component) File(java.io.File)

Aggregations

JFileChooser (javax.swing.JFileChooser)797 File (java.io.File)571 IOException (java.io.IOException)185 FileFilter (javax.swing.filechooser.FileFilter)109 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)96 ActionEvent (java.awt.event.ActionEvent)59 ActionListener (java.awt.event.ActionListener)48 JButton (javax.swing.JButton)44 JPanel (javax.swing.JPanel)40 Component (java.awt.Component)39 FileOutputStream (java.io.FileOutputStream)39 FileNotFoundException (java.io.FileNotFoundException)30 JMenuItem (javax.swing.JMenuItem)29 Point (java.awt.Point)28 ArrayList (java.util.ArrayList)28 FileWriter (java.io.FileWriter)25 Dimension (java.awt.Dimension)24 PrintWriter (java.io.PrintWriter)24 JLabel (javax.swing.JLabel)22 JFrame (javax.swing.JFrame)21