Skip to content

Commit

Permalink
Added the instrument cluster panel skeleton (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Aug 3, 2023
1 parent 117e818 commit 8b03963
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public InstrumentCluster(
* @return System status flux. A new item is emitted every time a particular entity's status is updated,
* the item can and must be treated as an incremental update.
*/
public Flux<SystemStatus> getFlux() {
public Flux<Signal<SystemStatus, Void>> getFlux() {

logger.error("FIXME: NOT IMPLEMENTED: getFlux(SystemStatus)");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @param <T> Signal value type.
* @param <P> Extra payload type.
* @see EntityCell
* @author Copyright &copy; <a href="mailto:vt@homeclimatecontrol.com">Vadim Tkachenko</a> 2001-2022
* @author Copyright &copy; <a href="mailto:vt@homeclimatecontrol.com">Vadim Tkachenko</a> 2001-2023
*/
public abstract class EntityPanel<T, P> extends SwingSink<T, P> implements KeyListener {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sf.dz3r.view.swing;

import net.sf.dz3r.instrumentation.InstrumentCluster;
import net.sf.dz3r.model.HvacMode;
import net.sf.dz3r.model.UnitDirector;
import net.sf.dz3r.model.Zone;
Expand All @@ -8,6 +9,8 @@
import net.sf.dz3r.signal.Signal;
import net.sf.dz3r.signal.hvac.HvacDeviceStatus;
import net.sf.dz3r.signal.hvac.ZoneStatus;
import net.sf.dz3r.view.swing.dashboard.DashboardCell;
import net.sf.dz3r.view.swing.dashboard.DashboardPanel;
import net.sf.dz3r.view.swing.sensor.SensorCell;
import net.sf.dz3r.view.swing.sensor.SensorPanel;
import net.sf.dz3r.view.swing.unit.UnitCell;
Expand Down Expand Up @@ -61,6 +64,7 @@ public EntitySelectorPanel(ReactiveConsole.Config consoleConfig, ScreenDescripto

private void init(ReactiveConsole.Config config) {

initDashboard(config.ic());
initDirectors(config.directors());
initSensors(config.sensors());

Expand All @@ -69,6 +73,21 @@ private void init(ReactiveConsole.Config config) {
initGraphics();
}

private void initDashboard(InstrumentCluster ic) {
entities.add(createDashboardPair(ic));
}

private CellAndPanel<?,?> createDashboardPair(InstrumentCluster ic) {

var cell = new DashboardCell();
var panel = new DashboardPanel(ic, config.screen);

cell.subscribe(ic.getFlux());
panel.subscribe(ic.getFlux());

return new CellAndPanel<>(cell, panel);
}

private void initDirectors(Set<UnitDirector> initSet) {

// VT: NOTE: sort() the units
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.sf.dz3r.view.swing.dashboard;

import net.sf.dz3r.signal.health.SystemStatus;
import net.sf.dz3r.view.swing.ColorScheme;
import net.sf.dz3r.view.swing.EntityCell;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class DashboardCell extends EntityCell<SystemStatus, Void> {

public DashboardCell() {
setPreferredSize(new Dimension(20, 70));
}

@Override
protected void paintContent(Graphics2D g2d, Rectangle boundary) {

if (getSignal() == null) {
g2d.setPaint(ColorScheme.offMap.error);
g2d.fill(boundary);
}
}

@Override
protected Color getBorderColor() {
// Mode has no say in this case, unlike every other cell
return ColorScheme.offMap.green;
}

@Override
protected Color getIndicatorColor() {

if (getSignal() == null || getSignal().isError()) {
return ColorScheme.offMap.error;
}

return ColorScheme.offMap.green.darker().darker();
}

@Override
protected void consumeSignalValue(SystemStatus value) {
// No special handling
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package net.sf.dz3r.view.swing.dashboard;

import net.sf.dz3r.instrumentation.InstrumentCluster;
import net.sf.dz3r.signal.health.SystemStatus;
import net.sf.dz3r.view.swing.ColorScheme;
import net.sf.dz3r.view.swing.EntityPanel;
import net.sf.dz3r.view.swing.ScreenDescriptor;
import reactor.core.publisher.Flux;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.KeyEvent;

public class DashboardPanel extends EntityPanel<SystemStatus, Void> {

private final InstrumentCluster ic;

private final JPanel sensorPanel = new JPanel();
private final JPanel switchPanel = new JPanel();
private final JPanel connectorPanel = new JPanel();
private final JPanel collectorPanel = new JPanel();
private final JPanel hvacDevicePanel = new JPanel();

public DashboardPanel(InstrumentCluster ic, ScreenDescriptor screenDescriptor) {

this.ic = ic;

setFontSize(screenDescriptor);
initGraphics();
}

private void initGraphics() {

setBackground(ColorScheme.offMap.background);
setBorder(new TitledBorder("Instrument Cluster"));
((TitledBorder) getBorder()).setTitleColor(Color.WHITE);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

sensorPanel.setBorder(new TitledBorder("Sensors"));
switchPanel.setBorder(new TitledBorder("Switches"));
connectorPanel.setBorder(new TitledBorder("Connectors"));
collectorPanel.setBorder(new TitledBorder("Collectors"));
hvacDevicePanel.setBorder(new TitledBorder("HVAC Devices"));

Flux
.just(
sensorPanel,
switchPanel,
connectorPanel,
collectorPanel,
hvacDevicePanel)
.doOnNext(panel -> panel.setBackground(ColorScheme.offMap.background))
.doOnNext(panel -> ((TitledBorder) panel.getBorder()).setTitleColor(Color.WHITE))
.doOnNext(this::add)
.subscribe();
}

@Override
public void keyTyped(KeyEvent e) {
// No special handling
}

@Override
public void keyPressed(KeyEvent e) {
// No special handling yet
}

@Override
public void keyReleased(KeyEvent e) {
// No special handling
}

@Override
protected void consumeSignalValue(SystemStatus status) {
// No special handling
}

@Override
protected void update() {

var signal = getSignal();
}

@Override
protected void createControls(JPanel controls, GridBagLayout layout, GridBagConstraints cs) {
throw new IllegalStateException("Not Implemented Here");
}

@Override
public void setFontSize(ScreenDescriptor screenDescriptor) {

sensorPanel.setFont(screenDescriptor.fontSetpoint);
switchPanel.setFont(screenDescriptor.fontSetpoint);
connectorPanel.setFont(screenDescriptor.fontSetpoint);
collectorPanel.setFont(screenDescriptor.fontSetpoint);
hvacDevicePanel.setFont(screenDescriptor.fontSetpoint);
}
}

0 comments on commit 8b03963

Please sign in to comment.