private ContextMenu popup;
public TabControlButtons() {
getStyleClass().setAll("control-buttons-tab");
TabPane tabPane = getSkinnable();
downArrowBtn = new Pane();
downArrowBtn.getStyleClass().setAll("tab-down-button");
downArrowBtn.setVisible(isShowTabsMenu());
downArrow = new StackPane();
downArrow.setManaged(false);
downArrow.getStyleClass().setAll("arrow");
downArrow.setRotate(tabPane.getSide().equals(Side.BOTTOM) ? 180.0F : 0.0F);
downArrowBtn.getChildren().add(downArrow);
downArrowBtn.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent me) {
showPopupMenu();
}
});
setupPopupMenu();
inner = new StackPane() {
private double getArrowBtnWidth() {
if (animationLock) return maxArrowWidth;
if (isShowTabsMenu()) {
maxArrowWidth = Math.max(maxArrowWidth, snapSize(downArrow.prefWidth(getHeight())) + snapSize(downArrowBtn.prefWidth(getHeight())));
}
return maxArrowWidth;
}
@Override protected double computePrefWidth(double height) {
if (animationLock) return innerPrefWidth;
innerPrefWidth = getActualPrefWidth();
return innerPrefWidth;
}
public double getActualPrefWidth() {
double pw;
double maxArrowWidth = getArrowBtnWidth();
pw = 0.0F;
if (isShowTabsMenu()) {
pw += maxArrowWidth;
}
if (pw > 0) {
pw += snappedLeftInset() + snappedRightInset();
}
return pw;
}
@Override protected double computePrefHeight(double width) {
double height = 0.0F;
if (isShowTabsMenu()) {
height = Math.max(height, snapSize(downArrowBtn.prefHeight(width)));
}
if (height > 0) {
height += snappedTopInset() + snappedBottomInset();
}
return height;
}
@Override protected void layoutChildren() {
Side tabPosition = getSkinnable().getSide();
double x = 0.0F;
//padding.left;
double y = snappedTopInset();
double h = snapSize(getHeight()) - y + snappedBottomInset();
// when on the left or bottom, we need to position the tabs controls
// button such that it is the furtherest button away from the tabs.
if (tabPosition.equals(Side.BOTTOM) || tabPosition.equals(Side.LEFT)) {
x += positionTabsMenu(x, y, h, true);
} else {
x += positionTabsMenu(x, y, h, false);
}
}
private double positionTabsMenu(double x, double y, double h, boolean showSep) {
double newX = x;
if (isShowTabsMenu()) {
// DOWN ARROW BUTTON
positionArrow(downArrowBtn, downArrow, newX, y, maxArrowWidth, h);
newX += maxArrowWidth;
}
return newX;
}
private void positionArrow(Pane btn, StackPane arrow, double x, double y, double width, double height) {
btn.resize(width, height);
positionInArea(btn, x, y, width, height, /*baseline ignored*/0,
HPos.CENTER, VPos.CENTER);
// center arrow region within arrow button
double arrowWidth = snapSize(arrow.prefWidth(-1));
double arrowHeight = snapSize(arrow.prefHeight(-1));
arrow.resize(arrowWidth, arrowHeight);
positionInArea(arrow, btn.snappedLeftInset(), btn.snappedTopInset(),
width - btn.snappedLeftInset() - btn.snappedRightInset(),
height - btn.snappedTopInset() - btn.snappedBottomInset(),
/*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
}
};
inner.getStyleClass().add("container");
inner.getChildren().add(downArrowBtn);
getChildren().add(inner);
tabPane.sideProperty().addListener(new InvalidationListener() {
@Override public void invalidated(Observable valueModel) {
Side tabPosition = getSkinnable().getSide();
downArrow.setRotate(tabPosition.equals(Side.BOTTOM)? 180.0F : 0.0F);
}
});
tabPane.getTabs().addListener(new ListChangeListener<Tab>() {
@Override public void onChanged(Change<? extends Tab> c) {
setupPopupMenu();
}
});
showControlButtons = false;