use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class ScopedExpressionTableCellRenderer method getTableCellRendererComponent.
/**
* This method is sent to the renderer by the drawing table to
* configure the renderer appropriately before drawing. Return
* the Component used for drawing.
*
* @param table the JTable that is asking the renderer to draw.
* This parameter can be null.
* @param value the value of the cell to be rendered. It is
* up to the specific renderer to interpret
* and draw the value. eg. if value is the
* String "true", it could be rendered as a
* string or it could be rendered as a check
* box that is checked. null is a valid value.
* @param isSelected true is the cell is to be renderer with
* selection highlighting
* @param row the row index of the cell being drawn. When
* drawing the header the rowIndex is -1.
* @param column the column index of the cell being drawn
*/
public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
try {
TableModel tableModel = table.getModel();
if (value == null) {
templateJLabel.setIcon(null);
templateJLabel.setText(null);
templateJLabel.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (tableModel instanceof VCellSortTableModel) {
if (row < ((VCellSortTableModel<?>) tableModel).getRowCount()) {
Object rowObject = ((VCellSortTableModel<?>) tableModel).getValueAt(row);
if (rowObject instanceof SpeciesContextSpecParameter) {
templateJLabel.setText(((SpeciesContextSpecParameter) rowObject).getNullExpressionDescription());
}
}
}
return templateJLabel;
}
if (!(value instanceof ScopedExpression)) {
return stringRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
imageRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
JLabel renderer = imageRenderer;
ScopedExpression scopedExpression = (ScopedExpression) value;
String scopedExpressInfix = scopedExpression.infix();
ReusableExpressionIcon rei = scopedExpressionImageIconHash.get(scopedExpressInfix);
if (rei != null && rei.background.equals(imageRenderer.getBackground()) && rei.foreground.equals(imageRenderer.getForeground())) {
// Re-use existing ImageIcon is it exists and is same state
imageRenderer.setIcon(rei.imageIcon);
} else {
// Create new ImageIcon
try {
ExpressionPrintFormatter epf = new ExpressionPrintFormatter(scopedExpression.getRenamedExpression());
//
// Use graphicsContextProvider BufferedImage to get started because
// theTable may have a null GC and epf needs a non-null GC
//
java.awt.Graphics2D tempG2D = (java.awt.Graphics2D) graphicsContextProvider.getGraphics();
// Must set here before epf.getSize is called
tempG2D.setFont(italicFont);
// Determine how big the expression image will be
java.awt.Dimension dim = epf.getSize(tempG2D);
// Create and render the expression image
java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(dim.width, dim.height, java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D g2d = bi.createGraphics();
// epf.paint needs a non-null clipBounds
g2d.setClip(0, 0, dim.width, dim.height);
// set the SAME font used in epf.getSize
g2d.setFont(italicFont);
if (table != null && imageRenderer != null) {
g2d.setBackground(imageRenderer.getBackground());
g2d.setColor(imageRenderer.getForeground());
}
// paint background
g2d.clearRect(0, 0, dim.width, dim.height);
// paint expression into image
epf.paint(g2d);
// Limit cacheing in case a large number of DIFFERENT expressions are being serviced by this TableCellRenderer.
if ((scopedExpressionCacheSize + (dim.width * dim.height)) >= CACHE_SIZE_LIMIT) {
scopedExpressionImageIconHash.clear();
scopedExpressionCacheSize = 0;
}
javax.swing.ImageIcon newImageIcon = new javax.swing.ImageIcon(bi);
rei = new ReusableExpressionIcon(newImageIcon, imageRenderer.getBackground(), imageRenderer.getForeground());
if (scopedExpressionImageIconHash.put(scopedExpressInfix, rei) == null) {
scopedExpressionCacheSize += dim.width * dim.height;
}
imageRenderer.setIcon(newImageIcon);
} catch (Exception e) {
// Fallback to String
e.printStackTrace();
templateJLabel.setText(scopedExpression.infix());
renderer = templateJLabel;
}
}
ExpressionBindingException expressionBindingException = scopedExpression.getExpressionBindingException();
if (expressionBindingException != null) {
renderer.setBorder(BorderFactory.createLineBorder(Color.red));
renderer.setToolTipText(expressionBindingException.getMessage());
} else {
renderer.setBorder(BorderFactory.createEmptyBorder());
renderer.setToolTipText(null);
}
if (tableModel instanceof VCellSortTableModel) {
List<Issue> issueList = ((VCellSortTableModel<?>) tableModel).getIssues(row, column, Issue.SEVERITY_ERROR);
if (issueList.size() > 0) {
renderer.setToolTipText(Issue.getHtmlIssueMessage(issueList));
if (column == 0) {
renderer.setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
} else if (column == table.getColumnCount() - 1) {
renderer.setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
} else {
renderer.setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
}
} else {
renderer.setBorder(BORDER);
}
}
return renderer;
} catch (Exception e) {
e.printStackTrace();
templateJLabel.setText("ScopedExpressionTableCellRenderer Error - " + e.getMessage() + " " + value);
return templateJLabel;
}
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class ViewJobsPanel method initialize.
private void initialize() {
try {
setName("ViewSimulationJobsPanel");
getRefreshAllButton().addActionListener(eventHandler);
// ----------------------------------------------------------------------------------
// filters, buttons
JPanel top = new JPanel();
// table with results
JPanel bottom = new JPanel();
Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
TitledBorder titleTop = BorderFactory.createTitledBorder(loweredEtchedBorder, " Query Filters ");
titleTop.setTitleJustification(TitledBorder.LEFT);
titleTop.setTitlePosition(TitledBorder.TOP);
TitledBorder titleBottom = BorderFactory.createTitledBorder(loweredEtchedBorder, " Query Results ");
titleBottom.setTitleJustification(TitledBorder.LEFT);
titleBottom.setTitlePosition(TitledBorder.TOP);
top.setBorder(titleTop);
bottom.setBorder(titleBottom);
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
// top, left, bottom, right
gbc.insets = new Insets(5, 2, 2, 3);
add(top, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5, 2, 2, 3);
add(bottom, gbc);
// --------------------------------------- top panel (filters, button) --------------
// filters
JPanel left = new JPanel();
JPanel center = new SeparatedJPanel();
// buttons
JPanel right = new SeparatedJPanel();
top.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 3);
top.add(left, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5, 2, 2, 3);
top.add(center, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5, 2, 2, 3);
top.add(right, gbc);
// ------------------------------------ left panel (of top panel) -------------
left.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 0);
left.add(getWaitingButton(), gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 3);
JLabel label = new JLabel(waitingIcon);
left.add(label, gbc);
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 15, 2, 0);
left.add(getQueuedButton(), gbc);
gbc.gridx = 3;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 10);
label = new JLabel(queuedIcon);
left.add(label, gbc);
// -------------------------------------
gbc.gridx = 0;
gbc.gridy = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 0);
left.add(getDispatchedButton(), gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 3);
label = new JLabel(dispatchedIcon);
left.add(label, gbc);
gbc.gridx = 2;
gbc.gridy = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 15, 2, 0);
left.add(getRunningButton(), gbc);
gbc.gridx = 3;
gbc.gridy = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 10);
label = new JLabel(runningIcon);
left.add(label, gbc);
// -------------------------------------
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 0);
left.add(getCompletedButton(), gbc);
gbc.gridx = 1;
gbc.gridy = 2;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 3);
label = new JLabel(completedIcon);
left.add(label, gbc);
gbc.gridx = 2;
gbc.gridy = 2;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 15, 2, 3);
left.add(getFailedButton(), gbc);
gbc.gridx = 3;
gbc.gridy = 2;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 10);
label = new JLabel(failedIcon);
left.add(label, gbc);
// -------------------------------------
gbc.gridx = 0;
gbc.gridy = 3;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 0);
left.add(getStoppedButton(), gbc);
gbc.gridx = 1;
gbc.gridy = 3;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 0, 2, 3);
label = new JLabel(stoppedIcon);
left.add(label, gbc);
// ---------------------------------------- center panel (of top panel) ------------
center.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.insets = new Insets(4, 15, 4, 4);
center.add(new JLabel("Max # of results "), gbc);
textFieldJobsLimit = new JTextField();
textFieldJobsLimit.addActionListener(eventHandler);
// textFieldJobsLimit.getDocument().addDocumentListener(eventHandler);
textFieldJobsLimit.setText(maxRows + "");
Dimension d = textFieldJobsLimit.getPreferredSize();
d.width = 80;
textFieldJobsLimit.setPreferredSize(d);
textFieldJobsLimit.setMaximumSize(d);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.insets = new Insets(4, 0, 4, 4);
center.add(textFieldJobsLimit, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 15, 2, 3);
center.add(getOrphanedButton(), gbc);
// gbc = new GridBagConstraints();
// gbc.weighty = 1.0;
// gbc.gridx = 0;
// gbc.gridy = 2;
// // gbc.gridheight = GridBagConstraints.REMAINDER;
// gbc.anchor = GridBagConstraints.WEST;
// gbc.fill = java.awt.GridBagConstraints.VERTICAL;
// gbc.insets = new Insets(4,4,4,4);
// center.add(new JLabel("---"), gbc); // fake vertical
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 11, 4, 4);
center.add(getSubmitDatePanel(), gbc);
gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 3;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 4);
// fake horizontal
center.add(new JLabel("-"), gbc);
// ---------------------------------------- right panel (of top panel) -------------
right.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = java.awt.GridBagConstraints.VERTICAL;
// fake vertical
right.add(new JLabel(""), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 12, 4, 8);
right.add(getRefreshAllButton(), gbc);
getCompletedButton().setSelected(false);
getDispatchedButton().setSelected(true);
getFailedButton().setSelected(true);
getQueuedButton().setSelected(true);
getRunningButton().setSelected(true);
getStoppedButton().setSelected(true);
getWaitingButton().setSelected(true);
getOrphanedButton().setSelected(false);
getSubmitBetweenButton().setSelected(false);
// ----------------------------------------- bottom panel (the table) -------------------
table = new EditorScrollTable();
model = new SimulationJobsTableModel(table, this);
table.setModel(model);
table.getSelectionModel().addListSelectionListener(eventHandler);
table.getModel().addTableModelListener(eventHandler);
table.addMouseMotionListener(new // add toolTipText for each table cell
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)));
}
});
bottom.setLayout(new GridBagLayout());
int gridy = 0;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
// table.setPreferredScrollableViewportSize(new Dimension(700,350)); // apparently useless
bottom.add(table.getEnclosingScrollPane(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.insets = new Insets(4, 4, 4, 4);
bottom.add(new JLabel("Search "), gbc);
textFieldSearch = new JTextField(70);
textFieldSearch.addActionListener(eventHandler);
textFieldSearch.getDocument().addDocumentListener(eventHandler);
textFieldSearch.putClientProperty("JTextField.variant", "search");
gbc = new java.awt.GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 0, 4, 4);
bottom.add(textFieldSearch, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
bottom.add(countLabel, gbc);
// renderer for the status icon; the tooltip gives the text
DefaultScrollTableCellRenderer statusCellRenderer = 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);
setText((String) value);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == model) {
selectedObject = model.getValueAt(row);
}
if (selectedObject != null && selectedObject instanceof SimpleJobStatus) {
SimpleJobStatus js = (SimpleJobStatus) selectedObject;
SchedulerStatus ss1 = js.jobStatus.getSchedulerStatus();
switch(ss1) {
case WAITING:
setIcon(waitingIcon);
break;
case QUEUED:
setIcon(queuedIcon);
break;
case DISPATCHED:
setIcon(dispatchedIcon);
break;
case RUNNING:
setIcon(runningIcon);
break;
case COMPLETED:
setIcon(completedIcon);
break;
case STOPPED:
setIcon(stoppedIcon);
break;
case FAILED:
setIcon(failedIcon);
break;
default:
setIcon(failedIcon);
break;
}
// setText("");
setToolTipText(ss1.getDescription());
setHorizontalTextPosition(SwingConstants.RIGHT);
}
}
return this;
}
};
// statusCellRenderer.setHorizontalAlignment(JLabel.RIGHT);
DefaultScrollTableCellRenderer dateTimeCellRenderer = 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);
setText((String) value);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == model) {
selectedObject = model.getValueAt(row);
}
if (selectedObject != null && selectedObject instanceof SimpleJobStatus) {
SimpleJobStatus sjs = (SimpleJobStatus) selectedObject;
DateFormat df = new SimpleDateFormat("MM.dd.yyyy HH:MM:SS");
Date date = sjs.jobStatus.getStartDate();
String str = df.format(date);
setToolTipText(str);
}
}
return this;
}
};
DefaultScrollTableCellRenderer hasDataCellRenderer = 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);
setText((String) value);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == model) {
selectedObject = model.getValueAt(row);
}
if (selectedObject != null && selectedObject instanceof SimpleJobStatus) {
SimpleJobStatus sjs = (SimpleJobStatus) selectedObject;
if (sjs.jobStatus.hasData()) {
setIcon(dataYesIcon);
} else {
setIcon(dataNoIcon);
}
}
}
return this;
}
};
table.getColumnModel().getColumn(SimulationJobsTableModel.iColStatus).setCellRenderer(statusCellRenderer);
table.getColumnModel().getColumn(SimulationJobsTableModel.iColSubmitDate).setCellRenderer(dateTimeCellRenderer);
table.getColumnModel().getColumn(SimulationJobsTableModel.iColHasData).setCellRenderer(hasDataCellRenderer);
// table.getColumnModel().getColumn(SimulationJobsTableModel.iColDepiction).setMinWidth(400);
// table.getColumnModel().getColumn(SimulationJobsTableModel.iColStatus).setPreferredWidth(30);
// table.getColumnModel().getColumn(SimulationJobsTableModel.iColStatus).setMaxWidth(30);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
refreshInterface();
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class InitialConditionsPanel method initialize.
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("InitialConditionsPanel");
setLayout(new BorderLayout());
add(getRadioButtonAndCheckboxPanel(), BorderLayout.NORTH);
add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
getJMenuItemPaste().addActionListener(ivjEventHandler);
getJMenuItemCopy().addActionListener(ivjEventHandler);
getJMenuItemCopyAll().addActionListener(ivjEventHandler);
getJMenuItemPasteAll().addActionListener(ivjEventHandler);
getAmountRadioButton().addActionListener(ivjEventHandler);
getConcentrationRadioButton().addActionListener(ivjEventHandler);
getRandomizeInitCondnCheckbox().addActionListener(ivjEventHandler);
DefaultTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setIcon(null);
defaultToolTipText = null;
if (value instanceof Species) {
setText(((Species) value).getCommonName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof SpeciesContext) {
setText(((SpeciesContext) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof Structure) {
setText(((Structure) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof ScopedExpression) {
SpeciesContextSpec scSpec = tableModel.getValueAt(row);
VCUnitDefinition unit = null;
if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_INITIAL.label)) {
SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
unit = initialConditionParameter.getUnitDefinition();
} else if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_DIFFUSION.label)) {
SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
unit = diffusionParameter.getUnitDefinition();
}
if (unit != null) {
setHorizontalTextPosition(JLabel.LEFT);
setIcon(new TextIcon("[" + unit.getSymbolUnicode() + "]", DefaultScrollTableCellRenderer.uneditableForeground));
}
int rgb = 0x00ffffff & DefaultScrollTableCellRenderer.uneditableForeground.getRGB();
defaultToolTipText = "<html>" + StringEscapeUtils.escapeHtml4(getText()) + " <font color=#" + Integer.toHexString(rgb) + "> [" + unit.getSymbolUnicode() + "] </font></html>";
setToolTipText(defaultToolTipText);
if (unit != null) {
setText(defaultToolTipText);
}
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
setHorizontalTextPosition(JLabel.TRAILING);
}
return this;
}
};
DefaultTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
// sp may be null for "plain" species contexts
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, shapeManager, 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);
}
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class ModelProcessSpecsPanel method initConnections.
/**
* Initializes connections
* @exception java.lang.Exception The exception description.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
this.addPropertyChangeListener(ivjEventHandler);
getScrollPaneTable().setModel(getModelProcessSpecsTableModel());
getScrollPaneTable().setDefaultRenderer(ModelProcess.class, new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
defaultToolTipText = null;
if (value instanceof ModelProcess) {
setText(((ModelProcess) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
}
return this;
}
});
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() == ivjModelProcessSpecsTableModel) {
selectedObject = ivjModelProcessSpecsTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof ModelProcessSpec) {
ModelProcessSpec mps = (ModelProcessSpec) selectedObject;
ModelProcess mp = (ModelProcess) mps.getModelProcess();
if (mp instanceof ReactionRule) {
ReactionRule rr = (ReactionRule) mp;
Graphics panelContext = table.getGraphics();
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, shapeManager, 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() + 15;
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, shapeManager, panelContext, rr, isSelected, issueManager);
if (i < ppList.size() - 1) {
spss.addEndText("+");
}
xPos += spss.getWidth() + 15;
spssList.add(spss);
}
} else {
ReactionStep rs = (ReactionStep) mp;
Graphics panelContext = table.getGraphics();
spssList.clear();
int xPos = 4;
int extraSpace = 0;
for (int i = 0; i < rs.getNumReactants(); i++) {
SpeciesPattern sp = rs.getReactant(i).getSpeciesContext().getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rs, isSelected, issueManager);
if (i < rs.getNumReactants() - 1) {
spss.addEndText("+");
} else {
if (rs.isReversible()) {
spss.addEndText("<->");
extraSpace += 7;
} else {
spss.addEndText("->");
}
}
int offset = sp == null ? 17 : 15;
offset += extraSpace;
int w = spss.getWidth();
xPos += w + offset;
spssList.add(spss);
}
xPos += 8;
for (int i = 0; i < rs.getNumProducts(); i++) {
SpeciesPattern sp = rs.getProduct(i).getSpeciesContext().getSpeciesPattern();
if (i == 0 && rs.getNumReactants() == 0) {
xPos += 14;
}
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rs, isSelected, issueManager);
if (i == 0 && rs.getNumReactants() == 0) {
spss.addStartText("->");
}
if (i < rs.getNumProducts() - 1) {
spss.addEndText("+");
}
int offset = sp == null ? 17 : 15;
int w = spss.getWidth();
xPos += w + offset;
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);
}
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setPreferredWidth(180);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel 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);
}
}
Aggregations