From a9e20298376378d5336bf03c3dd1d6a69c70e09b Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 9 Nov 2024 18:55:38 +0000 Subject: [PATCH] Improvements to custom panel based on 4.4.1 API improvements --- java/embedControlJavaFx/pom.xml | 2 +- .../jfxapp/panel/RemoteConnectionPanel.java | 29 +++--- java/embeddedJavaDeviceUI/data/README.md | 5 +- .../optional/LocalTreeComponentManager.java | 1 + .../optional/StatusPanelDrawable.java | 96 +++---------------- .../devicedemo/optional/UpdatablePanel.java | 15 --- .../target/classes/application.properties | 2 +- 7 files changed, 36 insertions(+), 114 deletions(-) delete mode 100644 java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/UpdatablePanel.java diff --git a/java/embedControlJavaFx/pom.xml b/java/embedControlJavaFx/pom.xml index 8066817..52a1dce 100644 --- a/java/embedControlJavaFx/pom.xml +++ b/java/embedControlJavaFx/pom.xml @@ -17,7 +17,7 @@ 23.0.1 11.6.15 6.0.11 - 4.4.0 + 4.4.1-SNAPSHOT diff --git a/java/embedControlJavaFx/src/main/java/com/thecoderscorner/embedcontrol/jfxapp/panel/RemoteConnectionPanel.java b/java/embedControlJavaFx/src/main/java/com/thecoderscorner/embedcontrol/jfxapp/panel/RemoteConnectionPanel.java index f2da3cd..d41c8d1 100644 --- a/java/embedControlJavaFx/src/main/java/com/thecoderscorner/embedcontrol/jfxapp/panel/RemoteConnectionPanel.java +++ b/java/embedControlJavaFx/src/main/java/com/thecoderscorner/embedcontrol/jfxapp/panel/RemoteConnectionPanel.java @@ -5,7 +5,7 @@ import com.thecoderscorner.embedcontrol.core.creators.RemotePanelDisplayable; import com.thecoderscorner.embedcontrol.core.service.GlobalSettings; import com.thecoderscorner.embedcontrol.core.service.TcMenuPersistedConnection; -import com.thecoderscorner.embedcontrol.core.util.DataException; +import com.thecoderscorner.embedcontrol.jfx.controlmgr.UpdatablePanel; import com.thecoderscorner.embedcontrol.core.util.StringHelper; import com.thecoderscorner.embedcontrol.customization.GlobalColorCustomizable; import com.thecoderscorner.embedcontrol.customization.MenuItemStore; @@ -78,7 +78,6 @@ public class RemoteConnectionPanel implements PanelPresentable, RemotePane private MenuItemStore itemStore; private RemoteControllerListener remoteListener; private RemoteInformation remoteInformation = RemoteInformation.NOT_CONNECTED; - private ContextMenu layoutContextMenu = null; public RemoteConnectionPanel(EmbedControlContext context, MenuItem item, ScheduledExecutorService executorService, TcMenuPersistedConnection connection) { @@ -133,7 +132,7 @@ private void generateWidgets() { private ContextMenu generateSettingsContextMenu() { var colorConfig = new javafx.scene.control.MenuItem("Color Settings"); - colorConfig.setOnAction(evt -> navigationManager.pushNavigation(new ColorSettingsPresentable( + colorConfig.setOnAction(_ -> navigationManager.pushNavigation(new ColorSettingsPresentable( settings, navigationManager, GlobalColorCustomizable.KEY_NAME, true))); var editConfig = new javafx.scene.control.MenuItem("Edit Connection"); editConfig.setOnAction(this::editConnection); @@ -213,8 +212,8 @@ private Node getDialogComponents(BorderPane pane) { GridPane.setHalignment(messageLabel, HPos.CENTER); showDialog(false); - dlgButton1.setOnAction(evt -> dialogManager.buttonWasPressed(dialogManager.getButtonType(1))); - dlgButton2.setOnAction(evt -> dialogManager.buttonWasPressed(dialogManager.getButtonType(2))); + dlgButton1.setOnAction(_ -> dialogManager.buttonWasPressed(dialogManager.getButtonType(1))); + dlgButton2.setOnAction(_ -> dialogManager.buttonWasPressed(dialogManager.getButtonType(2))); return dialogPane; } @@ -278,9 +277,11 @@ public void statusHasChanged(AuthStatus status) { } private void notifyControlGrid(boolean up) { - if(navigationManager.currentNavigationPanel() instanceof JfxMenuPresentable menuPresentable) { - menuPresentable.connectionIsUp(up); - } + Platform.runLater(() -> { + if(navigationManager.currentNavigationPanel() instanceof UpdatablePanel updatablePanel) { + updatablePanel.connectionIsUp(up); + } + }); } private void doPairing() { @@ -319,9 +320,11 @@ private void createNewController() { remoteListener = new RemoteControllerListener() { @Override public void menuItemChanged(MenuItem item, boolean valueOnly) { - if(navigationManager.currentNavigationPanel() instanceof JfxMenuPresentable menuPanel) { - menuPanel.getGridComponent().itemHasUpdated(item); - } + Platform.runLater(() -> { + if(navigationManager.currentNavigationPanel() instanceof UpdatablePanel updatablePanel) { + updatablePanel.itemHasUpdated(item); + } + }); } @Override @@ -354,8 +357,8 @@ public void connectionState(RemoteInformation remoteInformation, AuthStatus conn @Override public void ackReceived(CorrelationId key, MenuItem item, AckStatus status) { if(item == null) return; // we ignore dialog acks at the moment. - if(navigationManager.currentNavigationPanel() instanceof JfxMenuPresentable menuPanel) { - menuPanel.getGridComponent().acknowledgementReceived(key, status); + if(navigationManager.currentNavigationPanel() instanceof UpdatablePanel menuPanel) { + menuPanel.acknowledgedCorrelationId(key, status); } } diff --git a/java/embeddedJavaDeviceUI/data/README.md b/java/embeddedJavaDeviceUI/data/README.md index f453263..fe57f28 100644 --- a/java/embeddedJavaDeviceUI/data/README.md +++ b/java/embeddedJavaDeviceUI/data/README.md @@ -1,3 +1,4 @@ ## Data Directory -This directory will usually contain data files used by the app at runtime. It's copied by the maven -build script at compile time into the deployment directory. +This directory will usually contain data files used by the app at runtime. It's copied by the maven build script at compile time into the deployment directory. + +If you are using EmbedControlJS then you simply copy all the output files from the latest release into the `www` directory to update it, generally speaking it will always work with the latest Java API. diff --git a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/LocalTreeComponentManager.java b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/LocalTreeComponentManager.java index b15751f..e8a3f18 100644 --- a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/LocalTreeComponentManager.java +++ b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/LocalTreeComponentManager.java @@ -2,6 +2,7 @@ import com.thecoderscorner.embedcontrol.jfx.controlmgr.JfxMenuPresentable; import com.thecoderscorner.embedcontrol.jfx.controlmgr.JfxNavigationManager; +import com.thecoderscorner.embedcontrol.jfx.controlmgr.UpdatablePanel; import com.thecoderscorner.menu.domain.MenuItem; import com.thecoderscorner.menu.mgr.MenuManagerListener; import com.thecoderscorner.menu.mgr.MenuManagerServer; diff --git a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/StatusPanelDrawable.java b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/StatusPanelDrawable.java index 39a7fac..cd442ae 100644 --- a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/StatusPanelDrawable.java +++ b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/StatusPanelDrawable.java @@ -5,14 +5,17 @@ import com.thecoderscorner.embedcontrol.customization.FontInformation; import com.thecoderscorner.embedcontrol.customization.FontInformation.SizeMeasurement; import com.thecoderscorner.embedcontrol.customization.customdraw.NumberCustomDrawingConfiguration; +import com.thecoderscorner.embedcontrol.jfx.controlmgr.panels.BaseCustomMenuPanel; import com.thecoderscorner.menu.devicedemo.EmbeddedJavaDemoMenu; -import com.thecoderscorner.menu.domain.MenuItem; import com.thecoderscorner.menu.mgr.MenuManagerServer; import javafx.geometry.HPos; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.layout.*; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; +import javafx.scene.layout.RowConstraints; import javafx.scene.paint.Color; import java.util.HashMap; @@ -21,70 +24,37 @@ import java.util.concurrent.TimeUnit; import static com.thecoderscorner.embedcontrol.core.controlmgr.EditorComponent.PortableAlignment; -import static com.thecoderscorner.embedcontrol.core.controlmgr.EditorComponent.RenderingStatus.NORMAL; -import static com.thecoderscorner.embedcontrol.core.controlmgr.color.ConditionalColoring.ColorComponentType.TEXT_FIELD; -import static com.thecoderscorner.embedcontrol.core.controlmgr.color.ControlColor.asFxColor; import static com.thecoderscorner.embedcontrol.core.controlmgr.color.ControlColor.fromFxColor; import static com.thecoderscorner.embedcontrol.customization.customdraw.CustomDrawingConfiguration.NO_CUSTOM_DRAWING; import static com.thecoderscorner.embedcontrol.customization.customdraw.CustomDrawingConfiguration.NumericColorRange; /// Demonstrates how to create your own panel to be presented instead of an automatic menu panel. Simply /// register this panel with the navigation manager class and it will be presented instead of the standard -/// panel. See `JfxLocalAutoUI` where this panel is added. Any panel that implements `UpdatablePanel` will -/// automatically be told when menu items have updated, and be provided with a tick function for animations. -public class StatusPanelDrawable implements PanelPresentable, UpdatablePanel { +/// panel. See `JfxLocalAutoUI` where this panel is added. As the base class implements `UpdatablePanel` +/// it will automatically be told when menu items have updated, and be provided with a tick function for +/// animations. You can override the methods in `UpdatablePanel` if you use controls other than the +/// standard menu controls created from `ComponentSettings` which will automatically update. +public class StatusPanelDrawable extends BaseCustomMenuPanel { private final EmbeddedJavaDemoMenu menuDef; - private final MenuEditorFactory editorFactory; private final MenuComponentControl componentControl; private final ConditionalColoring globalColors; private final ScheduledExecutorService executor; private final MenuManagerServer manager; - private final HashMap> controlsBeingManaged = new HashMap<>(); - private double presentableWidth = 999; - private GridPane gridPane; - private double lastWidth = 999; public StatusPanelDrawable(EmbeddedJavaDemoMenu menuDef, ScheduledExecutorService executor, MenuEditorFactory factory, MenuComponentControl control, MenuManagerServer manager, ConditionalColoring globalColors) { + super(factory, globalColors, menuDef.getMenuTree(), true); this.menuDef = menuDef; this.executor = executor; - this.editorFactory = factory; this.componentControl = control; - this.manager = manager; this.globalColors = globalColors; + this.manager = manager; } - @Override - public Node getPanelToPresent(double width) throws Exception { - lastWidth = width; - if (gridPane != null) { - // empty it if it already exists to make GC easier - gridPane.getChildren().clear(); - gridPane.getColumnConstraints().clear(); - gridPane.getRowConstraints().clear(); - } - gridPane = makeGridPanel(); - presentableWidth = width; - return gridPane; - } - - private GridPane makeGridPanel() { + protected void populateGrid() { // here we create a JavaFX grid using the regular way of doing so. You can consult the JavaFx documentation // for more on how to create grids. - gridPane = new GridPane(); - gridPane.setHgap(5); - gridPane.setVgap(5); - gridPane.setMaxWidth(9999); - gridPane.setPrefWidth(presentableWidth); - gridPane.getChildren().clear(); - - // the grid will be 4 across by three down. - gridPane.getColumnConstraints().clear(); - gridPane.getRowConstraints().clear(); - gridPane.setBackground(new Background(new BackgroundFill( - asFxColor(globalColors.colorFor(NORMAL, TEXT_FIELD).getBg()), null, null - ))); gridPane.getRowConstraints().add(new RowConstraints(80)); gridPane.getRowConstraints().add(new RowConstraints(20)); gridPane.getRowConstraints().add(new RowConstraints(20)); @@ -100,7 +70,7 @@ private GridPane makeGridPanel() { gridPane.add(new Label("Start Simulating"), 2, 0); var runSimButton = new Button("Run Sim"); - runSimButton.setOnAction(event -> executor.scheduleAtFixedRate(this::updateTemp, 200L, 200L, TimeUnit.MILLISECONDS)); + runSimButton.setOnAction(_ -> executor.scheduleAtFixedRate(this::updateTemp, 200L, 200L, TimeUnit.MILLISECONDS)); gridPane.add(runSimButton, 2, 1); // and now we add in a component that will render using the VU meter style. It is a float item, and we provide @@ -126,8 +96,6 @@ private GridPane makeGridPanel() { globalColors, font100Pc, PortableAlignment.RIGHT, new ComponentPositioning(1, 1), RedrawingMode.SHOW_VALUE, ControlType.RGB_CONTROL, NO_CUSTOM_DRAWING, true)); - - return gridPane; } private void updateTemp() { @@ -135,17 +103,6 @@ private void updateTemp() { manager.updateMenuItem(this, menuDef.getLED1Brightness(), Math.random() * 100 ); } - private void putIntoGrid(MenuItem item, ComponentSettings componentSettings) { - ComponentPositioning pos = componentSettings.getPosition(); - var component = editorFactory.getComponentEditorItem(item, componentSettings, this::noAction); - component.ifPresent(comp -> { - controlsBeingManaged.put(item.getId(), comp); - gridPane.add(comp.createComponent(), pos.getCol(), pos.getRow(), pos.getColSpan(), pos.getRowSpan()); - }); - } - - private void noAction(MenuItem menuItem) { - } @Override public String getPanelName() { @@ -157,29 +114,4 @@ public String getPanelName() { public boolean canBeRemoved() { return true; } - - @Override - public boolean canClose() { - return true; - } - - @Override - public void closePanel() { - controlsBeingManaged.clear(); - } - - @Override - public void itemHasUpdated(MenuItem item) { - if(controlsBeingManaged.containsKey(item.getId())) { - controlsBeingManaged.get(item.getId()).onItemUpdated(item, manager.getManagedMenu().getMenuState(item)); - } - } - - @Override - public void tickAll() { - for(var component : controlsBeingManaged.values()) { - component.tick(); - } - } - } diff --git a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/UpdatablePanel.java b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/UpdatablePanel.java deleted file mode 100644 index bea629f..0000000 --- a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/UpdatablePanel.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.thecoderscorner.menu.devicedemo.optional; - -import com.thecoderscorner.menu.domain.MenuItem; - -/// Represents a `PanelPresentable` that can be updated when menu items change, it is also provided with a -/// tick function so that the implementor can tick down updates that occur. When an item updates the update -/// will be sent through the `itemHasUpdated` method, and you will be on the JavaFx thread when it occurs. -public interface UpdatablePanel { - /// called every 100 millis by the framework so that you can tick any animations that are in progress. - void tickAll(); - - /// called whenever there is a menu item update so that the display can be updated. - /// @param item the item that has updated - void itemHasUpdated(MenuItem item); -} diff --git a/java/embeddedJavaDeviceUI/target/classes/application.properties b/java/embeddedJavaDeviceUI/target/classes/application.properties index 083947f..2439e69 100644 --- a/java/embeddedJavaDeviceUI/target/classes/application.properties +++ b/java/embeddedJavaDeviceUI/target/classes/application.properties @@ -2,7 +2,7 @@ build.version=0.0.1-SNAPSHOT build.groupId=com.thecoderscorner.menuexample build.artifactId=embeddedJavaDeviceUI -build.timestamp=2024-11-09T16:19:17Z +build.timestamp=2024-11-09T17:04:31Z # server name properties server.name=Embedded Java Demo