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.
          主站蜘蛛池模板: 彰化县| 宁明县| 榆社县| 得荣县| 长泰县| 天津市| 阿巴嘎旗| 周至县| 浪卡子县| 阿克陶县| 波密县| 古浪县| 双峰县| 吴江市| 彭阳县| 楚雄市| 辉南县| 旬邑县| 闸北区| 蒲城县| 通榆县| 汶川县| 新疆| 泰和县| 白水县| 定远县| 镇平县| 彰化市| 五原县| 阜新市| 汝阳县| 江陵县| 邵阳县| 吉水县| 瑞金市| 汾西县| 鸡泽县| 聂拉木县| 濮阳县| 辉县市| 平乡县|