Java Code Examples for org.jfree.ui.RectangleEdge#LEFT

The following examples show how to use org.jfree.ui.RectangleEdge#LEFT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AxisSpace.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds space to the top, bottom, left or right edge of the plot area.
 *
 * @param space  the space (in Java2D units).
 * @param edge  the edge (<code>null</code> not permitted).
 */
public void add(double space, RectangleEdge edge) {
    ParamChecks.nullNotPermitted(edge, "edge");
    if (edge == RectangleEdge.TOP) {
        this.top += space;
    }
    else if (edge == RectangleEdge.BOTTOM) {
        this.bottom += space;
    }
    else if (edge == RectangleEdge.LEFT) {
        this.left += space;
    }
    else if (edge == RectangleEdge.RIGHT) {
        this.right += space;
    }
    else {
        throw new IllegalStateException("Unrecognised 'edge' argument.");
    }
}
 
Example 2
Source File: CategoryAxis.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the starting coordinate for the specified category.
 *
 * @param category  the category.
 * @param categoryCount  the number of categories.
 * @param area  the data area.
 * @param edge  the axis location.
 *
 * @return The coordinate.
 *
 * @see #getCategoryMiddle(int, int, Rectangle2D, RectangleEdge)
 * @see #getCategoryEnd(int, int, Rectangle2D, RectangleEdge)
 */
public double getCategoryStart(int category, int categoryCount, 
        Rectangle2D area, RectangleEdge edge) {

    double result = 0.0;
    if ((edge == RectangleEdge.TOP) || (edge == RectangleEdge.BOTTOM)) {
        result = area.getX() + area.getWidth() * getLowerMargin();
    }
    else if ((edge == RectangleEdge.LEFT)
            || (edge == RectangleEdge.RIGHT)) {
        result = area.getMinY() + area.getHeight() * getLowerMargin();
    }

    double categorySize = calculateCategorySize(categoryCount, area, edge);
    double categoryGapWidth = calculateCategoryGapSize(categoryCount, area,
            edge);

    result = result + category * (categorySize + categoryGapWidth);
    return result;
}
 
Example 3
Source File: CategoryAxis.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the size (width or height, depending on the location of the
 * axis) of a category gap.
 *
 * @param categoryCount  the number of categories.
 * @param area  the area within which the categories will be drawn.
 * @param edge  the axis location.
 *
 * @return The category gap width.
 */
protected double calculateCategoryGapSize(int categoryCount, 
        Rectangle2D area, RectangleEdge edge) {

    double result = 0.0;
    double available = 0.0;

    if ((edge == RectangleEdge.TOP) || (edge == RectangleEdge.BOTTOM)) {
        available = area.getWidth();
    }
    else if ((edge == RectangleEdge.LEFT)
            || (edge == RectangleEdge.RIGHT)) {
        available = area.getHeight();
    }

    if (categoryCount > 1) {
        result = available * getCategoryMargin() / (categoryCount - 1);
    }
    return result;
}
 
Example 4
Source File: AxisCollection.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds an axis to the collection.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 * @param edge  the edge of the plot that the axis should be drawn on
 *              (<code>null</code> not permitted).
 */
public void add(Axis axis, RectangleEdge edge) {
    ParamChecks.nullNotPermitted(axis, "axis");
    ParamChecks.nullNotPermitted(edge, "edge");
    if (edge == RectangleEdge.TOP) {
        this.axesAtTop.add(axis);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        this.axesAtBottom.add(axis);
    }
    else if (edge == RectangleEdge.LEFT) {
        this.axesAtLeft.add(axis);
    }
    else if (edge == RectangleEdge.RIGHT) {
        this.axesAtRight.add(axis);
    }
}
 
Example 5
Source File: CategoryLabelPositions.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the category label position specification for an axis at the
 * given location.
 *
 * @param edge  the axis location.
 *
 * @return The category label position specification.
 */
public CategoryLabelPosition getLabelPosition(RectangleEdge edge) {
    CategoryLabelPosition result = null;
    if (edge == RectangleEdge.TOP) {
        result = this.positionForAxisAtTop;
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result = this.positionForAxisAtBottom;
    }
    else if (edge == RectangleEdge.LEFT) {
        result = this.positionForAxisAtLeft;
    }
    else if (edge == RectangleEdge.RIGHT) {
        result = this.positionForAxisAtRight;
    }
    return result;
}
 
Example 6
Source File: Plot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adjusts the supplied x-value.
 *
 * @param x  the x-value.
 * @param w1  width 1.
 * @param w2  width 2.
 * @param edge  the edge (left or right).
 *
 * @return The adjusted x-value.
 */
protected double getRectX(double x, double w1, double w2,
                          RectangleEdge edge) {

    double result = x;
    if (edge == RectangleEdge.LEFT) {
        result = result + w1;
    }
    else if (edge == RectangleEdge.RIGHT) {
        result = result + w2;
    }
    return result;

}
 
Example 7
Source File: AxisState.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Moves the cursor outwards by the specified number of units.
 *
 * @param units  the units.
 * @param edge  the edge.
 */
public void moveCursor(double units, RectangleEdge edge) {
    if (edge == RectangleEdge.TOP) {
        cursorUp(units);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        cursorDown(units);
    }
    else if (edge == RectangleEdge.LEFT) {
        cursorLeft(units);
    }
    else if (edge == RectangleEdge.RIGHT) {
        cursorRight(units);
    }
}
 
Example 8
Source File: AxisSpace.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures there is a minimum amount of space at the edge corresponding to
 * the specified axis location.
 *
 * @param space  the space.
 * @param edge  the location.
 */
public void ensureAtLeast(double space, RectangleEdge edge) {
    if (edge == RectangleEdge.TOP) {
        if (this.top < space) {
            this.top = space;
        }
    }
    else if (edge == RectangleEdge.BOTTOM) {
        if (this.bottom < space) {
            this.bottom = space;
        }
    }
    else if (edge == RectangleEdge.LEFT) {
        if (this.left < space) {
            this.left = space;
        }
    }
    else if (edge == RectangleEdge.RIGHT) {
        if (this.right < space) {
            this.right = space;
        }
    }
    else {
        throw new IllegalStateException(
            "AxisSpace.ensureAtLeast(): unrecognised AxisLocation."
        );
    }
}
 
Example 9
Source File: ImageTitle.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param area  the area allocated for the title.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area) {
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
        drawHorizontal(g2, area);
    }
    else if (position == RectangleEdge.LEFT
                 || position == RectangleEdge.RIGHT) {
        drawVertical(g2, area);
    }
    else {
        throw new RuntimeException("Invalid title position.");
    }
}
 
Example 10
Source File: AxisState.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Moves the cursor outwards by the specified number of units.
 *
 * @param units  the units.
 * @param edge  the edge.
 */
public void moveCursor(double units, RectangleEdge edge) {
    if (edge == RectangleEdge.TOP) {
        cursorUp(units);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        cursorDown(units);
    }
    else if (edge == RectangleEdge.LEFT) {
        cursorLeft(units);
    }
    else if (edge == RectangleEdge.RIGHT) {
        cursorRight(units);
    }
}
 
Example 11
Source File: TextTitle.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a the title vertically within the specified area.  This method
 * will be called from the {@link #draw(Graphics2D, Rectangle2D) draw}
 * method.
 *
 * @param g2  the graphics device.
 * @param area  the area for the title.
 */
protected void drawVertical(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlockAnchor anchor = null;
    float y = 0.0f;
    VerticalAlignment verticalAlignment = getVerticalAlignment();
    if (verticalAlignment == VerticalAlignment.TOP) {
        y = (float) titleArea.getY();
        anchor = TextBlockAnchor.TOP_RIGHT;
    }
    else if (verticalAlignment == VerticalAlignment.BOTTOM) {
        y = (float) titleArea.getMaxY();
        anchor = TextBlockAnchor.TOP_LEFT;
    }
    else if (verticalAlignment == VerticalAlignment.CENTER) {
        y = (float) titleArea.getCenterY();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float x = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.LEFT) {
        x = (float) titleArea.getX();
    }
    else if (position == RectangleEdge.RIGHT) {
        x = (float) titleArea.getMaxX();
        if (verticalAlignment == VerticalAlignment.TOP) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        }
        else if (verticalAlignment == VerticalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        }
        else if (verticalAlignment == VerticalAlignment.BOTTOM) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        }
    }
    this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
}
 
Example 12
Source File: AxisState.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Moves the cursor outwards by the specified number of units.
 *
 * @param units  the units.
 * @param edge  the edge.
 */
public void moveCursor(double units, RectangleEdge edge) {
    if (edge == RectangleEdge.TOP) {
        cursorUp(units);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        cursorDown(units);
    }
    else if (edge == RectangleEdge.LEFT) {
        cursorLeft(units);
    }
    else if (edge == RectangleEdge.RIGHT) {
        cursorRight(units);
    }
}
 
Example 13
Source File: StandardBarPainter.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a shadow for the bar.
 *
 * @param bar  the bar shape.
 * @param xOffset  the x-offset for the shadow.
 * @param yOffset  the y-offset for the shadow.
 * @param base  the edge that is the base of the bar.
 * @param pegShadow  peg the shadow to the base?
 *
 * @return A rectangle for the shadow.
 */
private Rectangle2D createShadow(RectangularShape bar, double xOffset,
        double yOffset, RectangleEdge base, boolean pegShadow) {
    double x0 = bar.getMinX();
    double x1 = bar.getMaxX();
    double y0 = bar.getMinY();
    double y1 = bar.getMaxY();
    if (base == RectangleEdge.TOP) {
        x0 += xOffset;
        x1 += xOffset;
        if (!pegShadow) {
            y0 += yOffset;
        }
        y1 += yOffset;
    }
    else if (base == RectangleEdge.BOTTOM) {
        x0 += xOffset;
        x1 += xOffset;
        y0 += yOffset;
        if (!pegShadow) {
            y1 += yOffset;
        }
    }
    else if (base == RectangleEdge.LEFT) {
        if (!pegShadow) {
            x0 += xOffset;
        }
        x1 += xOffset;
        y0 += yOffset;
        y1 += yOffset;
    }
    else if (base == RectangleEdge.RIGHT) {
        x0 += xOffset;
        if (!pegShadow) {
            x1 += xOffset;
        }
        y0 += yOffset;
        y1 += yOffset;
    }
    return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
}
 
Example 14
Source File: CategoryAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a temporary list of ticks that can be used when drawing the axis.
 *
 * @param g2  the graphics device (used to get font measurements).
 * @param state  the axis state.
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
@Override
public List refreshTicks(Graphics2D g2, AxisState state, 
        Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = plot.getCategoriesForAxis(this);
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position
                = this.categoryLabelPositions.getLabelPosition(edge);
        float r = this.maximumCategoryLabelWidthRatio;
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea,
                    edge);
        }
        else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            }
            else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();
            g2.setFont(getTickLabelFont(category));
            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label,
                        position, g2));
            }
            else if (edge == RectangleEdge.LEFT
                    || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label,
                        position, g2));
            }
            Tick tick = new CategoryTick(category, label,
                    position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;

}
 
Example 15
Source File: ImageTitle.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the title (and plot) should be
 *                   drawn.
 *
 * @return The size of the area used by the title.
 */
protected Size2D drawVertical(Graphics2D g2, Rectangle2D chartArea) {

    double startX;
    double topSpace = 0.0;
    double bottomSpace = 0.0;
    double leftSpace = 0.0;
    double rightSpace = 0.0;

    double w = getWidth();
    double h = getHeight();

    RectangleInsets padding = getPadding();
    if (padding != null) {
        topSpace = padding.calculateTopOutset(h);
        bottomSpace = padding.calculateBottomOutset(h);
        leftSpace = padding.calculateLeftOutset(w);
        rightSpace = padding.calculateRightOutset(w);
    }

    if (getPosition() == RectangleEdge.LEFT) {
        startX = chartArea.getX() + leftSpace;
    }
    else {
        startX = chartArea.getMaxX() - rightSpace - w;
    }

    // what is our alignment?
    VerticalAlignment alignment = getVerticalAlignment();
    double startY = 0.0;
    if (alignment == VerticalAlignment.CENTER) {
        startY = chartArea.getMinY() + topSpace
                 + chartArea.getHeight() / 2.0 - h / 2.0;
    }
    else if (alignment == VerticalAlignment.TOP) {
        startY = chartArea.getMinY() + topSpace;
    }
    else if (alignment == VerticalAlignment.BOTTOM) {
        startY = chartArea.getMaxY() - bottomSpace - h;
    }

    g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h,
            null);

    return new Size2D(chartArea.getWidth() + leftSpace + rightSpace,
        h + topSpace + bottomSpace);

}
 
Example 16
Source File: Plot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves a domain axis location for a given plot orientation.
 *
 * @param location  the location (<code>null</code> not permitted).
 * @param orientation  the orientation (<code>null</code> not permitted).
 *
 * @return The edge (never <code>null</code>).
 */
public static RectangleEdge resolveDomainAxisLocation(
        AxisLocation location, PlotOrientation orientation) {

    ParamChecks.nullNotPermitted(location, "location");
    ParamChecks.nullNotPermitted(orientation, "orientation");

    RectangleEdge result = null;
    if (location == AxisLocation.TOP_OR_RIGHT) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            result = RectangleEdge.RIGHT;
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            result = RectangleEdge.TOP;
        }
    }
    else if (location == AxisLocation.TOP_OR_LEFT) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            result = RectangleEdge.LEFT;
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            result = RectangleEdge.TOP;
        }
    }
    else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            result = RectangleEdge.RIGHT;
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            result = RectangleEdge.BOTTOM;
        }
    }
    else if (location == AxisLocation.BOTTOM_OR_LEFT) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            result = RectangleEdge.LEFT;
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            result = RectangleEdge.BOTTOM;
        }
    }
    // the above should cover all the options...
    if (result == null) {
        throw new IllegalStateException("resolveDomainAxisLocation()");
    }
    return result;

}
 
Example 17
Source File: StandardXYBarPainter.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a shadow for the bar.
 *
 * @param bar  the bar shape.
 * @param xOffset  the x-offset for the shadow.
 * @param yOffset  the y-offset for the shadow.
 * @param base  the edge that is the base of the bar.
 * @param pegShadow  peg the shadow to the base?
 *
 * @return A rectangle for the shadow.
 */
private Rectangle2D createShadow(RectangularShape bar, double xOffset,
        double yOffset, RectangleEdge base, boolean pegShadow) {
    double x0 = bar.getMinX();
    double x1 = bar.getMaxX();
    double y0 = bar.getMinY();
    double y1 = bar.getMaxY();
    if (base == RectangleEdge.TOP) {
        x0 += xOffset;
        x1 += xOffset;
        if (!pegShadow) {
            y0 += yOffset;
        }
        y1 += yOffset;
    }
    else if (base == RectangleEdge.BOTTOM) {
        x0 += xOffset;
        x1 += xOffset;
        y0 += yOffset;
        if (!pegShadow) {
            y1 += yOffset;
        }
    }
    else if (base == RectangleEdge.LEFT) {
        if (!pegShadow) {
            x0 += xOffset;
        }
        x1 += xOffset;
        y0 += yOffset;
        y1 += yOffset;
    }
    else if (base == RectangleEdge.RIGHT) {
        x0 += xOffset;
        if (!pegShadow) {
            x1 += xOffset;
        }
        y0 += yOffset;
        y1 += yOffset;
    }
    return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
}
 
Example 18
Source File: CyclicNumberAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the tick marks and labels.
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the plot area.
 * @param dataArea  the area inside the axes.
 * @param edge  the side on which the axis is displayed.
 *
 * @return The axis state.
 */
@Override
protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor,
        Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge) {
    this.internalMarkerWhenTicksOverlap = false;
    AxisState ret = super.drawTickMarksAndLabels(g2, cursor, plotArea,
            dataArea, edge);

    // continue and separate the labels only if necessary
    if (!this.internalMarkerWhenTicksOverlap) {
        return ret;
    }

    double ol;
    FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
    if (isVerticalTickLabels()) {
        ol = fm.getMaxAdvance();
    }
    else {
        ol = fm.getHeight();
    }

    double il = 0;
    if (isTickMarksVisible()) {
        float xx = (float) valueToJava2D(getRange().getUpperBound(),
                dataArea, edge);
        Line2D mark = null;
        g2.setStroke(getTickMarkStroke());
        g2.setPaint(getTickMarkPaint());
        if (edge == RectangleEdge.LEFT) {
            mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
        }
        else if (edge == RectangleEdge.RIGHT) {
            mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
        }
        else if (edge == RectangleEdge.TOP) {
            mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
        }
        g2.draw(mark);
    }
    return ret;
}
 
Example 19
Source File: CategoryAxis3D.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Java 2D coordinate for a category.
 *
 * @param anchor  the anchor point.
 * @param category  the category index.
 * @param categoryCount  the category count.
 * @param area  the data area.
 * @param edge  the location of the axis.
 *
 * @return The coordinate.
 */
@Override
public double getCategoryJava2DCoordinate(CategoryAnchor anchor, 
        int category, int categoryCount, Rectangle2D area, 
        RectangleEdge edge) {

    double result = 0.0;
    Rectangle2D adjustedArea = area;
    CategoryPlot plot = (CategoryPlot) getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof Effect3D) {
        Effect3D e3D = (Effect3D) renderer;
        double adjustedX = area.getMinX();
        double adjustedY = area.getMinY();
        double adjustedW = area.getWidth() - e3D.getXOffset();
        double adjustedH = area.getHeight() - e3D.getYOffset();

        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
            adjustedY += e3D.getYOffset();
        }
        else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
            adjustedX += e3D.getXOffset();
        }
        adjustedArea = new Rectangle2D.Double(adjustedX, adjustedY,
                adjustedW, adjustedH);
    }

    if (anchor == CategoryAnchor.START) {
        result = getCategoryStart(category, categoryCount, adjustedArea,
                edge);
    }
    else if (anchor == CategoryAnchor.MIDDLE) {
        result = getCategoryMiddle(category, categoryCount, adjustedArea,
                edge);
    }
    else if (anchor == CategoryAnchor.END) {
        result = getCategoryEnd(category, categoryCount, adjustedArea,
                edge);
    }
    return result;

}
 
Example 20
Source File: NumberAxis3D.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the axis on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the area for drawing the axes and data.
 * @param dataArea  the area for drawing the data (a subset of the
 *                  plotArea).
 * @param edge  the axis location.
 * @param plotState  collects information about the plot (<code>null</code>
 *                   permitted).
 *
 * @return The updated cursor value.
 */
@Override
public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea,
        Rectangle2D dataArea, RectangleEdge edge,
        PlotRenderingInfo plotState) {

    // if the axis is not visible, don't draw it...
    if (!isVisible()) {
        AxisState state = new AxisState(cursor);
        // even though the axis is not visible, we need ticks for the
        // gridlines...
        List ticks = refreshTicks(g2, state, dataArea, edge);
        state.setTicks(ticks);
        return state;
    }

    // calculate the adjusted data area taking into account the 3D effect...
    double xOffset = 0.0;
    double yOffset = 0.0;
    Plot plot = getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        CategoryItemRenderer r = cp.getRenderer();
        if (r instanceof Effect3D) {
            Effect3D e3D = (Effect3D) r;
            xOffset = e3D.getXOffset();
            yOffset = e3D.getYOffset();
        }
    }

    double adjustedX = dataArea.getMinX();
    double adjustedY = dataArea.getMinY();
    double adjustedW = dataArea.getWidth() - xOffset;
    double adjustedH = dataArea.getHeight() - yOffset;

    if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
        adjustedY += yOffset;
    }
    else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
        adjustedX += xOffset;
    }
    Rectangle2D adjustedDataArea = new Rectangle2D.Double(adjustedX,
            adjustedY, adjustedW, adjustedH);

    // draw the tick marks and labels...
    AxisState info = drawTickMarksAndLabels(g2, cursor, plotArea,
            adjustedDataArea, edge);

    if (getAttributedLabel() != null) {
        info = drawAttributedLabel(getAttributedLabel(), g2, plotArea, 
                dataArea, edge, info);
    } else {
        info = drawLabel(getLabel(), g2, plotArea, dataArea, edge, info);
    }
    return info;

}