leftPanes.setOrientation(Orientation.VERTICAL);
leftPanes.setStyle("-fx-background-color:#000000");
//Set up the GO button
Text goButton = new Text("Go");
goButton.setFill(Color.GREEN);
BorderPane goPane = new BorderPane(goButton);
goButton.setOnMouseClicked(event -> playSelectedTrack());
leftPanes.getItems().add(goPane);
//Set up the STOP button
Text stopButton = new Text("Stop");
stopButton.setFill(Color.RED);
BorderPane stopPane = new BorderPane(stopButton);
stopButton.setOnMouseClicked(event -> stopSelectedTrack());
leftPanes.getItems().add(stopPane);
//Set up the FADE button
Text fadeButton = new Text("Fade");
fadeButton.setFill(Color.YELLOW);
BorderPane fadePane = new BorderPane(fadeButton);
fadeButton.setOnMouseClicked(event -> fadeSelectedTrack());
leftPanes.getItems().add(fadePane);
//Set up the clock
Text clock = new Text("00:00:00");
clock.setFill(Color.WHITE);
BorderPane clockPane = new BorderPane(clock);
leftPanes.getItems().add(clockPane);
//Make the clock tick:
new AnimationTimer() {
@Override
public void handle(long now) {
clock.setText(new SimpleDateFormat("HH:mm:ss").format(new Date()));
}
}.start();
//Evaluating text width is easy - we just ask the Text object for its width boundary.
// Similarly, the text height is done with the Text height boundary.
// The maximum width is easily done, too, actually. Just get the width of the pane!
// However, to calculate the height is a bit trickier...
// Typically, we'll need to find the position of the dividers ABOVE and BELOW the pane and subtract them.
// To get these positions, we can ask the dividers for their position - but that's actually a percentage of
// the entire SplitPane height, so we need to multiply the resulting subtraction by the SplitPane's height.
//First, let's do the vertical movement of the first divider, which affects panes 0 (Go) and 1 (Stop)
leftPanes.getDividers().get(0).positionProperty().addListener((observable, oldValue, newValue) -> {
//Note: Special case, as "ABOVE" is 0 (top of panes)
double scale = resizeText(goButton.getBoundsInLocal().getWidth(), goButton.getBoundsInLocal().getHeight(), goPane.getWidth(), leftPanes.getHeight() * newValue.doubleValue());
goButton.setScaleX(scale);
goButton.setScaleY(scale);
scale = resizeText(stopButton.getBoundsInLocal().getWidth(), stopButton.getBoundsInLocal().getHeight(), stopPane.getWidth(), leftPanes.getHeight() * (leftPanes.getDividers().get(1).getPosition() - newValue.doubleValue()));
stopButton.setScaleX(scale);
stopButton.setScaleY(scale);
});
//Then do the vertical movement of the second divider, which affects 1 (Stop) and 2 (Fade)
leftPanes.getDividers().get(1).positionProperty().addListener((observable, oldValue, newValue) -> {
double scale = resizeText(stopButton.getBoundsInLocal().getWidth(), stopButton.getBoundsInLocal().getHeight(), stopPane.getWidth(), leftPanes.getHeight() * (newValue.doubleValue() - leftPanes.getDividers().get(0).getPosition()));
stopButton.setScaleX(scale);
stopButton.setScaleY(scale);
scale = resizeText(fadeButton.getBoundsInLocal().getWidth(), fadeButton.getBoundsInLocal().getHeight(), fadePane.getWidth(), leftPanes.getHeight() * (leftPanes.getDividers().get(2).getPosition() - newValue.doubleValue()));
fadeButton.setScaleX(scale);
fadeButton.setScaleY(scale);
});
//Next, the third divider, affecting 2 (Fade) and 3 (Clock)
leftPanes.getDividers().get(2).positionProperty().addListener((observable, oldValue, newValue) -> {
double scale = resizeText(fadeButton.getBoundsInLocal().getWidth(), fadeButton.getBoundsInLocal().getHeight(), fadePane.getWidth(), leftPanes.getHeight() * (newValue.doubleValue() - leftPanes.getDividers().get(1).getPosition()));
fadeButton.setScaleX(scale);
fadeButton.setScaleY(scale);
//Note: Special case, as BELOW is leftPanes.getHeight (bottom of panes)
scale = resizeText(clock.getBoundsInLocal().getWidth(), clock.getBoundsInLocal().getHeight(), clockPane.getWidth(), leftPanes.getHeight() - (leftPanes.getHeight() * newValue.doubleValue()));
clock.setScaleX(scale);
clock.setScaleY(scale);
});
//Lastly do the horizontal width of the first pane. In fact, if this pane's width changes, all the panes do.
goPane.widthProperty().addListener((observable, oldValue, newValue) -> {
double scale = resizeText(goButton.getBoundsInLocal().getWidth(), goButton.getBoundsInLocal().getHeight(), newValue.doubleValue(), leftPanes.getHeight() * leftPanes.getDividers().get(0).getPosition());
goButton.setScaleX(scale);
goButton.setScaleY(scale);
});
stopPane.widthProperty().addListener((observable, oldValue, newValue) -> {
double scale = resizeText(stopButton.getBoundsInLocal().getWidth(), stopButton.getBoundsInLocal().getHeight(), newValue.doubleValue(), leftPanes.getHeight() * (leftPanes.getDividers().get(1).getPosition() - leftPanes.getDividers().get(0).getPosition()));
stopButton.setScaleX(scale);
stopButton.setScaleY(scale);
});
fadePane.widthProperty().addListener((observable, oldValue, newValue) -> {
double scale = resizeText(fadeButton.getBoundsInLocal().getWidth(), fadeButton.getBoundsInLocal().getHeight(), newValue.doubleValue(), leftPanes.getHeight() * (leftPanes.getDividers().get(2).getPosition() - leftPanes.getDividers().get(1).getPosition()));
fadeButton.setScaleX(scale);
fadeButton.setScaleY(scale);
});
clockPane.widthProperty().addListener((observable, oldValue, newValue) -> {
double scale = resizeText(clock.getBoundsInLocal().getWidth(), clock.getBoundsInLocal().getHeight(), newValue.doubleValue(), leftPanes.getHeight() - (leftPanes.getHeight() * leftPanes.getDividers().get(2).getPosition()));
clock.setScaleX(scale);
clock.setScaleY(scale);
});
return leftPanes;
}