IMB 의 Zest 문서 학습 코드

16641 단어 공부 하 다.
첫 번 째 프로그램:
public class FirstZest { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              //    Graph 
              Graph graph = new Graph(shell, SWT.NONE); 
              //         
              GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
              //           
              GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
              //       
              new GraphConnection(graph, SWT.NONE, startNode, endNode); 
              //        
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                            LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 

              //    SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 
두 번 째 프로그램: 그림 과 연결 화살 표를 설정 합 니 다.
public class FirstZest2 { 

	public static void main(String[] args) { 
		// SWT 
		Display display = new Display(); 
		Shell shell = new Shell(display); 
		shell.setText("First Zest Program Demo"); 
		shell.setLayout(new FillLayout()); 
		shell.setSize(300, 300); 

		Graph graph = new Graph(shell, SWT.NONE); 
		graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); 
		Image startIcon = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
		GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start", startIcon);  
		GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
		new GraphConnection(graph, SWT.NONE, startNode, endNode); 
		graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
				LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 

		shell.open(); 
		while (!shell.isDisposed()) { 
			while (!display.readAndDispatch()) { 
				display.sleep(); 
			} 
		} 
	} 
} 

 
 
그림% 1 개의 캡 션 을 편 집 했 습 니 다.
 public class FirstZest3 { 

       public static void main(String[] args) { 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              Graph graph = new Graph(shell, SWT.NONE); 
              GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
              GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
              new GraphConnection(graph, SWT.NONE, startNode, endNode); 
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                            LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              
              //           
              graph.addSelectionListener(new SelectionAdapter() { 
                    @Override 
                    public void widgetSelected(SelectionEvent e) { 
                           List selection = ((Graph) e.widget).getSelection(); 
                           //           
                           if (selection.size() == 1) { 
                                  Object o = selection.get(0); 
                                  //       
                                  if (o instanceof GraphNode) { 
                                         //       
                                         ((GraphNode) o).setBorderWidth(3); 
                                  //       
                                  } else if (o instanceof GraphConnection) { 
                                         //       
                                         ((GraphConnection) o).setLineWidth(3); 
                                  } 
                           } 
                    } 
              }); 

              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 
 
서로 다른 레이아웃 관리자 알고리즘 테스트:
 public class FirstZest4 { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 


              Graph graph = new Graph(shell, SWT.NONE); 
              graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); 
              for (int i = 0; i < 10; i++) { 
                 GraphNode node1 = new GraphNode(graph, ZestStyles.NODES_FISHEYE, 
                         "Begin"); 
                 GraphNode node2 = new GraphNode(graph, ZestStyles.NODES_FISHEYE, 
                         "Middle"); 
                 GraphNode node3 = new GraphNode(graph, ZestStyles.NODES_FISHEYE, 
                         "Finish"); 
                 new GraphConnection(graph, SWT.NONE, node1, node2); 
                 new GraphConnection(graph, SWT.NONE, node2, node3); 
              } 
              graph.setLayoutAlgorithm(new GridLayoutAlgorithm(
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              /* 
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              graph.setLayoutAlgorithm(new RadialLayoutAlgorithm( 
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              graph.setLayoutAlgorithm(new DirectedGraphLayoutAlgorithm( 
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              */

              //    SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 
 
맞 춤 형 레이아웃 관리자:
public class FirstZest5 { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              Graph graph = new Graph(shell, SWT.NONE); 
              graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); 
              GraphNode node1 = new GraphNode(graph, SWT.NONE, "Node 1"); 
              GraphNode node2 = new GraphNode(graph, SWT.NONE, "Node 2"); 
              GraphNode node3 = new GraphNode(graph, SWT.NONE, "Node 3"); 
              new GraphConnection(graph, SWT.NONE, node1, node2); 
              new GraphConnection(graph, SWT.NONE, node2, node3); 
              graph.setLayoutAlgorithm(new AbstractLayoutAlgorithm(SWT.NONE) { 
                 int totalNodes; 

                 protected int getCurrentLayoutStep() { 
                     return 0; 
                 } 

                 protected int getTotalNumberOfLayoutSteps() { 
                     return totalNodes; 
                 } 

                 protected boolean isValidConfiguration(boolean asynchronous, 
                         boolean continuous) { 
                     return true; 
              } 

                 protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, 
                         InternalRelationship[] relationshipsToConsider) { 
                 } 

                 protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, 
                         InternalRelationship[] relationshipsToConsider, double x, 
                         double y, double width, double height) { 
                 } 
                 public void setLayoutArea(double x, double y, double width, 
                         double height) { 
                 }

				@Override
				protected void applyLayoutInternal(
						InternalNode[] entitiesToLayout,
						InternalRelationship[] relationshipsToConsider,
						double boundsX, double boundsY, double boundsWidth,
						double boundsHeight) {
                    //          
                    totalNodes = entitiesToLayout.length; 
                    //         
                    double spcaing = 100; 
                    //       
                    int startX = 10; 
                    //       
                    fireProgressStarted(totalNodes); 
                    //       ,              
                    for (int curNode = 0; curNode < entitiesToLayout.length; curNode++) { 
                        LayoutEntity layoutEntity = entitiesToLayout[curNode] 
                                .getLayoutEntity(); 
                        //            
                        layoutEntity.setLocationInLayout(startX, layoutEntity 
                                .getYInLayout()+10); 
                        //        
                        startX += spcaing; 
                        //           
                        fireProgressEvent(curNode, totalNodes); 
                    } 
                    //       
                    fireProgressEnded(totalNodes); 
					// TODO Auto-generated method stub
				}
              }, true); 
              
              //    SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 
 
사용자 정의 그림:
public class FirstZest6 { 

	public static void main(String[] args) { 
		// SWT 
		Display display = new Display(); 
		Shell shell = new Shell(display); 
		shell.setText("First Zest Program Demo"); 
		shell.setLayout(new FillLayout()); 
		shell.setSize(300, 300); 

		Graph graph = new Graph(shell, SWT.NONE); 
		GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
		EllipseGraphNode ellipseNode = new EllipseGraphNode(graph, SWT.NONE, "ellipse"); 
		GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 

		//       
		new GraphConnection(graph, SWT.NONE, startNode, ellipseNode); 
		new GraphConnection(graph, SWT.NONE, ellipseNode, endNode); 
		//        
		graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
				LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 

		//    SWT 
		shell.open(); 
		while (!shell.isDisposed()) { 
			while (!display.readAndDispatch()) { 
				display.sleep(); 
			} 
		} 
	} 
} 

class EllipseGraphNode extends CGraphNode { 
	public EllipseGraphNode(IContainer graphModel, int style, IFigure figure) { 
		super(graphModel, style, figure); 
	}

	public EllipseGraphNode(IContainer graphModel, int style, String name) { 
		super(graphModel, style, createEllipseFigure(name)); 
	}

	private static IFigure createEllipseFigure(String name) { 
		EllipseFigure circleFigure = new EllipseFigure(name); 
		circleFigure.setSize(-1, -1); 
		return circleFigure; 
	}

} 

class EllipseFigure extends Figure { 


	public EllipseFigure(String name) { 
		//       
		Label label = new Label(name); 
		//            
		ToolbarLayout layout = new ToolbarLayout(); 
		setLayoutManager(layout); 
		setBorder(new LineBorder(ColorConstants.white, 1)); 
		setOpaque(true); 

		add(label); 
	} 
	//       ,           ,          Zest     
	@Override 
	public void paint(Graphics graphics) { 
		super.paint(graphics); 
		//          
		Rectangle rectangle = getBounds().getCopy(); 
		graphics.setLineWidth(2); 
		//    
		graphics.drawOval(rectangle); 
	} 
} 

 
 
드래그 하지 않도록 설정:
package com.iteye.xmind.draw2d.zest2;

import java.util.Iterator;
import java.util.List;

import org.eclipse.draw2d.SWTEventDispatcher;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

public class FirstZest7 { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              //    Graph 
              Graph graph = new Graph(shell, SWT.NONE); 
              //         
              GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
              //           
              GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
              //       
              new GraphConnection(graph, SWT.NONE, startNode, endNode); 
              //        
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                            LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
      		graph.getLightweightSystem().setEventDispatcher( 
    				new SWTEventDispatcher() { 
    					public void dispatchMouseMoved(MouseEvent me) { 
    						List selection = ((Graph) me.widget).getSelection(); 
    						for (Iterator iterator = selection.iterator(); iterator.hasNext();) { 
    							Object object = (Object) iterator.next(); 
    							if (object instanceof GraphNode) { 
    								String nodeName = ((GraphNode) object).getText(); 
    								if ("Start".equalsIgnoreCase(nodeName)) { 
    									//     Start     ,      
    								} else { 
    									//       ,    
    									super.dispatchMouseMoved(me); 
    								} 
    							} 
    						} 
    					} 
    				}); 
              //    SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

좋은 웹페이지 즐겨찾기