Hi
I'd like to do some dynamic background coloring in SpringLayout.
So I override paint() from GraphDraw and do a call to super.paint() after coloring the background.
But unfortunately GraphDraw.paint() seems to reset the background color every time to default gray, so i have to choose between no nodes or no background coloring :)
Any hint?
Thanx in advance
Till
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In Java -- not just GraphDraw -- paint() starts by painting the background, and then working forwrad. (This, btw, is why we override only paintComponent: it assures that we don't have to take responsibility for the other things on screen.)
Fortunately, paint() respects JComponent settings. And setBackground is the method to set the background color.
so call gd.setBackground( color )
and enjoy.
Danyel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using the new graphdraw component, but this will also working for the old one.
I implemented a custom background (I'm actually using a picture for background) by overriding the paintComponent-method. As this method resets the background, too, I just took the code from the original new graphdraw and put it into my paintComponent method. yes, it's awkward and I will have to update the class if JUNG changes but it works very well.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
OK, seems like this is the only way. As I said, I overwrote paint(), but this didn't do the job. I tried this with paintComponent, too, but only with calling super() before or after doing my backgrounding - no way :( Now I see that I obviously have to _replace_ the whole function as you did... Thank you for the hint!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I extended the interface and added the prepaint() at the very start of paintComponent()... But the vertices and edges are still painted a the gray default background! So my own background gets overwritten every time a node changes.
I can never see nodes and my background together, only a flashing graph - looks awful :(
bg
Till
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK you can't find paintComponent in GraphDraw. but in VisualizationViewer, so I had to hack the whole library :(
@offkey: I'd like to update the background everytime something's changing. There's user data for each vertex (temperature) which modulates the background color, and which is updated very often.
bg
Till
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First, I obviously wasn't thinking much. This would actually take an incompatible break of the Renderer interface to put a setBackground into Renderer.
Ick.
So, yes, the place to get to work here is VisualizationViewer.
What would you think of a VisualizationViewer.setBackgroundFunction() that worked pretty much the same way as the one before?
Your background paint function would paint as a result of state
("setColor(theColorOf(MY_NUM_VERTICES))"
and then, when your state changed, you'd just call GraphDraw.repaint().
Let me play with this tonight and see what hacks I can work out. TWimmer, if you can email me the changes you've made ( offkey@sourceforge.net), I'll use them as a starting point.
Danyel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I'd like to do some dynamic background coloring in SpringLayout.
So I override paint() from GraphDraw and do a call to super.paint() after coloring the background.
But unfortunately GraphDraw.paint() seems to reset the background color every time to default gray, so i have to choose between no nodes or no background coloring :)
Any hint?
Thanx in advance
Till
In Java -- not just GraphDraw -- paint() starts by painting the background, and then working forwrad. (This, btw, is why we override only paintComponent: it assures that we don't have to take responsibility for the other things on screen.)
Fortunately, paint() respects JComponent settings. And setBackground is the method to set the background color.
so call gd.setBackground( color )
and enjoy.
Danyel
I'm using the new graphdraw component, but this will also working for the old one.
I implemented a custom background (I'm actually using a picture for background) by overriding the paintComponent-method. As this method resets the background, too, I just took the code from the original new graphdraw and put it into my paintComponent method. yes, it's awkward and I will have to update the class if JUNG changes but it works very well.
Hi
OK, seems like this is the only way. As I said, I overwrote paint(), but this didn't do the job. I tried this with paintComponent, too, but only with calling super() before or after doing my backgrounding - no way :( Now I see that I obviously have to _replace_ the whole function as you did... Thank you for the hint!
Hm. So would it work if we did something like this? Add one more call to PluggableRenderer:
setPrePaintFunction( PrePaintFunction ppf );
where
public interface PrePaintFunction {
public void prePaint( Graphics g );
}
and paintComponent has a few lines added up front:
public void paintComponent( Graphics g ) {
if prePaintFunction != null
prePaintFunction.prepaint( g );
...
}
PLEASE HELP ME! :/
I extended the interface and added the prepaint() at the very start of paintComponent()... But the vertices and edges are still painted a the gray default background! So my own background gets overwritten every time a node changes.
I can never see nodes and my background together, only a flashing graph - looks awful :(
bg
Till
OK you can't find paintComponent in GraphDraw. but in VisualizationViewer, so I had to hack the whole library :(
@offkey: I'd like to update the background everytime something's changing. There's user data for each vertex (temperature) which modulates the background color, and which is updated very often.
bg
Till
First, I obviously wasn't thinking much. This would actually take an incompatible break of the Renderer interface to put a setBackground into Renderer.
Ick.
So, yes, the place to get to work here is VisualizationViewer.
What would you think of a VisualizationViewer.setBackgroundFunction() that worked pretty much the same way as the one before?
Your background paint function would paint as a result of state
("setColor(theColorOf(MY_NUM_VERTICES))"
and then, when your state changed, you'd just call GraphDraw.repaint().
Let me play with this tonight and see what hacks I can work out. TWimmer, if you can email me the changes you've made ( offkey@sourceforge.net), I'll use them as a starting point.
Danyel