use of cbit.vcell.graph.FluxReactionShape in project vcell by virtualcell.
the class ReactionCartoonTool method getLineTypeFromAttachment.
private LineType getLineTypeFromAttachment(SpeciesContext speciesContext, Point worldPoint) throws Exception {
Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
if (mouseOverShape instanceof ReactionStepShape) {
// check if the ReactionStep already has a ReactionParticipant for
// this SpeciesContext
ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
if (mouseOverShape instanceof SimpleReactionShape) {
switch(mouseOverShape.getAttachmentFromAbs(worldPoint)) {
case Shape.ATTACH_LEFT:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
case Shape.ATTACH_CENTER:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Catalyst && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.CATALYST;
}
case Shape.ATTACH_RIGHT:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Product && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.PRODUCT;
}
}
} else if (mouseOverShape instanceof FluxReactionShape) {
switch(mouseOverShape.getAttachmentFromAbs(worldPoint)) {
case Shape.ATTACH_LEFT:
{
// return LineType.FLUX;
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
case Shape.ATTACH_CENTER:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Catalyst && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.CATALYST;
}
case Shape.ATTACH_RIGHT:
{
for (int i = 0; i < rps.length; i++) {
// return LineType.FLUX;
if (rps[i] instanceof Product && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.PRODUCT;
}
}
}
}
return LineType.NULL;
}
use of cbit.vcell.graph.FluxReactionShape in project vcell by virtualcell.
the class ReactionCartoonTool method mouseReleased.
@Override
public void mouseReleased(MouseEvent event) {
if (getReactionCartoon() == null) {
return;
}
try {
if (dragStructTimer != null) {
dragStructTimer.stop();
}
endPointWorld = getReactionCartoon().getResizeManager().unzoom(event.getPoint());
Shape endShape = getReactionCartoon().pickWorld(endPointWorld);
if (event.isPopupTrigger() && mode == Mode.SELECT) {
// win, linux popup
popupMenu(getReactionCartoon().getSelectedShape(), event.getX(), event.getY());
return;
}
if (mode == Mode.SELECT && bStartRxContainerLabel) {
resetDropTargets(null, mode == Mode.STRUCTURE);
if (endShape != null && endShape instanceof ReactionContainerShape) {
Rectangle labelOutlineRectangle = ((ReactionContainerShape) endShape).getLabelOutline(endShape.getAbsX(), endShape.getAbsY());
boolean bLabel = labelOutlineRectangle.contains(startPointWorld.x, startPointWorld.y);
getGraphPane().setCursor((bLabel ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)));
}
bStartRxContainerLabel = false;
RXContainerDropTargetInfo trueRXContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
lastRXContainerDropTargetInfoMap = null;
if (trueRXContainerDropTargetInfo == null) {
// turn off rxDropTargetRectangles
getGraphPane().repaint();
return;
}
StructureSuite structureSuite = null;
structureSuite = getReactionCartoon().getStructureSuite();
if (structureSuite != null) {
Structure[] originalOrderedStructArr = structureSuite.getStructures().toArray(new Structure[0]);
// find where user wants to put the structure
try {
if (trueRXContainerDropTargetInfo != null) {
ArrayList<Structure> newStructOrderList = new ArrayList<Structure>(Arrays.asList(originalOrderedStructArr));
newStructOrderList.remove(((ReactionContainerShape) startShape).getStructure());
int indexEnd = newStructOrderList.indexOf(((ReactionContainerShape) trueRXContainerDropTargetInfo.dropShape).getStructure());
int indexClosestNeighbor = (trueRXContainerDropTargetInfo.closestNeighborShape == null ? (trueRXContainerDropTargetInfo.insertFlag == RXContainerDropTargetInfo.INSERT_BEGINNING ? 0 : newStructOrderList.size()) : newStructOrderList.indexOf(((ReactionContainerShape) trueRXContainerDropTargetInfo.closestNeighborShape).getStructure()));
if (indexClosestNeighbor < indexEnd) {
newStructOrderList.add(indexEnd, ((ReactionContainerShape) startShape).getStructure());
} else {
newStructOrderList.add(indexClosestNeighbor, ((ReactionContainerShape) startShape).getStructure());
}
if (structureSuite instanceof AllStructureSuite) {
((AllStructureSuite) structureSuite).setModelStructureOrder(true);
}
ArrayList<Diagram> newDiagramOrderList = new ArrayList<Diagram>();
for (Structure structure : newStructOrderList) {
newDiagramOrderList.add(getModel().getDiagram(structure));
}
getModel().setDiagrams(newDiagramOrderList.toArray(new Diagram[0]));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return;
}
// else do select and move
switch(mode) {
case SELECT:
{
getGraphPane().setCursor(Cursor.getDefaultCursor());
if (bMoving) {
getGraphPane().invalidate();
((JViewport) getGraphPane().getParent()).revalidate();
getGraphPane().repaint();
saveDiagram();
} else if (bRectStretch) {
Point absLoc = rectShape.getSpaceManager().getRelPos();
Dimension size = rectShape.getSpaceManager().getSize();
// remove temporary rectangle
getReactionCartoon().removeShape(rectShape);
rectShape = null;
Rectangle rect = new Rectangle(absLoc.x, absLoc.y, size.width, size.height);
boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
selectEventFromWorld(rect, bShift, bCntrl);
getGraphPane().repaint();
}
bMoving = false;
movingShape = null;
bRectStretch = false;
rectShape = null;
break;
}
case LINEDIRECTED:
{
getGraphPane().setCursor(Cursor.getDefaultCursor());
if (bLineStretch && getDragDistanceSquared() >= MIN_DRAG_DISTANCE_TO_CREATE_NEW_ELEMENTS_SQUARED) {
bLineStretch = false;
// set label and color for line depending on which shape the edge started.
// (rather than attachment area on ReactionStepShape)
LineType lineType = getLineTypeFromDirection(startShape, endPointWorld);
if (endShape instanceof SimpleReactionShape) {
SimpleReaction simpleReaction = (SimpleReaction) endShape.getModelObject();
Object startShapeObject = null;
if (startShape != null) {
startShapeObject = startShape.getModelObject();
}
if (startShapeObject instanceof SpeciesContext) {
SpeciesContext speciesContext = (SpeciesContext) startShapeObject;
lineAction(speciesContext, simpleReaction);
} else if (startShapeObject instanceof Structure) {
Structure structure = (Structure) startShapeObject;
lineActon(structure, simpleReaction);
}
} else if (endShape instanceof SpeciesContextShape) {
SpeciesContext speciesContextEnd = (SpeciesContext) endShape.getModelObject();
Object startShapeObject = null;
if (startShape != null) {
startShapeObject = startShape.getModelObject();
}
if (startShapeObject instanceof SimpleReaction) {
SimpleReaction simpleReaction = (SimpleReaction) startShapeObject;
lineAction(simpleReaction, speciesContextEnd);
} else if (startShapeObject instanceof FluxReaction) {
FluxReaction fluxReaction = (FluxReaction) startShapeObject;
lineAction(fluxReaction, speciesContextEnd);
} else if (startShapeObject instanceof SpeciesContext) {
SpeciesContext speciesContextStart = (SpeciesContext) startShapeObject;
if (!speciesContextStart.equals(speciesContextEnd)) {
lineAction(speciesContextStart, speciesContextEnd);
}
} else if (startShapeObject instanceof Structure) {
Structure startStructure = (Structure) startShapeObject;
lineAction(startStructure, speciesContextEnd);
}
} else if (endShape instanceof FluxReactionShape) {
FluxReaction fluxReaction = (FluxReaction) endShape.getModelObject();
fluxReaction.setModel(getModel());
Object startShapeObject = null;
if (startShape != null) {
startShapeObject = startShape.getModelObject();
}
if (startShapeObject instanceof SpeciesContext) {
SpeciesContext speciesContext = (SpeciesContext) startShapeObject;
lineAction(speciesContext, fluxReaction);
} else if (startShapeObject instanceof Structure) {
Structure structure = (Structure) startShapeObject;
lineActon(structure, fluxReaction);
}
// remove temporary edge
getReactionCartoon().removeShape(edgeShape);
edgeShape = null;
} else if (endShape instanceof ReactionContainerShape) {
Structure endStructure = (Structure) endShape.getModelObject();
Object startObject = null;
if (startShape != null) {
startObject = startShape.getModelObject();
}
if (startObject instanceof SimpleReaction) {
SimpleReaction reaction = (SimpleReaction) startObject;
lineAction(reaction, endStructure);
} else if (startObject instanceof FluxReaction) {
FluxReaction reaction = (FluxReaction) startObject;
lineAction(reaction, endStructure);
} else if (startObject instanceof SpeciesContext) {
SpeciesContext speciesContextStart = (SpeciesContext) startObject;
lineAction(speciesContextStart, endStructure);
} else if (startObject instanceof Structure) {
Structure startStructure = (Structure) startObject;
lineAction(startStructure, endStructure, endShape);
}
}
}
saveDiagram();
break;
}
case LINECATALYST:
{
getGraphPane().setCursor(Cursor.getDefaultCursor());
if (bLineStretch && getDragDistanceSquared() >= MIN_DRAG_DISTANCE_TO_CREATE_NEW_ELEMENTS_SQUARED) {
bLineStretch = false;
// set label and color for line depending on which shape the edge started.
// (rather than attachment area on ReactionStepShape)
Object startObject = startShape.getModelObject();
Object endObject = endShape.getModelObject();
ReactionStep reactionStep = null;
SpeciesContext speciesContext = null;
if (startObject instanceof ReactionStep) {
reactionStep = (ReactionStep) startObject;
if (endObject instanceof SpeciesContext) {
if (StructureUtil.reactionHereCanHaveParticipantThere(reactionStep.getStructure(), ((SpeciesContext) endObject).getStructure())) {
speciesContext = (SpeciesContext) endObject;
}
} else if (endObject instanceof Structure) {
Structure endStructure = (Structure) endObject;
if (StructureUtil.reactionHereCanHaveParticipantThere(reactionStep.getStructure(), endStructure)) {
speciesContext = getReactionCartoon().getModel().createSpeciesContext(endStructure);
getReactionCartoon().notifyChangeEvent();
Point endPos = edgeShape.getEnd();
positionShapeForObject(endStructure, speciesContext, endPos);
}
}
} else if (startObject instanceof SpeciesContext) {
speciesContext = (SpeciesContext) startObject;
if (endObject instanceof ReactionStep) {
if (StructureUtil.reactionHereCanHaveParticipantThere(((ReactionStep) endObject).getStructure(), speciesContext.getStructure())) {
reactionStep = (ReactionStep) endObject;
}
} else if (endObject instanceof Structure) {
Structure endStructure = (Structure) endObject;
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, speciesContext.getStructure())) {
reactionStep = getReactionCartoon().getModel().createSimpleReaction(endStructure);
getReactionCartoon().notifyChangeEvent();
Point endPos = edgeShape.getEnd();
positionShapeForObject(endStructure, reactionStep, endPos);
}
}
} else if (startObject instanceof Structure) {
Structure startStructure = (Structure) startObject;
if (endObject instanceof ReactionStep) {
reactionStep = (ReactionStep) endObject;
if (StructureUtil.reactionHereCanHaveParticipantThere(reactionStep.getStructure(), startStructure)) {
speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, speciesContext, startPointWorld);
}
} else if (endObject instanceof SpeciesContext) {
speciesContext = (SpeciesContext) endObject;
if (StructureUtil.reactionHereCanHaveParticipantThere(startStructure, speciesContext.getStructure())) {
reactionStep = getReactionCartoon().getModel().createSimpleReaction(startStructure);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, reactionStep, startPointWorld);
}
} else if (endObject instanceof Structure) {
Structure endStructure = (Structure) endObject;
if (StructureUtil.reactionHereCanHaveParticipantThere(startStructure, endStructure)) {
speciesContext = getReactionCartoon().getModel().createSpeciesContext(endStructure);
reactionStep = getReactionCartoon().getModel().createSimpleReaction(startStructure);
getReactionCartoon().notifyChangeEvent();
Point endPos = edgeShape.getEnd();
positionShapeForObject(endStructure, speciesContext, endPos);
positionShapeForObject(startStructure, reactionStep, startPointWorld);
} else if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
reactionStep = getReactionCartoon().getModel().createSimpleReaction(endStructure);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, speciesContext, startPointWorld);
Point endPos = edgeShape.getEnd();
positionShapeForObject(endStructure, reactionStep, endPos);
}
}
}
if (reactionStep != null && speciesContext != null) {
Catalyst catalyst = null;
for (ReactionParticipant participant : reactionStep.getReactionParticipants()) {
if (participant instanceof Catalyst && participant.getSpeciesContext().equals(speciesContext)) {
catalyst = (Catalyst) participant;
}
}
if (catalyst == null) {
reactionStep.addCatalyst(speciesContext);
getReactionCartoon().notifyChangeEvent();
}
// add reactionParticipant to model
} else {
getGraphPane().repaint();
}
}
saveDiagram();
break;
}
default:
{
break;
}
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseReleased: uncaught exception");
e.printStackTrace(System.out);
}
resetMouseActionHistory();
getGraphPane().repaint();
}
use of cbit.vcell.graph.FluxReactionShape in project vcell by virtualcell.
the class ReactionCartoonTool method editInPlace.
private void editInPlace(final Shape selectedShape, Point worldPoint) {
if (getGraphPane().getComponentCount() > 0) {
// remove any existing editor
getGraphPane().remove(0);
}
Rectangle labelOutline = null;
// What kind of thing is being edited
if (selectedShape instanceof ReactionContainerShape) {
labelOutline = ((ReactionContainerShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
if (!labelOutline.contains(worldPoint)) {
return;
}
} else if (selectedShape instanceof SpeciesContextShape) {
labelOutline = ((SpeciesContextShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else if (selectedShape instanceof SimpleReactionShape) {
labelOutline = ((SimpleReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else if (selectedShape instanceof FluxReactionShape) {
labelOutline = ((FluxReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else if (selectedShape instanceof ReactionRuleDiagramShape) {
labelOutline = ((ReactionRuleDiagramShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else {
return;
}
// Add press 'Enter' action, 'Escape' action, editor gets focus and mouse 'Exit' parent action
if (true) {
final JTextField jTextField = new JTextField(selectedShape.getLabel());
jTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
// Type specific edit actions
if (selectedShape instanceof ReactionContainerShape) {
((ReactionContainerShape) selectedShape).getStructure().setName(jTextField.getText(), true);
} else if (selectedShape instanceof SpeciesContextShape) {
((SpeciesContextShape) selectedShape).getSpeciesContext().setName(jTextField.getText());
} else if (selectedShape instanceof SimpleReactionShape) {
((SimpleReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
} else if (selectedShape instanceof FluxReactionShape) {
((FluxReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
} else if (selectedShape instanceof ReactionRuleDiagramShape) {
((ReactionRuleDiagramShape) selectedShape).getReactionRule().setName(jTextField.getText());
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(ReactionCartoonTool.this.getGraphPane(), e2.getMessage());
}
stopEditing();
}
});
// just to be sure
ReactionCartoonTool.this.getGraphPane().removeMouseListener(myStopEditAdapter);
ReactionCartoonTool.this.getGraphPane().addMouseListener(myStopEditAdapter);
getGraphModel().removeGraphListener(myGraphListener);
getGraphModel().addGraphListener(myGraphListener);
InputMap im = jTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap am = jTextField.getActionMap();
im.put(KeyStroke.getKeyStroke("ESCAPE"), "cancelChange");
am.put("cancelChange", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
stopEditing();
}
});
GraphResizeManager grm = getGraphModel().getResizeManager();
jTextField.setBounds((int) grm.zoom(labelOutline.x), (int) grm.zoom(labelOutline.y), Math.max((int) grm.zoom(labelOutline.width + 2), 100), Math.max((int) grm.zoom(labelOutline.height + 2), 20));
getGraphPane().add(jTextField);
getGraphPane().validate();
jTextField.requestFocus();
}
return;
}
use of cbit.vcell.graph.FluxReactionShape in project vcell by virtualcell.
the class ReactionCartoonTool method menuAction.
@Override
protected void menuAction(Shape shape, String menuAction) {
if (shape == null) {
return;
}
if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
if (shape instanceof FluxReactionShape) {
// showFluxReactionPropertiesDialog((FluxReactionShape) shape);
} else if (shape instanceof SimpleReactionShape) {
// showSimpleReactionPropertiesDialog((SimpleReactionShape) shape);
} else if (shape instanceof ReactantShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showReactantPropertiesDialog((ReactantShape) shape,
// locationOnScreen);
} else if (shape instanceof ProductShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showProductPropertiesDialog((ProductShape) shape,
// locationOnScreen);
} else if (shape instanceof SpeciesContextShape) {
// showEditSpeciesDialog(getGraphPane(), getReactionCartoon()
// .getModel(), ((SpeciesContextShape) shape)
// .getSpeciesContext());
} else if (shape instanceof ReactionContainerShape) {
// ReactionContainerShape rcs = (ReactionContainerShape) shape;
// if (rcs.getStructure() instanceof Feature) {
// //
// // showFeaturePropertyDialog is invoked in two modes:
// //
// // 1) parent!=null and child==null
// // upon ok, it adds a new feature to the supplied parent.
// //
// // 2) parent==null and child!=null
// // upon ok, edits the feature name
// //
// showFeaturePropertiesDialog(getGraphPane(),
// (getReactionCartoon().getModel() == null ? null
// : getReactionCartoon().getModel()), null,
// (Feature) rcs.getStructure());
// } else if (rcs.getStructure() instanceof Membrane) {
// showMembranePropertiesDialog(getGraphPane(), (Membrane) rcs
// .getStructure());
// }
}
} else if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
getGraphModel().deselectShape(shape);
// showCreateSpeciesContextDialog(getGraphPane(),
// getReactionCartoon().getModel(),
// ((ReactionContainerShape) shape).getStructure(), null);
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) shape).getStructure());
getGraphModel().select(speciesContext);
}
} else if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants whose rule is not selected won't
shape instanceof RuleParticipantSignatureDiagramShape || // be copied since standalone they are meaningless
shape instanceof ReactionRuleDiagramShape) {
SpeciesContext[] spArray = getSelectedSpeciesContextArray();
ReactionStep[] rsArray = getSelectedReactionStepArray();
ReactionRule[] rrArray = getSelectedReactionRuleArray();
MolecularType[] mtArray = getSelectedMolecularTypeArray(rrArray, rsArray, spArray);
Structure[] structArray = getSelectedStructuresArray(rrArray, rsArray, spArray, mtArray);
Structure fromStruct = null;
ReactionContainerShape rcs = null;
Shape parentShape = shape.getParent();
if (parentShape instanceof ReactionContainerShape) {
rcs = (ReactionContainerShape) parentShape;
fromStruct = rcs.getStructure();
}
ReactionSpeciesCopy reactionSpeciesCopy = new ReactionSpeciesCopy(spArray, rsArray, rrArray, mtArray, fromStruct, structArray);
VCellTransferable.sendToClipboard(reactionSpeciesCopy);
}
} else if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
|| */
menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
pasteReactionsAndSpecies(getGraphPane().getRootPane(), ((ReactionContainerShape) shape).getStructure());
}
} else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
try {
if (getGraphModel().getSelectedShape() instanceof ReactionContainerShape && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
getModel().removeStructure(((ReactionContainerShape) getGraphModel().getSelectedShape()).getStructure());
return;
}
if (getSelectedReactionStepArray() != null || getSelectedSpeciesContextArray() != null) {
deleteReactionsAndSpecies(getGraphPane(), getSelectedReactionStepArray(), getSelectedSpeciesContextArray());
}
if (getSelectedReactionParticipantArray() != null && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
ReactionParticipant[] reactionParticipantArr = getSelectedReactionParticipantArray();
if (ReactionCartoonTool.checkAllCatalyst(reactionParticipantArr)) {
DialogUtils.showWarningDialog(getGraphPane(), "Catalysts are determined automatically from the reaction kinetic expression.");
return;
}
String response = DialogUtils.showWarningDialog(getGraphPane(), "Delete " + reactionParticipantArr.length + " Reaction Stoichiometries", new String[] { RXSPECIES_DELETE, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
if (response != null && response.equals(RXSPECIES_DELETE)) {
for (int i = 0; i < reactionParticipantArr.length; i++) {
if (reactionParticipantArr[i] instanceof Catalyst) {
// Catalysts may only be deleted by editing kynetic / proxy parameters
continue;
}
ReactionStep reactionStep = reactionParticipantArr[i].getReactionStep();
reactionStep.removeReactionParticipant(reactionParticipantArr[i]);
}
}
}
} catch (UserCancelException uce) {
return;
} catch (PropertyVetoException e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage());
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
try {
if (shape instanceof ReactionContainerShape) {
showReactionBrowserDialog(((ReactionContainerShape) shape).getStructure(), null);
}
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
try {
String resType = null;
if (shape instanceof ReactionContainerShape) {
showSaveReactionImageDialog();
}
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
if (shape instanceof ReactionStepShape) {
// MIRIAMHelper.showMIRIAMAnnotationDialog(((SimpleReactionShape)shape).getReactionStep());
// System.out.println("Menu action annotate activated...");
ReactionStep rs = ((ReactionStepShape) shape).getReactionStep();
VCMetaData vcMetaData = rs.getModel().getVcMetaData();
try {
String newAnnotation = DialogUtils.showAnnotationDialog(getGraphPane(), vcMetaData.getFreeTextAnnotation(rs));
vcMetaData.setFreeTextAnnotation(rs, newAnnotation);
} catch (UtilCancelException e) {
// Do Nothing
} catch (Throwable exc) {
exc.printStackTrace(System.out);
DialogUtils.showErrorDialog(getGraphPane(), "Failed to edit annotation!\n" + exc.getMessage(), exc);
}
}
} else {
// default action is to ignore
}
}
use of cbit.vcell.graph.FluxReactionShape in project vcell by virtualcell.
the class ReactionCartoonTool method mouseClicked.
@Override
public void mouseClicked(MouseEvent event) {
Point screenPoint = new Point(event.getX(), event.getY());
Point worldPoint = screenToWorld(screenPoint);
try {
if (event.getButton() != MouseEvent.BUTTON1) {
return;
}
switch(mode) {
case SELECT:
{
if (event.getClickCount() == 2) {
final Shape selectedShape = getReactionCartoon().getSelectedShape();
if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
editInPlace(selectedShape, worldPoint);
}
if (selectedShape != null) {
menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
}
}
break;
}
case STEP:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
positionShapeForObject(structure, reactionStep, worldPoint);
saveDiagram();
}
}
break;
}
case FLUX:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
saveDiagram();
// setMode(SELECT_MODE);
} else {
// setMode(SELECT_MODE);
// throw new Exception("fluxes only applicable to membranes");
}
}
break;
}
case SPECIES:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
reactionCartoon.clearSelection();
getGraphModel().select(speciesContext);
positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
// showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
saveDiagram();
}
}
default:
break;
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseClicked: uncaught exception");
e.printStackTrace(System.out);
Point canvasLoc = getGraphPane().getLocationOnScreen();
canvasLoc.x += screenPoint.x;
canvasLoc.y += screenPoint.y;
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
}
Aggregations