Skip to main content

I need to draw labeled node in graph

6 replies [Last post]
m7md_3cs_fci
Offline
Joined: 2008-05-19
Points: 0

Hi every body,
I need to draw labeled node in graph,
I use this code:

<br />
import java.lang.*;<br />
import java.util.*;<br />
import javafx.ui.*;<br />
import javafx.ui.canvas.*;</p>
<p>class GraphNode extends  CompositeNode{<br />
    attribute x:Number;<br />
    attribute y:Number;<br />
    attribute title:String;<br />
    attribute stroke:Paint;<br />
    attribute fill:Paint;<br />
    attribute t:Text = Text{<br />
       transform: bind Transform.translate(x - c.radiusX+10, y - c.radiusY+10)<br />
    	content: title<br />
    };<br />
    attribute c:Ellipse = Ellipse {<br />
        cursor: Cursor.HAND<br />
        cx: bind x<br />
        cy: bind y<br />
       radiusX: bind ((t.currentWidth + 20)/2.0)<br />
       radiusY: bind ((t.currentHeight + 20)/2.0)<br />
        stroke: stroke<br />
        strokeWidth: 2<br />
        fill: fill<br />
        onMouseDragged: function(e: CanvasMouseEvent) {<br />
            x += e.localDragTranslation.x;<br />
            y += e.localDragTranslation.y;<br />
        }<br />
    };<br />
    function composeNode(){<br />
        Group {<br />
            content:[c ,t]<br />
        }<br />
    }<br />
}<br />

this code throw Stack overflow Exception.
can anyone help me in solving this problem, or give me another way to draw this node?
thanx in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
m7md_3cs_fci
Offline
Joined: 2008-05-19
Points: 0

Thanks for your help,
but i get this Exception:
Unexpected exception caught in MasterTimer.timePulse():
java.lang.StackOverflowError

:(

alexsch
Offline
Joined: 2007-07-12
Points: 0

Do you get the Exception using this simple code:

[code]
Frame{
title: "Hello World!"
content: Canvas{
content: GraphNode{
title: "Title"
x: 100
y: 100
stroke: Color.BLUE
fill: Color.ORANGE

}
}
visible: true
}
[/code]

If no, may be there is an recursion in your code?

alexsch
Offline
Joined: 2007-07-12
Points: 0

I can't reproduce the problem. I use the GraphNode in the following code:

[code]
Frame{
title: "Hello World!"
content: Canvas{
content: GraphNode{
title: "Title"
x: 100
y: 100
stroke: Color.BLUE
fill: Color.ORANGE

}
}
visible: true
}
[/code]

One suggestion is to define text and Ellipse components in composeNode() function, like:

[code]
function composeNode(){
Group {
content:[Text{
transform: bind Transform.translate(x - c.radiusX+10, y - c.radiusY+10)
content: title
} ,
Ellipse {
cursor: Cursor.HAND
cx: bind x
cy: bind y
radiusX: bind ((t.currentWidth + 20)/2.0)
radiusY: bind ((t.currentHeight + 20)/2.0)
stroke: stroke
strokeWidth: 2
fill: fill
onMouseDragged: function(e: CanvasMouseEvent) {
x += e.localDragTranslation.x;
y += e.localDragTranslation.y;
}
}]
}
}
[/code]

It reduces number of attributes.

m7md_3cs_fci
Offline
Joined: 2008-05-19
Points: 0

thanks, but
c.radiusX will get compilation error and also t.currentWidth will get
and what i'll gain if i rduce the number of attributes??

alexsch
Offline
Joined: 2007-07-12
Points: 0

It is just a question of language style preference.
Defining an attribute for each UI component is more imperative style ( it is similar to Java language) and defining UI components in one UI tree is more declarative style.

The advantage is that your declare only necessary attributes in your class.
For example, if your class needs to have radiusX, radiusY and currentWidth, currentHeight attributes, you can define you class in the following way:

[code]
class GraphNode extends CompositeNode{
attribute x:Number;
attribute y:Number;

attribute title:String;
attribute stroke:Paint;
attribute fill:Paint;

attribute radiusX:Number;
attribute radiusY:Number;

attribute width :Number = 100 on replace{ radiusX = (width + 20)/2.0 };
attribute height:Number = 100 on replace{ radiusY = (height + 20)/2.0 };

function composeNode(){
Group {
content:[
Ellipse {
cursor: Cursor.HAND
cx: bind x
cy: bind y
radiusX: bind radiusX with inverse
radiusY: bind radiusY with inverse
stroke: stroke
strokeWidth: 2
fill: fill
onMouseDragged: function(e: CanvasMouseEvent) {
x += e.localDragTranslation.x;
y += e.localDragTranslation.y;
}
},Text{
transform: bind Transform.translate(x - radiusX+10, y - radiusY+10)
content: title
currentWidth: bind width with inverse
currentHeight: bind height with inverse

}]
}
}
}
[/code]

m7md_3cs_fci
Offline
Joined: 2008-05-19
Points: 0

thanks