use of cbit.vcell.graph.SpeciesPatternLargeShape in project vcell by virtualcell.
the class ViewGeneratedReactionsPanel method updateShape.
public void updateShape(int selectedRow) {
GeneratedReactionTableRow reactionTableRow = tableModel.getValueAt(selectedRow);
String inputString = reactionTableRow.getExpression();
System.out.println(selectedRow + ": " + inputString);
// ReactionRule newReactionRule = (ReactionRule)RbmUtils.parseReactionRule(inputString, bioModel);
Model tempModel = null;
try {
tempModel = new Model("MyTempModel");
tempModel.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
// This should not be possible
throw new RuntimeException("Owner or SimulationContext are null.");
}
int arrowIndex = inputString.indexOf("<->");
boolean bReversible = true;
if (arrowIndex < 0) {
arrowIndex = inputString.indexOf("->");
bReversible = false;
}
String left = inputString.substring(0, arrowIndex).trim();
String right = inputString.substring(arrowIndex + (bReversible ? 3 : 2)).trim();
if (left.length() == 0 && right.length() == 0) {
return;
}
// we recover the original rule that generated the flattened reaction we now try to transform back into a fake rule
BNGReaction reactionObject = reactionTableRow.getReactionObject();
String name = reactionObject.getRuleName();
if (name.contains(GeneratedReactionTableModel.reverse)) {
name = name.substring(GeneratedReactionTableModel.reverse.length());
}
if (name.endsWith(ReactionRule.DirectHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
}
if (name.endsWith(ReactionRule.InverseHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
}
// get the name of the original structure from the original rule and make here another structure with the same name
String strStructure = null;
Structure ruleStructure;
SimulationContext sc = owner.getSimulationContext();
ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
if (rr != null && rr.getStructure() != null) {
strStructure = rr.getStructure().getName();
}
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
try {
if (rr.getStructure().getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
tempModel.addMembrane(strStructure);
} else {
tempModel.addFeature(strStructure);
}
} catch (ModelException | PropertyVetoException e) {
e.printStackTrace();
}
}
ruleStructure = tempModel.getStructure(strStructure);
} else {
throw new RuntimeException("Failed to recover a Structure name from the Reaction Rule: " + name);
}
// making the fake rules just for display purpose, actually they are the flattened reactions resulted from bngl
// the name is probably not unique, it's likely that many flattened reactions are derived from the same rule
ReactionRule reactionRule = tempModel.getRbmModelContainer().createReactionRule(name, ruleStructure, bReversible);
String regex = "[^!]\\+";
String[] patterns = left.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
// if compartments are present, we're cheating big time making some fake compartments just for compartment name display purposes
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
if (sc.getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
tempModel.addMembrane(strStructure);
} else {
tempModel.addFeature(strStructure);
}
}
structure = tempModel.getStructure(strStructure);
} else {
// if nothing explicit for a participant, we use by default the structure of the rule
structure = ruleStructure;
}
reactionRule.addReactant(new ReactantPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
// error (red circle)
SpeciesPatternLargeShape spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
reactantPatternShapeList.clear();
productPatternShapeList.clear();
reactantPatternShapeList.add(spls);
shapePanel.repaint();
return;
}
}
patterns = right.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
if (sc.getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
tempModel.addMembrane(strStructure);
} else {
tempModel.addFeature(strStructure);
}
}
structure = tempModel.getStructure(strStructure);
} else {
structure = ruleStructure;
}
// BNGLParser parser = new BNGLParser(new StringReader(sp));
// ASTSpeciesPattern astSpeciesPattern = parser.SpeciesPattern();
// BnglObjectConstructionVisitor constructionVisitor = new BnglObjectConstructionVisitor(tempModel, null, false);
// SpeciesPattern speciesPattern = (SpeciesPattern) astSpeciesPattern.jjtAccept(constructionVisitor, null);
// for(MolecularTypePattern mtp : speciesPattern.getMolecularTypePatterns()) {
// mtp.setParticipantMatchLabel("*");
// }
// System.out.println(speciesPattern.toString());
reactionRule.addProduct(new ProductPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
// error (red circle)
SpeciesPatternLargeShape spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
reactantPatternShapeList.clear();
productPatternShapeList.clear();
reactantPatternShapeList.add(spls);
shapePanel.repaint();
return;
}
}
// ----------------------------------------------------------------------------------------------------
List<ReactantPattern> rpList = reactionRule.getReactantPatterns();
reactantPatternShapeList.clear();
int xOffset = 20;
int xOffsetRound = 20;
if (rpList != null && rpList.size() > 0) {
for (int i = 0; i < rpList.size(); i++) {
SpeciesPattern sp = rpList.get(i).getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
mtp.setParticipantMatchLabel("*");
}
SpeciesPatternLargeShape sps = new SpeciesPatternLargeShape(xOffset, 20, -1, sp, shapePanel, reactionRule, issueManager);
// SpeciesPatternRoundShape sps = new SpeciesPatternRoundShape(xOffsetRound, 20, -1, sp, shapePanel, reactionRule);
if (i < rpList.size() - 1) {
sps.addEndText("+");
} else {
if (reactionRule.isReversible()) {
sps.addEndText("<->");
} else {
sps.addEndText("->");
}
}
xOffset = sps.getRightEnd() + 45;
xOffsetRound = sps.getRightEnd() + 45;
reactantPatternShapeList.add(sps);
}
}
// space for the <-> sign
xOffset += 15;
List<ProductPattern> ppList = reactionRule.getProductPatterns();
productPatternShapeList.clear();
if (ppList != null && ppList.size() > 0) {
for (int i = 0; i < ppList.size(); i++) {
SpeciesPattern sp = ppList.get(i).getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
mtp.setParticipantMatchLabel("*");
}
SpeciesPatternLargeShape sps = new SpeciesPatternLargeShape(xOffset, 20, -1, sp, shapePanel, reactionRule, issueManager);
// SpeciesPatternRoundShape sps = new SpeciesPatternRoundShape(xOffset, 20, -1, sp, shapePanel, reactionRule);
if (i < ppList.size() - 1) {
sps.addEndText("+");
}
xOffset = sps.getRightEnd() + 45;
productPatternShapeList.add(sps);
}
}
Dimension preferredSize = new Dimension(xOffset + 90, 50);
shapePanel.setPreferredSize(preferredSize);
shapePanel.repaint();
}
use of cbit.vcell.graph.SpeciesPatternLargeShape 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.graph.SpeciesPatternLargeShape 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.graph.SpeciesPatternLargeShape in project vcell by virtualcell.
the class OutputSpeciesResultsPanel method updateShape.
public void updateShape(int selectedRow) {
GeneratedSpeciesTableRow speciesTableRow = tableModel.getValueAt(selectedRow);
SpeciesContext sc = speciesTableRow.species;
if (sc == null || sc.getSpeciesPattern() == null) {
// error (red circle)
spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
} else {
spls = new SpeciesPatternLargeShape(20, 20, -1, sc.getSpeciesPattern(), shapePanel, sc, issueManager);
}
int xOffset = spls.getRightEnd() + 45;
Dimension preferredSize = new Dimension(xOffset + 90, 50);
shapePanel.setPreferredSize(preferredSize);
shapePanel.repaint();
}
use of cbit.vcell.graph.SpeciesPatternLargeShape in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
if (popupFromShapeMenu == null) {
popupFromShapeMenu = new JPopupMenu();
}
if (popupFromShapeMenu.isShowing()) {
return;
}
final Object deepestShape = locationContext.getDeepestShape();
final Object selectedObject;
if (deepestShape == null) {
selectedObject = null;
// when cursor is outside there's nothing to do ???
System.out.println("outside");
return;
} else if (deepestShape instanceof ComponentStateLargeShape) {
System.out.println("inside state");
if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStateDefinition();
} else {
// right click only works on highlighted entity, if it's not highlighted we simply return
return;
}
} else if (deepestShape instanceof MolecularComponentLargeShape) {
System.out.println("inside component");
if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponent();
} else {
return;
}
} else if (deepestShape instanceof MolecularTypeLargeShape) {
System.out.println("inside molecule");
if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularType();
} else {
return;
}
} else if (deepestShape instanceof SpeciesPatternLargeShape) {
// this cannot happen, here just for symmetry
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;
}
System.out.println(selectedObject);
boolean bDelete = false;
boolean bAdd = false;
popupFromShapeMenu.removeAll();
Point mousePoint = e.getPoint();
if (selectedObject instanceof MolecularType) {
// rename, add
if (selectedObject != molecularType) {
throw new RuntimeException("The selected object from shape different from the current object");
}
JMenuItem renamMenuItem = new JMenuItem("Rename");
popupFromShapeMenu.add(renamMenuItem);
JMenuItem addMenuItem = new JMenuItem("Add " + MolecularComponent.typeName);
// Icon icon = new MolecularTypeSmallShape(1, 4, mt, gc, mt);
// menuItem.setIcon(icon);
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(addMenuItem);
addMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent molecularComponent = molecularType.createMolecularComponent();
molecularType.addMolecularComponent(molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustSpeciesContextPatterns(molecularType, molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, molecularComponent);
// editInPlace((LargeShape)deepestShape);
}
});
renamMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editInPlace((LargeShape) deepestShape);
}
});
} else if (selectedObject instanceof MolecularComponent) {
// move left / right / separator / rename, delete, separator, add
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) {
MolecularComponent from = (MolecularComponent) selectedObject;
List<MolecularComponent> mcList = molecularType.getComponentList();
int fromIndex = mcList.indexOf(from);
if (mcList.size() == fromIndex + 1) {
// already the last element
return;
}
int toIndex = fromIndex + 1;
MolecularComponent to = mcList.remove(toIndex);
mcList.add(fromIndex, to);
molecularTypeTreeModel.populateTree();
molecularType.firePropertyChange("entityChange", null, "bbb");
}
});
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) {
MolecularComponent from = (MolecularComponent) selectedObject;
List<MolecularComponent> mcList = molecularType.getComponentList();
int fromIndex = mcList.indexOf(from);
if (fromIndex == 0) {
// already the first element
return;
}
int toIndex = fromIndex - 1;
MolecularComponent to = mcList.remove(toIndex);
mcList.add(fromIndex, to);
molecularTypeTreeModel.populateTree();
molecularType.firePropertyChange("entityChange", null, "bbb");
}
});
popupFromShapeMenu.add(moveLeftMenuItem);
popupFromShapeMenu.add(new JSeparator());
JMenuItem renamMenuItem = new JMenuItem("Rename");
popupFromShapeMenu.add(renamMenuItem);
JMenuItem addMenuItem = new JMenuItem("Add " + ComponentStateDefinition.typeName);
JMenuItem deleteMenuItem = new JMenuItem("Delete ");
popupFromShapeMenu.add(deleteMenuItem);
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(addMenuItem);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent mc = (MolecularComponent) selectedObject;
// detailed verifications will be done there, to see if they are being used in reactions, species, observables
if (!mc.getComponentStateDefinitions().isEmpty()) {
String[] options = { "OK" };
String errMsg = mc.getDisplayType() + " '<b>" + mc.getDisplayName() + "</b>' cannot be deleted because it contains explicit States.";
errMsg += "<br>Please delete each individual State first.";
errMsg += "<br><br>Detailed usage information will be provided at that time to help you decide.";
errMsg = "<html>" + errMsg + "</html>";
JOptionPane.showOptionDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
return;
}
// we find and display component usage information to help the user decide
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findComponentUsage(molecularType, mc, usedHere);
if (!usedHere.isEmpty()) {
String errMsg = mc.dependenciesToHtml(usedHere);
errMsg += "<br><br>Delete anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
molecularType.removeMolecularComponent(mc);
}
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
molecularType.removeMolecularComponent(mc);
}
}
}
});
addMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent mc = (MolecularComponent) selectedObject;
ComponentStateDefinition componentStateDefinition = mc.createComponentStateDefinition();
mc.addComponentStateDefinition(componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, mc, componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, mc, componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustSpeciesPatterns(molecularType, mc, componentStateDefinition);
// editInPlace((LargeShape)deepestShape);
}
});
renamMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editInPlace((LargeShape) deepestShape);
}
});
} else if (selectedObject instanceof ComponentStateDefinition) {
// rename, delete
JMenuItem renamMenuItem = new JMenuItem("Rename");
popupFromShapeMenu.add(renamMenuItem);
JMenuItem deleteMenuItem = new JMenuItem("Delete");
popupFromShapeMenu.add(deleteMenuItem);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ComponentStateDefinition csd = (ComponentStateDefinition) selectedObject;
// must exist, we're deleting one of its states
MolecularComponent mc = locationContext.mcs.getMolecularComponent();
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findStateUsage(molecularType, mc, csd, usedHere);
if (!usedHere.isEmpty()) {
String errMsg = csd.dependenciesToHtml(usedHere);
errMsg += "<br><br>Delete anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
mc.deleteComponentStateDefinition(csd);
}
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
mc.deleteComponentStateDefinition(csd);
}
}
}
});
renamMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editInPlace((LargeShape) deepestShape);
}
});
}
popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Aggregations