use of java.awt.FileDialog in project GCViewer by chewiebug.
the class OpenFile method actionPerformed.
public void actionPerformed(final ActionEvent e) {
if (OSXSupport.isOSX()) {
// there is no way to show a checkbox on the native dialog so
// open a new window instead
FileDialog dialog = new FileDialog(gcViewer, LocalisationHelper.getString("fileopen_dialog_title"), FileDialog.LOAD);
dialog.setMultipleMode(true);
dialog.setVisible(true);
// dialog.setFilenameFilter doesn't do much on OSX
openFiles(dialog.getFiles(), false);
dialog.dispose();
return;
}
openFileView.setShowAddCheckBox(gcViewer.getSelectedGCDocument() != null);
// TODO SWINGWORKER: open at last openposition (directory)
final int val = openFileView.showOpenDialog(gcViewer);
if (val == JFileChooser.APPROVE_OPTION) {
openFiles(openFileView.getSelectedFiles(), openFileView.isAddCheckBoxSelected());
}
}
use of java.awt.FileDialog in project vcell by virtualcell.
the class DocumentWindow method startStopImageJService.
private void startStopImageJService() {
if (ImageJHelper.serviceExists()) {
try {
ImageJHelper.stopService();
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, "Error stopping ImageJ Service: " + e.getMessage());
}
} else {
final String VC_PLUG_CONTINUE = "Continue";
final String CANCEL = "Cancel";
final String NEW_IJ_PLUGIN = "Install new plugin...";
final String CHANGE_IJ_PLUGIN = "Update plugin or Change path...";
Preferences prefs = Preferences.userNodeForPackage(DocumentWindow.class);
String imageJVCellPluginVersion = "vcell-imagej-helper-" + TokenMangler.fixTokenStrict(VCellSoftwareVersion.fromSystemProperty().getSoftwareVersionString()) + ".jar";
String imageJPluginPath = prefs.get(IMAGEJ_PLUGIN_PATH, null);
URL imageJVCellPluginURL = null;
try {
imageJVCellPluginURL = new URL(PropertyLoader.getRequiredProperty(PropertyLoader.imageJVcellPluginURL) + "/" + imageJVCellPluginVersion);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
DialogUtils.showErrorDialog(this, "Error download URL: " + e1.getMessage());
return;
}
String downLoadOption = NEW_IJ_PLUGIN;
// File ijPluginFile = null;
File[] existingVCPlugins = new File[] {};
Boolean bSame = null;
if (imageJPluginPath != null) {
existingVCPlugins = (new File(imageJPluginPath)).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.startsWith("vcell-imagej-helper-") && name.endsWith(".jar");
}
});
if (existingVCPlugins.length > 1) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < existingVCPlugins.length; i++) {
sb.append((i != 0 ? "\n" : "") + existingVCPlugins[i].getName());
}
DialogUtils.showWarningDialog(this, "Found " + existingVCPlugins.length + " installed VCell Imagej plugins:\n" + sb.toString() + "\nRemove the " + existingVCPlugins.length + " plugins from ImageJ directory and start service again.\nPlugin path=" + imageJPluginPath);
return;
}
if (existingVCPlugins.length == 1) {
downLoadOption = CHANGE_IJ_PLUGIN;
if (imageJVCellPluginVersion.equals(existingVCPlugins[0].getName())) {
bSame = true;
} else {
bSame = false;
}
}
}
String[] options = (existingVCPlugins.length == 0 ? new String[] { downLoadOption, CANCEL } : new String[] { VC_PLUG_CONTINUE, downLoadOption, CANCEL });
String result = DialogUtils.showWarningDialog(this, "Start VCell's FIJI Service", "VCell's FIJI (ImageJ) service allows scripts running in FIJI to communicate with VCell " + "allowing query, control, and transfer of model/simulation data between VCell and FIJI.\n" + "(see Help->'VCell Help' then search 'start imagej service')\n" + (existingVCPlugins.length == 0 ? "Install FIJI (https://imagej.net/Fiji) before starting this service." : "Current plugin path:\n" + existingVCPlugins[0].getAbsolutePath() + "\n" + "Available version=" + imageJVCellPluginVersion), options, CANCEL);
if (NEW_IJ_PLUGIN.equals(result) || CHANGE_IJ_PLUGIN.equals(result)) {
File selectedDir = null;
if (OperatingSystemInfo.getInstance().isMac()) {
Frame f = (Frame) BeanUtils.findTypeParentOfComponent(this, Frame.class);
System.setProperty("apple.awt.fileDialogForDirectories", "true");
FileDialog fdiag = new FileDialog(f);
fdiag.setMultipleMode(false);
if (existingVCPlugins.length == 1) {
fdiag.setDirectory(existingVCPlugins[0].getParentFile().getParentFile().getAbsolutePath());
fdiag.setDirectory(existingVCPlugins[0].getParentFile().getAbsolutePath());
}
fdiag.setVisible(true);
File[] files = fdiag.getFiles();
if (files == null || files.length == 0) {
return;
}
selectedDir = files[0];
} else {
VCFileChooser vcf = new VCFileChooser((existingVCPlugins.length == 0 ? ResourceUtil.getUserHomeDir() : existingVCPlugins[0].getParentFile().getParentFile()));
vcf.setMultiSelectionEnabled(false);
if (existingVCPlugins.length == 1) {
vcf.setSelectedFile(existingVCPlugins[0].getParentFile());
}
vcf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = vcf.showOpenDialog(this);
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
selectedDir = vcf.getSelectedFile();
}
try {
if (!selectedDir.getName().equals("plugins")) {
String pluginWarn = DialogUtils.showOKCancelWarningDialog(this, "Unexpected plugins directory warning", "path " + selectedDir.getAbsolutePath() + "\nexpected to end with 'plugins'");
if (pluginWarn == null || !pluginWarn.equals(SimpleUserMessage.OPTION_OK)) {
return;
}
}
final File pluginDestination = new File(selectedDir, imageJVCellPluginVersion);
FileUtils.copyURLToFile(imageJVCellPluginURL, pluginDestination);
prefs.put(IMAGEJ_PLUGIN_PATH, selectedDir.getAbsolutePath());
if (existingVCPlugins.length != 0 && bSame != null && !bSame) {
if (!existingVCPlugins[0].delete()) {
throw new Exception("Couldn't delete old plugin " + existingVCPlugins[0].getAbsolutePath() + ". Please stop Imagej and manually remove the old plugin file.");
}
}
DialogUtils.showInfoDialog(this, "VCell ImageJ plugin installed at:\n" + pluginDestination.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage());
return;
}
} else if (!VC_PLUG_CONTINUE.equals(result)) {
return;
}
try {
ImageJHelper.startService(null);
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, "error starting ImageJ Service: " + e.getMessage());
}
}
}
use of java.awt.FileDialog in project propane by ruby-processing.
the class ShimAWT method selectImpl.
/*
// Will remove the 'sketch' parameter once we get an upstream JOGL fix
// https://github.com/processing/processing/issues/3831
static protected void selectEvent(final String prompt,
final String callbackMethod,
final File defaultSelection,
final Object callbackObject,
final Frame parentFrame,
final int mode,
final PApplet sketch) {
EventQueue.invokeLater(new Runnable() {
public void run() {
boolean hide = (sketch != null) &&
(sketch.g instanceof PGraphicsOpenGL) &&
(PApplet.platform == PConstants.WINDOWS);
if (hide) sketch.getSurface().setVisible(false);
selectImpl(prompt, callbackMethod, defaultSelection, callbackObject,
parentFrame, mode, sketch);
if (hide) sketch.getSurface().setVisible(true);
}
});
}
*/
public static void selectImpl(final String prompt, final String callbackMethod, final File defaultSelection, final Object callbackObject, final Frame parentFrame, final int mode) {
File selectedFile = null;
if (PApplet.useNativeSelect) {
FileDialog dialog = new FileDialog(parentFrame, prompt, mode);
if (defaultSelection != null) {
dialog.setDirectory(defaultSelection.getParent());
dialog.setFile(defaultSelection.getName());
}
dialog.setVisible(true);
String directory = dialog.getDirectory();
String filename = dialog.getFile();
if (filename != null) {
selectedFile = new File(directory, filename);
}
} else {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(prompt);
if (defaultSelection != null) {
chooser.setSelectedFile(defaultSelection);
}
int result = -1;
if (mode == FileDialog.SAVE) {
result = chooser.showSaveDialog(parentFrame);
} else if (mode == FileDialog.LOAD) {
result = chooser.showOpenDialog(parentFrame);
}
if (result == JFileChooser.APPROVE_OPTION) {
selectedFile = chooser.getSelectedFile();
}
}
PApplet.selectCallback(selectedFile, callbackMethod, callbackObject);
}
Aggregations