Search in sources :

Example 11 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class AlignmentUtils method distribute.

public static void distribute(List<? extends Pane> panes, Alignment type) {
    if (panes == null || panes.size() < 3) {
        return;
    }
    int size = panes.size();
    double spacing, firstCenter, lastCenter;
    Pane first, last;
    switch(type) {
        case LEFT:
            Collections.sort(panes, leftComparator);
            first = panes.get(0);
            last = panes.get(size - 1);
            spacing = (last.getLayoutX() - first.getLayoutX()) / (size - 1);
            for (int i = 1; i < size - 1; i++) {
                Pane pane = panes.get(i);
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newX = (int) ((i * spacing) + first.getLayoutX());
                bsbObj.setX(newX);
            }
            break;
        case HORIZONTAL_CENTER:
            Collections.sort(panes, horizontalCenterComparator);
            first = panes.get(0);
            last = panes.get(size - 1);
            firstCenter = first.getLayoutX() + (first.getWidth() / 2);
            lastCenter = last.getLayoutX() + (last.getWidth() / 2);
            spacing = (lastCenter - firstCenter) / (size - 1);
            for (int i = 1; i < size - 1; i++) {
                Pane pane = panes.get(i);
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newX = (int) ((i * spacing) + firstCenter);
                newX = newX - (int) (pane.getWidth() / 2);
                bsbObj.setX(newX);
            }
            break;
        case RIGHT:
            Collections.sort(panes, rightComparator);
            first = panes.get(0);
            last = panes.get(size - 1);
            spacing = ((last.getLayoutX() + last.getWidth()) - (first.getLayoutX() + first.getWidth())) / (size - 1);
            for (int i = 1; i < size - 1; i++) {
                Pane pane = panes.get(i);
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newX = (int) ((i * spacing) + first.getLayoutX() + first.getWidth());
                newX = newX - (int) pane.getWidth();
                bsbObj.setX(newX);
            }
            break;
        case TOP:
            Collections.sort(panes, topComparator);
            first = panes.get(0);
            last = panes.get(size - 1);
            spacing = (last.getLayoutY() - first.getLayoutY()) / (size - 1);
            for (int i = 1; i < size - 1; i++) {
                Pane pane = panes.get(i);
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newY = (int) ((i * spacing) + first.getLayoutY());
                bsbObj.setY(newY);
            }
            break;
        case VERTICAL_CENTER:
            Collections.sort(panes, verticalCenterComparator);
            first = (Pane) panes.get(0);
            last = (Pane) panes.get(size - 1);
            firstCenter = first.getLayoutY() + (first.getHeight() / 2);
            lastCenter = last.getLayoutY() + (last.getHeight() / 2);
            spacing = (lastCenter - firstCenter) / (size - 1);
            for (int i = 1; i < size - 1; i++) {
                Pane pane = panes.get(i);
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newY = (int) ((i * spacing) + firstCenter);
                newY = newY - (int) (pane.getHeight() / 2);
                bsbObj.setY(newY);
            }
            break;
        case BOTTOM:
            Collections.sort(panes, bottomComparator);
            first = panes.get(0);
            last = panes.get(size - 1);
            spacing = ((last.getLayoutY() + last.getHeight()) - (first.getLayoutY() + first.getHeight())) / (size - 1);
            for (int i = 1; i < size - 1; i++) {
                Pane pane = panes.get(i);
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newY = (int) ((i * spacing) + first.getLayoutY() + first.getHeight());
                newY = newY - (int) pane.getHeight();
                bsbObj.setY(newY);
            }
            break;
    }
}
Also used : BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) Pane(javafx.scene.layout.Pane)

Example 12 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class AlignmentUtils method align.

public static void align(List<? extends Pane> panes, Alignment type) {
    double left, right, top, bottom, center;
    switch(type) {
        case LEFT:
            Optional<? extends Pane> leftPane = panes.stream().min((o1, o2) -> Double.compare(o1.getLayoutX(), o2.getLayoutX()));
            if (leftPane.isPresent()) {
                int x = (int) leftPane.get().getLayoutX();
                for (Pane pane : panes) {
                    BSBObject bsbObj = (BSBObject) pane.getUserData();
                    bsbObj.setX(x);
                }
            }
            break;
        case HORIZONTAL_CENTER:
            left = Integer.MAX_VALUE;
            right = 0;
            for (Pane comp : panes) {
                if (comp.getLayoutX() < left) {
                    left = comp.getLayoutX();
                }
                double rightSide = comp.getLayoutX() + comp.getWidth();
                if (rightSide > right) {
                    right = rightSide;
                }
            }
            center = ((right - left) / 2) + left;
            for (Pane pane : panes) {
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newX = (int) (center - (pane.getWidth() / 2));
                bsbObj.setX(newX);
            }
            break;
        case RIGHT:
            right = 0;
            for (Pane comp : panes) {
                double rightSide = comp.getLayoutX() + comp.getWidth();
                if (rightSide > right) {
                    right = rightSide;
                }
            }
            for (Pane pane : panes) {
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                bsbObj.setX((int) (right - pane.getWidth()));
            }
            break;
        case TOP:
            Optional<? extends Pane> topPane = panes.stream().min((o1, o2) -> Double.compare(o1.getLayoutY(), o2.getLayoutY()));
            if (topPane.isPresent()) {
                int y = (int) topPane.get().getLayoutY();
                for (Pane pane : panes) {
                    BSBObject bsbObj = (BSBObject) pane.getUserData();
                    bsbObj.setY(y);
                }
            }
            break;
        case VERTICAL_CENTER:
            top = Integer.MAX_VALUE;
            bottom = 0;
            for (Pane comp : panes) {
                if (comp.getLayoutY() < top) {
                    top = comp.getLayoutY();
                }
                double bottomSide = comp.getLayoutY() + comp.getHeight();
                if (bottomSide > bottom) {
                    bottom = bottomSide;
                }
            }
            center = ((bottom - top) / 2) + top;
            for (Pane pane : panes) {
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                int newY = (int) (center - (pane.getHeight() / 2));
                bsbObj.setY(newY);
            }
            break;
        case BOTTOM:
            bottom = 0;
            for (Pane comp : panes) {
                double bottomSide = comp.getLayoutY() + comp.getHeight();
                if (bottomSide > bottom) {
                    bottom = bottomSide;
                }
            }
            for (Pane pane : panes) {
                BSBObject bsbObj = (BSBObject) pane.getUserData();
                bsbObj.setY((int) (bottom - pane.getHeight()));
            }
            break;
    }
}
Also used : BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) Pane(javafx.scene.layout.Pane)

Example 13 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class SubChannelListPanel method reconcileSubChannelRemoveInBlueArrangement.

/**
 * A hack to explicitly walk the current blue orchestra to find any
 * BlueSynthBuilder's that contain BSBSubChannelDropdown's and to reconcile
 * with the removed channel
 *
 * @param removedChannel
 *
 * @param oldName
 * @param newName
 */
private void reconcileSubChannelRemoveInBlueArrangement(String removedChannel) {
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    if (data == null) {
        return;
    }
    Arrangement arr = data.getArrangement();
    for (int i = 0; i < arr.size(); i++) {
        Instrument instr = arr.getInstrument(i);
        if (instr instanceof BlueSynthBuilder) {
            BlueSynthBuilder bsb = (BlueSynthBuilder) instr;
            BSBGraphicInterface bsbInterface = bsb.getGraphicInterface();
            for (BSBObject bsbObj : bsbInterface.getAllSet()) {
                if (bsbObj instanceof BSBSubChannelDropdown) {
                    BSBSubChannelDropdown bsbSubDrop = (BSBSubChannelDropdown) bsbObj;
                    if (bsbSubDrop.getChannelOutput().equals(removedChannel)) {
                        bsbSubDrop.setChannelOutput(Channel.MASTER);
                    }
                }
            }
        }
    }
}
Also used : BlueData(blue.BlueData) BSBGraphicInterface(blue.orchestra.blueSynthBuilder.BSBGraphicInterface) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) BSBSubChannelDropdown(blue.orchestra.blueSynthBuilder.BSBSubChannelDropdown) Instrument(blue.orchestra.Instrument) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) Arrangement(blue.Arrangement)

Aggregations

BSBObject (blue.orchestra.blueSynthBuilder.BSBObject)13 GridSettings (blue.orchestra.blueSynthBuilder.GridSettings)4 Pane (javafx.scene.layout.Pane)4 BSBGraphicInterface (blue.orchestra.blueSynthBuilder.BSBGraphicInterface)3 Rectangle (javafx.scene.shape.Rectangle)3 Arrangement (blue.Arrangement)2 BlueData (blue.BlueData)2 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)2 Instrument (blue.orchestra.Instrument)2 BSBGroup (blue.orchestra.blueSynthBuilder.BSBGroup)2 BSBSubChannelDropdown (blue.orchestra.blueSynthBuilder.BSBSubChannelDropdown)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Bindings (javafx.beans.binding.Bindings)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 ChangeListener (javafx.beans.value.ChangeListener)2 ObservableList (javafx.collections.ObservableList)2 ActionEvent (javafx.event.ActionEvent)2 EventHandler (javafx.event.EventHandler)2 BoundingBox (javafx.geometry.BoundingBox)2