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();
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 두 수의 최대 공약수 구하 기 (세 가지 방법)자바 두 수의 최대 공약수 구하 기 (세 가지 방법) 1. 역법 전에 저도 몰 랐 습 니 다. 인터넷 에서 찾 아 봤 는데 0 과 0 이 아 닌 수의 약 수 는 모두 이 0 이 아 닌 숫자 입 니 다. 결실 2. 전...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.