use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class SpeciesPropertiesPanel method manageComponentPatternFromShape.
public void manageComponentPatternFromShape(final RbmElementAbstract selectedObject, PointLocationInShapeContext locationContext, ShowWhat showWhat) {
popupFromShapeMenu.removeAll();
final MolecularComponentPattern mcp = (MolecularComponentPattern) selectedObject;
final MolecularComponent mc = mcp.getMolecularComponent();
// ------------------------------------------------------------------- State
if (showWhat == ShowWhat.ShowState && mc.getComponentStateDefinitions().size() != 0) {
String prefix = "State: ";
final Map<String, String> itemMap = new LinkedHashMap<String, String>();
// itemList.add(ComponentStatePattern.strAny); // any is not an option for state
String csdCurrentName;
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 = mcp.getBondType() == BondType.None ? "<html><b>" + "Site is unbound" + "</b></html>" : "<html>" + "Site is unbound" + "</html>";
itemMap.put(noneString, null);
// itemMap.put(possibleString, null); // not a valid option for species
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(sp, mtp, mc, index), b);
// itemMap.put(b.toHtmlStringLong(sp, index), b);
}
}
int index = 0;
Graphics gc = shapePanel.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 {
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, fieldSpeciesContext, false, issueManager);
((SpeciesPatternSmallShape) icon).setDisplayRequirements(DisplayRequirements.highlightBonds);
menuItem.setIcon(icon);
editBondMenu.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 none since this is the only option
mcp.getBond().molecularComponentPattern.setBondType(BondType.None);
mcp.getBond().molecularComponentPattern.setBond(null);
}
mcp.setBondType(BondType.None);
mcp.setBond(null);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
speciesPropertiesTreeModel.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 none since it's the only available option, continue using the bond id
mcp.getBond().molecularComponentPattern.setBondType(BondType.None);
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() {
speciesPropertiesTreeModel.populateTree();
}
});
}
}
});
index++;
}
popupFromShapeMenu.add(editBondMenu);
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class SpeciesPropertiesTreeModel method valueForPathChanged.
@Override
public void valueForPathChanged(TreePath path, Object newValue) {
Object obj = path.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
BioModelNode parentNode = (BioModelNode) selectedNode.getParent();
Object userObject = selectedNode.getUserObject();
try {
if (newValue instanceof String) {
String inputString = (String) newValue;
if (inputString == null || inputString.length() == 0) {
return;
}
// if (userObject instanceof SeedSpecies) {
// ((SeedSpecies) userObject).setSpeciesPattern(inputString);
// }
} else if (newValue instanceof MolecularComponentPattern) {
MolecularComponentPattern newMcp = (MolecularComponentPattern) newValue;
Object parentObject = parentNode == null ? null : parentNode.getUserObject();
if (parentObject instanceof MolecularTypePattern) {
MolecularTypePattern mtp = (MolecularTypePattern) parentObject;
MolecularComponent mc = newMcp.getMolecularComponent();
MolecularComponentPattern mcp = mtp.getMolecularComponentPattern(mc);
// TODO: what's correct here ?
mcp.setComponentStatePattern(newMcp.getComponentStatePattern());
BondType bp = mcp.getBondType();
BondType newbp = newMcp.getBondType();
mcp.setBondType(newbp);
// specified -> specified
if (bp == BondType.Specified && newbp == BondType.Specified) {
// bond didn't change
} else if (bp == BondType.Specified && newbp != BondType.Specified) {
// specified -> non specified
// change the partner to possible
mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
mcp.setBond(null);
} else if (bp != BondType.Specified && newbp == BondType.Specified) {
// non specified -> specified
int newBondId = newMcp.getBondId();
mcp.setBondId(newBondId);
mcp.setBond(newMcp.getBond());
mcp.getBond().molecularComponentPattern.setBondId(newBondId);
speciesContext.getSpeciesPattern().resolveBonds();
} else {
}
}
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
}
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class SpeciesContextSpecPanel method initialize.
private void initialize() {
try {
shapePanel = new // glyph (shape) panel
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;
}
};
shapePanel.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point overWhat = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
spls.contains(locationContext);
shapePanel.setToolTipText("View-Only panel");
}
});
shapePanel.setBackground(new Color(0xe0e0e0));
shapePanel.setZoomFactor(-2);
shapePanel.setEditable(false);
shapePanel.setShowMoleculeColor(false);
shapePanel.setShowNonTrivialOnly(false);
// --------------------------------------------------------------
JPanel upperPanel = new JPanel();
upperPanel.setLayout(new java.awt.BorderLayout());
upperPanel.add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
getScrollPaneTable().setModel(getSpeciesContextSpecParameterTableModel());
scrollPane = new JScrollPane(shapePanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
JPanel optionsPanel = new JPanel();
optionsPanel.setLayout(new GridBagLayout());
getZoomSmallerButton().setEnabled(true);
getZoomLargerButton().setEnabled(true);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(4, 4, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomLargerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(4, 4, 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);
// ------------------------------------------------
splitPaneHorizontal.setTopComponent(upperPanel);
splitPaneHorizontal.setBottomComponent(containerOfScrollPanel);
splitPaneHorizontal.setOneTouchExpandable(true);
// upper panel is 165 pixel height
splitPaneHorizontal.setDividerLocation(165);
splitPaneHorizontal.setResizeWeight(1);
setLayout(new BorderLayout());
add(splitPaneHorizontal, BorderLayout.CENTER);
setBackground(Color.white);
setName("SpeciesContextSpecPanel");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class GeneratedSpeciesTableModel2 method getComparator.
public Comparator<GeneratedSpeciesTableRow> getComparator(final int col, final boolean ascending) {
final int scale = ascending ? 1 : -1;
return new Comparator<GeneratedSpeciesTableRow>() {
public int compare(GeneratedSpeciesTableRow o1, GeneratedSpeciesTableRow o2) {
switch(col) {
case iColMultiplier:
return scale * o1.getMultiplier().compareTo(o2.getMultiplier());
case iColOriginalName:
return scale * o1.getOriginalName().compareToIgnoreCase(o2.getOriginalName());
case iColStructure:
// String n1 = es1.substring(1, es1.indexOf(":"));
return // all generated species must belong to the same structure - the one of the observable
0;
case // sort just by the expression, doesn't matter if the structure is mentioned or not because
iColDefinition:
// all the generated species for this observable are in the same structure anyway
return scale * o1.getExpression().compareToIgnoreCase(o2.getExpression());
case iColDepiction:
if (o1.getSpecies() != null && o1.getSpecies().hasSpeciesPattern() && o2.getSpecies() != null && o2.getSpecies().hasSpeciesPattern()) {
Integer i1 = o1.getSpecies().getSpeciesPattern().getMolecularTypePatterns().size();
Integer i2 = o2.getSpecies().getSpeciesPattern().getMolecularTypePatterns().size();
if (scale * i1.compareTo(i2) == 0) {
// if same number of molecule we try to sort by number of sites of the mt
i1 = 0;
i2 = 0;
for (MolecularTypePattern mtp : o1.getSpecies().getSpeciesPattern().getMolecularTypePatterns()) {
i1 += mtp.getMolecularType().getComponentList().size();
}
for (MolecularTypePattern mtp : o2.getSpecies().getSpeciesPattern().getMolecularTypePatterns()) {
i2 += mtp.getMolecularType().getComponentList().size();
}
if (i1 == i2) {
// equal number of molecules and sites, sort by name as a last resort
return scale * o1.getOriginalName().compareToIgnoreCase(o2.getOriginalName());
}
return scale * i1.compareTo(i2);
} else {
return scale * i1.compareTo(i2);
}
}
return 0;
default:
return 0;
}
}
};
}
use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.
the class ObservablesGroupTableModel method getComparator.
public Comparator<ObservablesGroupTableRow> getComparator(final int col, final boolean ascending) {
final int scale = ascending ? 1 : -1;
return new Comparator<ObservablesGroupTableRow>() {
public int compare(ObservablesGroupTableRow o1, ObservablesGroupTableRow o2) {
String n1 = o1.getObservableGroupObject().getObservableGroupName();
String n2 = o2.getObservableGroupObject().getObservableGroupName();
RbmObservable ob1 = o1.getObservable(n1);
RbmObservable ob2 = o2.getObservable(n2);
switch(col) {
case iColOriginalName:
return scale * n1.compareToIgnoreCase(n2);
case iColStructure:
String es1 = ObservablesGroupTableRow.toBnglString(o1.getObservable(n1));
String es2 = ObservablesGroupTableRow.toBnglString(o2.getObservable(n2));
if (es1.startsWith("@") && es1.contains(":")) {
// no point to check es2 as well
String sn1 = es1.substring(1, es1.indexOf(":"));
String sn2 = es2.substring(1, es2.indexOf(":"));
return scale * sn1.compareToIgnoreCase(sn2);
} else {
// we should be here only if we have one single structure, so nothing to sort
return 0;
}
case iColDepiction:
if (ob1 == null && ob2 == null) {
return 0;
}
// the sp list is always allocated even though it may be empty
Integer s1 = ob1.getSpeciesPatternList().size();
Integer s2 = ob2.getSpeciesPatternList().size();
if (s1 != s2) {
// different number of species patterns, sort by number of patterns
return scale * s1.compareTo(s2);
// this includes the case when one list is empty
}
if (s1 > 1 && s2 > 1) {
// same number of species patterns, more than one - we don't bother to sort
return 0;
// TODO: add functionality to sort by total number of molecules / sites
}
// one pattern each, sort by number of molecules, if that equal sort by total number of sites
if (s1 == 1 && s2 == 1) {
Integer i1 = ob1.getSpeciesPattern(0).getMolecularTypePatterns().size();
Integer i2 = ob2.getSpeciesPattern(0).getMolecularTypePatterns().size();
if (scale * i1.compareTo(i2) == 0) {
// if same number of molecule we try to sort by number of sites of the mt
i1 = 0;
i2 = 0;
for (MolecularTypePattern mtp : ob1.getSpeciesPattern(0).getMolecularTypePatterns()) {
i1 += mtp.getMolecularType().getComponentList().size();
}
for (MolecularTypePattern mtp : ob2.getSpeciesPattern(0).getMolecularTypePatterns()) {
i2 += mtp.getMolecularType().getComponentList().size();
}
return scale * i1.compareTo(i2);
} else {
return scale * i1.compareTo(i2);
}
}
return 0;
case iColDefinition:
es1 = ObservablesGroupTableRow.toBnglString(o1.getObservable(n1));
es2 = ObservablesGroupTableRow.toBnglString(o2.getObservable(n2));
if (es1.startsWith("@") && es1.contains(":")) {
// multi-structure; no point to check es2 as well
String sn1 = es1.substring(es1.indexOf(":") + 1);
String sn2 = es2.substring(es2.indexOf(":") + 1);
return scale * sn1.compareToIgnoreCase(sn2);
} else {
// single structure
return scale * es1.compareToIgnoreCase(es2);
}
case iColCount:
return scale * ob1.getType().name().compareTo(ob2.getType().name());
default:
return 0;
}
}
};
}
Aggregations