use of cbit.vcell.parser.ExpressionPrintFormatter in project vcell by virtualcell.
the class PDEPlotControlPanel method viewFunction.
public void viewFunction() {
Object selectedValue = getPlotVariableJList().getSelectedValue();
if (selectedValue == null) {
return;
}
DataIdentifier di = (DataIdentifier) selectedValue;
AnnotatedFunction func = findFunction(di, Arrays.asList(myAnnotFunctions));
if (func == null || !func.isOldUserDefined()) {
return;
}
try {
Expression newexp = new Expression(func.getExpression());
for (AnnotatedFunction af : myAnnotFunctions) {
if (af.isOldUserDefined()) {
newexp.substituteInPlace(new Expression(af.getName()), new Expression(af.getDisplayName()));
}
}
java.awt.Font italicFont = getFont().deriveFont(Font.BOLD, 11);
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel nameLabel = new JLabel(func.getDisplayName() + " = ");
nameLabel.setFont(italicFont);
panel.add(nameLabel);
JLabel label = new JLabel();
ExpressionPrintFormatter epf = new ExpressionPrintFormatter(newexp);
java.awt.image.BufferedImage graphicsContextProvider = new java.awt.image.BufferedImage(10, 10, java.awt.image.BufferedImage.TYPE_BYTE_GRAY);
java.awt.Graphics2D tempG2D = (java.awt.Graphics2D) graphicsContextProvider.getGraphics();
java.awt.Dimension dim = epf.getSize(tempG2D);
java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(dim.width, dim.height, java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D g2d = bi.createGraphics();
g2d.setClip(0, 0, dim.width, dim.height);
italicFont = getFont().deriveFont(Font.BOLD + Font.ITALIC, 11);
g2d.setFont(italicFont);
g2d.setBackground(getBackground());
g2d.setColor(getForeground());
g2d.clearRect(0, 0, dim.width, dim.height);
epf.paint(g2d);
javax.swing.ImageIcon newImageIcon = new javax.swing.ImageIcon(bi);
label.setIcon(newImageIcon);
panel.add(label);
String COPYEXP = "Copy Expression";
JOptionPane inputDialog = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[] { COPYEXP, UserMessage.OPTION_CLOSE });
final JDialog d = inputDialog.createDialog(this, "Function '" + func.getDisplayName() + "'");
d.setResizable(true);
d.pack();
try {
DialogUtils.showModalJDialogOnTop(d, this);
if (inputDialog.getValue() != null && inputDialog.getValue().equals(COPYEXP)) {
VCellTransferable.sendToClipboard(newexp.infix());
}
} finally {
d.dispose();
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(this, ex.getMessage(), ex);
}
}
Aggregations