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;
}
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());
}
}
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;
}
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) {
}
}
}
}
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();
}
Aggregations