Skip to content

Commit

Permalink
Improvements to custom panel based on 4.4.1 API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Nov 15, 2024
1 parent 96ac053 commit 8df4b56
Showing 1 changed file with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,14 +21,15 @@
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.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;

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8df4b56

Please sign in to comment.