Weird Node Resizing Problem [message #894775] |
Tue, 10 July 2012 13:21 |
Saurabh Srivastava Messages: 7 Registered: June 2012 |
Junior Member |
|
|
Hi,
I am building a Zest based Graph Drawing Tool. I use some Complex Draw2d Figures as My Nodes. I am facing a strange problem, that I am not able to track.
My nodes have a "collapsible" part. which can be expanded or collapsed on a Label click. It all works fine to start with. The nodes get shrunk or expanded, as I click on the Label.
However, if I drag my nodes a bit, and then try to Collapse/Expand my nodes, my "node won't resize itself".
I tried repainting my node's figure, but it didn't helped. Can anyone suggest what may be going wrong??
The Screen shots of the problem are also attached.
-
Attachment: Screen 1.bmp
(Size: 125.93KB, Downloaded 924 times) -
Attachment: Screen 2.bmp
(Size: 573.94KB, Downloaded 1021 times) -
Attachment: Screen 3.bmp
(Size: 319.97KB, Downloaded 967 times) -
Attachment: Screen 4.bmp
(Size: 478.25KB, Downloaded 976 times)
[Updated on: Tue, 10 July 2012 13:22] Report message to a moderator
|
|
|
Re: Weird Node Resizing Problem [message #894925 is a reply to message #894775] |
Wed, 11 July 2012 06:26 |
Saurabh Srivastava Messages: 7 Registered: June 2012 |
Junior Member |
|
|
Ok, SO I found the problem after a lot of debugging. I am posting my experience, just in case its of help to someone else.
I am using Zest 1.1 for drawing my Graphs. It has a Class called GraphNode, which acts as a Starting Point if you want to have Custom Nodes in your Graph. So I just extended this Class and added my Figures to be used as the Node Figures.
There is, however, a method called refreshLocation() in this Class. This is called whenever there is a Drag Event on a Node, and the node is repositioned. The code for the same is below:
protected void refreshLocation() {
Point loc = this.getLocation();
Dimension size = this.getSize();
Rectangle bounds = new Rectangle(loc, size);
if (nodeFigure == null || nodeFigure.getParent() == null) {
return; // node figure has not been created yet
}
//nodeFigure.setBounds(bounds);
nodeFigure.getParent().setConstraint(nodeFigure, bounds);
}
See the Last Line in the Method, that is doing the major work,
nodeFigure.getParent().setConstraint(nodeFigure, bounds);
It sets the Constraints on the Node Figure. However, see the Lines:
Dimension size = this.getSize();
Rectangle bounds = new Rectangle(loc, size);
Which essentially would never allow the Figure to resize at all !!
Since we'll keep using the "previous" size, the new size is never calculated.
I've overridden that method in my own class, copied the above code in my method, and just changed one line:
Dimension size = new Dimension(-1, -1);
That does the trick.... Hope it may have been already changed in later versions of Zest !!
|
|
|
|
Powered by
FUDForum. Page generated in 0.04219 seconds