| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.bulenkov.iconloader; |
| 18 |
|
| 19 |
import com.bulenkov.iconloader.util.GraphicsUtil; |
| 20 |
|
| 21 |
import java.awt.*; |
| 22 |
import java.awt.font.FontRenderContext; |
| 23 |
import java.awt.font.GlyphVector; |
| 24 |
import java.awt.geom.AffineTransform; |
| 25 |
import java.awt.image.BufferedImage; |
| 26 |
import java.awt.image.BufferedImageOp; |
| 27 |
import java.awt.image.ImageObserver; |
| 28 |
import java.awt.image.RenderedImage; |
| 29 |
import java.awt.image.renderable.RenderableImage; |
| 30 |
import java.text.AttributedCharacterIterator; |
| 31 |
import java.util.Map; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class HiDPIScaledGraphics extends Graphics2D { |
| 37 |
protected final Graphics2D myPeer; |
| 38 |
private BufferedImage myImage; |
| 39 |
|
| 40 |
public HiDPIScaledGraphics(Graphics g, BufferedImage image) { |
| 41 |
myImage = image; |
| 42 |
myPeer = (Graphics2D) g; |
| 43 |
scale(2, 2); |
| 44 |
GraphicsUtil.setupAAPainting(myPeer); |
| 45 |
} |
| 46 |
|
| 47 |
@Override |
| 48 |
public void draw3DRect(int x, int y, int width, int height, boolean raised) { |
| 49 |
myPeer.draw3DRect(x, y, width, height, raised); |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public void fill3DRect(int x, int y, int width, int height, boolean raised) { |
| 54 |
myPeer.fill3DRect(x, y, width, height, raised); |
| 55 |
} |
| 56 |
|
| 57 |
@Override |
| 58 |
public void draw(Shape s) { |
| 59 |
myPeer.draw(s); |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { |
| 64 |
return myPeer.drawImage(img, xform, obs); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) { |
| 69 |
myPeer.drawImage(img, op, x, y); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public void drawRenderedImage(RenderedImage img, AffineTransform xform) { |
| 74 |
myPeer.drawRenderedImage(img, xform); |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public void drawRenderableImage(RenderableImage img, AffineTransform xform) { |
| 79 |
myPeer.drawRenderableImage(img, xform); |
| 80 |
} |
| 81 |
|
| 82 |
@Override |
| 83 |
public void drawString(String str, int x, int y) { |
| 84 |
myPeer.drawString(str, x, y); |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public void drawString(String str, float x, float y) { |
| 89 |
myPeer.drawString(str, x, y); |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public void drawString(AttributedCharacterIterator iterator, int x, int y) { |
| 94 |
myPeer.drawString(iterator, x, y); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public void drawString(AttributedCharacterIterator iterator, float x, float y) { |
| 99 |
myPeer.drawString(iterator, x, y); |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public void drawGlyphVector(GlyphVector g, float x, float y) { |
| 104 |
myPeer.drawGlyphVector(g, x, y); |
| 105 |
} |
| 106 |
|
| 107 |
@Override |
| 108 |
public void fill(Shape s) { |
| 109 |
myPeer.fill(s); |
| 110 |
} |
| 111 |
|
| 112 |
@Override |
| 113 |
public boolean hit(Rectangle rect, Shape s, boolean onStroke) { |
| 114 |
return myPeer.hit(rect, s, onStroke); |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public GraphicsConfiguration getDeviceConfiguration() { |
| 119 |
return myPeer.getDeviceConfiguration(); |
| 120 |
} |
| 121 |
|
| 122 |
@Override |
| 123 |
public void setComposite(Composite comp) { |
| 124 |
myPeer.setComposite(comp); |
| 125 |
} |
| 126 |
|
| 127 |
@Override |
| 128 |
public void setPaint(Paint paint) { |
| 129 |
myPeer.setPaint(paint); |
| 130 |
} |
| 131 |
|
| 132 |
@Override |
| 133 |
public void setStroke(Stroke s) { |
| 134 |
myPeer.setStroke(s); |
| 135 |
} |
| 136 |
|
| 137 |
@Override |
| 138 |
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { |
| 139 |
myPeer.setRenderingHint(hintKey, hintValue); |
| 140 |
} |
| 141 |
|
| 142 |
@Override |
| 143 |
public Object getRenderingHint(RenderingHints.Key hintKey) { |
| 144 |
return myPeer.getRenderingHint(hintKey); |
| 145 |
} |
| 146 |
|
| 147 |
@Override |
| 148 |
public void setRenderingHints(Map<?, ?> hints) { |
| 149 |
myPeer.setRenderingHints(hints); |
| 150 |
} |
| 151 |
|
| 152 |
@Override |
| 153 |
public void addRenderingHints(Map<?, ?> hints) { |
| 154 |
myPeer.addRenderingHints(hints); |
| 155 |
} |
| 156 |
|
| 157 |
@Override |
| 158 |
public RenderingHints getRenderingHints() { |
| 159 |
return myPeer.getRenderingHints(); |
| 160 |
} |
| 161 |
|
| 162 |
@Override |
| 163 |
public void translate(int x, int y) { |
| 164 |
myPeer.translate(x, y); |
| 165 |
} |
| 166 |
|
| 167 |
@Override |
| 168 |
public void translate(double tx, double ty) { |
| 169 |
myPeer.translate(tx, ty); |
| 170 |
} |
| 171 |
|
| 172 |
@Override |
| 173 |
public void rotate(double theta) { |
| 174 |
myPeer.rotate(theta); |
| 175 |
} |
| 176 |
|
| 177 |
@Override |
| 178 |
public void rotate(double theta, double x, double y) { |
| 179 |
myPeer.rotate(theta, x, y); |
| 180 |
} |
| 181 |
|
| 182 |
@Override |
| 183 |
public void scale(double sx, double sy) { |
| 184 |
myPeer.scale(sx, sy); |
| 185 |
} |
| 186 |
|
| 187 |
@Override |
| 188 |
public void shear(double shx, double shy) { |
| 189 |
myPeer.shear(shx, shy); |
| 190 |
} |
| 191 |
|
| 192 |
@Override |
| 193 |
public void transform(AffineTransform Tx) { |
| 194 |
myPeer.transform(Tx); |
| 195 |
} |
| 196 |
|
| 197 |
@Override |
| 198 |
public void setTransform(AffineTransform Tx) { |
| 199 |
myPeer.setTransform(Tx); |
| 200 |
} |
| 201 |
|
| 202 |
@Override |
| 203 |
public AffineTransform getTransform() { |
| 204 |
return myPeer.getTransform(); |
| 205 |
} |
| 206 |
|
| 207 |
@Override |
| 208 |
public Paint getPaint() { |
| 209 |
return myPeer.getPaint(); |
| 210 |
} |
| 211 |
|
| 212 |
@Override |
| 213 |
public Composite getComposite() { |
| 214 |
return myPeer.getComposite(); |
| 215 |
} |
| 216 |
|
| 217 |
@Override |
| 218 |
public void setBackground(Color color) { |
| 219 |
myPeer.setBackground(color); |
| 220 |
} |
| 221 |
|
| 222 |
@Override |
| 223 |
public Color getBackground() { |
| 224 |
return myPeer.getBackground(); |
| 225 |
} |
| 226 |
|
| 227 |
@Override |
| 228 |
public Stroke getStroke() { |
| 229 |
return myPeer.getStroke(); |
| 230 |
} |
| 231 |
|
| 232 |
@Override |
| 233 |
public void clip(Shape s) { |
| 234 |
myPeer.clip(s); |
| 235 |
} |
| 236 |
|
| 237 |
@Override |
| 238 |
public FontRenderContext getFontRenderContext() { |
| 239 |
return myPeer.getFontRenderContext(); |
| 240 |
} |
| 241 |
|
| 242 |
@Override |
| 243 |
public Graphics create() { |
| 244 |
Graphics g = myPeer.create(); |
| 245 |
return g; |
| 246 |
} |
| 247 |
|
| 248 |
@Override |
| 249 |
public Graphics create(int x, int y, int width, int height) { |
| 250 |
return myPeer.create(x, y, width, height); |
| 251 |
} |
| 252 |
|
| 253 |
@Override |
| 254 |
public Color getColor() { |
| 255 |
return myPeer.getColor(); |
| 256 |
} |
| 257 |
|
| 258 |
@Override |
| 259 |
public void setColor(Color c) { |
| 260 |
myPeer.setColor(c); |
| 261 |
} |
| 262 |
|
| 263 |
@Override |
| 264 |
public void setPaintMode() { |
| 265 |
myPeer.setPaintMode(); |
| 266 |
} |
| 267 |
|
| 268 |
@Override |
| 269 |
public void setXORMode(Color c1) { |
| 270 |
myPeer.setXORMode(c1); |
| 271 |
} |
| 272 |
|
| 273 |
@Override |
| 274 |
public Font getFont() { |
| 275 |
return myPeer.getFont(); |
| 276 |
} |
| 277 |
|
| 278 |
@Override |
| 279 |
public void setFont(Font font) { |
| 280 |
myPeer.setFont(font); |
| 281 |
} |
| 282 |
|
| 283 |
@Override |
| 284 |
public FontMetrics getFontMetrics() { |
| 285 |
return myPeer.getFontMetrics(); |
| 286 |
} |
| 287 |
|
| 288 |
@Override |
| 289 |
public FontMetrics getFontMetrics(Font f) { |
| 290 |
return myPeer.getFontMetrics(f); |
| 291 |
} |
| 292 |
|
| 293 |
@Override |
| 294 |
public Rectangle getClipBounds() { |
| 295 |
return myPeer.getClipBounds(); |
| 296 |
} |
| 297 |
|
| 298 |
@Override |
| 299 |
public void clipRect(int x, int y, int width, int height) { |
| 300 |
myPeer.clipRect(x, y, width, height); |
| 301 |
} |
| 302 |
|
| 303 |
@Override |
| 304 |
public void setClip(int x, int y, int width, int height) { |
| 305 |
myPeer.setClip(x, y, width, height); |
| 306 |
} |
| 307 |
|
| 308 |
@Override |
| 309 |
public Shape getClip() { |
| 310 |
return myPeer.getClip(); |
| 311 |
} |
| 312 |
|
| 313 |
@Override |
| 314 |
public void setClip(Shape clip) { |
| 315 |
myPeer.setClip(clip); |
| 316 |
} |
| 317 |
|
| 318 |
@Override |
| 319 |
public void copyArea(int x, int y, int width, int height, int dx, int dy) { |
| 320 |
myPeer.copyArea(x, y, width, height, dx, dy); |
| 321 |
} |
| 322 |
|
| 323 |
@Override |
| 324 |
public void drawLine(int x1, int y1, int x2, int y2) { |
| 325 |
myPeer.drawLine(x1, y1, x2, y2); |
| 326 |
} |
| 327 |
|
| 328 |
@Override |
| 329 |
public void fillRect(int x, int y, int width, int height) { |
| 330 |
myPeer.fillRect(x, y, width, height); |
| 331 |
} |
| 332 |
|
| 333 |
@Override |
| 334 |
public void drawRect(int x, int y, int width, int height) { |
| 335 |
myPeer.drawRect(x, y, width, height); |
| 336 |
} |
| 337 |
|
| 338 |
@Override |
| 339 |
public void clearRect(int x, int y, int width, int height) { |
| 340 |
myPeer.clearRect(x, y, width, height); |
| 341 |
} |
| 342 |
|
| 343 |
@Override |
| 344 |
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { |
| 345 |
myPeer.drawRoundRect(x, y, width, height, arcWidth, arcHeight); |
| 346 |
} |
| 347 |
|
| 348 |
@Override |
| 349 |
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { |
| 350 |
myPeer.fillRoundRect(x, y, width, height, arcWidth, arcHeight); |
| 351 |
} |
| 352 |
|
| 353 |
@Override |
| 354 |
public void drawOval(int x, int y, int width, int height) { |
| 355 |
myPeer.drawOval(x, y, width, height); |
| 356 |
} |
| 357 |
|
| 358 |
@Override |
| 359 |
public void fillOval(int x, int y, int width, int height) { |
| 360 |
myPeer.fillOval(x, y, width, height); |
| 361 |
} |
| 362 |
|
| 363 |
@Override |
| 364 |
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { |
| 365 |
myPeer.drawArc(x, y, width, height, startAngle, arcAngle); |
| 366 |
} |
| 367 |
|
| 368 |
@Override |
| 369 |
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { |
| 370 |
myPeer.fillArc(x, y, width, height, startAngle, arcAngle); |
| 371 |
} |
| 372 |
|
| 373 |
@Override |
| 374 |
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { |
| 375 |
|
| 376 |
myPeer.drawPolyline(xPoints, yPoints, nPoints); |
| 377 |
} |
| 378 |
|
| 379 |
@Override |
| 380 |
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { |
| 381 |
|
| 382 |
myPeer.drawPolygon(xPoints, yPoints, nPoints); |
| 383 |
} |
| 384 |
|
| 385 |
@Override |
| 386 |
public void drawPolygon(Polygon p) { |
| 387 |
|
| 388 |
myPeer.drawPolygon(p); |
| 389 |
} |
| 390 |
|
| 391 |
@Override |
| 392 |
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { |
| 393 |
|
| 394 |
myPeer.fillPolygon(xPoints, yPoints, nPoints); |
| 395 |
} |
| 396 |
|
| 397 |
@Override |
| 398 |
public void fillPolygon(Polygon p) { |
| 399 |
|
| 400 |
myPeer.fillPolygon(p); |
| 401 |
} |
| 402 |
|
| 403 |
@Override |
| 404 |
public void drawChars(char[] data, int offset, int length, int x, int y) { |
| 405 |
myPeer.drawChars(data, offset, length, x, y); |
| 406 |
} |
| 407 |
|
| 408 |
@Override |
| 409 |
public void drawBytes(byte[] data, int offset, int length, int x, int y) { |
| 410 |
myPeer.drawBytes(data, offset, length, x, y); |
| 411 |
} |
| 412 |
|
| 413 |
@Override |
| 414 |
public boolean drawImage(Image img, int x, int y, ImageObserver observer) { |
| 415 |
return myPeer.drawImage(img, x, y, observer); |
| 416 |
} |
| 417 |
|
| 418 |
@Override |
| 419 |
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { |
| 420 |
return myPeer.drawImage(img, x, y, width, height, observer); |
| 421 |
} |
| 422 |
|
| 423 |
@Override |
| 424 |
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { |
| 425 |
return myPeer.drawImage(img, x, y, bgcolor, observer); |
| 426 |
} |
| 427 |
|
| 428 |
@Override |
| 429 |
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { |
| 430 |
return myPeer.drawImage(img, x, y, width, height, bgcolor, observer); |
| 431 |
} |
| 432 |
|
| 433 |
@Override |
| 434 |
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { |
| 435 |
return myPeer.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); |
| 436 |
} |
| 437 |
|
| 438 |
@Override |
| 439 |
public boolean drawImage(Image img, |
| 440 |
int dx1, |
| 441 |
int dy1, |
| 442 |
int dx2, |
| 443 |
int dy2, |
| 444 |
int sx1, |
| 445 |
int sy1, |
| 446 |
int sx2, |
| 447 |
int sy2, |
| 448 |
Color bgcolor, |
| 449 |
ImageObserver observer) { |
| 450 |
return myPeer.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); |
| 451 |
} |
| 452 |
|
| 453 |
@Override |
| 454 |
public void dispose() { |
| 455 |
myPeer.dispose(); |
| 456 |
} |
| 457 |
|
| 458 |
@Override |
| 459 |
public void finalize() { |
| 460 |
myPeer.finalize(); |
| 461 |
} |
| 462 |
|
| 463 |
@Override |
| 464 |
public String toString() { |
| 465 |
return myPeer.toString(); |
| 466 |
} |
| 467 |
|
| 468 |
@Override |
| 469 |
@Deprecated |
| 470 |
public Rectangle getClipRect() { |
| 471 |
return myPeer.getClipRect(); |
| 472 |
} |
| 473 |
|
| 474 |
@Override |
| 475 |
public boolean hitClip(int x, int y, int width, int height) { |
| 476 |
return myPeer.hitClip(x, y, width, height); |
| 477 |
} |
| 478 |
|
| 479 |
@Override |
| 480 |
public Rectangle getClipBounds(Rectangle r) { |
| 481 |
return myPeer.getClipBounds(r); |
| 482 |
} |
| 483 |
|
| 484 |
} |