mainComposite.addPaintListener(new GraphPaintListener());
mainComposite.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
mainComposite.setLayout(null);
mainComposite.addMouseMoveListener(new MouseMoveListener() {
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() {
public void mouseDoubleClick(MouseEvent e) {
}
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;
}
}
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() {
public void widgetDisposed(DisposeEvent e) {
if (currentLayoutAlgorithm != null) {
currentLayoutAlgorithm.stop();
}
}
});
mainComposite.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
if (selectedEntity != null && mouseDownPoint != null) {
double dx = e.x - mouseDownPoint.x;
double dy = e.y - mouseDownPoint.y;