/** * Draw the outline of the specified rectangle. The logical coordinates * are proportional to the base coordinates. */ public void drawRectBaseRatio(double[] topLeft, double[] rightBottom) { if (!(projection instanceof Projection2D)) { throw new UnsupportedOperationException("Only 2D graphics supports drawing rectangles."); } int[] sc = projection.screenProjectionBaseRatio(topLeft); int[] sc2 = projection.screenProjectionBaseRatio(rightBottom); g2d.drawRect(sc[0], sc[1], sc2[0] - sc[0], sc2[1] - sc[1]); }
/** * Fill the specified rectangle. The logical coordinates are proportional * to the base coordinates. */ public void fillRectBaseRatio(double[] topLeft, double[] rightBottom) { if (!(projection instanceof Projection2D)) { throw new UnsupportedOperationException("Only 2D graphics supports drawing rectangles."); } int[] sc = projection.screenProjectionBaseRatio(topLeft); int[] sc2 = projection.screenProjectionBaseRatio(rightBottom); g2d.fillRect(sc[0], sc[1], sc2[0] - sc[0], sc2[1] - sc[1]); }
/** * Draw poly line. The logical coordinates are proportional to the base * coordinates. */ public void drawLineBaseRatio(double[]... coord) { int[][] sc = new int[coord.length][]; for (int i = 0; i < sc.length; i++) { sc[i] = projection.screenProjectionBaseRatio(coord[i]); } drawLine(sc); }
/** * Draw a string with given reference point and rotation angle. (0.5, 0.5) * is center, (0, 0) is lower left, (1, 0) is upper left, etc. * The angle of rotation is in radians. The logical are proportional to * the base coordinates. */ public void drawTextBaseRatio(String label, double horizontalReference, double verticalReference, double rotation, double[] coord) { int[] sc = projection.screenProjectionBaseRatio(coord); int x = sc[0]; int y = sc[1]; AffineTransform transform = g2d.getTransform(); // Corner offset adjustment : Text Offset is used Here FontRenderContext frc = g2d.getFontRenderContext(); Font font = g2d.getFont(); double w = font.getStringBounds(label, frc).getWidth(); double h = font.getSize2D(); if (rotation != 0) { g2d.rotate(rotation, x, y); } x -= (int) (w * horizontalReference); y += (int) (h * verticalReference); g2d.drawString(label, x, y); g2d.setTransform(transform); }