private GeneralPath makeIOPath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); ShapePoint point1 = new ShapePoint((float)bounds.getMinX(), (float)bounds.getMinY()); ShapePoint point2 = new ShapePoint((float)bounds.getMaxX(), (float)bounds.getMinY()); ShapePoint point3 = new ShapePoint((float)bounds.getMaxX(), (float)bounds.getMaxY()); ShapePoint point4 = new ShapePoint((float)bounds.getMinX(), (float)bounds.getMaxY()); float offset = diagram.getCellWidth() / 2; GeneralPath path = new GeneralPath(); path.moveTo(point1.x + offset, point1.y); path.lineTo(point2.x + offset, point2.y); path.lineTo(point3.x - offset, point3.y); path.lineTo(point4.x - offset, point4.y); path.closePath(); return path; }
private GeneralPath makeTrapezoidPath(Diagram diagram, boolean inverted) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); float offset = 0.7f * diagram.getCellWidth(); // fixed slope if (inverted) offset = -offset; ShapePoint ul = new ShapePoint((float)bounds.getMinX() + offset, (float)bounds.getMinY()); ShapePoint ur = new ShapePoint((float)bounds.getMaxX() - offset, (float)bounds.getMinY()); ShapePoint br = new ShapePoint((float)bounds.getMaxX() + offset, (float)bounds.getMaxY()); ShapePoint bl = new ShapePoint((float)bounds.getMinX() - offset, (float)bounds.getMaxY()); ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(ul.x, ul.y); path.lineTo(ur.x, ur.y); path.lineTo(br.x, br.y); path.lineTo(bl.x, bl.y); path.closePath(); return path; }
public void drawCollapsedMarker(int x, int y, int width, int height) { // rectangle int rectangleWidth = MARKER_WIDTH; int rectangleHeight = MARKER_WIDTH; Rectangle rect = new Rectangle(x + (width - rectangleWidth) / 2, y + height - rectangleHeight - 3, rectangleWidth, rectangleHeight); g.draw(rect); // plus inside rectangle Line2D.Double line = new Line2D.Double(rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2); g.draw(line); line = new Line2D.Double(rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY()); g.draw(line); }
private GeneralPath makeDecisionPath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getCenterY()); ShapePoint left = new ShapePoint((float)bounds.getMinX(), (float)pointMid.getY()); ShapePoint right = new ShapePoint((float)bounds.getMaxX(), (float)pointMid.getY()); ShapePoint top = new ShapePoint((float)pointMid.getX(), (float)bounds.getMinY()); ShapePoint bottom = new ShapePoint((float)pointMid.getX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(left.x, left.y); path.lineTo(top.x, top.y); path.lineTo(right.x, right.y); path.lineTo(bottom.x, bottom.y); path.closePath(); return path; }
private GeneralPath makeDocumentPath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); ShapePoint point1 = new ShapePoint((float)bounds.getMinX(), (float)bounds.getMinY()); ShapePoint point2 = new ShapePoint((float)bounds.getMaxX(), (float)bounds.getMinY()); ShapePoint point3 = new ShapePoint((float)bounds.getMaxX(), (float)bounds.getMaxY()); ShapePoint point4 = new ShapePoint((float)bounds.getMinX(), (float)bounds.getMaxY()); ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(point1.x, point1.y); path.lineTo(point2.x, point2.y); path.lineTo(point3.x, point3.y); //int controlDX = diagram.getCellWidth(); //int controlDY = diagram.getCellHeight() / 2; int controlDX = bounds.width / 6; int controlDY = bounds.height / 8; path.quadTo(pointMid.x + controlDX, pointMid.y - controlDY, pointMid.x, pointMid.y); path.quadTo(pointMid.x - controlDX, pointMid.y + controlDY, point4.x, point4.y); path.closePath(); return path; }
private GeneralPath makeEllipsePath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); float xOff = (float) bounds.getWidth() * 0.5f * KAPPA; float yOff = (float) bounds.getHeight() * 0.5f * KAPPA; ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getCenterY()); ShapePoint left = new ShapePoint((float)bounds.getMinX(), (float)pointMid.getY()); ShapePoint right = new ShapePoint((float)bounds.getMaxX(), (float)pointMid.getY()); ShapePoint top = new ShapePoint((float)pointMid.getX(), (float)bounds.getMinY()); ShapePoint bottom = new ShapePoint((float)pointMid.getX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(top.x, top.y); path.curveTo(top.x + xOff, top.y, right.x, right.y - yOff, right.x, right.y); path.curveTo(right.x, right.y + yOff, bottom.x + xOff, bottom.y, bottom.x, bottom.y); path.curveTo(bottom.x - xOff, bottom.y, left.x, left.y + yOff, left.x, left.y); path.curveTo(left.x, left.y - yOff, top.x - xOff, top.y, top.x, top.y); path.closePath(); return path; }
public void paint(Graphics2D g, StateColorMap colorMap) { Rectangle boundary = g.getClipBounds(); if (x > boundary.getMaxX() || x + width < boundary.getMinX()) { // no need to paint if this line isn't displayed return; } // TODO - we need to clip these to the visible states for (LifelineState state : states) { state.paint(g, colorMap); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Rectangle bounds = g.getClipBounds(); int index = 0; for (String name : shortLineNames.keySet()) { int nameWidth = g.getFontMetrics().stringWidth(name); int lineX = lineStep * index; index++; if (bounds.getMaxX() < lineX || bounds.getMinX() > lineX + nameWidth) { continue; } g.setClip(lineX + LINE_LABEL_BOUNDARY, 0, lineStep - +LINE_LABEL_BOUNDARY * 2, getHeight()); g.drawString(name, lineX + LINE_LABEL_BOUNDARY, AXIS_SIZE / 3); g.setClip(null); } } }
private GeneralPath makeStoragePath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); ShapePoint point1 = new ShapePoint((float)bounds.getMinX(), (float)bounds.getMinY()); ShapePoint point2 = new ShapePoint((float)bounds.getMaxX(), (float)bounds.getMinY()); ShapePoint point3 = new ShapePoint((float)bounds.getMaxX(), (float)bounds.getMaxY()); ShapePoint point4 = new ShapePoint((float)bounds.getMinX(), (float)bounds.getMaxY());
/** Calculates the world bounds of the current screen area. */ private ReferencedEnvelope calculateActualBounds() { Point2D p0 = new Point2D.Double(screenArea.getMinX(), screenArea.getMinY()); Point2D p1 = new Point2D.Double(screenArea.getMaxX(), screenArea.getMaxY()); screenToWorld.transform(p0, p0); screenToWorld.transform(p1, p1); return new ReferencedEnvelope( Math.min(p0.getX(), p1.getX()), Math.max(p0.getX(), p1.getX()), Math.min(p0.getY(), p1.getY()), Math.max(p0.getY(), p1.getY()), bounds.getCoordinateReferenceSystem()); }
@Override public Position getNextPosition() { if (symbols > targetSymbolCount || r >= rows) { return null; } attempts++; // System.out.println("Grid position: " + c + ", " + r + ", deltas: " + deltaX + "," + // deltaY + " target area: " + targetArea); position.x = (int) Math.round( targetArea.getMinX() + c * deltaX + random.nextDouble() * deltaX); position.y = (int) Math.round( targetArea.getMinY() + r * deltaY + random.nextDouble() * deltaY); if (randomRotation) { position.rotation = random.nextDouble() * 360; } // System.out.println("Position: " + position); return position; }
if (p.x > rect.getMinX() - 5 && p.x < rect.getMaxX() + 5 || p.y > rect.getMinY() - 5 && p.y < rect.getMaxY() + 5) {
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.black); g2d.setTransform( AffineTransform.getTranslateInstance( -shp.getBounds().getMinX(), -shp.getBounds().getMinY())); g2d.draw(shp); g2d.dispose(); } }
new GeometryClipper( new Envelope( displayArea.getMinX(), displayArea.getMaxX(), displayArea.getMinY(),
double dist = Math.sqrt(Math.pow(deviceBounds.getMaxX() - deviceBounds.getMinX(), 2) + Math.pow(deviceBounds.getMaxY() - deviceBounds.getMinY(), 2)); factor = (int) Math.ceil(dist);
double dist = Math.sqrt(Math.pow(deviceBounds.getMaxX() - deviceBounds.getMinX(), 2) + Math.pow(deviceBounds.getMaxY() - deviceBounds.getMinY(), 2)); factor = (int) Math.ceil(dist);
@Test public void coordinateTransform_MatchingAspectRatioDisabled() throws Exception { MapViewport vp = new MapViewport(false); // world and screen bounds with different aspect ratios final ReferencedEnvelope world = WORLD_1_1; final Rectangle screen = SCREEN_2_1; vp.setBounds(world); vp.setScreenArea(screen); double[] screenXY = { screen.getMinX(), screen.getMinY(), screen.getMaxX(), screen.getMaxY() }; double[] worldXY = new double[screenXY.length]; vp.getScreenToWorld().transform(screenXY, 0, worldXY, 0, screenXY.length / 2); assertEquals(world.getMinX(), worldXY[0], TOL); assertEquals(world.getMaxY(), worldXY[1], TOL); assertEquals(world.getMaxX(), worldXY[2], TOL); assertEquals(world.getMinY(), worldXY[3], TOL); }
@Test public void coordinateTransform_MatchingAspectRatioEnabled() throws Exception { MapViewport vp = new MapViewport(true); // world and screen bounds with different aspect ratios final Rectangle screen = SCREEN_2_1; vp.setBounds(WORLD_1_1); vp.setScreenArea(screen); ReferencedEnvelope actualWorld = vp.getBounds(); double[] screenXY = { screen.getMinX(), screen.getMinY(), screen.getMaxX(), screen.getMaxY() }; double[] worldXY = new double[screenXY.length]; vp.getScreenToWorld().transform(screenXY, 0, worldXY, 0, screenXY.length / 2); assertEquals(actualWorld.getMinX(), worldXY[0], TOL); assertEquals(actualWorld.getMaxY(), worldXY[1], TOL); assertEquals(actualWorld.getMaxX(), worldXY[2], TOL); assertEquals(actualWorld.getMinY(), worldXY[3], TOL); }