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.
          主站蜘蛛池模板: 刚察县| 札达县| 容城县| 措勤县| 盈江县| 兰溪市| 大方县| 涿州市| 锦州市| 上蔡县| 望奎县| 泰安市| 仙游县| 巢湖市| 贺州市| 日喀则市| 苏尼特左旗| 临泉县| 依安县| 呼图壁县| 天柱县| 彩票| 台北县| 宜阳县| 阳泉市| 杭锦后旗| 福贡县| 文成县| 司法| 临沂市| 台南市| 江山市| 白玉县| 宝坻区| 桐城市| 齐河县| 桂林市| 云浮市| 开江县| 新津县| 黄大仙区|