Back to index

wims  3.65+svn20090927
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
ptolemy.plot.PlotFormatter Class Reference

PlotFormatter is a panel that controls the format of a plotter object passed to the constructor. More...

Inheritance diagram for ptolemy.plot.PlotFormatter:
Inheritance graph
[legend]
Collaboration diagram for ptolemy.plot.PlotFormatter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PlotFormatter (PlotBox plot)
 Construct a plot formatter for the specified plot object.
void apply ()
 Apply currently specified values to the associated plot.
void openModal ()
 Open a format control window as a top-level, modal dialog.
void restore ()
 Restore the original configuration of the plot, and request a a redraw.

Protected Attributes

final PlotBox _plot
 The plot object controlled by this formatter.

Private Member Functions

void _saveConnected ()
void _setConnected (boolean value)
void _restoreConnected ()

Private Attributes

Query _wideQuery
Query _narrowQuery
String _originalTitle
String _originalXLabel
String _originalYLabel
String _originalMarks
String _originalXTicksSpec
String _originalYTicksSpec
double[] _originalXRange
double[] _originalYRange
Vector[] _originalXTicks
Vector[] _originalYTicks
boolean _originalGrid
boolean _originalStems
boolean _originalColor
boolean[][] _originalConnected
PlotPoint[][] _originalPoints

Detailed Description

PlotFormatter is a panel that controls the format of a plotter object passed to the constructor.

See also:
Plot
PlotBox
Author:
Edward A. Lee
Version:
Id:
PlotFormatter.java,v 1.26 2005/07/08 19:59:35 cxh Exp
Since:
Ptolemy II 1.0 .ProposedRating Yellow (eal) .AcceptedRating Red (cxh)

Definition at line 56 of file PlotFormatter.java.


Constructor & Destructor Documentation

Construct a plot formatter for the specified plot object.

Definition at line 59 of file PlotFormatter.java.

                                       {
        super();
        _plot = plot;

        setLayout(new BorderLayout());
        _wideQuery = new Query();
        add(_wideQuery, BorderLayout.WEST);
        _narrowQuery = new Query();
        add(_narrowQuery, BorderLayout.EAST);

        // Populate the wide query.
        _wideQuery.setTextWidth(20);
        _originalTitle = plot.getTitle();
        _wideQuery.addLine("title", "Title", _originalTitle);
        _originalXLabel = plot.getXLabel();
        _wideQuery.addLine("xlabel", "X Label", _originalXLabel);
        _originalYLabel = plot.getYLabel();
        _wideQuery.addLine("ylabel", "Y Label", _originalYLabel);
        _originalXRange = plot.getXRange();
        _wideQuery.addLine("xrange", "X Range", "" + _originalXRange[0] + ", "
                + _originalXRange[1]);
        _originalYRange = plot.getYRange();
        _wideQuery.addLine("yrange", "Y Range", "" + _originalYRange[0] + ", "
                + _originalYRange[1]);

        String[] marks = { "none", "points", "dots", "various", "pixels" };
        _originalMarks = "none";

        if (plot instanceof Plot) {
            _originalMarks = ((Plot) plot).getMarksStyle();
            _wideQuery.addRadioButtons("marks", "Marks", marks, _originalMarks);
        }

        _originalXTicks = plot.getXTicks();
        _originalXTicksSpec = "";

        if (_originalXTicks != null) {
            StringBuffer buffer = new StringBuffer();
            Vector positions = _originalXTicks[0];
            Vector labels = _originalXTicks[1];

            for (int i = 0; i < labels.size(); i++) {
                if (buffer.length() > 0) {
                    buffer.append(", ");
                }

                buffer.append(labels.elementAt(i).toString());
                buffer.append(" ");
                buffer.append(positions.elementAt(i).toString());
            }

            _originalXTicksSpec = buffer.toString();
        }

        _wideQuery.addLine("xticks", "X Ticks", _originalXTicksSpec);

        _originalYTicks = plot.getYTicks();
        _originalYTicksSpec = "";

        if (_originalYTicks != null) {
            StringBuffer buffer = new StringBuffer();
            Vector positions = _originalYTicks[0];
            Vector labels = _originalYTicks[1];

            for (int i = 0; i < labels.size(); i++) {
                if (buffer.length() > 0) {
                    buffer.append(", ");
                }

                buffer.append(labels.elementAt(i).toString());
                buffer.append(" ");
                buffer.append(positions.elementAt(i).toString());
            }

            _originalYTicksSpec = buffer.toString();
        }

        _wideQuery.addLine("yticks", "Y Ticks", _originalYTicksSpec);

        _originalGrid = plot.getGrid();
        _narrowQuery.addCheckBox("grid", "Grid", _originalGrid);
        _originalStems = false;
        _originalConnected = null;

        if (plot instanceof Plot) {
            _originalStems = ((Plot) plot).getImpulses();
            _narrowQuery.addCheckBox("stems", "Stems", _originalStems);
            _saveConnected();
            _narrowQuery.addCheckBox("connected", "Connect", ((Plot) plot)
                    .getConnected());
        }

        _originalColor = plot.getColor();
        _narrowQuery.addCheckBox("color", "Use Color", _originalColor);

        // FIXME: setXLog() and setYLog() cause problems with
        // dropped data if they are toggled after data is read in.
        // This is because the log axis facility modifies the datasets
        // in addPlotPoint() in Plot.java.  When this is fixed
        // we can add the XLog and YLog facility to the Format menu
        //
        // _originalXLog = plot.getXLog();
        //_narrowQuery.addCheckBox("xlog", "X Log", _originalXLog);
        //if (_originalXTicks != null) {
        //    _narrowQuery.setBoolean("xlog", false);
        //    _narrowQuery.setEnabled("xlog", false);
        //}
        // _originalYLog = plot.getYLog();
        //_narrowQuery.addCheckBox("ylog", "Y Log", _originalYLog);
        //if (_originalYTicks != null) {
        //    _narrowQuery.setBoolean("ylog", false);
        //    _narrowQuery.setEnabled("ylog", false);
        //}
        // Attach listeners.
        _wideQuery.addQueryListener(new QueryListener() {
            public void changed(String name) {
                if (name.equals("title")) {
                    _plot.setTitle(_wideQuery.getStringValue("title"));
                } else if (name.equals("xlabel")) {
                    _plot.setXLabel(_wideQuery.getStringValue("xlabel"));
                } else if (name.equals("ylabel")) {
                    _plot.setYLabel(_wideQuery.getStringValue("ylabel"));
                } else if (name.equals("xrange")) {
                    _plot
                            .read("XRange: "
                                    + _wideQuery.getStringValue("xrange"));
                } else if (name.equals("xticks")) {
                    String spec = _wideQuery.getStringValue("xticks").trim();
                    _plot.read("XTicks: " + spec);

                    // FIXME: log axis format temporarily
                    // disabled, see above.
                    // if (spec.equals("")) {
                    //    _narrowQuery.setEnabled("xlog", true);
                    // } else {
                    //    _narrowQuery.setBoolean("xlog", false);
                    //    _narrowQuery.setEnabled("xlog", false);
                    // }
                } else if (name.equals("yticks")) {
                    String spec = _wideQuery.getStringValue("yticks").trim();
                    _plot.read("YTicks: " + spec);

                    // FIXME: log axis format temporarily
                    // disabled, see above.
                    // if (spec.equals("")) {
                    //    _narrowQuery.setEnabled("ylog", true);
                    // } else {
                    //    _narrowQuery.setBoolean("ylog", false);
                    //    _narrowQuery.setEnabled("ylog", false);
                    // }
                } else if (name.equals("yrange")) {
                    _plot
                            .read("YRange: "
                                    + _wideQuery.getStringValue("yrange"));
                } else if (name.equals("marks")) {
                    ((Plot) _plot).setMarksStyle(_wideQuery
                            .getStringValue("marks"));
                }

                _plot.repaint();
            }
        });

        _narrowQuery.addQueryListener(new QueryListener() {
            public void changed(String name) {
                if (name.equals("grid")) {
                    _plot.setGrid(_narrowQuery.getBooleanValue("grid"));
                } else if (name.equals("stems")) {
                    ((Plot) _plot).setImpulses(_narrowQuery
                            .getBooleanValue("stems"));
                    _plot.repaint();
                } else if (name.equals("color")) {
                    _plot.setColor(_narrowQuery.getBooleanValue("color"));

                    // FIXME: log axis format temporarily
                    // disabled, see above.
                    // } else if (name.equals("xlog")) {
                    //    _plot.setXLog(_narrowQuery.getBooleanValue("xlog"));
                    // } else if (name.equals("ylog")) {
                    //    _plot.setYLog(_narrowQuery.getBooleanValue("ylog"));
                } else if (name.equals("connected")) {
                    _setConnected(_narrowQuery.getBooleanValue("connected"));
                }

                _plot.repaint();
            }
        });
    }

Here is the call graph for this function:


Member Function Documentation

Definition at line 421 of file PlotFormatter.java.

                                     {
        for (int dataset = 0; dataset < _originalPoints.length; dataset++) {
            for (int i = 0; i < _originalPoints[dataset].length; i++) {
                PlotPoint pt = _originalPoints[dataset][i];
                pt.connected = _originalConnected[dataset][i];
            }
        }
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotFormatter._saveConnected ( ) [inline, private]

Definition at line 372 of file PlotFormatter.java.

                                  {
        Vector points = ((Plot) _plot)._points;
        _originalConnected = new boolean[points.size()][];
        _originalPoints = new PlotPoint[points.size()][];

        for (int dataset = 0; dataset < points.size(); dataset++) {
            Vector pts = (Vector) points.elementAt(dataset);
            _originalConnected[dataset] = new boolean[pts.size()];
            _originalPoints[dataset] = new PlotPoint[pts.size()];

            for (int i = 0; i < pts.size(); i++) {
                PlotPoint pt = (PlotPoint) pts.elementAt(i);
                _originalConnected[dataset][i] = pt.connected;
                _originalPoints[dataset][i] = pt;
            }
        }
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotFormatter._setConnected ( boolean  value) [inline, private]

Definition at line 394 of file PlotFormatter.java.

                                              {
        Vector points = ((Plot) _plot)._points;

        // Make sure the default matches.
        ((Plot) _plot).setConnected(value);

        boolean[][] result = new boolean[points.size()][];

        for (int dataset = 0; dataset < points.size(); dataset++) {
            Vector pts = (Vector) points.elementAt(dataset);
            result[dataset] = new boolean[pts.size()];

            boolean first = true;

            for (int i = 0; i < pts.size(); i++) {
                PlotPoint pt = (PlotPoint) pts.elementAt(i);
                pt.connected = value && !first;
                first = false;
            }
        }
    }

Here is the caller graph for this function:

Apply currently specified values to the associated plot.

This requests a repaint of the plot.

Definition at line 254 of file PlotFormatter.java.

                        {
        // Apply current values.
        _plot.setTitle(_wideQuery.getStringValue("title"));
        _plot.setXLabel(_wideQuery.getStringValue("xlabel"));
        _plot.setYLabel(_wideQuery.getStringValue("ylabel"));
        _plot.read("XRange: " + _wideQuery.getStringValue("xrange"));
        _plot.read("YRange: " + _wideQuery.getStringValue("yrange"));
        _plot.setGrid(_narrowQuery.getBooleanValue("grid"));
        _plot.setColor(_narrowQuery.getBooleanValue("color"));

        // FIXME: log axis format temporarily disable, see above.
        // _plot.setXLog(_narrowQuery.getBooleanValue("xlog"));
        // _plot.setYLog(_narrowQuery.getBooleanValue("ylog"));
        if (_plot instanceof Plot) {
            Plot cplot = (Plot) _plot;
            cplot.setMarksStyle(_wideQuery.getStringValue("marks"));
            cplot.setImpulses(_narrowQuery.getBooleanValue("stems"));
            _setConnected(_narrowQuery.getBooleanValue("connected"));
        }

        // FIXME: log axis format temporarily disable, see above.
        // String spec = _wideQuery.getStringValue("xticks").trim();
        // _plot.read("XTicks: " + spec);
        // if (spec.equals("")) {
        //    _narrowQuery.setEnabled("xlog", true);
        // } else {
        //    _narrowQuery.setBoolean("xlog", false);
        //    _narrowQuery.setEnabled("xlog", false);
        // }
        // spec = _wideQuery.getStringValue("yticks").trim();
        // _plot.read("YTicks: " + spec);
        // if (spec.equals("")) {
        //    _narrowQuery.setEnabled("ylog", true);
        // } else {
        //    _narrowQuery.setBoolean("ylog", false);
        //    _narrowQuery.setEnabled("ylog", false);
        // }
        _plot.repaint();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Open a format control window as a top-level, modal dialog.

Definition at line 296 of file PlotFormatter.java.

                            {
        String[] buttons = { "Apply", "Cancel" };

        // NOTE: If the plot is in a top-level container that is a Frame
        // (as opposed to an applet), then tell the dialog that the Frame
        // owns the dialog.
        Container toplevel = _plot.getTopLevelAncestor();
        Frame frame = null;

        if (toplevel instanceof Frame) {
            frame = (Frame) toplevel;
        }

        ComponentDialog dialog = new ComponentDialog(frame, "Set plot format",
                this, buttons);

        if (dialog.buttonPressed().equals("Apply")) {
            apply();
        } else {
            restore();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Restore the original configuration of the plot, and request a a redraw.

Definition at line 322 of file PlotFormatter.java.

                          {
        // Restore _original values.
        _plot.setTitle(_originalTitle);
        _plot.setXLabel(_originalXLabel);
        _plot.setYLabel(_originalYLabel);
        _plot.setXRange(_originalXRange[0], _originalXRange[1]);
        _plot.setYRange(_originalYRange[0], _originalYRange[1]);
        _plot.setGrid(_originalGrid);
        _plot.setColor(_originalColor);

        // FIXME: log axis format temporarily disable, see above.
        // _plot.setXLog(_originalXLog);
        // _plot.setYLog(_originalYLog);
        if (_plot instanceof Plot) {
            Plot cplot = (Plot) _plot;
            cplot.setMarksStyle(_originalMarks);
            cplot.setImpulses(_originalStems);
            _restoreConnected();
        }

        // FIXME: log axis format temporarily disabled, see above.
        // _plot.read("XTicks: " + _originalXTicksSpec);
        // if (_originalXTicksSpec.equals("")) {
        //    _narrowQuery.setEnabled("xlog", true);
        // } else {
        //   _narrowQuery.setBoolean("xlog", false);
        //    _narrowQuery.setEnabled("xlog", false);
        // }
        // _plot.read("YTicks: " + _originalYTicksSpec);
        // if (_originalYTicksSpec.equals("")) {
        //    _narrowQuery.setEnabled("ylog", true);
        // } else {
        //    _narrowQuery.setBoolean("ylog", false);
        //    _narrowQuery.setEnabled("ylog", false);
        // }
        _plot.repaint();
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 438 of file PlotFormatter.java.

Definition at line 470 of file PlotFormatter.java.

Definition at line 472 of file PlotFormatter.java.

Definition at line 466 of file PlotFormatter.java.

Definition at line 450 of file PlotFormatter.java.

Definition at line 474 of file PlotFormatter.java.

Definition at line 468 of file PlotFormatter.java.

Definition at line 441 of file PlotFormatter.java.

Definition at line 444 of file PlotFormatter.java.

Definition at line 458 of file PlotFormatter.java.

Definition at line 462 of file PlotFormatter.java.

Definition at line 453 of file PlotFormatter.java.

Definition at line 447 of file PlotFormatter.java.

Definition at line 460 of file PlotFormatter.java.

Definition at line 464 of file PlotFormatter.java.

Definition at line 456 of file PlotFormatter.java.

The plot object controlled by this formatter.

Definition at line 364 of file PlotFormatter.java.

Definition at line 433 of file PlotFormatter.java.


The documentation for this class was generated from the following file: