use of cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver in project vcell by virtualcell.
the class PDEPlotControlPanel 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
getJTextField1().addActionListener(ivjEventHandler);
getJTextField1().addFocusListener(ivjEventHandler);
getDefaultListModelCivilized1().addListDataListener(ivjEventHandler);
getViewFunctionButton().addActionListener(ivjEventHandler);
getPlotVariableJList().setModel(getDefaultListModelCivilized1());
getJSliderTime().getModel().addChangeListener(ivjEventHandler);
getPlotVariableJList().addListSelectionListener(ivjEventHandler);
getPlotVariableJList().setCellRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel c = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (dataInfoProvider == null) {
if (value instanceof DataIdentifier) {
DataIdentifier var = (DataIdentifier) value;
if (var.getVariableType() == VariableType.POSTPROCESSING) {
setToolTipText(getText());
setText(var.getName());
}
}
return this;
}
// System.out.println("rendering object "+value+" of type "+value.getClass());
DataIdentifier var = (DataIdentifier) value;
c.setText(var.getName());
c.setToolTipText("dataInfoProvier not found");
DataSymbolMetadataResolver dataSymbolMetadataResolver = dataInfoProvider.getSimulationModelInfo().getDataSymbolMetadataResolver();
if (dataSymbolMetadataResolver != null && dataSymbolMetadataResolver.getDataSymbolMetadata(var.getName()) != null) {
DataSymbolMetadata dsm = dataSymbolMetadataResolver.getDataSymbolMetadata(var.getName());
String tooltipString = "dataInfoProvider found, but identifier " + var.getName() + " not found";
if (dsm == null) {
tooltipString = "did not find info on variable " + var.getDisplayName();
} else {
c.setText(var.getName() + " [" + dsm.unit + "]");
tooltipString = dsm.tooltipString;
}
c.setToolTipText(tooltipString);
}
return this;
}
});
}
use of cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver in project vcell by virtualcell.
the class DisplayImageOp method displayImage.
public void displayImage(final Image image, String title, WindowListener listener) {
final ImagePlaneManagerPanel imagePanel = new ImagePlaneManagerPanel();
double[] doublePixels = image.getDoublePixels();
double minPixel = Double.MAX_VALUE;
double maxPixel = -Double.MAX_VALUE;
for (int i = 0; i < doublePixels.length; i++) {
double pixel = doublePixels[i];
doublePixels[i] = pixel;
minPixel = Math.min(minPixel, pixel);
maxPixel = Math.max(maxPixel, pixel);
}
Range newRange = new Range(minPixel, maxPixel);
SourceDataInfo source = new SourceDataInfo(SourceDataInfo.RAW_VALUE_TYPE, doublePixels, image.getExtent(), image.getOrigin(), newRange, 0, image.getNumX(), 1, image.getNumY(), image.getNumX(), image.getNumZ(), image.getNumX() * image.getNumY());
imagePanel.setDisplayAdapterServicePanelVisible(true);
imagePanel.setCurveValueProvider(new CurveValueProvider() {
@Override
public void curveAdded(Curve curve) {
System.out.println("called curveAdded(" + curve + "), do nothing for now");
}
@Override
public void curveRemoved(Curve curve) {
System.out.println("called curveRemoved(" + curve + ")");
}
@Override
public String getCurveValue(CurveSelectionInfo csi) {
System.out.println("called getCurveValue(CurveSelectionInfo " + csi);
return null;
}
@Override
public CurveSelectionInfo getInitalCurveSelection(int tool, Coordinate wc) {
System.out.println("called getInitialCurveSelection(tool=" + tool + ", coord=" + wc + ")");
return null;
}
@Override
public boolean isAddControlPointOK(int tool, Coordinate wc, Curve addedToThisCurve) {
System.out.println("called isAddControlPointOK");
return true;
}
@Override
public boolean providesInitalCurve(int tool, Coordinate wc) {
System.out.println("called providesInitialCurve(tool=" + tool + " (TOOL_LINE=" + CurveEditorTool.TOOL_LINE + "), coord=" + wc);
return false;
}
@Override
public void setDescription(Curve curve) {
System.out.println("called setDescription(" + curve + ")");
curve.setDescription(CurveValueProvider.DESCRIPTION_VOLUME);
}
@Override
public CurveSelectionInfo findChomboCurveSelectionInfoForPoint(CoordinateIndex ci) {
System.out.println("called find ChomboCurveSelectionInfoForPoint(coord=" + ci + ")");
return null;
}
});
DisplayAdapterService das = imagePanel.getDisplayAdapterServicePanel().getDisplayAdapterService();
das.setValueDomain(null);
das.addColorModelForValues(DisplayAdapterService.createGrayColorModel(), DisplayAdapterService.createGraySpecialColors(), DisplayAdapterService.GRAY);
das.addColorModelForValues(DisplayAdapterService.createBlueRedColorModel(), DisplayAdapterService.createBlueRedSpecialColors(), DisplayAdapterService.BLUERED);
das.setActiveColorModelID(DisplayAdapterService.BLUERED);
final JFrame jframe = new JFrame();
jframe.setTitle(title);
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints imageConstraints = new GridBagConstraints();
imageConstraints.gridx = 0;
imageConstraints.gridy = 0;
imageConstraints.weightx = 1.0;
imageConstraints.weighty = 1.0;
imageConstraints.fill = GridBagConstraints.BOTH;
panel.add(imagePanel, imageConstraints);
JButton plotButton = new JButton("plot");
plotButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Curve curve = imagePanel.getCurveRenderer().getSelection().getCurve();
VariableType variableType = VariableType.VOLUME;
Curve samplerCurve = curve.getSampledCurve();
samplerCurve.setDescription(curve.getDescription());
VCImage vcImage = new VCImageUncompressed(null, new byte[image.getISize().getXYZ()], image.getExtent(), image.getISize().getX(), image.getISize().getY(), image.getISize().getZ());
int dimension = 1 + (image.getISize().getY() > 0 ? 1 : 0) + (image.getISize().getZ() > 0 ? 1 : 0);
RegionImage regionImage = new RegionImage(vcImage, dimension, image.getExtent(), image.getOrigin(), RegionImage.NO_SMOOTHING);
CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(image.getOrigin(), image.getExtent(), image.getISize(), regionImage);
SpatialSelectionVolume ssVolume = new SpatialSelectionVolume(new CurveSelectionInfo(samplerCurve), variableType, mesh);
String varName = "var";
SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[] { new VolVariable(varName, null) };
PlotData plotData = getLineScan(ssVolume, image, mesh);
PlotPane plotPane = new PlotPane();
DataSymbolMetadataResolver resolver = null;
Plot2D plot2D = new Plot2D(symbolTableEntries, resolver, new String[] { varName }, new PlotData[] { plotData }, new String[] { "Values along curve", "Distance (\u00b5m)", "[" + varName + "]" });
plotPane.setPlot2D(plot2D);
DialogUtils.showComponentCloseDialog(jframe, plotPane, "plot");
} catch (ImageException | IOException | DataAccessException | MathException e1) {
e1.printStackTrace();
}
}
});
GridBagConstraints plotButtonConstraints = new GridBagConstraints();
plotButtonConstraints.gridx = 0;
plotButtonConstraints.gridy = 1;
panel.add(plotButton, plotButtonConstraints);
jframe.getContentPane().add(panel);
jframe.setSize(500, 500);
jframe.addWindowListener(listener);
jframe.setVisible(true);
imagePanel.setSourceDataInfo(source);
}
use of cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver in project vcell by virtualcell.
the class PDEDataViewer method createMultiTimePlotHelper.
// private static class MultiTimePointPropChangeListener implements PropertyChangeListener {
// @Override
// public void propertyChange(PropertyChangeEvent evt) {
// }
// }
private MultiTimePlotHelper createMultiTimePlotHelper(final ClientPDEDataContext copyThisPDEDatacontext, final User user, DataSymbolMetadataResolver argDataSymbolMetadataResolver) throws Exception {
final ClientPDEDataContext[] copyHolder = new ClientPDEDataContext[1];
if (PDEDataViewer.this.isPostProcess()) {
copyHolder[0] = PDEDataViewerPostProcess.createPostProcessPDEDataContext(copyThisPDEDatacontext);
} else {
copyHolder[0] = (ClientPDEDataContext) ((PDEDataManager) copyThisPDEDatacontext.getDataManager()).createNewPDEDataManager(copyThisPDEDatacontext.getVCDataIdentifier(), null).getPDEDataContext();
}
copyHolder[0].setVariableAndTime(copyThisPDEDatacontext.getDataIdentifier(), copyThisPDEDatacontext.getTimePoint());
return new PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper() {
private DataSymbolMetadataResolver dataSymbolMetadataResolver = argDataSymbolMetadataResolver;
private ArrayList<PropertyChangeListener> myPropertyChangeHolder = new ArrayList<>();
private ClientPDEDataContext myPdeDataContext = copyHolder[0];
private VariableType myVariableType = copyThisPDEDatacontext.getDataIdentifier().getVariableType();
// catch events from 'this' PDEDataViewer and pass with new source
private PropertyChangeListener myPropertyChangeListener;
private User myUser = user;
// List<AnnotatedFunction> myAnnots;
// access to anonymous outer class
private PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelperThis = this;
private PDEPlotControlPanel.IdentifierListCellRenderer myListCellRenderer;
private AnnotatedFunction[] lastAnnotatedFunctions;
private PDEPlotControlPanel.FunctionListProvider functionListProvider = new PDEPlotControlPanel.FunctionListProvider() {
@Override
public List<AnnotatedFunction> getAnnotatedFunctions() {
if (myPdeDataContext.getDataManager().getOutputContext() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions().length > 0) {
return new ArrayList<>(Arrays.asList(myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions()));
}
return new ArrayList<>();
}
};
private Comparator<AnnotatedFunction> nameComparator = new Comparator<AnnotatedFunction>() {
@Override
public int compare(AnnotatedFunction o1, AnnotatedFunction o2) {
return o2.getName().compareToIgnoreCase(o1.getName());
}
};
@Override
public void removeDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.removeDataJobListener(dataJobListener);
}
@Override
public void addDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.addDataJobListener(dataJobListener);
}
@Override
public User getUser() {
return myUser;
}
@Override
public PDEDataContext getPdeDatacontext() {
return myPdeDataContext;
}
@Override
public DataIdentifier[] getCopyOfDisplayedDataIdentifiers() {
DataIdentifier[] newData = PDEDataViewer.this.getPDEPlotControlPanel1().getDataIdentifierFilter().accept(DefaultDataIdentifierFilter.ALL, functionListProvider.getAnnotatedFunctions(), myPdeDataContext.getDataIdentifiers()).toArray(new DataIdentifier[0]);
return DataIdentifier.collectSortedSimilarDataTypes(this.getVariableType(), newData);
}
@Override
public PDEPlotControlPanel.IdentifierListCellRenderer getListCellRenderer() {
if (myListCellRenderer == null) {
myListCellRenderer = new PDEPlotControlPanel.IdentifierListCellRenderer(functionListProvider);
}
return myListCellRenderer;
}
@Override
public Simulation getsimulation() {
return PDEDataViewer.this.getSimulation();
}
private List<AnnotatedFunction> efficiencyFilter(List<AnnotatedFunction> funcs) {
ArrayList<AnnotatedFunction> outputfunctions = new ArrayList<>();
Iterator<AnnotatedFunction> iter = funcs.iterator();
while (iter.hasNext()) {
AnnotatedFunction theFunc = iter.next();
if ((isPostProcess() && theFunc.getFunctionType().equals(VariableType.POSTPROCESSING)) || (!isPostProcess() && !theFunc.getFunctionType().equals(VariableType.POSTPROCESSING))) {
outputfunctions.add(theFunc);
}
}
return outputfunctions;
}
@Override
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
myPropertyChangeHolder.add(propertyChangeListener);
if (myPropertyChangeListener == null) {
myPropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() == PDEDataViewer.this && evt.getPropertyName().equals(PDEDataContext.PROP_PDE_DATA_CONTEXT)) {
// List<AnnotatedFunction> currentOutputFunctions = functionListProvider.getAnnotatedFunctions();
// currentOutputFunctions = efficiencyFilter(currentOutputFunctions);
// currentOutputFunctions.sort(nameComparator);
List<AnnotatedFunction> newOutputFunctions0 = Arrays.asList(((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext()).getDataManager().getOutputContext().getOutputFunctions());
List<AnnotatedFunction> newOutputFunctions = efficiencyFilter(newOutputFunctions0);
newOutputFunctions.sort(nameComparator);
if (lastAnnotatedFunctions != null && Compare.isEqualOrNullStrict(lastAnnotatedFunctions, newOutputFunctions.toArray(new AnnotatedFunction[0]))) {
return;
}
lastAnnotatedFunctions = new AnnotatedFunction[newOutputFunctions.size()];
for (int i = 0; i < newOutputFunctions.size(); i++) {
lastAnnotatedFunctions[i] = new AnnotatedFunction(newOutputFunctions.get(i));
}
// lastAnnotatedFunctions = newOutputFunctions0.toArray(new AnnotatedFunction[0]);
myPdeDataContext.getDataManager().setOutputContext(new OutputContext(newOutputFunctions0.toArray(new AnnotatedFunction[0])));
myPdeDataContext.refreshIdentifiers();
for (int i = 0; i < myPropertyChangeHolder.size(); i++) {
myPropertyChangeHolder.get(i).propertyChange(new PropertyChangeEvent(multiTimePlotHelperThis, SimDataConstants.PROPERTY_NAME_DATAIDENTIFIERS, null, null));
}
}
}
};
PDEDataViewer.this.addPropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public void removeallPropertyChangeListeners() {
myPropertyChangeHolder.clear();
if (myPropertyChangeListener != null) {
PDEDataViewer.this.removePropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public VariableType getVariableType() {
return myVariableType;
}
// @Override
// public void addExtraTasks(AsynchClientTask[] moreTasks) {
// PDEDataViewer.this.addExtraTasks(moreTasks);
// }
@Override
public DataSymbolMetadataResolver getDataSymbolMetadataResolver() {
return dataSymbolMetadataResolver;
}
};
}
use of cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver in project vcell by virtualcell.
the class PlotPane method updateLegend.
/**
* Comment
*/
private void updateLegend() {
Plot2D plot = getPlot2DPanel1().getPlot2D();
SymbolTableEntry[] steList = plot.getSymbolTableEntries();
DataSymbolMetadataResolver metadataResolver = plot.getDataSymbolMetadataResolver();
String[] plotLabels = plot.getVisiblePlotColumnTitles();
int[] plotIndices = plot.getVisiblePlotIndices();
Component[] legends = getJPanelPlotLegends().getComponents();
// add legends if necessarry
if (ml == null) {
ml = new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
String name = ((JLabel) evt.getSource()).getText();
getPlot2DPanel1().setCurrentPlot(name);
}
};
}
for (int i = 0; i < plotIndices.length - legends.length / 2; i++) {
JLabel line = new JLabel();
JLabel text = new JLabel();
line.setBorder(new EmptyBorder(6, 0, 0, 0));
text.setBorder(new EmptyBorder(0, 8, 6, 0));
getJPanelPlotLegends().add(line);
getJPanelPlotLegends().add(text);
text.addMouseListener(ml);
}
legends = getJPanelPlotLegends().getComponents();
// update labels and show them,use reverse loop to generate non-repeatable colors
for (int i = (plotIndices.length - 1); i >= 0; i--) {
LineIcon icon = new LineIcon(getPlot2DPanel1().getVisiblePlotPaint(i));
String plotLabel = null;
if (plot instanceof SingleXPlot2D) {
plotLabel = plotLabels[i + 1];
} else {
plotLabel = plotLabels[2 * i + 1];
}
((JLabel) legends[2 * i]).setIcon(icon);
final int head = 20;
final int tail = 0;
String tooltipString = "";
String unitSymbol = "";
if (metadataResolver != null) {
DataSymbolMetadata metaData = metadataResolver.getDataSymbolMetadata(plotLabel);
if (metaData != null && metaData.unit != null) {
VCUnitDefinition ud = metaData.unit;
if (ud != null) {
unitSymbol += ud.getSymbolUnicode();
}
}
if (metaData != null && metaData.tooltipString != null) {
tooltipString = metaData.tooltipString;
}
}
String shortLabel = plotLabel;
if (shortLabel.length() > head + 3 + tail) {
shortLabel = shortLabel.substring(0, head) + "..." + shortLabel.substring(shortLabel.length() - tail, shortLabel.length());
}
// shortLabel = "<html>" + shortLabel + "<font color=\"red\">" + " [" + unitSymbol + "] " + "</font></html>";
shortLabel = "<html>" + shortLabel + "<font color=\"#8B0000\">" + " [" + unitSymbol + "] " + "</font></html>";
tooltipString = "<html>" + plotLabel + "<font color=\"#0000FF\">" + " " + tooltipString + " " + "</font></html>";
((JLabel) legends[2 * i + 1]).setText(shortLabel);
((JLabel) legends[2 * i + 1]).setToolTipText(tooltipString);
legends[2 * i].setVisible(true);
legends[2 * i + 1].setVisible(true);
}
// if extra ones, hide them
for (int i = 2 * plotIndices.length; i < legends.length; i++) {
legends[i].setVisible(false);
}
}
Aggregations