惡魔的尾巴

          JGraph學習筆記

          看這樣一段代碼:

           1    protected JGraph createGraph() {
           2        JGraph graph = new MyGraph(new MyModel());
           3        graph.getGraphLayoutCache().setFactory(new DefaultCellViewFactory() {
           4
           5            // Override Superclass Method to Return Custom EdgeView
           6            protected EdgeView createEdgeView(Object cell) {
           7
           8                // Return Custom EdgeView
           9                return new EdgeView(cell) {
          10
          11                    /**
          12                     * Returns a cell handle for the view.
          13                     * 這里是返回一個Handle(對這個線條事件的執(zhí)行器)
          14                     */

          15                    public CellHandle getHandle(GraphContext context) {
          16                    
          17                        return new MyEdgeHandle(this, context);
          18                    }

          19
          20                }
          ;
          21            }

          22        }
          );
          23        return graph;
          24    }
          其中 setFactory是用來設置一個工廠類對象的,而這里的工廠類對象繼承了DefaultCellViewFactory,這里覆蓋了EdgeView,作用是產生一個自定義的EdgeView,來渲染特定的線形效果。
          而 其中返回的EdgeView是被覆蓋了getHandle方法的類,這個handle是用來處理這個線接受的事件。
          看下述的Handle的代碼:
              public static class MyEdgeHandle extends EdgeView.EdgeHandle {

                  
          /**
                   * 
          @param edge
                   * 
          @param ctx
                   
          */

                  
          public MyEdgeHandle(EdgeView edge, GraphContext ctx) {
                      
          super(edge, ctx);
                  }

                  
          //這個方法是用來添加一個方法,判斷是否要在線條上添加一個斷點,終于試出來了,不爽,看來做事還是要靜心下來才能做
                  
          // Override Superclass Method
                  public boolean isAddPointEvent(MouseEvent event) {
                      
          // Points are Added using Shift-Click
                      return event.isShiftDown();
                      
          //return false;
                  }

                  
          //這個方法是用來添加一個方法,判斷是否要在線條消除一個斷點。
                  
          // Override Superclass Method
                  public boolean isRemovePointEvent(MouseEvent event) {
                      
          // Points are Removed using Shift-Click
                      return event.isShiftDown();
                  }


              }
          其中isAddPointEvent和isRemovePointEvent兩個方法分別是用來回調判斷何時加入和刪除線條的中間斷點。

          posted on 2007-08-23 14:33 惡魔的尾巴 閱讀(870) 評論(0)  編輯  收藏


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          <2007年8月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 古交市| 巍山| 武功县| 北安市| 平阴县| 莆田市| 石泉县| 天镇县| 岱山县| 翁源县| 藁城市| 乡宁县| 行唐县| 拉孜县| 东乡族自治县| 通道| 商洛市| 炎陵县| 马山县| 建湖县| 沙洋县| 政和县| 新宾| 文昌市| 武夷山市| 四平市| 汉中市| 巴彦县| 雷山县| 铜山县| 和平县| 新龙县| 尉氏县| 西盟| 二连浩特市| 依安县| 巢湖市| 金塔县| 平顺县| 凌源市| 灵石县|