Skip to content

Commit

Permalink
molecular details: NamedColor combobox, editor, renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
danv61 committed Oct 29, 2024
1 parent 089fbdc commit 1bc1632
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public class MolecularTypeSpecsTableModel extends VCellSortTableModel<MolecularC
// TODO: add is2D flag here as a checkbox (var is SpeciesContextSpec) - membrane species may have it set to true, for compartment species is always false
// TODO: math is wrong for a model with a membrane species, saving model fails, see model aaa-SS-membrane, see issue #1097

private enum ColumnType {
public enum ColumnType {
COLUMN_SITE("Site"),
COLUMN_MOLECULE("Molecule"),
COLUMN_STRUCTURE("Location"),
COLUMN_STATE("Initial State"),
COLUMN_RADIUS("Radius (nm)"),
COLUMN_DIFFUSION("Diff. Rate (um^2/s)"),
COLUMN_RADIUS("Radius"),
COLUMN_DIFFUSION("Diff. Rate"),
COLUMN_COLOR("Color");

public final String label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import cbit.vcell.model.Species;
import cbit.vcell.model.SpeciesContext;
import cbit.vcell.model.Structure;
import cbit.vcell.parser.Expression;
import cbit.vcell.units.VCUnitDefinition;
import org.apache.commons.lang3.StringEscapeUtils;
import org.vcell.model.rbm.MolecularComponentPattern;
Expand Down Expand Up @@ -551,9 +552,42 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
return this;
}
};
// The Expression cell renderer in the MolecularTypeSpecsTable
DefaultScrollTableCellRenderer expressionTableCellRenderer = 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 MolecularTypeSpecsTableModel) {
MolecularTypeSpecsTableModel model = (MolecularTypeSpecsTableModel)table.getModel();
if (value instanceof Double) {
String columnName = model.getColumnName(column);
if(MolecularTypeSpecsTableModel.ColumnType.COLUMN_RADIUS.ordinal() == column) {
if(!isSelected) {
String brown = "#A52A2A";
String text = "<html>" + value + "<span style='color:" + brown + ";'> [nm]</span></html>";
setText(text);
} else {
setText(value + " [nm]");
}
} else if(MolecularTypeSpecsTableModel.ColumnType.COLUMN_DIFFUSION.ordinal() == column) {
if(!isSelected) {
String darkRed = "#8B0000";
String text = "<html>" + value + "<span style='color:" + darkRed + ";'> [um^2/s]</span></html>";
setText(text);
} else {
setText(value + " [um^2/s");
}
}
}
}
return this;
}
};

getMolecularTypeSpecsTable().setDefaultRenderer(String.class, new DefaultScrollTableCellRenderer());
getMolecularTypeSpecsTable().setDefaultRenderer(Structure.class, structuresTableCellRenderer); // The Structures combobox cell renderer
getMolecularTypeSpecsTable().setDefaultRenderer(Expression.class, expressionTableCellRenderer); // Expression field cell renderer
getMolecularTypeSpecsTable().setDefaultRenderer(NamedColor.class, namedColorTableCellRenderer); // NamedColor combobox cell renderer


Expand Down

0 comments on commit 1bc1632

Please sign in to comment.