⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot.java

📁 DE算法的java程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            _dataurls.addElement(args[i]);        }        return argsread;    }    /* Split pxgraphargs up into an array and call _parseArgs     * @return The number of arguments read.     * @exception ptplot.CmdLineArgException if there is a problem parsing     * the command line arguments passed in.     */           public int parsePxgraphargs(String pxgraphargs) throws CmdLineArgException  {        // We convert the String to a Stream and then use a StreamTokenizer        // to parse the arguments into a Vector and then copy        // the vector into an array of Strings.  We use a Vector        // so that we can handle an arbitrary number of arguments        if (_debug > 3) {            System.out.println("Plot: parsePxgraphargs "+pxgraphargs);        }        Vector argvector = new Vector();        boolean prependdash = false; // true if we need to add a -                StringBufferInputStream inp = new StringBufferInputStream(pxgraphargs);        // StringBufferInput is deprecated, but StringReader is not in 1.0.2        //StringReader inp = new StringReader(pxgraphargs);        try {            StreamTokenizer stoken = new StreamTokenizer(inp); // Deprecated.            // We don't want to parse numbers specially, so we reset            // the syntax and then add back what we want.            stoken.resetSyntax();            stoken.whitespaceChars(0, ' ');            stoken.wordChars('(','~');            stoken.quoteChar('"');            stoken.quoteChar('\'');            int c;            String partialarg = null;        out:            while (true) {                c = stoken.nextToken();                //System.out.print(c + " "+stoken.ttype+" "+stoken.sval+" ");                 switch (stoken.ttype) {        // same as value of 'c'                case StreamTokenizer.TT_EOF:                    break out;                case StreamTokenizer.TT_WORD:                    //System.out.println("Word: " + stoken.sval);                    if (prependdash) {                        prependdash = false;                        if (partialarg == null)                             argvector.addElement(new String("-"+stoken.sval));                        else                            argvector.addElement(new String("-" + partialarg +                                    stoken.sval));                    } else {                        if (partialarg == null)                             argvector.addElement(new String(stoken.sval));                        else                            argvector.addElement(new String(partialarg +                                     stoken.sval));                    }                    partialarg = null;                    break;                case '-':                    prependdash = true;                    break;                case '#':                case '$':                case '%':                case '&':                    // The above chars can be part of a URL.  For example                    // perl scripts use &.  However, we cannot include                    // them in the wordChars() range of chars, since                    // the single quote is between them and the rest of the                    // chars. So we have to process them by hand.                    partialarg = ((String)argvector.lastElement()) + (char)c;                    argvector.removeElementAt(argvector.size()-1);                    break;                case '"':                case '\'':                    //System.out.println("String: " + stoken.sval);                    argvector.addElement(new String(stoken.sval));                    break;                default:                    throw new IOException("Failed to parse: '"+ (char)c +                            "' in `" + pxgraphargs + "'");                }            }        } catch (IOException e) {            e.printStackTrace();        }        // Create a array         String args[] = new String[argvector.size()];        for(int i = 0; i<argvector.size(); i++) {            args[i] = (String)argvector.elementAt(i);            if (_debug > 2) System.out.print("<"+args[i]+ "> ");        }        if (_debug > 2) System.out.println(" ");        return parseArgs(args);    }    /**      * Resize the plot.     * @deprecated As of JDK1.1 in java.awt.component, but we need      * to compile under 1.0.2 for netscape3.x compatibility.     */    public void resize(int width, int height) {        if (_debug > 8)            System.out.println("Plot: resize"+width+" "+height);        _width = width;        _height = height;
        super.resize(width,height); // FIXME: resize() is deprecated.
    }    /**     * Turn bars on or off.     */    public void setBars (boolean on) {        _bars = on;    }    /**      * Turn bars on and set the width and offset.  Both are specified     * in units of the x axis.  The offset is the amount by which the     * i<sup>th</sup> data set is shifted to the right, so that it     * peeks out from behind the earlier data sets.     */    public void setBars (double width, double offset) {        _barwidth = width;        _baroffset = offset;        _bars = true;    }        /**      * If the argument is true, then the default is to connect     * subsequent points with a line.  If the argument is false, then     * points are not connected.  When points are by default     * connected, individual points can be not connected by giving the     * appropriate argument to <code>addPoint()</code>.     */    public void setConnected (boolean on) {        _connected = on;    }        /**      * If the argument is true, then a line will be drawn from any     * plotted point down to the x axis.  Otherwise, this feature is     * disabled.     */    public void setImpulses (boolean on) {        _impulses = on;    }        /**     * Set the marks style to "none", "points", "dots", or "various".     * In the last case, unique marks are used for the first ten data     * sets, then recycled.     */    public void setMarksStyle (String style) {        if (style.equalsIgnoreCase("none")) {            _marks = 0;        } else if (style.equalsIgnoreCase("points")) {            _marks = 1;        } else if (style.equalsIgnoreCase("dots")) {            _marks = 2;        } else if (style.equalsIgnoreCase("various")) {            _marks = 3;        }    }    /**      * Specify the number of data sets to be plotted together.     * Allocate a Vector to store each data set.  Note that calling     * this causes any previously plotted points to be forgotten.     * This method should be called before     * <code>setPointsPersistence</code>.     * @exception java.lang.NumberFormatException if the number is less     * than 1 or greater than an internal limit (usually 63).     */    public void setNumSets (int numsets) throws NumberFormatException {        if (numsets < 1) {            throw new NumberFormatException("Number of data sets ("+                    numsets + ") must be greater than 0.");        }        if (numsets > _MAX_DATASETS) {            throw new NumberFormatException("Number of data sets (" +                    numsets + ") must be less than the internal limit of " +                    _MAX_DATASETS + "To increase this value, edit " +                    "_MAX_DATASETS and recompile");        }        _currentdataset = -1;        _datasetoverflow = false;        _numsets = numsets;        _points = new Vector[numsets];        _prevx = new long[numsets];        _prevy = new long[numsets];        for (int i=0; i<numsets; i++) {            _points[i] = new Vector();        }    }        /**      * Calling this method with a positive argument sets the     * persistence of the plot to the given number of points.  Calling     * with a zero argument turns off this feature, reverting to     * infinite memory (unless sweeps persistence is set).  If both     * sweeps and points persistence are set then sweeps take     * precedence.  This method should be called after     * <code>setNumSets()</code>.       * FIXME: No file format yet.     */    public void setPointsPersistence (int persistence) {        _pointsPersistence = persistence;        if (persistence > 0) {            for (int i = 0; i < _numsets; i++) {                _points[i].setSize(persistence);            }        }    }        /**      * A sweep is a sequence of points where the value of X is     * increasing.  A point that is added with a smaller x than the     * previous point increments the sweep count.  Calling this method     * with a non-zero argument sets the persistence of the plot to     * the given number of sweeps.  Calling with a zero argument turns     * off this feature.  If both sweeps and points persistence are     * set then sweeps take precedence.     * FIXME: No file format yet.     * FIXME: Not implemented yet.     */    public void setSweepsPersistence (int persistence) {        _sweepsPersistence = persistence;    }    /** Start the plot.     * This method is redefined in child classes, such as PlotLive.        */    public void start () {    }    /** Stop the plot.     * This method is redefined in child classes, such as PlotLive.        */    public void stop () {    }    //////////////////////////////////////////////////////////////////////////    ////                          protected methods                       ////              /**     * Draw bar from the specified point to the y axis.     * If the specified point is below the y axis or outside the     * x range, do nothing.  If the <i>clip</i> argument is true,     * then do not draw above the y range.     * Note that PlotBox::drawPlot() should be called before     * calling this method so that _xscale and _yscale are properly set.     */    protected void _drawBar (Graphics graphics, int dataset,            long xpos, long ypos, boolean clip) {        if (_debug > 21) {            System.out.println("Plot: _drawBar("+dataset+" "+                    xpos+" "+ypos+" "+clip+")");        }        if (clip) {            if (ypos < _uly) {                ypos = _uly;            } if (ypos > _lry) {                ypos = _lry;            }        }        if (ypos <= _lry && xpos <= _lrx && xpos >= _ulx) {            // left x position of bar.            int barlx = (int)(xpos - _barwidth * _xscale/2 +                    (_currentdataset - dataset - 1) *                    _baroffset * _xscale);            // right x position of bar            int barrx = (int)(barlx + _barwidth * _xscale);            if (barlx < _ulx) barlx = _ulx;            if (barrx > _lrx) barrx = _lrx;            // Make sure that a bar is always at least one pixel wide.            if (barlx >= barrx) barrx = barlx+1;            // The y position of the zero line.            long zeroypos = _lry - (long) ((0-_yMin) * _yscale);            if (_lry < zeroypos) zeroypos = _lry;            if (_uly > zeroypos) zeroypos = _uly;            if (_debug > 20) {                System.out.println("Plot:_drawBar ("+barlx+" "+ypos+" "+                        (barrx - barlx) + " "+(zeroypos-ypos)+") "+barrx+" "+                        barlx+" ("+_ulx+" "+_lrx+" "+_uly+" "+_lry+                        ") xpos="+xpos+" ypos="+ypos+" zeroypos="+zeroypos+                         " "+_barwidth+" "+_xscale+" "+_currentdataset+                        " "+_yMin);            }            if (_yMin >= 0 || ypos <= zeroypos) {                graphics.fillRect(barlx, (int)ypos,                        barrx - barlx, (int)(zeroypos - ypos));            } else {                graphics.fillRect(barlx, (int)zeroypos,                        barrx - barlx, (int)(ypos - zeroypos));            }        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -