Search in sources :

Example 6 with VCFileChooser

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;
}
Also used : VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Example 7 with VCFileChooser

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);
            }
        }
    }
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) SimpleFilenameFilter(org.vcell.util.SimpleFilenameFilter) Point(java.awt.Point) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) ClientServerManager(cbit.vcell.client.server.ClientServerManager) JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Example 8 with VCFileChooser

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;
}
Also used : VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Example 9 with VCFileChooser

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;
}
Also used : VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Example 10 with VCFileChooser

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;
}
Also used : VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Aggregations

File (java.io.File)15 VCFileChooser (org.vcell.util.gui.VCFileChooser)15 UserCancelException (org.vcell.util.UserCancelException)5 UserPreferences (cbit.vcell.client.server.UserPreferences)4 TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)3 FileOutputStream (java.io.FileOutputStream)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 Point (java.awt.Point)2 BufferedImage (java.awt.image.BufferedImage)2 PropertyVetoException (java.beans.PropertyVetoException)2 Hashtable (java.util.Hashtable)2 JFrame (javax.swing.JFrame)2 FileFilter (javax.swing.filechooser.FileFilter)2 UtilCancelException (org.vcell.util.UtilCancelException)2 DisplayAdapterService (cbit.image.DisplayAdapterService)1 ImageException (cbit.image.ImageException)1 BioModel (cbit.vcell.biomodel.BioModel)1 ClientServerManager (cbit.vcell.client.server.ClientServerManager)1 ChooseFile (cbit.vcell.client.task.ChooseFile)1 UserDataEntry (cbit.vcell.export.gloworm.atoms.UserDataEntry)1