Search in sources :

Example 76 with FileDialog

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());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Example 77 with FileDialog

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());
        }
    }
}
Also used : Frame(java.awt.Frame) LWTopFrame(org.vcell.client.logicalwindow.LWTopFrame) URISyntaxException(java.net.URISyntaxException) UtilCancelException(org.vcell.util.UtilCancelException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URL(java.net.URL) FilenameFilter(java.io.FilenameFilter) VCFileChooser(org.vcell.util.gui.VCFileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) FileDialog(java.awt.FileDialog)

Example 78 with FileDialog

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);
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File) FileDialog(java.awt.FileDialog)

Aggregations

FileDialog (java.awt.FileDialog)78 File (java.io.File)43 JFileChooser (javax.swing.JFileChooser)18 Frame (java.awt.Frame)16 IOException (java.io.IOException)16 FilenameFilter (java.io.FilenameFilter)10 Dialog (java.awt.Dialog)8 FileFilter (javax.swing.filechooser.FileFilter)7 FileOutputStream (java.io.FileOutputStream)5 PrintStream (java.io.PrintStream)4 Button (java.awt.Button)3 Dimension (java.awt.Dimension)3 MenuItem (java.awt.MenuItem)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MalformedURLException (java.net.MalformedURLException)3 SQLException (java.sql.SQLException)3 JLabel (javax.swing.JLabel)3 Component (java.awt.Component)2 GridLayout (java.awt.GridLayout)2