use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.
the class GraphContainerLayoutReactions method getPreferedSizeReactionContainerShape.
public Dimension getPreferedSizeReactionContainerShape(ReactionContainerShape shape, Graphics2D g) {
// get size when empty
Font origFont = g.getFont();
g.setFont(shape.getLabelFont(g));
try {
Dimension preferredSize = shape.getPreferedSizeSelf(g);
// make larger than empty size so that children fit
for (Shape child : shape.getChildren()) {
if (child instanceof ReactionStepShape || child instanceof SpeciesContextShape || child instanceof RuleParticipantSignatureFullDiagramShape || child instanceof RuleParticipantSignatureShortDiagramShape || child instanceof ReactionRuleDiagramShape) {
preferredSize.width = Math.max(preferredSize.width, child.getSpaceManager().getRelPos().x + child.getSpaceManager().getSize().width);
preferredSize.height = Math.max(preferredSize.height, child.getSpaceManager().getRelPos().y + child.getSpaceManager().getSize().height);
}
}
preferredSize.width = preferredSize.width + WIDTH_PADDING;
preferredSize.height = preferredSize.height + HEIGHT_PADDING;
Structure structure = shape.getStructure();
int minWidthSum = 0;
for (Structure structure2 : shape.getStructureSuite().getStructures()) {
if (structure2 instanceof Feature) {
minWidthSum += FEATURE_MIN_WIDTH;
} else {
minWidthSum += MEMBRANE_MIN_WIDTH;
}
}
int compartmentMinWidth = 0;
if (structure instanceof Feature) {
compartmentMinWidth = FEATURE_MIN_WIDTH;
} else {
compartmentMinWidth = MEMBRANE_MIN_WIDTH;
}
int apportionedWidth = compartmentMinWidth * TOTAL_MIN_WIDTH / minWidthSum;
if (preferredSize.width < compartmentMinWidth) {
preferredSize.width = compartmentMinWidth;
}
if (preferredSize.width < apportionedWidth) {
preferredSize.width = apportionedWidth;
}
if (preferredSize.height < MIN_HEIGHT) {
preferredSize.height = MIN_HEIGHT;
}
return preferredSize;
} finally {
g.setFont(origFont);
}
}
use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.
the class GraphContainerLayoutReactions method refreshLayoutChildrenContainerContainerShape.
public void refreshLayoutChildrenContainerContainerShape(ContainerContainerShape shape) {
List<ReactionContainerShape> structureContainers = shape.getStructureContainers();
int currentX = 0;
int currentY = 0;
for (int i = 0; i < structureContainers.size(); i++) {
structureContainers.get(i).getSpaceManager().setRelPos(currentX, currentY);
currentX += structureContainers.get(i).getSpaceManager().getSize().width;
}
}
use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.
the class GraphContainerLayoutVCellClassical method getPreferedSizeReactionContainerShape.
public Dimension getPreferedSizeReactionContainerShape(ReactionContainerShape shape, Graphics2D g) {
// get size when empty
Font origFont = g.getFont();
g.setFont(shape.getLabelFont(g));
try {
Dimension emptySize = shape.getPreferedSizeSelf(g);
// make larger than empty size so that children fit
for (Shape child : shape.getChildren()) {
if (child instanceof ReactionStepShape || child instanceof SpeciesContextShape) {
emptySize.width = Math.max(emptySize.width, child.getSpaceManager().getRelPos().x + child.getSpaceManager().getSize().width);
emptySize.height = Math.max(emptySize.height, child.getSpaceManager().getRelPos().y + child.getSpaceManager().getSize().height);
}
}
emptySize.width = emptySize.width + emptySize.width / 10;
emptySize.height = emptySize.height + emptySize.height / 10;
return emptySize;
} finally {
g.setFont(origFont);
}
}
use of cbit.vcell.graph.ReactionContainerShape 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.vcell.graph.ReactionContainerShape 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
}
}
Aggregations