• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Subclassing Graphics2D

 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic