1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.vci.client.omd.lifecycle.ui;
 
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.GraphTransferHandler;
 
 
 
public class WestJpanel extends JGraph{
    /**
     * 
     */
    private static final long serialVersionUID = 3283671560611467556L;
    Map<String,String> map = new HashMap<String,String>();
    public WestJpanel(){
        initUI();
        this.updateUI();
    }
    public void initUI(){
        map = new LifeCycleReadXml().lifecycle();
        Set<String> key=map.keySet();
        ArrayList<DefaultGraphCell> cells = new ArrayList<DefaultGraphCell>();
        // model���ڿ������ģ����ʾ���Եȣ�view���ڿ������ͼ����ʾ���ԣ����ﶼ��Ĭ�ϼ���
        GraphModel model = new DefaultGraphModel();
        //this.getModel().remove(this.getRoots());
        //this.getModel().remove(this.getRoots());
        this.setModel(model);
        this.updateUI();
        this.setLayout(getLayout());
//        GraphLayoutCache view = new GraphLayoutCache(model,
//        new DefaultCellViewFactory());
////        // JGraph����
//        JGraph graph = new JGraph(model, view);
        // ������ĵ�һ��vertex����
        int i=0;
        int j=0;
        int n=0;
        for (Iterator it = key.iterator(); it.hasNext();) {
            String s =(String) it.next();
            map.get(s);
            
            
            
            DefaultGraphCell dgc = new DefaultGraphCell(s);
            GraphConstants.setBorderColor(dgc.getAttributes(), Color.black);
            cells.add(dgc);
            //GraphConstants.setIcon(cells.get(i).getAttributes(), ii);
            
//            GraphConstants.setBounds(cells.get(i).getAttributes(),
//                    new Rectangle2D.Double(48,48, 48, 48));
            //add by caill start 2016.3.29 生命周期中将所有的状态显示在左侧导航栏中
            if(i>=0){
                if((i%4==0)&&(i != 0)){
                    n++;
                }
                GraphConstants.setBounds(cells.get(i).getAttributes(),
                        new Rectangle2D.Double(78*j, 33*n, 75, 30));
                j++;
                if((i%4==3)&&(i != 0)){
                    j=0;
                }
            }
            GraphConstants.setOpaque(cells.get(i).getAttributes(), true);
            i+=1;
            //add by caill end
            /*if(i>=0&&i<4){
                GraphConstants.setBounds(cells.get(i).getAttributes(),
                        new Rectangle2D.Double(48*i,0, 48, 48));
            }else if(i>=4&&i<8){
                    GraphConstants.setBounds(cells.get(i).getAttributes(),
                            new Rectangle2D.Double(48*j,48, 48, 48));
                j++;
                if(i==7)
                    j=0;
            }else if(i>=8&&i<12){
                
                GraphConstants.setBounds(cells.get(i).getAttributes(),
                        new Rectangle2D.Double(48*j,48*2, 48, 48));
                j++;
                if(i==11)
                    j=0;
            }else if(i>=12&&i<16){
                GraphConstants.setBounds(cells.get(i).getAttributes(),
                        new Rectangle2D.Double(48*j,48*3, 48, 48));
                j++;
                if(i==15)
                    j=0;
            }else if(i>=16&&i<20){
                GraphConstants.setBounds(cells.get(i).getAttributes(),
                        new Rectangle2D.Double(48*j,48*4, 48, 48));
                j++;
                if(i==19)
                    j=0;
            }
            
            
            GraphConstants.setOpaque(cells.get(i).getAttributes(), true);
//            DefaultPort port0 = new DefaultPort();
//            cells.get(i).add(port0);
            i+=1;*/
        }
        // �����϶����cells�������graph����
        Iterator it = cells.iterator();
        while (it.hasNext()) {
            this.getGraphLayoutCache().insert(it.next());
        }
        // һЩgraph����ļ򵥵���
        this.setMoveable(true);//�ɷ��ƶ����ͼ��
        //graph.setDisconnectable(false);//�����ƶ��ߵ�ָ��,���ǿ����ƶ�ͼ��
        //graph.setDisconnectOnMove(true);//�ɷ��ƶ������,�����ڱߵ�Դ���յ�ı��ʧЧ
        { this.setGridEnabled(true); this.setGridVisible(true); } // ��ʾ���
        this.setMoveBelowZero(false); //�Ƿ�����cellԽ�����Ͻ�.ͨ������Ϊfalse,����������ô�
        this.setAntiAliased(true);// Բ��ͼ������
        this.setTransferHandler(new GraphTransferHandler());
        this.setDragEnabled(true);
        this.setTransferHandler(new MyTransferHandler());
        
    }
    
}