use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSWTExample method createSimpleNode.
/**
* Creates a SimpleNode
* @param name
* @return SimpleNode
*/
private SimpleNode createSimpleNode(String name) {
SimpleNode simpleNode = new SimpleNode(name);
// an initial approximation of the width
int w = name.length() * 8;
simpleNode.setSizeInLayout(Math.max(w, INITIAL_NODE_WIDTH), INITIAL_NODE_HEIGHT);
return simpleNode;
}
use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSWTExample method placeRandomly.
/**
* Places nodes randomly on the screen *
*/
private void placeRandomly() {
for (Iterator iter = entities.iterator(); iter.hasNext(); ) {
SimpleNode simpleNode = (SimpleNode) iter.next();
double x = Math.random() * INITIAL_PANEL_WIDTH - INITIAL_NODE_WIDTH;
double y = Math.random() * INITIAL_PANEL_HEIGHT - INITIAL_NODE_HEIGHT;
simpleNode.setLocationInLayout(x, y);
}
}
use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSWTExample method createTreeGraph.
/**
* @param maxLevels Max number of levels wanted in tree
* @param maxChildren Max number of children for each node in the tree
* @param random Whether or not to pick random number of levels (from 1 to maxLevels) and
* random number of children (from 1 to maxChildren)
*/
private void createTreeGraph(int maxLevels, int maxChildren, boolean random) {
entities = new ArrayList();
relationships = new ArrayList();
// ccallendar - testing out having 2 roots
SimpleNode root = createSimpleNode(getNextID());
entities.add(root);
SimpleNode root2 = createSimpleNode(getNextID());
entities.add(root2);
// end
SimpleNode currentParent = createSimpleNode(getNextID());
entities.add(currentParent);
// ccallendar - adding relationships from the parent to the 2 roots
SimpleRelationship rel = new SimpleRelationship(root, currentParent, false);
root.addRelationship(rel);
currentParent.addRelationship(rel);
relationships.add(rel);
rel = new SimpleRelationship(root2, currentParent, false);
root2.addRelationship(rel);
currentParent.addRelationship(rel);
relationships.add(rel);
// end
int levels = random ? (int) (Math.random() * maxLevels + 1) : maxLevels;
createTreeGraphRecursive(currentParent, maxChildren, levels, 1, random);
}
use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSWTExample method createMainPanel.
private void createMainPanel() {
mainComposite = new Canvas(mainShell, SWT.NO_BACKGROUND);
GridData mainGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_FILL, true, true);
mainGridData.widthHint = INITIAL_PANEL_WIDTH;
mainGridData.heightHint = INITIAL_PANEL_HEIGHT;
mainComposite.setLayoutData(mainGridData);
mainComposite.addPaintListener(new GraphPaintListener());
mainComposite.setBackground(new Color(255, 255, 255));
mainComposite.setLayout(null);
mainComposite.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (selectedEntity == null) {
// Nothing selected, lets use a mouse hover
SimpleNode oldEntity = hoverEntity;
hoverEntity = null;
for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null; ) {
SimpleNode entity = (SimpleNode) iter.next();
double x = entity.getX();
double y = entity.getY();
double w = entity.getWidth();
double h = entity.getHeight();
Rectangle rect = new Rectangle((int) x, (int) y, (int) w, (int) h);
if (rect.contains(e.x, e.y)) {
hoverEntity = entity;
hoverEntity.ignoreInLayout(true);
hoverEntity.setSelected();
break;
}
}
if (oldEntity != null && oldEntity != hoverEntity) {
oldEntity.ignoreInLayout(false);
oldEntity.setUnSelected();
}
}
}
});
mainComposite.addMouseListener(new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
}
@Override
public void mouseDown(MouseEvent e) {
selectedEntity = null;
hoverEntity = null;
for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null; ) {
SimpleNode entity = (SimpleNode) iter.next();
double x = entity.getX();
double y = entity.getY();
double w = entity.getWidth();
double h = entity.getHeight();
Rectangle rect = new Rectangle((int) x, (int) y, (int) w, (int) h);
if (rect.contains(e.x, e.y)) {
selectedEntity = entity;
}
}
if (selectedEntity != null) {
mouseDownPoint = new Point(e.x, e.y);
selectedEntityPositionAtMouseDown = new Point((int) selectedEntity.getX(), (int) selectedEntity.getY());
selectedEntity.ignoreInLayout(true);
selectedEntity.setSelected();
} else {
mouseDownPoint = null;
selectedEntityPositionAtMouseDown = null;
}
}
@Override
public void mouseUp(MouseEvent e) {
if (selectedEntity != null) {
selectedEntity.ignoreInLayout(false);
selectedEntity.setUnSelected();
List relatedNodes = selectedEntity.getRelatedEntities();
for (Iterator iter = relatedNodes.iterator(); iter.hasNext(); ) {
SimpleNode element = (SimpleNode) iter.next();
element.setUnSelected();
}
SimpleRelationship[] rels = selectedEntity.getRelationships();
for (int i = 0; i < rels.length; i++) {
rels[i].resetLineWidth();
}
}
selectedEntity = null;
mouseDownPoint = null;
selectedEntityPositionAtMouseDown = null;
}
});
// stops the algorithm when the window is closed
mainComposite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (currentLayoutAlgorithm != null) {
currentLayoutAlgorithm.stop();
}
}
});
mainComposite.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (selectedEntity != null && mouseDownPoint != null) {
double dx = e.x - mouseDownPoint.x;
double dy = e.y - mouseDownPoint.y;
selectedEntity.setLocation(selectedEntityPositionAtMouseDown.x + dx, selectedEntityPositionAtMouseDown.y + dy);
mainComposite.redraw();
}
}
});
}
use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSwingExample method placeRandomly.
/**
* Places nodes randomly on the screen *
*/
private void placeRandomly() {
for (Iterator iter = entities.iterator(); iter.hasNext(); ) {
SimpleNode simpleNode = (SimpleNode) iter.next();
double x = Math.random() * INITIAL_PANEL_WIDTH - INITIAL_NODE_WIDTH;
double y = Math.random() * INITIAL_PANEL_HEIGHT - INITIAL_NODE_HEIGHT;
simpleNode.setLocationInLayout(x, y);
simpleNode.setSizeInLayout(INITIAL_NODE_WIDTH, INITIAL_NODE_HEIGHT);
}
}
Aggregations