Skip to content

Commit

Permalink
Jetty 12 upgrade WS working but a few glitches still. Tidy up of UI s…
Browse files Browse the repository at this point in the history
…upport
  • Loading branch information
davetcc committed Nov 17, 2024
1 parent 8432588 commit 110af8e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
Expand All @@ -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)),
Expand All @@ -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)
Expand All @@ -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.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
3 changes: 1 addition & 2 deletions java/embeddedJavaDeviceUI/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 110af8e

Please sign in to comment.