Skip to content

Commit

Permalink
Add option for hiding/showing work position in DRO
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed Nov 29, 2024
1 parent a211ab9 commit 6acb82f
Show file tree
Hide file tree
Showing 62 changed files with 241 additions and 15,465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Settings {

// Transient, don't serialize or deserialize.
transient private SettingChangeListener listener = null;
transient public static int HISTORY_SIZE = 20;
transient public static int HISTORY_SIZE = 10;

private String firmwareVersion = "GRBL";
private String fileName = System.getProperty("user.home");
Expand Down Expand Up @@ -84,6 +84,7 @@ public class Settings {
private int statusUpdateRate = 200;
private Units preferredUnits = Units.MM;
private Set<Axis> disabledAxes = new HashSet<>();
private boolean showMachinePosition = false;

private boolean showNightlyWarning = true;
private boolean showSerialPortWarning = true;
Expand Down Expand Up @@ -404,6 +405,15 @@ public void setAxisEnabled(Axis a, boolean enabled) {
}
}

public boolean isShowMachinePosition() {
return showMachinePosition;
}

public void setShowMachinePosition(boolean showMachinePosition) {
this.showMachinePosition = showMachinePosition;
changed();
}

public void setPreferredUnits(Units units) {
if (units != null) {
double scaleUnits = UnitUtils.scaleUnits(preferredUnits, units);
Expand Down
12 changes: 6 additions & 6 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ mainWindow.swing.hostLabel = Host\:
mainWindow.swing.remainingRowsLabel = Remaining Rows\:
mainWindow.swing.remainingTimeLabel = Estimated Time Remaining\:
mainWindow.swing.resetCoordinatesButton = Reset Zero
action.resetXCoordinatesButton = Reset X Zero
action.resetYCoordinatesButton = Reset Y Zero
action.resetZCoordinatesButton = Reset Z Zero
action.resetACoordinatesButton = Reset A Zero
action.resetBCoordinatesButton = Reset B Zero
action.resetCCoordinatesButton = Reset C Zero
action.resetXCoordinatesButton = Zero X
action.resetYCoordinatesButton = Zero Y
action.resetZCoordinatesButton = Zero Z
action.resetACoordinatesButton = Zero A
action.resetBCoordinatesButton = Zero B
action.resetCCoordinatesButton = Zero C
mainWindow.swing.returnToZeroButton = Return to Zero
mainWindow.swing.homeMachine = Home Machine
mainWindow.swing.openDoor = Open door
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void settingsShouldHaveDefaultValues() {
assertNotNull(target.getVisualizerWindowSettings());
assertEquals(Double.valueOf(1), Double.valueOf(target.getZJogStepSize()));
assertFalse(target.isAutoStartPendant());
assertFalse(target.isShowMachinePosition());
}

@Test
Expand Down Expand Up @@ -123,10 +124,10 @@ public void recentsShouldOverflowOldestAndReturnLIFO() throws IOException {
Assertions.assertThat(target.getRecentFiles())
.hasSize(HISTORY_SIZE)
.doesNotContain(path + "2"+File.separator+"file.gcode")
.startsWith(path + "21"+File.separator+"file.gcode", path + "1"+File.separator+"file.gcode");
.startsWith(path + "11"+File.separator+"file.gcode", path + "1"+File.separator+"file.gcode");
Assertions.assertThat(target.getRecentDirectories())
.hasSize(HISTORY_SIZE)
.doesNotContain(path + "2")
.startsWith(path + "21", path + "1");
.startsWith(path + "11", path + "1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,33 @@ This file is part of Universal Gcode Sender (UGS).

public class FontManager {

private List<Font> workCoordinateFont = new ArrayList<>(3);
private List<Font> machineCoordinateFont = new ArrayList<>(3);
private List<Font> axisResetFont = new ArrayList<>(3);
private List<Font> axisResetZeroFont = new ArrayList<>(3);
private List<Font> propertyLabelFont = new ArrayList<>(3);
private List<Font> speedValueFont = new ArrayList<>(3);
private List<Font> activeStateFont = new ArrayList<>(3);

private List<JComponent> workCoordinateComponents = new ArrayList<>();
private List<JComponent> machineCoordinateComponents = new ArrayList<>();
private List<JComponent> axisResetComponents = new ArrayList<>();
private List<JComponent> axisResetZeroComponents = new ArrayList<>();
private List<JComponent> propertyLabelComponents = new ArrayList<>();
private List<JComponent> speedValueComponents = new ArrayList<>();
private List<JComponent> activeStateLabelComponents = new ArrayList<>();
private final List<Font> workCoordinateFont = new ArrayList<>(3);
private final List<Font> machineCoordinateFont = new ArrayList<>(3);
private final List<Font> propertyLabelFont = new ArrayList<>(3);
private final List<Font> activeStateFont = new ArrayList<>(3);

private final List<JComponent> workCoordinateComponents = new ArrayList<>();
private final List<JComponent> machineCoordinateComponents = new ArrayList<>();
private final List<JComponent> propertyLabelComponents = new ArrayList<>();
private final List<JComponent> speedValueComponents = new ArrayList<>();
private final List<JComponent> activeStateLabelComponents = new ArrayList<>();

public void init() {
Font font = FontUtils.getLcdFont();
Font boldFont = FontUtils.getSansBoldFont();
Font regularFont = FontUtils.getSansFont();

workCoordinateFont.add(font.deriveFont(Font.PLAIN,18));
workCoordinateFont.add(font.deriveFont(Font.PLAIN,24));
workCoordinateFont.add(font.deriveFont(Font.PLAIN,32));
machineCoordinateFont.add(font.deriveFont(Font.PLAIN,14));
machineCoordinateFont.add(font.deriveFont(Font.PLAIN,18));
machineCoordinateFont.add(font.deriveFont(Font.PLAIN,24));
speedValueFont.add(font.deriveFont(Font.PLAIN,14));
speedValueFont.add(font.deriveFont(Font.PLAIN,16));
speedValueFont.add(font.deriveFont(Font.PLAIN,20));

activeStateFont.add(boldFont.deriveFont(Font.PLAIN, 20));
activeStateFont.add(boldFont.deriveFont(Font.PLAIN, 24));
activeStateFont.add(boldFont.deriveFont(Font.PLAIN, 30));
workCoordinateFont.add(font.deriveFont(Font.PLAIN, 20));
workCoordinateFont.add(font.deriveFont(Font.PLAIN, 26));
workCoordinateFont.add(font.deriveFont(Font.PLAIN, 34));

axisResetFont.add(regularFont.deriveFont(Font.PLAIN, 20));
axisResetFont.add(regularFont.deriveFont(Font.PLAIN, 24));
axisResetFont.add(regularFont.deriveFont(Font.PLAIN, 30));
machineCoordinateFont.add(font.deriveFont(Font.PLAIN, 14));
machineCoordinateFont.add(font.deriveFont(Font.PLAIN, 18));
machineCoordinateFont.add(font.deriveFont(Font.PLAIN, 24));

axisResetZeroFont.add(regularFont.deriveFont(Font.PLAIN, 12));
axisResetZeroFont.add(regularFont.deriveFont(Font.PLAIN, 14));
axisResetZeroFont.add(regularFont.deriveFont(Font.PLAIN, 18));
activeStateFont.add(boldFont.deriveFont(Font.PLAIN, 20));
activeStateFont.add(boldFont.deriveFont(Font.PLAIN, 26));
activeStateFont.add(boldFont.deriveFont(Font.PLAIN, 34));

propertyLabelFont.add(regularFont.deriveFont(Font.PLAIN, 12));
propertyLabelFont.add(regularFont.deriveFont(Font.PLAIN, 14));
Expand All @@ -84,10 +69,8 @@ public void applyFonts(int size) {
int index = Math.max(0, Math.min(2, size));
workCoordinateComponents.forEach(c -> c.setFont(workCoordinateFont.get(index)));
machineCoordinateComponents.forEach(c -> c.setFont(machineCoordinateFont.get(index)));
axisResetComponents.forEach(c -> c.setFont(axisResetFont.get(index)));
axisResetZeroComponents.forEach(c -> c.setFont(axisResetZeroFont.get(index)));
propertyLabelComponents.forEach(c -> c.setFont(propertyLabelFont.get(index)));
speedValueComponents.forEach(c -> c.setFont(speedValueFont.get(index)));
speedValueComponents.forEach(c -> c.setFont(machineCoordinateFont.get(index)));
activeStateLabelComponents.forEach(c -> c.setFont(activeStateFont.get(index)));
});
}
Expand All @@ -100,14 +83,6 @@ public void addMachineCoordinateLabel(JComponent... label) {
machineCoordinateComponents.addAll(Arrays.asList(label));
}

public void addAxisResetLabel(JLabel... label) {
axisResetComponents.addAll(Arrays.asList(label));
}

public void addAxisResetZeroLabel(JLabel... label) {
axisResetZeroComponents.addAll(Arrays.asList(label));
}

public void addPropertyLabel(JLabel... label) {
propertyLabelComponents.addAll(Arrays.asList(label));
}
Expand All @@ -124,10 +99,7 @@ public void registerFonts(GraphicsEnvironment ge) {
List<Font> all = new ArrayList<>();
all.addAll(workCoordinateFont);
all.addAll(machineCoordinateFont);
all.addAll(axisResetFont);
all.addAll(axisResetZeroFont);
all.addAll(propertyLabelFont);
all.addAll(speedValueFont);
all.forEach(ge::registerFont);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ This file is part of Universal Gcode Sender (UGS).
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.util.HashSet;
Expand All @@ -47,36 +49,48 @@ This file is part of Universal Gcode Sender (UGS).
public class AxisPanel extends JPanel {
private static final int RADIUS = 7;
public static final int HIGHLIGHT_TIME = 300;
private final CoordinateLabel work = new CoordinateLabel(0.0);
private final CoordinateLabel machine = new CoordinateLabel(0.0);
private final HighlightableLabel axisLabel = new HighlightableLabel();
private final CoordinateLabel workLabel = new CoordinateLabel(0.0);
private final CoordinateLabel machineLabel = new CoordinateLabel(0.0);
private final Set<AxisPanelListener> axisPanelListenerList = new HashSet<>();
private transient ScheduledFuture<?> highlightLabelsFuture;

public AxisPanel(Axis axis, FontManager fontManager) {
super(new MigLayout("fill, inset 0", "[50]5[grow, fill]"));
super(new MigLayout("fill, inset 0", "[grow, fill]5[50]"));
RoundedPanel axisPanel = new RoundedPanel(RADIUS);
axisPanel.setBackground(ThemeColors.VERY_DARK_GREY);
axisPanel.setForeground(ThemeColors.LIGHT_BLUE);
axisPanel.setLayout(new MigLayout("fillx, inset 4 6 4 6, gap 0", "[grow, right]"));
axisPanel.setLayout(new MigLayout("fill, inset 6 6 6 6, gap 0", "[left][grow, right, fill]"));

work.addMouseListener(new MouseClickListener() {
axisLabel.setText(axis.toString());
workLabel.addMouseListener(new MouseClickListener() {
@Override
public void onClick(MouseEvent e) {
axisPanelListenerList.forEach(axisPanelListener -> axisPanelListener.onWorkPositionClick(work, axis));
axisPanelListenerList.forEach(axisPanelListener -> axisPanelListener.onWorkPositionClick(workLabel, axis));
}
});

axisPanel.add(work, "grow, gapleft 5, wrap");
axisPanel.add(machine, "span 2");
fontManager.addWorkCoordinateLabel(axisLabel);
fontManager.addWorkCoordinateLabel(workLabel);
fontManager.addMachineCoordinateLabel(machineLabel);

fontManager.addWorkCoordinateLabel(work);
fontManager.addMachineCoordinateLabel(machine);
JPanel coordinatesPanel = new JPanel(new MigLayout("fill, inset 0, wrap 1, gap 0", "[grow, align right]"));
coordinatesPanel.setOpaque(false);
coordinatesPanel.add(workLabel);
coordinatesPanel.add(machineLabel, "hidemode 3");

axisPanel.add(axisLabel, "spany 2, growy");
axisPanel.add(coordinatesPanel, "growy");
add(axisPanel, "growy");

Dimension minimumSize = new Dimension(50, 18);
JButton resetButton = new JButton(createAction(axis));
resetButton.setMinimumSize(minimumSize);
resetButton.setVerticalTextPosition(SwingConstants.TOP);
resetButton.setHorizontalTextPosition(SwingConstants.CENTER);

resetButton.setMargin(new Insets(0, 0, 0, 0));
resetButton.setText("");
add(resetButton, "grow");
add(axisPanel);
}

private static Action createAction(Axis axis) {
Expand All @@ -101,11 +115,11 @@ public void addListener(AxisPanelListener axisPanelListener) {
}

public void setMachinePosition(double value) {
setLabelValue(machine, value);
setLabelValue(machineLabel, value);
}

public void setWorkPosition(double value) {
setLabelValue(work, value);
setLabelValue(workLabel, value);
}

private void setLabelValue(CoordinateLabel label, double value) {
Expand All @@ -116,8 +130,9 @@ private void setLabelValue(CoordinateLabel label, double value) {
}

private void highlightLabels() {
work.setHighlighted(true);
machine.setHighlighted(true);
axisLabel.setHighlighted(true);
workLabel.setHighlighted(true);
machineLabel.setHighlighted(true);

// Disable any old future
if (highlightLabelsFuture != null && !highlightLabelsFuture.isDone()) {
Expand All @@ -126,15 +141,21 @@ private void highlightLabels() {

// Start new future
highlightLabelsFuture = ThreadHelper.invokeLater(() -> {
work.setHighlighted(false);
machine.setHighlighted(false);
workLabel.setHighlighted(false);
machineLabel.setHighlighted(false);
axisLabel.setHighlighted(false);
}, HIGHLIGHT_TIME);
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
work.setEnabled(enabled);
machine.setEnabled(enabled);
workLabel.setEnabled(enabled);
machineLabel.setEnabled(enabled);
axisLabel.setEnabled(enabled);
}

public void setShowMachinePosition(boolean showMachinePosition) {
machineLabel.setVisible(showMachinePosition);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Will Winder
Copyright 2023-2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand All @@ -18,61 +18,26 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.ugs.nbp.dro.panels;

import com.willwinder.universalgcodesender.uielements.helpers.ThemeColors;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Color;
import java.text.DecimalFormat;

public class CoordinateLabel extends JLabel {
public class CoordinateLabel extends HighlightableLabel {

private final DecimalFormat decimalFormatter = new DecimalFormat("0.000");

private double value = 0.0;
private boolean highlighted = false;
private boolean isEnabled = true;

public CoordinateLabel(double value) {
setValue(value);
setHorizontalAlignment(SwingConstants.RIGHT);
}

@Override
public void setEnabled(boolean enabled) {
this.isEnabled = enabled;
updateColor();
}

@Override
public boolean isEnabled() {
// Force returning true or else we will get problems with colors on some LaFs
return true;
}

public double getValue() {
return value;
}


public void setValue(double value) {
this.value = value;
String textValue = decimalFormatter.format(value);
setText(textValue);
}

public void setHighlighted(boolean highlighted) {
this.highlighted = highlighted;
updateColor();
}

private void updateColor() {
Color color = isEnabled ? ThemeColors.LIGHT_BLUE : ThemeColors.LIGHT_BLUE_GREY;

if (highlighted) {
color = ThemeColors.GREEN;
}

setForeground(color);
}
}
Loading

0 comments on commit 6acb82f

Please sign in to comment.