use of javafx.scene.Node in project JFoenix by jfoenixadmin.
the class JFXTableColumnHeader method layoutChildren.
@Override
protected void layoutChildren() {
super.layoutChildren();
double w = snapSize(getWidth()) - (snappedLeftInset() + snappedRightInset());
container.resizeRelocate(snappedLeftInset(), 0, w, getHeight());
if (!getChildren().contains(container)) {
invalid = true;
container.getChildren().remove(arrowContainer);
for (int i = 0; i < getChildren().size(); ) {
Node child = getChildren().get(i);
container.getChildren().add(child);
}
getChildren().add(container);
}
// add animation to sorting arrow
if (invalid) {
if (container.getChildren().size() > 1 && !container.getChildren().contains(arrowContainer)) {
// setup children
arrowPane = (GridPane) container.getChildren().get(1);
arrow = (Region) arrowPane.getChildren().get(0);
arrowContainer.getChildren().clear();
container.getChildren().remove(1);
container.getChildren().add(arrowContainer);
for (int i = 0; i < arrowPane.getChildren().size(); ) {
Node child = arrowPane.getChildren().get(i);
arrowContainer.getChildren().add(child);
if (child instanceof HBox) {
HBox dotsContainer = (HBox) child;
dotsContainer.setMaxHeight(5);
dotsContainer.translateYProperty().bind(Bindings.createDoubleBinding(() -> {
return arrow.getHeight() + 2;
}, arrow.heightProperty()));
} else if (child instanceof Label) {
Label labelContainer = (Label) child;
labelContainer.setMaxHeight(5);
labelContainer.translateYProperty().bind(Bindings.createDoubleBinding(() -> {
return arrow.getHeight() + 3;
}, arrow.heightProperty()));
}
}
arrowContainer.maxWidthProperty().bind(arrow.widthProperty());
StackPane.setAlignment(arrowContainer, Pos.CENTER_RIGHT);
// set padding to the label to replace it with ... if it's too close to the sorting arrow
Label label = (Label) container.getChildren().get(0);
oldMargin = StackPane.getMargin(label);
StackPane.setMargin(label, new Insets(oldMargin == null ? 0 : oldMargin.getTop(), oldMargin == null || oldMargin.getRight() < 30 ? 30 : oldMargin.getRight(), oldMargin == null ? 0 : oldMargin.getBottom(), oldMargin == null || oldMargin.getLeft() < 30 ? 30 : oldMargin.getLeft()));
// fixed the issue of arrow translate X while resizing the column header
arrowContainer.translateXProperty().bind(Bindings.createDoubleBinding(() -> {
if (arrowContainer.getLayoutX() <= 8)
return -arrowContainer.getLayoutX() - 2;
return -10.0;
}, arrowContainer.layoutXProperty()));
if (arrowAnimation != null && arrowAnimation.getStatus().equals(Status.RUNNING))
arrowAnimation.stop();
if (arrow.getRotate() == 180 && arrow.getRotate() != currentArrowRotation) {
arrowContainer.setOpacity(0);
arrowContainer.setTranslateY(getHeight() / 4);
arrowAnimation = new Timeline(new KeyFrame(Duration.millis(320), new KeyValue(arrowContainer.opacityProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.translateYProperty(), 0, Interpolator.EASE_BOTH)));
} else if (arrow.getRotate() == 0 && arrow.getRotate() != currentArrowRotation) {
arrow.setRotate(-180);
arrowAnimation = new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(arrow.rotateProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.opacityProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.translateYProperty(), 0, Interpolator.EASE_BOTH)));
}
arrowAnimation.setOnFinished((finish) -> currentArrowRotation = arrow.getRotate());
arrowAnimation.play();
}
if (arrowContainer != null && arrowPane != null && container.getChildren().size() == 1 && !arrowPane.isVisible()) {
if (arrowAnimation != null && arrowAnimation.getStatus().equals(Status.RUNNING))
arrowAnimation.stop();
Label label = (Label) container.getChildren().get(0);
// dont change the padding if arrow is not showing
if (currentArrowRotation == 0)
StackPane.setMargin(label, new Insets(oldMargin == null ? 0 : oldMargin.getTop(), oldMargin == null || oldMargin.getRight() < 30 ? 30 : oldMargin.getRight(), oldMargin == null ? 0 : oldMargin.getBottom(), oldMargin == null || oldMargin.getLeft() < 30 ? 30 : oldMargin.getLeft()));
container.getChildren().add(arrowContainer);
arrowAnimation = new Timeline(new KeyFrame(Duration.millis(320), new KeyValue(arrowContainer.opacityProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.translateYProperty(), getHeight() / 4, Interpolator.EASE_BOTH)));
arrowAnimation.setOnFinished((finish) -> {
currentArrowRotation = -1;
StackPane.setMargin(label, null);
});
arrowAnimation.play();
}
}
}
use of javafx.scene.Node in project JFoenix by jfoenixadmin.
the class JFXTextAreaSkin method showError.
private void showError(ValidatorBase validator) {
// set text in error label
errorLabel.setText(validator.getMessage());
// show error icon
Node awsomeIcon = validator.getIcon();
errorIcon.getChildren().clear();
if (awsomeIcon != null) {
errorIcon.getChildren().add(awsomeIcon);
StackPane.setAlignment(awsomeIcon, Pos.TOP_RIGHT);
}
// init only once, to fix the text pane from resizing
if (initYLayout == -1) {
scrollPane.setMaxHeight(scrollPane.getHeight());
initYLayout = scrollPane.getBoundsInParent().getMinY();
initHeight = getSkinnable().getHeight();
currentFieldHeight = initHeight;
}
errorContainer.setVisible(true);
errorShown = true;
}
use of javafx.scene.Node in project JFoenix by jfoenixadmin.
the class JFXResponsiveHandler method scanAllNodes.
/**
* scans all nodes in the scene and apply the css pseduoClass to them.
*
* @param parent stage parent node
* @param pseudoClass css class for certain device
*/
private void scanAllNodes(Parent parent, PseudoClass pseudoClass) {
parent.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
while (c.next()) if (!c.wasPermutated() && !c.wasUpdated())
for (Node addedNode : c.getAddedSubList()) if (addedNode instanceof Parent)
scanAllNodes((Parent) addedNode, pseudoClass);
}
});
for (Node component : parent.getChildrenUnmodifiable()) {
if (component instanceof Pane) {
((Pane) component).getChildren().addListener(new ListChangeListener<Node>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
while (c.next()) {
if (!c.wasPermutated() && !c.wasUpdated()) {
for (Node addedNode : c.getAddedSubList()) {
if (addedNode instanceof Parent)
scanAllNodes((Parent) addedNode, pseudoClass);
}
}
}
}
});
//if the component is a container, scan its children
scanAllNodes((Pane) component, pseudoClass);
} else if (component instanceof ScrollPane) {
((ScrollPane) component).contentProperty().addListener((o, oldVal, newVal) -> {
scanAllNodes((Parent) newVal, pseudoClass);
});
//if the component is a container, scan its children
if (((ScrollPane) component).getContent() instanceof Parent) {
scanAllNodes((Parent) ((ScrollPane) component).getContent(), pseudoClass);
}
} else if (component instanceof Control) {
//if the component is an instance of IInputControl, add to list
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_EX_SMALL, pseudoClass == PSEUDO_CLASS_EX_SMALL);
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_SMALL, pseudoClass == PSEUDO_CLASS_SMALL);
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_MEDIUM, pseudoClass == PSEUDO_CLASS_MEDIUM);
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_LARGE, pseudoClass == PSEUDO_CLASS_LARGE);
}
}
}
use of javafx.scene.Node in project JFoenix by jfoenixadmin.
the class JFXDepthManager method createMaterialNode.
/**
* this method will generate a new container node that prevent
* control transformation to be applied to the shadow effect
* (which makes it looks as a real shadow)
*/
public static Node createMaterialNode(Node control, int level) {
Node container = new Pane(control);
container.getStyleClass().add("depth-container");
level = level < 0 ? 0 : level;
level = level > 5 ? 5 : level;
container.setEffect(new DropShadow(BlurType.GAUSSIAN, depth[level].getColor(), depth[level].getRadius(), depth[level].getSpread(), depth[level].getOffsetX(), depth[level].getOffsetY()));
return container;
}
use of javafx.scene.Node in project JFoenix by jfoenixadmin.
the class JFXComboBox method defaultNodeConverter.
private static <T> NodeConverter<T> defaultNodeConverter() {
return new NodeConverter<T>() {
@Override
public Node toNode(T object) {
if (object == null)
return null;
StackPane selectedValueContainer = new StackPane();
selectedValueContainer.getStyleClass().add("combo-box-selected-value-container");
selectedValueContainer.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null)));
Label selectedValueLabel;
if (object instanceof Label)
selectedValueLabel = new Label(((Label) object).getText());
else
selectedValueLabel = new Label(object.toString());
selectedValueLabel.setTextFill(Color.BLACK);
selectedValueContainer.getChildren().add(selectedValueLabel);
StackPane.setAlignment(selectedValueLabel, Pos.CENTER_LEFT);
StackPane.setMargin(selectedValueLabel, new Insets(0, 0, 0, 5));
return selectedValueContainer;
}
@SuppressWarnings("unchecked")
@Override
public T fromNode(Node node) {
return (T) node;
}
@Override
public String toString(T object) {
if (object == null)
return null;
if (object instanceof Label)
return ((Label) object).getText();
return object.toString();
}
};
}
Aggregations