Search in sources :

Example 1 with BSBGroup

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;
}
Also used : EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene) BooleanBinding(javafx.beans.binding.BooleanBinding) BoundingBox(javafx.geometry.BoundingBox) MouseEvent(javafx.scene.input.MouseEvent) Bindings(javafx.beans.binding.Bindings) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup) ContextMenu(javafx.scene.control.ContextMenu) Point2D(javafx.geometry.Point2D) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) Pane(javafx.scene.layout.Pane) Color(javafx.scene.paint.Color) MenuItem(javafx.scene.control.MenuItem) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings) Rectangle(javafx.scene.shape.Rectangle) Collectors(java.util.stream.Collectors) Menu(javafx.scene.control.Menu) Cursor(javafx.scene.Cursor) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) Region(javafx.scene.layout.Region) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup)

Example 2 with BSBGroup

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;
}
Also used : BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Region(javafx.scene.layout.Region) EditModeOnly(blue.orchestra.editor.blueSynthBuilder.EditModeOnly) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup)

Example 3 with BSBGroup

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);
    }
}
Also used : Region(javafx.scene.layout.Region) EditModeOnly(blue.orchestra.editor.blueSynthBuilder.EditModeOnly) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup)

Aggregations

BSBGroup (blue.orchestra.blueSynthBuilder.BSBGroup)3 Region (javafx.scene.layout.Region)3 EditModeOnly (blue.orchestra.editor.blueSynthBuilder.EditModeOnly)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 BSBObject (blue.orchestra.blueSynthBuilder.BSBObject)1 GridSettings (blue.orchestra.blueSynthBuilder.GridSettings)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Bindings (javafx.beans.binding.Bindings)1 BooleanBinding (javafx.beans.binding.BooleanBinding)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 ObservableList (javafx.collections.ObservableList)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 BoundingBox (javafx.geometry.BoundingBox)1 Point2D (javafx.geometry.Point2D)1 Cursor (javafx.scene.Cursor)1 Scene (javafx.scene.Scene)1