use of cbit.gui.ScopedExpression 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.gui.ScopedExpression in project vcell by virtualcell.
the class ElectricalMembraneMappingTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
MembraneMapping membraneMapping = getValueAt(rowIndex);
switch(columnIndex) {
case COLUMN_CALCULATE_POTENTIAL:
{
boolean bCalculatePotential = ((Boolean) aValue).booleanValue();
membraneMapping.setCalculateVoltage(bCalculatePotential);
fireTableRowsUpdated(rowIndex, rowIndex);
break;
}
case COLUMN_INITIAL_POTENTIAL:
{
Expression newExpression = null;
try {
if (aValue instanceof String) {
String newExpressionString = (String) aValue;
newExpression = new Expression(newExpressionString);
}
membraneMapping.getInitialVoltageParameter().setExpression(newExpression);
fireTableRowsUpdated(rowIndex, rowIndex);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
case COLUMN_SPECIFIC_CAPACITANCE:
{
Expression newExpression = null;
try {
if (aValue instanceof String) {
String newExpressionString = (String) aValue;
newExpression = new Expression(newExpressionString);
} else if (aValue instanceof ScopedExpression) {
// newExpression = ((ScopedExpression)aValue).getExpression();
throw new RuntimeException("unexpected value type ScopedExpression");
}
membraneMapping.getSpecificCapacitanceParameter().setExpression(newExpression);
fireTableRowsUpdated(rowIndex, rowIndex);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
}
}
use of cbit.gui.ScopedExpression in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method getValueAt.
/**
* getValueAt method comment.
*/
public Object getValueAt(int row, int col) {
try {
SpeciesContextSpec scSpec = getValueAt(row);
ColumnType columnType = columns.get(col);
switch(columnType) {
case COLUMN_SPECIESCONTEXT:
{
return scSpec.getSpeciesContext();
}
case COLUMN_STRUCTURE:
{
return scSpec.getSpeciesContext().getStructure();
}
case COLUMN_DEPICTION:
{
return scSpec.getSpeciesContext().getSpeciesPattern();
}
case COLUMN_CLAMPED:
{
return new Boolean(scSpec.isConstant());
}
case COLUMN_WELLMIXED:
{
return (scSpec.isConstant() || scSpec.isWellMixed()) && !getSimulationContext().isStoch();
}
case COLUMN_INITIAL:
{
SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
if (initialConditionParameter != null) {
return new ScopedExpression(initialConditionParameter.getExpression(), initialConditionParameter.getNameScope(), true, true, autoCompleteSymbolFilter);
} else {
return null;
}
}
case COLUMN_DIFFUSION:
{
SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
if (diffusionParameter != null && !scSpec.isConstant() && scSpec.isWellMixed() != null && !scSpec.isWellMixed()) {
return new ScopedExpression(diffusionParameter.getExpression(), diffusionParameter.getNameScope(), true, true, autoCompleteSymbolFilter);
} else {
return null;
}
}
case COLUMN_FORCECONTINUOUS:
{
return new Boolean(scSpec.isForceContinuous());
}
default:
{
return null;
}
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
return null;
}
}
use of cbit.gui.ScopedExpression in project vcell by virtualcell.
the class ParameterTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Parameter parameter = getValueAt(rowIndex);
// try {
switch(columnIndex) {
case COLUMN_NAME:
{
try {
if (aValue instanceof String) {
String newName = (String) aValue;
if (!parameter.getName().equals(newName)) {
if (parameter instanceof Kinetics.KineticsParameter) {
reactionStep.getKinetics().renameParameter(parameter.getName(), newName);
} else if (parameter instanceof Kinetics.KineticsProxyParameter) {
parameter.setName(newName);
}
fireTableRowsUpdated(rowIndex, rowIndex);
}
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
}
break;
}
case COLUMN_IS_GLOBAL:
{
if (aValue.equals(Boolean.FALSE)) {
// check box has been <unset> (<true> to <false>) : change param from global to local
if ((parameter instanceof KineticsProxyParameter) && ((((KineticsProxyParameter) parameter).getTarget() instanceof Model.ReservedSymbol) || (((KineticsProxyParameter) parameter).getTarget() instanceof SpeciesContext) || (((KineticsProxyParameter) parameter).getTarget() instanceof ModelQuantity))) {
PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a " + ((KineticsProxyParameter) parameter).getTarget().getClass() + " in the model; cannot convert it to a local kinetic parameter.");
} else {
try {
reactionStep.getKinetics().convertParameterType(parameter, false);
} catch (PropertyVetoException pve) {
pve.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + pve.getMessage());
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + e.getMessage());
}
}
} else {
// check box has been <set> (<false> to <true>) : change param from local to global
if ((parameter instanceof KineticsParameter) && (((KineticsParameter) parameter).getRole() != Kinetics.ROLE_UserDefined)) {
PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a pre-defined kinetics parameter (not user-defined); cannot convert it to a model level (global) parameter.");
} else {
ModelParameter mp = reactionStep.getKinetics().getReactionStep().getModel().getModelParameter(parameter.getName());
// model already had the model parameter 'param', but check if 'param' value is different from
// model parameter with same name. If it is, the local value will be overridden by global (model) param
// value, and user should be warned.
String choice = "Ok";
if (mp != null && !(mp.getExpression().compareEqual(parameter.getExpression()))) {
String msgStr = "Model already has a global parameter named : \'" + parameter.getName() + "\'; with value = \'" + mp.getExpression().infix() + "\'; This local parameter \'" + parameter.getName() + "\' with value = \'" + parameter.getExpression().infix() + "\' will be overridden by the global value. \nPress \'Ok' to override " + "local value with global value of \'" + parameter.getName() + "\'. \nPress \'Cancel\' to retain new local value.";
choice = PopupGenerator.showWarningDialog(ownerTable, msgStr, new String[] { "Ok", "Cancel" }, "Ok");
}
if (choice.equals("Ok")) {
try {
// Now 'parameter' is a local kinetic parameter. If it is not numeric, and if its expression
// contains other local kinetic parameters, warn user that 'parameter' cannot be promoted because
// of its expression containing other local parameters.
boolean bPromoteable = true;
if (!parameter.getExpression().isNumeric()) {
String[] symbols = parameter.getExpression().getSymbols();
for (int i = 0; i < symbols.length; i++) {
if (reactionStep.getKinetics().getKineticsParameter(symbols[i]) != null) {
PopupGenerator.showErrorDialog(ownerTable, "Parameter \'" + parameter.getName() + "\' contains other local kinetic parameters; Cannot convert it to global until the referenced parameters are global.");
bPromoteable = false;
}
}
}
if (bPromoteable) {
reactionStep.getKinetics().convertParameterType(parameter, true);
}
} catch (PropertyVetoException pve) {
pve.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + pve.getMessage());
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + e.getMessage());
}
}
}
}
fireTableRowsUpdated(rowIndex, rowIndex);
break;
}
case COLUMN_VALUE:
{
try {
if (aValue instanceof ScopedExpression) {
// }
throw new RuntimeException("unexpected value type ScopedExpression");
} else if (aValue instanceof String) {
String newExpressionString = (String) aValue;
if (parameter instanceof Kinetics.KineticsParameter) {
reactionStep.getKinetics().setParameterValue((Kinetics.KineticsParameter) parameter, new Expression(newExpressionString));
} else if (parameter instanceof Kinetics.KineticsProxyParameter) {
parameter.setExpression(new Expression(newExpressionString));
}
}
reactionStep.getKinetics().resolveUndefinedUnits();
fireTableRowsUpdated(rowIndex, rowIndex);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Error:\n" + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
}
break;
}
case COLUMN_UNITS:
{
try {
if (aValue instanceof String && parameter instanceof Kinetics.KineticsParameter && ((Kinetics.KineticsParameter) parameter).getRole() == Kinetics.ROLE_UserDefined) {
String newUnitString = (String) aValue;
Kinetics.KineticsParameter kineticsParm = (Kinetics.KineticsParameter) parameter;
ModelUnitSystem modelUnitSystem = reactionStep.getModel().getUnitSystem();
if (!kineticsParm.getUnitDefinition().getSymbol().equals(newUnitString)) {
kineticsParm.setUnitDefinition(modelUnitSystem.getInstance(newUnitString));
reactionStep.getKinetics().resolveUndefinedUnits();
fireTableRowsUpdated(rowIndex, rowIndex);
}
}
} catch (VCUnitException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter unit:\n" + e.getMessage());
}
break;
}
}
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
use of cbit.gui.ScopedExpression in project vcell by virtualcell.
the class TransformMassActionTableModel method getValueAt.
// end of method getRowCount()
/**
* display data in table
*/
public Object getValueAt(int row, int col) {
try {
if (row < 0 || row >= getRowCount()) {
throw new RuntimeException("TransformMassActionTableModel.getValueAt(), row = " + row + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
}
if (col < 0 || col >= NUM_COLUMNS) {
throw new RuntimeException("TransfromMassActionTableModel.getValueAt(), column = " + col + " out of range [" + 0 + "," + (NUM_COLUMNS - 1) + "]");
}
Kinetics origKinetics = getModel().getReactionSteps()[row].getKinetics();
MassActionSolver.MassActionFunction maFunc = transMAs.getTransformedReactionSteps()[row].getMassActionFunction();
switch(col) {
case COLUMN_REACTION:
{
return getModel().getReactionSteps()[row].getName();
}
case COLUMN_REACTIONTYPE:
{
if (getModel().getReactionSteps()[row] instanceof SimpleReaction) {
return "reaction";
} else {
return "flux";
}
}
case COLUMN_KINETICS:
{
if (origKinetics != null) {
return origKinetics.getKineticsDescription().getDescription();
}
return null;
}
case COLUMN_RATE:
{
if (origKinetics != null) {
Kinetics.KineticsParameter ratePara = origKinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate);
if (ratePara != null && ratePara.getExpression() != null) {
return new ScopedExpression(ratePara.getExpression(), ratePara.getNameScope(), false, true, null);
}
}
return null;
}
case COLUMN_TRANSFORM:
{
// so the checkbox will not be ticked for flux regardless it can be transformed or not.
return getIsSelected(row);
}
case COLUMN_FORWARDRATE:
{
if (maFunc != null && maFunc.getForwardRate() != null) {
return new ScopedExpression(maFunc.getForwardRate(), null, false, true, null);
}
return null;
}
case COLUMN_REVERSERATE:
{
if (maFunc != null && maFunc.getReverseRate() != null) {
return new ScopedExpression(maFunc.getReverseRate(), null, false, true, null);
}
return null;
}
case COLUMN_REMARK:
{
if (transMAs.getTransformedReactionSteps()[row] != null) {
return transMAs.getTransformedReactionSteps()[row].getTransformRemark();
}
return null;
}
default:
{
return null;
}
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
return null;
}
}
Aggregations