use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ViewObservablesMapPanel method initialize.
private void initialize() {
try {
// --------------------------------------- the split panels
setName("ViewGeneratedSpeciesPanel");
setLayout(new BorderLayout());
JPanel topPanel = new JPanel();
topPanel.setLayout(new GridBagLayout());
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new GridBagLayout());
JSplitPane splitPaneHorizontal = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPaneHorizontal.setDividerSize(10);
splitPaneHorizontal.setOneTouchExpandable(true);
splitPaneHorizontal.setDividerLocation(260);
splitPaneHorizontal.setResizeWeight(0.5);
splitPaneHorizontal.setTopComponent(topPanel);
splitPaneHorizontal.setBottomComponent(bottomPanel);
add(splitPaneHorizontal, BorderLayout.CENTER);
// ---------------------------------------- species shape panel
shapePanelSpecies = 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;
}
};
shapePanelSpecies.setLayout(new GridBagLayout());
shapePanelSpecies.setBackground(Color.white);
// not really editable but we don't want the brown contours here
shapePanelSpecies.setEditable(true);
shapePanelSpecies.setShowMoleculeColor(true);
shapePanelSpecies.setShowNonTrivialOnly(true);
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
JScrollPane scrollPaneSpecies = new JScrollPane(shapePanelSpecies);
scrollPaneSpecies.setBorder(loweredBevelBorder);
scrollPaneSpecies.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneSpecies.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanelSpecies = new JPanel();
optionsPanelSpecies.setLayout(new GridBagLayout());
getZoomSmallerButtonSpecies().setEnabled(true);
getZoomLargerButtonSpecies().setEnabled(true);
shapePanelSpecies.zoomSmaller();
shapePanelSpecies.zoomSmaller();
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelSpecies.add(getZoomLargerButtonSpecies(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelSpecies.add(getZoomSmallerButtonSpecies(), 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);
optionsPanelSpecies.add(new JLabel(""), gbc);
JPanel containerOfScrollPanelSpecies = new JPanel();
containerOfScrollPanelSpecies.setLayout(new BorderLayout());
containerOfScrollPanelSpecies.add(optionsPanelSpecies, BorderLayout.WEST);
containerOfScrollPanelSpecies.add(scrollPaneSpecies, BorderLayout.CENTER);
Dimension dimS = new Dimension(500, 125);
// dimension of shape panel
containerOfScrollPanelSpecies.setPreferredSize(dimS);
containerOfScrollPanelSpecies.setMinimumSize(dimS);
containerOfScrollPanelSpecies.setMaximumSize(dimS);
shapePanelObservable = new LargeShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternLargeShape sps : spsList) {
if (sps == null) {
continue;
}
sps.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;
}
};
//
DefaultScrollTableCellRenderer rbmSpeciesPatternCellRenderer = new DefaultScrollTableCellRenderer() {
@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 GeneratedSpeciesTableModel2) {
Object selectedObject = null;
if (table.getModel() == speciesTableModel) {
selectedObject = speciesTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedSpeciesTableRow && value instanceof String) {
SpeciesPattern sp = ((GeneratedSpeciesTableRow) selectedObject).getSpecies().getSpeciesPattern();
String text = "<html>";
text += RbmTableRenderer.toHtml(sp, isSelected);
text += "</html>";
setText(text);
}
}
}
return this;
}
};
// shapePanelObservable.setLayout(null);
shapePanelObservable.setLayout(new GridBagLayout());
shapePanelObservable.setBackground(Color.white);
shapePanelObservable.setEditable(true);
shapePanelObservable.setShowMoleculeColor(true);
shapePanelObservable.setShowNonTrivialOnly(true);
JScrollPane scrollPaneObservable = new JScrollPane(shapePanelObservable);
scrollPaneObservable.setBorder(loweredBevelBorder);
scrollPaneObservable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneObservable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanelObservable = new JPanel();
optionsPanelObservable.setLayout(new GridBagLayout());
getZoomSmallerButtonObservable().setEnabled(true);
getZoomLargerButtonObservable().setEnabled(true);
shapePanelObservable.zoomSmaller();
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelObservable.add(getZoomLargerButtonObservable(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelObservable.add(getZoomSmallerButtonObservable(), 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);
optionsPanelObservable.add(new JLabel(""), gbc);
JPanel containerOfScrollPanelObservable = new JPanel();
containerOfScrollPanelObservable.setLayout(new BorderLayout());
containerOfScrollPanelObservable.add(optionsPanelObservable, BorderLayout.WEST);
containerOfScrollPanelObservable.add(scrollPaneObservable, BorderLayout.CENTER);
Dimension dimO = new Dimension(500, 100);
// dimension of shape panel
containerOfScrollPanelObservable.setPreferredSize(dimO);
containerOfScrollPanelObservable.setMinimumSize(dimO);
containerOfScrollPanelObservable.setMaximumSize(dimO);
// -------------- connection between tables, table models, selection models, renderers, event handlers
speciesTable = new EditorScrollTable();
speciesTableModel = new GeneratedSpeciesTableModel2(speciesTable, owner);
speciesTable.setModel(speciesTableModel);
speciesTable.getSelectionModel().addListSelectionListener(eventHandlerS);
speciesTable.getModel().addTableModelListener(eventHandlerS);
observablesTable = new EditorScrollTable();
observablesTableModel = new ObservablesGroupTableModel(observablesTable, owner, speciesTableModel);
observablesTable.setModel(observablesTableModel);
observablesTable.getSelectionModel().addListSelectionListener(eventHandlerO);
observablesTable.getModel().addTableModelListener(eventHandlerO);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setCellRenderer(rbmSpeciesPatternCellRenderer);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
// speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setCellRenderer(rightRenderer); // right align
// left column wide enough for title
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setMaxWidth(70);
speciesTable.addMouseMotionListener(new // add toolTipText for each table cell
MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int row = speciesTable.rowAtPoint(p);
int column = speciesTable.columnAtPoint(p);
speciesTable.setToolTipText(String.valueOf(speciesTable.getValueAt(row, column)));
}
});
// ---------------------------------------------- top panel
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);
observablesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
topPanel.add(observablesTable.getEnclosingScrollPane(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
topPanel.add(new JLabel("Search "), gbc);
textFieldSearchObservables = new JTextField(70);
textFieldSearchObservables.addActionListener(eventHandlerO);
textFieldSearchObservables.getDocument().addDocumentListener(eventHandlerO);
textFieldSearchObservables.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);
topPanel.add(textFieldSearchObservables, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
topPanel.add(totalObservablesLabel, 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);
topPanel.add(containerOfScrollPanelObservable, gbc);
// -------------------------------------------- bottom panel
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);
speciesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
bottomPanel.add(speciesTable.getEnclosingScrollPane(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
bottomPanel.add(new JLabel("Search "), gbc);
textFieldSearchSpecies = new JTextField(70);
textFieldSearchSpecies.addActionListener(eventHandlerS);
textFieldSearchSpecies.getDocument().addDocumentListener(eventHandlerS);
textFieldSearchSpecies.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);
bottomPanel.add(textFieldSearchSpecies, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
bottomPanel.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);
bottomPanel.add(containerOfScrollPanelSpecies, gbc);
// rendering the small shapes of the flattened species in the Depiction column of this viewer table)
// TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
// of a species context in the Depiction column of the species 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() == speciesTableModel) {
selectedObject = speciesTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedSpeciesTableRow) {
SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).getSpecies();
// sp cannot be null
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);
}
}
};
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setPreferredWidth(400);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setMinWidth(400);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setPreferredWidth(30);
speciesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
DefaultScrollTableCellRenderer rbmObservableShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();
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() == observablesTableModel) {
selectedObject = observablesTableModel.getValueAt(row);
}
if (selectedObject != null && selectedObject instanceof ObservablesGroupTableRow) {
ObservablesGroupTableRow ogtr = ((ObservablesGroupTableRow) selectedObject);
String obsName = ogtr.getObservableGroupObject().getObservableGroupName();
RbmObservable observable = ogtr.getObservable(obsName);
Graphics panelContext = table.getGraphics();
int xPos = 4;
spssList.clear();
for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, observable, isSelected, issueManager);
xPos += spss.getWidth() + 6;
spssList.add(spss);
}
} else {
spssList.clear();
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternSmallShape spss : spssList) {
if (spss == null) {
continue;
}
spss.paintSelf(g);
}
}
};
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setCellRenderer(rbmObservableShapeDepictionCellRenderer);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setPreferredWidth(150);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setMinWidth(150);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDefinition).setPreferredWidth(80);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColExpression).setPreferredWidth(100);
observablesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ViewObservablesMapPanel method updateShapeObservable.
private void updateShapeObservable(int selectedRow) {
spsList.clear();
if (selectedRow == -1) {
shapePanelObservable.repaint();
return;
}
ObservablesGroupTableRow observablesTableRow = observablesTableModel.getValueAt(selectedRow);
String obsName = observablesTableRow.getObservableGroupObject().getObservableGroupName();
RbmObservable observable = observablesTableRow.getObservable(obsName);
int maxXOffset = xOffsetInitial;
int maxYOffset = 8;
if (observable != null && observable.getSpeciesPatternList() != null && observable.getSpeciesPatternList().size() > 0) {
// if more than one sp per observable, since non-editable we show them all on a single row
for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
SpeciesPatternLargeShape sps = new SpeciesPatternLargeShape(maxXOffset, maxYOffset, 80, sp, shapePanelObservable, observable, issueManager);
spsList.add(sps);
int xOffset = sps.getRightEnd();
maxXOffset = xOffset + 40;
}
}
Dimension preferredSize = new Dimension(maxXOffset + 200, maxYOffset);
shapePanelObservable.setPreferredSize(preferredSize);
shapePanelObservable.repaint();
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ObservablesGroupTableModel method getValueAt.
public Object getValueAt(int iRow, int iCol) {
ObservablesGroupTableRow observablesTableRow = getValueAt(iRow);
String obsName = observablesTableRow.getObservableGroupObject().getObservableGroupName();
RbmObservable obs = observablesTableRow.getObservable(obsName);
String obsDefinition = ObservablesGroupTableRow.toBnglString(obs);
switch(iCol) {
case iColOriginalName:
return obsName;
case iColStructure:
{
if (obsDefinition.startsWith("@") && obsDefinition.contains(":")) {
String structName = obsDefinition.substring(1, obsDefinition.indexOf(":"));
return structName;
} else {
SimulationContext sc = owner.getSimulationContext();
if (sc.getModel().getStructures().length > 1) {
// if we have more than 1 compartments
return "?";
} else {
Structure struct = sc.getModel().getStructure(0);
return struct.getName();
}
}
}
case iColDepiction:
return obsDefinition;
case iColDefinition:
switch(obs.getSequence()) {
case Multimolecular:
return obsDefinition;
case PolymerLengthEqual:
return obsDefinition + "=" + obs.getSequenceLength();
case PolymerLengthGreater:
return obsDefinition + ">" + obs.getSequenceLength();
default:
return obsDefinition;
}
case iColExpression:
String exp;
BNGSpecies[] speciesList = observablesTableRow.getObservableGroupObject().getListofSpecies();
if (speciesList == null || speciesList.length == 0) {
exp = "<html><font color=\"red\">No generated species</html>";
} else {
exp = getExpressionAsString(observablesTableRow.getObservableGroupObject());
}
return exp;
case iColCount:
return obs.getType().name();
default:
return null;
}
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ObservablePropertiesPanel method onSelectedObjectsChange.
@Override
protected void onSelectedObjectsChange(Object[] selectedObjects) {
RbmObservable observable = null;
if (selectedObjects.length == 1 && selectedObjects[0] instanceof RbmObservable) {
observable = (RbmObservable) selectedObjects[0];
}
setObservable(observable);
updateSequence();
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ObservableTreeModel 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;
}
String mangled = TokenMangler.fixTokenStrict(inputString);
if (!mangled.equals(inputString)) {
String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
throw new RuntimeException(errMsg);
}
if (userObject instanceof RbmObservable) {
// TODO: untested!!!
((RbmObservable) userObject).setName(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);
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);
for (SpeciesPattern sp : observable.getSpeciesPatternList()) {
sp.resolveBonds();
}
} else {
}
}
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
}
}
Aggregations