standardlegend.java

来自「jfreechart安装程序和使用说明」· Java 代码 · 共 1,420 行 · 第 1/4 页

JAVA
1,420
字号
     * Sets the title of the legend and sends a {@link LegendChangeEvent} to all registered 
     * listeners.
     *
     * @param title  the title (<code>null</code> permitted).
     */
    public void setTitle(String title) {
        this.title = title;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the title font.
     *
     * @return The font (never <code>null</code>).
     */
    public Font getTitleFont() {
        return this.titleFont;
    }

    /**
     * Sets the title font and sends a {@link LegendChangeEvent} to all registered listeners.
     *
     * @param font  the font (<code>null</code> not permitted).
     */
    public void setTitleFont(Font font) {
        if (font == null) {
            throw new IllegalArgumentException("Null 'font' argument.");   
        }
        this.titleFont = font;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the series label font.
     *
     * @return The font (never <code>null</code>).
     */
    public Font getItemFont() {
        return this.itemFont;
    }

    /**
     * Sets the series label font and sends a {@link LegendChangeEvent} to all registered 
     * listeners.
     *
     * @param font  the font (<code>null</code> not permitted).
     */
    public void setItemFont(Font font) {
        if (font == null) {
            throw new IllegalArgumentException("Null 'font' argument.");  
        }
        this.itemFont = font;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the series label paint.
     *
     * @return The paint (never <code>null</code>).
     */
    public Paint getItemPaint() {
        return this.itemPaint;
    }

    /**
     * Sets the series label paint and sends a {@link LegendChangeEvent} to all registered 
     * listeners.
     *
     * @param paint  the paint (<code>null</code> not permitted).
     */
    public void setItemPaint(Paint paint) {
        if (paint == null) {
            throw new IllegalArgumentException("Null 'paint' argument.");   
        }
        this.itemPaint = paint;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the flag that indicates whether or not outlines are drawn around shapes.
     *
     * @return The flag.
     */
    public boolean getOutlineShapes() {
        return this.outlineShapes;
    }

    /**
     * Sets the flag that controls whether or not outlines are drawn around shapes, and sends a
     * {@link LegendChangeEvent} to all registered listeners.
     *
     * @param flag  the flag.
     */
    public void setOutlineShapes(boolean flag) {
        this.outlineShapes = flag;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the stroke used to outline shapes.
     *
     * @return The stroke (never <code>null</code>).
     */
    public Stroke getShapeOutlineStroke() {
        return this.shapeOutlineStroke;
    }

    /**
     * Sets the stroke used to outline shapes and sends a {@link LegendChangeEvent} to all 
     * registered listeners.
     *
     * @param stroke  the stroke (<code>null</code> not permitted).
     */
    public void setShapeOutlineStroke(Stroke stroke) {
        if (stroke == null) {
            throw new NullPointerException("Null 'stroke' argument");
        }
        this.shapeOutlineStroke = stroke;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the paint used to outline shapes.
     *
     * @return The paint.
     */
    public Paint getShapeOutlinePaint() {
        return this.shapeOutlinePaint;
    }

    /**
     * Sets the paint used to outline shapes.  A {@link LegendChangeEvent} is sent to all
     * registered listeners.
     *
     * @param paint  the paint.
     */
    public void setShapeOutlinePaint(Paint paint) {
        this.shapeOutlinePaint = paint;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Sets a flag that controls whether or not the legend displays the series shapes.
     *
     * @param flag  the new value of the flag.
     */
    public void setDisplaySeriesShapes(boolean flag) {
        this.displaySeriesShapes = flag;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns a flag that controls whether or not the legend displays the series shapes.
     *
     * @return <code>true</code> if the series shapes should be displayed, <code>false</code> 
     *         otherwise.
     */
    public boolean getDisplaySeriesShapes() {
        return this.displaySeriesShapes;
    }
    
    /**
     * Returns the x scale factor for shapes displayed in the legend.
     * 
     * @return the x scale factor.
     */
    public double getShapeScaleX() {
        return this.shapeScaleX;
    }
    
    /**
     * Sets the x scale factor for shapes displayed in the legend and sends a
     * {@link LegendChangeEvent} to all registered listeners.
     * 
     * @param factor  the factor.
     */
    public void setShapeScaleX(double factor) {
        this.shapeScaleX = factor;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the y scale factor for shapes displayed in the legend.
     * 
     * @return the y scale factor.
     */
    public double getShapeScaleY() {
        return this.shapeScaleY;
    }
    
    /**
     * Sets the y scale factor for shapes displayed in the legend and sends a
     * {@link LegendChangeEvent} to all registered listeners.
     * 
     * @param factor  the factor.
     */
    public void setShapeScaleY(double factor) {
        this.shapeScaleY = factor;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Sets a flag that controls whether or not the legend displays the series line stroke.
     *
     * @param flag  the new value of the flag.
     */
    public void setDisplaySeriesLines(boolean flag) {
        this.displaySeriesLines = flag;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns a flag that controls whether or not the legend displays the series line stroke.
     *
     * @return <code>true</code> if the series lines should be displayed, <code>false</code> 
     *         otherwise.
     */
    public boolean getDisplaySeriesLines() {
        return this.displaySeriesLines;
    }

    /**
     * Returns the legend rendering order. 
     * 
     * @return The order (never <code>null</code>).
     */
    public LegendRenderingOrder getRenderingOrder() {
        return this.renderingOrder;
    }

    /**
     * Sets the legend rendering order and sends a {@link LegendChangeEvent} to all registered
     * listeners.
     * 
     * @param order  the order (<code>null</code> not permitted).
     */
    public void setRenderingOrder(LegendRenderingOrder order) {
        if (order == null) {
            throw new IllegalArgumentException("Null 'order' argument.");   
        }
        this.renderingOrder = order;
        notifyListeners(new LegendChangeEvent(this));
    }

    
    /**
     * Returns the width of the arc used to round off the corners of the
     * bounding box. 
     * 
     * @return the width of the arc used to round off the corners of the
     * bounding box.
     */
    public int getBoundingBoxArcWidth() {
        return this.boundingBoxArcWidth;
    }
    
    /**
     * Sets the width of the arc used to round off the corners of the
     * bounding box. 
     * A {@link LegendChangeEvent} is sent to all registered listeners.
     * 
     * @param arcWidth the new arc width.
     */
    public void setBoundingBoxArcWidth(int arcWidth) {
        this.boundingBoxArcWidth = arcWidth;
        notifyListeners(new LegendChangeEvent(this));
    }
    
    /**
     * Returns the height of the arc used to round off the corners of the
     * bounding box. 
     * 
     * @return the height of the arc used to round off the corners of the
     * bounding box.
     */
    public int getBoundingBoxArcHeight() {
        return this.boundingBoxArcHeight;
    }
    
    /**
     * Sets the height of the arc used to round off the corners of the
     * bounding box. 
     * A {@link LegendChangeEvent} is sent to all registered listeners.
     * 
     * @param arcHeight the new arc height.
     */
    public void setBoundingBoxArcHeight(int arcHeight) {
        this.boundingBoxArcHeight = arcHeight;
        notifyListeners(new LegendChangeEvent(this));
    }

    /**
     * Returns the preferred width of the legend bounding box if such width
     * has been defined; otherwise returns <code>NO_PREFERRED_WIDTH</code>.
     * 
     * @return the preferred width of the legend bounding box if such width
     * has been defined; otherwise returns <code>NO_PREFERRED_WIDTH</code>.
     */
    public double getPreferredWidth() {
        return this.preferredWidth;
    }

    /**
     * Sets the preferred width of the legend bounding box. If a preferred
     * width is set, the legend text is word-wrapped in an attempt to fulfill 
     * the preferred width. If the preferred width cannot be fulfilled, the 
     * legend would be wider to the extent necessary.
     * 
     * <p>
     * The preferred width takes effect only when the legend's anchor is set to 
     * one of the three EAST anchors or to one of the three WEST anchors.
     *   
     * <p>  
     * A {@link LegendChangeEvent} is sent to all registered listeners.
     * 
     * @param width the new width.
     */
    public void setPreferredWidth(double width) {
        this.preferredWidth = width;
        notifyListeners(new LegendChangeEvent(this));
    }
    
    /**
     * Draws the legend on a Java 2D graphics device (such as the screen or a printer).
     *
     * @param g2  the graphics device.
     * @param available  the area within which the legend, and afterwards the plot, should be
     *                   drawn.
     * @param info  collects rendering info (optional).
     *
     * @return The area NOT used by the legend.
     */
    public Rectangle2D draw(Graphics2D g2, Rectangle2D available, ChartRenderingInfo info) {

        return draw(
            g2, available, (getAnchor() & HORIZONTAL) != 0, (getAnchor() & INVERTED) != 0, info
        );

    }

    /**
     * Draws the legend.
     *
     * @param g2  the graphics device.
     * @param available  the area available for drawing the chart.
     * @param horizontal  a flag indicating whether the legend items are laid out horizontally.
     * @param inverted ???
     * @param info  collects rendering info (optional).
     *
     * @return The remaining available drawing area.
     */
    protected Rectangle2D draw(Graphics2D g2, Rectangle2D available,
                               boolean horizontal, boolean inverted,
                               ChartRenderingInfo info) {

⌨️ 快捷键说明

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