use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class FieldDataGUIPanel method jButtonFDFromSim_ActionPerformed.
private void jButtonFDFromSim_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
try {
final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager();
final FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = FieldDataWindowManager.selectOpenModelsFromDesktop(this, fieldDataWindowManager.getRequestManager(), true, "Select Simulation for Field Data", true);
if (simInfoHolder == null) {
PopupGenerator.showErrorDialog(this, "Please open a Bio or Math model containing the spatial (non-compartmental) simulation you wish to use to create a new Field Data");
return;
}
// Check that the sim is in a state that can be copied
final SimulationInfo simInfo = simInfoHolder.getSimInfo();
if (simInfo == null) {
throw new Exception("Selected sim '" + simInfoHolder.getSimName() + "' has no simInfo (save your model and retry).");
}
SimulationStatus simStatus = clientRequestManager.getServerSimulationStatus(simInfo);
if (simStatus != null && (simStatus.isRunning() || simStatus.isStartRequested())) {
throw new Exception("Can't copy 'running' simulation data from sim '" + simInfo.getName() + "'");
}
final FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createCopySimFieldDataFileOperationSpec(null, (simInfo.getParentSimulationReference() != null ? simInfo.getParentSimulationReference() : simInfo.getSimulationVersion().getVersionKey()), simInfo.getOwner(), simInfoHolder.getJobIndex(), clientRequestManager.getDocumentManager().getUser());
AsynchClientTask[] addTasks = addNewExternalData(this, this, true);
AsynchClientTask[] taskArray = new AsynchClientTask[1 + addTasks.length];
// add to the end
System.arraycopy(addTasks, 0, taskArray, 1, addTasks.length);
taskArray[0] = new AsynchClientTask("Create Field Data from Simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FieldDataFileOperationResults fdor = clientRequestManager.getDocumentManager().fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec((simInfo.getParentSimulationReference() != null ? simInfo.getParentSimulationReference() : simInfo.getSimulationVersion().getVersionKey()), simInfo.getOwner(), simInfoHolder.getJobIndex()));
// Create (non-editable) info for display
fdos.origin = fdor.origin;
fdos.extent = fdor.extent;
fdos.isize = fdor.iSize;
fdos.times = fdor.times;
fdos.varNames = new String[fdor.dataIdentifierArr.length];
for (int i = 0; i < fdor.dataIdentifierArr.length; i += 1) {
fdos.varNames[i] = (fdor.dataIdentifierArr[i].getVariableType().equals(VariableType.VOLUME) ? "(vol) " : "") + (fdor.dataIdentifierArr[i].getVariableType().equals(VariableType.MEMBRANE) ? "(mbr) " : "") + fdor.dataIdentifierArr[i].getName();
}
hashTable.put("fdos", fdos);
hashTable.put("initFDName", simInfo.getName());
// addNewExternalData(clientRequestManager, fdos, simInfoHolder.simInfo.getName(), true);
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hash, taskArray, false);
} catch (UserCancelException e) {
return;
} catch (Exception e) {
PopupGenerator.showErrorDialog(this, "Error creating Field Data from simulation\n" + e.getMessage(), e);
}
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class FieldDataGUIPanel method jButtonFDCopyRef_ActionPerformed.
private void jButtonFDCopyRef_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
if (actionEvent.getSource() == getJButtonCreateGeom()) {
DocumentWindow.showGeometryCreationWarning(FieldDataGUIPanel.this);
return;
}
TreePath selPath = getJTree1().getSelectionPath();
final DefaultMutableTreeNode varNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
final DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) varNode.getParent().getParent();
SelectedTimes selectedTimes = null;
try {
selectedTimes = selectTimeFromNode(mainNode);
} catch (UserCancelException e) {
return;
}
double selectedTime = selectedTimes.getTimes()[selectedTimes.getSelectedIndex()];
if (actionEvent.getSource() == getJButtonFDCopyRef()) {
String fieldFunctionReference = SimulationData.createCanonicalFieldFunctionSyntax(((FieldDataMainList) mainNode.getUserObject()).externalDataIdentifier.getName(), ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getName(), selectedTime, ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getVariableType().getTypeName());
VCellTransferable.sendToClipboard(fieldFunctionReference);
} else if (actionEvent.getSource() == dsDataSymbolButton && dataSymbolCallBack != null) {
dataSymbolCallBack.createDataSymbol(((FieldDataMainList) mainNode.getUserObject()).externalDataIdentifier, ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getName(), ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getVariableType(), selectedTime);
}
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class FieldDataInfoPanel method getJButtonVarNameEdit.
/**
* This method initializes jButtonVarNameEdit
*
* @return javax.swing.JButton
*/
private JButton getJButtonVarNameEdit() {
if (jButtonVarNameEdit == null) {
jButtonVarNameEdit = new JButton();
jButtonVarNameEdit.setText("Edit Var...");
jButtonVarNameEdit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
String newVarName = inputStrictName(jComboBoxVarNames.getSelectedItem().toString(), "Edit Variable Name");
int selIndex = jComboBoxVarNames.getSelectedIndex();
((DefaultComboBoxModel) jComboBoxVarNames.getModel()).removeElementAt(selIndex);
((DefaultComboBoxModel) jComboBoxVarNames.getModel()).insertElementAt(newVarName, selIndex);
jComboBoxVarNames.setSelectedIndex(selIndex);
} catch (UserCancelException e2) {
// ignore
}
}
});
}
return jButtonVarNameEdit;
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ROIMultiPaintManager method askInitialize.
private void askInitialize(boolean bForceAddDistinct) {
final TreeSet<Integer> sortedPixVal = new TreeSet<Integer>();
BitSet uniquePixelBS = new BitSet((int) Math.pow(2, Short.SIZE));
for (int i = 0; i < getImageDataSetChannel().getAllImages().length; i++) {
short[] dataToSegment = getImageDataSetChannel().getAllImages()[i].getPixels();
for (int j = 0; j < dataToSegment.length; j++) {
if ((int) (dataToSegment[j] & 0x0000FFFF) != 0) {
if (!uniquePixelBS.get((int) (dataToSegment[j] & 0x0000FFFF))) {
sortedPixVal.add((int) (dataToSegment[j] & 0x0000FFFF));
}
uniquePixelBS.set((int) (dataToSegment[j] & 0x0000FFFF));
}
}
}
boolean bNotAddDomains = uniquePixelBS.cardinality() >= 256 || /*too many to add*/
!bHasOriginalData || /*no import*/
uniquePixelBS.cardinality() == 0;
final String addROIManual = "1. Add empty Domain";
final String addAllDistinct = "2. Assume Pre-Segmented";
final String cancel = "Cancel";
String result = null;
String distinctDescr = "The current image contains " + uniquePixelBS.cardinality() + " distinct non-zero pixel values.";
if (!bForceAddDistinct) {
result = DialogUtils.showWarningDialog(overlayEditorPanelJAI, "Image Editor", distinctDescr + " Segmenting an image begins with defining Domain(s) manually or automatically." + " Editing tools are used to create/edit more Domains. Choose an action:\n" + "1. Add an 'empty' Domain to begin segmenting manually." + (bNotAddDomains ? "" : "\n2. Pre-Segmented (add Domains for every distinct pixel value)."), (bNotAddDomains ? new String[] { addROIManual, cancel } : new String[] { addROIManual, addAllDistinct, cancel }), cancel);
if (result.equals(cancel)) {
// throw UserCancelException.CANCEL_GENERIC;
return;
}
} else {
if (uniquePixelBS.cardinality() == 0) {
DialogUtils.showWarningDialog(overlayEditorPanelJAI, "Underlay contains no non-zero pixel values available for Domain assignment.");
return;
}
boolean bHasExistingROIs = overlayEditorPanelJAI.getAllCompositeROINamesAndColors() != null && overlayEditorPanelJAI.getAllCompositeROINamesAndColors().length > 0;
result = DialogUtils.showWarningDialog(overlayEditorPanelJAI, (bHasExistingROIs ? "Warning: Existing Domains may be overwritten. " : "") + distinctDescr, new String[] { addAllDistinct, cancel }, addAllDistinct);
if (result.equals(cancel)) {
// throw UserCancelException.CANCEL_GENERIC;
return;
}
}
try {
if (result.equals(addAllDistinct)) {
// try add all distinct, fail if too many regions
final String LOOKUP_KEY = "LOOKUP_KEY";
AsynchClientTask createDistinctROI = new AsynchClientTask("Create distinct ROI...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Integer[] uniquePivValArr = sortedPixVal.toArray(new Integer[0]);
int[] lookup = new int[uniquePivValArr[uniquePivValArr.length - 1] + 1];
Arrays.fill(lookup, -1);
for (int i = 0; i < uniquePivValArr.length; i++) {
lookup[uniquePivValArr[i]] = i + 1;
overlayEditorPanelJAI.addROIName("roi_" + uniquePivValArr[i], false, "roi_" + uniquePivValArr[0], true, i + 1);
}
hashTable.put(LOOKUP_KEY, lookup);
}
};
AsynchClientTask applyDistinctROI = new AsynchClientTask("Apply distinct ROI...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
int[] lookup = (int[]) hashTable.get(LOOKUP_KEY);
for (int i = 0; i < getImageDataSetChannel().getAllImages().length; i++) {
short[] dataToSegment = getImageDataSetChannel().getAllImages()[i].getPixels();
byte[] roiBytes = ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData();
for (int j = 0; j < dataToSegment.length; j++) {
if ((int) (dataToSegment[j] & 0x0000FFFF) != 0) {
roiBytes[j] = (byte) lookup[(int) (dataToSegment[j] & 0x0000FFFF)];
}
}
}
}
};
AsynchClientTask failTask = new AsynchClientTask("Check fail...", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false, true) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Throwable throwable = (Throwable) hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR);
if (throwable != null) {
// cleanup
ComboboxROIName[] comboboxROINames = overlayEditorPanelJAI.getAllCompositeROINamesAndColors();
for (int i = 0; i < comboboxROINames.length; i++) {
overlayEditorPanelJAI.deleteROIName(comboboxROINames[i]);
}
for (int i = 0; i < roiComposite.length; i++) {
byte[] roiBytes = ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData();
Arrays.fill(roiBytes, (byte) 0);
}
}
}
};
AsynchClientTask clearHighlightsTask = new AsynchClientTask("Apply distinct ROI...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
overlayEditorPanelJAI.setHighliteInfo(null, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
}
};
ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { createDistinctROI, applyDistinctROI, createRegionImageTask, failTask, clearHighlightsTask, saveSortRegionImageTask, updateList }, false, false, null, true);
} else {
try {
addNewROI(overlayEditorPanelJAI.getAllCompositeROINamesAndColors(), null);
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(overlayEditorPanelJAI, e.getMessage());
}
}
} catch (UserCancelException e) {
// do nothing
}
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ROIMultiPaintManager method resizeDataset.
private void resizeDataset() {
final ISize currentISize = new ISize(roiComposite[0].getWidth(), roiComposite[0].getHeight(), roiComposite.length);
ImageSizeInfo origImageSizeInfo = new ImageSizeInfo(null, currentISize, 0, new double[] { 0 }, 0);
ImageSizeInfo newImageSizeInfo = null;
try {
newImageSizeInfo = ClientRequestManager.queryImageResize(overlayEditorPanelJAI, origImageSizeInfo, false);
} catch (UserCancelException e) {
return;
}
final ISize newImageSize = newImageSizeInfo.getiSize();
AsynchClientTask resizeTask = new AsynchClientTask("Resizing...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
resizeImpl(ResizeInfo.createScaleResizeInfo(currentISize, newImageSize), getClientTaskStatusSupport());
}
};
final AsynchClientTask updatePanelTask = getUpdateDisplayAfterCropTask();
ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { resizeTask, updatePanelTask }, false, false, null, true);
}
Aggregations