File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace and the fly likes Subclassing Graphics2D Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Subclassing Graphics2D" Watch "Subclassing Graphics2D" New topic
Author

Subclassing Graphics2D

Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
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 (http://c2.com/cgi/wiki?ExtremeProgrammingTestingGuiIntensiveApps) 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:



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?



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32421
I don't have an answer to that, but here's a library that contains several subclasses of Graphics2D; maybe its source code provides some clues.


Android appsImageJ pluginsJava web charts
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
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.


Or wrapping the Graphics object inside an overridden paint(Graphics) method:


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.

This message was edited 1 time. Last update was at by Garrett Rowe

 
 
subject: Subclassing Graphics2D
 
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture