use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class CartoonTool method actionPerformed.
public final void actionPerformed(ActionEvent event) {
if (getGraphModel() == null) {
return;
}
Shape popupMenuShape = getGraphModel().getSelectedShape();
menuAction(popupMenuShape, event.getActionCommand());
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class GraphPane method getToolTipText.
@Override
public String getToolTipText(MouseEvent event) {
if (graphModel == null) {
return getToolTipText();
}
Point unzoomedMousePos = graphModel.getResizeManager().unzoom(event.getPoint());
Shape pickedShape = graphModel.pickWorld(unzoomedMousePos);
if (pickedShape == null) {
return getToolTipText();
}
if (pickedShape instanceof ReactionContainerShape) {
return ((ReactionContainerShape) pickedShape).getSpecialToolTipText(unzoomedMousePos);
}
return pickedShape.getLabel();
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class PathwayGraphTool method selectEventFromWorld.
private void selectEventFromWorld(Rectangle rect, boolean bShift, boolean bCntrl) {
if (!bShift && !bCntrl) {
getGraphModel().clearSelection();
List<Shape> shapes = getGraphModel().pickWorld(rect);
for (Shape shape : shapes) {
if (shape instanceof BioPaxShape) {
getGraphModel().selectShape(shape);
}
}
} else if (bShift) {
if (getGraphModel().getSelectedShape() instanceof PathwayContainerShape) {
getGraphModel().clearSelection();
}
List<Shape> shapes = getGraphModel().pickWorld(rect);
for (Shape shape : shapes) {
if (shape instanceof BioPaxShape) {
getGraphModel().selectShape(shape);
}
}
} else if (bCntrl) {
if (getGraphModel().getSelectedShape() instanceof PathwayContainerShape) {
getGraphModel().clearSelection();
}
List<Shape> shapes = getGraphModel().pickWorld(rect);
for (Shape shape : shapes) {
if (shape instanceof BioPaxShape) {
if (shape.isSelected()) {
getGraphModel().deselectShape(shape);
} else {
getGraphModel().selectShape(shape);
}
}
}
}
}
use of cbit.gui.graph.Shape 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(((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();
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++) {
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.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonTool method mouseDragged.
@Override
public void mouseDragged(MouseEvent event) {
if (getGraphPane().getComponentCount() > 0) {
// we're editing, cancel
stopEditing();
}
if (event.isPopupTrigger()) {
return;
}
boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
if (mode == Mode.SELECT && bStartRxContainerLabel) {
if (dragStructTimer != null) {
dragStructTimer.stop();
}
Point dragPointWorld = getGraphModel().getResizeManager().unzoom(event.getPoint());
RXContainerDropTargetInfo lastTrueRXContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
lastRXContainerDropTargetInfoMap = updateRXContainerDropTargetInfoMap(dragPointWorld);
RXContainerDropTargetInfo currentTrueRXContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
// System.out.println(lastTrueRXContainerDropTargetInfo+" "+currentTrueRXContainerDropTargetInfo);
if (dragStructTimer != null || !Compare.isEqualOrNull(lastTrueRXContainerDropTargetInfo, currentTrueRXContainerDropTargetInfo)) {
activateDropTargetEnable();
getGraphPane().repaint();
}
return;
}
try {
switch(mode) {
case SELECT:
{
Point worldPoint = screenToWorld(event.getX(), event.getY());
if (bMoving) {
if (movingShape instanceof ReactionContainerShape) {
bMoving = false;
return;
}
List<Shape> selectedShapes = getReactionCartoon().getSelectedShapes();
// constrain to stay within the corresponding parent for the
// "movingShape" as well as all other selected (hence
// moving) shapes.
Point movingParentLoc = movingShape.getParent().getSpaceManager().getAbsLoc();
Dimension movingParentSize = movingShape.getParent().getSpaceManager().getSize();
worldPoint.x = Math.max(movingOffsetWorld.x + movingParentLoc.x, Math.min(movingOffsetWorld.x + movingParentLoc.x + movingParentSize.width - movingShape.getSpaceManager().getSize().width, worldPoint.x));
worldPoint.y = Math.max(movingOffsetWorld.y + movingParentLoc.y, Math.min(movingOffsetWorld.x + movingParentLoc.y + movingParentSize.height - movingShape.getSpaceManager().getSize().height, worldPoint.y));
for (Shape shape : selectedShapes) {
if (shape != movingShape) {
Point selectedParentLoc = shape.getParent().getSpaceManager().getAbsLoc();
Dimension selectedParentSize = shape.getParent().getSpaceManager().getSize();
int selectedMovingOffsetX = movingOffsetWorld.x + (movingShape.getSpaceManager().getAbsLoc().x - shape.getSpaceManager().getAbsLoc().x);
int selectedMovingOffsetY = movingOffsetWorld.y + (movingShape.getSpaceManager().getAbsLoc().y - shape.getSpaceManager().getAbsLoc().y);
worldPoint.x = Math.max(selectedMovingOffsetX + selectedParentLoc.x, Math.min(selectedMovingOffsetX + selectedParentLoc.x + selectedParentSize.width - shape.getSpaceManager().getSize().width, worldPoint.x));
worldPoint.y = Math.max(selectedMovingOffsetY + selectedParentLoc.y, Math.min(selectedMovingOffsetY + selectedParentLoc.y + selectedParentSize.height - shape.getSpaceManager().getSize().height, worldPoint.y));
}
}
getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
Point newMovingPoint = new Point(worldPoint.x - movingOffsetWorld.x, worldPoint.y - movingOffsetWorld.y);
int deltaX = newMovingPoint.x - movingPointWorld.x;
int deltaY = newMovingPoint.y - movingPointWorld.y;
movingPointWorld = newMovingPoint;
movingShape.getSpaceManager().setRelPos(movingPointWorld.x - movingParentLoc.x, movingPointWorld.y - movingParentLoc.y);
// them also
for (Shape shape : selectedShapes) {
if (shape != movingShape) {
shape.getSpaceManager().move(deltaX, deltaY);
}
}
getGraphPane().invalidate();
((JViewport) getGraphPane().getParent()).revalidate();
getGraphPane().repaint();
} else if (bRectStretch) {
// constain to stay within parent
Point parentLoc = rectShape.getParent().getSpaceManager().getAbsLoc();
Dimension parentSize = rectShape.getParent().getSpaceManager().getSize();
worldPoint.x = Math.max(1, Math.min(parentSize.width - 1, worldPoint.x - parentLoc.x)) + parentLoc.x;
worldPoint.y = Math.max(1, Math.min(parentSize.height - 1, worldPoint.y - parentLoc.y)) + parentLoc.y;
getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
// getGraphPane().repaint();
Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
AffineTransform oldTransform = g.getTransform();
g.scale(0.01 * getReactionCartoon().getZoomPercent(), 0.01 * getReactionCartoon().getZoomPercent());
g.setXORMode(Color.white);
rectShape.setEnd(endPointWorld);
rectShape.paint(g, 0, 0);
endPointWorld = worldPoint;
rectShape.setEnd(endPointWorld);
rectShape.paint(g, 0, 0);
g.setTransform(oldTransform);
} else {
Shape shape = (getGraphModel().getSelectedShape() != null ? getGraphModel().getSelectedShape() : getReactionCartoon().pickWorld(worldPoint));
if (!bCntrl && !bShift && (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || shape instanceof RuleParticipantSignatureDiagramShape || shape instanceof ReactionRuleDiagramShape)) {
bMoving = true;
movingShape = shape;
movingPointWorld = shape.getSpaceManager().getAbsLoc();
movingOffsetWorld = new Point(worldPoint.x - movingPointWorld.x, worldPoint.y - movingPointWorld.y);
} else if (shape instanceof ReactionContainerShape || bShift || bCntrl) {
if (rectShape == null) {
return;
}
if (startPointWorld != null && worldPoint != null && startPointWorld.equals(worldPoint)) {
// Don't start stretching until mouse moves at least 1 from startpoint
return;
}
bRectStretch = true;
endPointWorld = new Point((startPointWorld != null ? startPointWorld.x : worldPoint.x), (startPointWorld != null ? startPointWorld.y : worldPoint.y));
rectShape.setEnd(endPointWorld);
if (!(shape instanceof ReactionContainerShape)) {
shape.getParent().addChildShape(rectShape);
} else {
shape.addChildShape(rectShape);
}
Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
AffineTransform oldTransform = g.getTransform();
g.scale(0.01 * getReactionCartoon().getZoomPercent(), 0.01 * getReactionCartoon().getZoomPercent());
g.setXORMode(Color.white);
rectShape.paint(g, 0, 0);
g.setTransform(oldTransform);
}
}
break;
}
case LINE:
case LINEDIRECTED:
case LINECATALYST:
{
int x = event.getX();
int y = event.getY();
Point worldPoint = new Point((int) (x * 100.0 / getReactionCartoon().getZoomPercent()), (int) (y * 100.0 / getReactionCartoon().getZoomPercent()));
if (bLineStretch) {
// repaint last location with XOR
Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
g.setXORMode(Color.white);
edgeShape.setEnd(endPointWorld);
AffineTransform oldTransform = g.getTransform();
g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
edgeShape.paint_NoAntiAlias(g, 0, 0);
g.setTransform(oldTransform);
// set label and color for line depending on attachment area on ReactionStepShape
LineType lineType;
if (Mode.LINE.equals(mode)) {
SpeciesContext speciesContext = (SpeciesContext) edgeShape.getStartShape().getModelObject();
lineType = getLineTypeFromAttachment(speciesContext, worldPoint);
} else if (Mode.LINECATALYST.equals(mode)) {
lineType = LineType.CATALYST;
} else if (edgeShape.getStartShape() instanceof SpeciesContextShape) {
lineType = LineType.REACTANT;
} else {
lineType = LineType.PRODUCT;
}
edgeShape.setLabel(lineType.getLabel());
edgeShape.setForgroundColor(lineType.getColor());
getGraphPane().setCursor(lineType.getCursor());
// move line and paint with XOR
endPointWorld = worldPoint;
edgeShape.setEnd(worldPoint);
oldTransform = g.getTransform();
g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
edgeShape.paint_NoAntiAlias(g, 0, 0);
g.setTransform(oldTransform);
} else {
if (edgeShape != null) {
return;
}
if (startShape instanceof SpeciesContextShape || ((Mode.LINEDIRECTED.equals(mode) || Mode.LINECATALYST.equals(mode)) && startShape instanceof ElipseShape)) {
ElipseShape startElipseShape = (ElipseShape) startShape;
bLineStretch = true;
endPointWorld = worldPoint;
edgeShape = new RubberBandEdgeShape(startElipseShape, null, getReactionCartoon());
edgeShape.setEnd(worldPoint);
Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
g.setXORMode(Color.white);
AffineTransform oldTransform = g.getTransform();
g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
edgeShape.paint(g, 0, 0);
g.setTransform(oldTransform);
} else if ((Mode.LINEDIRECTED.equals(mode) || Mode.LINECATALYST.equals(mode)) && startShape instanceof ContainerShape) {
bLineStretch = true;
endPointWorld = worldPoint;
edgeShape = new RubberBandEdgeShape((ElipseShape) null, null, getReactionCartoon());
edgeShape.setStart(startPointWorld);
edgeShape.setEnd(worldPoint);
Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
g.setXORMode(Color.white);
AffineTransform oldTransform = g.getTransform();
g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
edgeShape.paint(g, 0, 0);
g.setTransform(oldTransform);
}
}
break;
}
default:
{
break;
}
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseDragged: uncaught exception");
e.printStackTrace(System.out);
}
}
Aggregations