Multiple calls [message #550862] |
Wed, 04 August 2010 14:14 |
Deepak Singla Messages: 27 Registered: December 2009 |
Junior Member |
|
|
Hi,
In GEF application, I am using view objects as classes that extends the draw2d.Figure class.
Inside the classes I have implemented the paintFigure (graphics g) and setBound(Rect r) methods for setting colors property and bounds property for rectangles and other drawing object respectively.
Everything is working fine. But I am surprised that there are n number of calls for method setBound and paintFigure methods. It can hit the performance of my application.
Do you have any idea what could be the reason for this and any Idea to stop multiples calls to these method?
One More Thing I noticed about this behaviour: these method are called infinite time untill your view is displayed inside the editor. If you minimize your editor, the calling to these method stops. But when both are open simultaneously, the calling is going on...!!!!!!!!!!!!!!!!!!!!!!
Any Idea would be appreciated
[Updated on: Wed, 04 August 2010 15:39] Report message to a moderator
|
|
|
Re: Multiple calls [message #551685 is a reply to message #550862] |
Mon, 09 August 2010 07:20 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
Can you please prove the code for the extended figure...
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
Re: Multiple calls [message #552447 is a reply to message #551685] |
Thu, 12 August 2010 09:35 |
Deepak Singla Messages: 27 Registered: December 2009 |
Junior Member |
|
|
Here is my figure class extending the Figure
public class NodeFigure extends Figure {
//... lot of declaration of instance varaibles
/**
* Constructor
*/
public NodeFigure(String labelString) {
setLayoutManager(new XYLayout());
nodeLabel = new Label();
nodeLabel.setText(labelString);
this.roundedRect.setCornerDimensions(cornerDimensions);
this.shadowNode.setCornerDimensions(cornerDimensions);
roundedRect.setForegroundColor(blackColor);
toolTipLabel = new Label();
this.toolTipLabel.setBorder(new MarginBorder(2, 2, 2, 2));
add(nodeLabel);
}
/**
* Constructor
*/
public NodeFigure(String labelString, boolean isStartNode) {
this(labelString);
this.isStartNode = isStartNode;
startIconRoundedRectangle.setBackgroundColor(nodeFillColor);
startIconRoundedRectangle.setForegroundColor(nodeFillColor);
if(this.isStartNode == true){
startIconRoundedRectangle.setBackgroundColor(startFillColor) ;
startLabel = new Label();
this.startLabel.setIcon(START_NODE_ICON);
add(startLabel);
}
}
/*
* (non-Javadoc)
* @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Gra phics)
*/
public void paintFigure(Graphics graphics) {
//System.out.println("Graphics method is called::-----graphics is not null check::"+graphics);
graphics.setBackgroundColor(shadowColor);
graphics.setForegroundColor(shadowColor);
graphics.fillRoundRectangle(shadowNode.getBounds(), 7, 7);
if(this.isPresentation){
nodeFillColor = jspNodeFillColor;
}else{
nodeFillColor = new Color(null, 230, 230, 255);
}
if(this.isStartNode == false){
roundedRect.setForegroundColor(ColorConstants.black);
roundedRect.setBackgroundColor(nodeFillColor);
roundedRect.setFill(true);
add(roundedRect);
add(nodeLabel);
}
if(this.isStartNode == true){
graphics.setForegroundColor(startFillColor);
graphics.setBackgroundColor(nodeFillColor);
graphics.fillGradient(roundedRect.getBounds().x+1,roundedRec t.getBounds().y, (roundedRect.getBounds().width/3),roundedRect.getBounds().he ight, false);
graphics.setForegroundColor(nodeFillColor);
graphics.setBackgroundColor(nodeFillColor);
graphics.fillRoundRectangle(new Rectangle((roundedRect.getBounds().x+ roundedRect.getBounds().width/3), roundedRect.getBounds().y, roundedRect.getBounds().width*2/3,roundedRect.getBounds().he ight), 7, 7);
roundedRect.setForegroundColor(blackColor);
roundedRect.setFill(false);
add(roundedRect);
add(startLabel);
}
if(this.isPresentation || this.isImplementation){
add(propertyLabel);
}
}
/*
* Creates the bounds for the figure.
* (non-Javadoc)
* @see org.eclipse.draw2d.Figure#setBounds(org.eclipse.draw2d.geome try.Rectangle)
*/
public void setBounds(Rectangle rect) {
super.setBounds(rect);
//System.out.println("inside the setBound method of Figure class");
//bounds for the rounded rectangle
rectangle = new Rectangle();
rectangle.height=rect.height-2;
rectangle.width=rect.width-2;
rectangle.x=rect.x;
rectangle.y= rect.y;
//bounds for a shadow rectangle
Rectangle shadowBoundsRect = new Rectangle();
shadowBoundsRect.height=rect.height;
shadowBoundsRect.width=rect.width;
shadowBoundsRect.x=rect.x;
shadowBoundsRect.y= rect.y;
//bounds for the start icon
startIconRectangle = new Rectangle();
startIconRectangle.x = rect.x+1;
startIconRectangle.y = rect.y+1;
startIconRectangle.width = 17;
startIconRectangle.height= rect.height-4;
/* bounds for the Node Label text rectangle i.e should be start after icon rectangle*/
Rectangle textLabelWithStartRectangle = new Rectangle();
textLabelWithStartRectangle.x = rect.x + 16;
textLabelWithStartRectangle.y = rect.y+5;
textLabelWithStartRectangle.width = rect.width-20;
textLabelWithStartRectangle.height= rect.height-15;
/* bounds for the Node Label text rectangle when there is no start icon*/
Rectangle textLabelRectangle = new Rectangle();
textLabelRectangle.x = rect.x +5;
textLabelRectangle.y = rect.y;
textLabelRectangle.width = rect.width-8;
textLabelRectangle.height= rect.height-2;
this.shadowNode.setBounds(shadowBoundsRect);
this.roundedRect.setBounds(rectangle);
if(this.isStartNode){
this.nodeLabel.setBounds(textLabelWithStartRectangle);
this.startLabel.setBounds(startIconRectangle);
}else{
this.nodeLabel.setBounds(textLabelRectangle);
}
startIconRoundedRectangle.setBounds(startIconRectangle);
if(this.isImplementation || this.isPresentation){
propertyIconRectangle = new Rectangle();
propertyIconRectangle.x = rect.x+rect.width-20;
propertyIconRectangle.y = rect.y;
propertyIconRectangle.width = 18;
propertyIconRectangle.height =rect.height;
propertyLabel.setBounds(propertyIconRectangle);
}
}
}
|
|
|
Re: Multiple calls [message #553418 is a reply to message #552447] |
Tue, 17 August 2010 13:32 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
The painfigure method contains adding of child figures this in tern calles the paintfigure again hence it is being called infinitly...
also adding children triggers layout changes which in tern calles setbounds and again painfigure method and so on...
remove adding children code from paintfigure method,instead put them in the specific property change method like setPresentation or setStartNodeMethods....
always avoid adding children, layout,changing properties like setFont,setBackground,setForeground of self or children in paintFigure method...
hope this solves your problem...
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
Powered by
FUDForum. Page generated in 0.05935 seconds