package com.qualityeclipse.genealogy.view;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import com.qualityeclipse.genealogy.listener.*;
public class main {
public static void main(String[] args) {
Shell shell= new Shell(new Display());
shell.setSize(800, 600);
shell.setText("DTF Parametereingabe mit Drag and Drop Funktion");
shell.setLayout(new GridLayout());
Canvas canvas = createDiagram(shell);
canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
Display display = shell.getDisplay();
shell.open();
while (!shell.isDisposed()) {
while (!display.readAndDispatch()) {
display.sleep();
}
}
}
private static Canvas createDiagram(Composite parent) {
Figure root = new Figure();//root Figure und simples Layout erzeugen
root.setFont(parent.getFont()); //setze Font für root Figure, dass jedes Lable korrekt kalkuliert wird
XYLayout layout = new XYLayout();
root.setLayoutManager(layout);
Canvas canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);//canvas erzeugen um root Figur zu erzeugen
canvas.setBounds(10, 10, 100, 100); //groeße und position von Canvas festlegen funktioneirt nicht!
canvas.setBackground(ColorConstants.white); // Hintergrundfarbe bestimmen
LightweightSystem lws = new LightweightSystem(canvas);
//create Sensor Figure
IFigure sensor = createSensorFigure("Sensor");
root.add(sensor);
layout.setConstraint(sensor,
new Rectangle (new Point(300, 200), sensor.getPreferredSize()));
//create AKtuator Figure
IFigure aktuator = createAktuatorFigure("Aktuator");
root.add(aktuator);
layout.setConstraint(aktuator,
new Rectangle (new Point(700, 200), aktuator.getPreferredSize()));
//create Super Element
IFigure Super = createSuperFigure("Super Element");
root.add(Super,
new Rectangle(new Point (450, 50),
Super.getPreferredSize()));
root.add(connect(sensor, Super));
root.add(connect(Super, aktuator));
// create Button
Button button = new Button("Create txt File for Simulation");
root.add(button,
new Rectangle(575, 532, 200, 20));
Group group = new Group(canvas, 0);
group.setBounds(5, 5, 200, 600);
//group.setBackground(ColorConstants.gray);
group.setText("Auswahl der Elemente:");
lws.setContents(root);
return canvas;
}
private static IFigure connect(IFigure figure1, IFigure figure2) {
PolylineConnection connection = new PolylineConnection();
connection.setSourceAnchor(new ChopboxAnchor(figure1));
connection.setTargetAnchor(new ChopboxAnchor(figure2));
return connection;
}
private static IFigure createSuperFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.darkGray);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(150, 350);
rectangleFigure.add(new Label(name));
return rectangleFigure;
}
//private RectangleFigure createAktuatorFigure(String name) {
private static IFigure createAktuatorFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.lightBlue);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(50, 50);
rectangleFigure.add(new Label(name));
//new FigureMover(rectangleFigure);
return rectangleFigure;
}
private static IFigure createSensorFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.lightGray);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(50, 50);
rectangleFigure.add(new Label(name));
return rectangleFigure;
}
}package com.qualityeclipse.genealogy.view;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
public class main {
public static void main(String[] args) {
Shell shell= new Shell(new Display());
shell.setSize(800, 600);
shell.setText("DTF Parametereingabe mit Drag and Drop Funktion");
shell.setLayout(new GridLayout());
Canvas canvas = createDiagram(shell);
canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
Display display = shell.getDisplay();
shell.open();
while (!shell.isDisposed()) {
while (!display.readAndDispatch()) {
display.sleep();
}
}
}
private static Canvas createDiagram(Composite parent) {
Figure root = new Figure();//root Figure und simples Layout erzeugen
root.setFont(parent.getFont()); //setze Font für root Figure, dass jedes Lable korrekt kalkuliert wird
XYLayout layout = new XYLayout();
root.setLayoutManager(layout);
Canvas canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);//canvas erzeugen um root Figur zu erzeugen
canvas.setBounds(10, 10, 100, 100); //groeße und position von Canvas festlegen funktioneirt nicht!
canvas.setBackground(ColorConstants.white); // Hintergrundfarbe bestimmen
LightweightSystem lws = new LightweightSystem(canvas);
/*
private IFigure createPersonFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.lightGray);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(50, 50);
rectangleFigure.add(new Lable(name));
return rectangleFigure;
}
IFigure sensor = createPersonFigure("Sensor");
root.add(sensor
layout.setConstraint(sensor,
new Rectangle (new Point(20, 20), sensor.getPreferredSize()));
IFigure aktuator = createPersonFigure("Aktuator");
root.add(aktuator);
layout.setConstraint(aktuator,
new Rectangle (new Point(120, 120), aktuator.getPreferredSize()));
}
*/
Button button = new Button("Create txt File for Simulation");
root.add(button,
new Rectangle(575, 532, 200, 20));
Group group = new Group(canvas, 0);
group.setBounds(5, 5, 200, 600);
//group.setBackground(ColorConstants.gray);
group.setText("Auswahl:");
lws.setContents(root);
return canvas;
}
private static IFigure createPersonFigure(String string) {
// TODO Auto-generated method stub
return null;
}
}