use of cbit.vcell.graph.MolecularTypeSmallShape in project vcell by virtualcell.
the class RbmObservableTreeCellRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setBorder(null);
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
Object userObject = node.getUserObject();
obj = userObject;
String text = null;
Icon icon = null;
String toolTip = null;
if (userObject instanceof RbmObservable) {
RbmObservable ob = (RbmObservable) userObject;
text = toHtml(ob);
toolTip = toHtmlWithTip(ob);
icon = VCellIcons.rbmObservableIcon;
} else if (userObject instanceof SpeciesPatternLocal) {
SpeciesPatternLocal spl = (SpeciesPatternLocal) userObject;
text = toHtml(spl, true);
toolTip = toHtmlWithTip(spl, true);
icon = VCellIcons.rbmProductIcon;
} else if (userObject instanceof MolecularTypePattern) {
MolecularTypePattern molecularTypePattern = (MolecularTypePattern) userObject;
text = toHtml(molecularTypePattern, true);
toolTip = toHtmlWithTip(molecularTypePattern, true);
if (owner == null) {
icon = VCellIcons.rbmMolecularTypeSimpleIcon;
;
} else {
Graphics gc = owner.getGraphics();
icon = new MolecularTypeSmallShape(1, 5, molecularTypePattern.getMolecularType(), null, gc, molecularTypePattern.getMolecularType(), null, issueManager);
}
} else if (userObject instanceof MolecularComponentPattern) {
MolecularComponentPattern mcp = (MolecularComponentPattern) userObject;
text = toHtml(mcp, true);
toolTip = toHtmlWithTip(mcp, true);
icon = VCellIcons.rbmComponentGrayIcon;
if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGrayStateIcon;
}
if (mcp.isbVisible()) {
icon = VCellIcons.rbmComponentGreenIcon;
if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGreenStateIcon;
}
}
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp != null && !csp.isAny()) {
icon = VCellIcons.rbmComponentGreenIcon;
if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGreenStateIcon;
}
}
BioModelNode parent = (BioModelNode) ((BioModelNode) value).getParent().getParent().getParent();
if (parent == null) {
icon = VCellIcons.rbmComponentErrorIcon;
return this;
}
Object parentObject = parent.getUserObject();
if (!(parentObject instanceof RbmObservable)) {
icon = VCellIcons.rbmComponentErrorIcon;
return this;
}
if (hasErrorIssues((RbmObservable) parentObject, mcp, mcp.getMolecularComponent())) {
icon = VCellIcons.rbmComponentErrorIcon;
}
} else if (userObject instanceof StateLocal) {
StateLocal sl = (StateLocal) userObject;
text = toHtml(sl, true);
toolTip = toHtmlWithTip(sl, true);
icon = VCellIcons.rbmComponentStateIcon;
} else if (userObject instanceof BondLocal) {
BondLocal bl = (BondLocal) userObject;
text = toHtml(bl, sel);
toolTip = toHtmlWithTip(bl, true);
icon = VCellIcons.rbmBondIcon;
} else {
if (userObject != null) {
System.out.println(userObject.toString());
text = userObject.toString();
} else {
text = "null user object";
}
}
setText(text);
setIcon(icon);
setToolTipText(toolTip == null ? text : toolTip);
}
return this;
}
use of cbit.vcell.graph.MolecularTypeSmallShape in project vcell by virtualcell.
the class ReactionRuleEditorPropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
if (popupFromShapeMenu == null) {
popupFromShapeMenu = new JPopupMenu();
}
if (popupFromShapeMenu.isShowing()) {
return;
}
popupFromShapeMenu.removeAll();
Point mousePoint = e.getPoint();
final Object deepestShape = locationContext.getDeepestShape();
final RbmObject selectedObject;
if (deepestShape == null) {
selectedObject = null;
// when cursor is outside any species pattern we offer to add a new one
System.out.println("outside");
// popupFromShapeMenu.add(getAddSpeciesPatternFromShapeMenuItem());
} else if (deepestShape instanceof ComponentStateLargeShape) {
System.out.println("inside state");
if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStatePattern();
} else {
return;
}
} else if (deepestShape instanceof MolecularComponentLargeShape) {
System.out.println("inside component");
if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponentPattern();
} else {
return;
}
} else if (deepestShape instanceof MolecularTypeLargeShape) {
System.out.println("inside molecule");
if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularTypePattern();
} else {
return;
}
} else if (deepestShape instanceof SpeciesPatternLargeShape) {
System.out.println("inside species pattern");
if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
} else {
return;
}
} else if (deepestShape instanceof ReactionRulePatternLargeShape) {
System.out.println("inside reactant line or products line");
if (((ReactionRulePatternLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((ReactionRulePatternLargeShape) deepestShape).getReactionRule();
} else {
return;
}
} else {
selectedObject = null;
System.out.println("inside something else?");
return;
}
boolean bReactantsZone = false;
int xExtent = SpeciesPatternLargeShape.calculateXExtent(shapePanel);
Rectangle2D reactantRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetReactantInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
Rectangle2D productRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetProductInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
if (locationContext.isInside(reactantRectangle)) {
// clicked inside the reactant rectangle (above yOffsetProductInitial)
bReactantsZone = true;
} else if (locationContext.isInside(productRectangle)) {
// clicked inside the product rectangle (below yOffsetProductInitial)
bReactantsZone = false;
} else {
return;
}
// -------------------------------- reactant zone --------------------------------------------------------
if (bReactantsZone) {
if (selectedObject == null) {
return;
} else if (selectedObject instanceof ReactionRule) {
// add reactant pattern
JMenuItem addMenuItem = new JMenuItem("Add Reactant");
addMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reactionRule.addReactant(new ReactantPattern(new SpeciesPattern(), reactionRule.getStructure()));
shapePanel.repaint();
}
});
popupFromShapeMenu.add(addMenuItem);
} else if (selectedObject instanceof SpeciesPattern) {
// delete (pattern) / specify molecule
final SpeciesPattern sp = (SpeciesPattern) selectedObject;
JMenuItem deleteMenuItem = new JMenuItem("Delete");
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
if (rp.getSpeciesPattern() == sp) {
reactionRule.removeReactant(rp);
Structure st = rp.getStructure();
if (reactionRule.getReactantPatterns().isEmpty()) {
reactionRule.addReactant(new ReactantPattern(new SpeciesPattern(), st));
shapePanel.repaint();
}
}
}
}
});
popupFromShapeMenu.add(deleteMenuItem);
JMenu addMenuItem = new JMenu(VCellErrorMessages.SpecifyMolecularTypes);
popupFromShapeMenu.add(addMenuItem);
addMenuItem.removeAll();
for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
JMenuItem menuItem = new JMenuItem(mt.getName());
Graphics gc = shapePanel.getGraphics();
Icon icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
menuItem.setIcon(icon);
addMenuItem.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
for (MolecularComponentPattern mcp : molecularTypePattern.getComponentPatternList()) {
mcp.setBondType(BondType.Possible);
}
sp.addMolecularTypePattern(molecularTypePattern);
shapePanel.repaint();
}
});
}
JMenu compartmentMenuItem = new JMenu("Specify structure");
popupFromShapeMenu.add(compartmentMenuItem);
if (sp.getMolecularTypePatterns().isEmpty()) {
compartmentMenuItem.setEnabled(false);
}
compartmentMenuItem.removeAll();
for (final Structure struct : bioModel.getModel().getStructures()) {
JMenuItem menuItem = new JMenuItem(struct.getName());
compartmentMenuItem.add(menuItem);
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
MolecularType mt = mtp.getMolecularType();
if (mt.isAnchorAll()) {
// no restrictions (no anchor exclusion) for this molecular type
continue;
}
if (!mt.getAnchors().contains(struct)) {
// sp can't be in this struct if any of its molecules is excluded (not anchored)
menuItem.setEnabled(false);
break;
}
}
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String nameStruct = e.getActionCommand();
Structure struct = bioModel.getModel().getStructure(nameStruct);
ReactantPattern rp = reactionRule.getReactantPattern(sp);
rp.setStructure(struct);
productTreeModel.populateTree();
shapePanel.repaint();
}
});
}
} else if (selectedObject instanceof MolecularTypePattern) {
// move left / right / delete molecule / reassign match
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
int numMtp = locationContext.sps.getSpeciesPattern().getMolecularTypePatterns().size();
String moveRightMenuText = "Move <b>" + "right" + "</b>";
moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
Icon icon = VCellIcons.moveRightIcon;
moveRightMenuItem.setIcon(icon);
moveRightMenuItem.setEnabled(numMtp < 2 ? false : true);
moveRightMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftRight(from);
reactantTreeModel.populateTree();
productTreeModel.populateTree();
shapePanel.repaint();
}
});
popupFromShapeMenu.add(moveRightMenuItem);
String moveLeftMenuText = "Move <b>" + "left" + "</b>";
moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
icon = VCellIcons.moveLeftIcon;
moveLeftMenuItem.setIcon(icon);
moveLeftMenuItem.setEnabled(numMtp < 2 ? false : true);
moveLeftMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftLeft(from);
reactantTreeModel.populateTree();
productTreeModel.populateTree();
shapePanel.repaint();
}
});
popupFromShapeMenu.add(moveLeftMenuItem);
popupFromShapeMenu.add(new JSeparator());
String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
deleteMenuText = "<html>" + deleteMenuText + "</html>";
JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.removeMolecularTypePattern(mtp);
shapePanel.repaint();
}
});
popupFromShapeMenu.add(deleteMenuItem);
if (mtp.hasExplicitParticipantMatch()) {
String newKey = mtp.getParticipantMatchLabel();
List<String> keyCandidates = new ArrayList<String>();
List<MolecularTypePattern> mtpReactantList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Reactant);
List<MolecularTypePattern> mtpProductList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Product);
for (MolecularTypePattern mtpCandidate : mtpReactantList) {
// we can look for indexes in any list, we should find the same
if (mtpCandidate.hasExplicitParticipantMatch() && !mtpCandidate.getParticipantMatchLabel().equals(newKey)) {
keyCandidates.add(mtpCandidate.getParticipantMatchLabel());
}
}
if (!keyCandidates.isEmpty()) {
JMenu reassignMatchMenuItem = new JMenu();
reassignMatchMenuItem.setText("Reassign match to");
for (int i = 0; i < keyCandidates.size(); i++) {
JMenuItem menuItem = new JMenuItem(keyCandidates.get(i));
reassignMatchMenuItem.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String oldKey = e.getActionCommand();
MolecularTypePattern orphanReactant = reactionRule.findMatch(oldKey, mtpReactantList);
mtp.setParticipantMatchLabel(oldKey);
orphanReactant.setParticipantMatchLabel(newKey);
// TODO: replace the populate tree with reactantPatternShapeList.update() and productPatternShapeList.update()
// when the tree will be gone
reactantTreeModel.populateTree();
productTreeModel.populateTree();
shapePanel.repaint();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
reactantShape.flash(oldKey);
productShape.flash(oldKey);
}
});
}
});
}
popupFromShapeMenu.add(reassignMatchMenuItem);
}
}
} else if (selectedObject instanceof MolecularComponentPattern) {
// edit bond / edit state
manageComponentPatternFromShape(selectedObject, locationContext, reactantTreeModel, ShowWhat.ShowBond, bReactantsZone);
} else if (selectedObject instanceof ComponentStatePattern) {
// edit state
MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
manageComponentPatternFromShape(mcp, locationContext, reactantTreeModel, ShowWhat.ShowState, bReactantsZone);
}
// ---------------------------------------- product zone ---------------------------------------------
} else if (!bReactantsZone) {
if (selectedObject == null) {
return;
} else if (selectedObject instanceof ReactionRule) {
// add product pattern
JMenuItem addMenuItem = new JMenuItem("Add Product");
addMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reactionRule.addProduct(new ProductPattern(new SpeciesPattern(), reactionRule.getStructure()));
shapePanel.repaint();
}
});
popupFromShapeMenu.add(addMenuItem);
} else if (selectedObject instanceof SpeciesPattern) {
// delete (pattern) / specify molecule
final SpeciesPattern sp = (SpeciesPattern) selectedObject;
JMenuItem deleteMenuItem = new JMenuItem("Delete");
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (ProductPattern pp : reactionRule.getProductPatterns()) {
if (pp.getSpeciesPattern() == sp) {
reactionRule.removeProduct(pp);
Structure st = pp.getStructure();
if (reactionRule.getProductPatterns().isEmpty()) {
reactionRule.addProduct(new ProductPattern(new SpeciesPattern(), st));
shapePanel.repaint();
}
}
}
}
});
popupFromShapeMenu.add(deleteMenuItem);
JMenu addMenuItem = new JMenu(VCellErrorMessages.SpecifyMolecularTypes);
popupFromShapeMenu.add(addMenuItem);
addMenuItem.removeAll();
for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
JMenuItem menuItem = new JMenuItem(mt.getName());
Graphics gc = shapePanel.getGraphics();
Icon icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
menuItem.setIcon(icon);
addMenuItem.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
for (MolecularComponentPattern mcp : molecularTypePattern.getComponentPatternList()) {
mcp.setBondType(BondType.Possible);
}
sp.addMolecularTypePattern(molecularTypePattern);
shapePanel.repaint();
}
});
}
// specify structure
JMenu compartmentMenuItem = new JMenu("Specify structure");
popupFromShapeMenu.add(compartmentMenuItem);
compartmentMenuItem.removeAll();
if (sp.getMolecularTypePatterns().isEmpty()) {
compartmentMenuItem.setEnabled(false);
}
for (final Structure struct : bioModel.getModel().getStructures()) {
JMenuItem menuItem = new JMenuItem(struct.getName());
compartmentMenuItem.add(menuItem);
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
MolecularType mt = mtp.getMolecularType();
if (mt.isAnchorAll()) {
// no restrictions for this molecular type
continue;
}
if (!mt.getAnchors().contains(struct)) {
// sp can't be in this struct if any of its molecules is excluded (not anchored)
menuItem.setEnabled(false);
break;
}
}
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String nameStruct = e.getActionCommand();
Structure struct = bioModel.getModel().getStructure(nameStruct);
ProductPattern pp = reactionRule.getProductPattern(sp);
pp.setStructure(struct);
productTreeModel.populateTree();
shapePanel.repaint();
}
});
}
} else if (selectedObject instanceof MolecularTypePattern) {
// move left / right / delete molecule / reassign match
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
int numMtp = locationContext.sps.getSpeciesPattern().getMolecularTypePatterns().size();
String moveRightMenuText = "Move <b>" + "right" + "</b>";
moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
Icon icon = VCellIcons.moveRightIcon;
moveRightMenuItem.setIcon(icon);
moveRightMenuItem.setEnabled(numMtp < 2 ? false : true);
moveRightMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftRight(from);
reactantTreeModel.populateTree();
productTreeModel.populateTree();
shapePanel.repaint();
}
});
popupFromShapeMenu.add(moveRightMenuItem);
String moveLeftMenuText = "Move <b>" + "left" + "</b>";
moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
icon = VCellIcons.moveLeftIcon;
moveLeftMenuItem.setIcon(icon);
moveLeftMenuItem.setEnabled(numMtp < 2 ? false : true);
moveLeftMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftLeft(from);
reactantTreeModel.populateTree();
productTreeModel.populateTree();
shapePanel.repaint();
}
});
popupFromShapeMenu.add(moveLeftMenuItem);
popupFromShapeMenu.add(new JSeparator());
String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
deleteMenuText = "<html>" + deleteMenuText + "</html>";
JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.removeMolecularTypePattern(mtp);
shapePanel.repaint();
}
});
popupFromShapeMenu.add(deleteMenuItem);
if (mtp.hasExplicitParticipantMatch()) {
String newKey = mtp.getParticipantMatchLabel();
List<String> keyCandidates = new ArrayList<String>();
List<MolecularTypePattern> mtpReactantList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Reactant);
List<MolecularTypePattern> mtpProductList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Product);
for (MolecularTypePattern mtpCandidate : mtpReactantList) {
// we can look for indexes in any list, we should find the same
if (mtpCandidate.hasExplicitParticipantMatch() && !mtpCandidate.getParticipantMatchLabel().equals(newKey)) {
keyCandidates.add(mtpCandidate.getParticipantMatchLabel());
}
}
if (!keyCandidates.isEmpty()) {
JMenu reassignMatchMenuItem = new JMenu();
reassignMatchMenuItem.setText("Reassign match to");
for (int i = 0; i < keyCandidates.size(); i++) {
JMenuItem menuItem = new JMenuItem(keyCandidates.get(i));
reassignMatchMenuItem.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String oldKey = e.getActionCommand();
MolecularTypePattern orphanProduct = reactionRule.findMatch(oldKey, mtpProductList);
mtp.setParticipantMatchLabel(oldKey);
orphanProduct.setParticipantMatchLabel(newKey);
// TODO: replace the populate tree with reactantPatternShapeList.update() and productPatternShapeList.update()
// when the tree will be gone
reactantTreeModel.populateTree();
productTreeModel.populateTree();
shapePanel.repaint();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
reactantShape.flash(oldKey);
productShape.flash(oldKey);
}
});
}
});
}
popupFromShapeMenu.add(reassignMatchMenuItem);
}
}
} else if (selectedObject instanceof MolecularComponentPattern) {
// edit bond / edit state
manageComponentPatternFromShape(selectedObject, locationContext, productTreeModel, ShowWhat.ShowBond, bReactantsZone);
} else if (selectedObject instanceof ComponentStatePattern) {
// edit state
MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
manageComponentPatternFromShape(mcp, locationContext, productTreeModel, ShowWhat.ShowState, bReactantsZone);
}
}
popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
use of cbit.vcell.graph.MolecularTypeSmallShape in project vcell by virtualcell.
the class ObservablePropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
if (popupFromShapeMenu == null) {
popupFromShapeMenu = new JPopupMenu();
}
if (popupFromShapeMenu.isShowing()) {
return;
}
boolean bDelete = false;
boolean bAdd = false;
boolean bEdit = false;
boolean bRename = false;
popupFromShapeMenu.removeAll();
Point mousePoint = e.getPoint();
final Object deepestShape = locationContext.getDeepestShape();
final RbmElementAbstract selectedObject;
if (deepestShape == null) {
selectedObject = null;
// when cursor is outside any species pattern we offer to add a new one
System.out.println("outside");
popupFromShapeMenu.add(getAddSpeciesPatternFromShapeMenuItem());
} else if (deepestShape instanceof ComponentStateLargeShape) {
System.out.println("inside state");
if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStatePattern();
} else {
return;
}
} else if (deepestShape instanceof MolecularComponentLargeShape) {
System.out.println("inside component");
if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponentPattern();
} else {
return;
}
} else if (deepestShape instanceof MolecularTypeLargeShape) {
System.out.println("inside molecule");
if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularTypePattern();
} else {
return;
}
} else if (deepestShape instanceof SpeciesPatternLargeShape) {
System.out.println("inside species pattern");
if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
} else {
return;
}
} else {
selectedObject = null;
System.out.println("inside something else?");
return;
}
if (selectedObject instanceof SpeciesPattern) {
getAddFromShapeMenu().setText(VCellErrorMessages.AddMolecularTypes);
getAddFromShapeMenu().removeAll();
for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
JMenuItem menuItem = new JMenuItem(mt.getName());
Graphics gc = splitPaneHorizontal.getGraphics();
Icon icon = new MolecularTypeSmallShape(4, 4, mt, null, gc, mt, null, issueManager);
menuItem.setIcon(icon);
getAddFromShapeMenu().add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
((SpeciesPattern) selectedObject).addMolecularTypePattern(molecularTypePattern);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
}
});
}
});
}
JMenu compartmentMenuItem = new JMenu("Specify structure (for all)");
compartmentMenuItem.removeAll();
for (final Structure struct : bioModel.getModel().getStructures()) {
JMenuItem menuItem = new JMenuItem(struct.getName());
compartmentMenuItem.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String nameStruct = e.getActionCommand();
Structure struct = bioModel.getModel().getStructure(nameStruct);
observable.setStructure(struct);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// repaint tree
observableTreeModel.populateTree();
// observableTree.scrollPathToVisible(path); // scroll back up to show the observable
}
});
}
});
}
JMenuItem deleteMenuItem = new JMenuItem("Delete Species Pattern");
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// observable.getSpeciesPatternList().remove((SpeciesPattern)selectedObject);
observable.removeSpeciesPattern((SpeciesPattern) selectedObject);
final TreePath path = observableTreeModel.findObjectPath(null, observable);
observableTree.setSelectionPath(path);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// repaint tree
observableTreeModel.populateTree();
// scroll back up to show the observable
observableTree.scrollPathToVisible(path);
}
});
}
});
popupFromShapeMenu.add(deleteMenuItem);
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(getAddFromShapeMenu());
popupFromShapeMenu.add(compartmentMenuItem);
} else if (selectedObject instanceof MolecularTypePattern) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
String moveRightMenuText = "Move <b>" + "right" + "</b>";
moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
Icon icon = VCellIcons.moveRightIcon;
moveRightMenuItem.setIcon(icon);
moveRightMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftRight(from);
observableTreeModel.populateTree();
}
});
popupFromShapeMenu.add(moveRightMenuItem);
String moveLeftMenuText = "Move <b>" + "left" + "</b>";
moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
icon = VCellIcons.moveLeftIcon;
moveLeftMenuItem.setIcon(icon);
moveLeftMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftLeft(from);
observableTreeModel.populateTree();
}
});
popupFromShapeMenu.add(moveLeftMenuItem);
popupFromShapeMenu.add(new JSeparator());
String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
deleteMenuText = "<html>" + deleteMenuText + "</html>";
JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.removeMolecularTypePattern(mtp);
}
});
popupFromShapeMenu.add(deleteMenuItem);
} else if (selectedObject instanceof MolecularComponentPattern) {
manageComponentPatternFromShape(selectedObject, locationContext, ShowWhat.ShowBond);
bDelete = false;
} else if (selectedObject instanceof ComponentStatePattern) {
MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
manageComponentPatternFromShape(mcp, locationContext, ShowWhat.ShowState);
}
if (bRename) {
popupFromShapeMenu.add(getRenameFromShapeMenuItem());
}
if (bDelete) {
popupFromShapeMenu.add(getDeleteFromShapeMenuItem());
}
if (bEdit) {
popupFromShapeMenu.add(getEditFromShapeMenuItem());
}
if (bAdd) {
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(getAddFromShapeMenu());
}
popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Aggregations