final Label connectionNumber = new Label();
connectionNumber.setStyle("-fx-background-color:rgb(255, 255, 255); -fx-border-color:rgba(0, 0, 0, 0.5); ");
connectionNumber.setVisible(false);
Circle output = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
output.setStroke(Paint.valueOf("black"));
updateText();
Circle[] sockets = new Circle[resources.arity()];
double angle, xPos, yPos;
for (int l = 0; l < sockets.length; l++) {
angle = (((l + 1) / ((double) (resources.arity() + 1))) * Constants.THETA) - (Constants.THETA / 2);
xPos = -Math.cos(angle) * Constants.NODE_RADIUS;
yPos = Math.sin(angle) * Constants.NODE_RADIUS;
sockets[l] = new Circle(xPos, yPos, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
sockets[l].setId(String.valueOf(l));
sockets[l].setStroke(Paint.valueOf("black"));
final Circle s = sockets[l];
final int index = l;
/*
* Mouse event handlers on sockets
*
*/
s.addEventFilter(MouseEvent.DRAG_DETECTED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// the mouse has been dragged out of the socket, this means a full drag is in progress
startFullDrag();
}
});
s.addEventFilter(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// user is hovering over connection socket
connectionNumber.setText("C: " + s.getId());
connectionNumber.relocate(s.getCenterX() + 5, s.getCenterY() - 10);
connectionNumber.setVisible(true);
}
});
s.addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// user exits the connection socket
connectionNumber.setVisible(false);
}
});
s.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// mouse was pressed on the socket
setState(GUIGeneState.SOURCE);
connectionIndex = index;
}
});
s.addEventFilter(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (!parent.isTarget()) {
lines[connectionIndex].setEndX(event.getX() + ((Circle) event.getSource()).getParent().getLayoutX());
lines[connectionIndex].setEndY(event.getY() + ((Circle) event.getSource()).getParent().getLayoutY());
}
}
});
s.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.isStillSincePress()) {
// mouse was released before dragging out of the socket
updateLine(index);