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

The following examples show how to use java.awt.geom.Rectangle2D#getY() . 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: OpenGL.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a string in perspective in the current color, with the given font, at the given position
 *
 * @param string
 *            the string to draw
 * @param font
 *            the font to use
 * @param x,y,z
 *            the coordinates
 * @param scale
 *            the scale to apply
 */
public void perspectiveText(final String string, final Font font, final double x, final double y, final double z,
		final GamaPoint anchor) {
	final int fontSize = computeFontSize(font.getSize());
	final TextRenderer r = fontCache.get(font, fontSize);
	if (r == null) { return; }

	if (getCurrentColor() != null) {
		r.setColor(getCurrentColor());
	}
	r.begin3DRendering();
	final Rectangle2D bounds = r.getBounds(string);

	final float ratio = (float) ratios.y;
	final float scale = 1f / ratio / textSizeMultiplier;

	final double curX = x - bounds.getWidth() * scale * anchor.x;
	final double curY = y + bounds.getY() * scale * anchor.y;

	r.draw3D(string, (float) curX, (float) curY, (float) (z + currentZTranslation), scale);
	r.flush();
	r.end3DRendering();
}
 
Example 2
Source File: ChartEntity.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a string containing the coordinates (x1, y1, x2, y2) for a given
 * rectangle.  This string is intended for use in an image map.
 *
 * @param rectangle  the rectangle (<code>null</code> not permitted).
 *
 * @return Upper left and lower right corner of a rectangle.
 */
private String getRectCoords(Rectangle2D rectangle) {
    ParamChecks.nullNotPermitted(rectangle, "rectangle");
    int x1 = (int) rectangle.getX();
    int y1 = (int) rectangle.getY();
    int x2 = x1 + (int) rectangle.getWidth();
    int y2 = y1 + (int) rectangle.getHeight();
    //      fix by rfuller
    if (x2 == x1) {
        x2++;
    }
    if (y2 == y1) {
        y2++;
    }
    //      end fix by rfuller
    return x1 + "," + y1 + "," + x2 + "," + y2;
}
 
Example 3
Source File: GlyphPainter2.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Paint the glyphs for the given view.  This is implemented
 * to only render if the Graphics is of type Graphics2D which
 * is required by TextLayout (and this should be the case if
 * running on the JDK).
 */
public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
    if (g instanceof Graphics2D) {
        Rectangle2D alloc = a.getBounds2D();
        Graphics2D g2d = (Graphics2D)g;
        float y = (float) alloc.getY() + layout.getAscent() + layout.getLeading();
        float x = (float) alloc.getX();
        if( p0 > v.getStartOffset() || p1 < v.getEndOffset() ) {
            try {
                //TextLayout can't render only part of it's range, so if a
                //partial range is required, add a clip region.
                Shape s = v.modelToView(p0, Position.Bias.Forward,
                                        p1, Position.Bias.Backward, a);
                Shape savedClip = g.getClip();
                g2d.clip(s);
                layout.draw(g2d, x, y);
                g.setClip(savedClip);
            } catch (BadLocationException e) {}
        } else {
            layout.draw(g2d, x, y);
        }
    }
}
 
Example 4
Source File: SearchComboBoxPainter.java    From cuba with Apache License 2.0 6 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.171875f, 0.34375f, 0.4815341f, 0.6193182f, 0.8096591f, 1.0f},
            new Color[]{color10,
                    decodeColor(color10, color11, 0.5f),
                    color11,
                    decodeColor(color11, color12, 0.5f),
                    color12,
                    decodeColor(color12, color13, 0.5f),
                    color13});
}
 
Example 5
Source File: NamedProgressBarRegionPainter.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private Paint decodeGradient2(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.038709678f, 0.05967742f, 0.08064516f, 0.23709677f, 0.3935484f, 0.41612905f, 0.43870968f, 0.67419356f, 0.90967745f, 0.91451615f, 0.91935486f},
            new Color[]{color3,
                    decodeColor(color3, color4, 0.5f),
                    color4,
                    decodeColor(color4, color5, 0.5f),
                    color5,
                    decodeColor(color5, color6, 0.5f),
                    color6,
                    decodeColor(color6, color7, 0.5f),
                    color7,
                    decodeColor(color7, color8, 0.5f),
                    color8});
}
 
Example 6
Source File: NamedComboBoxPainter.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private Paint decodeGradient8(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.171875f, 0.34375f, 0.4815341f, 0.6193182f, 0.8096591f, 1.0f},
            new Color[]{(Color) componentColors[4],
                    decodeColor((Color) componentColors[4], (Color) componentColors[5], 0.5f),
                    (Color) componentColors[5],
                    decodeColor((Color) componentColors[5], (Color) componentColors[6], 0.5f),
                    (Color) componentColors[6],
                    decodeColor((Color) componentColors[6], (Color) componentColors[7], 0.5f),
                    (Color) componentColors[7]});
}
 
Example 7
Source File: OverviewVertex.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Accessor for the Y Coordinate
 * 
 * @return The Y Coordinate
 */
public int getY() {
	Rectangle2D bounds = GraphConstants.getBounds(getAttributes());

	if (bounds != null) {
		return (int) bounds.getY();
	}
	return _initY;

}
 
Example 8
Source File: CaretFloatingPointAPITest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paint(Graphics g) {

    if (component == null) {
        return;
    }

    int dot = getDot();
    Rectangle2D r = null;
    try {
        r = component.modelToView2D(dot);
    } catch (BadLocationException e) {
        return;
    }

    if (r == null) {
        return;
    }

    Rectangle2D cr = getCaretRectangle(r);
    repaint(cr.getBounds());

    g.setColor(component.getCaretColor());
    float cx = (float) cr.getX();
    float cy = (float) cr.getY();
    float cw = (float) cr.getWidth();
    float ch = (float) cr.getHeight();
    float c = cx + cw / 2;

    Graphics2D g2d = (Graphics2D) g;
    g2d.draw(new Line2D.Float(c, cy, c, cy + ch));
    g2d.draw(new Line2D.Float(cx, cy, cx + cw, cy));
    g2d.draw(new Line2D.Float(cx, cy + ch, cx + cw, cy + ch));
}
 
Example 9
Source File: AbstractChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the data area for the chart (the area inside the axes) with the current scaling
 * applied (that is, the area as it appears on screen).
 * 
 * @return The scaled data area.
 */

@Override
public Rectangle2D getScreenDataArea() {
	Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
	Insets insets = getInsets();
	double x = dataArea.getX() * this.scaleX + insets.left;
	double y = dataArea.getY() * this.scaleY + insets.top;
	double w = dataArea.getWidth() * this.scaleX;
	double h = dataArea.getHeight() * this.scaleY;
	return new Rectangle2D.Double(x, y, w, h);
}
 
Example 10
Source File: Cardumen_0077_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 * 
 * @param dimensions  the dimensions for the rectangle.
 * @param frame  the frame to align to.
 * @param hAlign  the horizontal alignment.
 * @param vAlign  the vertical alignment.
 * 
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions, 
        Rectangle2D frame, HorizontalAlignment hAlign, 
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();   
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);   
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;   
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();   
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);   
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;   
    }
    
    return new Rectangle2D.Double(x, y, dimensions.width, 
            dimensions.height);
}
 
Example 11
Source File: XYPlotMarker.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    if (viewPoint != null) {
        Shape oldClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        g2.setClip(dataArea);

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Ellipse2D.Double ellipse = new Ellipse2D.Double(viewPoint.getX() - 0.5 * markerSize,
                                                        viewPoint.getY() - 0.5 * markerSize,
                                                        markerSize,
                                                        markerSize);
        g2.setPaint(fillPaint);
        g2.fill(ellipse);
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(ellipse);

        Rectangle2D box = new Rectangle2D.Double(dataArea.getX() + 5, dataArea.getY() + 5, 100, 52);
        g2.setPaint(fillPaint);
        g2.fill(box);
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(box);

        g2.drawString(String.format("x = %.3f", dataPoint.getX()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 20));
        g2.drawString(String.format("y = %.3f", dataPoint.getY()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 40));

        g2.setClip(oldClip);
    }
}
 
Example 12
Source File: Group.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public Rectangle2D translate(Rectangle2D rectangle) {
    double scaleX = getScaleX();
    double scaleY = getScaleY();
    return new Rectangle2D.Double(rectangle.getX() + translate.getX(),
            rectangle.getY() + translate.getY(), rectangle.getWidth()
            * scaleX, rectangle.getHeight() * scaleY);
}
 
Example 13
Source File: TexturePaint.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TexturePaint} object.
 * @param txtr the {@code BufferedImage} object with the texture
 * used for painting
 * @param anchor the {@code Rectangle2D} in user space used to
 * anchor and replicate the texture
 */
public TexturePaint(BufferedImage txtr,
                    Rectangle2D anchor) {
    this.bufImg = txtr;
    this.tx = anchor.getX();
    this.ty = anchor.getY();
    this.sx = anchor.getWidth() / bufImg.getWidth();
    this.sy = anchor.getHeight() / bufImg.getHeight();
}
 
Example 14
Source File: FlowElement.java    From orson-charts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the layout of the elements for the given bounds and 
 * constraints.
 * 
 * @param g2  the graphics target ({@code null} not permitted).
 * @param bounds  the bounds ({@code null} not permitted).
 * @param constraints  the constraints (not used here).
 * 
 * @return A list of positions for the sub-elements. 
 */
@Override
public List<Rectangle2D> layoutElements(Graphics2D g2, Rectangle2D bounds, 
        Map<String, Object> constraints) {
    int elementCount = this.elements.size();
    List<Rectangle2D> result = new ArrayList<>(elementCount);
    int i = 0;
    double x = bounds.getX() + getInsets().left;
    double y = bounds.getY() + getInsets().top;
    while (i < elementCount) {
        // get one row of elements...
        List<ElementInfo> elementsInRow = rowOfElements(i, g2, 
                bounds);
        double height = calcRowHeight(elementsInRow);
        double width = calcRowWidth(elementsInRow, this.hgap);  
        if (this.horizontalAlignment == HAlign.CENTER) {
            x = bounds.getCenterX() - (width / 2.0);
        } else if (this.horizontalAlignment == HAlign.RIGHT) {
            x = bounds.getMaxX() - getInsets().right - width;
        }
        for (ElementInfo elementInfo : elementsInRow) {
            Dimension2D dim = elementInfo.getDimension();
            Rectangle2D position = new Rectangle2D.Double(x, y, 
                    dim.getWidth(), height);
            result.add(position);
            x += position.getWidth() + this.hgap;
        }
        i = i + elementsInRow.size();
        x = bounds.getX() + getInsets().left;
        y += height;
    }
    return result;

}
 
Example 15
Source File: JFreeChart.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 * 
 * @param dimensions
 * @param frame
 * @param hAlign
 * @param vAlign
 * 
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions, 
        Rectangle2D frame, HorizontalAlignment hAlign, 
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();   
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);   
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;   
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();   
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);   
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;   
    }
    
    return new Rectangle2D.Double(x, y, dimensions.width, 
            dimensions.height);
}
 
Example 16
Source File: CaretFloatingPointAPITest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
Rectangle2D getCaretRectangle(Rectangle2D r) {
    int d = 3;
    double cx = r.getX() - d;
    double cy = r.getY();
    double cw = 2 * d;
    double ch = r.getHeight();
    return new Rectangle2D.Double(cx, cy, cw, ch);
}
 
Example 17
Source File: ChartPanel.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies any scaling that is in effect for the chart drawing to the
 * given rectangle.
 *  
 * @param rect  the rectangle.
 * 
 * @return A new scaled rectangle.
 */
public Rectangle2D scale(Rectangle2D rect) {
    Insets insets = getInsets();
    double x = rect.getX() * getScaleX() + insets.left;
    double y = rect.getY() * this.getScaleY() + insets.top;
    double w = rect.getWidth() * this.getScaleX();
    double h = rect.getHeight() * this.getScaleY();
    return new Rectangle2D.Double(x, y, w, h);
}
 
Example 18
Source File: NamedTabbedPaneTabPainter.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private Paint decodeGradient1(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.5f, 1.0f},
            new Color[]{color1,
                    decodeColor(color1, color2, 0.5f),
                    color2});
}
 
Example 19
Source File: Decoration.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void drawTextAndDecorations(Label label,
                            Graphics2D g2d,
                            float x,
                            float y) {

    if (fgPaint == null && bgPaint == null && swapColors == false) {
        drawTextAndEmbellishments(label, g2d, x, y);
    }
    else {
        Paint savedPaint = g2d.getPaint();
        Paint foreground, background;

        if (swapColors) {
            background = fgPaint==null? savedPaint : fgPaint;
            if (bgPaint == null) {
                if (background instanceof Color) {
                    Color bg = (Color)background;
                    // 30/59/11 is standard weights, tweaked a bit
                    int brightness = 33 * bg.getRed()
                        + 53 * bg.getGreen()
                        + 14 * bg.getBlue();
                    foreground = brightness > 18500 ? Color.BLACK : Color.WHITE;
                } else {
                    foreground = Color.WHITE;
                }
            } else {
                foreground = bgPaint;
            }
        }
        else {
            foreground = fgPaint==null? savedPaint : fgPaint;
            background = bgPaint;
        }

        if (background != null) {

            Rectangle2D bgArea = label.getLogicalBounds();
            bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(),
                                        y + (float)bgArea.getY(),
                                        (float)bgArea.getWidth(),
                                        (float)bgArea.getHeight());

            g2d.setPaint(background);
            g2d.fill(bgArea);
        }

        g2d.setPaint(foreground);
        drawTextAndEmbellishments(label, g2d, x, y);
        g2d.setPaint(savedPaint);
    }
}
 
Example 20
Source File: Decoration.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Rectangle2D getVisualBounds(Label label) {

            Rectangle2D visBounds = label.handleGetVisualBounds();

            if (swapColors || bgPaint != null || strikethrough
                        || stdUnderline != null || imUnderline != null) {

                float minX = 0;
                Rectangle2D lb = label.getLogicalBounds();

                float minY = 0, maxY = 0;

                if (swapColors || bgPaint != null) {

                    minY = (float)lb.getY();
                    maxY = minY + (float)lb.getHeight();
                }

                maxY = Math.max(maxY, getUnderlineMaxY(label.getCoreMetrics()));

                Rectangle2D ab = new Rectangle2D.Float(minX, minY, (float)lb.getWidth(), maxY-minY);
                visBounds.add(ab);
            }

            return visBounds;
        }