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

📄 polarplot.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   
    /**
     * Sets the item renderer, and notifies all listeners of a change to the plot.
     * <P>
     * If the renderer is set to <code>null</code>, no chart will be drawn.
     *
     * @param renderer  the new renderer (<code>null</code> permitted).
     */
    public void setRenderer(PolarItemRenderer renderer) {
        if (this.renderer != null) {
            this.renderer.removeChangeListener(this);
        }
       
        this.renderer = renderer;
        if (this.renderer != null) {
            this.renderer.setPlot(this);
        }
       
        notifyListeners(new PlotChangeEvent(this));
    }
   
    /**
     * Returns a flag that controls whether or not the angle labels are visible.
     * 
     * @return A boolean.
     */
    public boolean isAngleLabelsVisible() {
        return this.angleLabelsVisible;
    }
    
    /**
     * Sets the flag that controls whether or not the angle labels are visible, and sends a
     * {@link PlotChangeEvent} to all registered listeners.
     * 
     * @param visible  the flag.
     */
    public void setAngleLabelsVisible(boolean visible) {
        this.angleLabelsVisible = visible;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Returns the font used to display the angle labels.
     * 
     * @return A font.
     */
    public Font getAngleLabelFont() {
        return this.angleLabelFont;
    }
    
    /**
     * Sets the font used to display the angle labels and sends a {@link PlotChangeEvent} to
     * all registered listeners.
     * 
     * @param font  the font.
     */
    public void setAngleLabelFont(Font font) {
        this.angleLabelFont = font;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Returns the paint used to display the angle labels.
     * 
     * @return A paint.
     */
    public Paint getAngleLabelPaint() {
        return this.angleLabelPaint;
    }
    
    /**
     * Sets the paint used to display the angle labels and sends a {@link PlotChangeEvent}
     * to all registered listeners.
     * 
     * @param paint  the paint.
     */
    public void setAngleLabelPaint(Paint paint) {
        this.angleLabelPaint = paint;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Returns <code>true</code> if the angular gridlines are visible, and <code>false<code>
     * otherwise.
     *
     * @return <code>true</code> or <code>false</code>.
     */
    public boolean isAngleGridlinesVisible() {
        return this.angleGridlinesVisible;
    }
    
    /**
     * Sets the flag that controls whether or not the angular grid-lines are visible.
     * <p>
     * If the flag value is changed, a {@link PlotChangeEvent} is sent to all registered listeners.
     *
     * @param visible  the new value of the flag.
     */
    public void setAngleGridlinesVisible(boolean visible) {
        if (this.angleGridlinesVisible != visible) {
            this.angleGridlinesVisible = visible;
            notifyListeners(new PlotChangeEvent(this));
        }
    }
   
    /**
     * Returns the stroke for the grid-lines (if any) plotted against the angular axis.
     *
     * @return the stroke.
     */
    public Stroke getAngleGridlineStroke() {
        return this.angleGridlineStroke;
    }
    
    /**
     * Sets the stroke for the grid lines plotted against the angular axis.
     * <p>
     * If you set this to <code>null</code>, no grid lines will be drawn.
     *
     * @param stroke  the stroke (<code>null</code> permitted).
     */
    public void setAngleGridlineStroke(Stroke stroke) {
        this.angleGridlineStroke = stroke;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Returns the paint for the grid lines (if any) plotted against the angular axis.
     *
     * @return the paint.
     */
    public Paint getAngleGridlinePaint() {
        return this.angleGridlinePaint;
    }
   
    /**
     * Sets the paint for the grid lines plotted against the angular axis.
     * <p>
     * If you set this to <code>null</code>, no grid lines will be drawn.
     *
     * @param paint  the paint (<code>null</code> permitted).
     */
    public void setAngleGridlinePaint(Paint paint) {
        this.angleGridlinePaint = paint;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Returns <code>true</code> if the radius axis grid is visible, and <code>false<code>
     * otherwise.
     *
     * @return <code>true</code> or <code>false</code>.
     */
    public boolean isRadiusGridlinesVisible() {
        return this.radiusGridlinesVisible;
    }
    
    /**
     * Sets the flag that controls whether or not the radius axis grid lines are visible.
     * <p>
     * If the flag value is changed, a {@link PlotChangeEvent} is sent to all registered listeners.
     *
     * @param visible  the new value of the flag.
     */
    public void setRadiusGridlinesVisible(boolean visible) {
        if (this.radiusGridlinesVisible != visible) {
            this.radiusGridlinesVisible = visible;
            notifyListeners(new PlotChangeEvent(this));
        }
    }
   
    /**
     * Returns the stroke for the grid lines (if any) plotted against the radius axis.
     *
     * @return the stroke.
     */
    public Stroke getRadiusGridlineStroke() {
        return this.radiusGridlineStroke;
    }
    
    /**
     * Sets the stroke for the grid lines plotted against the radius axis.
     * <p>
     * If you set this to <code>null</code>, no grid lines will be drawn.
     *
     * @param stroke  the stroke (<code>null</code> permitted).
     */
    public void setRadiusGridlineStroke(Stroke stroke) {
        this.radiusGridlineStroke = stroke;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Returns the paint for the grid lines (if any) plotted against the radius axis.
     *
     * @return the paint.
     */
    public Paint getRadiusGridlinePaint() {
        return this.radiusGridlinePaint;
    }
    
    /**
     * Sets the paint for the grid lines plotted against the radius axis.
     * <p>
     * If you set this to <code>null</code>, no grid lines will be drawn.
     *
     * @param paint  the paint (<code>null</code> permitted).
     */
    public void setRadiusGridlinePaint(Paint paint) {
        this.radiusGridlinePaint = paint;
        notifyListeners(new PlotChangeEvent(this));
    }
    
    /**
     * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
     * <P>
     * This plot relies on an {@link org.jfree.chart.renderer.DefaultPolarItemRenderer} to draw 
     * each item in the plot.  This allows the visual representation of the data to be changed 
     * easily.
     * <P>
     * The optional info argument collects information about the rendering of
     * the plot (dimensions, tooltip information etc).  Just pass in <code>null</code> if
     * you do not need this information.
     *
     * @param g2  the graphics device.
     * @param plotArea  the area within which the plot (including axes and labels) should be drawn.
     * @param parentState  ignored.
     * @param info  collects chart drawing information (<code>null</code> permitted).
     */
    public void draw(Graphics2D g2, 
                     Rectangle2D plotArea, 
                     PlotState parentState,
                     PlotRenderingInfo info) {
       
        // if the plot area is too small, just return...
        boolean b1 = (plotArea.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
        boolean b2 = (plotArea.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
        if (b1 || b2) {
            return;
        }
       
        // record the plot area...
        if (info != null) {
            info.setPlotArea(plotArea);
        }
       
        // adjust the drawing area for the plot insets (if any)...
        Insets insets = getInsets();
        if (insets != null) {
            plotArea.setRect(plotArea.getX() + insets.left,
                             plotArea.getY() + insets.top,
                             plotArea.getWidth() - insets.left - insets.right,
                             plotArea.getHeight() - insets.top - insets.bottom);
        }
      
        Rectangle2D dataArea = plotArea;
        if (info != null) {
            info.setDataArea(dataArea);
        }
       
        // draw the plot background and axes...
        drawBackground(g2, dataArea);
        double h = Math.min(dataArea.getWidth() / 2.0, dataArea.getHeight() / 2.0) - MARGIN;
        Rectangle2D quadrant = new Rectangle2D.Double(
            dataArea.getCenterX(), dataArea.getCenterY(), h, h
        );
        AxisState state = drawAxis(g2, plotArea, quadrant);
        if (this.renderer != null) {
            Shape originalClip = g2.getClip();
            Composite originalComposite = g2.getComposite();
          
            g2.clip(dataArea);
            g2.setComposite(
                AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())
            );
          
            drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
          
            // draw...
            render(g2, dataArea, info);
          
            g2.setClip(originalClip);
            g2.setComposite(originalComposite);
        }
        drawOutline(g2, dataArea);
        drawCornerTextItems(g2, dataArea);
    }
   
    /**
     * Draws the corner text items.
     * 
     * @param g2  the drawing surface.
     * @param area  the area.
     */
    public void drawCornerTextItems(Graphics2D g2, Rectangle2D area) {
        if (this.cornerTextItems.isEmpty()) {
            return;
        }
       
        g2.setColor(Color.black);
        double width = 0.0;
        double height = 0.0;
        for (Iterator it = this.cornerTextItems.iterator(); it.hasNext();) {
            String msg = (String) it.next();
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(msg, g2, fm);
            width = Math.max(width, bounds.getWidth());
            height += bounds.getHeight();
        }
        
        double xadj = ANNOTATION_MARGIN * 2.0;
        double yadj = ANNOTATION_MARGIN;
        width += xadj;
        height += yadj;
       
        double x = area.getMaxX() - width;
        double y = area.getMaxY() - height;
        g2.drawRect((int) x, (int) y, (int) width, (int) height);
        x += ANNOTATION_MARGIN;
        for (Iterator it = this.cornerTextItems.iterator(); it.hasNext();) {
            String msg = (String) it.next();
            Rectangle2D bounds = TextUtilities.getTextBounds(msg, g2, g2.getFontMetrics());
            y += bounds.getHeight();
            g2.drawString(msg, (int) x, (int) y);
        }
    }
   
    /**
     * A utility method for drawing the axes.
     *
     * @param g2  the graphics device.
     * @param plotArea  the plot area.
     * @param dataArea  the data area.
     * 
     * @return A map containing the axis states.
     */
    protected AxisState drawAxis(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea) {
        return this.radiusAxis.draw(
            g2, dataArea.getMinY(), plotArea, dataArea, RectangleEdge.TOP, null
        );
    }
   
    /**
     * Draws a representation of the data within the dataArea region, using the
     * current m_Renderer.
     *
     * @param g2  the graphics device.
     * @param dataArea  the region in which the data is to be drawn.
     * @param info  an optional object for collection dimension 
     *              information (<code>null</code> permitted).
     */
    public void render(Graphics2D g2,
                       Rectangle2D dataArea,
                       PlotRenderingInfo info) {
      
        // now get the data and plot it (the visual representation will depend
        // on the m_Renderer that has been set)...

⌨️ 快捷键说明

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