Search in sources :

Example 1 with GraphEvent

use of cbit.gui.graph.GraphEvent in project vcell by virtualcell.

the class StructureMappingCartoon method refreshAll.

@Override
public void refreshAll() {
    {
        if (getGeometryContext() == null || getGeometryContext().getGeometry() == null) {
            return;
        }
        GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
        if (geometryClasses == null) {
            return;
        }
        for (int i = 0; i < geometryClasses.length; i++) {
            Shape testShape = getShapeFromModelObject(geometryClasses[i]);
            if (testShape instanceof GeometryClassLegendShape) {
                geometryClasses[i].removePropertyChangeListener((GeometryClassLegendShape) testShape);
            }
        }
    }
    clearAllShapes();
    if (getSimulationContext() == null) {
        fireGraphChanged(new GraphEvent(this));
        return;
    }
    GeometryContextGeometryShape geometryShape = new GeometryContextGeometryShape(this, getGeometryContext().getGeometry());
    GeometryContextStructureShape structureContainerShape = new GeometryContextStructureShape(this, getGeometryContext().getModel());
    GeometryContextContainerShape containerShape = new GeometryContextContainerShape(this, getGeometryContext(), structureContainerShape, geometryShape);
    addShape(containerShape);
    addShape(geometryShape);
    addShape(structureContainerShape);
    getGeometryContext().removePropertyChangeListener(this);
    getGeometryContext().addPropertyChangeListener(this);
    // create all StructureShapes
    Structure[] structures = getGeometryContext().getModel().getStructures();
    for (int i = 0; i < structures.length; i++) {
        StructureMappingStructureShape smShape = new StructureMappingStructureShape((Structure) structures[i], getGeometryContext().getModel(), this);
        addShape(smShape);
        structureContainerShape.addChildShape(smShape);
        structures[i].removePropertyChangeListener(this);
        structures[i].addPropertyChangeListener(this);
    }
    // create all SubvolumeLegendShapes (for legend)
    GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
    for (int i = 0; i < geometryClasses.length; i++) {
        GeometryClassLegendShape geometryClassLegendShape = new GeometryClassLegendShape(geometryClasses[i], getGeometryContext().getGeometry(), this, 10);
        geometryClasses[i].addPropertyChangeListener(geometryClassLegendShape);
        addShape(geometryClassLegendShape);
        geometryShape.addChildShape(geometryClassLegendShape);
    }
    if ((subVolumeContainerShape == null) || (subVolumeContainerShape.getModelObject() != getGeometryContext().getGeometry())) {
        subVolumeContainerShape = new SubVolumeContainerShape(getGeometryContext().getGeometry(), this);
    }
    subVolumeContainerShape.removeAllChildren();
    subVolumeContainerShape.setBrightImage(getGeometryContext().getGeometry().getGeometrySpec().getThumbnailImage().getCurrentValue());
    addShape(subVolumeContainerShape);
    geometryShape.addChildShape(subVolumeContainerShape);
    StructureMapping[] structureMappings = getGeometryContext().getStructureMappings();
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping structureMapping = structureMappings[i];
        structureMapping.removePropertyChangeListener(this);
        structureMapping.addPropertyChangeListener(this);
        if (structureMapping.getGeometryClass() != null) {
            StructureShape sShape = (StructureShape) getShapeFromModelObject(structureMapping.getStructure());
            GeometryClassLegendShape geometryClassLegendShape = (GeometryClassLegendShape) getShapeFromModelObject(structureMapping.getGeometryClass());
            StructureMappingShape smShape = new StructureMappingShape(structureMapping, sShape, geometryClassLegendShape, this);
            addShape(smShape);
            containerShape.addChildShape(smShape);
        }
    }
    // // assign children to shapes according to heirarchy in Model
    // int nullParentCount=0;
    // Collection<Shape> shapes = getShapes();
    // for(Shape shape : shapes) {
    // // for each featureShape, find corresponding featureShape
    // if (shape instanceof StructureShape){
    // StructureShape fs = (FeatureShape)shape;
    // if(!structureContainerShape.contains(fs)) {
    // structureContainerShape.addChildShape(fs);
    // }
    // nullParentCount++;
    // }
    // }
    fireGraphChanged(new GraphEvent(this));
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Shape(cbit.gui.graph.Shape) StructureMapping(cbit.vcell.mapping.StructureMapping) GraphEvent(cbit.gui.graph.GraphEvent) Structure(cbit.vcell.model.Structure)

Example 2 with GraphEvent

use of cbit.gui.graph.GraphEvent in project vcell by virtualcell.

the class ConstraintsGraphModel method refreshAll.

public void refreshAll() {
    Set<Shape> unwantedShapes = new HashSet<Shape>();
    unwantedShapes.addAll(getShapes());
    for (Shape shape : getShapes()) {
        if (shape instanceof ConstraintVarNode) {
            ((ConstraintVarNode) shape).setDegree(1);
        }
    }
    ContainerShape containerShape = (ContainerShape) getShapeFromModelObject(getConstraintContainerImpl());
    if (containerShape == null) {
        containerShape = new SimpleContainerShape(getConstraintContainerImpl(), this, "constraint network");
        containerShape.setLabel("constraint network");
        addShape(containerShape);
    }
    containerShape.refreshLabel();
    unwantedShapes.remove(containerShape);
    // 
    // add nodes for GeneralConstraints and edges to its Variables (add Variable when necessary)
    // 
    GeneralConstraint[] generalConstraints = getConstraintContainerImpl().getGeneralConstraints();
    for (int i = 0; i < generalConstraints.length; i++) {
        String[] symbols = generalConstraints[i].getExpression().getSymbols();
        if (symbols == null) {
            continue;
        }
        GeneralConstraintNode generalConstraintNode = (GeneralConstraintNode) getShapeFromModelObject(generalConstraints[i]);
        if (generalConstraintNode == null) {
            generalConstraintNode = new GeneralConstraintNode(generalConstraints[i], this, symbols.length);
            containerShape.addChildShape(generalConstraintNode);
            addShape(generalConstraintNode);
        }
        generalConstraintNode.refreshLabel();
        unwantedShapes.remove(generalConstraintNode);
        for (int j = 0; j < symbols.length; j++) {
            ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(symbols[j]);
            if (constraintVarNode == null) {
                constraintVarNode = new ConstraintVarNode(symbols[j], this, 1);
                containerShape.addChildShape(constraintVarNode);
                addShape(constraintVarNode);
            } else {
                constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
            }
            constraintVarNode.refreshLabel();
            unwantedShapes.remove(constraintVarNode);
            ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
            for (Shape shape : getShapes()) {
                if (shape instanceof ConstraintDependencyEdgeShape) {
                    if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == generalConstraintNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                        constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                    }
                }
            }
            if (constraintDependencyEdgeShape == null) {
                constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(generalConstraintNode, constraintVarNode, this);
                containerShape.addChildShape(constraintDependencyEdgeShape);
                addShape(constraintDependencyEdgeShape);
            }
            unwantedShapes.remove(constraintDependencyEdgeShape);
        }
    }
    // 
    // add nodes for SimpleBounds and edges to its Variables (add Variable when necessary)
    // 
    cbit.vcell.constraints.SimpleBounds[] simpleBounds = getConstraintContainerImpl().getSimpleBounds();
    for (int i = 0; i < simpleBounds.length; i++) {
        BoundsNode boundsNode = (BoundsNode) getShapeFromModelObject(simpleBounds[i]);
        if (boundsNode == null) {
            boundsNode = new BoundsNode(simpleBounds[i], this);
            containerShape.addChildShape(boundsNode);
            addShape(boundsNode);
        }
        boundsNode.refreshLabel();
        unwantedShapes.remove(boundsNode);
        ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(simpleBounds[i].getIdentifier());
        if (constraintVarNode == null) {
            constraintVarNode = new ConstraintVarNode(simpleBounds[i].getIdentifier(), this, 1);
            containerShape.addChildShape(constraintVarNode);
            addShape(constraintVarNode);
        } else {
            constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
        }
        constraintVarNode.refreshLabel();
        unwantedShapes.remove(constraintVarNode);
        ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
        for (Shape shape : getShapes()) {
            if (shape instanceof ConstraintDependencyEdgeShape) {
                if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == boundsNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                    constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                }
            }
        }
        if (constraintDependencyEdgeShape == null) {
            constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(boundsNode, constraintVarNode, this);
            containerShape.addChildShape(constraintDependencyEdgeShape);
            addShape(constraintDependencyEdgeShape);
        }
        constraintDependencyEdgeShape.refreshLabel();
        unwantedShapes.remove(constraintDependencyEdgeShape);
    }
    for (Shape unwantedShape : unwantedShapes) {
        removeShape(unwantedShape);
    }
    fireGraphChanged(new GraphEvent(this));
}
Also used : SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) SimpleBounds(cbit.vcell.constraints.SimpleBounds) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) GraphEvent(cbit.gui.graph.GraphEvent) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) HashSet(java.util.HashSet)

Example 3 with GraphEvent

use of cbit.gui.graph.GraphEvent in project vcell by virtualcell.

the class StructureMappingCartoon method refreshAll.

/**
 * This method was created by a SmartGuide.
 */
@Override
public void refreshAll() {
    clearAllShapes();
    if (getSimulationContext() == null) {
        fireGraphChanged(new GraphEvent(this));
        return;
    }
    GeometryContextGeometryShape geometryShape = new GeometryContextGeometryShape(this, getGeometryContext().getGeometry());
    // GeometryContextStructureShape structureShape = new GeometryContextStructureShape(this,getGeometryContext().getModel());
    // GeometryContextContainerShape containerShape = new GeometryContextContainerShape(this,getGeometryContext(),structureShape,geometryShape);
    // addShape(containerShape);
    addShape(geometryShape);
    // addShape(structureShape);
    getGeometryContext().removePropertyChangeListener(this);
    getGeometryContext().addPropertyChangeListener(this);
    // 
    // create all StructureShapes
    // 
    // Structure structures[] = getGeometryContext().getModel().getStructures();
    // for (int i=0;i<structures.length;i++){
    // if (structures[i] instanceof Feature){
    // //addShape(new FeatureShape((Feature)structures[i],getGeometryContext().getModel(),this));
    // StructureMappingFeatureShape smShape = new StructureMappingFeatureShape((Feature)structures[i],getGeometryContext().getModel(),this);
    // addShape(smShape);
    // containerShape.addChildShape(smShape);
    // structures[i].removePropertyChangeListener(this);
    // structures[i].addPropertyChangeListener(this);
    // }
    // }
    // create all SubvolumeLegendShapes (for legend)
    // 
    GeometrySpec geometrySpec = getGeometryContext().getGeometry().getGeometrySpec();
    SubVolume[] subVolumes = geometrySpec.getSubVolumes();
    for (int i = 0; i < subVolumes.length; i++) {
        cbit.vcell.geometry.SubVolume subvolume = subVolumes[i];
        GeometryClassLegendShape subvolumeLegendShape = new GeometryClassLegendShape(subvolume, getGeometryContext().getGeometry(), this, 10);
        addShape(subvolumeLegendShape);
        geometryShape.addChildShape(subvolumeLegendShape);
    }
    // --------------------------------------------------
    if ((subVolumeContainerShape == null) || (subVolumeContainerShape.getModelObject() != getGeometryContext().getGeometry())) {
        subVolumeContainerShape = new SubVolumeContainerShape(getGeometryContext().getGeometry(), this);
    }
    subVolumeContainerShape.removeAllChildren();
    addShape(subVolumeContainerShape);
    geometryShape.addChildShape(subVolumeContainerShape);
    // --------------------------------------------------
    // // create all SubvolumeShapes (for image)
    // //
    // for (int i=0;i<subVolumes.length;i++){
    // cbit.vcell.geometry.SubVolume subvolume = (cbit.vcell.geometry.SubVolume)subVolumes[i];
    // SubvolumeShape subvolumeShape = new SubvolumeShape(subvolume,getGeometryContext().getGeometry(),this);
    // addShape(subvolumeShape);
    // subVolumeContainerShape.addChildShape(subvolumeShape);
    // }
    // 
    // create all FeatureMappingShapes
    // 
    // StructureMapping structureMappings[] = getGeometryContext().getStructureMappings();
    // for (int i=0;i<structureMappings.length;i++){
    // StructureMapping structureMapping = structureMappings[i];
    // if (structureMapping instanceof FeatureMapping){
    // FeatureMapping featureMapping = (FeatureMapping)structureMapping;
    // if (featureMapping.getSubVolume()!=null){
    // FeatureShape featureShape = (FeatureShape)getShapeFromModelObject(featureMapping.getFeature());
    // SubvolumeLegendShape subvolumeLegendShape = (SubvolumeLegendShape)getShapeFromModelObject(featureMapping.getSubVolume());
    // FeatureMappingShape fmShape = new FeatureMappingShape(featureMapping,featureShape,subvolumeLegendShape,this);
    // //FeatureMappingShape fmShape = new FeatureMappingShape(featureMapping,featureShape,featureMapping.getSubVolume(),imageShape,this);
    // addShape(fmShape);
    // containerShape.addChildShape(fmShape);
    // }
    // }
    // }
    // 
    // assign children to shapes according to heirarchy in Model
    // 
    // int nullParentCount=0;
    // Enumeration enum_shape = getShapes();
    // while (enum_shape.hasMoreElements()){
    // Shape shape = (Shape)enum_shape.nextElement();
    // //
    // // for each featureShape, find corresponding featureShape
    // //
    // if (shape instanceof FeatureShape){
    // FeatureShape fs = (FeatureShape)shape;
    // Membrane membrane = fs.getFeature().getMembrane();
    // if (membrane!=null){
    // //
    // // add this feature as child to parent feature
    // //
    // Feature parentFeature = membrane.getOutsideFeature();
    // FeatureShape parentFeatureShape = (FeatureShape)getShapeFromModelObject(parentFeature);
    // if (!parentFeatureShape.contains(fs)){
    // parentFeatureShape.addChildShape(fs);
    // }
    // }else{
    // if (!structureShape.contains(fs)){
    // structureShape.addChildShape(fs);
    // }
    // nullParentCount++;
    // }
    // }
    // }
    fireGraphChanged(new GraphEvent(this));
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) GeometryClassLegendShape(cbit.vcell.graph.GeometryClassLegendShape) SubVolume(cbit.vcell.geometry.SubVolume) GeometryContextGeometryShape(cbit.vcell.graph.GeometryContextGeometryShape) GraphEvent(cbit.gui.graph.GraphEvent) SubVolume(cbit.vcell.geometry.SubVolume) SubVolumeContainerShape(cbit.vcell.graph.SubVolumeContainerShape)

Example 4 with GraphEvent

use of cbit.gui.graph.GraphEvent in project vcell by virtualcell.

the class ReactionCartoonFull method refreshAll.

@Override
protected void refreshAll(boolean reallocateShapes) {
    try {
        if (getModel() == null || getStructureSuite() == null) {
            return;
        }
        System.out.println("ReactionCartoonFull, RefreshAll()");
        for (Structure structure : structureSuite.getStructures()) {
            Diagram diagram = getModel().getDiagram(structure);
            if (diagram != null) {
                // Maintain consistency between rule participant nodes, signatures and
                // species pattern when a molecule is being modified.
                rebindAll(diagram);
            }
        }
        // calculate species context weight (number of reactions for which it's a participant)
        Map<SpeciesContext, Integer> scWeightMap = new HashMap<>();
        // all the species contexts that are catalysts
        Set<SpeciesContext> scCatalystSet = new HashSet<>();
        // calculate species context length (number of species patterns it contains, 1 if has no species patterns)
        for (ReactionStep rs : getModel().getReactionSteps()) {
            ReactionParticipant[] rpList = rs.getReactionParticipants();
            for (int i = 0; i < rpList.length; i++) {
                ReactionParticipant rp = rpList[i];
                SpeciesContext sc = rp.getSpeciesContext();
                // int increment = rp.getStoichiometry();
                int increment = 1;
                if (rp instanceof Catalyst) {
                    scCatalystSet.add(sc);
                }
                if (scWeightMap.containsKey(sc)) {
                    int weight = scWeightMap.get(sc);
                    weight += increment;
                    scWeightMap.put(sc, weight);
                } else {
                    scWeightMap.put(sc, increment);
                }
            }
        }
        Set<Shape> unwantedShapes = new HashSet<Shape>();
        Set<RuleParticipantSignature> unwantedSignatures = new HashSet<RuleParticipantSignature>();
        unwantedShapes.addAll(getShapes());
        unwantedSignatures.addAll(ruleParticipantSignatures);
        ContainerContainerShape containerShape = (ContainerContainerShape) getShapeFromModelObject(getModel());
        List<ReactionContainerShape> reactionContainerShapeList = new ArrayList<ReactionContainerShape>();
        List<Structure> structureList = new ArrayList<Structure>(getStructureSuite().getStructures());
        // create all ReactionContainerShapes (one for each Structure)
        for (Structure structure : structureList) {
            if (structure instanceof Membrane) {
                Membrane membrane = (Membrane) structure;
                ReactionContainerShape membraneShape = (ReactionContainerShape) getShapeFromModelObject(membrane);
                if (membraneShape == null) {
                    membraneShape = new ReactionContainerShape(membrane, structureSuite, this);
                    addShape(membraneShape);
                    membrane.getMembraneVoltage().removePropertyChangeListener(this);
                    membrane.getMembraneVoltage().addPropertyChangeListener(this);
                } else {
                    membraneShape.setStructureSuite(structureSuite);
                }
                membrane.removePropertyChangeListener(this);
                membrane.addPropertyChangeListener(this);
                membraneShape.refreshLabel();
                unwantedShapes.remove(membraneShape);
                reactionContainerShapeList.add(membraneShape);
            } else if (structure instanceof Feature) {
                Feature feature = (Feature) structure;
                ReactionContainerShape featureShape = (ReactionContainerShape) getShapeFromModelObject(feature);
                if (featureShape == null) {
                    featureShape = new ReactionContainerShape(feature, structureSuite, this);
                    addShape(featureShape);
                } else {
                    featureShape.setStructureSuite(structureSuite);
                }
                feature.removePropertyChangeListener(this);
                feature.addPropertyChangeListener(this);
                featureShape.refreshLabel();
                unwantedShapes.remove(featureShape);
                reactionContainerShapeList.add(featureShape);
            }
        }
        if (containerShape == null) {
            containerShape = new ContainerContainerShape(this, getModel(), reactionContainerShapeList);
            addShape(containerShape);
        } else {
            containerShape.setReactionContainerShapeList(reactionContainerShapeList);
        }
        containerShape.refreshLabel();
        unwantedShapes.remove(containerShape);
        // add all species context shapes within the structures
        for (Structure structure : getStructureSuite().getStructures()) {
            ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
            structure.removePropertyChangeListener(this);
            structure.addPropertyChangeListener(this);
            for (SpeciesContext structSpeciesContext : getModel().getSpeciesContexts(structure)) {
                SpeciesContextShape ss = (SpeciesContextShape) getShapeFromModelObject(structSpeciesContext);
                if (ss == null) {
                    ss = new SpeciesContextShape(structSpeciesContext, this);
                    ss.truncateLabelName(false);
                    structSpeciesContext.getSpecies().removePropertyChangeListener(this);
                    structSpeciesContext.getSpecies().addPropertyChangeListener(this);
                    reactionContainerShape.addChildShape(ss);
                    addShape(ss);
                    ss.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                }
                if (speciesSizeOption == SpeciesSizeOptions.weight) {
                    // this number sets the diameter of the shape
                    Integer weight = scWeightMap.get(structSpeciesContext);
                    if (weight != null) {
                        // we cap the diameter of the shape to something reasonable
                        weight = Math.min(weight, 16);
                    }
                    ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, weight);
                } else if (speciesSizeOption == SpeciesSizeOptions.length) {
                    Integer length = null;
                    if (structSpeciesContext.getSpeciesPattern() != null && !structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().isEmpty()) {
                        length = structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().size() * 2;
                        length = Math.min(length, 16);
                    }
                    ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, length);
                } else {
                    ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, null);
                }
                structSpeciesContext.removePropertyChangeListener(this);
                structSpeciesContext.addPropertyChangeListener(this);
                ss.refreshLabel();
                unwantedShapes.remove(ss);
            }
        }
        // add all reactionSteps that are in this structure (ReactionContainerShape), and draw the lines
        getModel().removePropertyChangeListener(this);
        getModel().addPropertyChangeListener(this);
        // 
        for (ReactionRule rr : getModel().getRbmModelContainer().getReactionRuleList()) {
            rr.removePropertyChangeListener(this);
            rr.addPropertyChangeListener(this);
            Structure structure = rr.getStructure();
            if (getStructureSuite().areReactionsShownFor(structure)) {
                ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
                ReactionRuleFullDiagramShape rrShape = (ReactionRuleFullDiagramShape) getShapeFromModelObject(rr);
                if (rrShape == null) {
                    rrShape = new ReactionRuleFullDiagramShape(rr, this);
                    addShape(rrShape);
                    rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                    reactionContainerShape.addChildShape(rrShape);
                    rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                }
                rrShape.refreshLabel();
                unwantedShapes.remove(rrShape);
                // 
                // add reaction participants as edges and SignatureShapes as needed
                // 
                List<ReactionRuleParticipant> participants = rr.getReactionRuleParticipants();
                List<RuleParticipantEdgeDiagramShape> ruleEdges = new ArrayList<>();
                for (ReactionRuleParticipant participant : participants) {
                    participant.getSpeciesPattern().removePropertyChangeListener(this);
                    participant.getSpeciesPattern().addPropertyChangeListener(this);
                    Structure speciesStructure = participant.getStructure();
                    Structure reactionStructure = rr.getStructure();
                    if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
                        // 
                        // find existing RuleParticipantSignatureShape in cartoon
                        // 
                        RuleParticipantLongSignature ruleParticipantLongSignature = null;
                        for (RuleParticipantSignature signature : ruleParticipantSignatures) {
                            if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == participant.getStructure() && signature.compareByCriteria(participant.getSpeciesPattern(), GroupingCriteria.full)) {
                                ruleParticipantLongSignature = (RuleParticipantLongSignature) signature;
                                break;
                            }
                        }
                        for (RuleParticipantSignature signature : ruleParticipantSignatures) {
                            if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == participant.getStructure()) {
                                System.out.println("ReactionCartoonFull, refreshAll(), RuleParticipantShortSignature");
                            }
                        }
                        // 
                        // if didn't find signature in cartoons list of signatures, then create one (and create a shape for it).
                        // 
                        RuleParticipantSignatureFullDiagramShape signatureShape = null;
                        if (ruleParticipantLongSignature == null) {
                            ruleParticipantLongSignature = RuleParticipantLongSignature.fromReactionRuleParticipant(participant, this);
                            ruleParticipantSignatures.add(ruleParticipantLongSignature);
                            signatureShape = new RuleParticipantSignatureFullDiagramShape(ruleParticipantLongSignature, this);
                            addShape(signatureShape);
                            ReactionContainerShape participantContainerShape = (ReactionContainerShape) getShapeFromModelObject(participant.getStructure());
                            signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
                            participantContainerShape.addChildShape(signatureShape);
                            signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
                        } else {
                            signatureShape = (RuleParticipantSignatureFullDiagramShape) getShapeFromModelObject(ruleParticipantLongSignature);
                        }
                        unwantedShapes.remove(signatureShape);
                        unwantedSignatures.remove(ruleParticipantLongSignature);
                        signatureShape.refreshLabel();
                        signatureShape.setVisible(true);
                        // 
                        // add edge for ReactionRuleParticipant if not already present.
                        // 
                        RuleParticipantEdgeDiagramShape ruleParticipantShape = (RuleParticipantEdgeDiagramShape) getShapeFromModelObject(participant);
                        if (ruleParticipantShape == null || ruleParticipantShape.getRuleParticipantSignatureShape() != signatureShape) {
                            if (participant instanceof ReactantPattern && signatureShape.isVisible()) {
                                ruleParticipantShape = new ReactantPatternEdgeDiagramShape((ReactantPattern) participant, rrShape, signatureShape, this);
                            } else if (participant instanceof ProductPattern && signatureShape.isVisible()) {
                                ruleParticipantShape = new ProductPatternEdgeDiagramShape((ProductPattern) participant, rrShape, signatureShape, this);
                            } else {
                                throw new RuntimeException("unsupported ReactionRuleParticipant " + participant.getClass());
                            }
                            addShape(ruleParticipantShape);
                        }
                        if (!containerShape.getChildren().contains(ruleParticipantShape)) {
                            containerShape.addChildShape(ruleParticipantShape);
                        }
                        unwantedShapes.remove(ruleParticipantShape);
                        ruleParticipantShape.refreshLabel();
                        // all the edges for this rule
                        ruleEdges.add(ruleParticipantShape);
                    }
                }
                // a product edge (a closed loop) between the rule diagram shape and the signature diagram shape
                for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
                    // reset them all
                    ours.setSibling(false);
                }
                for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
                    for (RuleParticipantEdgeDiagramShape theirs : ruleEdges) {
                        if (ours == theirs) {
                            // don't compare with self
                            continue;
                        }
                        if (ours.getRuleParticipantSignatureShape() == theirs.getRuleParticipantSignatureShape()) {
                            ours.setSibling(true);
                            theirs.setSibling(true);
                        }
                    }
                }
            }
        }
        ruleParticipantSignatures.removeAll(unwantedSignatures);
        for (ReactionStep reactionStep : getModel().getReactionSteps()) {
            reactionStep.removePropertyChangeListener(this);
            reactionStep.addPropertyChangeListener(this);
            Structure structure = reactionStep.getStructure();
            if (getStructureSuite().areReactionsShownFor(structure)) {
                ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
                if (reactionContainerShape == null) {
                    System.out.println("Reaction container shape is null for structure " + structure + " for reaction step " + reactionStep);
                }
                ReactionStepShape reactionStepShape = (ReactionStepShape) getShapeFromModelObject(reactionStep);
                if (reactionStepShape == null) {
                    if (reactionStep instanceof SimpleReaction) {
                        reactionStepShape = new SimpleReactionShape((SimpleReaction) reactionStep, this);
                    } else if (reactionStep instanceof FluxReaction) {
                        reactionStepShape = new FluxReactionShape((FluxReaction) reactionStep, this);
                    } else {
                        throw new RuntimeException("unknown type of ReactionStep '" + reactionStep.getClass().toString());
                    }
                    addShape(reactionStepShape);
                    reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                    reactionContainerShape.addChildShape(reactionStepShape);
                    reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                }
                reactionStepShape.refreshLabel();
                unwantedShapes.remove(reactionStepShape);
                // add reaction participants as edges
                for (ReactionParticipant participant : reactionStep.getReactionParticipants()) {
                    participant.removePropertyChangeListener(this);
                    participant.addPropertyChangeListener(this);
                    Structure speciesStructure = participant.getStructure();
                    Structure reactionStructure = reactionStep.getStructure();
                    if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
                        SpeciesContext speciesContext = getModel().getSpeciesContext(participant.getSpecies(), speciesStructure);
                        // add speciesContextShapes that are not in this structure, but are referenced from the reactionParticipants
                        // these are only when reactionParticipants are from features that are outside of the membrane being displayed
                        SpeciesContextShape speciesContextShape = (SpeciesContextShape) getShapeFromModelObject(speciesContext);
                        if (speciesContextShape == null) {
                            speciesContextShape = new SpeciesContextShape(speciesContext, this);
                            speciesContextShape.truncateLabelName(false);
                            reactionContainerShape.addChildShape(speciesContextShape);
                            addShape(speciesContextShape);
                            speciesContextShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                        }
                        speciesContextShape.refreshLabel();
                        unwantedShapes.remove(speciesContextShape);
                        ReactionParticipantShape reactionParticipantShape = (ReactionParticipantShape) getShapeFromModelObject(participant);
                        if (reactionParticipantShape == null) {
                            if (participant instanceof Reactant) {
                                reactionParticipantShape = new ReactantShape((Reactant) participant, reactionStepShape, speciesContextShape, this);
                            } else if (participant instanceof Product) {
                                reactionParticipantShape = new ProductShape((Product) participant, reactionStepShape, speciesContextShape, this);
                            } else if (participant instanceof Catalyst) {
                                reactionParticipantShape = new CatalystShape((Catalyst) participant, reactionStepShape, speciesContextShape, this);
                            } else {
                                throw new RuntimeException("unsupported ReactionParticipant " + participant.getClass());
                            }
                            addShape(reactionParticipantShape);
                        }
                        if (!containerShape.getChildren().contains(reactionParticipantShape)) {
                            containerShape.addChildShape(reactionParticipantShape);
                        }
                        unwantedShapes.remove(reactionParticipantShape);
                        reactionParticipantShape.refreshLabel();
                    }
                }
            }
        }
        for (Shape unwantedShape : unwantedShapes) {
            removeShape(unwantedShape);
        }
        // update diagrams
        for (Structure structure : structureSuite.getStructures()) {
            Diagram diagram = getModel().getDiagram(structure);
            if (diagram != null) {
                applyDefaults(diagram);
            }
        }
        fireGraphChanged(new GraphEvent(this));
    } catch (Throwable e) {
        handleException(e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) Reactant(cbit.vcell.model.Reactant) HashSet(java.util.HashSet) ReactionStep(cbit.vcell.model.ReactionStep) ReactionRuleParticipant(cbit.vcell.model.ReactionRuleParticipant) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) GraphEvent(cbit.gui.graph.GraphEvent) RuleParticipantShortSignature(cbit.vcell.model.RuleParticipantShortSignature) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ReactantPattern(cbit.vcell.model.ReactantPattern) RuleParticipantLongSignature(cbit.vcell.model.RuleParticipantLongSignature) SimpleReaction(cbit.vcell.model.SimpleReaction) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) Point(java.awt.Point) Diagram(cbit.vcell.model.Diagram)

Example 5 with GraphEvent

use of cbit.gui.graph.GraphEvent in project vcell by virtualcell.

the class ReactionCartoonMolecule method refreshAll.

@Override
protected void refreshAll(boolean reallocateShapes) {
    try {
        if (getModel() == null || getStructureSuite() == null) {
            return;
        }
        System.out.println("ReactionCartoonMolecule, RefreshAll()");
        for (Structure structure : structureSuite.getStructures()) {
            Diagram diagram = getModel().getDiagram(structure);
            if (diagram != null) {
                // Maintain consistency between rule participant nodes, signatures and
                // species pattern when a molecule is being modified.
                rebindAll(diagram);
            }
        }
        // calculate species context weight (number of reactions for which it's a participant)
        Map<SpeciesContext, Integer> scWeightMap = new HashMap<>();
        // all the species contexts that are catalysts
        Set<SpeciesContext> scCatalystSet = new HashSet<>();
        // calculate species context length (number of species patterns it contains, 1 if has no species patterns)
        for (ReactionStep rs : getModel().getReactionSteps()) {
            ReactionParticipant[] rpList = rs.getReactionParticipants();
            for (int i = 0; i < rpList.length; i++) {
                ReactionParticipant rp = rpList[i];
                SpeciesContext sc = rp.getSpeciesContext();
                int increment = 1;
                if (rp instanceof Catalyst) {
                    scCatalystSet.add(sc);
                }
                if (scWeightMap.containsKey(sc)) {
                    int weight = scWeightMap.get(sc);
                    weight += increment;
                    scWeightMap.put(sc, weight);
                } else {
                    scWeightMap.put(sc, increment);
                }
            }
        }
        Set<Shape> unwantedShapes = new HashSet<Shape>();
        Set<RuleParticipantSignature> unwantedSignatures = new HashSet<RuleParticipantSignature>();
        unwantedShapes.addAll(getShapes());
        unwantedSignatures.addAll(ruleParticipantSignatures);
        ContainerContainerShape containerShape = (ContainerContainerShape) getShapeFromModelObject(getModel());
        List<ReactionContainerShape> reactionContainerShapeList = new ArrayList<ReactionContainerShape>();
        List<Structure> structureList = new ArrayList<Structure>(getStructureSuite().getStructures());
        // create all ReactionContainerShapes (one for each Structure)
        for (Structure structure : structureList) {
            if (structure instanceof Membrane) {
                Membrane membrane = (Membrane) structure;
                ReactionContainerShape membraneShape = (ReactionContainerShape) getShapeFromModelObject(membrane);
                if (membraneShape == null) {
                    membraneShape = new ReactionContainerShape(membrane, structureSuite, this);
                    addShape(membraneShape);
                    membrane.getMembraneVoltage().removePropertyChangeListener(this);
                    membrane.getMembraneVoltage().addPropertyChangeListener(this);
                } else {
                    membraneShape.setStructureSuite(structureSuite);
                }
                membrane.removePropertyChangeListener(this);
                membrane.addPropertyChangeListener(this);
                membraneShape.refreshLabel();
                unwantedShapes.remove(membraneShape);
                reactionContainerShapeList.add(membraneShape);
            } else if (structure instanceof Feature) {
                Feature feature = (Feature) structure;
                ReactionContainerShape featureShape = (ReactionContainerShape) getShapeFromModelObject(feature);
                if (featureShape == null) {
                    featureShape = new ReactionContainerShape(feature, structureSuite, this);
                    addShape(featureShape);
                } else {
                    featureShape.setStructureSuite(structureSuite);
                }
                feature.removePropertyChangeListener(this);
                feature.addPropertyChangeListener(this);
                featureShape.refreshLabel();
                unwantedShapes.remove(featureShape);
                reactionContainerShapeList.add(featureShape);
            }
        }
        if (containerShape == null) {
            containerShape = new ContainerContainerShape(this, getModel(), reactionContainerShapeList);
            addShape(containerShape);
        } else {
            containerShape.setReactionContainerShapeList(reactionContainerShapeList);
        }
        containerShape.refreshLabel();
        unwantedShapes.remove(containerShape);
        // add all species context shapes within the structures
        for (Structure structure : getStructureSuite().getStructures()) {
            ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
            structure.removePropertyChangeListener(this);
            structure.addPropertyChangeListener(this);
            for (SpeciesContext structSpeciesContext : getModel().getSpeciesContexts(structure)) {
                SpeciesContextShape ss = (SpeciesContextShape) getShapeFromModelObject(structSpeciesContext);
                if (ss == null) {
                    ss = new SpeciesContextShape(structSpeciesContext, this);
                    ss.truncateLabelName(false);
                    structSpeciesContext.getSpecies().removePropertyChangeListener(this);
                    structSpeciesContext.getSpecies().addPropertyChangeListener(this);
                    reactionContainerShape.addChildShape(ss);
                    addShape(ss);
                    ss.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                }
                if (speciesSizeOption == SpeciesSizeOptions.weight) {
                    // this number sets the diameter of the shape
                    Integer weight = scWeightMap.get(structSpeciesContext);
                    if (weight != null) {
                        // we cap the diameter of the shape to something reasonable
                        weight = Math.min(weight, 16);
                    }
                    ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, weight);
                } else if (speciesSizeOption == SpeciesSizeOptions.length) {
                    Integer length = null;
                    if (structSpeciesContext.getSpeciesPattern() != null && !structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().isEmpty()) {
                        length = structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().size() * 2;
                        length = Math.min(length, 16);
                    }
                    ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, length);
                } else {
                    ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, null);
                }
                structSpeciesContext.removePropertyChangeListener(this);
                structSpeciesContext.addPropertyChangeListener(this);
                ss.refreshLabel();
                unwantedShapes.remove(ss);
            }
        }
        // add all reactionSteps that are in this structure (ReactionContainerShape), and draw the lines
        getModel().removePropertyChangeListener(this);
        getModel().addPropertyChangeListener(this);
        // 
        for (ReactionRule rr : getModel().getRbmModelContainer().getReactionRuleList()) {
            rr.removePropertyChangeListener(this);
            rr.addPropertyChangeListener(this);
            Structure structure = rr.getStructure();
            if (getStructureSuite().areReactionsShownFor(structure)) {
                ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
                ReactionRuleFullDiagramShape rrShape = (ReactionRuleFullDiagramShape) getShapeFromModelObject(rr);
                if (rrShape == null) {
                    rrShape = new ReactionRuleFullDiagramShape(rr, this);
                    addShape(rrShape);
                    rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                    reactionContainerShape.addChildShape(rrShape);
                    rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                }
                rrShape.refreshLabel();
                unwantedShapes.remove(rrShape);
                // 
                // add reaction participants as edges and SignatureShapes as needed
                // 
                List<ReactionRuleParticipant> participants = rr.getReactionRuleParticipants();
                List<RuleParticipantEdgeDiagramShape> ruleEdges = new ArrayList<>();
                for (ReactionRuleParticipant participant : participants) {
                    participant.getSpeciesPattern().removePropertyChangeListener(this);
                    participant.getSpeciesPattern().addPropertyChangeListener(this);
                    Structure speciesStructure = participant.getStructure();
                    Structure reactionStructure = rr.getStructure();
                    if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
                        // 
                        // find existing RuleParticipantSignatureShape in cartoon
                        // 
                        RuleParticipantShortSignature ruleParticipantShortSignature = null;
                        for (RuleParticipantSignature signature : ruleParticipantSignatures) {
                            if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == participant.getStructure()) {
                                System.out.println("ReactionCartoonMolecule, refreshAll(), RuleParticipantLongSignature");
                                break;
                            }
                        }
                        for (RuleParticipantSignature signature : ruleParticipantSignatures) {
                            if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == participant.getStructure() && signature.compareByCriteria(participant.getSpeciesPattern(), GroupingCriteria.molecule)) {
                                ruleParticipantShortSignature = (RuleParticipantShortSignature) signature;
                                break;
                            }
                        }
                        // 
                        // if didn't find signature in cartoons list of signatures, then create one (and create a shape for it).
                        // 
                        RuleParticipantSignatureShortDiagramShape signatureShape = null;
                        if (ruleParticipantShortSignature == null) {
                            ruleParticipantShortSignature = RuleParticipantShortSignature.fromReactionRuleParticipant(participant, this);
                            ruleParticipantSignatures.add(ruleParticipantShortSignature);
                            signatureShape = new RuleParticipantSignatureShortDiagramShape(ruleParticipantShortSignature, this);
                            addShape(signatureShape);
                            ReactionContainerShape participantContainerShape = (ReactionContainerShape) getShapeFromModelObject(participant.getStructure());
                            signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
                            participantContainerShape.addChildShape(signatureShape);
                            signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
                        } else {
                            signatureShape = (RuleParticipantSignatureShortDiagramShape) getShapeFromModelObject(ruleParticipantShortSignature);
                        }
                        unwantedShapes.remove(signatureShape);
                        unwantedSignatures.remove(ruleParticipantShortSignature);
                        signatureShape.refreshLabel();
                        signatureShape.setVisible(true);
                        // 
                        // add edge for ReactionRuleParticipant if not already present.
                        // 
                        RuleParticipantEdgeDiagramShape ruleParticipantShape = (RuleParticipantEdgeDiagramShape) getShapeFromModelObject(participant);
                        if (ruleParticipantShape == null || ruleParticipantShape.getRuleParticipantSignatureShape() != signatureShape) {
                            if (participant instanceof ReactantPattern && signatureShape.isVisible()) {
                                ruleParticipantShape = new ReactantPatternEdgeDiagramShape((ReactantPattern) participant, rrShape, signatureShape, this);
                            } else if (participant instanceof ProductPattern && signatureShape.isVisible()) {
                                ruleParticipantShape = new ProductPatternEdgeDiagramShape((ProductPattern) participant, rrShape, signatureShape, this);
                            } else {
                                throw new RuntimeException("unsupported ReactionRuleParticipant " + participant.getClass());
                            }
                            addShape(ruleParticipantShape);
                        }
                        if (!containerShape.getChildren().contains(ruleParticipantShape)) {
                            containerShape.addChildShape(ruleParticipantShape);
                        }
                        unwantedShapes.remove(ruleParticipantShape);
                        ruleParticipantShape.refreshLabel();
                        // all the edges for this rule
                        ruleEdges.add(ruleParticipantShape);
                    }
                }
                // a product edge (a closed loop) between the rule diagram shape and the signature diagram shape
                for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
                    // reset them all
                    ours.setSibling(false);
                }
                for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
                    for (RuleParticipantEdgeDiagramShape theirs : ruleEdges) {
                        if (ours == theirs) {
                            // don't compare with self
                            continue;
                        }
                        if (ours.getRuleParticipantSignatureShape() == theirs.getRuleParticipantSignatureShape()) {
                            ours.setSibling(true);
                            theirs.setSibling(true);
                        }
                    }
                }
            }
        }
        ruleParticipantSignatures.removeAll(unwantedSignatures);
        for (ReactionStep reactionStep : getModel().getReactionSteps()) {
            reactionStep.removePropertyChangeListener(this);
            reactionStep.addPropertyChangeListener(this);
            Structure structure = reactionStep.getStructure();
            if (getStructureSuite().areReactionsShownFor(structure)) {
                ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
                if (reactionContainerShape == null) {
                    System.out.println("Reaction container shape is null for structure " + structure + " for reaction step " + reactionStep);
                }
                ReactionStepShape reactionStepShape = (ReactionStepShape) getShapeFromModelObject(reactionStep);
                if (reactionStepShape == null) {
                    if (reactionStep instanceof SimpleReaction) {
                        reactionStepShape = new SimpleReactionShape((SimpleReaction) reactionStep, this);
                    } else if (reactionStep instanceof FluxReaction) {
                        reactionStepShape = new FluxReactionShape((FluxReaction) reactionStep, this);
                    } else {
                        throw new RuntimeException("unknown type of ReactionStep '" + reactionStep.getClass().toString());
                    }
                    addShape(reactionStepShape);
                    reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                    reactionContainerShape.addChildShape(reactionStepShape);
                    reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                }
                reactionStepShape.refreshLabel();
                unwantedShapes.remove(reactionStepShape);
                // add reaction participants as edges
                for (ReactionParticipant participant : reactionStep.getReactionParticipants()) {
                    participant.removePropertyChangeListener(this);
                    participant.addPropertyChangeListener(this);
                    Structure speciesStructure = participant.getStructure();
                    Structure reactionStructure = reactionStep.getStructure();
                    if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
                        SpeciesContext speciesContext = getModel().getSpeciesContext(participant.getSpecies(), speciesStructure);
                        // add speciesContextShapes that are not in this structure, but are referenced from the reactionParticipants
                        // these are only when reactionParticipants are from features that are outside of the membrane being displayed
                        SpeciesContextShape speciesContextShape = (SpeciesContextShape) getShapeFromModelObject(speciesContext);
                        if (speciesContextShape == null) {
                            speciesContextShape = new SpeciesContextShape(speciesContext, this);
                            speciesContextShape.truncateLabelName(false);
                            reactionContainerShape.addChildShape(speciesContextShape);
                            addShape(speciesContextShape);
                            speciesContextShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
                        }
                        speciesContextShape.refreshLabel();
                        unwantedShapes.remove(speciesContextShape);
                        ReactionParticipantShape reactionParticipantShape = (ReactionParticipantShape) getShapeFromModelObject(participant);
                        if (reactionParticipantShape == null) {
                            if (participant instanceof Reactant) {
                                reactionParticipantShape = new ReactantShape((Reactant) participant, reactionStepShape, speciesContextShape, this);
                            } else if (participant instanceof Product) {
                                reactionParticipantShape = new ProductShape((Product) participant, reactionStepShape, speciesContextShape, this);
                            } else if (participant instanceof Catalyst) {
                                reactionParticipantShape = new CatalystShape((Catalyst) participant, reactionStepShape, speciesContextShape, this);
                            } else {
                                throw new RuntimeException("unsupported ReactionParticipant " + participant.getClass());
                            }
                            addShape(reactionParticipantShape);
                        }
                        if (!containerShape.getChildren().contains(reactionParticipantShape)) {
                            containerShape.addChildShape(reactionParticipantShape);
                        }
                        unwantedShapes.remove(reactionParticipantShape);
                        reactionParticipantShape.refreshLabel();
                    }
                }
            }
        }
        for (Shape unwantedShape : unwantedShapes) {
            removeShape(unwantedShape);
        }
        // update diagrams
        for (Structure structure : structureSuite.getStructures()) {
            Diagram diagram = getModel().getDiagram(structure);
            if (diagram != null) {
                applyDefaults(diagram);
            }
        }
        fireGraphChanged(new GraphEvent(this));
    } catch (Throwable e) {
        handleException(e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) Reactant(cbit.vcell.model.Reactant) HashSet(java.util.HashSet) ReactionStep(cbit.vcell.model.ReactionStep) ReactionRuleParticipant(cbit.vcell.model.ReactionRuleParticipant) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) GraphEvent(cbit.gui.graph.GraphEvent) RuleParticipantShortSignature(cbit.vcell.model.RuleParticipantShortSignature) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ReactantPattern(cbit.vcell.model.ReactantPattern) RuleParticipantLongSignature(cbit.vcell.model.RuleParticipantLongSignature) SimpleReaction(cbit.vcell.model.SimpleReaction) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) Point(java.awt.Point) Diagram(cbit.vcell.model.Diagram)

Aggregations

GraphEvent (cbit.gui.graph.GraphEvent)6 Shape (cbit.gui.graph.Shape)4 Structure (cbit.vcell.model.Structure)3 HashSet (java.util.HashSet)3 ContainerShape (cbit.gui.graph.ContainerShape)2 SimpleContainerShape (cbit.gui.graph.SimpleContainerShape)2 Catalyst (cbit.vcell.model.Catalyst)2 Diagram (cbit.vcell.model.Diagram)2 Feature (cbit.vcell.model.Feature)2 FluxReaction (cbit.vcell.model.FluxReaction)2 Membrane (cbit.vcell.model.Membrane)2 Product (cbit.vcell.model.Product)2 ProductPattern (cbit.vcell.model.ProductPattern)2 Reactant (cbit.vcell.model.Reactant)2 ReactantPattern (cbit.vcell.model.ReactantPattern)2 ReactionParticipant (cbit.vcell.model.ReactionParticipant)2 ReactionRule (cbit.vcell.model.ReactionRule)2 ReactionRuleParticipant (cbit.vcell.model.ReactionRuleParticipant)2 ReactionStep (cbit.vcell.model.ReactionStep)2 RuleParticipantLongSignature (cbit.vcell.model.RuleParticipantLongSignature)2