Search in sources :

Example 1 with JFXTabPane

use of com.jfoenix.controls.JFXTabPane in project JFoenix by jfoenixadmin.

the class JFXTabPaneSkin method layoutChildren.

@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    final double headerHeight = snapSize(header.prefHeight(-1));
    final Side side = getSkinnable().getSide();
    double tabsX = side == Side.RIGHT ? x + w - headerHeight : x;
    double tabsY = side == Side.BOTTOM ? y + h - headerHeight : y;
    final int rotation = getRotation(side);
    // update header
    switch(side) {
        case TOP:
            header.resize(w, headerHeight);
            header.relocate(tabsX, tabsY);
            break;
        case LEFT:
            header.resize(h, headerHeight);
            header.relocate(tabsX + headerHeight, h - headerHeight);
            break;
        case RIGHT:
            header.resize(h, headerHeight);
            header.relocate(tabsX, y - headerHeight);
            break;
        case BOTTOM:
            header.resize(w, headerHeight);
            header.relocate(w, tabsY - headerHeight);
            break;
    }
    header.getTransforms().setAll(new Rotate(rotation, 0, headerHeight, 1));
    // update header clip
    // header.clip.setX(0);
    // header.clip.setY(0);
    // header.clip.setWidth(isHorizontal() ? w : h);
    // header.clip.setHeight(headerHeight + 10); // 10 is the height of the shadow effect
    // position the tab content of the current selected tab
    double contentStartX = x + (side == Side.LEFT ? headerHeight : 0);
    double contentStartY = y + (side == Side.TOP ? headerHeight : 0);
    double contentWidth = w - (isHorizontal() ? 0 : headerHeight);
    double contentHeight = h - (isHorizontal() ? headerHeight : 0);
    // update tabs container
    tabsClip.setWidth(contentWidth);
    tabsClip.setHeight(contentHeight);
    tabsContainerHolder.resize(contentWidth, contentHeight);
    tabsContainerHolder.relocate(contentStartX, contentStartY);
    tabsContainer.resize(contentWidth * tabContentHolders.size(), contentHeight);
    for (int i = 0, max = tabContentHolders.size(); i < max; i++) {
        TabContentHolder tabContentHolder = tabContentHolders.get(i);
        tabContentHolder.setVisible(true);
        tabContentHolder.setTranslateX(contentWidth * i);
        if (tabContentHolder.getClip() != null) {
            ((Rectangle) tabContentHolder.getClip()).setWidth(contentWidth);
            ((Rectangle) tabContentHolder.getClip()).setHeight(contentHeight);
        }
        if (tabContentHolder.tab == selectedTab) {
            int index = getSkinnable().getTabs().indexOf(selectedTab);
            if (index != i) {
                tabsContainer.setTranslateX(-contentWidth * i);
                diffTabsIndices = i - index;
            } else {
                // fix X translation after changing the tabs
                if (diffTabsIndices != 0) {
                    tabsContainer.setTranslateX(tabsContainer.getTranslateX() + contentWidth * diffTabsIndices);
                    diffTabsIndices = 0;
                }
                // animate upon tab selection only otherwise just translate the selected tab
                if (isSelectingTab && !((JFXTabPane) getSkinnable()).isDisableAnimation()) {
                    new CachedTransition(tabsContainer, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(tabsContainer.translateXProperty(), -contentWidth * index, Interpolator.EASE_BOTH)))) {

                        {
                            setCycleDuration(Duration.seconds(0.320));
                            setDelay(Duration.seconds(0));
                        }
                    }.play();
                } else {
                    tabsContainer.setTranslateX(-contentWidth * index);
                }
            }
        }
        tabContentHolder.resize(contentWidth, contentHeight);
    // tabContentHolder.relocate(contentStartX, contentStartY);
    }
}
Also used : Rotate(javafx.scene.transform.Rotate) JFXTabPane(com.jfoenix.controls.JFXTabPane) Rectangle(javafx.scene.shape.Rectangle) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 2 with JFXTabPane

use of com.jfoenix.controls.JFXTabPane in project JFoenix by jfoenixadmin.

the class TabsDemo method start.

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Tabs");
    JFXTabPane tabPane = new JFXTabPane();
    Tab tab = new Tab();
    tab.setText(msg);
    tab.setContent(new Label(TAB_0));
    tabPane.getTabs().add(tab);
    tabPane.setPrefSize(300, 200);
    Tab tab1 = new Tab();
    tab1.setText(TAB_01);
    tab1.setContent(new Label(TAB_01));
    tabPane.getTabs().add(tab1);
    SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
    selectionModel.select(1);
    JFXButton button = new JFXButton("New Tab");
    button.setOnMouseClicked((o) -> {
        Tab temp = new Tab();
        int count = tabPane.getTabs().size();
        temp.setText(msg + count);
        temp.setContent(new Label(TAB_0 + count));
        tabPane.getTabs().add(temp);
    });
    tabPane.setMaxWidth(500);
    HBox hbox = new HBox();
    hbox.getChildren().addAll(button, tabPane);
    hbox.setSpacing(50);
    hbox.setAlignment(Pos.CENTER);
    hbox.setStyle("-fx-padding:20");
    Group root = new Group();
    Scene scene = new Scene(root, 700, 250);
    root.getChildren().addAll(hbox);
    scene.getStylesheets().add(TabsDemo.class.getResource("/css/jfoenix-components.css").toExternalForm());
    primaryStage.setTitle("JFX Tabs Demo");
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : Group(javafx.scene.Group) HBox(javafx.scene.layout.HBox) Tab(javafx.scene.control.Tab) JFXTabPane(com.jfoenix.controls.JFXTabPane) Label(javafx.scene.control.Label) JFXButton(com.jfoenix.controls.JFXButton) Scene(javafx.scene.Scene)

Aggregations

JFXTabPane (com.jfoenix.controls.JFXTabPane)2 JFXButton (com.jfoenix.controls.JFXButton)1 CachedTransition (com.jfoenix.transitions.CachedTransition)1 Group (javafx.scene.Group)1 Scene (javafx.scene.Scene)1 Label (javafx.scene.control.Label)1 Tab (javafx.scene.control.Tab)1 HBox (javafx.scene.layout.HBox)1 Rectangle (javafx.scene.shape.Rectangle)1 Rotate (javafx.scene.transform.Rotate)1