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 map = new HashMap(); public WestJpanel(){ initUI(); this.updateUI(); } public void initUI(){ map = new LifeCycleReadXml().lifecycle(); Set key=map.keySet(); ArrayList cells = new ArrayList(); // 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()); } }