Re: A few questions about
To: comp.lang.java.gui
In article
<48f456c3$0$10592$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
"Qu0ll" <Qu0llSixFour@gmail.com> wrote:
"John B. Matthews" <nospam@nospam.invalid> wrote in message
news:nospam-C24B39.11234813102008@news.motzarella.org...
Hi John,
Thanks for the reply.
I ran the code and see no problems. I am running jdk1.6.0_03 on Suse
Linux 10.2
Looks right on Mac OS X 10.4.11, Java 1.5.0_16. Also, you can use the
AffineTransform to do the translate followed by the scale:
I am using Java 6 Update 10 RC2 on Windows Vista. Thanks for the tip on
combining the transforms - that's really useful. However, it still has the
same problems on my setup.
I am intrigued by the questions you raised up-thread about rendering
errors while scaling. I have seen a few such anomalies on Windows XP.
They tend to be small, off-by-one-pixel errors that are magnified by
scaling: lines that don't meet, circles that aren't circular.
I know that Java2D and Mac OS Quartz (and Linux GDK?) model graphics
devices using "Coordinates [that] are infinitely thin and lie between
the pixels of the output device." I have been told that Windows uses a
slightly different model, but I was using older systems (Java 1.4.2 &
Windows XP).
If you get a chance to run the example on a Mac, use accessibility
magnification or the Pixie tool to see the difference:
/Developer/Applications/Graphics Tools/Pixie.app
I was able to produce some artifact on Mac OS by adding diagonal lines
having CAP_SQUARE ends. Using CAP_ROUND precludes the problem. This
example lines up perfectly on my implementation at all sizes, weights,
aspects and magnifications I tried:
<code>
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TransTest extends JFrame {
private class MyPanel extends JPanel {
@Override
public void paintComponent(final Graphics g) {
final Graphics2D g2d = (Graphics2D)g;
final double scaleX = this.getWidth() / 100.0;
final double scaleY = this.getHeight() / 100.0;
final BasicStroke stroke = new BasicStroke(4f,
BasicStroke.CAP_ROUND , BasicStroke.JOIN_ROUND);
g2d.setStroke(stroke);
final AffineTransform at = new AffineTransform(
AffineTransform.getScaleInstance(scaleX, scaleY));
at.translate(10, 10);
g2d.transform(at);
g2d.setColor(Color.darkGray);
g2d.drawRect(0, 0, 80, 80);
fade(g2d);
g2d.drawLine(0, 40, 80, 40);
fade(g2d);
g2d.drawLine(40, 0, 40, 80);
fade(g2d);
g2d.drawLine(0, 0, 80, 80);
fade(g2d);
g2d.drawLine(80, 0, 0, 80);
}
}
private void fade(Graphics2D g2d) {
Color color = g2d.getColor();
g2d.setColor(color.brighter());
}
public TransTest() {
this.setLayout(new BorderLayout());
final MyPanel panel = new MyPanel();
this.add(panel, BorderLayout.CENTER);
panel.setBackground(Color.WHITE);
this.pack();
this.setSize(543, 567);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
}
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new TransTest().setVisible(true);
}
});
}
}
</code>
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24