use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class StructureMappingTableRenderer method getTableCellRendererComponent.
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);
if (table.getModel() instanceof StructureMappingTableModel) {
StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
String toolTip = structureMappingTableModel.getToolTip(row, column);
if (value instanceof Structure) {
Structure structure = (Structure) value;
setText(structure.getName());
} else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
if (structureMappingTableModel.isNonSpatial()) {
VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
if (sizeIcon == null) {
sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
}
setIcon(sizeIcon);
} else {
// spatial
if (structureMapping.getUnitSizeParameter() != null) {
VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
if (sizeIcon == null) {
sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
}
setIcon(sizeIcon);
}
}
}
if (structureMappingTableModel.isSubdomainColumn(column)) {
// can be null
if (value == null) {
setText("Unmapped");
setForeground(Color.red);
setIcon(null);
} else {
if (value instanceof GeometryClass) {
setText(((GeometryClass) value).getName());
if (value instanceof SubVolume) {
SubVolume subVolume = (SubVolume) value;
java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
// small square icon with subdomain color
Icon icon = new ColorIcon(10, 10, handleColor, true);
setHorizontalTextPosition(SwingConstants.RIGHT);
setIcon(icon);
} else if (value instanceof SurfaceClass) {
SurfaceClass sc = (SurfaceClass) value;
Set<SubVolume> sv = sc.getAdjacentSubvolumes();
Iterator<SubVolume> iterator = sv.iterator();
SubVolume sv1 = iterator.next();
SubVolume sv2 = iterator.next();
java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
Icon icon = new ColorIconEx(10, 10, c1, c2);
setIcon(icon);
setHorizontalTextPosition(SwingConstants.RIGHT);
}
} else {
setText(value.toString());
setIcon(null);
}
}
}
if (value instanceof BoundaryConditionType) {
// we get here only for spatial
Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
if (candidate instanceof SurfaceClass) {
SurfaceClass surfaceClass = (SurfaceClass) candidate;
cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
SubVolume innerSubVolume = ret.one;
java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
// small square icon with subdomain color
Icon icon = new ColorIcon(8, 8, handleColor, true);
setHorizontalTextPosition(SwingConstants.LEFT);
setIcon(icon);
setText("from");
// override default tooltip
toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
setToolTipText(toolTip);
} else {
setText(((BoundaryConditionType) value).boundaryTypeStringValue());
}
}
List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
if (issueList.size() > 0) {
// override default tooltip
setToolTipText(Issue.getHtmlIssueMessage(issueList));
if (column == 0) {
setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
} else if (column == table.getColumnCount() - 1) {
setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
} else {
setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
}
} else {
setToolTipText(toolTip);
setBorder(DEFAULT_GAP);
}
}
return this;
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method setSimulationContext.
/**
* Sets the simulationContext property (cbit.vcell.mapping.SimulationContext) value.
* @param simulationContext The new value for the property.
* @see #getSimulationContext
*/
public void setSimulationContext(SimulationContext simulationContext) {
SimulationContext oldValue = fieldSimulationContext;
int oldColumnCount = getColumnCount();
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
oldValue.getGeometryContext().removePropertyChangeListener(this);
updateListenersReactionContext(oldValue.getReactionContext(), true);
}
fieldSimulationContext = simulationContext;
refreshColumns();
int newColumnCount = getColumnCount();
if (oldColumnCount != newColumnCount) {
fireTableStructureChanged();
}
if (simulationContext != null) {
simulationContext.addPropertyChangeListener(this);
simulationContext.getGeometryContext().addPropertyChangeListener(this);
updateListenersReactionContext(simulationContext.getReactionContext(), false);
autoCompleteSymbolFilter = simulationContext.getAutoCompleteSymbolFilter();
refreshData();
}
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class GeneratedReactionTableModel method getValueAt.
public Object getValueAt(int iRow, int iCol) {
GeneratedReactionTableRow reactionTableRow = getValueAt(iRow);
BNGReaction reactionObject = reactionTableRow.getReactionObject();
String name = reactionObject.getRuleName();
switch(iCol) {
case iColRule:
if (name.endsWith(ReactionRule.DirectHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
}
if (name.endsWith(ReactionRule.InverseHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
name += " (rev)";
}
return name;
case iColStructure:
if (name.endsWith(ReactionRule.DirectHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
}
if (name.endsWith(ReactionRule.InverseHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
}
SimulationContext sc = owner.getSimulationContext();
ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
if (rr != null && rr.getStructure() != null) {
return rr.getStructure().getName();
} else {
return "?";
}
case iColDepiction:
case iColDefinition:
return reactionTableRow.getExpression();
default:
return null;
}
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class NfsimExtensionFilter method writeBioModel.
@Override
public void writeBioModel(DocumentManager documentManager, BioModel bioModel, File exportFile, SimulationContext simulationContext) throws Exception {
// TODO: get the first thing we find for now, in the future we'll need to modify ChooseFile
// to only offer the applications / simulations with bngl content
// This should be done by creating one or more additional Selector values and add the filtering logic to ChooseFile
SimulationContext[] simContexts = bioModel.getSimulationContexts();
Simulation selectedSim = simulationContext.getSimulations(0);
// Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null), 0);
// a fixed seed will allow us to run reproducible simulations
long randomSeed = 0;
// long randomSeed = System.currentTimeMillis();
NFsimSimulationOptions nfsimSimulationOptions = new NFsimSimulationOptions();
// we get the data we need from the math description
boolean bUseLocationMarks = true;
Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
Document doc = new Document();
doc.setRootElement(root);
XMLOutputter xmlOut = new XMLOutputter();
String resultString = xmlOut.outputString(doc);
FileUtils.writeStringToFile(exportFile, resultString);
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class SmoldynExtensionFilter method askUser.
@Override
public void askUser(ChooseContext ctx) throws UserCancelException {
SimulationContext chosenSimContext = ctx.chosenContext;
String[] simNames = new String[chosenSimContext.getSimulations().length];
Simulation[] sims = chosenSimContext.getSimulations();
for (int i = 0; i < sims.length; i++) {
simNames[i] = sims[i].getName();
}
Object choice = PopupGenerator.showListDialog(ctx.topLevelWindowManager, simNames, "Please select " + chosenSimContext.getName() + " simulation to export");
if (choice == null) {
throw UserCancelException.CANCEL_FILE_SELECTION;
}
String chosenSimulationName = (String) choice;
Simulation chosenSimulation = chosenSimContext.getSimulation(chosenSimulationName);
Objects.requireNonNull(chosenSimulation);
// PENDING delete
ctx.hashTable.put(SIM_KEY, chosenSimulation);
selectedSim = chosenSimulation;
}
Aggregations