Skip to content

Commit

Permalink
[prmr#508] Moved window transformation listener to NotificationServic…
Browse files Browse the repository at this point in the history
…e class
  • Loading branch information
ArthusWQZ committed Dec 6, 2023
1 parent 8c701bf commit 4fc4f46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/org/jetuml/JetUML.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.List;
import java.util.Optional;

import javafx.beans.value.ChangeListener;
import org.jetuml.application.UserPreferences;
import org.jetuml.application.Version;
import org.jetuml.diagram.Diagram;
Expand Down Expand Up @@ -105,18 +104,6 @@ public void start(Stage pStage) throws Exception
diagramToOpen.ifPresent(diagram -> editor.setOpenFileAsDiagram(fileToOpen.get(), diagram));
pStage.setScene(new Scene(editor));

// Window position and size listener for notifications
ChangeListener<Number> stageTransformationListener = (pObservableValue, pOldValue, pNewValue) ->
NotificationService.instance().updateNotificationPosition();

// When the stage is moved, update the notification positions
pStage.xProperty().addListener(stageTransformationListener);
pStage.yProperty().addListener(stageTransformationListener);

// When the stage is resized, update the notification positions
pStage.heightProperty().addListener(stageTransformationListener);
pStage.widthProperty().addListener(stageTransformationListener);

NotificationService.instance().setMainStage(pStage);

pStage.getScene().getStylesheets().add(getClass().getResource("JetUML.css").toExternalForm());
Expand Down
16 changes: 16 additions & 0 deletions src/org/jetuml/gui/NotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*******************************************************************************/
package org.jetuml.gui;

import javafx.beans.value.ChangeListener;
import javafx.stage.Stage;
import org.jetuml.annotations.Singleton;

Expand Down Expand Up @@ -68,6 +69,21 @@ public static NotificationService instance()
public void setMainStage(Stage pStage)
{
this.aMainStage = pStage;

if (pStage != null)
{
// Window position and size listener for notifications
ChangeListener<Number> stageTransformationListener = (pObservableValue, pOldValue, pNewValue) ->
NotificationService.instance().updateNotificationPosition();

// When the stage is moved, update the notification positions
pStage.xProperty().addListener(stageTransformationListener);
pStage.yProperty().addListener(stageTransformationListener);

// When the stage is resized, update the notification positions
pStage.heightProperty().addListener(stageTransformationListener);
pStage.widthProperty().addListener(stageTransformationListener);
}
}

/**
Expand Down

0 comments on commit 4fc4f46

Please sign in to comment.