Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » paintFigure(GEF figure (paintfigure ) caching)
paintFigure [message #1715218] Fri, 20 November 2015 10:35 Go to next message
Swaroop Shastri is currently offline Swaroop ShastriFriend
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 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 235
Registered: July 2009
Location: Lünen
Senior Member
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 Go to previous messageGo to next message
Swaroop Shastri is currently offline Swaroop ShastriFriend
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 #1715296 is a reply to message #1715292] Sat, 21 November 2015 09:08 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 235
Registered: July 2009
Location: Lünen
Senior Member
Dumb question, but have you set width and height of PRIVATE_RECT?
Re: paintFigure [message #1715333 is a reply to message #1715296] Sun, 22 November 2015 11:09 Go to previous messageGo to next message
Swaroop Shastri is currently offline Swaroop ShastriFriend
Messages: 7
Registered: November 2015
Junior Member
Yes, I did set it. It did not work. Sad
Re: paintFigure [message #1715336 is a reply to message #1715333] Sun, 22 November 2015 11:57 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 235
Registered: July 2009
Location: Lünen
Senior Member
I would need to see more of your code to help you out then.
Re: paintFigure [message #1715628 is a reply to message #1715336] Tue, 24 November 2015 18:16 Go to previous message
Swaroop Shastri is currently offline Swaroop ShastriFriend
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

Previous Topic:[Zest] Layout implementations and node overlapping
Next Topic:[GEF4] layout in mvc
Goto Forum:
  


Current Time: Sun Nov 18 07:56:31 GMT 2018

Powered by FUDForum. Page generated in 0.02440 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top