0

接続の開始位置または終了位置にラベルを追加したい。しかし、ここでは ManhattanMidpointLocator 以外のロケーターが見つかりませんでした。では、どうすればこれを行うことができますか?接続先にラベルを貼る方法を教えてください。
以下のように私のコードを見つけてください、

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) の位置にラベルを表示します。助けてください。

4

3 に答える 3

0

「任意の場所」が何を意味するのかはわかりませんが、独自のロケーターを実装する場合は非常に簡単です。

ManhattanMidpointLocator のコードを見てください。再配置機能では、キャンバス上の接続に関するすべてを知っています。そこから、ラベルの位置を計算するだけです。

于 2012-07-16T05:35:07.063 に答える
0

使用する:

Connection.getStartPoint()を使用して、接続のすべてのセグメントを取得する代わりに、接続の開始点を決定します。

ご挨拶

于 2012-07-16T10:03:51.027 に答える
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);
};
于 2012-07-16T08:12:40.643 に答える