diff options
author | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-05-29 07:14:31 +0000 |
---|---|---|
committer | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-05-29 07:14:31 +0000 |
commit | e4bdb9cbf32f1c8ac328acae4e63b361e3f47092 (patch) | |
tree | 515f595cd9f0102d3187aec1d961dcb49fd46c68 | |
parent | 0ef4c3a0d1c33e86e78100eb7d0d72093b88c077 (diff) | |
download | classpath-e4bdb9cbf32f1c8ac328acae4e63b361e3f47092.tar.gz |
2006-05-29 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* gnu/java/awt/peer/gtk/GdkGraphics2D.java (translate):
Rewritten.
* examples/gnu/classpath/examples/swing/FillRect.java (paintComponent):
Optionally paint with translation. (createContent): Added option
to test painting with translation
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | examples/gnu/classpath/examples/swing/FillRect.java | 39 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GdkGraphics2D.java | 29 |
3 files changed, 71 insertions, 5 deletions
@@ -1,3 +1,11 @@ +2006-05-29 Audrius Meskauskas <AudriusA@Bioinformatics.org> + + * gnu/java/awt/peer/gtk/GdkGraphics2D.java (translate): + Rewritten. + * examples/gnu/classpath/examples/swing/FillRect.java (paintComponent): + Optionally paint with translation. (createContent): Added option + to test painting with translation + 2006-05-29 Raif S. Naffah <raif@swiftdsl.com.au> * java/util/logging/FileHandler.java (FileHandler): Set the instance field diff --git a/examples/gnu/classpath/examples/swing/FillRect.java b/examples/gnu/classpath/examples/swing/FillRect.java index 0c5566958..11e208d85 100644 --- a/examples/gnu/classpath/examples/swing/FillRect.java +++ b/examples/gnu/classpath/examples/swing/FillRect.java @@ -37,6 +37,7 @@ public class FillRect LCDCanvas lcd; Worker worker; JLabel label; + JCheckBox translate; int nx = 64; int ny = 64; @@ -48,6 +49,11 @@ public class FillRect long lastMillis = System.currentTimeMillis(); boolean enableRepaints = true; + + /** + * If true, test translation. + */ + boolean testTranslation = false; public void actionPerformed(ActionEvent e) { @@ -71,8 +77,22 @@ public class FillRect lcd = new LCDCanvas(); label = new JLabel(); label.setText("paintComponent took 00 msec. (00000 fillRect calls)"); + + translate = new JCheckBox("translate"); + translate.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent event) + { + testTranslation = translate.isSelected(); + } + }); + + JPanel bottom = new JPanel(); + bottom.add(label); + bottom.add(translate); + p.add(lcd, BorderLayout.CENTER); - p.add(label, BorderLayout.SOUTH); + p.add(bottom, BorderLayout.SOUTH); add(p); } @@ -123,6 +143,9 @@ public class FillRect g.fillRect(0, 0, sx, sy); Color pixelColor = null; + + int dx, dy; + for (int ix = 0; ix < nx; ix++) { for (int iy = 0; iy < ny; iy++) @@ -131,9 +154,19 @@ public class FillRect pixelColor = activePixel; else pixelColor = passivePixel; - + + dx = 4 * ix; + dy = 4 * iy; g.setColor(pixelColor); - g.fillRect(4 * ix, 4 * iy, 3, 3); + + if (testTranslation) + { + g.translate(dx, dy); + g.fillRect(0, 0, 3, 3); + g.translate(-dx, -dy); + } + else + g.fillRect(dx, dy, 3, 3); } } diff --git a/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/gnu/java/awt/peer/gtk/GdkGraphics2D.java index 0a42d7fd5..74a72fcea 100644 --- a/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -746,10 +746,35 @@ public class GdkGraphics2D extends Graphics2D { transform(AffineTransform.getScaleInstance(sx, sy)); } - + + /** + * Translate the system of the co-ordinates. As translation is a frequent + * operation, it is done in an optimised way, unlike scaling and rotating. + */ public void translate(double tx, double ty) { - transform(AffineTransform.getTranslateInstance(tx, ty)); + // 200 -> 140 + if (transform != null) + transform.translate(tx, ty); + else + transform = AffineTransform.getTranslateInstance(tx, ty); + + if (clip != null) + { + // FIXME: this should actuall try to transform the shape + // rather than degrade to bounds. + Rectangle2D r; + + if (clip instanceof Rectangle2D) + r = (Rectangle2D) clip; + else + r = clip.getBounds2D(); + + r.setRect(r.getX() - tx, r.getY() - ty, r.getWidth(), r.getHeight()); + clip = r; + } + + setTransform(transform); } public void translate(int x, int y) |