use of javafx.geometry.BoundingBox in project JFoenix by jfoenixadmin.
the class JFXMasonryPane method layoutChildren.
/**
* {@inheritDoc}
*/
@Override
protected void layoutChildren() {
performingLayout = true;
int col, row;
col = (int) Math.floor((getWidth() + getHSpacing() - snappedLeftInset() - snappedRightInset()) / (getCellWidth() + getHSpacing()));
col = getLimitColumn() != -1 && col > getLimitColumn() ? getLimitColumn() : col;
if (matrix != null && col == matrix[0].length) {
performingLayout = false;
return;
}
// (int) Math.floor(this.getHeight() / (cellH + 2*vSpacing));
row = getLimitRow();
matrix = new int[row][col];
double minWidth = -1;
double minHeight = -1;
List<BoundingBox> newBoxes;
List<Region> managedChildren = getManagedChildren();
// filter Region nodes
for (int i = 0; i < managedChildren.size(); i++) {
if (!(managedChildren.get(i) instanceof Region)) {
managedChildren.remove(i);
i--;
}
}
// get bounding boxes layout
newBoxes = layoutMode.get().fillGrid(matrix, managedChildren, getCellWidth(), getCellHeight(), row, col, getHSpacing(), getVSpacing());
if (newBoxes == null) {
performingLayout = false;
return;
}
HashMap<Node, BoundingBox> oldBoxes = boundingBoxes;
if (dirtyBoxes) {
boundingBoxes = new HashMap<>();
}
for (int i = 0; i < managedChildren.size() && i < newBoxes.size(); i++) {
final Region child = managedChildren.get(i);
final BoundingBox boundingBox = newBoxes.get(i);
if (!(child instanceof GridPane)) {
double blockX;
double blockY;
double blockWidth;
double blockHeight;
if (boundingBox != null) {
blockX = boundingBox.getMinY() * getCellWidth() + boundingBox.getMinY() * getHSpacing() + snappedLeftInset();
blockY = boundingBox.getMinX() * getCellHeight() + boundingBox.getMinX() * getVSpacing() + snappedTopInset();
blockWidth = boundingBox.getWidth() * getCellWidth() + (boundingBox.getWidth() - 1) * getHSpacing();
blockHeight = boundingBox.getHeight() * getCellHeight() + (boundingBox.getHeight() - 1) * getVSpacing();
} else {
blockX = child.getLayoutX();
blockY = child.getLayoutY();
blockWidth = -1;
blockHeight = -1;
}
if (animationMap == null) {
// init static children
child.setPrefSize(blockWidth, blockHeight);
child.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
} else {
BoundingBox oldBoundingBox = oldBoxes.get(child);
if (oldBoundingBox == null || (!oldBoundingBox.equals(boundingBox) && dirtyBoxes)) {
// handle new children
child.setOpacity(0);
child.setPrefSize(blockWidth, blockHeight);
child.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
}
if (boundingBox != null) {
// handle children repositioning
if (child.getWidth() != blockWidth || child.getHeight() != blockHeight) {
child.setOpacity(0);
child.setPrefSize(blockWidth, blockHeight);
child.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
}
final KeyFrame keyFrame = new KeyFrame(Duration.millis(2000), new KeyValue(child.opacityProperty(), 1, Interpolator.LINEAR), new KeyValue(child.layoutXProperty(), blockX, Interpolator.LINEAR), new KeyValue(child.layoutYProperty(), blockY, Interpolator.LINEAR));
animationMap.put(child, new CachedTransition(child, new Timeline(keyFrame)) {
{
setCycleDuration(Duration.seconds(0.320));
setDelay(Duration.seconds(0));
setOnFinished((finish) -> {
child.setLayoutX(blockX);
child.setLayoutY(blockY);
child.setOpacity(1);
});
}
});
} else {
// handle children is being hidden ( cause it can't fit in the pane )
final KeyFrame keyFrame = new KeyFrame(Duration.millis(2000), new KeyValue(child.opacityProperty(), 0, Interpolator.LINEAR), new KeyValue(child.layoutXProperty(), blockX, Interpolator.LINEAR), new KeyValue(child.layoutYProperty(), blockY, Interpolator.LINEAR));
animationMap.put(child, new CachedTransition(child, new Timeline(keyFrame)) {
{
setCycleDuration(Duration.seconds(0.320));
setDelay(Duration.seconds(0));
setOnFinished((finish) -> {
child.setLayoutX(blockX);
child.setLayoutY(blockY);
child.setOpacity(0);
});
}
});
}
}
// update bounding box
boundingBoxes.put(child, boundingBox);
if (boundingBox != null) {
if (blockX + blockWidth > minWidth) {
minWidth = blockX + blockWidth;
}
if (blockY + blockHeight > minHeight) {
minHeight = blockY + blockHeight;
}
}
}
}
if (minHeight != -1) {
minHeight += snappedBottomInset();
setPrefHeight(minHeight);
}
if (animationMap == null) {
animationMap = new HashMap<>();
}
trans.stop();
ParallelTransition newTransition = new ParallelTransition();
newTransition.getChildren().addAll(animationMap.values());
newTransition.play();
trans = newTransition;
dirtyBoxes = false;
performingLayout = false;
}
use of javafx.geometry.BoundingBox in project JFoenix by jfoenixadmin.
the class JFXDecorator method maximize.
private void maximize(SVGGlyph resizeMin, SVGGlyph resizeMax) {
if (!isCustomMaximize()) {
primaryStage.setMaximized(!primaryStage.isMaximized());
maximized = primaryStage.isMaximized();
if (primaryStage.isMaximized()) {
btnMax.setGraphic(resizeMin);
btnMax.setTooltip(new Tooltip("Restore Down"));
} else {
btnMax.setGraphic(resizeMax);
btnMax.setTooltip(new Tooltip("Maximize"));
}
} else {
if (!maximized) {
// store original bounds
originalBox = new BoundingBox(primaryStage.getX(), primaryStage.getY(), primaryStage.getWidth(), primaryStage.getHeight());
// get the max stage bounds
Screen screen = Screen.getScreensForRectangle(primaryStage.getX(), primaryStage.getY(), primaryStage.getWidth(), primaryStage.getHeight()).get(0);
Rectangle2D bounds = screen.getVisualBounds();
maximizedBox = new BoundingBox(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
// maximized the stage
primaryStage.setX(maximizedBox.getMinX());
primaryStage.setY(maximizedBox.getMinY());
primaryStage.setWidth(maximizedBox.getWidth());
primaryStage.setHeight(maximizedBox.getHeight());
btnMax.setGraphic(resizeMin);
btnMax.setTooltip(new Tooltip("Restore Down"));
} else {
// restore stage to its original size
primaryStage.setX(originalBox.getMinX());
primaryStage.setY(originalBox.getMinY());
primaryStage.setWidth(originalBox.getWidth());
primaryStage.setHeight(originalBox.getHeight());
originalBox = null;
btnMax.setGraphic(resizeMax);
btnMax.setTooltip(new Tooltip("Maximize"));
}
maximized = !maximized;
}
}
use of javafx.geometry.BoundingBox in project JFoenix by jfoenixadmin.
the class JFXHighlighter method getMatchingBounds.
private ArrayList<Bounds> getMatchingBounds(String query, Text text) {
// find local text bounds in parent
Bounds textBounds = parent.sceneToLocal(text.localToScene(text.getBoundsInLocal()));
ArrayList<Bounds> rectBounds = new ArrayList<>();
TextLayout textLayout = null;
try {
textLayout = (TextLayout) textLayoutMethod.invoke(text);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
int queryLength = query.length();
TextLine[] lines = textLayout.getLines();
// handle matches in all lines
for (int i = 0; i < lines.length; i++) {
TextLine line = lines[i];
String lineText = text.getText().substring(line.getStart(), line.getStart() + line.getLength());
final String lineTextLow = lineText.toLowerCase();
final String queryLow = query.toLowerCase();
int beginIndex = lineTextLow.indexOf(queryLow);
if (beginIndex == -1) {
continue;
}
RectBounds lineBounds = (line.getBounds());
// compute Y layout
double height = Math.round(lineBounds.getMaxY()) - Math.round(lineBounds.getMinY());
double startY = height * i;
// handle multiple matches in one line
while (beginIndex != -1) {
// compute X layout
Text temp = new Text(lineText.substring(beginIndex, beginIndex + queryLength));
temp.setFont(text.getFont());
temp.applyCss();
double width = temp.getLayoutBounds().getWidth();
temp.setText(lineText.substring(0, beginIndex + queryLength));
temp.applyCss();
double maxX = temp.getLayoutBounds().getMaxX();
double startX = maxX - width;
rectBounds.add(new BoundingBox(textBounds.getMinX() + startX, textBounds.getMinY() + startY, width, temp.getLayoutBounds().getHeight()));
beginIndex = lineTextLow.indexOf(queryLow, beginIndex + queryLength);
}
}
return rectBounds;
}
Aggregations