Skip to content

Commit

Permalink
cache the screen the node is on
Browse files Browse the repository at this point in the history
  • Loading branch information
tbee committed Sep 1, 2024
1 parent ef184b8 commit f6e1efc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions javafx/src/main/java/org/tbee/javafx/scene/layout/MigPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.geometry.*;
import javafx.scene.Group;
import javafx.scene.Node;
Expand All @@ -15,14 +16,12 @@
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.Window;
import net.miginfocom.layout.*;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.NoSuchElementException;


/**
Expand Down Expand Up @@ -1007,11 +1006,18 @@ public int getVerticalScreenDPI() {

private Screen getScreen() {
Window window = node.getScene().getWindow();
for (Screen screen : Screen.getScreensForRectangle(window.getX(), window.getY(), 1., 1.)) {
return screen;
}
return Screen.getPrimary();
}

// Cache of one
int screenCacheKey = (window.getX() + "/" + window.getY()).hashCode();
if (screenCacheKey != this.screenCacheKey) {
List<Screen> screens = Screen.getScreensForRectangle(window.getX(), window.getY(), 1., 1.);
screen = (screens.isEmpty() ? Screen.getPrimary() : screens.get(0));
this.screenCacheKey = screenCacheKey;
}
return screen;
}
private int screenCacheKey = 0;
private Screen screen = null;

@Override
public float getPixelUnitFactor(boolean isHor) {
Expand Down

0 comments on commit f6e1efc

Please sign in to comment.