2012-07-14 4 views
0

연결의 시작 또는 끝 위치에 레이블을 추가하고 싶습니다. 하지만 여기서는 ManhattanMidpointLocator를 제외한 위치 정보를 찾지 못했습니다. 그러면 어떻게해야합니까? 어떻게 연결된 곳에 레이블을 붙일 수 있습니까?
다음과 같이 내 코드를 찾아주세요,draw2d의 특정 위치에 그림을 추가하는 방법은 무엇입니까?

draw2d.LabelConnection = function() { 
    draw2d.Connection.call(this); 
    this.sourcePort = null; 
    this.targetPort = null; 
    this.lineSegments = []; 
    this.setColor(new draw2d.Color(0, 255, 0)); 
    this.setLineWidth(2); 

    var label = new draw2d.Label("Message"); 
    label.setBackgroundColor(new draw2d.Color(230, 230, 250)); 
    label.setBorder(new draw2d.LineBorder(1)); 
    this.addFigure(label, new draw2d.Locator()); 
}; 

draw2d.LabelConnection.prototype = new draw2d.Connection(); 
draw2d.LabelConnection.prototype.type = "draw2d.LabelConnection"; 

위의 코드는 (0,0) 위치에 라벨을 보여줍니다. plz 나를 도와주세요.

답변

0

사용 :

Connection.getStartPoint()에 연결의 모든 세그먼트를 검색하려면 연결의 시작 지점을 결정하십시오 ( ).

인사말

+0

Connection.getStartPoint() 메서드를 사용하여 오류가 발생합니다. locator.relocate()는 함수가 아닙니다. 제발 도와주세요. 재배치() 메소드를 구현하려고 시도했지만 작동하지 않는 것으로 보인다. –

0

"모든 위치"가 의미하는 바를 잘 모르겠지만 자신의 로케이터를 구현하면 매우 간단합니다.

ManhattanMidpointLocator 코드를 확인하십시오. 재배치 (relocate) 함수에서 캔버스의 연결에 대한 모든 것을 알 수 있습니다. 그로부터 레이블의 위치를 ​​계산할 수 있습니다.

+0

감사합니다. 나는 그것을 얻으려고 노력할 것이다. –

+0

이 레이블을 중간 위치 대신 시작 위치에 배치하려고합니다. 그럼 내가 어떻게 할 수 있니? Locator()를 사용했지만 (0,0) 위치에 위치시킵니다. PLZ 도움? –

0

이제 (테스트하지 않았다) Draw2D 대신에 Graphiti 작업하지만 로케이터에 대한 코드는 다음과 같아야합니다

draw2d.StartConnectionLocator=function(/*:draw2d.Connection*/ connection) 
{ 
    draw2d.ConnectionLocator.call(this,connection); 
}; 
draw2d.StartConnectionLocator.prototype.relocate=function(/*:draw2d.Figure*/ target) 
{ 
    var conn = this.getConnection(); 

    var points = conn.getPoints(); 
    var index = Math.floor((points.getSize() -2)/2); 
    if (points.getSize() <= index+1) 
     return; 

    var startPoint = points.get(0); 
    var myPosition = new draw2d.Point(); 
    myPosition.x = startPoint.x +5; 
    myPosition.y = startPoint.y +5; 

    target.setPosition(myPosition.x,myPosition.y); 
}; 
+0

Andreas는 var startPoint = points.get (0); 대신 connection.getStartPoint()를 사용할 것을 제안했습니다. – Zerzio

+0

connection.getStartPoint()를 사용했지만 오류가 발생합니다. locator.relocate()는 함수가 아닙니다. 그래서 제가 어떻게 재배치 방법을 호출해야하는지 좀 도와주세요. 아래 코드를 찾으십시오 draw2d.ContextmenuConnection = function (src, target) { \t draw2d.Connection.call (this); \t this.sourceAnchor.setOwner (src); \t this.targetAnchor.setOwner (target); \t var label = new draw2d.Label ("Message"); \t this.addFigure (label, this.getStartPoint()); \t var arrowConnector = new draw2d.ArrowConnectionDecorator(); \t arrowConnector.setBackgroundColor (new draw2d.Color (0, 255, 0)); }; –

관련 문제