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

📄 plotbox.java

📁 Differential Evolution(JAVA)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                // Recalculate the start using the new step.                xTmpStart=tmpStep*Math.ceil(_xtickMin/tmpStep);                Vector unlabeledgrid  = _gridInit(xTmpStart, tmpStep,                        false, xgrid);                if (unlabeledgrid.size() > 0 ) {                    if (_debug == 5)                         System.out.println("PlotBox: drawPlot: tmpStep = "+                                tmpStep+" xTmpStart="+xTmpStart);                    for (double xpos = _gridStep(unlabeledgrid, xTmpStart,                             tmpStep, _xlog);                         xpos <= _xtickMax;                         xpos = _gridStep(unlabeledgrid, xpos,                                 tmpStep, _xlog)) {                        xCoord1 = _ulx + (int)((xpos-_xtickMin)*_xtickscale);                        if (_grid && xCoord1 != _ulx && xCoord1 != _lrx) {                            graphics.setColor(Color.lightGray);                            graphics.drawLine(xCoord1,_uly+1,xCoord1,_lry-1);                            graphics.setColor(_foreground);                        }                                        }                }                if (needExponent) {                    _xExp = (int)Math.floor(xTmpStart);                    graphics.setFont(_superscriptfont);                    graphics.drawString(Integer.toString(_xExp), xSPos,                            ySPos - halflabelheight);                    xSPos -= _labelFontMetrics.stringWidth("x10");                    graphics.setFont(_labelfont);                    graphics.drawString("x10", xSPos, ySPos);                } else {                    _xExp = 0;                }            }        } else {            // ticks have been explicitly specified            Enumeration nt = _xticks.elements();            Enumeration nl = _xticklabels.elements();            while (nl.hasMoreElements()) {                String label = (String) nl.nextElement();                double xpos = ((Double)(nt.nextElement())).doubleValue();                if (xpos > _xMax || xpos < _xMin) continue;                xCoord1 = _ulx + (int)((xpos-_xMin)*_xscale);                graphics.drawLine(xCoord1,_uly,xCoord1,yCoord1);                graphics.drawLine(xCoord1,_lry,xCoord1,yCoord2);                if (_grid && xCoord1 != _ulx && xCoord1 != _lrx) {                    graphics.setColor(Color.lightGray);                    graphics.drawLine(xCoord1,yCoord1,xCoord1,yCoord2);                    graphics.setColor(_foreground);                }                int labxpos = xCoord1 - _labelFontMetrics.stringWidth(label)/2;                // NOTE: 3 pixel spacing between axis and labels.                graphics.drawString(label, labxpos, _lry + 3 + labelheight);            }        }                ///////////////////// Draw title and axis labels now.                // Center the title and X label over the plotting region, not        // the window.        graphics.setColor(_foreground);                if (_title != null) {            graphics.setFont(_titlefont);            int titlex = _ulx +                (width - _titleFontMetrics.stringWidth(_title))/2;            graphics.drawString(_title,titlex,titley);        }                graphics.setFont(_labelfont);        if (_xlabel != null) {            int labelx = _ulx +                (width - _labelFontMetrics.stringWidth(_xlabel))/2;            graphics.drawString(_xlabel,labelx,ySPos);        }                int charcenter = 2 + _labelFontMetrics.stringWidth("W")/2;        int charheight = labelheight;        if (_ylabel != null) {            // Vertical label is fairly complex to draw.            int yl = _ylabel.length();            int starty = _uly + (_lry-_uly)/2 - yl*charheight/2 + charheight;            for (int i = 0; i < yl; i++) {                String nchar = _ylabel.substring(i,i+1);                int cwidth = _labelFontMetrics.stringWidth(nchar);                graphics.drawString(nchar,charcenter - cwidth/2, starty);                starty += charheight;            }        }    }        /**     * Get the Font by name.       * @deprecated: As of JDK1.1, use Font.decode() instead.     * We need to compile under JDK1.0.2, so we use this method.     */    public Font getFontByName(String fullfontname) {        // Can't use Font.decode() here, it is not present in jdk1.0.2        //_labelfont = Font.decode(fullfontname);        String fontname = new String ("helvetica");        int style = Font.PLAIN;        int size = 12;        StringTokenizer stoken = new StringTokenizer(fullfontname,"-");                if (stoken.hasMoreTokens()) {            fontname = stoken.nextToken();        }        if (stoken.hasMoreTokens()) {            String stylename = stoken.nextToken();            // FIXME: we need to be able to mix and match these            if (stylename.equals("PLAIN")) {                style = Font.PLAIN;            } else if (stylename.equals("BOLD")) {                style = Font.BOLD;            } else if (stylename.equals("ITALIC")) {                style = Font.ITALIC;            } else {                // Perhaps this is a font size?                try {                    size = Integer.valueOf(stylename).intValue();                } catch (NumberFormatException e) {}            }        }        if (stoken.hasMoreTokens()) {            try {                size = Integer.valueOf(stoken.nextToken()).intValue();            } catch (NumberFormatException e) {}        }        if (_debug > 7) System.out.println("PlotBox: getFontByName: "+                fontname+" "+style+" "+size);        return new Font(fontname, style, size);    }    /**      * Convert a color name into a Color.     */    public static Color getColorByName(String name) {        try {            // Check to see if it is a hexadecimal            // Can't use Color decode here, it is not in 1.0.2            //Color col = Color.decode(name);            Color col = new Color(Integer.parseInt(name,16));            return col;        } catch (NumberFormatException e) {}        // FIXME: This is a poor excuse for a list of colors and values.        // We should use a hash table here.        // Note that Color decode() wants the values to start with 0x.        String names[][] = {            {"black","00000"},{"white","ffffff"},            {"red","ff0000"}, {"green","00ff00"}, {"blue","0000ff"}        };        for(int i=0;i< names.length; i++) {            if(name.equals(names[i][0])) {                try {                    Color col = new Color(Integer.parseInt(names[i][1],16));                    return col;                } catch (NumberFormatException e) {}            }        }        return null;    }    /**     * Get the dataurl.     */    public String getDataurl () {        return _dataurl;    }    /** Get the document base     */    public URL getDocumentBase () {        return _documentBase;    }    /**      * Get the legend for a dataset.     */    public String getLegend(int dataset) {        int idx = _legendDatasets.indexOf(new Integer(dataset),0);        if (idx != -1) {            return (String)_legendStrings.elementAt(idx);        } else {            return null;        }    }          /** Get the minimum size of this component.     */    public Dimension getMinimumSize() {        if (_debug > 8) System.out.println("PlotBox: getMinimumSize");        return new Dimension(_width, _height);    }    /** Get the preferred size of this component.     */    public Dimension getPreferredSize() {        if (_debug > 8) System.out.println("PlotBox: getPreferredSize");       return new Dimension(_width, _height);    }    /** Initialize the component, creating the fill button and setting     * the colors.  If the dataurl has been set, then parse that file.     */    public void init() {
        //super.init();
        if (_debug > 8) System.out.println("PlotBox: init");                        _xticks = null;        _xticklabels = null;        _yticks = null;        _yticklabels = null;        _graphics = getGraphics(); //Debug Code
        if (_graphics == null) {            System.out.println("PlotBox::init(): Internal error: " +                    "_graphic was null, be sure to call show()\n"+                    "before calling init()");            return;        }        if (_foreground != null) {            setForeground(_foreground);        } else {            _foreground = Color.black;        }        if (_background != null) {            setBackground(_background);        } else {            _background = Color.white;        }        if (_debug > 6)            System.out.println("PlotBox: color = "+_foreground+" "+                    _background);        // Make a button that auto-scales the plot.        // NOTE: The button infringes on the title space.        // If more buttons are added, we may have to find some other place        // for them, like below the legend, stacked vertically.        setLayout(new FlowLayout(FlowLayout.RIGHT));

		//---Fill Button not needed---------------------        //_fillButton = new Button("fill");        //add(_fillButton);        //validate();        if (_dataurl != null) {            parseFile(_dataurl,_documentBase);        }    }            /** The minimum size.     * @deprecated As of JDK1.1 in java.awt.component, but we need      * to compile under 1.0.2 for netscape3.x compatibility.     */    public Dimension minimumSize() {        if (_debug > 9)            System.out.println("PlotBox: minimumSize "+_width+" "+_height);        return getMinimumSize();    }    /**     * Set the starting point for an interactive zoom box.     * @deprecated As of JDK1.1 in java.awt.component      * but we need to compile under 1.0.2 for netscape3.x compatibility.     */    public boolean mouseDown(Event evt, int x, int y) { // deprecated        // constrain to be in range        if (_debug > 9) System.out.println("PlotBox: mouseDown "+x+" "+y);        if (y > _lry) y=_lry;        if (y < _uly) y=_uly;        if (x > _lrx) x=_lrx;        if (x < _ulx) x=_ulx;        _zoomx = x;        _zoomy = y;        return true;    }        /**     * Draw a box for an interactive zoom box.     * Return a boolean indicating whether or not we have dealt with     * the event.     * @deprecated As of JDK1.1 in java.awt.component      * but we need to compile under 1.0.2 for netscape3.x compatibility.     */    public synchronized boolean mouseDrag(Event evt, int x, int y) {        // We make this method synchronized so that we can draw the drag        // box properly.  If this method is not synchronized, then        // we could end up calling setXORMode, being interrupted        // and having setPaintMode() called in another method.        if (_debug > 9) System.out.println("PlotBox: mouseDrag "+x+" "+y);        if (_graphics == null) {            System.out.println("PlotBox.mouseDrag(): Internal error: " +                    "_graphic was null, be sure to call init()");        }        // Bound the rectangle so it doesn't go outside the box.        if (y > _lry) y=_lry;        if (y < _uly) y=_uly;        if (x > _lrx) x=_lrx;        if (x < _ulx) x=_ulx;        // erase previous rectangle, if there was one.        if ((_zoomx != -1 || _zoomy != -1)) {            // Ability to zoom out added by William Wu.            // If we are not already zooming, figure out whether we            // are zooming in or out.            if (_zoomin == false && _zoomout == false){                if (y < _zoomy) {                    _zoomout = true;                    // Draw reference box.                    _graphics.drawRect(_zoomx-15, _zoomy-15, 30, 30);                } else if (y > _zoomy) {                    _zoomin = true;                 }            }            if (_zoomin == true){                   _graphics.setXORMode(_background);                // Erase the previous box if necessary.                if ((_zoomxn != -1 || _zoomyn != -1) && (_drawn == true)) {                    int minx = Math.min(_zoomx, _zoomxn);                    int maxx = Math.max(_zoomx, _zoomxn);

⌨️ 快捷键说明

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