Search in sources :

Example 36 with JFileChooser

use of javax.swing.JFileChooser in project pcgen by PCGen.

the class NotesView method getImageFromChooser.

/**
	 *  obtains an Image for input using a custom JFileChooser dialog
	 *
	 *@param  startDir  Directory to open JFielChooser to
	 *@param  exts      Extensions to search for
	 *@param  desc      Description for files
	 *@return           File pointing to the selected image
	 */
private File getImageFromChooser(String startDir, String[] exts, String desc) {
    JFileChooser jImageDialog = new JFileChooser();
    jImageDialog.setCurrentDirectory(new File(startDir));
    jImageDialog.setAccessory(new ImageFileChooserPreview(jImageDialog));
    jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG);
    jImageDialog.setFileFilter(new FileNameExtensionFilter(desc, exts));
    jImageDialog.setDialogTitle("Select an Image to Insert");
    int optionSelected = jImageDialog.showDialog(this, "Insert");
    if (optionSelected == JFileChooser.APPROVE_OPTION) {
        return jImageDialog.getSelectedFile();
    }
    return null;
}
Also used : ImageFileChooserPreview(gmgen.gui.ImageFileChooserPreview) JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) Point(java.awt.Point)

Example 37 with JFileChooser

use of javax.swing.JFileChooser in project pcgen by PCGen.

the class PreferencesNotesPanel method browseButtonActionPerformed.

/**
	 * <p>
	 * Handles browsing for a directory.
	 * </p>
	 *
	 * @param e
	 */
protected void browseButtonActionPerformed(ActionEvent e) {
    JFileChooser dlg = new JFileChooser(getDataDir());
    dlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (dlg.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        setDataDir(dlg.getSelectedFile().getAbsolutePath());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 38 with JFileChooser

use of javax.swing.JFileChooser in project ACS by ACS-Community.

the class ScriptFilter method getFileMenuLoadStatusButton.

/**
	 * This method initializes FileMenuLoadStatusButton
	 * @return javax.swing.JMenuItem
	 */
private JMenuItem getFileMenuLoadStatusButton() {
    if (FileMenuLoadStatusButton == null) {
        FileMenuLoadStatusButton = new JMenuItem();
        FileMenuLoadStatusButton.setText("Load GUI Status");
        FileMenuLoadStatusButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                Filter filter = new Filter();
                chooser.setFileFilter(filter);
                int returnVal = chooser.showOpenDialog(cl.utfsm.samplingSystemUI.SamplingSystemGUI.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    try {
                        readStatusFile(chooser.getSelectedFile().getAbsolutePath(), false);
                    } catch (ParserConfigurationException e1) {
                        e1.printStackTrace();
                    } catch (SAXException e1) {
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
    }
    return FileMenuLoadStatusButton;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) ActionEvent(java.awt.event.ActionEvent) SAXException(org.xml.sax.SAXException)

Example 39 with JFileChooser

use of javax.swing.JFileChooser in project ACS by ACS-Community.

the class FeedbackTabs method saveTab.

public void saveTab(FeedbackArea x) {
    // lazy creation
    if (fileChooser == null) {
        fileChooser = new JFileChooser();
    }
    // show save dialog
    int answer = fileChooser.showSaveDialog(this);
    if (answer == JFileChooser.APPROVE_OPTION) {
        File f = null;
        FileWriter fw = null;
        try {
            // write text to file
            f = fileChooser.getSelectedFile();
            fw = new FileWriter(f);
            fw.write(x.outputArea.getText());
            fw.flush();
        } catch (IOException exc) {
            master.log.fine("couldn't save log '" + x.surroundingTabTitle + "' to file '" + f + "' due to " + exc);
        } finally {
            try {
                if (fw != null)
                    fw.close();
            } catch (Exception exc) {
            }
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 40 with JFileChooser

use of javax.swing.JFileChooser in project EnrichmentMapApp by BaderLab.

the class FileBrowser method browseForRootFolderSwing.

private Optional<File> browseForRootFolderSwing(Component parent) {
    JFileChooser chooser = new JFileChooser(getCurrentDirectory());
    chooser.setDialogTitle("Select Root Folder");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        setCurrentDirectory(chooser.getCurrentDirectory());
        return Optional.of(chooser.getSelectedFile());
    }
    return Optional.empty();
}
Also used : JFileChooser(javax.swing.JFileChooser)

Aggregations

JFileChooser (javax.swing.JFileChooser)297 File (java.io.File)178 IOException (java.io.IOException)63 FileFilter (javax.swing.filechooser.FileFilter)40 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)30 ActionEvent (java.awt.event.ActionEvent)27 ActionListener (java.awt.event.ActionListener)22 FileOutputStream (java.io.FileOutputStream)19 JButton (javax.swing.JButton)19 JPanel (javax.swing.JPanel)16 Point (java.awt.Point)14 Preferences (java.util.prefs.Preferences)12 JMenuItem (javax.swing.JMenuItem)12 Component (java.awt.Component)11 FileNotFoundException (java.io.FileNotFoundException)11 JFrame (javax.swing.JFrame)10 JLabel (javax.swing.JLabel)10 ResourceBundle (java.util.ResourceBundle)8 BorderLayout (java.awt.BorderLayout)7 FileDialog (java.awt.FileDialog)7