use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class BioModelEditorSpeciesTableModel method checkInputValue.
public String checkInputValue(String inputValue, int row, int column) {
SpeciesContext speciesContext = getValueAt(row);
String errMsg = null;
switch(column) {
case COLUMN_NAME:
if (speciesContext == null || !speciesContext.getName().equals(inputValue)) {
if (getModel().getSpeciesContext(inputValue) != null) {
errMsg = "Species '" + inputValue + "' already exists!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
break;
case COLUMN_STRUCTURE:
if (getModel().getStructure(inputValue) == null) {
errMsg = "Structure '" + inputValue + "' does not exist!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
case COLUMN_DEFINITION:
try {
inputValue = inputValue.trim();
if (inputValue.length() > 0) {
// parsing will throw appropriate exception if molecular type or component don't exist
// our change
SpeciesPattern spThis = RbmUtils.parseSpeciesPattern(inputValue, bioModel.getModel());
// here we can restrict what the user can do
for (MolecularTypePattern mtpThis : spThis.getMolecularTypePatterns()) {
MolecularType mtThis = mtpThis.getMolecularType();
for (MolecularComponent mcThis : mtThis.getComponentList()) {
// we check that each component is present in the molecular type pattern (as component pattern)
if (mtpThis.getMolecularComponentPattern(mcThis) == null) {
// not found
errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
} else if (mtpThis.getMolecularComponentPattern(mcThis).isImplied()) {
errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
} else {
// now need to also check the states
if (mcThis.getComponentStateDefinitions().size() == 0) {
// nothing to do if the molecular component has no component state definition
continue;
// note that we raise exception in parseSpeciesPattern() if we attempt to use an undefined state
// so no need to check that here
}
boolean found = false;
for (ComponentStateDefinition csThis : mcThis.getComponentStateDefinitions()) {
MolecularComponentPattern mcpThis = mtpThis.getMolecularComponentPattern(mcThis);
if ((mcpThis.getComponentStatePattern() == null) || mcpThis.getComponentStatePattern().isAny()) {
// no component state pattern means no state, there's no point to check for this component again
break;
// we get out of the for and complain that we found no matching state
}
if (csThis.getName().equals(mcpThis.getComponentStatePattern().getComponentStateDefinition().getName())) {
found = true;
}
}
if (found == false) {
// we should have found a matching state for the molecular component pattern
errMsg = MolecularComponent.typeName + " " + mcThis.getDisplayName() + " of " + mtThis.getDisplayType() + " " + mtThis.getDisplayName() + " must be in one of the following states: ";
for (int i = 0; i < mcThis.getComponentStateDefinitions().size(); i++) {
ComponentStateDefinition csThis = mcThis.getComponentStateDefinitions().get(i);
errMsg += csThis.getName();
if (i < mcThis.getComponentStateDefinitions().size() - 1) {
errMsg += ", ";
}
}
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
}
}
}
} catch (Exception ex) {
errMsg = ex.getMessage();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
}
return null;
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class ModelRuleFactory method createRuleEntry.
public ModelRuleEntry createRuleEntry(ReactionRule reactionRule, int reactionRuleIndex, ReactionRuleDirection direction) {
ModelRuleEntry rule = new ModelRuleEntry(reactionRule, reactionRuleIndex);
//
// for each molecular type in reactant, find all possible matches in products (without regard for consistency).
//
int participantIndex = 0;
for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
ModelParticipantEntry reactantEntry = new ModelParticipantEntry(rule, participantIndex, rp);
rule.reactantEntries.add(reactantEntry);
int moleculeIndex = 0;
for (MolecularTypePattern mtp : rp.getSpeciesPattern().getMolecularTypePatterns()) {
ModelMolecularTypeEntry molecularTypeEntry = new ModelMolecularTypeEntry(reactantEntry, moleculeIndex, mtp);
rule.reactantMolecularTypeEntries.add(molecularTypeEntry);
int componentIndex = 0;
for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
// TODO: divergence point vs. MathRuleFactory
// we need to look at all components when we compare reactants to products looking for changes
// if(mcp.getBondType() == BondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
// continue;
// }
ModelMolecularComponentEntry mce = new ModelMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
rule.reactantMolecularComponentEntries.add(mce);
//
// if this reactant component has a bond, find partner already in list (will always find second binding site where first one is in the list already).
//
Bond bond = mcp.getBond();
if (bond != null) {
ReactantBondEntry bondEntry = null;
for (MolecularComponentEntry otherMCE : rule.reactantMolecularComponentEntries) {
if (((ModelMolecularComponentEntry) otherMCE).molecularComponentPattern == bond.molecularComponentPattern) {
bondEntry = new ReactantBondEntry(otherMCE, mce);
break;
}
}
if (bondEntry != null) {
rule.reactantBondEntries.add(bondEntry);
}
}
componentIndex++;
}
moleculeIndex++;
}
participantIndex++;
}
participantIndex = 0;
for (ProductPattern pp : reactionRule.getProductPatterns()) {
ModelParticipantEntry productEntry = new ModelParticipantEntry(rule, participantIndex, pp);
rule.productEntries.add(productEntry);
int moleculeIndex = 0;
for (MolecularTypePattern mtp : pp.getSpeciesPattern().getMolecularTypePatterns()) {
ModelMolecularTypeEntry molecularTypeEntry = new ModelMolecularTypeEntry(productEntry, moleculeIndex, mtp);
rule.productMolecularTypeEntries.add(molecularTypeEntry);
int componentIndex = 0;
for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
// TODO: divergence point vs. MathRuleFactory
// we need to look at all components when we compare reactants to products looking for changes
// if(mcp.getBondType() == BondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
// continue;
// }
ModelMolecularComponentEntry mce = new ModelMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
rule.productMolecularComponentEntries.add(mce);
//
// if this product component has a bond, find partner already in list (will always find second binding site where first one is in the list already).
//
Bond bond = mcp.getBond();
if (bond != null) {
ProductBondEntry bondEntry = null;
for (MolecularComponentEntry otherMCE : rule.productMolecularComponentEntries) {
if (((ModelMolecularComponentEntry) otherMCE).molecularComponentPattern == bond.molecularComponentPattern) {
bondEntry = new ProductBondEntry(otherMCE, mce);
break;
}
}
if (bondEntry != null) {
rule.productBondEntries.add(bondEntry);
}
}
componentIndex++;
}
moleculeIndex++;
}
participantIndex++;
}
return rule;
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class OutputSpeciesResultsPanel method initialize.
private void initialize() {
try {
setName("ViewGeneratedSpeciesPanel");
setLayout(new GridBagLayout());
shapePanel = new LargeShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spls != null) {
spls.paintSelf(g);
}
}
@Override
public DisplayMode getDisplayMode() {
return DisplayMode.other;
}
@Override
public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleParticipantSignature getSignature() {
return null;
}
@Override
public GroupingCriteria getCriteria() {
return null;
}
@Override
public boolean isViewSingleRow() {
return true;
}
};
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
shapePanel.setLayout(new GridBagLayout());
shapePanel.setBackground(Color.white);
// not really editable but we don't want the brown contours here
shapePanel.setEditable(true);
shapePanel.setShowMoleculeColor(true);
shapePanel.setShowNonTrivialOnly(true);
JScrollPane scrollPane = new JScrollPane(shapePanel);
scrollPane.setBorder(loweredBevelBorder);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanel = new JPanel();
optionsPanel.setLayout(new GridBagLayout());
getZoomSmallerButton().setEnabled(true);
getZoomLargerButton().setEnabled(false);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomLargerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomSmallerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanel.add(new JLabel(""), gbc);
JPanel containerOfScrollPanel = new JPanel();
containerOfScrollPanel.setLayout(new BorderLayout());
containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
Dimension dim = new Dimension(500, 135);
// dimension of shape panel
containerOfScrollPanel.setPreferredSize(dim);
containerOfScrollPanel.setMinimumSize(dim);
containerOfScrollPanel.setMaximumSize(dim);
// ------------------------------------------------------------------------
table = new EditorScrollTable();
tableModel = new OutputSpeciesResultsTableModel();
table.setModel(tableModel);
table.getSelectionModel().addListSelectionListener(eventHandler);
table.getModel().addTableModelListener(eventHandler);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
int gridy = 0;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
table.setPreferredScrollableViewportSize(new Dimension(400, 200));
add(table.getEnclosingScrollPane(), gbc);
// add toolTipText for each table cell
table.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int row = table.rowAtPoint(p);
int column = table.columnAtPoint(p);
table.setToolTipText(String.valueOf(table.getValueAt(row, column)));
}
});
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
add(new JLabel("Search "), gbc);
textFieldSearch = new JTextField(70);
textFieldSearch.addActionListener(eventHandler);
textFieldSearch.getDocument().addDocumentListener(eventHandler);
textFieldSearch.putClientProperty("JTextField.variant", "search");
gbc = new java.awt.GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 0, 4, 4);
add(textFieldSearch, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
add(totalSpeciesLabel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// gbc.weightx = 1.0;
gbc.gridwidth = 8;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
add(containerOfScrollPanel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 4);
add(getSpeciesFileLocationPanel(), gbc);
// // button to copy to clipboard the content of the JTextField.
// // TODO: do not delete! this is how it's done
// JButton buttonCopy = new JButton("Copy");
// buttonCopy.setToolTipText("Copy to clipboard the species file path");
// buttonCopy.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent le) {
// if(speciesFileLocationTextField.getSelectionStart() == speciesFileLocationTextField.getSelectionEnd()) {
// speciesFileLocationTextField.setSelectionStart(0);
// speciesFileLocationTextField.setSelectionEnd(speciesFileLocationTextField.getText().length());
// }
// speciesFileLocationTextField.copy();
// speciesFileLocationTextField.setSelectionStart(0);
// speciesFileLocationTextField.setSelectionEnd(0);
// }
// });
// gbc = new GridBagConstraints();
// gbc.gridx = 4;
// gbc.gridy = gridy;
// gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
// gbc.insets = new Insets(4,4,4,4);
// add(buttonCopy, gbc);
// rendering the small shapes of the flattened species in the Depiction column of this viewer table)
DefaultScrollTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedSpeciesTableRow) {
SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).species;
if (sc == null || sc.getSpeciesPattern() == null) {
spss = null;
} else {
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, panelContext, sc, isSelected, issueManager);
}
}
} else {
spss = null;
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spss != null) {
spss.paintSelf(g);
}
}
};
table.getColumnModel().getColumn(OutputSpeciesResultsTableModel.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
table.getColumnModel().getColumn(OutputSpeciesResultsTableModel.iColDepiction).setPreferredWidth(400);
table.getColumnModel().getColumn(OutputSpeciesResultsTableModel.iColDepiction).setMinWidth(400);
table.getColumnModel().getColumn(OutputSpeciesResultsTableModel.iColDefinition).setPreferredWidth(30);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method initialize.
private void initialize() {
JPanel leftPanel = new JPanel();
leftPanel.setLayout(new GridBagLayout());
// leftPanel.setBackground(Color.white);
anchorPanel = new JAnchorPanel();
anchorScrollPanel = new JScrollPane(anchorPanel);
molecularTypeTree = new BioModelNodeEditableTree();
molecularTypeTreeModel = new MolecularTypeTreeModel(molecularTypeTree);
molecularTypeTree.setModel(molecularTypeTreeModel);
molecularTypeTree.setEditable(true);
molecularTypeTree.setCellRenderer(new RbmMolecularTypeTreeCellRenderer(molecularTypeTree, issueManager));
molecularTypeTree.setCellEditor(new RbmMolecularTypeTreeCellEditor(molecularTypeTree));
int rowHeight = molecularTypeTree.getRowHeight();
if (rowHeight < 10) {
rowHeight = 20;
}
molecularTypeTree.setRowHeight(rowHeight + 2);
molecularTypeTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
ToolTipManager.sharedInstance().registerComponent(molecularTypeTree);
molecularTypeTree.addTreeSelectionListener(eventHandler);
molecularTypeTree.addTreeWillExpandListener(eventHandler);
molecularTypeTree.addMouseListener(eventHandler);
molecularTypeTree.setLargeModel(true);
molecularTypeTree.setRootVisible(true);
setLayout(new GridBagLayout());
int gridy = 0;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.insets = new Insets(4, 4, 4, 4);
titleLabel = new JLabel("Construct Solid Geometry");
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
leftPanel.add(titleLabel, gbc);
ButtonGroup bg = new ButtonGroup();
bg.add(getAnchorAllButton());
bg.add(getAnchorOnlyButton());
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
leftPanel.add(getAnchorAllButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
leftPanel.add(getAnchorOnlyButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.fill = GridBagConstraints.BOTH;
leftPanel.add(anchorScrollPanel, gbc);
// ------------------------------------------------------------------------------
splitPaneHorizontal.setOneTouchExpandable(true);
splitPaneHorizontal.setDividerLocation(120);
splitPaneHorizontal.setResizeWeight(0.1);
Border border = BorderFactory.createLineBorder(Color.gray);
Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
TitledBorder annotationBorder = BorderFactory.createTitledBorder(loweredEtchedBorder, " Annotation and Pathway Links ");
annotationBorder.setTitleJustification(TitledBorder.LEFT);
annotationBorder.setTitlePosition(TitledBorder.TOP);
annotationBorder.setTitleFont(getFont().deriveFont(Font.BOLD));
shapePanel = new LargeShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (LargeShape stls : molecularTypeShapeList) {
stls.paintSelf(g);
}
}
@Override
public DisplayMode getDisplayMode() {
return DisplayMode.other;
}
@Override
public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public boolean isViewSingleRow() {
return true;
}
@Override
public RuleParticipantSignature getSignature() {
return null;
}
@Override
public GroupingCriteria getCriteria() {
return null;
}
};
shapePanel.setBorder(border);
shapePanel.setLayout(null);
shapePanel.setBackground(Color.white);
shapePanel.setEditable(true);
shapePanel.setShowMoleculeColor(true);
shapePanel.setShowNonTrivialOnly(true);
shapePanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
stopEditing();
if (e.getButton() == 1) {
// left click selects the object (we highlight it)
Point whereClicked = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
manageMouseActivity(locationContext);
} else if (e.getButton() == 3) {
// right click invokes popup menu (only if the object is highlighted)
Point whereClicked = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
manageMouseActivity(locationContext);
if (locationContext.getDeepestShape() != null && !locationContext.getDeepestShape().isHighlighted()) {
// TODO: (maybe) add code here to highlight the shape if it's not highlighted already but don't show the menu
// return;
}
showPopupMenu(e, locationContext);
}
}
private void manageMouseActivity(PointLocationInShapeContext locationContext) {
Graphics g = shapePanel.getGraphics();
for (MolecularTypeLargeShape mtls : molecularTypeShapeList) {
mtls.turnHighlightOffRecursive(g);
}
for (MolecularTypeLargeShape mtls : molecularTypeShapeList) {
if (mtls.contains(locationContext)) {
// check if mouse is inside shape
break;
}
}
locationContext.highlightDeepestShape();
locationContext.paintDeepestShape(g);
}
});
shapePanel.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point overWhat = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
for (MolecularTypeLargeShape mtls : molecularTypeShapeList) {
if (mtls.contains(locationContext)) {
break;
}
}
HighlightableShapeInterface hsi = locationContext.getDeepestShape();
if (hsi == null) {
shapePanel.setToolTipText(null);
} else {
shapePanel.setToolTipText("Right click for " + hsi.getDisplayType() + " menus");
}
for (MolecularTypeLargeShape mtls : molecularTypeShapeList) {
Rectangle r = mtls.getAnchorHotspot();
if (r != null && r.contains(overWhat)) {
mtls.getMolecularType();
shapePanel.setToolTipText(mtls.getAnchorsHTML());
break;
}
}
}
});
// -------------------------------------------------------------------------------------------
// right bottom panel, contains just the annotation
JPanel generalPanel = new JPanel();
generalPanel.setBorder(annotationBorder);
generalPanel.setLayout(new GridBagLayout());
gridy = 0;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.LINE_START;
JLabel pathwayLink = new JLabel("Linked Pathway Object(s): ");
generalPanel.add(pathwayLink, gbc);
linkedPOScrollPane = new JScrollPane();
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 4);
generalPanel.add(linkedPOScrollPane, gbc);
gridy++;
// annotationTextArea = new javax.swing.JTextArea("", 1, 30);
// annotationTextArea.setLineWrap(true);
// annotationTextArea.setWrapStyleWord(true);
// annotationTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
annotationTextArea = new JTextPane();
annotationTextArea.setContentType("text/html");
annotationTextArea.setEditable(false);
javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(annotationTextArea);
gbc = new java.awt.GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 2;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
generalPanel.add(jsp, gbc);
scrollPane = new JScrollPane(shapePanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
splitPaneHorizontal.setTopComponent(scrollPane);
splitPaneHorizontal.setBottomComponent(generalPanel);
// -----------------------------------------------------------------------------
splitPane.setOneTouchExpandable(true);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(splitPaneHorizontal);
splitPane.setResizeWeight(0.0);
splitPane.getLeftComponent().setMaximumSize(new Dimension(120, 200));
splitPane.getLeftComponent().setPreferredSize(new Dimension(120, 200));
// splitPane.setDividerLocation(0.0d); // completely hides the left component
// attempt to use the preferred size
splitPane.setDividerLocation(-1);
setName("MolecularTypePropertiesPanel");
setLayout(new BorderLayout());
add(splitPane, BorderLayout.CENTER);
setBackground(Color.white);
annotationTextArea.addFocusListener(eventHandler);
annotationTextArea.addMouseListener(eventHandler);
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class ObservablePropertiesPanel method manageComponentPatternFromShape.
public void manageComponentPatternFromShape(final RbmElementAbstract selectedObject, PointLocationInShapeContext locationContext, ShowWhat showWhat) {
final MolecularComponentPattern mcp = (MolecularComponentPattern) selectedObject;
final MolecularComponent mc = mcp.getMolecularComponent();
popupFromShapeMenu.removeAll();
// ------------------------------------------------------------------- State
if (showWhat == ShowWhat.ShowState && mc.getComponentStateDefinitions().size() != 0) {
String prefix = "State: ";
String csdCurrentName = "";
final Map<String, String> itemMap = new LinkedHashMap<String, String>();
if (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny()) {
csdCurrentName = "<html>" + prefix + "<b>" + ComponentStatePattern.strAny + "</b></html>";
} else {
csdCurrentName = "<html>" + prefix + ComponentStatePattern.strAny + "</html>";
}
itemMap.put(csdCurrentName, ComponentStatePattern.strAny);
for (final ComponentStateDefinition csd : mc.getComponentStateDefinitions()) {
csdCurrentName = "";
if (mcp.getComponentStatePattern() != null && !mcp.getComponentStatePattern().isAny()) {
ComponentStateDefinition csdCurrent = mcp.getComponentStatePattern().getComponentStateDefinition();
csdCurrentName = csdCurrent.getName();
}
String name = csd.getName();
if (name.equals(csdCurrentName)) {
// currently selected menu item is shown in bold
name = "<html>" + prefix + "<b>" + name + "</b></html>";
} else {
name = "<html>" + prefix + name + "</html>";
}
itemMap.put(name, csd.getName());
}
for (String name : itemMap.keySet()) {
JMenuItem menuItem = new JMenuItem(name);
popupFromShapeMenu.add(menuItem);
menuItem.setIcon(VCellIcons.rbmComponentStateIcon);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String key = e.getActionCommand();
String name = itemMap.get(key);
if (name.equals(ComponentStatePattern.strAny)) {
ComponentStatePattern csp = new ComponentStatePattern();
mcp.setComponentStatePattern(csp);
} else {
ComponentStateDefinition csd = mcp.getMolecularComponent().getComponentStateDefinition(name);
if (csd == null) {
throw new RuntimeException("Missing ComponentStateDefinition " + name + " for Component " + mcp.getMolecularComponent().getName());
}
ComponentStatePattern csp = new ComponentStatePattern(csd);
mcp.setComponentStatePattern(csp);
}
}
});
}
}
if (showWhat == ShowWhat.ShowState) {
return;
}
// ------------------------------------------------------------------------------------------- Bonds
final MolecularTypePattern mtp = locationContext.getMolecularTypePattern();
final SpeciesPattern sp = locationContext.getSpeciesPattern();
JMenu editBondMenu = new JMenu();
final String specifiedString = mcp.getBondType() == BondType.Specified ? "<html><b>" + "Site bond specified" + "</b></html>" : "<html>" + "Site bond specified" + "</html>";
editBondMenu.setText(specifiedString);
editBondMenu.setToolTipText("Specified");
editBondMenu.removeAll();
final Map<String, Bond> itemMap = new LinkedHashMap<String, Bond>();
// String noneString = "<html>Bond: <b>" + BondType.None.symbol + "</b> " + BondType.None.name() + "</html>";
// String existsString = "<html>Bond: <b>" + BondType.Exists.symbol + "</b> " + BondType.Exists.name() + "</html>";
// String possibleString = "<html>Bond: <b>" + BondType.Possible.symbol + "</b> " + BondType.Possible.name() + "</html>";
String noneString = mcp.getBondType() == BondType.None ? "<html><b>" + "Site is unbound" + "</b></html>" : "<html>" + "Site is unbound" + "</html>";
// Site is bound
String existsString = mcp.getBondType() == BondType.Exists ? "<html><b>" + "Site has external bond" + "</b></html>" : "<html>" + "Site has external bond" + "</html>";
String possibleString = mcp.getBondType() == BondType.Possible ? "<html><b>" + "Site may be bound" + "</b></html>" : "<html>" + "Site may be bound" + "</html>";
itemMap.put(noneString, null);
itemMap.put(existsString, null);
itemMap.put(possibleString, null);
if (mtp != null && sp != null) {
List<Bond> bondPartnerChoices = sp.getAllBondPartnerChoices(mtp, mc);
for (Bond b : bondPartnerChoices) {
// if(b.equals(mcp.getBond())) {
// continue; // if the mcp has a bond already we don't offer it
// }
int index = 0;
if (mcp.getBondType() == BondType.Specified) {
index = mcp.getBondId();
} else {
index = sp.nextBondId();
}
// itemMap.put(b.toHtmlStringLong(mtp, mc, sp, index), b);
itemMap.put(b.toHtmlStringLong(sp, mtp, mc, index), b);
// itemMap.put(b.toHtmlStringLong(sp, index), b);
}
}
int index = 0;
Graphics gc = splitPaneHorizontal.getGraphics();
for (String name : itemMap.keySet()) {
JMenuItem menuItem = new JMenuItem(name);
if (index == 0) {
menuItem.setIcon(VCellIcons.rbmBondNoneIcon);
menuItem.setToolTipText("None");
popupFromShapeMenu.add(menuItem);
} else if (index == 1) {
menuItem.setIcon(VCellIcons.rbmBondExistsIcon);
menuItem.setToolTipText("Exists");
popupFromShapeMenu.add(menuItem);
} else if (index == 2) {
menuItem.setIcon(VCellIcons.rbmBondPossibleIcon);
menuItem.setToolTipText("Possible");
popupFromShapeMenu.add(menuItem);
} else if (index > 2) {
Bond b = itemMap.get(name);
// clone of the sp, with only the bond of interest
SpeciesPattern spBond = new SpeciesPattern(bioModel.getModel(), sp);
spBond.resetBonds();
spBond.resetStates();
MolecularTypePattern mtpFrom = spBond.getMolecularTypePattern(mtp.getMolecularType().getName(), mtp.getIndex());
MolecularComponentPattern mcpFrom = mtpFrom.getMolecularComponentPattern(mc);
MolecularTypePattern mtpTo = spBond.getMolecularTypePattern(b.molecularTypePattern.getMolecularType().getName(), b.molecularTypePattern.getIndex());
MolecularComponentPattern mcpTo = mtpTo.getMolecularComponentPattern(b.molecularComponentPattern.getMolecularComponent());
spBond.setBond(mtpTo, mcpTo, mtpFrom, mcpFrom);
Icon icon = new SpeciesPatternSmallShape(3, 4, spBond, gc, observable, false, issueManager);
((SpeciesPatternSmallShape) icon).setDisplayRequirements(DisplayRequirements.highlightBonds);
menuItem.setIcon(icon);
editBondMenu.add(menuItem);
// } else {
// if(index == 0) {
// menuItem.setForeground(Color.blue);
// }
// popupFromShapeMenu.add(menuItem);
}
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
BondType btBefore = mcp.getBondType();
if (name.equals(noneString)) {
if (btBefore == BondType.Specified) {
// specified -> not specified
// change the partner to possible
mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
mcp.getBond().molecularComponentPattern.setBond(null);
}
mcp.setBondType(BondType.None);
mcp.setBond(null);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
observableTreeModel.populateTree();
}
});
} else if (name.equals(existsString)) {
if (btBefore == BondType.Specified) {
// specified -> exists
// change the partner to possible
mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
mcp.getBond().molecularComponentPattern.setBond(null);
}
mcp.setBondType(BondType.Exists);
mcp.setBond(null);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
observableTreeModel.populateTree();
}
});
} else if (name.equals(possibleString)) {
if (btBefore == BondType.Specified) {
// specified -> possible
// change the partner to possible
mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
mcp.getBond().molecularComponentPattern.setBond(null);
}
mcp.setBondType(BondType.Possible);
mcp.setBond(null);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
observableTreeModel.populateTree();
}
});
} else {
if (btBefore != BondType.Specified) {
// if we go from a non-specified to a specified we need to find the next available
// bond id, so that we can choose the color for displaying the bond
// a bad bond id, like -1, will crash badly when trying to choose the color
int bondId = sp.nextBondId();
mcp.setBondId(bondId);
} else {
// specified -> specified
// change the old partner to possible, continue using the bond id
mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
mcp.getBond().molecularComponentPattern.setBond(null);
}
mcp.setBondType(BondType.Specified);
Bond b = itemMap.get(name);
mcp.setBond(b);
mcp.getBond().molecularComponentPattern.setBondId(mcp.getBondId());
sp.resolveBonds();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
observableTreeModel.populateTree();
}
});
}
}
});
index++;
}
popupFromShapeMenu.add(editBondMenu);
}
Aggregations