From 8df4b5615165e2bf66efb0b49269257979172bab Mon Sep 17 00:00:00 2001 From: dave Date: Fri, 15 Nov 2024 11:40:02 +0000 Subject: [PATCH] Improvements to custom panel based on 4.4.1 API improvements --- .../optional/StatusPanelDrawable.java | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) 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 8d66163..656025a 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 @@ -2,11 +2,15 @@ import com.thecoderscorner.embedcontrol.core.controlmgr.*; import com.thecoderscorner.embedcontrol.core.controlmgr.color.ConditionalColoring; +import com.thecoderscorner.embedcontrol.core.controlmgr.color.ControlColor; import com.thecoderscorner.embedcontrol.customization.FontInformation; import com.thecoderscorner.embedcontrol.customization.FontInformation.SizeMeasurement; +import com.thecoderscorner.embedcontrol.customization.customdraw.BooleanCustomDrawingConfiguration; import com.thecoderscorner.embedcontrol.customization.customdraw.NumberCustomDrawingConfiguration; +import com.thecoderscorner.embedcontrol.customization.customdraw.StringCustomDrawingConfiguration; import com.thecoderscorner.embedcontrol.jfx.controlmgr.panels.BaseCustomMenuPanel; import com.thecoderscorner.menu.devicedemo.EmbeddedJavaDemoMenu; +import com.thecoderscorner.menu.domain.state.PortableColor; import com.thecoderscorner.menu.mgr.MenuManagerServer; import javafx.geometry.HPos; import javafx.scene.Node; @@ -17,6 +21,7 @@ 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; @@ -24,7 +29,7 @@ import java.util.concurrent.TimeUnit; import static com.thecoderscorner.embedcontrol.core.controlmgr.EditorComponent.PortableAlignment; -import static com.thecoderscorner.embedcontrol.core.controlmgr.color.ControlColor.fromFxColor; +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; @@ -76,32 +81,45 @@ protected void populateGrid() { runSimButton.setOnAction(_ -> executor.scheduleAtFixedRate(this::updateTemp, 200L, 200L, TimeUnit.MILLISECONDS)); gridPane.add(runSimButton, 2, 1); + // for the three custom drawing below, these are to override the color for a menu item under certain + // conditions, we provide the custom drawing to a the ComponentSettings during creation. + // 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 greenOrangeRed = new NumberCustomDrawingConfiguration(List.of( + 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)), new NumericColorRange(90.0, 100.0, fromFxColor(Color.RED), fromFxColor(Color.LIGHTGRAY)) - ), "vuColors"); - putIntoGrid(menuDef.getStatusCaseTempOC(), new ComponentSettings( - globalColors, font100Pc, PortableAlignment.CENTER, - new ComponentPositioning(0, 1), RedrawingMode.SHOW_VALUE, ControlType.VU_METER, - greenOrangeRed, true) - ); + )); + + // here we create a custom drawing for a boolean item, it renders red when the items state is false + // and green when the item state is true + var redGreenBooleanCustom = new BooleanCustomDrawingConfiguration( + new ControlColor(GREEN, WHITE), new ControlColor(RED, WHITE)); + + // here we create a custom drawing for a string item, it renders red when the text value for the + // menu item is "Danger" + var stringColorCustom = new StringCustomDrawingConfiguration(List.of( + new Pair("Danger", new ControlColor(RED, WHITE)))); + + putIntoGrid(ComponentSettingsBuilder.forMenuItem(menuDef.getStatusCaseTempOC(), globalColors) + .withJustification(PortableAlignment.CENTER) + .withPosition(new ComponentPositioning(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(menuDef.getStatusIoTMonitor(), new ComponentSettings( - globalColors, font100Pc, PortableAlignment.RIGHT, - new ComponentPositioning(2, 1), RedrawingMode.SHOW_VALUE, ControlType.AUTH_IOT_CONTROL, - NO_CUSTOM_DRAWING, true)); + putIntoGrid(ComponentSettingsBuilder.forMenuItem(menuDef.getStatusIoTMonitor(), globalColors) + .withPosition(new ComponentPositioning(2, 1))); // Here we create an RGB control from the status light color menu item. - putIntoGrid(menuDef.getStatusLightColor(), new ComponentSettings( - globalColors, font100Pc, PortableAlignment.RIGHT, - new ComponentPositioning(1, 1), RedrawingMode.SHOW_VALUE, ControlType.RGB_CONTROL, - NO_CUSTOM_DRAWING, true)); + putIntoGrid(ComponentSettingsBuilder.forMenuItem(menuDef.getStatusLightColor(), globalColors) + .withJustification(PortableAlignment.RIGHT) + .withPosition(new ComponentPositioning(1, 1)) + .withDrawMode(RedrawingMode.SHOW_VALUE)); } // When the simulate button is pressed, this is called frequently to update a couple of menu items.