paintFigure [message #1715218] |
Fri, 20 November 2015 10:35 |
Swaroop Shastri Messages: 7 Registered: November 2015 |
Junior Member |
|
|
Hello All,
I have written GEF application and I have some concern over following code which gets called repeatedly. Also when I see jconsole/j virual machine, I see lot of memory is held by Rectangle figure.
public class MyFigure extends Figure implements IFiigure
...
protected void paintFigure(Graphics graphics) {
Rectangle r = getBounds().getCopy();
setConstraint(shape, new Rectangle(0, 0, r.width, r.height));
setConstraint(nameLabel, new Rectangle(0, 0, r.width, r.height));
shape.invalidate();
nameLabel.invalidate();
}
Can any one tell me , is there any better method / approach apart from this we can use to paint the figure.
I see new Rectangle(0, 0, r.width, r.height)) gets called continuously so I want to cache this figure and pass only if it has changed .
Also,I want to understand the flow, how GEF renders the canvas, figure and entire lifecycle , methods, classes etc, which it uses to render a flow/figure.
|
|
|
Re: paintFigure [message #1715272 is a reply to message #1715218] |
Fri, 20 November 2015 17:45 |
|
Figure uses PRIVATE_RECT for this purpose. You could do the same, i.e. cache the Rectangle instance, and not create a new instance each time.
|
|
|
Re: paintFigure [message #1715292 is a reply to message #1715272] |
Sat, 21 November 2015 06:06 |
Swaroop Shastri Messages: 7 Registered: November 2015 |
Junior Member |
|
|
Thanks for the reply,
I did try, creating a static variable and then passing it to the figure
setConstraint(shape, PRIVATE_RECT);
setConstraint(nameLabel, PRIVATE_RECT);
but, still I see that i can see the outer body (rectangle) but now label disappears.. If I pass new instance, it works.I want to understand
setConstraint(shape, PRIVATE_RECT);
setConstraint(nameLabel, new Rectangle(0, 0, r.width, r.height));
Any idea ?
|
|
|
|
|
|
Re: paintFigure [message #1715628 is a reply to message #1715336] |
Tue, 24 November 2015 18:16 |
Swaroop Shastri Messages: 7 Registered: November 2015 |
Junior Member |
|
|
Here is my code.
Let me know if you want any other class to be looked at..
public class MyFigure extends Figure implements IFigure {
private Label nameLabel;
private RoundedRectangle shape;
private ConnectionAnchor connectionAnchor;
public MyFigure {
setLayoutManager(new XYLayout());
shape = new RoundedRectangle();
shape.setCornerDimensions(new Dimension(50,50));
shape.setFill(true);
shape.setBackgroundColor(ColorConstants.green);
add(shape);
nameLabel = new Label();
add(nameLabel);
}
@Override
protected void paintFigure(Graphics graphics) {
Rectangle r = getBounds().getCopy();
setConstraint(shape, new Rectangle(0, 0, r.width, r.height));
setConstraint(nameLabel, new Rectangle(0, 0, r.width, r.height));
shape.invalidate();
nameLabel.invalidate();
}
public Label getNameLabel() {
return nameLabel;
}
public ConnectionAnchor getConnectionAnchor() {
if (connectionAnchor == null) {
connectionAnchor = new ChopboxAnchor(this);
}
return connectionAnchor;
}
}
[Updated on: Tue, 24 November 2015 18:17] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02756 seconds