use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class ViewGeneratedReactionsPanel method initialize.
private void initialize() {
try {
setName("ViewGeneratedReactionsPanel");
setLayout(new GridBagLayout());
shapePanel = new RulesShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (AbstractComponentShape stls : reactantPatternShapeList) {
stls.paintSelf(g);
}
for (AbstractComponentShape stls : productPatternShapeList) {
stls.paintSelf(g);
}
}
};
Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
shapePanel.setLayout(new GridBagLayout());
shapePanel.setBackground(Color.white);
// don't show the brown contour even though it's not editable
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, 140);
// dimension of shape panel
containerOfScrollPanel.setPreferredSize(dim);
containerOfScrollPanel.setMinimumSize(dim);
containerOfScrollPanel.setMaximumSize(dim);
// -----------------------------------------------------------------------------
table = new EditorScrollTable();
tableModel = new GeneratedReactionTableModel(table, owner);
table.setModel(tableModel);
table.getSelectionModel().addListSelectionListener(eventHandler);
table.getModel().addTableModelListener(eventHandler);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
// table.getColumnModel().getColumn(GeneratedReactionTableModel.iColIndex).setCellRenderer(rightRenderer); // right align first table column
// table.getColumnModel().getColumn(GeneratedReactionTableModel.iColIndex).setMaxWidth(60); // left column wide enough for 6-7 digits
int gridy = 0;
gbc = new 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 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(totalReactionsLabel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// gbc.weightx = 1.0;
// gbc.weighty = 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);
// rendering the small shapes of a fake rule 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 rule in the Depiction column of the reaction table)
DefaultScrollTableCellRenderer rbmReactionShapeDepictionCellRenderer = 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() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedReactionTableRow) {
ReactionRule rr = ((GeneratedReactionTableRow) selectedObject).getReactionRule();
Graphics panelContext = table.getGraphics();
BioModel bioModel = owner.getSimulationContext().getBioModel();
spssList.clear();
List<ReactantPattern> rpList = rr.getReactantPatterns();
int xPos = 4;
for (int i = 0; i < rpList.size(); i++) {
SpeciesPattern sp = rr.getReactantPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
if (i < rpList.size() - 1) {
spss.addEndText("+");
} else {
if (rr.isReversible()) {
spss.addEndText("<->");
xPos += 7;
} else {
spss.addEndText("->");
}
}
xPos += spss.getWidth() + 14;
spssList.add(spss);
}
List<ProductPattern> ppList = rr.getProductPatterns();
xPos += 7;
for (int i = 0; i < ppList.size(); i++) {
SpeciesPattern sp = rr.getProductPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
if (i < ppList.size() - 1) {
spss.addEndText("+");
}
xPos += spss.getWidth() + 14;
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);
}
}
};
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setPreferredWidth(400);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setMinWidth(400);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDefinition).setPreferredWidth(30);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class ClientDocumentManager method getBioModelXML.
/**
* Insert the method's description here.
* Creation date: (3/29/2004 4:04:16 PM)
* @return java.lang.String
* @param vType cbit.sql.VersionableType
* @param vKey cbit.sql.KeyValue
*/
private XMLHolder<BioModel> getBioModelXML(KeyValue vKey) throws DataAccessException {
try {
String xmlString = (String) xmlHash.get(vKey);
if (xmlString == null) {
BigString xmlBS = sessionManager.getUserMetaDbServer().getBioModelXML(vKey);
xmlString = (xmlBS != null ? xmlBS.toString() : null);
if (xmlString != null) {
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(xmlString));
String newXmlString = XmlHelper.bioModelToXML(bioModel);
xmlHash.put(vKey, newXmlString);
return new XMLHolder<BioModel>(newXmlString, bioModel);
} else {
throw new RuntimeException("unexpected: UserMetaDbServer.getBioModelXML() returned null");
}
} else {
return new XMLHolder<BioModel>(xmlString);
}
} catch (ObjectNotFoundException e) {
throw new DataAccessException("BioModel (id=" + vKey + ") does not exist. It either " + "has been deleted or its reference is outdated. Please use menu 'Server->Reconnect' to update document references.");
} catch (Exception e) {
e.printStackTrace(System.out);
throw FailToLoadDocumentExc.createException(e, vKey, this);
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class ClientDocumentManager method saveAsNew.
/**
* Insert the method's description here.
* Creation date: (1/19/01 11:27:52 AM)
*/
public BioModel saveAsNew(BioModel bioModel, java.lang.String newName, String[] independentSims) throws DataAccessException {
try {
String bioModelXML = null;
try {
bioModel.getVCMetaData().cleanupMetadata();
bioModelXML = XmlHelper.bioModelToXML(bioModel);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
String savedBioModelXML = sessionManager.getUserMetaDbServer().saveBioModelAs(new BigString(bioModelXML), newName, independentSims).toString();
BioModel savedBioModel = getBioModelFromDatabaseXML(new XMLHolder<BioModel>(savedBioModelXML));
KeyValue savedKey = savedBioModel.getVersion().getVersionKey();
if (xmlHash.get(savedKey) == null) {
xmlHash.put(savedKey, savedBioModelXML);
}
BioModelInfo savedBioModelInfo = new BioModelInfo(savedBioModel.getVersion(), savedBioModel.getModel().getKey(), savedBioModel.createBioModelChildSummary(), VCellSoftwareVersion.fromSystemProperty());
bioModelInfoHash.put(savedKey, savedBioModelInfo);
SimulationContext[] scArr = savedBioModel.getSimulationContexts();
for (int i = 0; i < scArr.length; i++) {
updateGeometryRelatedHashes(scArr[i].getGeometry());
}
fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, savedBioModelInfo));
return savedBioModel;
} catch (RemoteProxyException e) {
e.printStackTrace(System.out);
throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class ClientDocumentManager method save.
/**
* Insert the method's description here.
* Creation date: (10/28/00 12:08:30 AM)
*/
public BioModel save(BioModel bioModel, String[] independentSims) throws DataAccessException {
try {
String bioModelXML = null;
try {
bioModel.getVCMetaData().cleanupMetadata();
bioModelXML = XmlHelper.bioModelToXML(bioModel);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
String savedBioModelXML = sessionManager.getUserMetaDbServer().saveBioModel(new BigString(bioModelXML), independentSims).toString();
BioModel savedBioModel = getBioModelFromDatabaseXML(new XMLHolder<BioModel>(savedBioModelXML));
KeyValue savedKey = savedBioModel.getVersion().getVersionKey();
if (xmlHash.get(savedKey) == null) {
xmlHash.put(savedKey, savedBioModelXML);
}
BioModelInfo savedBioModelInfo = new BioModelInfo(savedBioModel.getVersion(), savedBioModel.getModel().getKey(), savedBioModel.createBioModelChildSummary(), VCellSoftwareVersion.fromSystemProperty());
bioModelInfoHash.put(savedKey, savedBioModelInfo);
SimulationContext[] scArr = savedBioModel.getSimulationContexts();
for (int i = 0; i < scArr.length; i++) {
updateGeometryRelatedHashes(scArr[i].getGeometry());
}
// copy some transient info from the old model to the new one
for (SimulationContext newsc : scArr) {
SimulationContext oldsc = bioModel.getSimulationContext(newsc.getName());
newsc.getTaskCallbackProcessor().initialize((oldsc.getTaskCallbackProcessor()));
newsc.setMostRecentlyCreatedOutputSpec(oldsc.getMostRecentlyCreatedOutputSpec());
newsc.setMd5hash(oldsc.getMd5hash());
}
fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, savedBioModelInfo));
return savedBioModel;
} catch (RemoteProxyException e) {
e.printStackTrace(System.out);
throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class ClientDocumentManager method getBioModel.
/**
* Insert the method's description here.
* Creation date: (11/14/00 4:02:44 PM)
* @return cbit.vcell.biomodel.BioModel
* @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
*/
public BioModel getBioModel(KeyValue bioModelKey) throws DataAccessException {
XMLHolder<BioModel> bioModelXML = getBioModelXML(bioModelKey);
BioModel bioModel = getBioModelFromDatabaseXML(bioModelXML);
// if the positive & negative features for the membranes are not already set, set them using struct topology.
bioModel.getModel().getElectricalTopology().populateFromStructureTopology();
//
// preload SimulationJobStatus for all simulations if any missing from hash.
//
Simulation[] simulations = bioModel.getSimulations();
KeyValue[] simKeys = new KeyValue[simulations.length];
for (int i = 0; i < simulations.length; i++) {
VCSimulationIdentifier vcSimulationIdentifier = simulations[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
simKeys[i] = vcSimulationIdentifier.getSimulationKey();
}
preloadSimulationStatus(simKeys);
return bioModel;
}
Aggregations