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,來渲染特定的線形效果。


2

3



4

5

6



7

8

9



10

11


12

13

14

15



16

17

18

19

20

21

22

23

24

而 其中返回的EdgeView是被覆蓋了getHandle方法的類,這個handle是用來處理這個線接受的事件。
看下述的Handle的代碼:
































