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 656025a..d8d55c5 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 @@ -17,25 +17,22 @@ import javafx.scene.control.Button; 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 javafx.scene.paint.Color; import javafx.util.Pair; -import java.util.HashMap; import java.util.List; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import static com.thecoderscorner.embedcontrol.core.controlmgr.EditorComponent.PortableAlignment; import static com.thecoderscorner.embedcontrol.core.controlmgr.color.ControlColor.*; -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. As the base class extends `BaseCustomMenuPanel` +/// panel. See `JfxLocalAutoUI` where this panel is added. As the class extends `BaseCustomMenuPanel` /// 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` to update such items yourself. @@ -70,12 +67,13 @@ protected void populateGrid() { } // now we add some labels into the grid on the left for each menu item - gridPane.add(new Label("Case Temperature"), 0, 0); - gridPane.add(new Label("Light Color"), 0, 1); - gridPane.add(new Label("Authenticator"), 0, 2); + putIntoGrid(ComponentSettingsBuilder.forText("Case Temperature", globalColors).withRowCol(0, 0)); + putIntoGrid(ComponentSettingsBuilder.forText("Light Color", globalColors).withRowCol(1, 0)); + putIntoGrid(ComponentSettingsBuilder.forText("Authenticator", globalColors).withRowCol(2, 0)); - // and on the right we create a custom simulation button, that when we click it causes some - // menu items to update automatically + // and on the right we create a custom simulation button that uses native components showing that these forms + // can not only use menu item components, but also native JavaFX components. When we click it causes some menu + // items to update automatically. gridPane.add(new Label("Start Simulating"), 2, 0); var runSimButton = new Button("Run Sim"); runSimButton.setOnAction(_ -> executor.scheduleAtFixedRate(this::updateTemp, 200L, 200L, TimeUnit.MILLISECONDS)); @@ -87,7 +85,6 @@ protected void populateGrid() { // and now we add in a component that will render using the VU meter style. It is a float item, and we provide // custom drawing configuration for it, so it has three ranges: green, orange, red. There are many forms of // custom drawing, this is one common example. - FontInformation font100Pc = new FontInformation(100, SizeMeasurement.PERCENT); var greenOrangeRedNumericCustom = new NumberCustomDrawingConfiguration(List.of( new NumericColorRange(0.0, 70.0, fromFxColor(Color.GREEN), fromFxColor(Color.WHITE)), new NumericColorRange(70.0, 90.0, fromFxColor(Color.ORANGE), fromFxColor(Color.WHITE)), @@ -106,14 +103,14 @@ protected void populateGrid() { putIntoGrid(ComponentSettingsBuilder.forMenuItem(menuDef.getStatusCaseTempOC(), globalColors) .withJustification(PortableAlignment.CENTER) - .withPosition(new ComponentPositioning(0, 1)) + .withRowCol(0, 1) .withDrawMode(RedrawingMode.SHOW_VALUE) .withControlType(ControlType.VU_METER) .withCustomDrawing(greenOrangeRedNumericCustom)); // Here we create an IoT manager button that represents the IoT Monitor menu item putIntoGrid(ComponentSettingsBuilder.forMenuItem(menuDef.getStatusIoTMonitor(), globalColors) - .withPosition(new ComponentPositioning(2, 1))); + .withRowCol(2, 1)); // Here we create an RGB control from the status light color menu item. putIntoGrid(ComponentSettingsBuilder.forMenuItem(menuDef.getStatusLightColor(), globalColors) @@ -136,6 +133,7 @@ public String getPanelName() { @Override public void entirelyRebuildGrid() { - // in here you put anything that would be needed should the menu structurally change. + // In here you put anything that would be needed should the menu structurally change. This will be called + // fairly infrequently. Example would be when a connection is lost and then subsequent bootstrap. } } diff --git a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/TcJettyWebServer.java b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/TcJettyWebServer.java index 8dae028..3154e04 100644 --- a/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/TcJettyWebServer.java +++ b/java/embeddedJavaDeviceUI/src/main/java/com/thecoderscorner/menu/devicedemo/optional/TcJettyWebServer.java @@ -9,6 +9,10 @@ import com.thecoderscorner.menu.remote.protocol.CommandProtocol; import com.thecoderscorner.menu.remote.protocol.ProtocolHelper; import org.eclipse.jetty.ee10.servlet.ServletContextHandler; +import org.eclipse.jetty.ee10.servlet.ServletHolder; +import org.eclipse.jetty.ee10.websocket.server.JettyWebSocketServlet; +import org.eclipse.jetty.ee10.websocket.server.JettyWebSocketServletFactory; +import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletContainerInitializer; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.ContextHandler; @@ -20,6 +24,8 @@ import org.eclipse.jetty.websocket.api.Session; import java.nio.ByteBuffer; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Clock; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -56,26 +62,25 @@ public void start(NewServerConnectionListener listener) { try { this.listener = listener; server = new Server(portNumber); - var serverConnector = new ServerConnector(server); - server.addConnector(serverConnector); var staticHandler = new ResourceHandler(); staticHandler.setDirAllowed(listDirectories); staticHandler.setWelcomeFiles("index.html"); - staticHandler.setBaseResource(ResourceFactory.of(serverConnector).newResource(resourceDirectory)); + Path webRootPath = Paths.get(resourceDirectory).toAbsolutePath().normalize(); + staticHandler.setBaseResource(ResourceFactory.of(server).newResource(webRootPath)); var contextHandler = new ContextHandler(); contextHandler.setHandler(staticHandler); - ServletContextHandler static_handler = new ServletContextHandler(); - static_handler.insertHandler(new GzipHandler()); - static_handler.setContextPath("/"); - static_handler.setBaseResourceAsString(resource_base); + ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); + servletContext.setContextPath("/"); - - webSockEndpoint = new TcJettyWebSocketEndpoint(); + JettyWebSocketServletContainerInitializer.configure(servletContext, null); + var wsHolder = new ServletHolder("tcmenu", new TcMenuWebSocket()); + servletContext.addServlet(wsHolder, "/ws/*"); var handlers = new ContextHandlerCollection(); handlers.addHandler(contextHandler); + handlers.addHandler(servletContext); server.setHandler(handlers); server.start(); @@ -220,4 +225,13 @@ public void socketDidClose() { if (connectionListener.get() != null) connectionListener.get().accept(this, false); } } + + public class TcMenuWebSocket extends JettyWebSocketServlet + { + @Override + public void configure(JettyWebSocketServletFactory factory) + { + factory.register(TcJettyWebSocketEndpoint.class); + } + } } diff --git a/java/embeddedJavaDeviceUI/src/main/java/module-info.java b/java/embeddedJavaDeviceUI/src/main/java/module-info.java index f857796..38213ad 100644 --- a/java/embeddedJavaDeviceUI/src/main/java/module-info.java +++ b/java/embeddedJavaDeviceUI/src/main/java/module-info.java @@ -11,6 +11,5 @@ exports com.thecoderscorner.menu.devicedemo.optional; opens com.thecoderscorner.menu.devicedemo; - requires org.eclipse.jetty.websocket.api; - requires org.eclipse.jetty.ee10.servlet; + requires org.eclipse.jetty.ee10.websocket.jetty.server; } diff --git a/java/embeddedJavaDeviceUI/target/classes/application.properties b/java/embeddedJavaDeviceUI/target/classes/application.properties index 022bb6c..5cae29e 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-16T08:51:43Z +build.timestamp=2024-11-17T09:05:23Z # server name properties server.name=Embedded Java Demo