List of usage examples for java.awt.geom Rectangle2D getY
public abstract double getY();
From source file:Main.java
public static Rectangle2D.Double fromSheetRect(Rectangle2D r, AffineTransform at) { Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY()); Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY()); Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY()); Point2D.Double pScreen = new Point2D.Double(); Point2D.Double pScreenX = new Point2D.Double(); Point2D.Double pScreenY = new Point2D.Double(); try {/*from ww w. ja v a2 s. c o m*/ at.transform(pSheet, pScreen); at.transform(pSX, pScreenX); at.transform(pSY, pScreenY); } catch (Exception e) { System.err.print(e.getMessage()); } Rectangle2D.Double res = new Rectangle2D.Double(); res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), pScreen.distance(pScreenY)); return res; }
From source file:Main.java
public static Rectangle2D.Double toSheetRect(Rectangle2D r, AffineTransform at) { Point2D.Double pSheet = toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at); Point2D.Double pSheetX = toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at); Point2D.Double pSheetY = toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at); Rectangle2D.Double res = new Rectangle2D.Double(); res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), pSheet.distance(pSheetY)); return res;/*w w w . j a v a 2 s. co m*/ }
From source file:Main.java
/** * Checks, whether the given rectangle1 fully contains rectangle 2 * (even if rectangle 2 has a height or width of zero!). * * @param rect1 the first rectangle.//from w w w . j av a2 s . c o m * @param rect2 the second rectangle. * * @return A boolean. */ public static boolean contains(final Rectangle2D rect1, final Rectangle2D rect2) { final double x0 = rect1.getX(); final double y0 = rect1.getY(); final double x = rect2.getX(); final double y = rect2.getY(); final double w = rect2.getWidth(); final double h = rect2.getHeight(); return ((x >= x0) && (y >= y0) && ((x + w) <= (x0 + rect1.getWidth())) && ((y + h) <= (y0 + rect1.getHeight()))); }
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius, boolean normalize) { Shape shape = generatePolygon(sides, outsideRadius, insideRadius); if (normalize) { Rectangle2D bounds = shape.getBounds2D(); GeneralPath path = new GeneralPath(shape); shape = path// ww w . j a va2s. co m .createTransformedShape(AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY())); } return shape; }
From source file:Main.java
/** * Serialises a <code>Shape</code> object. * * @param shape the shape object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */// ww w . java 2 s . c om public static void writeShape(final Shape shape, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (shape != null) { stream.writeBoolean(false); if (shape instanceof Line2D) { final Line2D line = (Line2D) shape; stream.writeObject(Line2D.class); stream.writeDouble(line.getX1()); stream.writeDouble(line.getY1()); stream.writeDouble(line.getX2()); stream.writeDouble(line.getY2()); } else if (shape instanceof Rectangle2D) { final Rectangle2D rectangle = (Rectangle2D) shape; stream.writeObject(Rectangle2D.class); stream.writeDouble(rectangle.getX()); stream.writeDouble(rectangle.getY()); stream.writeDouble(rectangle.getWidth()); stream.writeDouble(rectangle.getHeight()); } else if (shape instanceof Ellipse2D) { final Ellipse2D ellipse = (Ellipse2D) shape; stream.writeObject(Ellipse2D.class); stream.writeDouble(ellipse.getX()); stream.writeDouble(ellipse.getY()); stream.writeDouble(ellipse.getWidth()); stream.writeDouble(ellipse.getHeight()); } else if (shape instanceof Arc2D) { final Arc2D arc = (Arc2D) shape; stream.writeObject(Arc2D.class); stream.writeDouble(arc.getX()); stream.writeDouble(arc.getY()); stream.writeDouble(arc.getWidth()); stream.writeDouble(arc.getHeight()); stream.writeDouble(arc.getAngleStart()); stream.writeDouble(arc.getAngleExtent()); stream.writeInt(arc.getArcType()); } else if (shape instanceof GeneralPath) { stream.writeObject(GeneralPath.class); final PathIterator pi = shape.getPathIterator(null); final float[] args = new float[6]; stream.writeBoolean(pi.isDone()); while (!pi.isDone()) { final int type = pi.currentSegment(args); stream.writeInt(type); // TODO: could write this to only stream the values // required for the segment type for (int i = 0; i < 6; i++) { stream.writeFloat(args[i]); } stream.writeInt(pi.getWindingRule()); pi.next(); stream.writeBoolean(pi.isDone()); } } else { stream.writeObject(shape.getClass()); stream.writeObject(shape); } } else { stream.writeBoolean(true); } }
From source file:org.ut.biolab.medsavant.client.util.ClientMiscUtils.java
/** * Draws a string centred in the given box. */// ww w. jav a 2 s. com public static void drawCentred(Graphics2D g2, String message, Rectangle2D box) { FontMetrics metrics = g2.getFontMetrics(); Rectangle2D stringBounds = g2.getFont().getStringBounds(message, g2.getFontRenderContext()); float x = (float) (box.getX() + (box.getWidth() - stringBounds.getWidth()) / 2.0); float y = (float) (box.getY() + (box.getHeight() + metrics.getAscent() - metrics.getDescent()) / 2.0); g2.drawString(message, x, y); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static void drawText(Graphics2D g2, Rectangle2D imageArea, LinkedHashMap<Rectangle2D, String> textContentMap, JFreeChart chart) { if (textContentMap == null || textContentMap.size() == 0) { return;/*from ww w . ja va2 s .c om*/ } // for (Entry<Rectangle2D, String> textEntry : textMap.entrySet()) { // Rectangle2D rect = textEntry.getKey(); // String text = textEntry.getValue(); // drawText(g2, imageArea, rect, text, chart); // } Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) { Rectangle2D rect = entry.getKey(); Point2D screenPoint = ChartMaskingUtilities .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, chart); String text = entry.getValue(); if (text == null) { continue; } String[] lines = text.split("\n"); g2.setColor(Color.BLACK); for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15); } // if (rect == selectedTextWrapper) { // FontMetrics fm = g2.getFontMetrics(); // int maxWidth = 0; // int maxHeight = 0; // for (int i = 0; i < lines.length; i++) { // int lineWidth = fm.stringWidth(lines[i]); // if (lineWidth > maxWidth) { // maxWidth = lineWidth; // } // } // maxHeight = 15 * lines.length; // if (maxWidth < 100) { // maxWidth = 100; // } // Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight); // Color fillColor = new Color(250, 250, 50, 30); // g2.setPaint(fillColor); // g2.fill(inputBox); // g2.setColor(Color.ORANGE); // g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight); // // } // g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3); } g2.setColor(oldColor); }
From source file:com.t_oster.visicut.misc.Helper.java
/** * Returns the distance between two Rectangles * @param r first rectangle//from ww w. ja va 2 s.com * @param q second rectangle * @return Distance between two rectangles */ public static double distance(Rectangle2D r, Rectangle2D q) { double qx0 = q.getX(); double qy0 = q.getY(); double qx1 = q.getX() + q.getWidth(); double qy1 = q.getY() + q.getHeight(); double rx0 = r.getX(); double ry0 = r.getY(); double rx1 = r.getX() + r.getWidth(); double ry1 = r.getY() + r.getHeight(); //Check for Overlap if (qx0 <= rx1 && qy0 <= ry1 && rx0 <= qx1 && ry0 <= qy1) { return 0; } double d = 0; if (rx0 > qx1) { d += (rx0 - qx1) * (rx0 - qx1); } else if (qx0 > rx1) { d += (qx0 - rx1) * (qx0 - rx1); } if (ry0 > qy1) { d += (ry0 - qy1) * (ry0 - qy1); } else if (qy0 > ry1) { d += (qy0 - ry1) * (qy0 - ry1); } return Math.sqrt(d); }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0);/*from w w w . jav a 2 s . c o m*/ po.addPoint(0, 10); po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:savant.util.MiscUtils.java
/** * Patterned off GraphPane.drawMessageHelper, draws a string centred in the given box. */// w ww. j av a 2 s. c o m public static void drawMessage(Graphics2D g2, String message, Rectangle2D box) { FontMetrics metrics = g2.getFontMetrics(); Rectangle2D stringBounds = g2.getFont().getStringBounds(message, g2.getFontRenderContext()); float x = (float) (box.getX() + (box.getWidth() - stringBounds.getWidth()) / 2.0); float y = (float) (box.getY() + (box.getHeight() + metrics.getAscent() - metrics.getDescent()) / 2.0); g2.drawString(message, x, y); }