• Post Reply Bookmark Topic Watch Topic
  • New Topic

HELP ! Best Architecture for Swing Paint Tools  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would really, really appreciate any help you can offer. I have been working on this problem for several saturdays and sundays and still don't have a good solution.
Imagine a Swing application that emulates a football (or any other sport) coaches "paint" program.
Using the football metaphor...
The basic application extends a JFrame and has a Border Layout. There is a menu bar and a tool bar has been added to the component's South layout position. In the CENTER there is a JScrollPane that represents the football field, has grid lines drawn on it, etc. There's fully functional borders and corners. The field is Green, the gris markers are black.
Allright...now let's say coach wants to draw to the Panel of the JScrollPane. For example, he wants to draw polygons that represent "Zones" of coverage in a different color. Ultimately all objects, grids, players, zones, goalposts, etc will be drawon on the ContentPane...
So...let's start drawing an object...say a Zone Polygon.
Here's the basic problem.
1) If the bounds of the polygon are drawn with XOR Mode to the Graphics object that is the panel of the JScrollPanel, it is very difficult to control cleanly the colors of the lines that are drawn in this 'rubber band' mode.
2) If the entire contents of the field are redrawn with each mouse movement, the flicker is unacceptable.
3) Additionally, there are other objects that need to be drawn in a pseudo-animation style, like down field 'view windows' having arcs representing start and stopping points of these windows. Sort of a super-paint/CAD model.
1) I think basic XOR mode is unacceptable because of the multiple colors crossing other zones, players, objects, grid lines, etc. it is just too ugly.
2) I've tried drawing on the glassPane, but have all kinds of issues. The first is that when I do a clearRect (on the entire glassPane) it still requires the children components to be redrawn. Update...the whole thing becomes opaque (grey). Then there is the (simple) problem that lines can be drawn OVER the scrollbars, corner buttons, etc. Yuk.
3) My latest attempt seems better but I need some help and sanity checking. I have added a 'drawingPanel'..a JPanel...to the JLayeredPane of the basic JFrame that is transparent. The thinking is that XOR or clearing this will work leaving the field in tact...well...XOR doesn't seem to work...it just keeps drawing and leaving pecker tracks. clearRect is just making the opaque background again. I haven't even crossed the JScrollpane x,y mapping (though this seems relatively straightforward with SwingUtilities). This is why I've asked several times about XOR on a transparency.
So...there you have it. In affect, it is not unlike the Windows Paint accessory and should work similarly. I'm having a dickens of a time making it as smooth and flicker free.
Is my approach sound ? Is the use of the JLayeredPane appropriate ? Is there something much easier that I'm just to thickheaded to see ?
Thank you very, very much. Any help is so greatly appreciated.
The Halfordian Golfer
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!