Logo Search packages:      
Sourcecode: wims version File versions

boolean ptolemy::plot::Plot::_parseLine ( String  line  )  [inline, protected, inherited]

Parse a line that gives plotting information. Return true if the line is recognized. Lines with syntax errors are ignored. It is not synchronized, so its caller should be.

Parameters:
line A command line.
Returns:
True if the line is recognized.

Reimplemented from ptolemy::plot::PlotBox.

Definition at line 1466 of file Plot.java.

References ptolemy::plot::Plot::_barOffset, ptolemy::plot::Plot::_connected, ptolemy::plot::Plot::_currentdataset, ptolemy::plot::Plot::_firstInSet, ptolemy::plot::Plot::_formats, ptolemy::plot::Plot::_maxDataset, ptolemy::plot::Plot::_reuseDatasets, ptolemy::plot::Plot::_sawFirstDataSet, ptolemy::plot::Plot::addLegend(), ptolemy::plot::Plot::addPoint(), ptolemy::plot::Plot::addPointWithErrorBars(), ptolemy::plot::PlotBox::getLegend(), ptolemy::plot::Plot::setBars(), ptolemy::plot::Plot::setConnected(), ptolemy::plot::Plot::setImpulses(), ptolemy::plot::Plot::setMarksStyle(), and ptolemy::plot::Plot::setReuseDatasets().

                                              {
        boolean connected = false;

        if (_isConnected(_currentdataset)) {
            connected = true;
        }

        // parse only if the super class does not recognize the line.
        if (super._parseLine(line)) {
            return true;
        } else {
            // We convert the line to lower case so that the command
            // names are case insensitive
            String lcLine = line.toLowerCase();

            if (lcLine.startsWith("marks:")) {
                // If we have seen a dataset directive, then apply the
                // request to the current dataset only.
                String style = (line.substring(6)).trim();

                if (_sawFirstDataSet) {
                    setMarksStyle(style, _currentdataset);
                } else {
                    setMarksStyle(style);
                }

                return true;
            } else if (lcLine.startsWith("numsets:")) {
                // Ignore.  No longer relevant.
                return true;
            } else if (lcLine.startsWith("reusedatasets:")) {
                if (lcLine.indexOf("off", 16) >= 0) {
                    setReuseDatasets(false);
                } else {
                    setReuseDatasets(true);
                }

                return true;
            } else if (lcLine.startsWith("dataset:")) {
                if (_reuseDatasets && (lcLine.length() > 0)) {
                    String tlegend = (line.substring(8)).trim();
                    _currentdataset = -1;

                    int i;

                    for (i = 0; i <= _maxDataset; i++) {
                        if (getLegend(i).compareTo(tlegend) == 0) {
                            _currentdataset = i;
                        }
                    }

                    if (_currentdataset != -1) {
                        return true;
                    } else {
                        _currentdataset = _maxDataset;
                    }
                }

                // new data set
                _firstInSet = true;
                _sawFirstDataSet = true;
                _currentdataset++;

                if (lcLine.length() > 0) {
                    String legend = (line.substring(8)).trim();

                    if ((legend != null) && (legend.length() > 0)) {
                        addLegend(_currentdataset, legend);
                    }
                }

                _maxDataset = _currentdataset;
                return true;
            } else if (lcLine.startsWith("lines:")) {
                if (_sawFirstDataSet) {
                    // Backward compatbility with xgraph here.
                    // If we see some data sets, then they are drawn
                    // with lines, if we then see a Lines: off
                    // the current dataset and succeeding datasets
                    // will be drawn without lines.
                    // For each of the existing datasets, if
                    // it fmt.connectedUseDefault is true, then
                    // set fmt.connectedUseDefault to false and set
                    // the value of fmt.connected
                    Enumeration formats = _formats.elements();

                    while (formats.hasMoreElements()) {
                        Format format = (Format) formats.nextElement();

                        if (format.connectedUseDefault) {
                            format.connectedUseDefault = false;
                            format.connected = _connected;
                        }
                    }
                }

                if (lcLine.indexOf("off", 6) >= 0) {
                    setConnected(false);
                } else {
                    setConnected(true);
                }

                return true;
            } else if (lcLine.startsWith("impulses:")) {
                // If we have not yet seen a dataset, then this is interpreted
                // as the global default.  Otherwise, it is assumed to apply
                // only to the current dataset.
                if (_sawFirstDataSet) {
                    if (lcLine.indexOf("off", 9) >= 0) {
                        setImpulses(false, _currentdataset);
                    } else {
                        setImpulses(true, _currentdataset);
                    }
                } else {
                    if (lcLine.indexOf("off", 9) >= 0) {
                        setImpulses(false);
                    } else {
                        setImpulses(true);
                    }
                }

                return true;
            } else if (lcLine.startsWith("bars:")) {
                if (lcLine.indexOf("off", 5) >= 0) {
                    setBars(false);
                } else {
                    setBars(true);

                    int comma = line.indexOf(",", 5);
                    String barwidth;
                    String baroffset = null;

                    if (comma > 0) {
                        barwidth = (line.substring(5, comma)).trim();
                        baroffset = (line.substring(comma + 1)).trim();
                    } else {
                        barwidth = (line.substring(5)).trim();
                    }

                    try {
                        // Use Double.parseDouble() and avoid creating a Double
                        double bwidth = Double.parseDouble(barwidth);
                        double boffset = _barOffset;

                        if (baroffset != null) {
                            boffset = Double.parseDouble(baroffset);
                        }

                        setBars(bwidth, boffset);
                    } catch (NumberFormatException e) {
                        // ignore if format is bogus.
                    }
                }

                return true;
            } else if (line.startsWith("move:")) {
                // a disconnected point
                connected = false;

                // deal with 'move: 1 2' and 'move:2 2'
                line = line.substring(5, line.length()).trim();
            } else if (line.startsWith("move")) {
                // a disconnected point
                connected = false;

                // deal with 'move 1 2' and 'move2 2'
                line = line.substring(4, line.length()).trim();
            } else if (line.startsWith("draw:")) {
                // a connected point, if connect is enabled.
                line = line.substring(5, line.length()).trim();
            } else if (line.startsWith("draw")) {
                // a connected point, if connect is enabled.
                line = line.substring(4, line.length()).trim();
            }

            line = line.trim();

            // We can't use StreamTokenizer here because it can't
            // process numbers like 1E-01.
            // This code is somewhat optimized for speed, since
            // most data consists of two data points, we want
            // to handle that case as efficiently as possible.
            int fieldsplit = line.indexOf(",");

            if (fieldsplit == -1) {
                fieldsplit = line.indexOf(" ");
            }

            if (fieldsplit == -1) {
                fieldsplit = line.indexOf("\t"); // a tab
            }

            if (fieldsplit > 0) {
                String x = (line.substring(0, fieldsplit)).trim();
                String y = (line.substring(fieldsplit + 1)).trim();

                // Any more separators?
                int fieldsplit2 = y.indexOf(",");

                if (fieldsplit2 == -1) {
                    fieldsplit2 = y.indexOf(" ");
                }

                if (fieldsplit2 == -1) {
                    fieldsplit2 = y.indexOf("\t"); // a tab
                }

                if (fieldsplit2 > 0) {
                    line = (y.substring(fieldsplit2 + 1)).trim();
                    y = (y.substring(0, fieldsplit2)).trim();
                }

                try {
                    // Use Double.parseDouble() and avoid creating a Double.
                    double xpt = Double.parseDouble(x);
                    double ypt = Double.parseDouble(y);

                    if (fieldsplit2 > 0) {
                        // There was one separator after the y value, now
                        // look for another separator.
                        int fieldsplit3 = line.indexOf(",");

                        if (fieldsplit3 == -1) {
                            fieldsplit3 = line.indexOf(" ");
                        }

                        //if (fieldsplit3 == -1) {
                        //    fieldsplit2 = line.indexOf("\t"); // a tab
                        //}
                        if (fieldsplit3 > 0) {
                            // We have more numbers, assume that this is
                            // an error bar
                            String yl = (line.substring(0, fieldsplit3)).trim();
                            String yh = (line.substring(fieldsplit3 + 1))
                                    .trim();
                            double yLowEB = Double.parseDouble(yl);
                            double yHighEB = Double.parseDouble(yh);
                            connected = _addLegendIfNecessary(connected);
                            addPointWithErrorBars(_currentdataset, xpt, ypt,
                                    yLowEB, yHighEB, connected);
                            return true;
                        } else {
                            // It is unlikely that we have a fieldsplit2 >0
                            // but not fieldsplit3 >0, but just in case:
                            connected = _addLegendIfNecessary(connected);
                            addPoint(_currentdataset, xpt, ypt, connected);
                            return true;
                        }
                    } else {
                        // There were no more fields, so this is
                        // a regular pt.
                        connected = _addLegendIfNecessary(connected);
                        addPoint(_currentdataset, xpt, ypt, connected);
                        return true;
                    }
                } catch (NumberFormatException e) {
                    // ignore if format is bogus.
                }
            }
        }

        return false;
    }


Generated by  Doxygen 1.6.0   Back to index