use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSwingExample method createMainPanel.
private void createMainPanel() {
// see below for class definition
mainPanel = new MainPanel();
mainPanel.setPreferredSize(new Dimension(INITIAL_PANEL_WIDTH, INITIAL_PANEL_HEIGHT));
mainPanel.setBackground(Color.WHITE);
mainPanel.setLayout(null);
mainFrame.getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER);
mainPanel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
selectedEntity = 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();
Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
if (rect.contains(e.getX(), e.getY())) {
selectedEntity = entity;
}
}
if (selectedEntity != null) {
mouseDownPoint = e.getPoint();
selectedEntityPositionAtMouseDown = new Point((int) selectedEntity.getX(), (int) selectedEntity.getY());
} else {
mouseDownPoint = null;
selectedEntityPositionAtMouseDown = null;
}
updateGUI();
}
@Override
public void mouseReleased(MouseEvent e) {
selectedEntity = null;
mouseDownPoint = null;
selectedEntityPositionAtMouseDown = null;
updateGUI();
}
});
mainPanel.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
// if (selectedEntity != null) {
// //TODO: Add mouse moving
// //selectedEntity.setLocationInLayout(selectedEntityPositionAtMouseDown.x + dx, selectedEntityPositionAtMouseDown.y + dy);
// updateGUI();
// }
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
}
use of org.eclipse.zest.layouts.exampleStructures.SimpleNode in project archi by archimatetool.
the class SimpleSWTExample method createTreeGraphRecursive.
private void createTreeGraphRecursive(SimpleNode currentParentNode, int maxChildren, int maxLevel, int level, boolean random) {
if (level > maxLevel) {
return;
}
int numChildren = random ? (int) (Math.random() * maxChildren + 1) : maxChildren;
for (int child = 0; child < numChildren; child++) {
SimpleNode childNode = createSimpleNode(getNextID());
entities.add(childNode);
SimpleRelationship rel = new SimpleRelationship(currentParentNode, childNode, false);
childNode.addRelationship(rel);
currentParentNode.addRelationship(rel);
relationships.add(rel);
SimpleRelationship.setDefaultSize(2);
createTreeGraphRecursive(childNode, maxChildren, maxLevel, level + 1, random);
}
}
Aggregations