Java Code Examples for java.awt.geom.Rectangle2D#getWidth()

The following examples show how to use java.awt.geom.Rectangle2D#getWidth() . 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: NamedProgressBarRegionPainter.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private Paint decodeGradient12(Shape s) {
    Rectangle2D bounds = s.getBounds2D();
    float x = (float) bounds.getX();
    float y = (float) bounds.getY();
    float w = (float) bounds.getWidth();
    float h = (float) bounds.getHeight();
    return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
            new float[]{0.0f, 0.20645161f, 0.41290322f, 0.44193548f, 0.47096774f, 0.7354839f, 1.0f},
            new Color[]{color40,
                    decodeColor(color40, color41, 0.5f),
                    color41,
                    decodeColor(color41, color42, 0.5f),
                    color42,
                    decodeColor(color42, color50, 0.5f),
                    color50});
}
 
Example 2
Source File: CyclicNumberAxis.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Selects a tick unit when the axis is displayed horizontally.
 *
 * @param g2  the graphics device.
 * @param drawArea  the drawing area.
 * @param dataArea  the data area.
 * @param edge  the side of the rectangle on which the axis is displayed.
 */
protected void selectHorizontalAutoTickUnit(Graphics2D g2,
        Rectangle2D drawArea, Rectangle2D dataArea, RectangleEdge edge) {

    double tickLabelWidth
        = estimateMaximumTickLabelWidth(g2, getTickUnit());

    // Compute number of labels
    double n = getRange().getLength()
               * tickLabelWidth / dataArea.getWidth();

    setTickUnit(
            (NumberTickUnit) getStandardTickUnits().getCeilingTickUnit(n),
            false, false);

 }
 
Example 3
Source File: MeterPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fills an arc on the dial between the given values.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param minValue  the minimum data value.
 * @param maxValue  the maximum data value.
 * @param paint  the background paint (<code>null</code> not permitted).
 * @param dial  a flag that indicates whether the arc represents the whole
 *              dial.
 */
protected void fillArc(Graphics2D g2, Rectangle2D area,
        double minValue, double maxValue, Paint paint, boolean dial) {

    ParamChecks.nullNotPermitted(paint, "paint");
    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    int joinType = Arc2D.OPEN;
    if (this.shape == DialShape.PIE) {
        joinType = Arc2D.PIE;
    }
    else if (this.shape == DialShape.CHORD) {
        if (dial && this.meterAngle > 180) {
            joinType = Arc2D.CHORD;
        }
        else {
            joinType = Arc2D.PIE;
        }
    }
    else if (this.shape == DialShape.CIRCLE) {
        joinType = Arc2D.PIE;
        if (dial) {
            extent = 360;
        }
    }
    else {
        throw new IllegalStateException("DialShape not recognised.");
    }

    g2.setPaint(paint);
    Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent,
            joinType);
    g2.fill(arc);
}
 
Example 4
Source File: ParallelPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private void drawGrid(Graphics graphics, int pixWidth, int pixHeight) {
	double currentX = 0.0f;
	Graphics2D g = (Graphics2D) graphics;
	int[] columnMapping = getColumnMapping();
	double columnDistance = pixWidth / (double) (columnMapping.length - 1);
	for (int i = 0; i < columnMapping.length; i++) {
		g.setColor(GRID_COLOR);
		if ((i == 0) || (i == columnMapping.length - 1) || (columnMapping.length < 100)) {
			g.drawLine((int) currentX, 0, (int) currentX, pixHeight);
		}
		if (columnMapping.length <= 10) {
			g.setColor(Color.BLACK);
			g.setFont(LABEL_FONT);
			Rectangle2D stringBounds = LABEL_FONT.getStringBounds(this.dataTable.getColumnName(columnMapping[i]),
					g.getFontRenderContext());
			double xPos = currentX;
			if (i == columnMapping.length - 1) {
				xPos -= stringBounds.getWidth();
			}
			g.drawString(this.dataTable.getColumnName(columnMapping[i]), (int) xPos,
					(int) (pixHeight + 2 + stringBounds.getHeight()));
		}
		currentX += columnDistance;
	}
	g.setColor(GRID_COLOR);
	g.drawLine(0, 0, (int) ((columnMapping.length - 1) * columnDistance), 0);
	g.drawLine(0, pixHeight, (int) ((columnMapping.length - 1) * columnDistance), pixHeight);
}
 
Example 5
Source File: BarRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be
 * the minimum x-coordinate for a vertical bar, and the minimum
 * y-coordinate for a horizontal bar.
 *
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 *
 * @return The coordinate.
 */
protected double calculateBarW0(CategoryPlot plot,
                                PlotOrientation orientation,
                                Rectangle2D dataArea,
                                CategoryAxis domainAxis,
                                CategoryItemRendererState state,
                                int row,
                                int column) {
    // calculate bar width...
    double space = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(column, getColumnCount(),
            dataArea, plot.getDomainAxisEdge());
    int seriesCount = state.getVisibleSeriesCount() >= 0
            ? state.getVisibleSeriesCount() : getRowCount();
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin()
                           / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis,
                categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap)
                      + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(),
                dataArea, plot.getDomainAxisEdge()) - state.getBarWidth()
                / 2.0;
    }
    return barW0;
}
 
Example 6
Source File: ModuloAxis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translates a data value to a Java2D value for the first section of the
 * axis.
 *
 * @param value  the value.
 * @param area  the data area.
 * @param edge  the edge along which the axis lies.
 * @param length1  the length of the first section.
 * @param length2  the length of the second section.
 *
 * @return The Java2D coordinate.
 */
private double transStart(double value, Rectangle2D area,
                          RectangleEdge edge,
                          double length1, double length2) {
    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getX() + area.getWidth() * length1 / (length1 + length2);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        min = area.getMaxY();
        max = area.getMaxY() - area.getHeight() * length1
              / (length1 + length2);
    }
    if (isInverted()) {
        return max - ((value - this.displayStart)
            / (this.fixedRange.getUpperBound() - this.displayStart))
            * (max - min);
    }
    else {
        return min + ((value - this.displayStart)
            / (this.fixedRange.getUpperBound() - this.displayStart))
            * (max - min);
    }

}
 
Example 7
Source File: NamedTabbedPaneTabPainter.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private Paint decodeGradient4(Shape s) {
    Rectangle2D bounds = s.getBounds2D();
    float x = (float) bounds.getX();
    float y = (float) bounds.getY();
    float w = (float) bounds.getWidth();
    float h = (float) bounds.getHeight();
    return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
            new float[]{0.0f, 0.1f, 0.2f, 0.6f, 1.0f},
            new Color[]{color7,
                    decodeColor(color7, color8, 0.5f),
                    color8,
                    decodeColor(color8, color9, 0.5f),
                    color9});
}
 
Example 8
Source File: BoxBag.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
public void recalcSize() {
  Rectangle2D r = new Rectangle2D.Double(x, y, 0, 0);
  if (backgroundBox != null)
    r.add(backgroundBox);
  for (int i = 0; i < cells.size(); i++)
    r.add((AbstractBox) (cells.get(i)));
  preferredBounds.setRect(r);
  x = r.getX();
  y = r.getY();
  width = r.getWidth();
  height = r.getHeight();
}
 
Example 9
Source File: ValueAxis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A utility method for determining the height of the tallest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels
 *                  are 'vertical'.
 *
 * @return The height of the tallest tick label.
 */
protected double findMaximumTickLabelHeight(List ticks,
                                            Graphics2D g2,
                                            Rectangle2D drawArea,
                                            boolean vertical) {

    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxHeight = 0.0;
    if (vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(
                    tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.getTop()
                    + insets.getBottom() > maxHeight) {
                maxHeight = labelBounds.getWidth()
                            + insets.getTop() + insets.getBottom();
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz",
                g2.getFontRenderContext());
        maxHeight = metrics.getHeight()
                    + insets.getTop() + insets.getBottom();
    }
    return maxHeight;

}
 
Example 10
Source File: BarRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be
 * the minimum x-coordinate for a vertical bar, and the minimum
 * y-coordinate for a horizontal bar.
 *
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 *
 * @return The coordinate.
 */
protected double calculateBarW0(CategoryPlot plot, 
        PlotOrientation orientation, Rectangle2D dataArea, 
        CategoryAxis domainAxis, CategoryItemRendererState state,
        int row, int column) {
    // calculate bar width...
    double space;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(column, getColumnCount(),
            dataArea, plot.getDomainAxisEdge());
    int seriesCount = state.getVisibleSeriesCount() >= 0
            ? state.getVisibleSeriesCount() : getRowCount();
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin()
                           / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis,
                categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap)
                      + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(),
                dataArea, plot.getDomainAxisEdge()) - state.getBarWidth()
                / 2.0;
    }
    return barW0;
}
 
Example 11
Source File: LevelRenderer.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be
 * the minimum x-coordinate for a vertical bar, and the minimum
 * y-coordinate for a horizontal bar.
 *
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 *
 * @return The coordinate.
 */
protected double calculateBarW0(CategoryPlot plot, 
        PlotOrientation orientation, Rectangle2D dataArea,
        CategoryAxis domainAxis, CategoryItemRendererState state, int row,
        int column) {
    // calculate bar width...
    double space;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(column, getColumnCount(),
            dataArea, plot.getDomainAxisEdge());
    int seriesCount = state.getVisibleSeriesCount();
    if (seriesCount < 0) {
        seriesCount = getRowCount();
    }
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin()
                / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis,
                categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap)
                      + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(),
                dataArea, plot.getDomainAxisEdge()) - state.getBarWidth()
                / 2.0;
    }
    return barW0;
}
 
Example 12
Source File: GraphicComponent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Rectangle2D handleGetVisualBounds() {

        Rectangle2D bounds = graphic.getBounds();

        float width = (float) bounds.getWidth() +
                                 graphicAdvance * (graphicCount-1);

        return new Rectangle2D.Float((float) bounds.getX(),
                                     (float) bounds.getY(),
                                     width,
                                     (float) bounds.getHeight());
    }
 
Example 13
Source File: GeometryUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extends or shrinks a rectangle following the ration of a fixed one.
 * 
 * <p>This keeps the center point of the rectangle fixed.</p>
 * 
 * @param fixed the fixed {@link Rectangle2D} to use for the ratio.
 * @param toScale the {@link Rectangle2D} to adapt to the ratio of the fixed one. 
 * @param doShrink if <code>true</code>, the adapted rectangle is shrinked as 
 *          opposed to extended.
 */
public static void scaleToRatio( Rectangle2D fixed, Rectangle2D toScale, boolean doShrink ) {
    double origWidth = fixed.getWidth();
    double origHeight = fixed.getHeight();
    double toAdaptWidth = toScale.getWidth();
    double toAdaptHeight = toScale.getHeight();

    double scaleWidth = 0;
    double scaleHeight = 0;

    scaleWidth = toAdaptWidth / origWidth;
    scaleHeight = toAdaptHeight / origHeight;
    double scaleFactor;
    if (doShrink) {
        scaleFactor = Math.min(scaleWidth, scaleHeight);
    } else {
        scaleFactor = Math.max(scaleWidth, scaleHeight);
    }

    double newWidth = origWidth * scaleFactor;
    double newHeight = origHeight * scaleFactor;

    double dw = (toAdaptWidth - newWidth) / 2.0;
    double dh = (toAdaptHeight - newHeight) / 2.0;

    double newX = toScale.getX() + dw;
    double newY = toScale.getY() + dh;
    double newW = toAdaptWidth - 2 * dw;
    double newH = toAdaptHeight - 2 * dh;
    toScale.setRect(newX, newY, newW, newH);
}
 
Example 14
Source File: BarRenderer3D.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot,
        Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // highlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX()
                + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(),
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}
 
Example 15
Source File: ImageTitle.java    From buffer_bci 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: Chart_15_PiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws the right labels.
 * 
 * @param keys  the keys.
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param linkArea  the link area.
 * @param maxLabelWidth  the maximum label width.
 * @param state  the state.
 */
protected void drawRightLabels(KeyedValues keys, Graphics2D g2, 
                               Rectangle2D plotArea, Rectangle2D linkArea, 
                               float maxLabelWidth, PiePlotState state) {

    // draw the right labels...
    this.labelDistributor.clear();
    double lGap = plotArea.getWidth() * this.labelGap;
    double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;

    for (int i = 0; i < keys.getItemCount(); i++) {
        String label = this.labelGenerator.generateSectionLabel(
                this.dataset, keys.getKey(i));

        if (label != null) {
            TextBlock block = TextUtilities.createTextBlock(label, 
                    this.labelFont, this.labelPaint, maxLabelWidth, 
                    new G2TextMeasurer(g2));
            TextBox labelBox = new TextBox(block);
            labelBox.setBackgroundPaint(this.labelBackgroundPaint);
            labelBox.setOutlinePaint(this.labelOutlinePaint);
            labelBox.setOutlineStroke(this.labelOutlineStroke);
            labelBox.setShadowPaint(this.labelShadowPaint);
            labelBox.setInteriorGap(this.labelPadding);
            double theta = Math.toRadians(keys.getValue(i).doubleValue());
            double baseY = state.getPieCenterY() 
                          - Math.sin(theta) * verticalLinkRadius;
            double hh = labelBox.getHeight(g2);
            this.labelDistributor.addPieLabelRecord(new PieLabelRecord(
                    keys.getKey(i), theta, baseY, labelBox, hh,
                    lGap / 2.0 + lGap / 2.0 * Math.cos(theta), 
                    0.9 + getExplodePercent(keys.getKey(i))));
        }
    }
    this.labelDistributor.distributeLabels(plotArea.getMinY(), 
            plotArea.getHeight());
    for (int i = 0; i < this.labelDistributor.getItemCount(); i++) {
        drawRightLabel(g2, state, 
                this.labelDistributor.getPieLabelRecord(i));
    }

}
 
Example 17
Source File: jMutRepair_0020_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 18
Source File: DialValueIndicator.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // the indicator bounds is calculated from the templateValue (which
    // determines the minimum size), the maxTemplateValue (which, if
    // specified, provides a maximum size) and the actual value
    FontMetrics fm = g2.getFontMetrics(this.font);
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);

    // calculate the bounds of the template value
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
    double minW = tb.getWidth();
    double minH = tb.getHeight();

    double maxW = Double.MAX_VALUE;
    double maxH = Double.MAX_VALUE;
    if (this.maxTemplateValue != null) {
        s = this.formatter.format(this.maxTemplateValue);
        tb = TextUtilities.getTextBounds(s, g2, fm);
        maxW = Math.max(tb.getWidth(), minW);
        maxH = Math.max(tb.getHeight(), minH);
    }
    double w = fixToRange(valueBounds.getWidth(), minW, maxW);
    double h = fixToRange(valueBounds.getHeight(), minH, maxH);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h),
            pt.getX(), pt.getY(), this.frameAnchor);

    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);

    // now find the text anchor point
    Shape savedClip = g2.getClip();
    g2.clip(fb);

    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(),
            (float) pt2.getY(), this.textAnchor);
    g2.setClip(savedClip);

}
 
Example 19
Source File: ZoomHandlerFX.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
private double percentW(double x, Rectangle2D r) {
    return (x - r.getMinX()) / r.getWidth();
}
 
Example 20
Source File: GEFComponent.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
private Rectangle2D translate(Rectangle2D rectangle) {
    return new Rectangle2D.Double(translate(rectangle.getX()),
            translate(rectangle.getY()), rectangle.getWidth() * zoom,
            rectangle.getHeight() * zoom);
}