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 9, 2024
1 parent 88ec627 commit a9e2029
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 114 deletions.
2 changes: 1 addition & 1 deletion java/embedControlJavaFx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<jfx.version>23.0.1</jfx.version>
<jmetro.version>11.6.15</jmetro.version>
<springframework.version>6.0.11</springframework.version>
<java.api.version>4.4.0</java.api.version>
<java.api.version>4.4.1-SNAPSHOT</java.api.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,7 +78,6 @@ public class RemoteConnectionPanel implements PanelPresentable<Node>, 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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions java/embeddedJavaDeviceUI/data/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Node>, 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<Node> editorFactory;
private final MenuComponentControl componentControl;
private final ConditionalColoring globalColors;
private final ScheduledExecutorService executor;
private final MenuManagerServer manager;
private final HashMap<Integer, EditorComponent<Node>> controlsBeingManaged = new HashMap<>();
private double presentableWidth = 999;
private GridPane gridPane;
private double lastWidth = 999;

public StatusPanelDrawable(EmbeddedJavaDemoMenu menuDef, ScheduledExecutorService executor,
MenuEditorFactory<Node> 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));
Expand All @@ -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
Expand All @@ -126,26 +96,13 @@ 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() {
manager.updateMenuItem(this, menuDef.getStatusCaseTempOC(), Math.random() * 100);
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() {
Expand All @@ -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();
}
}

}

This file was deleted.

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-09T16:19:17Z
build.timestamp=2024-11-09T17:04:31Z

# server name properties
server.name=Embedded Java Demo
Expand Down

0 comments on commit a9e2029

Please sign in to comment.