1 43 44 package swingwt.awt; 45 46 import org.eclipse.swt.graphics.GC; 47 import swingwt.awt.font.FontRenderContext; 48 import swingwt.awt.font.GlyphVector; 49 import swingwt.awt.geom.AffineTransform; 50 51 import java.util.Map ; 52 53 60 public class SWTGraphics2DRenderer extends Graphics2D { 61 62 63 protected GC gc = null; 64 65 protected swingwt.awt.Font f = null; 66 67 protected swingwt.awt.Color c = null; 68 72 protected boolean shouldDestroy = false; 73 74 public SWTGraphics2DRenderer(final GC gcon) { 75 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 76 public void run() { 77 gc = gcon; 78 79 f = new swingwt.awt.Font(gc.getFont()); 82 c = new swingwt.awt.Color(gc.getForeground()); 83 } 84 }); 85 } 86 87 90 public SWTGraphics2DRenderer(GC gc, boolean needToCleanUp) { 91 this(gc); 92 shouldDestroy = needToCleanUp; 93 } 94 95 public Graphics create() { 96 return this; 98 } 99 100 public void dispose() { 101 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 102 public void run() { 103 gc.dispose(); 104 } 105 }); 106 } 107 108 109 public GC getSWTGC() { return gc; } 110 111 public void clearRect(final int x, final int y, final int width, final int height) { 112 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 113 public void run() { 114 gc.fillRectangle(x, y, width, height); 115 } 116 }); 117 } 118 119 public void clipRect(int x, int y, int width, int height) { } 120 121 public void copyArea(final int x, final int y, final int width, final int height, final int dx, final int dy) { 122 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 123 public void run() { 124 gc.copyArea(x, y, width, height, dx, dy); 125 } 126 }); 127 } 128 129 public void redrawUnder(final int x, final int y, final int width, final int height) { 130 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 131 public void run() { 132 org.eclipse.swt.graphics.Image image = new org.eclipse.swt.graphics.Image( 133 swingwtx.swing.SwingWTUtils.getDisplay(), width, height); 134 gc.copyArea(image, x, y); 135 gc.drawImage(image, x, y); 136 } 137 }); 138 } 139 140 public void drawArc(final int x, final int y, final int width, final int height, final int startAngle,final int arcAngle) { 141 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 142 public void run() { 143 gc.drawArc(x, y, width, height, startAngle, arcAngle); 144 } 145 }); 146 } 147 148 public void drawBytes(final byte[] data, final int offset, final int length, final int x, final int y) { 149 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 150 public void run() { 151 gc.drawString(new String (data), x, y, true); 152 } 153 }); 154 } 155 public void drawChars(final char[] data, final int offset, final int length, final int x, final int y) { 156 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 157 public void run() { 158 gc.drawString(new String (data), x, y, true); 159 } 160 }); 161 } 162 163 public boolean drawImage(final swingwt.awt.Image img, final int x, final int y, final Color bgcolor, final ImageObserver observer) { 164 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 165 public void run() { 166 gc.drawImage(img.image, x, y); 167 } 168 }); 169 return true; 170 } 171 public boolean drawImage(final swingwt.awt.Image img, final int x, final int y, final ImageObserver observer) { 172 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 173 public void run() { 174 gc.drawImage(img.image, x, y); 175 } 176 }); 177 return true; 178 } 179 public boolean drawImage(final swingwt.awt.Image img, final int x, final int y, final int width, final int height, final Color bgcolor, final ImageObserver observer) { 180 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 181 public void run() { 182 gc.drawImage(img.image, x, y); 183 } 184 }); 185 return true; 186 } 187 public boolean drawImage(final swingwt.awt.Image img, final int x, final int y, final int width, final int height, final ImageObserver observer) { 188 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 189 public void run() { 190 gc.drawImage(img.image, 0, 0, img.getWidth(null), img.getHeight(null), x, y, width, height); 191 } 192 }); 193 return true; 194 } 195 public boolean drawImage(final swingwt.awt.Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, final Color bgcolor,final ImageObserver observer) { 196 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 197 public void run() { 198 gc.drawImage(img.image, sx1, sy1, sx2 - sx1, sy2 - sy1, dx1, dy1, dx2 - dx1, dy2 - dy1); 199 } 200 }); 201 return true; 202 } 203 public boolean drawImage(final swingwt.awt.Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, ImageObserver observer) { 204 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 205 public void run() { 206 gc.drawImage(img.image, sx1, sy1, sx2 - sx1, sy2 - sy1, dx1, dy1, dx2 - dx1, dy2 - dy1); 207 } 208 }); 209 return true; 210 } 211 212 public void drawLine(final int x1, final int y1, final int x2, final int y2) { 213 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 214 public void run() { 215 gc.drawLine(x1, y1, x2, y2); 216 } 217 }); 218 } 219 220 public void drawOval(final int x, final int y, final int width, final int height) { 221 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 222 public void run() { 223 gc.drawOval(x, y, width, height); 224 } 225 }); 226 } 227 228 229 public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { 230 231 } 232 233 234 public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { 235 236 } 237 238 public void drawString(final String str, final int x, final int y) { 239 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 240 public void run() { 241 gc.drawString(str, x, y, false); 242 } 243 }); 244 } 245 246 public void drawString(final String str, final int x, final int y, final boolean transparent) { 247 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 248 public void run() { 249 gc.drawString(str, x, y, transparent); 250 } 251 }); 252 } 253 254 public void fillArc(final int x, final int y, final int width, final int height, final int startAngle, final int arcAngle) { 255 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 256 public void run() { 257 gc.setBackground(c.getSWTColor()); 258 gc.fillArc(x, y, width, height, startAngle, arcAngle); 259 } 260 }); 261 } 262 263 public void fillOval(final int x, final int y, final int width, final int height) { 264 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 265 public void run() { 266 gc.setBackground(c.getSWTColor()); 267 gc.fillOval(x, y, width, height); 268 } 269 }); 270 } 271 272 273 public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { 274 } 275 276 public void fillRect(final int x, final int y, final int width, final int height) { 277 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 278 public void run() { 279 gc.setBackground(c.getSWTColor()); 280 gc.fillRectangle(x, y, width, height); 281 } 282 }); 283 } 284 285 286 public void fillRoundRect(final int x, final int y, final int width, final int height, final int arcWidth, final int arcHeight) { 287 fillRect(x, y, width, height); 288 } 289 290 public Font getFont() { 291 return f; 292 } 293 294 public Color getColor() { 295 return c; 296 } 297 298 public void setFont(swingwt.awt.Font f) { 299 if (f != this.f) { 300 this.f = f; 301 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 302 public void run() { 303 gc.setFont(SWTGraphics2DRenderer.this.f.getSWTFont()); 304 } 305 }); 306 } 307 } 308 309 public void setColor(swingwt.awt.Color color) { 310 this.c = color; 311 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 312 public void run() { 313 gc.setForeground(c.getSWTColor()); 314 } 315 }); 316 } 317 318 protected void finalize() throws Throwable { 319 if (shouldDestroy) { 320 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 321 public void run() { 322 gc.dispose(); 323 } 324 }); 325 } 326 } 327 328 329 public void addRenderingHints(Map hints) { 330 } 331 332 333 public void clip(Shape s) { 334 } 335 336 337 public void draw(Shape s) { 338 } 339 340 341 public void drawGlyphVector(GlyphVector g, float x, float y) { 342 } 343 344 345 public void fill(Shape s) { 346 } 347 348 public Color getBackground() { 349 return new swingwt.awt.Color(gc.getBackground()); 350 } 351 352 353 public Composite getComposite() { 354 return null; 355 } 356 357 358 public GraphicsConfiguration getDeviceConfiguration() { 359 return null; 360 } 361 362 363 public FontRenderContext getFontRenderContext() { 364 return null; 365 } 366 367 368 public Paint getPaint() { 369 return null; 370 } 371 372 373 public Object getRenderingHint(Object hintKey) { 374 return null; 375 } 376 377 378 public RenderingHints getRenderingHints() { 379 return null; 380 } 381 382 383 public Stroke getStroke() { 384 return null; 385 } 386 387 388 public AffineTransform getTransform() { 389 return null; 390 } 391 392 393 public boolean hit(Rectangle rect, Shape s, boolean onStroke) { 394 return false; 395 } 396 397 398 public void rotate(double theta) { 399 } 400 401 402 public void rotate(double theta, double x, double y) { 403 } 404 405 406 public void scale(double sx, double sy) { 407 } 408 409 public void setBackground(final swingwt.awt.Color color) { 410 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 411 public void run() { 412 gc.setBackground(color.getSWTColor()); 413 } 414 }); 415 } 416 417 418 public void setComposite(Composite comp) { 419 } 420 421 422 public void setPaint(Paint paint) { 423 } 424 425 426 public void setRenderingHint(Object hintKey, Object hintValue) { 427 } 428 429 430 public void setRenderingHints(Map hints) { 431 } 432 433 434 public void setStroke(Stroke s) { 435 } 436 437 438 public void setTransform(AffineTransform Tx) { 439 } 440 441 442 public void shear(double shx, double shy) { 443 } 444 445 446 public void transform(AffineTransform Tx) { 447 } 448 449 450 public void translate(double tx, double ty) { 451 } 452 453 454 public void translate(int x, int y) { 455 } 456 457 458 public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { 459 } 460 461 462 public Shape getClip() { 463 return null; 464 } 465 466 public Rectangle getClipBounds() { 467 final swingwt.awt.Rectangle r = new swingwt.awt.Rectangle(); 468 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 469 public void run() { 470 org.eclipse.swt.graphics.Rectangle rc = gc.getClipping(); 471 r.height = rc.height; 472 r.width = rc.width; 473 r.x = rc.x; 474 r.y = rc.y; 475 } 476 }); 477 return r; 478 } 479 480 public FontMetrics getFontMetrics(Font f) { 481 return new swingwt.awt.FontMetrics(f); 482 } 483 484 485 public void setClip(Shape clip) { 486 } 487 488 public void setClip(final int x, final int y, final int width, final int height) { 489 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 490 public void run() { 491 gc.setClipping(x, y, width, height); 492 } 493 }); 494 } 495 496 497 public void setPaintMode() { 498 } 499 500 501 public void setXORMode(Color c1) { 502 } 503 504 } 505 | Popular Tags |