Dengues Studio: Google Group:http://groups.google.com/group/dengues; QQ Group:24885404.
          一般來說我們很難計算兩個節點之間的顯示名稱的位置,而且還要包括名稱字符串的大小。這個是在Dengues里面實現的效果:
          圖一:

          圖二:

          你可以看Dengues源代碼:
          org.dengues.designer.ui.process.models.CompConnectionLabel
           1 /**
           2      * Qiang.Zhang.Adolf@gmail.com Comment method "changeLocation".
           3      */
           4     public void changeLocation() {
           5         Point point = new Point();
           6 
           7         int x = connection.getSource().getLocation().x;
           8         int x2 = connection.getTarget().getLocation().x;
           9 
          10         int width = x2 > x ? connection.getSource().getSize().width : connection.getTarget().getSize().width;
          11         int abs = Math.abs(x2 - x) / 2 - width / 2;
          12         int px = x2 > x ? x + abs + width : x2 + abs + width;
          13 //這個作用是計算字符串getCompName()的大小。
          14         GC gc = new GC(Display.getDefault());
          15         org.eclipse.swt.graphics.Point stringExtent = gc.stringExtent(getCompName());
          16         gc.dispose();
          17         px = px - stringExtent.x / 2;
          18         point.x = px;
          19 
          20         int y = connection.getSource().getLocation().y;
          21         int y2 = connection.getTarget().getLocation().y;
          22 
          23         int height = y2 > y ? connection.getSource().getSize().height : connection.getTarget().getSize().height;
          24         abs = Math.abs(y2 - y) / 2 - height / 2;
          25         int py = y2 > y ? y + abs + height : y2 + abs + height;
          26         py = py - stringExtent.y;
          27         point.y = py;
          28         setLocation(point);
          29     }
          這樣的好就可以計算中間的位置。


          Dengues論壇(http://groups.google.com/group/dengues/),一個很好的Eclipse開發者樂園.

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          Dengues Studio: Google Group:http://groups.google.com/group/dengues; QQ Group:24885404.
          主站蜘蛛池模板: 五大连池市| 浦东新区| 广丰县| 类乌齐县| 湾仔区| 古浪县| 临朐县| 辛集市| 邵武市| 宜宾县| 绥德县| 耿马| 阳曲县| 滨海县| 榆树市| 共和县| 彰化市| 绵阳市| 金华市| 河津市| 屯留县| 和顺县| 西吉县| 滨州市| 叶城县| 冕宁县| 乌拉特后旗| 西贡区| 肇州县| 南充市| 新乐市| 方正县| 涪陵区| 咸阳市| 额敏县| 南宫市| 五大连池市| 禄丰县| 斗六市| 治多县| 华阴市|