The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Java 2D

Thread: Problem with layers

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 2 - Last Post: Aug 14, 2008 2:45 PM by: robross Threads: [ Previous | Next ]
xtomiii

Posts: 17
Problem with layers
Posted: Aug 13, 2008 5:04 AM
 
  Click to reply to this thread Reply

Hello

I'm creating simple shape editor.

I have a little problem with calling repaint() on the whole JPanel, because i show also grid in the background.

For example when I'm doing multiple selection, just because I want to show current selection boundary I have to repaint everything ... grid, geometry, selection box.

So my question is:
Is it possible to create more ovelaping layers and each one renders only itself ? (analogy to glasspane)

I'd like to have:
1st layer ... grid
2nd layer ... geometry
3rd layer ... guides, select boxes .. a.s.o.

Anyone can point me out to solution? Or a pages? Thanks a lot lot !!!

Tomas

ser207

Posts: 12
Re: Problem with layers
Posted: Aug 14, 2008 11:28 AM   in response to: xtomiii
 
  Click to reply to this thread Reply

I've come across this from a Sun book published in 1999, "Java 2D API Graphics"
http://java.sun.com/developer/Books/2dgraphics/chapter6.html

What i would like to know is, 9 years on is this the best way to do it? Is there an alternate framwork, method or pattern?

robross

Posts: 59
Re: Problem with layers
Posted: Aug 14, 2008 2:45 PM   in response to: ser207
 
  Click to reply to this thread Reply

The basic concepts of Java2D are based on the basic concepts of computer graphics, and they have been explored since the 1960's. So a lot of the core concepts are as relevant today as they were in 1999. The painter's model is the key abstraction. When you paint, paint the objects in the background before the objects in the foreground, because foreground objects obscure background objects.

The latest modern design strategy centers around the concept of "Painters." This is just a delegate object that does the actual painting. So instead of having a single paint() method in a component that does all the work, that component now calls out to its Painter delegate to do the actual painting. This allows for a more flexible design since you can swap out painters as needed to produce different effects, and you can combine painters to do combination of effects.

The Filthy Rich Clients book discusses this concept in great detail, and the SwingX project in SwingLabs uses this model extensively in its components.




 XML java.net RSS