免费行情网站app大全,网站质作,优化方案英语必修三,wordpress wiki主题最近#xff0c;我不得不为应用程序实现一个布局#xff0c;其中可以根据用户是否登录来隐藏或通过滑入/滑出动画显示或显示菜单区域和状态区域。 以下视频显示了实际的布局#xff1a; 在过去#xff0c;我可能会使用自定义控件和自定义布局代码来实现这种行为#xff0… 最近我不得不为应用程序实现一个布局其中可以根据用户是否登录来隐藏或通过滑入/滑出动画显示或显示菜单区域和状态区域。 以下视频显示了实际的布局 在过去我可能会使用自定义控件和自定义布局代码来实现这种行为如“皮肤中的layoutChildren方法”。 但是这次我的设置有所不同因为我使用的是Adam Bien的afterburner.fx 现在有了FXML和一个控制器类。 那该怎么办呢 我决定尝试使用锚定窗格来实现运气并通过时间轴实例更新堆栈窗格上的约束。 约束存储在堆栈窗格的可观察属性映射中。 只要这些限制发生变化就会自动请求锚定窗格的布局。 如果发生这种情况而没有任何闪烁那么我们最终将获得一个流畅的动画。 顺便说一句来自Swing我总是希望闪烁但是JavaFX通常不会发生闪烁。 最后我写了下面的控制器类来管理锚窗格及其子堆栈窗格。 请注意中间属性menuPaneLocation和bottomPaneLocation的小技巧。 它们是必需的因为动画时间轴可与属性一起使用。 因此它会更新这些属性并且每当它们更改时都会应用新的锚定窗格约束。 import static javafx.scene.layout.AnchorPane.setBottomAnchor;
import static javafx.scene.layout.AnchorPane.setLeftAnchor;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;/code/*** This presenter covers the top-level layout concepts of the workbench.*/
public class WorkbenchPresenter {FXML
private StackPane topPane;FXML
private StackPane menuPane;FXML
private StackPane centerPane;FXML
private StackPane bottomPane;public WorkbenchPresenter() {
}private final BooleanProperty showMenuPane new SimpleBooleanProperty(this, showMenuPane, true);public final boolean isShowMenuPane() {return showMenuPane.get();
}public final void setShowMenuPane(boolean showMenu) {showMenuPane.set(showMenu);
}/**
* Returns the property used to control the visibility of the menu panel.
* When the value of this property changes to false then the menu panel will
* slide out to the left).
*
* return the property used to control the menu panel
*/
public final BooleanProperty showMenuPaneProperty() {return showMenuPane;
}private final BooleanProperty showBottomPane new SimpleBooleanProperty(this, showBottomPane, true);public final boolean isShowBottomPane() {return showBottomPane.get();
}public final void setShowBottomPane(boolean showBottom) {showBottomPane.set(showBottom);
}/**
* Returns the property used to control the visibility of the bottom panel.
* When the value of this property changes to false then the bottom panel
* will slide out to the left).
*
* return the property used to control the bottom panel
*/
public final BooleanProperty showBottomPaneProperty() {return showBottomPane;
}public final void initialize() {menuPaneLocation.addListener(it - updateMenuPaneAnchors());bottomPaneLocation.addListener(it - updateBottomPaneAnchors());showMenuPaneProperty().addListener(it - animateMenuPane());showBottomPaneProperty().addListener(it - animateBottomPane());menuPane.setOnMouseClicked(evt - setShowMenuPane(false));centerPane.setOnMouseClicked(evt - {setShowMenuPane(true);setShowBottomPane(true);});bottomPane.setOnMouseClicked(evt - setShowBottomPane(false));
}/** The updateMenu/BottomPaneAnchors methods get called whenever the value of* menuPaneLocation or bottomPaneLocation changes. Setting anchor pane* constraints will automatically trigger a relayout of the anchor pane* children.*/private void updateMenuPaneAnchors() {setLeftAnchor(menuPane, getMenuPaneLocation());setLeftAnchor(centerPane, getMenuPaneLocation() menuPane.getWidth());
}private void updateBottomPaneAnchors() {setBottomAnchor(bottomPane, getBottomPaneLocation());setBottomAnchor(centerPane, getBottomPaneLocation() bottomPane.getHeight());setBottomAnchor(menuPane,getBottomPaneLocation() bottomPane.getHeight());
}/*
* Starts the animation for the menu pane.
*/
private void animateMenuPane() {if (isShowMenuPane()) {slideMenuPane(0);} else {slideMenuPane(-menuPane.prefWidth(-1));}
}/*
* Starts the animation for the bottom pane.
*/
private void animateBottomPane() {if (isShowBottomPane()) {slideBottomPane(0);} else {slideBottomPane(-bottomPane.prefHeight(-1));}
}/** The animations are using the JavaFX timeline concept. The timeline updates* properties. In this case we have to introduce our own properties further* below (menuPaneLocation, bottomPaneLocation) because ultimately we need to* update layout constraints, which are not properties. So this is a little* work-around.*/private void slideMenuPane(double toX) {KeyValue keyValue new KeyValue(menuPaneLocation, toX);KeyFrame keyFrame new KeyFrame(Duration.millis(300), keyValue);Timeline timeline new Timeline(keyFrame);timeline.play();
}private void slideBottomPane(double toY) {KeyValue keyValue new KeyValue(bottomPaneLocation, toY);KeyFrame keyFrame new KeyFrame(Duration.millis(300), keyValue);Timeline timeline new Timeline(keyFrame);timeline.play();
}private DoubleProperty menuPaneLocation new SimpleDoubleProperty(this, menuPaneLocation);private double getMenuPaneLocation() {return menuPaneLocation.get();
}private DoubleProperty bottomPaneLocation new SimpleDoubleProperty(this, bottomPaneLocation);private double getBottomPaneLocation() {return bottomPaneLocation.get();
}
} 以下是此项工作所需的FXML ?xml version1.0 encodingUTF-8??import java.lang.*?
?import javafx.scene.layout.*?AnchorPane maxHeight-Infinity maxWidth-Infinity minHeight-Infinity minWidth-Infinity prefHeight400.0 prefWidth600.0 xmlnshttp://javafx.com/javafx/8 xmlns:fxhttp://javafx.com/fxml/1 fx:controllercom.workbench.WorkbenchPresenterchildrenStackPane fx:idbottomPane layoutX-4.0 layoutY356.0 prefHeight40.0 AnchorPane.bottomAnchor0.0 AnchorPane.leftAnchor0.0 AnchorPane.rightAnchor0.0 /StackPane fx:idmenuPane layoutY28.0 prefWidth200.0 AnchorPane.bottomAnchor40.0 AnchorPane.leftAnchor0.0 AnchorPane.topAnchor40.0 /StackPane fx:idtopPane prefHeight40.0 AnchorPane.leftAnchor0.0 AnchorPane.rightAnchor0.0 AnchorPane.topAnchor0.0 /StackPane fx:idcenterPane layoutX72.0 layoutY44.0 AnchorPane.bottomAnchor40.0 AnchorPane.leftAnchor200.0 AnchorPane.rightAnchor0.0 AnchorPane.topAnchor40.0 //children
/AnchorPane翻译自: https://www.javacodegeeks.com/2015/02/javafx-tip-17-animated-workbench-layout-anchorpane.html