use of org.vcell.util.gui.sorttable.SortTableModel in project vcell by virtualcell.
the class DefaultScrollTableCellRenderer method getTableCellRendererComponent.
/**
* Insert the method's description here.
* Creation date: (3/27/2001 1:07:02 PM)
* @return java.awt.Component
* @param table javax.swing.JTable
* @param value java.lang.Object
* @param isSelected boolean
* @param hasFocus boolean
* @param row int
* @param column int
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
defaultToolTipText = null;
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
defaultToolTipText = getToolTipText();
setBorder(DEFAULT_GAP);
if (isSelected) {
setBackground(table.getSelectionBackground());
setForeground(table.getSelectionForeground());
} else {
if (table instanceof ScrollTable && ((ScrollTable) table).getHoverRow() == row) {
setBackground(hoverColor);
} else {
setBackground(row % 2 == 0 ? table.getBackground() : everyOtherRowColor);
}
if (table.getModel() instanceof SpatialProcessTableModel) /* && column == SpatialProcessTableModel.COLUMN_SpatialProcess_SPATIALOBJECTS */
{
boolean found = isMatchWithSelectedObject(table, row);
if (found == true) {
setBackground(Color.yellow);
}
} else if (table.getModel() instanceof SpatialObjectTableModel) /* && column == SpatialObjectTableModel.COLUMN_SpatialObject_NAME */
{
boolean found = isMatchWithSelectedProcess(table, row);
if (found == true) {
setBackground(Color.yellow);
}
}
setForeground(table.getForeground());
}
TableModel tableModel = table.getModel();
if (bEnableUneditableForeground && (!table.isEnabled() || !tableModel.isCellEditable(row, column))) {
if (!isSelected) {
setForeground(uneditableForeground);
if (tableModel instanceof NetworkConstraintsTableModel && column == NetworkConstraintsTableModel.iColValue) {
NetworkConstraintsTableModel tm = (NetworkConstraintsTableModel) tableModel;
String def = (String) tm.getValueAt(row, NetworkConstraintsTableModel.iColDefault);
String val = (String) value;
if (!val.equals(def)) {
value = "<html><b>" + value + "</b></html>";
setForeground(Color.red);
}
}
}
}
if (value instanceof Double) {
Double doubleValue = (Double) value;
setText(nicelyFormattedDouble(doubleValue));
} else if (value instanceof JComponent) {
JComponent jc = (JComponent) value;
if (hasFocus) {
jc.setBorder(focusHighlightBorder);
} else {
jc.setBorder(noFocusBorder);
}
return jc;
}
if (BioModelEditorRightSideTableModel.ADD_NEW_HERE_TEXT.equals(value)) {
setText(BioModelEditorRightSideTableModel.ADD_NEW_HERE_HTML);
} else if (value instanceof ModelProcessEquation && BioModelEditorRightSideTableModel.ADD_NEW_HERE_REACTION_TEXT.equals(((ModelProcessEquation) value).toString())) {
setText(BioModelEditorRightSideTableModel.ADD_NEW_REACTION_OR_RULE_HTML);
}
if (tableModel instanceof BioModelEditorApplicationsTableModel) {
// for the applications table we show the icons with the app type
Icon icon = null;
String toolTipSuffix = "";
BioModelEditorApplicationsTableModel bmeatm = (BioModelEditorApplicationsTableModel) tableModel;
SimulationContext simContext = (SimulationContext) (bmeatm.getValueAt(row));
if (simContext.isRuleBased()) {
if (simContext.getGeometry().getDimension() == 0) {
icon = VCellIcons.appRbmNonspIcon;
toolTipSuffix = "Rule Based / Non spatial";
}
} else if (simContext.isStoch()) {
if (simContext.getGeometry().getDimension() == 0) {
icon = VCellIcons.appStoNonspIcon;
toolTipSuffix = "Stochastic / Non spatial";
} else {
icon = VCellIcons.appStoSpatialIcon;
toolTipSuffix = "Stochastic / Spatial";
}
} else {
// deterministic
if (simContext.getGeometry().getDimension() == 0) {
icon = VCellIcons.appDetNonspIcon;
toolTipSuffix = "Deterministic / Non spatial";
} else {
icon = VCellIcons.appDetSpatialIcon;
toolTipSuffix = "Deterministic / Spatial";
}
}
String toolTipPrefix = "Application: ";
setToolTipText(toolTipPrefix + toolTipSuffix);
if (column == 0) {
setIcon(icon);
} else {
setIcon(null);
}
} else if (column == 2 && tableModel instanceof SpatialProcessTableModel) {
Icon icon = null;
SpatialProcess spatialProcess = (SpatialProcess) (((SpatialProcessTableModel) tableModel).getValueAt(row));
if (spatialProcess instanceof PointLocation) {
icon = VCellIcons.spatialPointIcon;
} else if (spatialProcess instanceof PointKinematics) {
icon = VCellIcons.spatialPointIcon;
} else if (spatialProcess instanceof SurfaceKinematics) {
icon = VCellIcons.spatialMembraneIcon;
} else {
icon = VCellIcons.spatialVolumeIcon;
}
setIcon(icon);
} else if (tableModel instanceof SortTableModel) {
// for most other tables we reserve the icon spot to display issues
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
}
return this;
}
use of org.vcell.util.gui.sorttable.SortTableModel 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);
}
}
};
DefaultScrollTableCellRenderer rulesTableCellRenderer = new DefaultScrollTableCellRenderer() {
final Color lightBlueBackground = new Color(214, 234, 248);
@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 SpeciesContextSpecsTableModel) {
Icon icon = VCellIcons.issueGoodIcon;
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (isSelected) {
setBackground(lightBlueBackground);
}
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
boolean foundRuleMatch = false;
if (fieldSimulationContext.getRateRules() != null && fieldSimulationContext.getRateRules().length > 0) {
for (RateRule rr : fieldSimulationContext.getRateRules()) {
if (rr.getRateRuleVar() == null) {
continue;
}
if (sc.getName().equals(rr.getRateRuleVar().getName())) {
foundRuleMatch = true;
icon = VCellIcons.ruleRateIcon;
break;
}
}
}
if (!foundRuleMatch && fieldSimulationContext.getAssignmentRules() != null && fieldSimulationContext.getAssignmentRules().length > 0) {
for (AssignmentRule rr : fieldSimulationContext.getAssignmentRules()) {
if (rr.getAssignmentRuleVar() == null) {
continue;
}
if (sc.getName().equals(rr.getAssignmentRuleVar().getName())) {
icon = VCellIcons.ruleAssignIcon;
break;
}
}
}
}
}
setIcon(icon);
}
return this;
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
// depiction icons
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
// rules icons
getScrollPaneTable().setDefaultRenderer(SpeciesContextSpecsTableModel.RulesProvenance.class, rulesTableCellRenderer);
// TODO: find out why the code below is not working properly
// int ordinal = SpeciesContextSpecsTableModel.ColumnType.COLUMN_RULES.ordinal();
// getScrollPaneTable().getColumnModel().getColumn(ordinal).setCellRenderer(rulesTableCellRenderer);
// final int rulesWidth = 50; // fixed max size, there's no point to enlarge some columns
// int index = SpeciesContextSpecsTableModel.ColumnType.COLUMN_RULES.ordinal();
// getScrollPaneTable().getColumnModel().getColumn(index).setPreferredWidth(rulesWidth);
// getScrollPaneTable().getColumnModel().getColumn(index).setMaxWidth(rulesWidth);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of org.vcell.util.gui.sorttable.SortTableModel 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);
}
Aggregations