};
closeBtn.getStyleClass().setAll("tab-close-button");
closeBtn.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent me) {
Tab tab = getTab();
TabPaneBehavior behavior = getBehavior();
if (behavior.canCloseTab(tab)) {
removeListeners(tab);
behavior.closeTab(tab);
setOnMousePressed(null);
}
}
});
updateGraphicRotation();
final int padding = 2;
final Region focusIndicator = new Region();
focusIndicator.setMouseTransparent(true);
focusIndicator.getStyleClass().add("focus-indicator");
inner = new StackPane() {
@Override protected void layoutChildren() {
final TabPane skinnable = getSkinnable();
final double paddingTop = snappedTopInset();
final double paddingRight = snappedRightInset();
final double paddingBottom = snappedBottomInset();
final double paddingLeft = snappedLeftInset();
final double w = getWidth() - (paddingLeft + paddingRight);
final double h = getHeight() - (paddingTop + paddingBottom);
final double prefLabelWidth = snapSize(label.prefWidth(-1));
final double prefLabelHeight = snapSize(label.prefHeight(-1));
final double closeBtnWidth = showCloseButton() ? snapSize(closeBtn.prefWidth(-1)) : 0;
final double closeBtnHeight = showCloseButton() ? snapSize(closeBtn.prefHeight(-1)) : 0;
final double minWidth = snapSize(skinnable.getTabMinWidth());
final double maxWidth = snapSize(skinnable.getTabMaxWidth());
final double minHeight = snapSize(skinnable.getTabMinHeight());
final double maxHeight = snapSize(skinnable.getTabMaxHeight());
double labelAreaWidth = prefLabelWidth;
double labelAreaHeight = prefLabelHeight;
double labelWidth = prefLabelWidth;
double labelHeight = prefLabelHeight;
final double childrenWidth = labelAreaWidth + closeBtnWidth;
final double childrenHeight = Math.max(labelAreaHeight, closeBtnHeight);
if (childrenWidth > maxWidth && maxWidth != Double.MAX_VALUE) {
labelAreaWidth = maxWidth - closeBtnWidth;
labelWidth = maxWidth - closeBtnWidth;
} else if (childrenWidth < minWidth) {
labelAreaWidth = minWidth - closeBtnWidth;
}
if (childrenHeight > maxHeight && maxHeight != Double.MAX_VALUE) {
labelAreaHeight = maxHeight;
labelHeight = maxHeight;
} else if (childrenHeight < minHeight) {
labelAreaHeight = minHeight;
}
if (animating) {
if (prefWidth.getValue() < labelAreaWidth) {
labelAreaWidth = prefWidth.getValue();
}
closeBtn.setVisible(false);
} else {
closeBtn.setVisible(showCloseButton());
}
label.resize(labelWidth, labelHeight);
double labelStartX = paddingLeft;
// If maxWidth is less than Double.MAX_VALUE, the user has
// clamped the max width, but we should
// position the close button at the end of the tab,
// which may not necessarily be the entire width of the
// provided max width.
double closeBtnStartX = (maxWidth < Double.MAX_VALUE ? Math.min(w, maxWidth) : w) - paddingRight - closeBtnWidth;
positionInArea(label, labelStartX, paddingTop, labelAreaWidth, h,
/*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
if (closeBtn.isVisible()) {
closeBtn.resize(closeBtnWidth, closeBtnHeight);
positionInArea(closeBtn, closeBtnStartX, paddingTop, closeBtnWidth, h,
/*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
}
focusIndicator.resizeRelocate(
label.getLayoutX() - padding,
Math.min(label.getLayoutY(), closeBtn.isVisible() ? closeBtn.getLayoutY() : Double.MAX_VALUE) - padding,
labelWidth + closeBtnWidth + padding * 2,
Math.max(labelHeight, closeBtnHeight) + padding*2);
}
};
inner.getStyleClass().add("tab-container");
inner.setRotate(getSkinnable().getSide().equals(Side.BOTTOM) ? 180.0F : 0.0F);
inner.getChildren().addAll(label, closeBtn, focusIndicator);
getChildren().addAll(inner);
tooltip = tab.getTooltip();
if (tooltip != null) {
Tooltip.install(this, tooltip);
oldTooltip = tooltip;
}
listener.registerChangeListener(tab.closableProperty(), "CLOSABLE");
listener.registerChangeListener(tab.selectedProperty(), "SELECTED");
listener.registerChangeListener(tab.textProperty(), "TEXT");
listener.registerChangeListener(tab.graphicProperty(), "GRAPHIC");
listener.registerChangeListener(tab.contextMenuProperty(), "CONTEXT_MENU");
listener.registerChangeListener(tab.tooltipProperty(), "TOOLTIP");
listener.registerChangeListener(tab.disableProperty(), "DISABLE");
listener.registerChangeListener(tab.styleProperty(), "STYLE");
tab.getStyleClass().addListener(weakStyleClassListener);
listener.registerChangeListener(getSkinnable().tabClosingPolicyProperty(), "TAB_CLOSING_POLICY");
listener.registerChangeListener(getSkinnable().sideProperty(), "SIDE");
listener.registerChangeListener(getSkinnable().rotateGraphicProperty(), "ROTATE_GRAPHIC");
listener.registerChangeListener(getSkinnable().tabMinWidthProperty(), "TAB_MIN_WIDTH");
listener.registerChangeListener(getSkinnable().tabMaxWidthProperty(), "TAB_MAX_WIDTH");
listener.registerChangeListener(getSkinnable().tabMinHeightProperty(), "TAB_MIN_HEIGHT");
listener.registerChangeListener(getSkinnable().tabMaxHeightProperty(), "TAB_MAX_HEIGHT");
getProperties().put(Tab.class, tab);
getProperties().put(ContextMenu.class, tab.getContextMenu());
setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
@Override public void handle(ContextMenuEvent me) {
if (getTab().getContextMenu() != null) {
getTab().getContextMenu().show(inner, me.getScreenX(), me.getScreenY());
me.consume();
}
}
});
setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent me) {
if (getTab().isDisable()) {
return;
}
if (me.getButton().equals(MouseButton.MIDDLE)) {
if (showCloseButton()) {
Tab tab = getTab();
TabPaneBehavior behavior = getBehavior();
if (behavior.canCloseTab(tab)) {
removeListeners(tab);
behavior.closeTab(tab);
}
}
} else if (me.getButton().equals(MouseButton.PRIMARY)) {
getBehavior().selectTab(getTab());
}