diff --git a/ugs-core/src/com/willwinder/universalgcodesender/Utils.java b/ugs-core/src/com/willwinder/universalgcodesender/Utils.java index 90ad663918..d6461a2402 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/Utils.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/Utils.java @@ -50,7 +50,7 @@ This file is part of Universal Gcode Sender (UGS). * @author wwinder */ public class Utils { - public static final NumberFormat formatter = new DecimalFormat("#.###", Localization.dfs); + public static final NumberFormat formatter = new DecimalFormat("#.#####", Localization.dfs); private static final Logger LOGGER = Logger.getLogger(Utils.class.getSimpleName()); private static final int MAX_WAIT_TIME_FOR_STATUS_REPORT = 1000; diff --git a/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/JogPanel.java b/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/JogPanel.java index 58a307ca09..ffadec5a4a 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/JogPanel.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/JogPanel.java @@ -33,12 +33,12 @@ This file is part of Universal Gcode Sender (UGS). public class JogPanel extends JPanel implements UGSEventListener { - private final StepSizeSpinner xyStepSizeSpinner = new StepSizeSpinner(); - private final StepSizeSpinner zStepSizeSpinner = new StepSizeSpinner(); + private StepSizeSpinner xyStepSizeSpinner = null; + private StepSizeSpinner zStepSizeSpinner = null; private final JLabel stepSizeLabel = new JLabel(Localization.getString("mainWindow.swing.stepSizeLabel")); private final JLabel stepSizeLabelZ = new JLabel(Localization.getString("mainWindow.swing.stepSizeZLabel")); - private final StepSizeSpinner feedRateSpinner = new StepSizeSpinner(); + private final StepSizeSpinner feedRateSpinner = new StepSizeSpinner(null); private final JLabel feedRateLabel = new JLabel(Localization.getString("mainWindow.swing.feedRateLabel")); private final JButton unitButton = new JButton(); @@ -59,6 +59,8 @@ public class JogPanel extends JPanel implements UGSEventListener { public JogPanel(BackendAPI backend, JogService jogService, boolean showKeyboardToggle) { this.backend = backend; this.showKeyboardToggle = showKeyboardToggle; + xyStepSizeSpinner = new StepSizeSpinner(backend.getSettings()); + zStepSizeSpinner = new StepSizeSpinner(backend.getSettings()); this.jogService = jogService; diff --git a/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/StepSizeSpinner.java b/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/StepSizeSpinner.java index 27d078d35b..ac034bed4d 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/StepSizeSpinner.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/uielements/jog/StepSizeSpinner.java @@ -18,26 +18,45 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.universalgcodesender.uielements.jog; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.model.UGSEvent; +import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; +import com.willwinder.universalgcodesender.model.events.SettingChangedEvent; +import com.willwinder.universalgcodesender.utils.Settings; +import java.awt.EventQueue; import javax.swing.*; import javax.swing.text.DefaultFormatter; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.ParseException; + public class StepSizeSpinner extends JSpinner { double currentValue = 0.0; - - public StepSizeSpinner() { + Settings settings = null; + + public StepSizeSpinner(Settings settings) { + this.settings = settings; + setModel(new StepSizeSpinnerModel()); // Make the editor fire update events when typing, not only after changing fields JComponent comp = getEditor(); JFormattedTextField field = (JFormattedTextField) comp.getComponent(0); DefaultFormatter formatter = (DefaultFormatter) field.getFormatter(); - formatter.setCommitsOnValidEdit(true); + formatter.setCommitsOnValidEdit(true); + + this.onBackendEvent(new SettingChangedEvent()); + } + public void onBackendEvent(UGSEvent event) { + if (event instanceof SettingChangedEvent) { + if (settings != null) { + super.setEditor(new JSpinner.NumberEditor(this, settings.getMachineDecimalFormat())); + } + setValue(currentValue); + } } - @Override public Double getValue() { try { @@ -46,18 +65,21 @@ public Double getValue() { setValue(currentValue); } - BigDecimal bd = new BigDecimal(super.getValue().toString()).setScale(3, RoundingMode.HALF_EVEN); + BigDecimal bd = new BigDecimal(super.getValue().toString()).setScale(getDecimalPlaces(), RoundingMode.HALF_EVEN); return bd.doubleValue(); } @Override public void setValue(Object value) { double val = Double.parseDouble(value.toString()); - BigDecimal bd = new BigDecimal(val).setScale(3, RoundingMode.HALF_EVEN); + BigDecimal bd = new BigDecimal(val).setScale(getDecimalPlaces(), RoundingMode.HALF_EVEN); currentValue = bd.doubleValue(); + super.setValue(currentValue); } - + + // todo: Add backend Settings Listener. + // todo: Apply formatting to formatter to enforce decimal places. public void increaseStep() { Object nextValue = getNextValue(); if (nextValue != null) { @@ -91,4 +113,33 @@ private double bound(double val) { return val; } } + + private int getDecimalPlaces() { + if (settings == null) { + return 0; + } + switch (settings.getMachineDecimalFormat()) { + case "0" -> { + return 0; + } + case "0.0" -> { + return 1; + } + case "0.00" -> { + return 2; + } + case "0.000" -> { + return 3; + } + case "0.0000" -> { + return 4; + } + case "0.00000" -> { + return 5; + } + + default -> throw new AssertionError(); + } + } + } diff --git a/ugs-core/src/com/willwinder/universalgcodesender/utils/Settings.java b/ugs-core/src/com/willwinder/universalgcodesender/utils/Settings.java index 6e81618764..dd0407abe0 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/utils/Settings.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/utils/Settings.java @@ -37,6 +37,7 @@ This file is part of Universal Gcode Sender (UGS). import java.util.Deque; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -141,6 +142,7 @@ public class Settings { private FxSettings fxSettings = new FxSettings(); + private String machineDecimalFormat = "0.000"; /** * The GSON deserialization doesn't do anything beyond initialize what's in the json document. Call finalizeInitialization() before using the Settings. */ @@ -602,7 +604,16 @@ public String getLastWorkingDirectory() { public void setLastWorkingDirectory(String lastWorkingDirectory) { this.lastWorkingDirectory = lastWorkingDirectory; } + + public String getMachineDecimalFormat() { + return this.machineDecimalFormat; + } + public void setMachineDecimalFormat(String aValue) { + this.machineDecimalFormat=aValue; + this.changed(); + } + public static class FileStats { public Position minCoordinate; public Position maxCoordinate; @@ -620,4 +631,5 @@ public FileStats(Position min, Position max, long num) { this.numCommands = num; } } + } diff --git a/ugs-core/src/resources/MessagesBundle_en_US.properties b/ugs-core/src/resources/MessagesBundle_en_US.properties index 43adfb40e7..7de683bd69 100644 --- a/ugs-core/src/resources/MessagesBundle_en_US.properties +++ b/ugs-core/src/resources/MessagesBundle_en_US.properties @@ -680,6 +680,9 @@ platform.visualizer.popup.presets.left = Left platform.visualizer.popup.presets.front = Front platform.plugin.jog.useSeparateStepSize = Use separate step sizes for Z and XY platform.plugin.jog.showABCStepSize = Show ABC step size +platform.plugin.jog.setMachineDecimalFormatThree=3 Decimal Places +platform.plugin.jog.setMachineDecimalFormatFour=4 Decimal Places +platform.plugin.jog.setMachineDecimalFormatFive=5 Decimal Places platform.plugin.jog.feedRate = Feed rate platform.plugin.jog.stepSize = Step size platform.plugin.jog.stepSizeZ = Step size Z diff --git a/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/AxisPanel.java b/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/AxisPanel.java index e888c52059..62b3c38a21 100644 --- a/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/AxisPanel.java +++ b/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/AxisPanel.java @@ -26,6 +26,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbp.core.actions.ResetZCoordinateToZeroAction; import com.willwinder.ugs.nbp.dro.FontManager; import com.willwinder.universalgcodesender.model.Axis; +import com.willwinder.universalgcodesender.model.BackendAPI; import com.willwinder.universalgcodesender.uielements.components.RoundedPanel; import com.willwinder.universalgcodesender.uielements.helpers.MouseClickListener; import com.willwinder.universalgcodesender.uielements.helpers.ThemeColors; @@ -50,13 +51,16 @@ public class AxisPanel extends JPanel { private static final int RADIUS = 7; public static final int HIGHLIGHT_TIME = 300; private final HighlightableLabel axisLabel = new HighlightableLabel(); - private final CoordinateLabel workLabel = new CoordinateLabel(0.0); - private final CoordinateLabel machineLabel = new CoordinateLabel(0.0); + private CoordinateLabel workLabel = null;//new CoordinateLabel(0.0); + private CoordinateLabel machineLabel = null;//new CoordinateLabel(0.0); private final Set axisPanelListenerList = new HashSet<>(); private transient ScheduledFuture highlightLabelsFuture; - public AxisPanel(Axis axis, FontManager fontManager) { + public AxisPanel(Axis axis, FontManager fontManager, BackendAPI backend) { super(new MigLayout("fill, inset 0", "[grow, fill]5[50]")); + workLabel = new CoordinateLabel(0.0,backend); + machineLabel = new CoordinateLabel(0.0,backend); + RoundedPanel axisPanel = new RoundedPanel(RADIUS); axisPanel.setBackground(ThemeColors.VERY_DARK_GREY); axisPanel.setForeground(ThemeColors.LIGHT_BLUE); diff --git a/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/CoordinateLabel.java b/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/CoordinateLabel.java index 5c29f6ccda..615933bf63 100644 --- a/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/CoordinateLabel.java +++ b/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/CoordinateLabel.java @@ -18,15 +18,28 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbp.dro.panels; +import com.willwinder.universalgcodesender.listeners.UGSEventListener; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.model.UGSEvent; +import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; +import com.willwinder.universalgcodesender.model.events.ControllerStatusEvent; +import com.willwinder.universalgcodesender.model.events.SettingChangedEvent; import javax.swing.SwingConstants; import java.text.DecimalFormat; -public class CoordinateLabel extends HighlightableLabel { +public class CoordinateLabel extends HighlightableLabel implements UGSEventListener { - private final DecimalFormat decimalFormatter = new DecimalFormat("0.000"); + private DecimalFormat decimalFormatter = new DecimalFormat("0.000"); private double value = 0.0; + private final transient BackendAPI backend; + + public CoordinateLabel(double value, BackendAPI backend) { + this.backend = backend; + + if (this.backend != null) { + this.backend.addUGSEventListener(this); + } - public CoordinateLabel(double value) { setValue(value); setHorizontalAlignment(SwingConstants.RIGHT); } @@ -37,7 +50,16 @@ public double getValue() { public void setValue(double value) { this.value = value; + if (this.backend != null) { + String valueToUse = this.backend.getSettings().getMachineDecimalFormat(); + decimalFormatter = new DecimalFormat(valueToUse); + } String textValue = decimalFormatter.format(value); setText(textValue); } + + @Override + public void UGSEvent(UGSEvent evt) { + setValue(this.value); + } } diff --git a/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/MachineStatusPanel.java b/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/MachineStatusPanel.java index 49d454ee61..4992887a3d 100644 --- a/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/MachineStatusPanel.java +++ b/ugs-platform/ugs-platform-plugin-dro/src/main/java/com/willwinder/ugs/nbp/dro/panels/MachineStatusPanel.java @@ -85,7 +85,7 @@ public class MachineStatusPanel extends JPanel implements UGSEventListener, Axis private final JPanel axisPanel = new JPanel(); private Units units; private final Map axisPanels = new EnumMap<>(Axis.class); - private final DecimalFormat decimalFormatter = new DecimalFormat("0.000"); + private DecimalFormat decimalFormatter = new DecimalFormat("0.000"); public MachineStatusPanel(BackendAPI backend) { @@ -102,8 +102,8 @@ public MachineStatusPanel(BackendAPI backend) { setUnits(Units.MM); } else { setUnits(Units.INCH); - } - + } + updateControls(); } @@ -167,7 +167,7 @@ private void initComponents() { } private void initializeAxisPanel(Axis axis) { - AxisPanel panel = new AxisPanel(axis, fontManager); + AxisPanel panel = new AxisPanel(axis, fontManager, backend); panel.setVisible(axis.isLinear()); panel.setEnabled(false); axisPanels.put(axis, panel); @@ -222,6 +222,11 @@ public void UGSEvent(UGSEvent evt) { */ private void updateControls() { Settings settings = backend.getSettings(); + + if (this.backend != null) { + decimalFormatter = new DecimalFormat(this.backend.getSettings().getMachineDecimalFormat() ); + } + if (!backend.isConnected()) { axisPanels.forEach((key, value) -> { value.setEnabled(false); diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java index 2e521e4f8c..0abf3525e5 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java @@ -27,6 +27,8 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.uielements.jog.StepSizeSpinner; import com.willwinder.universalgcodesender.utils.FontUtils; import com.willwinder.universalgcodesender.listeners.LongPressMouseListener; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.utils.Settings; import net.miginfocom.swing.MigLayout; import org.openide.util.ImageUtilities; @@ -103,8 +105,11 @@ public class JogPanel extends JPanel implements SteppedSizeManager.SteppedSizeCh private JButton unitToggleButton; private JButton increaseStepSizeButton; private JButton decreaseStepSizeButton; - - public JogPanel() { + + private BackendAPI backend; + + public JogPanel(BackendAPI backend) { + this.backend = backend; createComponents(); initPanels(); initListeners(); @@ -123,15 +128,20 @@ private void createComponents() { // Create our buttons Arrays.asList(JogPanelButtonEnum.values()).forEach(this::createJogButton); Dimension minimumSize = new Dimension(80, 18); - feedRateSpinner = new StepSizeSpinner(); + feedRateSpinner = new StepSizeSpinner(backend.getSettings()); feedRateSpinner.setMinimumSize(minimumSize); - xyStepSizeSpinner = new StepSizeSpinner(); + xyStepSizeSpinner = new StepSizeSpinner(backend.getSettings()); xyStepSizeSpinner.setMinimumSize(minimumSize); - zStepSizeSpinner = new StepSizeSpinner(); + backend.addUGSEventListener(xyStepSizeSpinner::onBackendEvent); + + zStepSizeSpinner = new StepSizeSpinner(backend.getSettings()); zStepSizeSpinner.setMinimumSize(minimumSize); - abcStepSizeSpinner = new StepSizeSpinner(); + backend.addUGSEventListener(zStepSizeSpinner::onBackendEvent); + + abcStepSizeSpinner = new StepSizeSpinner(backend.getSettings()); abcStepSizeSpinner.setMinimumSize(minimumSize); - + backend.addUGSEventListener(abcStepSizeSpinner::onBackendEvent); + // todo: could use a number of factory methods here to build similar stuff feedRateLabel = createSettingLabel(font, Localization.getString("platform.plugin.jog.feedRate")); feedRateLabel.setMinimumSize(new Dimension(0, 0)); diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogTopComponent.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogTopComponent.java index 95f2bc0d4a..37e7f01dd1 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogTopComponent.java +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogTopComponent.java @@ -18,6 +18,9 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbp.jog; +import com.willwinder.ugs.nbp.jog.actions.SetMachineDecimalFormatFive; +import com.willwinder.ugs.nbp.jog.actions.SetMachineDecimalFormatFour; +import com.willwinder.ugs.nbp.jog.actions.SetMachineDecimalFormatThree; import com.willwinder.ugs.nbp.jog.actions.ShowABCStepSizeAction; import com.willwinder.ugs.nbp.jog.actions.UseSeparateStepSizeAction; import com.willwinder.ugs.nbp.lib.Mode; @@ -41,6 +44,7 @@ This file is part of Universal Gcode Sender (UGS). import javax.swing.JPopupMenu; import java.awt.BorderLayout; +import javax.swing.JMenu; /** * The jog control panel in NetBeans @@ -75,15 +79,20 @@ public final class JogTopComponent extends TopComponent implements UGSEventListe private final ContinuousJogWorker continuousJogWorker; private boolean ignoreLongClick = false; - + private final JMenu precisionMenu = new JMenu("Precision"); public JogTopComponent() { backend = CentralLookup.getDefault().lookup(BackendAPI.class); jogService = CentralLookup.getDefault().lookup(JogService.class); continuousJogWorker = new ContinuousJogWorker(backend, jogService); UseSeparateStepSizeAction separateStepSizeAction = Lookup.getDefault().lookup(UseSeparateStepSizeAction.class); ShowABCStepSizeAction showABCStepSizeAction = Lookup.getDefault().lookup(ShowABCStepSizeAction.class); - - jogPanel = new JogPanel(); + + SetMachineDecimalFormatThree setMachineDecimalFormatThree = Lookup.getDefault().lookup(SetMachineDecimalFormatThree.class); + SetMachineDecimalFormatFour setMachineDecimalFormatFour = Lookup.getDefault().lookup(SetMachineDecimalFormatFour.class); + SetMachineDecimalFormatFive setMachineDecimalFormatFive = Lookup.getDefault().lookup(SetMachineDecimalFormatFive.class); + + + jogPanel = new JogPanel(backend); jogPanel.setEnabled(jogService.canJog()); updateSettings(); jogPanel.addListener(this); @@ -96,12 +105,18 @@ public JogTopComponent() { // Right click options if (separateStepSizeAction != null || showABCStepSizeAction != null) { JPopupMenu popupMenu = new JPopupMenu(); + if (separateStepSizeAction != null) { popupMenu.add(separateStepSizeAction); } if (showABCStepSizeAction != null) { popupMenu.add(showABCStepSizeAction); } + + popupMenu.add(precisionMenu); + precisionMenu.add(setMachineDecimalFormatThree); + precisionMenu.add(setMachineDecimalFormatFour); + precisionMenu.add(setMachineDecimalFormatFive); SwingHelpers.traverse(this, (comp) -> comp.setComponentPopupMenu(popupMenu)); } } @@ -150,6 +165,7 @@ private void checkAxisEnabled(Axis axis) { private void updateControls() { jogPanel.setEnabled(jogService.canJog()); + precisionMenu.setEnabled(jogService.canJog()); } @Override diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatFive.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatFive.java new file mode 100644 index 0000000000..fee4c91e2c --- /dev/null +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatFive.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2025 Damian Nikodem + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.willwinder.ugs.nbp.jog.actions; + +import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.model.UGSEvent; +import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; +import com.willwinder.universalgcodesender.model.events.SettingChangedEvent; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import static javax.swing.Action.NAME; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JMenuItem; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.actions.Presenter; +import org.openide.util.lookup.ServiceProvider; + +///** +// * +// * @author Damian Nikodem +// */ + +/** + * An action to set the number of Decimal Places in the backend. + * + * @author Damian Nikodem + */ +@ActionID( + category = LocalizingService.CATEGORY_MACHINE, + id = "com.willwinder.ugs.nbp.jog.actions.SetMachineDecimalFormatFive") +@ActionRegistration( + displayName = "resources.MessagesBundle#platform.plugin.jog.setMachineDecimalFormatFive", + lazy = false) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_MACHINE_JOG_DECIMAL_PLACES_5, + position = 10000, + separatorAfter = 10001) +}) +@ServiceProvider(service = SetMachineDecimalFormatFive.class) +public class SetMachineDecimalFormatFive extends AbstractAction implements Presenter.Menu { + private final String DECIMAL_FORMAT_FIVE = "0.00000"; + private final BackendAPI backend; + private final JCheckBoxMenuItem menuItem; + + public SetMachineDecimalFormatFive() { + String title = Localization.getString("platform.plugin.jog.setMachineDecimalFormatFive"); + putValue(NAME, title); + + menuItem = new JCheckBoxMenuItem(title); + menuItem.setAction(this); + + backend = CentralLookup.getDefault().lookup(BackendAPI.class); + backend.addUGSEventListener(this::onBackendEvent); + setEnabled(isEnabled()); + onBackendEvent( new SettingChangedEvent()) ; + } + + private void onBackendEvent(UGSEvent event) { + if (event instanceof SettingChangedEvent) { + menuItem.setSelected(backend.getSettings().getMachineDecimalFormat().equals(DECIMAL_FORMAT_FIVE)); + } else if (event instanceof ControllerStateEvent) { + EventQueue.invokeLater(() -> setEnabled(isEnabled())); + } + } + + @Override + public boolean isEnabled() { + return backend != null && backend.isConnected(); + } + + @Override + public JMenuItem getMenuPresenter() { + return menuItem; + } + + @Override + public void actionPerformed(ActionEvent e) { + backend.getSettings().setMachineDecimalFormat(DECIMAL_FORMAT_FIVE) ; + } +} diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatFour.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatFour.java new file mode 100644 index 0000000000..b90e088e36 --- /dev/null +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatFour.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2025 Damian Nikodem + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.willwinder.ugs.nbp.jog.actions; + +import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.model.UGSEvent; +import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; +import com.willwinder.universalgcodesender.model.events.SettingChangedEvent; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import static javax.swing.Action.NAME; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JMenuItem; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.actions.Presenter; +import org.openide.util.lookup.ServiceProvider; + +///** +// * +// * @author Damian Nikodem +// */ + +/** + * An action to set the number of Decimal Places in the backend. + * + * @author Damian Nikodem + */ +@ActionID( + category = LocalizingService.CATEGORY_MACHINE, + id = "com.willwinder.ugs.nbp.jog.actions.SetMachineDecimalFormatFour") +@ActionRegistration( + displayName = "resources.MessagesBundle#platform.plugin.jog.setMachineDecimalFormatFour", + lazy = false) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_MACHINE_JOG_DECIMAL_PLACES_4, + position = 10000, + separatorAfter = 10001) +}) +@ServiceProvider(service = SetMachineDecimalFormatFour.class) +public class SetMachineDecimalFormatFour extends AbstractAction implements Presenter.Menu { + private final String DECIMAL_FORMAT_FOUR = "0.0000"; + private final BackendAPI backend; + private final JCheckBoxMenuItem menuItem; + + public SetMachineDecimalFormatFour() { + String title = Localization.getString("platform.plugin.jog.setMachineDecimalFormatFour"); + putValue(NAME, title); + + menuItem = new JCheckBoxMenuItem(title); + menuItem.setAction(this); + + backend = CentralLookup.getDefault().lookup(BackendAPI.class); + backend.addUGSEventListener(this::onBackendEvent); + setEnabled(isEnabled()); + onBackendEvent( new SettingChangedEvent()) ; + } + + private void onBackendEvent(UGSEvent event) { + if (event instanceof SettingChangedEvent) { + menuItem.setSelected(backend.getSettings().getMachineDecimalFormat().equals(DECIMAL_FORMAT_FOUR)); + } else if (event instanceof ControllerStateEvent) { + EventQueue.invokeLater(() -> setEnabled(isEnabled())); + } + } + + @Override + public boolean isEnabled() { + return backend != null && backend.isConnected(); + } + + @Override + public JMenuItem getMenuPresenter() { + return menuItem; + } + + @Override + public void actionPerformed(ActionEvent e) { + backend.getSettings().setMachineDecimalFormat(DECIMAL_FORMAT_FOUR); + } +} diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatThree.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatThree.java new file mode 100644 index 0000000000..da94a0581c --- /dev/null +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/SetMachineDecimalFormatThree.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2025 Damian Nikodem + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.willwinder.ugs.nbp.jog.actions; + +import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.listeners.MessageType; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.model.GUIBackend; +import com.willwinder.universalgcodesender.model.UGSEvent; +import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; +import com.willwinder.universalgcodesender.model.events.SettingChangedEvent; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import static javax.swing.Action.NAME; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JMenuItem; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.actions.Presenter; +import org.openide.util.lookup.ServiceProvider; + +/** + * An action to set the number of Decimal Places in the backend. + * + * @author Damian Nikodem + */ +@ActionID( + category = LocalizingService.CATEGORY_MACHINE, + id = "com.willwinder.ugs.nbp.jog.actions.SetMachineDecimalFormatThree") +@ActionRegistration( + displayName = "resources.MessagesBundle#platform.plugin.jog.setMachineDecimalFormatThree", + lazy = false) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_MACHINE_JOG_DECIMAL_PLACES_3, + position = 10000, + separatorAfter = 10001) +}) +@ServiceProvider(service = SetMachineDecimalFormatThree.class) +public class SetMachineDecimalFormatThree extends AbstractAction implements Presenter.Menu { + private final String DECIMAL_FORMAT_THREE = "0.000"; + private final BackendAPI backend; + private final JCheckBoxMenuItem menuItem; + + public SetMachineDecimalFormatThree() { + String title = Localization.getString("platform.plugin.jog.setMachineDecimalFormatThree"); + putValue(NAME, title); + + menuItem = new JCheckBoxMenuItem(title); + menuItem.setAction(this); + + backend = CentralLookup.getDefault().lookup(BackendAPI.class); + backend.addUGSEventListener(this::onBackendEvent); + setEnabled(isEnabled()); + onBackendEvent( new SettingChangedEvent()) ; + } + + private void onBackendEvent(UGSEvent event) { + if (event instanceof SettingChangedEvent) { + menuItem.setSelected(backend.getSettings().getMachineDecimalFormat().equals(DECIMAL_FORMAT_THREE)); + } else if (event instanceof ControllerStateEvent) { + EventQueue.invokeLater(() -> setEnabled(isEnabled())); + } + } + + @Override + public boolean isEnabled() { + return backend != null && backend.isConnected(); + } + + @Override + public JMenuItem getMenuPresenter() { + return menuItem; + } + + @Override + public void actionPerformed(ActionEvent e) { + backend.getSettings().setMachineDecimalFormat(DECIMAL_FORMAT_THREE); + } +} diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/ShowABCStepSizeAction.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/ShowABCStepSizeAction.java index ca17369887..54d063c453 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/ShowABCStepSizeAction.java +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/ShowABCStepSizeAction.java @@ -69,6 +69,7 @@ public ShowABCStepSizeAction() { backend = CentralLookup.getDefault().lookup(BackendAPI.class); backend.addUGSEventListener(this::onBackendEvent); setEnabled(isEnabled()); + onBackendEvent( new SettingChangedEvent()) ; } private void onBackendEvent(UGSEvent event) { diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/UseSeparateStepSizeAction.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/UseSeparateStepSizeAction.java index bc2c04a10b..06d1a28707 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/UseSeparateStepSizeAction.java +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/actions/UseSeparateStepSizeAction.java @@ -69,6 +69,7 @@ public UseSeparateStepSizeAction() { backend = CentralLookup.getDefault().lookup(BackendAPI.class); backend.addUGSEventListener(this::onBackendEvent); setEnabled(isEnabled()); + onBackendEvent( new SettingChangedEvent()) ; } private void onBackendEvent(UGSEvent event) { diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/resources/resources/MessagesBundle.properties b/ugs-platform/ugs-platform-plugin-jog/src/main/resources/resources/MessagesBundle.properties index b2ea325feb..f2fd763d18 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/main/resources/resources/MessagesBundle.properties +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/resources/resources/MessagesBundle.properties @@ -1,6 +1,9 @@ # Default texts for the labels platform.plugin.jog.useSeparateStepSize = Use separate step sizes for Z and XY platform.plugin.jog.showABCStepSize = Show ABC step size +platform.plugin.jog.setMachineDecimalFormatThree=3 Decimal Places +platform.plugin.jog.setMachineDecimalFormatFour=4 Decimal Places +platform.plugin.jog.setMachineDecimalFormatFive=5 Decimal Places platform.plugin.jog.feedRate = Feed rate platform.plugin.jog.stepSize = Step size platform.plugin.jog.stepSizeZ = Step size Z diff --git a/ugs-platform/ugs-platform-plugin-jog/src/test/java/com/willwinder/ugs/nbp/jog/JogPanelTest.java b/ugs-platform/ugs-platform-plugin-jog/src/test/java/com/willwinder/ugs/nbp/jog/JogPanelTest.java index 0b35529a75..7d7cf4083e 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/test/java/com/willwinder/ugs/nbp/jog/JogPanelTest.java +++ b/ugs-platform/ugs-platform-plugin-jog/src/test/java/com/willwinder/ugs/nbp/jog/JogPanelTest.java @@ -29,7 +29,7 @@ public static void main(String[] args) throws Exception { } private void start() throws Exception { - jogPanel = new JogPanel(); + jogPanel = new JogPanel(null); getContentPane().add(jogPanel); createMenuBar(); diff --git a/ugs-platform/ugs-platform-ugslib/src/main/java/com/willwinder/ugs/nbp/lib/services/LocalizingService.java b/ugs-platform/ugs-platform-ugslib/src/main/java/com/willwinder/ugs/nbp/lib/services/LocalizingService.java index c5d991cbd4..fa2a853460 100644 --- a/ugs-platform/ugs-platform-ugslib/src/main/java/com/willwinder/ugs/nbp/lib/services/LocalizingService.java +++ b/ugs-platform/ugs-platform-ugslib/src/main/java/com/willwinder/ugs/nbp/lib/services/LocalizingService.java @@ -43,6 +43,9 @@ public class LocalizingService { public static final String MENU_PROGRAM = "Menu/Program"; public static final String MENU_MACHINE_JOG = "Menu/Machine/Jog"; public static final String MENU_MACHINE_JOG_STEP_SIZE = "Menu/Machine/Jog/Step Size"; + public static final String MENU_MACHINE_JOG_DECIMAL_PLACES_3 = "Menu/Machine/Precision"; + public static final String MENU_MACHINE_JOG_DECIMAL_PLACES_4 = "Menu/Machine/Precision"; + public static final String MENU_MACHINE_JOG_DECIMAL_PLACES_5 = "Menu/Machine/Precision"; public static final String MENU_MACHINE_ACTIONS = "Menu/Machine/Actions"; public static final String MENU_VISUALIZER = "Menu/Visualizer"; public static final String MENU_MACROS = "Menu/Machine/Macros";