Search in sources :

Example 6 with ExpressionPrintFormatter

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);
    }
}
Also used : JPanel(javax.swing.JPanel) DataIdentifier(cbit.vcell.simdata.DataIdentifier) FlowLayout(java.awt.FlowLayout) ExpressionPrintFormatter(cbit.vcell.parser.ExpressionPrintFormatter) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Font(java.awt.Font) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) Expression(cbit.vcell.parser.Expression) JDialog(javax.swing.JDialog)

Aggregations

ExpressionPrintFormatter (cbit.vcell.parser.ExpressionPrintFormatter)6 Dimension (java.awt.Dimension)5 Font (java.awt.Font)5 ExpressionException (cbit.vcell.parser.ExpressionException)3 Graphics2D (java.awt.Graphics2D)3 Rectangle (java.awt.Rectangle)2 JLabel (javax.swing.JLabel)2 ScopedExpression (cbit.gui.ScopedExpression)1 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)1 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)1 Expression (cbit.vcell.parser.Expression)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 DataIdentifier (cbit.vcell.simdata.DataIdentifier)1 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)1 FlowLayout (java.awt.FlowLayout)1 FontMetrics (java.awt.FontMetrics)1 ImageIcon (javax.swing.ImageIcon)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1 JPanel (javax.swing.JPanel)1