Search in sources :

Example 11 with UserCancelException

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);
    }
}
Also used : FieldDataFileOperationResults(cbit.vcell.field.io.FieldDataFileOperationResults) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) Hashtable(java.util.Hashtable) FieldDataWindowManager(cbit.vcell.client.FieldDataWindowManager) UserCancelException(org.vcell.util.UserCancelException) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) RequestManager(cbit.vcell.client.RequestManager) ClientRequestManager(cbit.vcell.client.ClientRequestManager) SimulationStatus(cbit.vcell.server.SimulationStatus) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 12 with UserCancelException

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);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UserCancelException(org.vcell.util.UserCancelException)

Example 13 with UserCancelException

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;
}
Also used : JButton(javax.swing.JButton) UserCancelException(org.vcell.util.UserCancelException)

Example 14 with UserCancelException

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
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) BitSet(java.util.BitSet) UserCancelException(org.vcell.util.UserCancelException) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) TreeSet(java.util.TreeSet)

Example 15 with UserCancelException

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ISize(org.vcell.util.ISize) Hashtable(java.util.Hashtable) UserCancelException(org.vcell.util.UserCancelException) ImageSizeInfo(cbit.image.ImageSizeInfo)

Aggregations

UserCancelException (org.vcell.util.UserCancelException)44 Hashtable (java.util.Hashtable)15 UtilCancelException (org.vcell.util.UtilCancelException)15 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)14 PropertyVetoException (java.beans.PropertyVetoException)11 DataAccessException (org.vcell.util.DataAccessException)10 Vector (java.util.Vector)9 ActionEvent (java.awt.event.ActionEvent)8 DataFormatException (java.util.zip.DataFormatException)8 BioModel (cbit.vcell.biomodel.BioModel)7 ActionListener (java.awt.event.ActionListener)7 IOException (java.io.IOException)7 Point (java.awt.Point)6 ArrayList (java.util.ArrayList)6 ImageException (cbit.image.ImageException)5 CSGObject (cbit.vcell.geometry.CSGObject)5 GeometryException (cbit.vcell.geometry.GeometryException)5 Structure (cbit.vcell.model.Structure)5 JButton (javax.swing.JButton)5 ProgrammingException (org.vcell.util.ProgrammingException)5