1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| import org.apache.batik.svggen.SVGGraphics2D;
import java.awt.*;
public class BatikDrawingUtil {
public static void drawLine(SVGGraphics2D g2d, int x1, int y1, int x2, int y2, Color color, int strokeWidth) { g2d.setPaint(color); g2d.setStroke(new BasicStroke(strokeWidth)); g2d.drawLine(x1, y1, x2, y2); }
public static void drawSolidRect(SVGGraphics2D g2d, int x, int y, int width, int height, Color color) { g2d.setPaint(color); g2d.fillRect(x, y, width, height); }
public static void drawHollowRect(SVGGraphics2D g2d, int x, int y, int width, int height, Color color, int strokeWidth) { g2d.setPaint(color); g2d.setStroke(new BasicStroke(strokeWidth)); g2d.drawRect(x, y, width, height); }
public static void drawSolidRectCenterBased(SVGGraphics2D g2d, int centerX, int centerY, int width, int height, Color color) { int x = centerX - width / 2; int y = centerY - height / 2; g2d.setPaint(color); g2d.fillRect(x, y, width, height); }
public static void drawSolidCircle(SVGGraphics2D g2d, int x, int y, int radius, Color color) { g2d.setPaint(color); g2d.fillOval(x - radius, y - radius, radius * 2, radius * 2); }
public static void drawHollowCircle(SVGGraphics2D g2d, int x, int y, int radius, Color color, int strokeWidth) { g2d.setPaint(color); g2d.setStroke(new BasicStroke(strokeWidth)); g2d.drawOval(x - radius, y - radius, radius * 2, radius * 2); }
public static void writeText(SVGGraphics2D g2d, String text, int x, int y, Color color, Font font) { g2d.setPaint(color); g2d.setFont(font); g2d.drawString(text, x, y); }
public static void writeTextYModified(SVGGraphics2D g2d, String text, int x, int centerY, Color color, Font font) { g2d.setPaint(color); g2d.setFont(font); FontMetrics metrics = g2d.getFontMetrics(font); int textHeight = metrics.getHeight(); int y = centerY + textHeight / 4; g2d.drawString(text, x, y); } }
|