use of blue.orchestra.blueSynthBuilder.BSBGroup in project blue by kunstmusik.
the class BSBObjectViewHolder method getContextMenu.
private static ContextMenu getContextMenu() {
if (MENU == null) {
MENU = new ContextMenu();
MenuItem cut = new MenuItem("Cut");
cut.setOnAction(e -> {
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
selection.cut();
});
MenuItem copy = new MenuItem("Copy");
copy.setOnAction(e -> {
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
selection.copy();
});
MenuItem remove = new MenuItem("Remove");
remove.setOnAction(e -> {
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
selection.remove();
});
MenuItem makeGroup = new MenuItem("Make Group");
makeGroup.setOnAction(e -> {
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
List<BSBGroup> groupsList = data.groupsList;
List<BSBObject> bsbObjs = selection.selection.stream().map(b -> b.deepCopy()).collect(Collectors.toList());
int x = Integer.MAX_VALUE;
int y = Integer.MAX_VALUE;
for (BSBObject bsbObj : bsbObjs) {
x = Math.min(x, bsbObj.getX());
y = Math.min(y, bsbObj.getY());
}
for (BSBObject bsbObj : bsbObjs) {
bsbObj.setX(bsbObj.getX() - x + 10);
bsbObj.setY(bsbObj.getY() - y + 10);
}
selection.remove();
BSBGroup group = new BSBGroup();
group.interfaceItemsProperty().addAll(bsbObjs);
group.setX(x);
group.setY(y);
groupsList.get(groupsList.size() - 1).addBSBObject(group);
});
MenuItem breakGroup = new MenuItem("Break Group");
breakGroup.setOnAction((ActionEvent e) -> {
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
List<BSBGroup> groupsList = data.groupsList;
BSBGroup group = (BSBGroup) selection.selection.toArray()[0];
int x = group.getX();
int y = group.getY();
selection.remove();
BSBGroup rootGroup = groupsList.get(groupsList.size() - 1);
for (BSBObject bsbObj : group) {
BSBObject temp = bsbObj.deepCopy();
temp.setX(temp.getX() + x);
temp.setY(temp.getY() + y);
rootGroup.addBSBObject(temp);
}
;
});
final Menu align = new Menu("Align");
final Menu distribute = new Menu("Distribute");
EventHandler<ActionEvent> alignListener = ae -> {
MenuItem source = (MenuItem) ae.getSource();
Alignment alignment = (Alignment) source.getUserData();
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
AlignmentUtils.align(selection.getSelectedNodes(), alignment);
};
EventHandler<ActionEvent> distributeListener = ae -> {
MenuItem source = (MenuItem) ae.getSource();
Alignment alignment = (Alignment) source.getUserData();
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
AlignmentUtils.distribute(selection.getSelectedNodes(), alignment);
};
for (Alignment alignment : Alignment.values()) {
MenuItem a = new MenuItem(alignment.toString());
a.setUserData(alignment);
a.setOnAction(alignListener);
MenuItem d = new MenuItem(alignment.toString());
d.setUserData(alignment);
d.setOnAction(distributeListener);
align.getItems().add(a);
distribute.getItems().add(d);
}
MENU.getItems().addAll(cut, copy, remove);
MENU.getItems().addAll(new SeparatorMenuItem(), makeGroup, breakGroup);
MENU.getItems().addAll(new SeparatorMenuItem(), align, distribute);
MENU.setOnHidden(e -> MENU.setUserData(null));
MENU.setOnShowing(e -> {
MenuData data = (MenuData) MENU.getUserData();
BSBEditSelection selection = data.selection;
align.setDisable(selection.selection.size() < 2);
distribute.setDisable(selection.selection.size() < 2);
breakGroup.setDisable(selection.selection.size() != 1 || selection.selection.stream().noneMatch((x) -> x instanceof BSBGroup));
});
}
return MENU;
}
use of blue.orchestra.blueSynthBuilder.BSBGroup in project blue by kunstmusik.
the class BSBEditPane method getEditorForBSBObject.
private BSBObjectViewHolder getEditorForBSBObject(BSBObject bsbObj) {
Region objectView = BSBObjectEditorFactory.getView(bsbObj);
BooleanProperty editEnabledProperty = allowEditing ? bsbInterface.editEnabledProperty() : null;
BSBObjectViewHolder viewHolder = new BSBObjectViewHolder(editEnabledProperty, selection, groupsList, objectView);
if (objectView instanceof EditModeOnly) {
if (allowEditing) {
viewHolder.visibleProperty().bind(bsbInterface.editEnabledProperty());
} else {
viewHolder.setVisible(false);
}
}
if (bsbObj instanceof BSBGroup) {
BSBGroupView bsbGroupView = (BSBGroupView) objectView;
bsbGroupView.initialize(editEnabledProperty, selection, groupsList);
}
return viewHolder;
}
use of blue.orchestra.blueSynthBuilder.BSBGroup in project blue by kunstmusik.
the class BSBGroupView method addBSBObject.
protected void addBSBObject(BSBObject bsbObj) {
try {
Region objectView = BSBObjectEditorFactory.getView(bsbObj);
// FIXME
// BooleanProperty editEnabledProperty = allowEditing ? bsbInterface.editEnabledProperty() : null;
BSBObjectViewHolder viewHolder = new BSBObjectViewHolder(editEnabledProperty, selection, groupsList, objectView);
if (objectView instanceof EditModeOnly) {
if (editEnabledProperty != null) {
viewHolder.visibleProperty().bind(editEnabledProperty);
} else {
viewHolder.setVisible(false);
}
}
if (bsbObj instanceof BSBGroup) {
BSBGroupView bsbGroupView = (BSBGroupView) objectView;
bsbGroupView.initialize(editEnabledProperty, selection, groupsList);
}
editorPane.getChildren().add(viewHolder);
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
}
Aggregations