<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[JavaRanch: Latest posts for the topic "Subclassing Graphics2D"]]></title>
		<link>http://www.coderanch.com/forums/t/2/Swing-AWT-SWT-JFace/Subclassing-Graphics-D</link>
		<description><![CDATA[Latest messages posted in the topic "Subclassing Graphics2D"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Subclassing Graphics2D</title>
				<description><![CDATA[One article that I read about testing GUI intensive applications suggested subclassing the Graphics object to provide a textual representation of the calls made on it (<a class="snap_shots" href="http://c2.com/cgi/wiki?ExtremeProgrammingTestingGuiIntensiveApps" target="_new" rel="nofollow">http://c2.com/cgi/wiki?ExtremeProgrammingTestingGuiIntensiveApps</a>) my question is, since the Graphics object is propagated by the Swing components that control the rendering of individual controls, how can one substitute a subclass in a coherent manner. One solution I can think of is something like this:<br /> <br /> <pre>public class FooComponent {

   private final SpecialGraphics2D wrapper;

   public FooComponent(SpecialGraphics2D special) {
       wrapper = special;
   }

   public JComponent getComponent() {
      return new JComponent() {
         @Override
         public void paintComponent(Graphics g) {
            Graphics2D g2d = wrapper.wrap((Graphics2D)g);
            doStuffWith(g2d)
         }
      };
   }
   
   //Elsewhere
   String log = wrapper.logString();
}</pre><br /> <br /> But since you would have to add the boilerplate to every GUI class, that seems a bit clumsy. Is there a better way where the Graphics subclass will automatically get propogated throughout the system?<br />        <br />       ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450620/2005725</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450620/2005725</link>
				<pubDate><![CDATA[Sun, Jun 21 2009 01:46:21 MDT]]></pubDate>
				<author><![CDATA[Garrett Rowe]]></author>
			</item>
			<item>
				<title>Subclassing Graphics2D</title>
				<description><![CDATA[I don't have an answer to that, but <a class="snap_shots" href="http://java.freehep.org/vectorgraphics/apidocs/" target="_new" rel="nofollow">here's a library</a> that contains several subclasses of Graphics2D; maybe its source code provides some clues.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450620/2006565</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450620/2006565</link>
				<pubDate><![CDATA[Mon, Jun 22 2009 02:23:26 MDT]]></pubDate>
				<author><![CDATA[Ulf Dittmer]]></author>
			</item>
			<item>
				<title>Subclassing Graphics2D</title>
				<description><![CDATA[Thanks for the link Ulf. Looking at the tutorials for that library, the two use cases that I see are either constructing the Graphics2D subclass and calling paint(Graphics) directly with the newly created subclass.<br /> <pre>
SpecialGraphics graph = new SpecialGraphics();
myPanel.paint(graph)</pre><br /> <br /> Or wrapping the Graphics object inside an overridden paint(Graphics) method:<br /> <pre>
@Override
public void paint(Graphics g) {
   SpecialGraphics graph = new SpecialGraphics(g);
   //do stuff here...
}</pre><br /> <br /> I guess the first version would be better for the unit testing strategy discussed in the link. That was so simple I don't know why it was escaping me.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450620/2007809</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450620/2007809</link>
				<pubDate><![CDATA[Tue, Jun 23 2009 09:18:17 MDT]]></pubDate>
				<author><![CDATA[Garrett Rowe]]></author>
			</item>
	</channel>
</rss>
