恶魔的尾巴

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(对这个线条事件的执行器)
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 恶魔的尾巴 阅读(842) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(1)

随笔档案

文章档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜