use of com.kotcrab.vis.ui.util.dialog.InputDialogListener in project HyperLap2D by rednblackgames.
the class GraphContainer method setupListeners.
private void setupListeners() {
addListener(new ClickListener(Input.Buttons.RIGHT) {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!containedInWindow(x, y)) {
NodeGroupImpl nodeGroup = null;
for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
Rectangle rectangle = nodeGroupEntry.getValue();
if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
// Hit the label
nodeGroup = nodeGroupEntry.getKey();
break;
}
}
if (nodeGroup != null) {
final NodeGroupImpl finalNodeGroup = nodeGroup;
H2DPopupMenu popupMenu = new H2DPopupMenu();
MenuItem rename = new MenuItem("Rename group");
rename.addListener(new ClickListener(Input.Buttons.LEFT) {
@Override
public void clicked(InputEvent event, float x, float y) {
Dialogs.showInputDialog(getStage(), "Enter group name", "Name", new InputValidator() {
@Override
public boolean validateInput(String input) {
return !input.trim().isEmpty();
}
}, new InputDialogListener() {
@Override
public void finished(String input) {
finalNodeGroup.setName(input.trim());
fire(new GraphChangedEvent(false, false));
}
@Override
public void canceled() {
}
}).setText(finalNodeGroup.getName(), true);
}
});
popupMenu.addItem(rename);
MenuItem remove = new MenuItem("Remove group");
remove.addListener(new ClickListener(Input.Buttons.LEFT) {
@Override
public void clicked(InputEvent event, float x, float y) {
nodeGroups.remove(finalNodeGroup);
fire(new GraphChangedEvent(false, false));
}
});
popupMenu.addItem(remove);
showPopupMenu(popupMenu);
} else {
H2DPopupMenu popupMenu = popupMenuProducer.createPopupMenu(x, y);
showPopupMenu(popupMenu);
}
}
}
});
addListener(new ClickListener(Input.Buttons.LEFT) {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
processLeftClick(x, y);
return super.touchDown(event, x, y, pointer, button);
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button);
processLeftClick(x, y);
}
});
DragListener dragListener = new DragListener() {
private float canvasXStart;
private float canvasYStart;
private NodeGroup dragGroup;
private float movedByX = 0;
private float movedByY = 0;
@Override
public void dragStart(InputEvent event, float x, float y, int pointer) {
if (event.getTarget() == GraphContainer.this) {
canvasXStart = canvasX;
canvasYStart = canvasY;
movedByX = 0;
movedByY = 0;
dragGroup = null;
for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
Rectangle rectangle = nodeGroupEntry.getValue();
if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
// Hit the label
dragGroup = nodeGroupEntry.getKey();
break;
}
}
}
}
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
if (event.getTarget() == GraphContainer.this) {
if (dragGroup != null) {
movingSelected = true;
float moveByX = x - getDragStartX() - movedByX;
float moveByY = y - getDragStartY() - movedByY;
for (String nodeId : dragGroup.getNodeIds()) {
getBoxWindow(nodeId).moveBy(moveByX, moveByY);
}
movedByX += moveByX;
movedByY += moveByY;
windowsMoved();
updateNodeGroups();
movingSelected = false;
} else {
navigateTo(canvasXStart + getDragStartX() - x, canvasYStart + getDragStartY() - y);
}
}
}
};
dragListener.setTapSquareSize(0f);
dragListener.setButton(Input.Buttons.MIDDLE);
addListener(dragListener);
}
Aggregations