Search in sources :

Example 1 with UserPreferences

use of cbit.vcell.client.server.UserPreferences 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 2 with UserPreferences

use of cbit.vcell.client.server.UserPreferences in project vcell by virtualcell.

the class ReferenceDataPanel method setUserPreferences.

/**
 * Sets the userPreferences property (cbit.vcell.client.server.UserPreferences) value.
 * @param userPreferences The new value for the property.
 * @see #getUserPreferences
 */
public void setUserPreferences(UserPreferences userPreferences) {
    UserPreferences oldValue = fieldUserPreferences;
    fieldUserPreferences = userPreferences;
    firePropertyChange("userPreferences", oldValue, userPreferences);
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences)

Example 3 with UserPreferences

use of cbit.vcell.client.server.UserPreferences in project vcell by virtualcell.

the class ChooseFile method showBioModelXMLFileChooser.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 */
private File showBioModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    BioModel bioModel = (BioModel) hashTable.get("documentToExport");
    JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
    UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
    TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
    SelectorExtensionFilter forceFileFilter = null;
    {
        Object obj = hashTable.get(FORCE_FILE_FILTER);
        if (obj != null) {
            VCAssert.ofType(obj, SelectorExtensionFilter.class);
            forceFileFilter = (SelectorExtensionFilter) obj;
            VCAssert.assertTrue(forceFileFilter.supports(Selector.FULL_MODEL), "only " + Selector.FULL_MODEL + " filters supported for force file filter");
        }
    }
    if (topLevelWindowManager == null) {
        throw new RuntimeException("toplLevelWindowManager required");
    }
    File defaultPath = userPreferences.getCurrentDialogPath();
    // JFileChooser fileChooser = new JFileChooser(defaultPath);
    VCFileChooser fileChooser = new VCFileChooser(defaultPath);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    final SimulationContext[] simContexts = bioModel.getSimulationContexts();
    boolean spatialDeterministicSim = false;
    boolean nonspatialDeterministicSim = false;
    boolean stochasticSim = false;
    @SuppressWarnings("unused") boolean // add logic to set this
    bnglSim = false;
    for (SimulationContext sc : simContexts) {
        if (sc.getApplicationType() == Application.NETWORK_STOCHASTIC) {
            stochasticSim = true;
        } else {
            if (sc.getGeometry().getDimension() > 0) {
                spatialDeterministicSim = true;
            } else {
                nonspatialDeterministicSim = true;
            }
        }
    }
    FileFilter defaultFileFilter;
    if (forceFileFilter == null) {
        List<FileFilter> dlist = FileFilters.supports(SelectorExtensionFilter.Selector.DEFAULT);
        VCAssert.assertTrue(dlist.size() == 1, "Exactly one filter must be designated default");
        defaultFileFilter = dlist.get(0);
        // use a set to avoid duplicated entries; TreeSet show listing is alphabetical
        Set<FileFilter> filters = new TreeSet<>();
        filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.FULL_MODEL));
        if (spatialDeterministicSim) {
            filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.DETERMINISTIC, SelectorExtensionFilter.Selector.SPATIAL));
        }
        if (nonspatialDeterministicSim) {
            filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.DETERMINISTIC, SelectorExtensionFilter.Selector.NONSPATIAL));
        }
        if (stochasticSim) {
            filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.STOCHASTIC));
        }
        /*add BNGL selector here
		if (bnglSim) {
			filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.BNGL));
		}
		*/
        fileChooser.addChoosableFileFilter(defaultFileFilter);
        for (FileFilter f : filters) {
            if (f == defaultFileFilter) {
                continue;
            }
            fileChooser.addChoosableFileFilter(f);
        }
        /*
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_12);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_21);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_22);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_23);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_24);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_31_CORE);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_31_SPATIAL);
	//	fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CELLML);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SEDML);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_VCML);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MATLABV6);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SMOLDYN_INPUT);
		*/
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SEDML);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_OMEX);
    } else {
        defaultFileFilter = forceFileFilter;
    }
    // remove all selectors
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    // Set the default file filter...
    fileChooser.setFileFilter(defaultFileFilter);
    fileChooser.setSelectedFile(new java.io.File(TokenMangler.fixTokenStrict(bioModel.getName())));
    fileChooser.setDialogTitle("Export Virtual Cell BioModel As...");
    if (fileChooser.showSaveDialog(currentWindow) != JFileChooser.APPROVE_OPTION) {
        // user didn't choose save
        throw UserCancelException.CANCEL_FILE_SELECTION;
    }
    File selectedFile = fileChooser.getSelectedFile();
    FileFilter gfileFilter = fileChooser.getFileFilter();
    VCAssert.ofType(gfileFilter, SelectorExtensionFilter.class);
    // only ExtensionFilters should have been added;
    SelectorExtensionFilter fileFilter = (SelectorExtensionFilter) gfileFilter;
    if (selectedFile == null) {
        // no file selected (no name given)
        throw UserCancelException.CANCEL_FILE_SELECTION;
    }
    final File fileUserSpecified = selectedFile.getCanonicalFile();
    // /
    String selectedFileName = recordAndRemoveExtension(selectedFile.getPath());
    if (extensionUserProvided != null && !extensionUserProvided.isEmpty() && !extensionUserProvided.startsWith(".")) {
        extensionUserProvided = "." + extensionUserProvided;
    }
    if (fileFilter.isValidExtension(extensionUserProvided)) {
        selectedFileName += extensionUserProvided;
    } else {
        selectedFileName += fileFilter.getPrimaryExtension();
    }
    selectedFile = new File(selectedFileName);
    checkForOverwrites(selectedFile, topLevelWindowManager.getComponent(), userPreferences);
    // put the filter in the hash so the export task knows what to do...
    hashTable.put(FILE_FILTER, fileFilter);
    if (fileFilter.supports(SelectorExtensionFilter.Selector.FULL_MODEL)) {
        // nothing more to do in this case
        resetPreferredFilePath(selectedFile, userPreferences);
        return selectedFile;
    }
    // ArrayList<String> applicableAppNameList = new ArrayList<String>();
    ArrayList<SimulationContext> applicableSimContexts = new ArrayList<>();
    for (SimulationContext sc : simContexts) {
        if (sc.getGeometry().getDimension() == 0) {
            if (!fileFilter.supports(SelectorExtensionFilter.Selector.NONSPATIAL)) {
                continue;
            }
        } else if (!fileFilter.supports(SelectorExtensionFilter.Selector.SPATIAL)) {
            continue;
        }
        if (sc.getApplicationType() == Application.NETWORK_STOCHASTIC) {
            if (!fileFilter.supports(SelectorExtensionFilter.Selector.STOCHASTIC)) {
                continue;
            }
        } else if (!fileFilter.supports(SelectorExtensionFilter.Selector.DETERMINISTIC)) {
            continue;
        }
        applicableSimContexts.add(sc);
    }
    /*
		{} else {
			// all apps
			for (int i=0;i<simContexts.length;i++){
				applicableAppNameList.add(simContexts[i].getName());
			}
		}
	 */
    final String exportDesc = fileFilter.getShortDescription();
    List<SimulationContext> all = new ArrayList<>(Arrays.asList(simContexts));
    all.removeAll(applicableSimContexts);
    if (!all.isEmpty()) {
        SimContextAdapter[] removed = adapt(all);
        StringBuilder sb = new StringBuilder();
        sb.append("The following applications are not supported by ");
        sb.append(exportDesc);
        sb.append(" and are not available for exporting: \n\n");
        // sb.append(StringUtils.join(removed,", "));
        for (SimulationContext sc : all) {
            // sb.append("   " + sc.getName() + " ( " + sc.getApplicationType() + " ).\n");
            int dim = sc.getGeometry().getDimension();
            sb.append("   " + sc.getName() + " ( " + sc.getMathType() + ", " + (dim == 0 ? "Non-Spatial" : "Spatial") + " ).\n");
        }
        sb.append("\n");
        sb.append("Press Ok to continue or Cancel to abort.\n");
        String reply = DialogUtils.showOKCancelWarningDialog(currentWindow, "Verify Export", sb.toString());
        if (!SimpleUserMessage.OPTION_OK.equals(reply)) {
            throw UserCancelException.CANCEL_GENERIC;
        }
    }
    SimulationContext chosenSimContext = null;
    if (applicableSimContexts.size() == 1) {
        chosenSimContext = applicableSimContexts.get(0);
    } else /*
		else if (!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_PDF.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_12.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_21.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_22.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_23.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_24.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_CORE.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL.getDescription())) {
			if(fileFilter.getDescription().equals(FileFilters.FILE_FILTER_BNGL.getDescription())) {
				boolean hasReactions = bioModel.getModel().getReactionSteps().length > 0 ? true : false;
				System.out.println(hasReactions);
				if(hasReactions) {					// mixed
					String errMsg = "Simple Reactions cannot be exported to .bngl format.";
					errMsg += "<br>Some information will be lost.";
					errMsg += "<br><br>Continue anyway?";
					errMsg = "<html>" + errMsg + "</html>";
					int dialogButton = JOptionPane.YES_NO_OPTION;
					int returnCode = JOptionPane.showConfirmDialog(topLevelWindowManager.getComponent(), errMsg, "Exporting to .bngl", dialogButton);
					if (returnCode != JOptionPane.YES_OPTION) {
						throw UserCancelException.CANCEL_FILE_SELECTION;
					}
				}
			}

			//String[] applicationNames = (String[])org.vcell.util.BeanUtils.getArray(applicableAppNameList,String.class);
		}	 */
    {
        // String[] applicationNames = applicableAppNameList.toArray(new String[applicableAppNameList.size()]);
        SimContextAdapter[] scarray = adapt(applicableSimContexts);
        String message = "Multiple Applications are compatible with " + exportDesc + "\nPlease select one.\n";
        Object choice = DialogUtils.showListDialog(topLevelWindowManager.getComponent(), scarray, "Application selection", null, message);
        if (choice == null) {
            throw UserCancelException.CANCEL_FILE_SELECTION;
        }
        VCAssert.ofType(choice, SimContextAdapter.class);
        SimContextAdapter sca = (SimContextAdapter) choice;
        chosenSimContext = sca.simCtx;
    }
    hashTable.put(SIM_CONTEXT, chosenSimContext);
    // boolean isSbml = fileFilter.supports(SelectorExtensionFilter.Selector.SBML);
    if (fileFilter.requiresMoreChoices()) {
        ExtensionFilter.ChooseContext ctx = new ExtensionFilter.ChooseContext(hashTable, topLevelWindowManager, currentWindow, chosenSimContext, selectedFile, selectedFileName);
        fileFilter.askUser(ctx);
    }
    {
        boolean showConfirm = false;
        if (fileFilter instanceof SbmlExtensionFilter) {
            SbmlExtensionFilter sbmlef = (SbmlExtensionFilter) fileFilter;
            if (sbmlef.isExportingOverrides()) {
                showConfirm = true;
            }
        }
        if (applicableSimContexts.size() > 1) {
            showConfirm = true;
        }
        // showConfirm = someContextsFiltered;
        if (!showConfirm) {
            final File fileAfterProcessing = selectedFile.getCanonicalFile();
            if (!fileAfterProcessing.equals(fileUserSpecified)) {
                final String nameUserSpecified = fileUserSpecified.getCanonicalPath();
                final String nameAfterProcessing = fileAfterProcessing.getCanonicalPath();
                if (FilenameUtils.indexOfExtension(nameUserSpecified) > 0) {
                    // have extension on user path
                    showConfirm = true;
                } else {
                    // don't prompt if user left extension off
                    String nameAfterNoExtension = FilenameUtils.getFullPath(nameAfterProcessing) + FilenameUtils.getBaseName(nameAfterProcessing);
                    if (!nameAfterNoExtension.equals(nameUserSpecified)) {
                        showConfirm = true;
                    }
                }
            }
        }
        if (showConfirm) {
            // final String exportDesc = fileFilter.getShortDescription();
            StringBuilder sb = new StringBuilder();
            SimContextAdapter[] included = adapt(applicableSimContexts);
            if (fileFilter instanceof SbmlExtensionFilter) {
                SbmlExtensionFilter sbmlef = (SbmlExtensionFilter) fileFilter;
                if (sbmlef.isExportingOverrides()) {
                    String overrideSimName = sbmlef.getSimulationOverrideName();
                    sb.append("Export model from application '" + chosenSimContext.getName() + "', simulation '" + overrideSimName + "' (with overrides) ");
                } else {
                    sb.append("Export model from application '" + chosenSimContext.getName() + "' (default values) ");
                }
            } else {
                sb.append("Export model with simulations ");
                sb.append(StringUtils.join(included, ", "));
            }
            sb.append(" to file of type ");
            sb.append(exportDesc);
            sb.append(' ');
            sb.append(selectedFile.getCanonicalPath());
            sb.append('?');
            String reply = DialogUtils.showOKCancelWarningDialog(currentWindow, "Verify Export", sb.toString());
            if (!SimpleUserMessage.OPTION_OK.equals(reply)) {
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
    }
    resetPreferredFilePath(selectedFile, userPreferences);
    return selectedFile;
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) ArrayList(java.util.ArrayList) JFrame(javax.swing.JFrame) TreeSet(java.util.TreeSet) ExtensionFilter(org.vcell.util.gui.exporter.ExtensionFilter) SelectorExtensionFilter(org.vcell.util.gui.exporter.SelectorExtensionFilter) SbmlExtensionFilter(org.vcell.util.gui.exporter.SbmlExtensionFilter) VCFileChooser(org.vcell.util.gui.VCFileChooser) FileFilter(javax.swing.filechooser.FileFilter) SelectorExtensionFilter(org.vcell.util.gui.exporter.SelectorExtensionFilter) SimulationContext(cbit.vcell.mapping.SimulationContext) File(java.io.File) BioModel(cbit.vcell.biomodel.BioModel) File(java.io.File) SbmlExtensionFilter(org.vcell.util.gui.exporter.SbmlExtensionFilter)

Example 4 with UserPreferences

use of cbit.vcell.client.server.UserPreferences in project vcell by virtualcell.

the class SimulationListPanel method createBatchSimulations.

/**
 * Comment
 */
private void createBatchSimulations() {
    int[] selections = getScrollPaneTable().getSelectedRows();
    if (selections == null || selections.length != 1) {
        throw new RuntimeException("Exactly one template Simulation is required for Batch Creation");
    }
    Vector<Simulation> v = new Vector<Simulation>();
    v.add((Simulation) (ivjSimulationListTableModel1.getValueAt(selections[0])));
    Simulation[] toCopy = (Simulation[]) BeanUtils.getArray(v, Simulation.class);
    if (toCopy == null || toCopy.length != 1) {
        throw new RuntimeException("Exactly one template Simulation is required for Batch Creation");
    }
    int index = -1;
    UserPreferences up = getSimulationWorkspace().getClientSimManager().getUserPreferences();
    Map<Integer, Map<String, String>> batchInputDataMap = new LinkedHashMap<>();
    File batchInputFile = parseBatchInputFile(up, batchInputDataMap);
    if (batchInputFile == null || batchInputDataMap.isEmpty()) {
        System.out.println("Failed to read batch input data file or user canceled");
        return;
    }
    try {
        index = getSimulationWorkspace().createBatchSimulations(toCopy, batchInputDataMap, this);
    } catch (Throwable exc) {
        exc.printStackTrace(System.out);
        PopupGenerator.showErrorDialog(this, exc.getMessage(), exc);
    }
    // set selection back to the template simulation
    getScrollPaneTable().getSelectionModel().setSelectionInterval(index, index);
    getScrollPaneTable().scrollRectToVisible(getScrollPaneTable().getCellRect(index, 0, true));
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) LinkedHashMap(java.util.LinkedHashMap) Simulation(cbit.vcell.solver.Simulation) Vector(java.util.Vector) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File)

Example 5 with UserPreferences

use of cbit.vcell.client.server.UserPreferences in project vcell by virtualcell.

the class ChooseFile method showGeometryModelXMLFileChooser.

// // Check structure sized and select a simulation to export to SBML
// if (isSbml) {
// // get user choice of structure and its size and computes absolute sizes of compartments using the StructureSizeSolver.
// Structure[] structures = bioModel.getModel().getStructures();
// // get the nonspatial simulationContexts corresponding to names in applicableAppNameList
// // This is needed in ApplnSelectionAndStructureSizeInputPanel
// 
// SimulationContext[] applicableSimContexts = applicableSimContext.toArray(new SimulationContext[applicableSimContext.size()]);
// 
// String strucName = null;
// double structSize = 1.0;
// int structSelection = -1;
// int option = JOptionPane.CANCEL_OPTION;
// Simulation chosenSimulation = null;
// 
// ApplnSelectionAndStructureSizeInputPanel applnStructInputPanel = null;
// while (structSelection < 0) {
// applnStructInputPanel = new ApplnSelectionAndStructureSizeInputPanel();
// applnStructInputPanel.setSimContexts(applicableSimContexts);
// applnStructInputPanel.setStructures(structures);
// applnStructInputPanel.setPreferredSize(new java.awt.Dimension(350, 400));
// applnStructInputPanel.setMaximumSize(new java.awt.Dimension(350, 400));
// option = DialogUtils.showComponentOKCancelDialog(currentWindow, applnStructInputPanel, "Select Application and Specify Structure Size to Export:");
// structSelection = applnStructInputPanel.getStructSelectionIndex();
// if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
// break;
// } else if (option == JOptionPane.OK_OPTION && structSelection < 0) {
// DialogUtils.showErrorDialog(currentWindow, "Please select a structure and set its size");
// }
// }
// 
// if (option == JOptionPane.OK_OPTION) {
// applnStructInputPanel.applyStructureNameAndSizeValues();
// strucName = applnStructInputPanel.getSelectedStructureName();
// chosenSimContext = applnStructInputPanel.getSelectedSimContext();
// hashTable.put("selectedSimContext", chosenSimContext);
// 
// GeometryContext geoContext = chosenSimContext.getGeometryContext();
// if (!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL.getDescription())) {
// // calculate structure Sizes only if appln is not spatial
// structSize = applnStructInputPanel.getStructureSize();
// // Invoke StructureSizeEvaluator to compute absolute sizes of compartments if all sizes are not set
// if ( (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) ||
// ((strucName == null || structSize <= 0.0) && (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecified())) ||
// (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) ||
// (!geoContext.isAllSizeSpecifiedPositive() && !geoContext.isAllVolFracAndSurfVolSpecified()) ||
// (geoContext.isAllSizeSpecifiedNull() && !geoContext.isAllVolFracAndSurfVolSpecified()) ) {
// DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment sizes being set. This can be automatically " +
// " computed if the absolute size of at least one compartment and the relative sizes (Surface-to-volume-ratio/Volume-fraction) " +
// " of all compartments are known. Sufficient information is not available to perform this computation." +
// "\n\nThis can be fixed by going back to the application '" + chosenSimContext.getName() + "' and setting structure sizes in the 'StructureMapping' tab.");
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// if (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecified()) {
// Structure chosenStructure = chosenSimContext.getModel().getStructure(strucName);
// StructureMapping chosenStructMapping = chosenSimContext.getGeometryContext().getStructureMapping(chosenStructure);
// StructureSizeSolver.updateAbsoluteStructureSizes(chosenSimContext, chosenStructure, structSize, chosenStructMapping.getSizeParameter().getUnitDefinition());
// }
// } else {
// if (!geoContext.isAllUnitSizeParameterSetForSpatial()) {
// DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment size ratios being set."  +
// "\n\nThis can be fixed by going back to the application '" + chosenSimContext.getName() + "' and setting structure" +
// " size ratios in the 'StructureMapping' tab.");
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// }
// 
// // Select simulation whose overrides need to be exported
// // If simContext doesn't have simulations, don't pop up simulationSelectionPanel
// Simulation[] sims = bioModel.getSimulations(chosenSimContext);
// // display only those simulations that have overrides in the simulationSelectionPanel.
// Vector<Simulation> orSims = new Vector<Simulation>();
// for (int s = 0; (sims != null) && (s < sims.length); s++) {
// if (sims[s].getMathOverrides().hasOverrides()) {
// orSims.addElement(sims[s]);
// }
// }
// Simulation[] overriddenSims = (Simulation[])BeanUtils.getArray(orSims, Simulation.class);
// if (overriddenSims.length > 0) {
// SimulationSelectionPanel simSelectionPanel = new SimulationSelectionPanel();
// simSelectionPanel.setPreferredSize(new java.awt.Dimension(600, 400));
// simSelectionPanel.setMaximumSize(new java.awt.Dimension(600, 400));
// simSelectionPanel.setSimulations(overriddenSims);
// int simOption = DialogUtils.showComponentOKCancelDialog(currentWindow, simSelectionPanel, "Select Simulation whose overrides should be exported:");
// if (simOption == JOptionPane.OK_OPTION) {
// chosenSimulation = simSelectionPanel.getSelectedSimulation();
// if (chosenSimulation != null) {
// hashTable.put("selectedSimulation", chosenSimulation);
// }
// } else if (simOption == JOptionPane.CANCEL_OPTION || simOption == JOptionPane.CLOSED_OPTION) {
// // User did not choose a simulation whose overrides are required to be exported.
// // Without that information, cannot export successfully into SBML,
// // Hence canceling the entire export to SBML operation.
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// }
// } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
// // User did not choose to set size for any structure.
// // Without that information, cannot export successfully into SBML,
// // Hence canceling the entire export to SBML operation.
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// 
// if (chosenSimulation != null) {
// // rename file to contain exported simulation.
// String ext = FilenameUtils.getExtension(selectedFileName);
// String base = FilenameUtils.getBaseName(selectedFileName);
// String path = FilenameUtils.getPath(selectedFileName);
// base += "_"  + TokenMangler.mangleToSName(chosenSimulation.getName());
// selectedFileName = path + base + ext;
// selectedFile.renameTo(new File(selectedFileName));
// }
// resetPreferredFilePath(selectedFile, userPreferences);
// return selectedFile;
// }
/**
 * Export to Geometry
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
private File showGeometryModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    Geometry geom = (Geometry) hashTable.get("documentToExport");
    JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
    UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
    TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
    Component comp = (Component) hashTable.get("component");
    comp = (comp == null ? (currentWindow == null ? (topLevelWindowManager == null ? null : topLevelWindowManager.getComponent()) : currentWindow) : comp);
    File defaultPath = userPreferences.getCurrentDialogPath();
    VCFileChooser fileChooser = new VCFileChooser(defaultPath);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    // fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_VCML);
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
    if (geom.getDimension() > 0) {
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_AVS);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_STL);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PLY);
    }
    // remove all selector
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    // set the default file filter...
    fileChooser.setFileFilter(FileFilters.FILE_FILTER_VCML);
    fileChooser.setSelectedFile(new java.io.File(TokenMangler.fixTokenStrict(geom.getName())));
    fileChooser.setDialogTitle("Export Virtual Cell Geometry As...");
    if (fileChooser.showSaveDialog(comp) != JFileChooser.APPROVE_OPTION) {
        // user didn't choose save
        throw UserCancelException.CANCEL_FILE_SELECTION;
    } else {
        File selectedFile = fileChooser.getSelectedFile();
        javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
        if (selectedFile == null) {
            // no file selected (no name given)
            throw UserCancelException.CANCEL_FILE_SELECTION;
        } else {
            // /
            String selectedFileName = recordAndRemoveExtension(selectedFile.getPath());
            String n = selectedFile.getPath().toLowerCase();
            if (fileFilter == FileFilters.FILE_FILTER_VCML && !n.endsWith(".vcml")) {
                selectedFile = new File(selectedFileName + ".vcml");
            } else if (fileFilter == FileFilters.FILE_FILTER_PDF && !n.endsWith(".pdf")) {
                selectedFile = new File(selectedFileName + ".pdf");
            }
            if (fileFilter == null) {
                throw new Exception("No file save type was selected.");
            }
            checkForOverwrites(selectedFile, comp, userPreferences);
            // put the filter in the hash so the export task knows what to do...
            hashTable.put("fileFilter", fileFilter);
            resetPreferredFilePath(selectedFile, userPreferences);
            return selectedFile;
        }
    }
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException) Geometry(cbit.vcell.geometry.Geometry) JFrame(javax.swing.JFrame) VCFileChooser(org.vcell.util.gui.VCFileChooser) Component(java.awt.Component) File(java.io.File)

Aggregations

UserPreferences (cbit.vcell.client.server.UserPreferences)6 File (java.io.File)5 VCFileChooser (org.vcell.util.gui.VCFileChooser)4 TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)3 JFrame (javax.swing.JFrame)3 FileFilter (javax.swing.filechooser.FileFilter)3 UserCancelException (org.vcell.util.UserCancelException)3 Simulation (cbit.vcell.solver.Simulation)2 BioModel (cbit.vcell.biomodel.BioModel)1 ClientServerManager (cbit.vcell.client.server.ClientServerManager)1 Geometry (cbit.vcell.geometry.Geometry)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathModel (cbit.vcell.mathmodel.MathModel)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Component (java.awt.Component)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 PropertyVetoException (java.beans.PropertyVetoException)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1