From 1c053b33552c5259896c6c7d037f9a810494e3e3 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 13 Dec 2023 04:15:24 +0100 Subject: [PATCH] fix: fixed bugs --- .../main/java/com/resourcetracker/GUI.java | 2 + .../service/element/common/WindowHelper.java | 6 -- .../element/graph/GraphVisualizer.java | 12 +-- .../image/view/ConnectionStatusImageView.java | 1 + .../layout/common/ConnectionStatusHBox.java | 2 +- .../element/layout/common/LandingHBox.java | 43 ++++++++++ .../layout/scene/main/StartSceneLayout.java | 84 ++++++++++++++----- .../service/element/stage/MainStage.java | 23 +++-- .../service/event/state/LocalState.java | 46 ++++++---- .../payload/WindowHeightUpdateEvent.java | 3 + .../state/payload/WindowWidthUpdateEvent.java | 3 + .../resource/observer/ResourceObserver.java | 6 ++ gui/src/main/resources/application.properties | 4 +- gui/src/main/resources/smartgraph.css | 3 +- gui/src/main/resources/smartgraph.properties | 10 +-- 15 files changed, 183 insertions(+), 65 deletions(-) create mode 100644 gui/src/main/java/com/resourcetracker/service/element/layout/common/LandingHBox.java diff --git a/gui/src/main/java/com/resourcetracker/GUI.java b/gui/src/main/java/com/resourcetracker/GUI.java index 0fcc04af..ce1a9e90 100644 --- a/gui/src/main/java/com/resourcetracker/GUI.java +++ b/gui/src/main/java/com/resourcetracker/GUI.java @@ -1,7 +1,9 @@ package com.resourcetracker; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; +@EnableAsync @SpringBootApplication public class GUI { public static void main(String[] args) { diff --git a/gui/src/main/java/com/resourcetracker/service/element/common/WindowHelper.java b/gui/src/main/java/com/resourcetracker/service/element/common/WindowHelper.java index c9b01e11..e7fb82c8 100644 --- a/gui/src/main/java/com/resourcetracker/service/element/common/WindowHelper.java +++ b/gui/src/main/java/com/resourcetracker/service/element/common/WindowHelper.java @@ -18,12 +18,6 @@ public static void switchScene(Scene prev, Scene next) { ((Stage) prev.getWindow()).setScene(next); } - // - // public static void switchStage(Stage prev, Stage next) { - // prev.close(); - // next.show(); - // } - /** Retrieves */ public static Point2D getCentralPoint(Double width, Double height) { Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds(); diff --git a/gui/src/main/java/com/resourcetracker/service/element/graph/GraphVisualizer.java b/gui/src/main/java/com/resourcetracker/service/element/graph/GraphVisualizer.java index d228a374..7f2f8034 100644 --- a/gui/src/main/java/com/resourcetracker/service/element/graph/GraphVisualizer.java +++ b/gui/src/main/java/com/resourcetracker/service/element/graph/GraphVisualizer.java @@ -85,11 +85,13 @@ public GraphVisualizer( } catch (URISyntaxException e) { throw new SmartGraphCssFileNotFoundException(e.getMessage()); } -// -// ElementStorage.setElement( -// id, -// new SmartGraphPanel<>( -// g, smartGraphProperties, strategy, smartGraphCssFileLocationURI)); + + + + ElementStorage.setElement( + id, + new SmartGraphPanel<>( + g, smartGraphProperties, strategy, smartGraphCssFileLocationURI)); } /** diff --git a/gui/src/main/java/com/resourcetracker/service/element/image/view/ConnectionStatusImageView.java b/gui/src/main/java/com/resourcetracker/service/element/image/view/ConnectionStatusImageView.java index c1dd6c31..91ec2c1d 100644 --- a/gui/src/main/java/com/resourcetracker/service/element/image/view/ConnectionStatusImageView.java +++ b/gui/src/main/java/com/resourcetracker/service/element/image/view/ConnectionStatusImageView.java @@ -12,6 +12,7 @@ import com.resourcetracker.service.element.storage.ElementStorage; import com.resourcetracker.service.event.state.LocalState; import javafx.application.Platform; +import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.SplitPane; import javafx.scene.control.Tooltip; diff --git a/gui/src/main/java/com/resourcetracker/service/element/layout/common/ConnectionStatusHBox.java b/gui/src/main/java/com/resourcetracker/service/element/layout/common/ConnectionStatusHBox.java index 7632fa7c..a33d028d 100644 --- a/gui/src/main/java/com/resourcetracker/service/element/layout/common/ConnectionStatusHBox.java +++ b/gui/src/main/java/com/resourcetracker/service/element/layout/common/ConnectionStatusHBox.java @@ -19,7 +19,7 @@ public class ConnectionStatusHBox implements IElement { public ConnectionStatusHBox(SplitPane connectionStatusImage) { HBox hBox = new HBox(connectionStatusImage); - hBox.setAlignment(Pos.CENTER_RIGHT); + hBox.setAlignment(Pos.TOP_RIGHT); ElementStorage.setElement(id, hBox); } diff --git a/gui/src/main/java/com/resourcetracker/service/element/layout/common/LandingHBox.java b/gui/src/main/java/com/resourcetracker/service/element/layout/common/LandingHBox.java new file mode 100644 index 00000000..240df244 --- /dev/null +++ b/gui/src/main/java/com/resourcetracker/service/element/layout/common/LandingHBox.java @@ -0,0 +1,43 @@ +package com.resourcetracker.service.element.layout.common; + +import com.resourcetracker.service.element.IElement; +import com.resourcetracker.service.element.IElementResizable; +import com.resourcetracker.service.element.storage.ElementStorage; +import javafx.scene.Node; +import javafx.scene.layout.HBox; + +import java.util.UUID; + +public class LandingHBox implements IElementResizable, IElement { + UUID id = UUID.randomUUID(); + + public LandingHBox(Node... elements) { + HBox hbox = new HBox(20, elements); + + ElementStorage.setElement(id, hbox); + } + + /** + * @return + */ + @Override + public HBox getContent() { + return ElementStorage.getElement(id); + } + + /** + * + */ + @Override + public void handlePrefWidth() { + + } + + /** + * + */ + @Override + public void handlePrefHeight() { + + } +} diff --git a/gui/src/main/java/com/resourcetracker/service/element/layout/scene/main/StartSceneLayout.java b/gui/src/main/java/com/resourcetracker/service/element/layout/scene/main/StartSceneLayout.java index 8d28dc74..4d5c2cd7 100644 --- a/gui/src/main/java/com/resourcetracker/service/element/layout/scene/main/StartSceneLayout.java +++ b/gui/src/main/java/com/resourcetracker/service/element/layout/scene/main/StartSceneLayout.java @@ -5,39 +5,59 @@ import com.resourcetracker.service.element.IElementResizable; import com.resourcetracker.service.element.button.BasicButton; import com.resourcetracker.service.element.common.WindowHelper; +import com.resourcetracker.service.element.graph.GraphVisualizer; import com.resourcetracker.service.element.image.view.ConnectionStatusImageView; import com.resourcetracker.service.element.layout.common.ButtonVBox; import com.resourcetracker.service.element.layout.common.ConnectionStatusHBox; +import com.resourcetracker.service.element.layout.common.LandingHBox; import com.resourcetracker.service.element.menu.TabMenuBar; import com.resourcetracker.service.element.scene.main.DeploymentDetailsScene; import com.resourcetracker.service.element.scene.main.DeploymentScene; +import com.resourcetracker.service.element.scene.main.StartScene; import com.resourcetracker.service.element.scene.settings.SettingsLanguagesScene; +import com.resourcetracker.service.element.stage.SettingsStage; import com.resourcetracker.service.element.storage.ElementStorage; import com.resourcetracker.service.event.state.LocalState; +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; +import javafx.scene.layout.RowConstraints; +import org.apache.logging.log4j.core.tools.picocli.CommandLine; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import java.awt.*; import java.util.UUID; @Service public class StartSceneLayout implements IElementResizable, IElement { UUID id = UUID.randomUUID(); + @Lazy + @Autowired + private StartScene startScene; + + @Lazy + @Autowired + private DeploymentScene deploymentScene; + + @Lazy + @Autowired + private DeploymentDetailsScene deploymentDetailsScene; + public StartSceneLayout( @Autowired PropertiesEntity properties, - @Autowired SettingsLanguagesScene settingsLanguagesScene, - @Autowired ConnectionStatusImageView connectionStatusImageView + @Autowired SettingsStage settingsStage, + @Autowired ConnectionStatusImageView connectionStatusImageView, + @Autowired GraphVisualizer graphVisualizer ) { -// @Autowired DeploymentScene deploymentScene, -// @Autowired DeploymentDetailsScene deploymentDetailsScene, -// @Autowired SettingsLanguagesScene settingsLanguagesScene, - GridPane grid = new GridPane(); grid.setVgap(20); - grid.setMinWidth(400); grid.setGridLinesVisible(true); ConnectionStatusHBox connectionStatusHBox = new ConnectionStatusHBox( @@ -48,28 +68,49 @@ public StartSceneLayout( new BasicButton( "Start", properties, - () -> { - WindowHelper.switchScene(getContent().getScene(), settingsLanguagesScene.getContent()); - System.out.println("it start"); - }) + () -> WindowHelper.switchScene(getContent().getScene(), startScene.getContent())) .getContent(), new BasicButton( "Deployment", properties, - () -> { - System.out.println("it deployment"); - }) + () -> WindowHelper.switchScene(getContent().getScene(), deploymentScene.getContent())) .getContent(), new BasicButton( "Settings", properties, - () -> { - System.out.println("it settings"); - }) + () -> settingsStage.getContent().show()) .getContent()); - grid.addRow(0, connectionStatusHBox.getContent()); - grid.addRow(1, buttonVBox.getContent()); +// graphVisualizer.getContent().setTranslateX(100); +// graphVisualizer.getContent().setTranslateY(100); + + Label label = new Label("Your long text here"); + label.setAlignment(Pos.CENTER); + label.setMaxWidth(180); + label.setWrapText(true); + + LandingHBox landingHBox = new LandingHBox( + buttonVBox.getContent(), label); + + ColumnConstraints column1 = new ColumnConstraints(); + column1.setHgrow(Priority.ALWAYS); + + grid.getColumnConstraints().add(0, column1); + + RowConstraints row1 = new RowConstraints(); + row1.setPercentHeight(5); + RowConstraints row2 = new RowConstraints(); + row2.setPercentHeight(70); + + grid.getRowConstraints().add(0, row1); + grid.getRowConstraints().add(1, row2); + + grid.addColumn(0, connectionStatusHBox.getContent(), + landingHBox.getContent()); + +// grid.addRow(0, +// ); +// grid.addRow(1, ); // // // GraphVisualizer graphVisualizer = new GraphVisualizer(); // @@ -98,8 +139,7 @@ public GridPane getContent() { */ @Override public void handlePrefWidth() { - System.out.println(LocalState.getWindowWidth()); - + getContent().setMinWidth(LocalState.getWindowWidth()); } /** @@ -107,6 +147,6 @@ public void handlePrefWidth() { */ @Override public void handlePrefHeight() { - System.out.println(LocalState.getWindowHeight()); + getContent().setMinHeight(LocalState.getWindowHeight()); } } diff --git a/gui/src/main/java/com/resourcetracker/service/element/stage/MainStage.java b/gui/src/main/java/com/resourcetracker/service/element/stage/MainStage.java index 45d0c627..304b9476 100644 --- a/gui/src/main/java/com/resourcetracker/service/element/stage/MainStage.java +++ b/gui/src/main/java/com/resourcetracker/service/element/stage/MainStage.java @@ -5,16 +5,23 @@ import com.resourcetracker.service.element.common.WindowHelper; import com.resourcetracker.service.element.scene.main.StartScene; import java.util.UUID; +import java.util.concurrent.CountDownLatch; import com.resourcetracker.service.element.storage.ElementStorage; +import com.resourcetracker.service.event.state.LocalState; import com.resourcetracker.service.event.state.payload.WindowHeightUpdateEvent; import com.resourcetracker.service.event.state.payload.WindowWidthUpdateEvent; +import jakarta.annotation.PostConstruct; import javafx.application.Platform; import javafx.geometry.Point2D; import javafx.geometry.Rectangle2D; import javafx.stage.Stage; +import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cglib.core.Local; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; /** MainStage represents main window. */ @@ -22,7 +29,7 @@ public class MainStage implements IElement { UUID id = UUID.randomUUID(); - public MainStage( + public MainStage( @Autowired PropertiesEntity properties, @Autowired StartScene startScene, @Autowired ApplicationEventPublisher applicationEventPublisher) { @@ -31,7 +38,7 @@ public MainStage( Stage mainStage = new Stage(); mainStage.setTitle(properties.getWindowMainName()); - Rectangle2D window = + Rectangle2D window = WindowHelper.getSizeWithScale( properties.getWindowMainScaleWidth(), properties.getWindowMainScaleHeight()); mainStage.setWidth(window.getWidth()); @@ -49,13 +56,17 @@ public MainStage( mainStage .widthProperty() .addListener( - (obs, oldVal, newVal) -> applicationEventPublisher.publishEvent( - new WindowWidthUpdateEvent(newVal.doubleValue()))); + (obs, oldVal, newVal) -> { + applicationEventPublisher.publishEvent( + new WindowWidthUpdateEvent(newVal.doubleValue())); + }); mainStage .heightProperty() .addListener( - (obs, oldVal, newVal) -> applicationEventPublisher.publishEvent( - new WindowHeightUpdateEvent(newVal.doubleValue()))); + (obs, oldVal, newVal) -> { + applicationEventPublisher.publishEvent( + new WindowHeightUpdateEvent(newVal.doubleValue())); + }); ElementStorage.setElement(id, mainStage); }); diff --git a/gui/src/main/java/com/resourcetracker/service/event/state/LocalState.java b/gui/src/main/java/com/resourcetracker/service/event/state/LocalState.java index 5cc16e57..057f4565 100644 --- a/gui/src/main/java/com/resourcetracker/service/event/state/LocalState.java +++ b/gui/src/main/java/com/resourcetracker/service/event/state/LocalState.java @@ -1,16 +1,22 @@ package com.resourcetracker.service.event.state; +import com.resourcetracker.entity.PropertiesEntity; +import com.resourcetracker.service.element.common.WindowHelper; import com.resourcetracker.service.event.state.payload.ConnectionStatusEvent; import com.resourcetracker.service.event.state.payload.WindowHeightUpdateEvent; import com.resourcetracker.service.event.state.payload.WindowWidthUpdateEvent; import javafx.geometry.Rectangle2D; import lombok.Getter; import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cglib.core.Local; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import java.util.Objects; +import java.util.concurrent.CountDownLatch; /** * Represents local state management model, which is used to handle application state changes and @@ -18,6 +24,12 @@ */ @Component public class LocalState { + @Autowired + private PropertiesEntity properties; + + @Autowired + private ApplicationEventPublisher applicationEventPublisher; + @Getter @Setter private static Boolean connectionEstablished = false; @Getter @Setter private static Double prevWindowHeight; @@ -28,20 +40,18 @@ public class LocalState { @Getter @Setter private static Double windowWidth; + @Getter private static CountDownLatch locker = new CountDownLatch(1); /** * * @return */ public static Boolean isWindowHeightChanged() { - if (Objects.isNull(LocalState.getPrevWindowHeight())) { + if (Objects.isNull(LocalState.getPrevWindowHeight()) && !Objects.isNull(LocalState.getWindowHeight())) { + return true; + } else if (Objects.isNull(LocalState.getPrevWindowHeight())) { return false; } -// System.out.println("before"); -// System.out.println(prevWindowHeight); -// System.out.println(windowHeight); -// System.out.println("after"); - return !prevWindowHeight.equals(windowHeight); } @@ -50,7 +60,9 @@ public static Boolean isWindowHeightChanged() { * @return */ public static Boolean isWindowWidthChanged() { - if (Objects.isNull(LocalState.getPrevWindowWidth())) { + if (Objects.isNull(LocalState.getPrevWindowWidth()) && !Objects.isNull(LocalState.getWindowWidth())) { + return true; + } else if (Objects.isNull(LocalState.getPrevWindowWidth())) { return false; } @@ -71,6 +83,18 @@ public static synchronized void synchronizeWindowWidth() { LocalState.setPrevWindowWidth(LocalState.getWindowWidth()); } + @EventListener(classes = {ContextRefreshedEvent.class}) + public void eventListen(ContextRefreshedEvent contextRefreshedEvent) { + Rectangle2D window = + WindowHelper.getSizeWithScale( + properties.getWindowMainScaleWidth(), properties.getWindowMainScaleHeight()); + + applicationEventPublisher.publishEvent( + new WindowWidthUpdateEvent(window.getWidth())); + applicationEventPublisher.publishEvent( + new WindowHeightUpdateEvent(window.getHeight())); + } + /** * Handles changes of connection establishment status. * @param event connection status event, which contains connection establishment status. @@ -86,10 +110,6 @@ void handleConnectionStatusEvent(ConnectionStatusEvent event) { */ @EventListener void handleWindowHeightUpdateEvent(WindowHeightUpdateEvent event) { - if (Objects.isNull(LocalState.getPrevWindowHeight())) { - LocalState.setPrevWindowHeight(event.getHeight()); - } - LocalState.setWindowHeight(event.getHeight()); } @@ -99,10 +119,6 @@ void handleWindowHeightUpdateEvent(WindowHeightUpdateEvent event) { */ @EventListener void handleWindowWidthUpdateEvent(WindowWidthUpdateEvent event) { - if (Objects.isNull(LocalState.getPrevWindowWidth())) { - LocalState.setPrevWindowWidth(event.getWidth()); - } - LocalState.setWindowWidth(event.getWidth()); } } diff --git a/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowHeightUpdateEvent.java b/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowHeightUpdateEvent.java index 5fc0d4a1..b17e1c01 100644 --- a/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowHeightUpdateEvent.java +++ b/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowHeightUpdateEvent.java @@ -3,6 +3,9 @@ import lombok.Getter; import org.springframework.context.ApplicationEvent; +/** + * + */ @Getter public class WindowHeightUpdateEvent extends ApplicationEvent { private final Double height; diff --git a/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowWidthUpdateEvent.java b/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowWidthUpdateEvent.java index df6f71a6..c24bb754 100644 --- a/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowWidthUpdateEvent.java +++ b/gui/src/main/java/com/resourcetracker/service/event/state/payload/WindowWidthUpdateEvent.java @@ -4,6 +4,9 @@ import lombok.Getter; import org.springframework.context.ApplicationEvent; +/** + * + */ @Getter public class WindowWidthUpdateEvent extends ApplicationEvent { private final Double width; diff --git a/gui/src/main/java/com/resourcetracker/service/resource/observer/ResourceObserver.java b/gui/src/main/java/com/resourcetracker/service/resource/observer/ResourceObserver.java index 5f68b319..337cf874 100644 --- a/gui/src/main/java/com/resourcetracker/service/resource/observer/ResourceObserver.java +++ b/gui/src/main/java/com/resourcetracker/service/resource/observer/ResourceObserver.java @@ -9,6 +9,9 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; +/** + * Provides resource observables to manage state of the application. + */ @Component public class ResourceObserver { @Autowired @@ -20,6 +23,9 @@ public class ResourceObserver { @Autowired private HealthCommandService healthCommandService; + /** + * Sends healthcheck requests to API Server and updates connection status. + */ @PostConstruct private void handleHealthCommand() { SchedulerHelper.scheduleTask(() -> { diff --git a/gui/src/main/resources/application.properties b/gui/src/main/resources/application.properties index 7dae4912..a0f0b24d 100644 --- a/gui/src/main/resources/application.properties +++ b/gui/src/main/resources/application.properties @@ -26,8 +26,8 @@ process.background.period=1000 process.healthcheck.period=500 # Describes frequency of background window size tracker in milliseconds. -process.window.width.period=100 -process.window.height.period=100 +process.window.width.period=50 +process.window.height.period=50 # Describe location of graph css file graph.css.location=smartgraph.css diff --git a/gui/src/main/resources/smartgraph.css b/gui/src/main/resources/smartgraph.css index ff490eeb..0ad355ca 100644 --- a/gui/src/main/resources/smartgraph.css +++ b/gui/src/main/resources/smartgraph.css @@ -1,5 +1,6 @@ .graph { - -fx-background-color: #F4FFFB; + -fx-background-color: #FFFFFF; + -fx-border-radius: 25; } .vertex { diff --git a/gui/src/main/resources/smartgraph.properties b/gui/src/main/resources/smartgraph.properties index 92843dba..61ebc977 100644 --- a/gui/src/main/resources/smartgraph.properties +++ b/gui/src/main/resources/smartgraph.properties @@ -3,19 +3,15 @@ vertex.allow-user-move = true vertex.radius = 15 vertex.tooltip = true -vertex.label = false +vertex.label = true # Edge related configurations # edge.tooltip = true -edge.label = false +edge.label = true # only makes sense if displaying an oriented graph -edge.arrow = false +edge.arrow = true -# (automatic) Force-directed layout related configurations -# -- You should experiment with different values for your -# -- particular problem, knowing that not all will achieve -# -- a stable state layout.repulsive-force = 25000 layout.attraction-force = 30 layout.attraction-scale = 10 \ No newline at end of file