defaultoldlegend.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,343 行 · 第 1/4 页
JAVA
1,343 行
if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.outlinePaint = paint; notifyListeners(new LegendChangeEvent(this)); } /** * Gets the title for the legend. * * @return The title (possibly <code>null</code>). */ public String getTitle() { return this.title; } /** * 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 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)); } /** * 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) { LegendItemCollection legendItems = getChart().getPlot().getLegendItems(); if (legendItems == null || legendItems.getItemCount() == 0) { return available; } // else... DrawableLegendItem legendTitle = null; LegendItem titleItem = null; if (this.title != null && !this.title.equals("")) { titleItem = new LegendItem( this.title, this.title, null, null, (Shape) null, Color.black ); } RectangularShape legendArea; double availableWidth = available.getWidth(); // the translation point for the origin of the drawing system Point2D translation; // Create buffer for individual items within the legend List items = new ArrayList(); // Compute individual rectangles in the legend, translation point as // well as the bounding box for the legend. if (horizontal) { double xstart = available.getX() + getMargin().calculateLeftOutset(availableWidth); double xlimit = available.getMaxX() - getMargin().calculateRightOutset(availableWidth); double maxRowWidth = 0; double xoffset = 0; double rowHeight = 0; double totalHeight = 0; boolean wrappingAllowed = true; if (titleItem != null) { g2.setFont(getTitleFont()); legendTitle = createDrawableLegendItem( g2, titleItem, xoffset, totalHeight ); rowHeight = Math.max(0, legendTitle.getHeight()); xoffset += legendTitle.getWidth(); } g2.setFont(this.itemFont); for (int i = 0; i < legendItems.getItemCount(); i++) { DrawableLegendItem item; if (this.renderingOrder == LegendRenderingOrder.STANDARD) { item = createDrawableLegendItem( g2, legendItems.get(i), xoffset, totalHeight ); } else if (this.renderingOrder == LegendRenderingOrder.REVERSE) { item = createDrawableLegendItem( g2, legendItems.get(legendItems.getItemCount() - i - 1),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?