use of org.vcell.util.gui.VCFileChooser in project vcell by virtualcell.
the class PythonConfigurationPanel method chooseExecutableFile.
private File chooseExecutableFile(String title, FileFilter fileFilter) {
VCFileChooser fileChooser = new VCFileChooser();
for (String likely : likelyes) {
File f = new File(likely);
if (f.exists() && f.isDirectory()) {
fileChooser = new VCFileChooser(likely);
break;
}
}
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
if (OperatingSystemInfo.getInstance().isWindows()) {
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_EXE);
// Set the default file filter...
fileChooser.setFileFilter(FileFilters.FILE_FILTER_EXE);
// remove all selector
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
}
fileChooser.setDialogTitle(title);
File selectedFile = null;
while (true) {
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
selectedFile = null;
break;
}
selectedFile = fileChooser.getSelectedFile();
if (fileFilter.accept(selectedFile) && selectedFile.exists()) {
break;
}
}
return selectedFile;
}
use of org.vcell.util.gui.VCFileChooser in project vcell by virtualcell.
the class ReactionCartoonTool method showSaveReactionImageDialog.
// TO DO: allow user preferences for directory selection.
public void showSaveReactionImageDialog() throws Exception {
// set file filter
String result = DialogUtils.showInputDialog0(getDialogOwner(getGraphPane()), "Enter pixel width of saved rxdiagram image (height will be proportional)", "800");
int width = Integer.parseInt(result);
SimpleFilenameFilter jpgFilter = new SimpleFilenameFilter("jpg");
final java.io.File defaultFile = new java.io.File(getModel().getName() + ".jpg");
ClientServerManager csm = (ClientServerManager) getDocumentManager().getSessionManager();
UserPreferences userPref = csm.getUserPreferences();
File defaultPath = userPref.getCurrentDialogPath();
VCFileChooser fileChooser = new VCFileChooser(defaultPath);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.addChoosableFileFilter(jpgFilter);
fileChooser.setSelectedFile(defaultFile);
fileChooser.setDialogTitle("Save Image As...");
// name once the user changes the directory.
class FileChooserFix implements java.beans.PropertyChangeListener {
public void propertyChange(java.beans.PropertyChangeEvent ev) {
JFileChooser chooser = (JFileChooser) ev.getSource();
if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(ev.getPropertyName())) {
chooser.setSelectedFile(defaultFile);
}
}
}
fileChooser.addPropertyChangeListener(new FileChooserFix());
// process user input
if (fileChooser.showSaveDialog(getDialogOwner(getGraphPane())) == JFileChooser.APPROVE_OPTION) {
java.io.File selectedFile = fileChooser.getSelectedFile();
if (selectedFile != null) {
if (selectedFile.exists()) {
int question = javax.swing.JOptionPane.showConfirmDialog(getDialogOwner(getGraphPane()), "Overwrite file: " + selectedFile.getPath() + "?");
if (question == javax.swing.JOptionPane.NO_OPTION || question == javax.swing.JOptionPane.CANCEL_OPTION) {
return;
}
}
BufferedImage bufferedImage = ITextWriter.generateDocReactionsImage(this.getModel(), width);
FileOutputStream reactionImageOutputStream = null;
try {
reactionImageOutputStream = new FileOutputStream(selectedFile);
reactionImageOutputStream.write(ITextWriter.encodeJPEG(bufferedImage).toByteArray());
} finally {
try {
if (reactionImageOutputStream != null) {
reactionImageOutputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
// reset the user preference for the default path, if needed.
File newPath = selectedFile.getParentFile();
if (!newPath.equals(defaultPath)) {
userPref.setCurrentDialogPath(newPath);
}
}
}
}
use of org.vcell.util.gui.VCFileChooser in project vcell by virtualcell.
the class ComsolConfigurationPanel method chooseDirectory.
private File chooseDirectory(String title, FileFilter fileFilter) {
VCFileChooser fileChooser = new VCFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
// fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MOV);
// Set the default file filter...
// fileChooser.setFileFilter(FileFilters.FILE_FILTER_MOV);
// remove all selector
// fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
fileChooser.setDialogTitle(title);
File selectedFile = null;
while (true) {
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
selectedFile = null;
break;
}
selectedFile = fileChooser.getSelectedFile();
if (fileFilter.accept(selectedFile) && selectedFile.exists()) {
break;
}
}
return selectedFile;
}
use of org.vcell.util.gui.VCFileChooser in project vcell by virtualcell.
the class PythonConfigurationPanel3 method chooseExecutableFile.
private File chooseExecutableFile(String title, FileFilter fileFilter) {
VCFileChooser fileChooser = new VCFileChooser();
for (String likely : likelyes) {
File f = new File(likely);
if (f.exists() && f.isDirectory()) {
fileChooser = new VCFileChooser(likely);
break;
}
}
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
if (OperatingSystemInfo.getInstance().isWindows()) {
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_EXE);
// Set the default file filter...
fileChooser.setFileFilter(FileFilters.FILE_FILTER_EXE);
// remove all selector
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
}
fileChooser.setDialogTitle(title);
File selectedFile = null;
while (true) {
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
selectedFile = null;
break;
}
selectedFile = fileChooser.getSelectedFile();
if (fileFilter.accept(selectedFile) && selectedFile.exists()) {
break;
}
}
return selectedFile;
}
use of org.vcell.util.gui.VCFileChooser in project vcell by virtualcell.
the class VisItConfigurationPanel method chooseExecutableFile.
private File chooseExecutableFile(String title, FileFilter fileFilter) {
VCFileChooser fileChooser = new VCFileChooser();
for (String likely : likelyes) {
File f = new File(likely);
if (f.exists() && f.isDirectory()) {
fileChooser = new VCFileChooser(likely);
break;
}
}
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
if (OperatingSystemInfo.getInstance().isWindows()) {
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_EXE);
// Set the default file filter...
fileChooser.setFileFilter(FileFilters.FILE_FILTER_EXE);
// remove all selector
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
}
fileChooser.setDialogTitle(title);
File selectedFile = null;
while (true) {
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
selectedFile = null;
break;
}
selectedFile = fileChooser.getSelectedFile();
if (fileFilter.accept(selectedFile) && selectedFile.exists()) {
break;
}
}
return selectedFile;
}
Aggregations