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

The following examples show how to use org.jfree.ui.RectangleEdge#BOTTOM . 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: 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 3
Source File: ValueAxis.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the anchor point for a tick label.
 *
 * @param tick  the tick.
 * @param cursor  the cursor.
 * @param dataArea  the data area.
 * @param edge  the edge on which the axis is drawn.
 *
 * @return The x and y coordinates of the anchor point.
 */
protected float[] calculateAnchorPoint(ValueTick tick, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {

    RectangleInsets insets = getTickLabelInsets();
    float[] result = new float[2];
    if (edge == RectangleEdge.TOP) {
        result[0] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
        result[1] = (float) (cursor - insets.getBottom() - 2.0);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result[0] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
        result[1] = (float) (cursor + insets.getTop() + 2.0);
    }
    else if (edge == RectangleEdge.LEFT) {
        result[0] = (float) (cursor - insets.getLeft() - 2.0);
        result[1] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
    }
    else if (edge == RectangleEdge.RIGHT) {
        result[0] = (float) (cursor + insets.getRight() + 2.0);
        result[1] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
    }
    return result;
}
 
Example 4
Source File: LogarithmicAxisTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test of valueToJava2D method.
 */
@Test
public void testValueToJava2D() {
    Rectangle2D plotArea = new Rectangle2D.Double(22, 33, 500, 500);
    RectangleEdge edge = RectangleEdge.BOTTOM;

    // set axis bounds to be both greater than 1
    this.axis.setRange(10, 20);
    checkPointsToJava2D(edge, plotArea);

    // check for bounds interval that includes 1
    this.axis.setRange(0.5, 10);
    checkPointsToJava2D(edge, plotArea);

    // check for bounds interval that includes 1
    this.axis.setRange(0.2, 20);
    checkPointsToJava2D(edge, plotArea);

    // check for both bounds smaller than 1
    this.axis.setRange(0.2, 0.7);
    checkPointsToJava2D(edge, plotArea);
}
 
Example 5
Source File: CategoryAxis.java    From opensim-gui with Apache License 2.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.
 */
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 6
Source File: CategoryAxis.java    From ECG-Viewer with GNU General Public License v2.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 7
Source File: Axis.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws an axis line at the current cursor position and edge.
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    Line2D axisLine = null;
    double x = dataArea.getX();
    double y = dataArea.getY();
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(x, cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(x, cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, y, cursor, dataArea.getMaxY());
    } else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, y, cursor, dataArea.getMaxY());
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(axisLine);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 8
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
private static RectangleEdge getEdge(EdgeEnum position, RectangleEdge defaultPosition)
{
	RectangleEdge edge = defaultPosition;
	if (position != null)
	{
		switch (position)
		{
			case TOP :
			{
				edge = RectangleEdge.TOP;
				break;
			}
			case BOTTOM :
			{
				edge = RectangleEdge.BOTTOM;
				break;
			}
			case LEFT :
			{
				edge = RectangleEdge.LEFT;
				break;
			}
			case RIGHT :
			{
				edge = RectangleEdge.RIGHT;
				break;
			}
		}
	}
	return edge;
}
 
Example 9
Source File: ImageTitle.java    From SIMVA-SoS with Apache License 2.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: AxisSpace.java    From buffer_bci 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 11
Source File: CyclicNumberAxis.java    From openstock 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 12
Source File: PeriodAxis.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or 
 * bottom of the plot.
 * 
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state, 
                                       Rectangle2D dataArea, 
                                       RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0 = dataArea.getX();
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = RegularTimePeriod.createInstance(
            this.majorTickTimePeriodClass, this.first.getStart(), 
            getTimeZone());
    long t0 = t.getFirstMillisecond(this.calendar);
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond(this.calendar);
    long lastOnAxis = getLast().getLastMillisecond(this.calendar);
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(new Double(t0), "", TextAnchor.CENTER, 
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);  
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 > firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = RegularTimePeriod.createInstance(
                    this.minorTickTimePeriodClass, new Date(t0), 
                    getTimeZone());
            long tt0 = tminor.getFirstMillisecond(this.calendar);
            while (tt0 < t.getLastMillisecond(this.calendar) 
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0, 
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0, 
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0, 
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0, 
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tt0 = tminor.getFirstMillisecond(this.calendar);
            }
        }            
        t = t.next();
        t0 = t.getFirstMillisecond(this.calendar);
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength, 
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength, 
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 13
Source File: CategoryAxis3D.java    From opensim-gui with Apache License 2.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 (<code>null</code> not permitted).
 * @param cursor  the cursor location.
 * @param plotArea  the area within which the axis should be drawn 
 *                  (<code>null</code> not permitted).
 * @param dataArea  the area within which the plot is being drawn 
 *                  (<code>null</code> not permitted).
 * @param edge  the location of the axis (<code>null</code> not permitted).
 * @param plotState  collects information about the plot (<code>null</code>
 *                   permitted).
 * 
 * @return The axis state (never <code>null</code>).
 */
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()) {
        return new AxisState(cursor);
    }

    // calculate the adjusted data area taking into account the 3D effect...
    // this assumes that there is a 3D renderer, all this 3D effect is a 
    // bit of an ugly hack...
    CategoryPlot plot = (CategoryPlot) getPlot();

    Rectangle2D adjustedDataArea = new Rectangle2D.Double();
    if (plot.getRenderer() instanceof Effect3D) {
        Effect3D e3D = (Effect3D) plot.getRenderer();
        double adjustedX = dataArea.getMinX();
        double adjustedY = dataArea.getMinY();
        double adjustedW = dataArea.getWidth() - e3D.getXOffset();
        double adjustedH = dataArea.getHeight() - e3D.getYOffset();

        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
            adjustedY += e3D.getYOffset();
        }
        else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
            adjustedX += e3D.getXOffset();
        }
        adjustedDataArea.setRect(adjustedX, adjustedY, adjustedW, 
                adjustedH);
    }
    else {
        adjustedDataArea.setRect(dataArea);   
    }

    // draw the category labels and axis label
    AxisState state = new AxisState(cursor);
    state = drawCategoryLabels(g2, plotArea, adjustedDataArea, edge, 
            state, plotState);
    state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);

    return state;
    
}
 
Example 14
Source File: Plot.java    From openstock with GNU General Public License v3.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 15
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 16
Source File: StandardBarPainter.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 17
Source File: CategoryAxis3D.java    From buffer_bci with GNU General Public License v3.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 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: ValueAxis.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the axis line, tick marks and tick mark labels.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the plot area.
 * @param dataArea  the data area.
 * @param edge  the edge that the axis is aligned with.
 * 
 * @return The width or height used to draw the axis.
 */
protected AxisState drawTickMarksAndLabels(Graphics2D g2, 
                                           double cursor,
                                           Rectangle2D plotArea,
                                           Rectangle2D dataArea, 
                                           RectangleEdge edge) {
                                          
    AxisState state = new AxisState(cursor);

    if (isAxisLineVisible()) {
        drawAxisLine(g2, cursor, dataArea, edge);
    }

    double ol = getTickMarkOutsideLength();
    double il = getTickMarkInsideLength();

    List ticks = refreshTicks(g2, state, dataArea, edge);
    state.setTicks(ticks);
    g2.setFont(getTickLabelFont());
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        if (isTickLabelsVisible()) {
            g2.setPaint(getTickLabelPaint());
            float[] anchorPoint = calculateAnchorPoint(tick, cursor, 
                    dataArea, edge);
            TextUtilities.drawRotatedString(tick.getText(), g2, 
                    anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), 
                    tick.getAngle(), tick.getRotationAnchor());
        }

        if (isTickMarksVisible()) {
            float xx = (float) valueToJava2D(tick.getValue(), 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);
        }
    }
    
    // need to work out the space used by the tick labels...
    // so we can update the cursor...
    double used = 0.0;
    if (isTickLabelsVisible()) {
        if (edge == RectangleEdge.LEFT) {
            used += findMaximumTickLabelWidth(ticks, g2, plotArea, 
                    isVerticalTickLabels());  
            state.cursorLeft(used);      
        }
        else if (edge == RectangleEdge.RIGHT) {
            used = findMaximumTickLabelWidth(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorRight(used);      
        }
        else if (edge == RectangleEdge.TOP) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorUp(used);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorDown(used);
        }
    }
   
    return state;
}
 
Example 20
Source File: DateTitle.java    From openstock with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new chart title that displays the current date.
 * <p>
 * The date style should be one of:  {@code SHORT},
 * {@code MEDIUM}, {@code LONG} or {@code FULL} (defined
 * in {@code java.util.DateFormat}).
 * <P>
 * For the locale, you can use {@code Locale.getDefault()} for the
 * default locale.
 *
 * @param style  the date style.
 * @param locale  the locale.
 * @param font  the font.
 * @param paint  the text color.
 */
public DateTitle(int style, Locale locale, Font font, Paint paint) {
    this(style, locale, font, paint, RectangleEdge.BOTTOM,
            HorizontalAlignment.RIGHT, VerticalAlignment.CENTER,
            Title.DEFAULT_PADDING);
}