use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class FieldDataInfoPanel method getJButtonSeqTimes.
/**
* This method initializes jButtonSeqTimes
*
* @return javax.swing.JButton
*/
private JButton getJButtonSeqTimes() {
if (jButtonSeqTimes == null) {
jButtonSeqTimes = new JButton();
jButtonSeqTimes.setText("Sequence...");
jButtonSeqTimes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
String incrS = PopupGenerator.showInputDialog(FieldDataInfoPanel.this, "Enter a uniform Time Step value", "1.0");
double incrVal = Double.parseDouble(incrS);
if (incrVal == 0) {
throw new Exception("Time Step value cannot be 0");
}
double[] newTimes = new double[dataTimes.length];
for (int i = 0; i < dataTimes.length; i += 1) {
newTimes[i] = i * incrVal;
}
initTimes(newTimes);
} catch (UserCancelException e2) {
// ignore
} catch (Exception e2) {
PopupGenerator.showErrorDialog(FieldDataInfoPanel.this, "Error generating sequence\n" + e2.getMessage(), e2);
}
}
});
}
return jButtonSeqTimes;
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ClientRequestManager method createNewDocument.
/**
* Insert the method's description here.
* Creation date: (5/10/2004 3:48:16 PM)
*/
public AsynchClientTask[] createNewDocument(final TopLevelWindowManager requester, final VCDocument.DocumentCreationInfo documentCreationInfo) {
// throws UserCancelException, Exception {
/* asynchronous and not blocking any window */
AsynchClientTask[] taskArray = null;
final int createOption = documentCreationInfo.getOption();
switch(documentCreationInfo.getDocumentType()) {
case BIOMODEL_DOC:
{
AsynchClientTask task1 = new AsynchClientTask("creating biomodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel bioModel = createDefaultBioModelDocument(null);
hashTable.put("doc", bioModel);
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
}
case MATHMODEL_DOC:
{
if ((createOption == VCDocument.MATH_OPTION_NONSPATIAL) || (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS)) {
AsynchClientTask task2 = new AsynchClientTask("creating mathmodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = null;
if (createOption == VCDocument.MATH_OPTION_NONSPATIAL) {
geometry = new Geometry("Untitled", 0);
} else {
geometry = (Geometry) hashTable.get(GEOMETRY_KEY);
}
MathModel mathModel = createMathModel("Untitled", geometry);
mathModel.setName("MathModel" + (getMdiManager().getNumCreatedDocumentWindows() + 1));
hashTable.put("doc", mathModel);
}
};
if (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS) {
AsynchClientTask task1 = createSelectDocTask(requester);
AsynchClientTask task1b = createSelectLoadGeomTask(requester);
taskArray = new AsynchClientTask[] { task1, task1b, task2 };
} else {
taskArray = new AsynchClientTask[] { task2 };
}
break;
} else if (createOption == VCDocument.MATH_OPTION_FROMBIOMODELAPP) {
AsynchClientTask task1 = new AsynchClientTask("select biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// spatial or non-spatial
BioModelInfo bioModelInfo = (BioModelInfo) DialogUtils.getDBTreePanelSelection(requester.getComponent(), getMdiManager().getDatabaseWindowManager().getBioModelDbTreePanel(), "Open", "Select BioModel");
if (bioModelInfo != null) {
// may throw UserCancelException
hashTable.put("bioModelInfo", bioModelInfo);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("find sim contexts in biomodel application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// spatial or non-spatial
// Get the simContexts in the corresponding BioModel
BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
SimulationContext[] simContexts = getDocumentManager().getBioModel(bioModelInfo).getSimulationContexts();
if (simContexts != null) {
// may throw UserCancelException
hashTable.put("simContexts", simContexts);
}
}
};
AsynchClientTask task3 = new AsynchClientTask("create math model from biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
SimulationContext[] simContexts = (SimulationContext[]) hashTable.get("simContexts");
String[] simContextNames = new String[simContexts.length];
if (simContextNames.length == 0) {
throw new RuntimeException("no application is available");
} else {
for (int i = 0; i < simContexts.length; i++) {
simContextNames[i] = simContexts[i].getName();
}
Component component = requester.getComponent();
// Get the simContext names, so that user can choose which simContext math to import
String simContextChoice = (String) PopupGenerator.showListDialog(component, simContextNames, "Please select Application");
if (simContextChoice == null) {
throw UserCancelException.CANCEL_DB_SELECTION;
}
SimulationContext chosenSimContext = null;
for (int i = 0; i < simContexts.length; i++) {
if (simContexts[i].getName().equals(simContextChoice)) {
chosenSimContext = simContexts[i];
break;
}
}
Objects.requireNonNull(chosenSimContext);
BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
// Get corresponding mathDesc to create new mathModel and return.
String newName = bioModelInfo.getVersion().getName() + "_" + chosenSimContext.getName();
MathDescription bioMathDesc = chosenSimContext.getMathDescription();
MathDescription newMathDesc = null;
newMathDesc = new MathDescription(newName + "_" + (new Random()).nextInt());
newMathDesc.setGeometry(bioMathDesc.getGeometry());
newMathDesc.read_database(new CommentStringTokenizer(bioMathDesc.getVCML_database()));
newMathDesc.isValid();
MathModel newMathModel = new MathModel(null);
newMathModel.setName(newName);
newMathModel.setMathDescription(newMathDesc);
hashTable.put("doc", newMathModel);
}
}
};
taskArray = new AsynchClientTask[] { task1, task2, task3 };
break;
} else {
throw new RuntimeException("Unknown MathModel Document creation option value=" + documentCreationInfo.getOption());
}
}
case GEOMETRY_DOC:
{
if (createOption == VCDocument.GEOM_OPTION_1D || createOption == VCDocument.GEOM_OPTION_2D || createOption == VCDocument.GEOM_OPTION_3D) {
// analytic
AsynchClientTask task1 = new AsynchClientTask("creating analytic geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), documentCreationInfo.getOption());
geometry.getGeometrySpec().addSubVolume(new AnalyticSubVolume("subdomain0", new Expression(1.0)));
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
hashTable.put("doc", geometry);
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
}
if (createOption == VCDocument.GEOM_OPTION_CSGEOMETRY_3D) {
// constructed solid geometry
AsynchClientTask task1 = new AsynchClientTask("creating constructed solid geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), 3);
Extent extent = geometry.getExtent();
if (extent != null) {
// create a CSGPrimitive of type cube and scale it to the 'extent' components. Use this as the default or background CSGObject (subdomain).
// This can be considered as the equivalent of subdomain (with expression) 1.0 for analyticSubvolume.
// basic cube
CSGPrimitive cube = new CSGPrimitive("cube", CSGPrimitive.PrimitiveType.CUBE);
// scaled cube
double x = extent.getX();
double y = extent.getY();
double z = extent.getZ();
CSGScale scaledCube = new CSGScale("scale", new Vect3d(x / 2.0, y / 2.0, z / 2.0));
scaledCube.setChild(cube);
// translated scaled cube
CSGTranslation translatedScaledCube = new CSGTranslation("translation", new Vect3d(x / 2, y / 2, z / 2));
translatedScaledCube.setChild(scaledCube);
CSGObject csgObject = new CSGObject(null, "subdomain0", 0);
csgObject.setRoot(translatedScaledCube);
geometry.getGeometrySpec().addSubVolume(csgObject, false);
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
hashTable.put("doc", geometry);
}
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
} else {
throw new RuntimeException("Unknown Geometry Document creation option value=" + documentCreationInfo.getOption());
}
}
default:
{
throw new RuntimeException("Unknown default document type: " + documentCreationInfo.getDocumentType());
}
}
return taskArray;
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ClientRequestManager method openDocument.
public void openDocument(VCDocumentType documentType, DocumentWindowManager requester) {
/* trying to open from database; called by DocumentWindow */
// get an info first
VCDocumentInfo documentInfo = null;
try {
documentInfo = getMdiManager().getDatabaseWindowManager().selectDocument(documentType, requester);
// check whether request comes from a blank, unchanged document window; if so, open in same window, otherwise in a new window
boolean inNewWindow = isDifferentFromBlank(documentType, requester.getVCDocument());
openDocument(documentInfo, requester, inNewWindow);
} catch (UserCancelException uexc) {
System.out.println(uexc);
return;
} catch (Exception exc) {
exc.printStackTrace(System.out);
PopupGenerator.showErrorDialog(requester, "Open document failed\n" + exc.getMessage(), exc);
}
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ClientRequestManager method getGeometryFromDocumentSelection.
public Geometry getGeometryFromDocumentSelection(Component parentComponent, VCDocumentInfo vcDocumentInfo, boolean bClearVersion) throws Exception, UserCancelException {
Geometry geom = null;
if (vcDocumentInfo.getVersionType().equals(VersionableType.BioModelMetaData)) /*documentType == VCDocument.BIOMODEL_DOC*/
{
BioModelInfo bioModelInfo = getDocumentManager().getBioModelInfo(vcDocumentInfo.getVersion().getVersionKey());
BioModelChildSummary bioModelChildSummary = bioModelInfo.getBioModelChildSummary();
if (bioModelChildSummary != null && bioModelChildSummary.getSimulationContextNames() != null) {
Vector<Integer> spatialV = new Vector<Integer>();
for (int i = 0; i < bioModelChildSummary.getSimulationContextNames().length; i++) {
if (bioModelChildSummary.getGeometryDimensions()[i] > 0) {
spatialV.add(i);
}
}
if (spatialV.size() > 0) {
String[] columnNames = new String[] { "Application", "Geometry", "Dimension" };
String[][] rowData = new String[spatialV.size()][3];
for (int i = 0; i < spatialV.size(); i++) {
rowData[i][0] = bioModelChildSummary.getSimulationContextNames()[spatialV.elementAt(i)];
rowData[i][1] = bioModelChildSummary.getGeometryNames()[spatialV.elementAt(i)];
rowData[i][2] = bioModelChildSummary.getGeometryDimensions()[spatialV.elementAt(i)] + "";
}
int[] selection = DialogUtils.showComponentOKCancelTableList(JOptionPane.getFrameForComponent(parentComponent), "Select Geometry", columnNames, rowData, ListSelectionModel.SINGLE_SELECTION);
ModelGeometryOPResults modelGeometryOPResults = (ModelGeometryOPResults) getDocumentManager().getSessionManager().getUserMetaDbServer().doTestSuiteOP(new ModelGeometryOP((BioModelInfo) vcDocumentInfo, rowData[selection[0]][0]));
geom = getDocumentManager().getGeometry(modelGeometryOPResults.getGeometryKey());
// BioModel bioModel = getDocumentManager().getBioModel((BioModelInfo)vcDocumentInfo);
// for (int i = 0; i < bioModel.getSimulationContexts().length; i++) {
// if(bioModel.getSimulationContexts()[i].getName().equals(rowData[selection[0]][0])){
// geom = bioModel.getSimulationContexts()[i].getGeometry();
// break;
// }
// }
} else {
throw new Exception("BioModel '" + bioModelInfo.getVersion().getName() + "' contains no spatial geometries.");
}
} else {
throw new Exception("BioModel '" + bioModelInfo.getVersion().getName() + "' contains no spatial geometries.");
}
} else if (vcDocumentInfo.getVersionType().equals(VersionableType.MathModelMetaData)) /*documentType == VCDocument.MATHMODEL_DOC*/
{
MathModelInfo mathModelInfo = getDocumentManager().getMathModelInfo(vcDocumentInfo.getVersion().getVersionKey());
MathModelChildSummary mathModelChildSummary = mathModelInfo.getMathModelChildSummary();
if (mathModelChildSummary != null) {
if (mathModelChildSummary.getGeometryDimension() > 0) {
ModelGeometryOPResults modelGeometryOPResults = (ModelGeometryOPResults) getDocumentManager().getSessionManager().getUserMetaDbServer().doTestSuiteOP(new ModelGeometryOP((MathModelInfo) vcDocumentInfo));
geom = getDocumentManager().getGeometry(modelGeometryOPResults.getGeometryKey());
// MathModel mathModel = getDocumentManager().getMathModel(mathModelInfo);
// geom = mathModel.getMathDescription().getGeometry();
} else {
throw new Exception("MathModel '" + mathModelInfo.getVersion().getName() + "' contains no spatial geometry.");
}
} else {
throw new Exception("MathModel '" + mathModelInfo.getVersion().getName() + "' contains no spatial geometry.");
}
} else if (vcDocumentInfo.getVersionType().equals(VersionableType.Geometry)) {
geom = getDocumentManager().getGeometry((GeometryInfo) vcDocumentInfo);
if (geom.getDimension() == 0) {
throw new Exception("Error, Only spatial geometries allowed (dimension > 0).");
}
} else {
throw new IllegalArgumentException("Error selecting geometry from document type " + vcDocumentInfo.getVersionType() + ". Must be BioModel,MathModel or Geometry.");
}
if (geom == null) {
throw new Exception("error selecting geometry");
}
if (bClearVersion) {
geom.clearVersion();
}
return geom;
}
Aggregations