_graphics.setColor(fontColor); final double scale = _graphics.getTransform().getScaleX(); final String str = text.getText(); AffineTransform before = _graphics.getTransform(); _graphics.setTransform(new AffineTransform()); AffineTransform fontTransform = new AffineTransform(); fontTransform.scale(fs, fs); fontTransform.rotate(-ta.getOrientationAngle() * Math.PI / 180); fontTransform.rotate(-ta.getOrientationAngle() * Math.PI / 180); final double yy = bounds.getHeight() + bounds.getY(); Point2D.Double pos = new Point2D.Double(text.getPosition().getX(), text.getPosition().getY()); before.transform(pos, pos); double y = 0; if (ta.getOrientationAngle() == 0) { x = -0.5 * ta.getHorizontalAnchor().getFactor() * bounds.getWidth(); y = 0.5 * ta.getVerticalAnchor().getFactor() * bounds.getHeight() - yy; x = pos.x + x;
private void showMatchedPart(int idx) { Point2D.Double coord = matchedPartCoordinates.get(idx); Dimension treeSize = tjp.getPreferredSize(); JScrollBar horizontal = scroller.getHorizontalScrollBar(); JScrollBar vertical = scroller.getVerticalScrollBar(); int horizontalLength = horizontal.getMaximum() - horizontal.getMinimum(); double x = Math.max(0, (coord.getX() / treeSize.getWidth() * horizontalLength - (scroller.getWidth() / 2.0))); int verticalLength = vertical.getMaximum() - vertical.getMinimum(); double y = Math.max(0, (coord.getY() / treeSize.getHeight() * verticalLength - (scroller.getHeight() / 2.0))); horizontal.setValue((int) x); vertical.setValue((int) y); }
private void paintShapeNode_0_0_0_5(Graphics2D g) { GeneralPath shape5 = new GeneralPath(); shape5.moveTo(4.205356, 9.242575); shape5.lineTo(12.929209, 9.242575); g.setPaint(new LinearGradientPaint(new Point2D.Double(-13.97996711730957, 7.864083766937256), new Point2D.Double(-2.027459144592285, 7.864083766937256), new float[] {0.0f,1.0f}, new Color[] {new Color(92, 184, 255, 255),new Color(213, 239, 255, 255)}, MultipleGradientPaint.CycleMethod.NO_CYCLE, MultipleGradientPaint.ColorSpaceType.SRGB, new AffineTransform(0.6166481971740723f, 0.0f, 0.0f, 0.8346183896064758f, 6.707635402679443f, 20.285995483398438f))); g.fill(shape5); g.setPaint(new Color(0, 119, 203, 255)); g.setStroke(new BasicStroke(0.17935055f,0,2,4.0f,null,0.0f)); g.draw(shape5); }
private static final Color BACKGROUND = new Color(0, 0, 0, 0); private static final Color INITIAL_COLOUR = Color.BLACK; private static final int BORDER_WIDTH = 5; private static final Color LINE_DRAWING_COLOR = new Color(200, 200, 255); private static final Color LINE_COLOR = Color.blue; private static final Stroke DRAWING_LINE_STROKE = new BasicStroke((float)BORDER_WIDTH); public static final int ELLIPSE_DIAMETER = 10; private MouseState mouseState = MouseState.IDLE; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke initStroke = g2.getStroke(); g2.setStroke(DRAWING_LINE_STROKE); if (mouseState == MouseState.DRAGGING && drawingLine != null) { g2.setColor(LINE_DRAWING_COLOR); g2.draw(drawingLine); g2.setColor(LINE_COLOR); for (List<Ellipse2D> ellipses : ellipseList) { Point2D p2d1 = new Point2D.Double(ellipses.get(0).getCenterX(), ellipses.get(0).getCenterY()); Point2D p2d2 = new Point2D.Double(ellipses.get(1).getCenterX(), ellipses.get(1).getCenterY()); Line2D line = new Line2D.Double(p2d1, p2d2); g2.draw(line); g.drawImage(bufImage, 0, 0, this); g2.setStroke(initStroke);
double xTickSpace = stylerCategory.getPlotContentSize() * getBounds().getWidth(); double xLeftMargin = Utils.getTickStartOffset(getBounds().getWidth(), xTickSpace); double yTickSpace = stylerCategory.getPlotContentSize() * getBounds().getHeight(); double yTopMargin = Utils.getTickStartOffset(getBounds().getHeight(), yTickSpace); steppedPath = new ArrayList<Point2D.Double>(); steppedReturnPath = new ArrayList<Point2D.Double>(); steppedPath.add(new Point2D.Double(xOffset, yCenter)); } else if (stylerCategory.isStacked()) { steppedPath.add(new Point2D.Double(xOffset, yCenter)); steppedPath.add(new Point2D.Double(xOffset, yTip)); steppedPath.add(new Point2D.Double(xOffset + stepLength, yTip)); steppedReturnPath.add(new Point2D.Double(xOffset, yCenter)); steppedReturnPath.add(new Point2D.Double(xOffset + stepLength, yCenter)); path.closePath(); g.setColor(series.getFillColor()); g.fill(path);
private void paintShapeNode_0_0_0_4(Graphics2D g) { Rectangle2D.Double shape4 = new Rectangle2D.Double(4.324751377105713, 2.8455440998077393, 6.532177448272705, 4.279702663421631); g.setPaint(new LinearGradientPaint(new Point2D.Double(8.784652709960938, 6.652227878570557), new Point2D.Double(8.424254417419434, 2.7329208850860596), new float[] {0.0f,1.0f}, new Color[] {new Color(192, 192, 192, 255),new Color(255, 255, 255, 255)}, MultipleGradientPaint.CycleMethod.NO_CYCLE, MultipleGradientPaint.ColorSpaceType.SRGB, new AffineTransform(0.771276593208313f, 0.0f, 0.0f, 1.0439560413360596f, 0.9891719818115234f, 0.01601026952266693f))); g.fill(shape4); }
float[] vproj = profile.getVerticalProjection(); g.setStroke(new BasicStroke(1f)); g.setColor(Color.RED); Point2D last = new Point2D.Double(page.getLeft(), page.getBottom()), cur; for (int i = 0; i < hproj.length; i++) { cur = new Point2D.Double(page.getLeft() + i / prec, page.getBottom() - hproj[i]); g.draw(new Line2D.Double(last, cur)); last = cur; float[] deriv = ProjectionProfile.filter(ProjectionProfile.getFirstDeriv(profile.getHorizontalProjection()), 0.01f); last = new Point2D.Double(page.getLeft(), page.getBottom()); for (int i = 0; i < deriv.length; i++) { cur = new Point2D.Double(page.getLeft() + i / prec, page.getBottom() - deriv[i]); g.setStroke(new BasicStroke(1f)); g.setColor(Color.GREEN); last = new Point2D.Double(page.getLeft(), page.getTop()); for (int i = 0; i < vproj.length; i++) { cur = new Point2D.Double(page.getLeft() + vproj[i] / prec, page.getTop() + i / prec); g.setColor(new Color(0, 0, 1, 0.5f)); deriv = ProjectionProfile.filter(ProjectionProfile.getFirstDeriv(vproj), 0.1f); last = new Point2D.Double(page.getRight(), page.getTop()); for (int i = 0; i < deriv.length; i++) { cur = new Point2D.Double(page.getRight() - deriv[i] * 10, page.getTop() + i / prec);
Color curColor = g2.getColor(); g2.setColor(paintColor); g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent)); g2.setColor(curColor); double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip); double layerHeight = nodeHeight * layerMultiplier; if (t.isLeaf()) { yieldOffsets[leafCtr++] = (float) (nodeTab + start.getX()); return nodeWidth; if(matchedParts != null && matchedParts.contains(child)) { Point2D.Double coord = new Point2D.Double(childStartX, childStartY); matchedPartCoordinates.add(coord); cWidth = paintTree(child, coord, g2, fM, matchedColor); if(((CoreLabel) child.label()).containsKey(CoreAnnotations.DoAnnotation.class)) col = (((CoreLabel) child.label()).get(CoreAnnotations.DoAnnotation.class)) ? tdiffColor : defaultColor; cWidth = paintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM, col);
public USegment rotate(double theta) { if (coord.length != 2) { throw new UnsupportedOperationException(); } Point2D p1 = new Point2D.Double(coord[0], coord[1]); final AffineTransform rotate = AffineTransform.getRotateInstance(theta); rotate.transform(p1, p1); return new USegment(new double[] { p1.getX(), p1.getY() }, pathType); }
Rectangle2D rect = new Rectangle2D.Double(x, y, width, height); Graphics2D g2d = (Graphics2D) g.create(); g2d.draw(rect); g2d.draw(line); g2d.setColor(Color.RED); Point2D[] ps = getIntersectionPoint(line, rect); for (Point2D p : ps) { if (p != null) { g2d.fill(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8)); g2d.dispose(); double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; p = new Point2D.Double(xi, yi);
private void drawVertices(Graphics2D g2, Coordinate[] coords) { for (int i = 1; i < coords.length; i++) { Point2D p0 = new Point2D.Double(coords[i - 1].x, coords[i - 1].y); tr.transform(p0, p0); Point2D p1 = new Point2D.Double(coords[i].x, coords[i].y); tr.transform(p1, p1); g2.drawLine((int) p0.getX(), (int) p0.getY(), (int) p1.getX(), (int) p1.getY()); } }
new AffineTransform( worldToScreen.getShearX(), worldToScreen.getScaleX(), worldToScreen.getScaleY(), worldToScreen.getShearY(), this.worldToScreenTransform = worldToScreen; error = 0; if (java2dHints != null) graphics.setRenderingHints(java2dHints); new Point2D.Double( worldToScreenTransform.getTranslateX(), worldToScreenTransform.getTranslateY()); graphics.setRenderingHint(StyledShapePainter.TEXTURE_ANCHOR_HINT_KEY, textureAnchor); graphics.setClip(paintArea);
private void drawCoordinate(Graphics2D g2, Coordinate coord) { Point2D p = new Point2D.Double(coord.x, coord.y); tr.transform(p, p); g2.fillOval((int)p.getX() - POINT_RADIUS, (int)p.getY() - POINT_RADIUS, 2 * POINT_RADIUS, 2 * POINT_RADIUS ); }
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { final DotPath result = new DotPath(); final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); final Line2D.Double line = new Line2D.Double(tangeante.getP1(), center); final Point2D inter = BezierUtils.intersect(line, rect); final CubicCurve2D.Double curv = new CubicCurve2D.Double(line.getX1(), line.getY1(), line.getX1(), line.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }
superPaint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font; if ("".equals(fontName)) { font = g2.getFont(); fontName = font.getName(); style = font.getStyle(); g2.setFont(font); FontMetrics fM = g2.getFontMetrics(); Dimension space = getSize(); paintTree(tree, new Point2D.Double(startX, startY), g2, fM, matchedColor); } else { paintTree(tree, new Point2D.Double(startX, startY), g2, fM, defaultColor); renderRows(g2,fM, defaultColor);
g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent)); if (t.isLeaf()) { return nodeWidth; double childStartX = start.getX() + childTab; double childStartY = start.getY() + layerHeight; double lineStartX = start.getX() + nodeCenter; double cWidth = paintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM); g2.draw(new Line2D.Double(lineStartX, lineStartY, lineEndX, lineEndY)); childStartX += cWidth; if (i < t.children().length - 1) {
Point2D inter = null; if (in.getX() > rect.getMinX() && in.getX() < rect.getMaxX()) { if (in.getY() < rect.getMinY()) { inter = new Point2D.Double(in.getX(), rect.getMinY()); } else if (in.getY() > rect.getMaxY()) { inter = new Point2D.Double(in.getX(), rect.getMaxY()); } else { throw new IllegalArgumentException(); } else if (in.getY() > rect.getMinY() && in.getY() < rect.getMaxY()) { if (in.getX() < rect.getMinX()) { inter = new Point2D.Double(rect.getMinX(), in.getY()); } else if (in.getX() > rect.getMaxX()) { inter = new Point2D.Double(rect.getMaxX(), in.getY()); } else { throw new IllegalArgumentException(); final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
public void zoom(Point2D newCenter, double factor) { AffineTransform at = new AffineTransform(); double bboxCenterX = actualBBox.getCenterX(); double bboxCenterY = actualBBox.getCenterY(); if (newCenter==null) newCenter = new Point2D.Double(bboxCenterX, bboxCenterY); double centerX = newCenter.getX(); double centerY = newCenter.getY(); factor = 1 / factor; at.translate(centerX, centerY); at.scale(factor, factor); at.translate(-bboxCenterX, -bboxCenterY); actualBBox = at.createTransformedShape(actualBBox).getBounds2D(); }
@SuppressWarnings("WeakerAccess") protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) { // TODO: we need to find the two points for gradient - the problem is, which point at the outline // do you take? My solution would be to apply the gradient rotation to the shape in reverse // and then scan the shape for the largest possible horizontal distance double angle = fill.getGradientAngle(); if (!fill.isRotatedWithShape()) { angle -= shape.getRotation(); } Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY()); double diagonal = Math.sqrt(Math.pow(anchor.getWidth(),2) + Math.pow(anchor.getHeight(),2)); final Point2D p1 = at.transform(new Point2D.Double(anchor.getCenterX() - diagonal / 2, anchor.getCenterY()), null); final Point2D p2 = at.transform(new Point2D.Double(anchor.getMaxX(), anchor.getCenterY()), null); // snapToAnchor(p1, anchor); // snapToAnchor(p2, anchor); // gradient paint on the same point throws an exception ... and doesn't make sense return (p1.equals(p2)) ? null : safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill); }