List of usage examples for java.awt.geom RectangularShape getWidth
public abstract double getWidth();
From source file:GraphicsUtil.java
public static Rectangle2D contract(RectangularShape rect, double amountX, double amountY) { return new Rectangle2D.Double(rect.getX() + amountX, rect.getY() + amountY, rect.getWidth() - (2 * amountX), rect.getHeight() - (2 * amountY)); }
From source file:GraphicsUtil.java
public static Rectangle2D expand(RectangularShape rect, double amountX, double amountY) { return new Rectangle2D.Double(rect.getX() - amountX, rect.getY() - amountY, rect.getWidth() + (2 * amountX), rect.getHeight() + (2 * amountY)); }
From source file:ShapeTransform.java
/** * Translates a given shape. Special care is taken to preserve the shape's * original class, if the shape is a rectangle or a line. * /*from w ww.jav a 2 s . c om*/ * @param s * the shape * @param x * the x coordinate where the shape is translated to * @param y * the y coordinate where the shape is translated to * @return the translated shape */ public static Shape translateShape(final Shape s, final double x, final double y) { if (s instanceof RectangularShape) { final RectangularShape rect = (RectangularShape) s; final RectangularShape retval = (RectangularShape) rect.clone(); retval.setFrame(retval.getX() + x, retval.getY() + y, retval.getWidth(), retval.getHeight()); return retval; } if (s instanceof Line2D) { final Line2D line = (Line2D) s; final Line2D retval = (Line2D) line.clone(); retval.setLine(retval.getX1() + x, retval.getY1() + y, retval.getX2() + x, retval.getY2() + y); return retval; } final AffineTransform af = AffineTransform.getTranslateInstance(x, y); return af.createTransformedShape(s); }
From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraRenderer.java
public PseudoSpectraRenderer(Color color, boolean isTransparent) { this.isTransparent = isTransparent; // Set painting color setBasePaint(color);//from w w w . j a va 2 s . c om // Shadow makes fake peaks setShadowVisible(false); // Set the tooltip generator SpectraToolTipGenerator tooltipGenerator = new SpectraToolTipGenerator(); setBaseToolTipGenerator(tooltipGenerator); // We want to paint the peaks using simple color without any gradient // effects setBarPainter(new StandardXYBarPainter() { @Override public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) { super.paintBar(g2, renderer, row, column, new Rectangle2D.Double( bar.getX() + (bar.getWidth() - 2) / 2, bar.getY(), 2, bar.getHeight()), base); } }); }
From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape./*from w w w. ja v a 2s .c om*/ * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double x0 = bar.getMinX(); double x1 = Math.rint(x0 + (bar.getWidth() * a)); double x2 = Math.rint(x0 + (bar.getWidth() * b)); double x3 = Math.rint(x0 + (bar.getWidth() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight()); result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight()); result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight()); result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight()); return result; }
From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape./*from w w w .j a v a 2s . c om*/ * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double y0 = bar.getMinY(); double y1 = Math.rint(y0 + (bar.getHeight() * a)); double y2 = Math.rint(y0 + (bar.getHeight() * b)); double y3 = Math.rint(y0 + (bar.getHeight() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0); result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1); result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2); result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3); return result; }
From source file:com.rapidminer.gui.plotter.charts.RapidXYBarPainter.java
@Override public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {/* w w w. j a v a2 s . c o m*/ Paint itemPaint = renderer.getItemPaint(row, column); Color c0 = null; if (itemPaint instanceof Color) { c0 = (Color) itemPaint; } else { c0 = SwingTools.DARK_BLUE; } // as a special case, if the bar color has alpha == 0, we draw // nothing. if (c0.getAlpha() == 0) { return; } g2.setPaint(c0); g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight())); // draw the outline... if (renderer.isDrawBarOutline()) { Stroke stroke = renderer.getItemOutlineStroke(row, column); Paint paint = renderer.getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } }
From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java
/** * Paints a single bar instance.//from w w w .ja v a 2 s . c o m * * @param g2 * the graphics target. * @param renderer * the renderer. * @param row * the row index. * @param column * the column index. * @param bar * the bar * @param base * indicates which side of the rectangle is the base of the bar. */ @Override public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column, final RectangularShape bar, final RectangleEdge base) { Paint itemPaint = renderer.getItemPaint(row, column); Color c0 = null; if (itemPaint instanceof Color) { c0 = (Color) itemPaint; } else { c0 = SwingTools.DARK_BLUE; } // as a special case, if the bar color has alpha == 0, we draw // nothing. if (c0.getAlpha() == 0) { return; } g2.setPaint(c0); g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight())); // draw the outline... if (renderer.isDrawBarOutline()) { Stroke stroke = renderer.getItemOutlineStroke(row, column); Paint paint = renderer.getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
public void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle, boolean multiline) { Graphics2D g2 = (Graphics2D) g; Font font = g2.getFont();/* w w w .j a v a 2 s. c o m*/ if (angle != 0) { g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle)))); } Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2); Point2D pos = getPoint(bounds, align); double x = pos.getX(); double y = pos.getY() + sSize.getHeight(); switch (align) { case TopCenter: case BottomCenter: case Center: x -= (sSize.getWidth() / 2); break; case TopRight: case MiddleRight: case BottomRight: x -= (sSize.getWidth()); break; case BottomLeft: case MiddleLeft: case TopLeft: break; } if (multiline) { // Create a new LineBreakMeasurer from the paragraph. // It will be cached and re-used. //if (lineMeasurer == null) { AttributedCharacterIterator paragraph = new AttributedString(text).getIterator(); paragraphStart = paragraph.getBeginIndex(); paragraphEnd = paragraph.getEndIndex(); FontRenderContext frc = g2.getFontRenderContext(); lineMeasurer = new LineBreakMeasurer(paragraph, frc); //} // Set break width to width of Component. float breakWidth = (float) bounds.getWidth(); float drawPosY = (float) y; // Set position to the index of the first character in the paragraph. lineMeasurer.setPosition(paragraphStart); // Get lines until the entire paragraph has been displayed. while (lineMeasurer.getPosition() < paragraphEnd) { // Retrieve next layout. A cleverer program would also cache // these layouts until the component is re-sized. TextLayout layout = lineMeasurer.nextLayout(breakWidth); // Compute pen x position. If the paragraph is right-to-left we // will align the TextLayouts to the right edge of the panel. // Note: this won't occur for the English text in this sample. // Note: drawPosX is always where the LEFT of the text is placed. float drawPosX = layout.isLeftToRight() ? (float) x : (float) x + breakWidth - layout.getAdvance(); // Move y-coordinate by the ascent of the layout. drawPosY += layout.getAscent(); // Draw the TextLayout at (drawPosX, drawPosY). layout.draw(g2, drawPosX, drawPosY); // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); } } else { g2.drawString(text, (float) x, (float) y); } g2.setFont(font); }
From source file:org.jcurl.demo.tactics.old.MenuView.java
private void pan(final double rx, final double ry, final int dt) { if (getModel() == null) return;/*from w ww . ja v a 2s .c om*/ final RectangularShape src = getModel().getZoom(); src.setFrame(src.getX() + src.getWidth() * rx, src.getY() + src.getHeight() * ry, src.getWidth(), src.getHeight()); zoom(src, dt); }