diff --git a/ugs-core/src/com/willwinder/universalgcodesender/uielements/TextFieldUnit.java b/ugs-core/src/com/willwinder/universalgcodesender/uielements/TextFieldUnit.java index 4c1e12d6f5..dac7c4bc5e 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/uielements/TextFieldUnit.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/uielements/TextFieldUnit.java @@ -1,5 +1,5 @@ /* - Copyright 2021 Will Winder + Copyright 2021-2023 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -25,7 +25,7 @@ public enum TextFieldUnit { MM("mm"), INCH("\""), MM_PER_MINUTE("mm/min"), - INCHES_PER_MINUTE("inches/min"), + INCHES_PER_MINUTE("inch/min"), ROTATIONS_PER_MINUTE("rpm"), PERCENT("%"), DEGREE("°"); diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/PercentSpinner.java b/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/PercentSpinner.java similarity index 68% rename from ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/PercentSpinner.java rename to ugs-core/src/com/willwinder/universalgcodesender/uielements/components/PercentSpinner.java index 3a58c261c9..5ac9b88cd2 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/PercentSpinner.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/PercentSpinner.java @@ -1,4 +1,22 @@ -package com.willwinder.ugs.platform.surfacescanner.ui; +/* + Copyright 2023 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS 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. + + UGS 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 UGS. If not, see . + */ +package com.willwinder.universalgcodesender.uielements.components; import com.willwinder.universalgcodesender.uielements.TextFieldUnit; import com.willwinder.universalgcodesender.uielements.TextFieldUnitFormatter; @@ -6,6 +24,11 @@ import javax.swing.*; import javax.swing.text.DefaultFormatterFactory; +/** + * A spinner that shows the percent character at the end when not editing. + * + * @author Joacim Breiler + */ public class PercentSpinner extends JSpinner { private final SpinnerNumberModel spinnerNumberModel; diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/Spinner.java b/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/Spinner.java similarity index 97% rename from ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/Spinner.java rename to ugs-core/src/com/willwinder/universalgcodesender/uielements/components/Spinner.java index 41e7b4b7dc..71eca6a017 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/Spinner.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/Spinner.java @@ -16,7 +16,7 @@ This file is part of Universal Gcode Sender (UGS). You should have received a copy of the GNU General Public License along with UGS. If not, see . */ -package com.willwinder.ugs.platform.surfacescanner.ui; +package com.willwinder.universalgcodesender.uielements.components; import javax.swing.*; diff --git a/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/UnitSpinner.java b/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/UnitSpinner.java new file mode 100644 index 0000000000..cd708838e5 --- /dev/null +++ b/ugs-core/src/com/willwinder/universalgcodesender/uielements/components/UnitSpinner.java @@ -0,0 +1,97 @@ +/* + Copyright 2023 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS 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. + + UGS 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 UGS. If not, see . + */ +package com.willwinder.universalgcodesender.uielements.components; + +import com.willwinder.universalgcodesender.uielements.TextFieldUnit; +import com.willwinder.universalgcodesender.uielements.TextFieldUnitFormatter; + +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import javax.swing.SwingConstants; +import javax.swing.text.DefaultFormatterFactory; + +/** + * Spinner that shows the given unit with its abbreviation + * + * @author Joacim Breiler + */ +public class UnitSpinner extends JSpinner { + + private SpinnerNumberModel spinnerNumberModel; + private NumberEditor numberEditor; + + public UnitSpinner(double value, TextFieldUnit units) { + this(value, units, null, null, 0.01d); + } + + public UnitSpinner(double value, TextFieldUnit units, Double minimum, Double maximum, Double stepSize) { + spinnerNumberModel = new SpinnerNumberModel(Double.valueOf(value), minimum, maximum, stepSize); + setModel(spinnerNumberModel); + setValue(value); + setUnits(units); + } + + public void setUnits(TextFieldUnit units) { + if(units == TextFieldUnit.MM) { + spinnerNumberModel.setStepSize(0.01); + } else { + spinnerNumberModel.setStepSize(0.001); + } + + numberEditor = new JSpinner.NumberEditor(this); + numberEditor.getTextField().setFormatterFactory(new DefaultFormatterFactory( + new TextFieldUnitFormatter(units, 3), + new TextFieldUnitFormatter(units, 3), + new TextFieldUnitFormatter(units, 3, false))); + numberEditor.getTextField().setHorizontalAlignment(SwingConstants.LEFT); + setEditor(numberEditor); + } + + public double getDoubleValue() { + return (Double) getModel().getValue(); + } + + + public void setMinimum(double min) { + spinnerNumberModel.setMinimum(min); + if (getDoubleValue() < min) { + setValue(min); + } + } + + @Override + public Object getNextValue() { + if (super.getNextValue() == null) { + return null; + } + + double power = 1d / spinnerNumberModel.getStepSize().doubleValue(); + return Math.round((Double) super.getNextValue() * power) / power; + } + + @Override + public Object getPreviousValue() { + if (super.getPreviousValue() == null) { + return null; + } + + double power = 1d / spinnerNumberModel.getStepSize().doubleValue(); + return Math.round((Double) super.getPreviousValue() * power) / power; + } +} diff --git a/ugs-core/src/resources/MessagesBundle_en_US.properties b/ugs-core/src/resources/MessagesBundle_en_US.properties index db1d2ab85b..5d7f25af76 100644 --- a/ugs-core/src/resources/MessagesBundle_en_US.properties +++ b/ugs-core/src/resources/MessagesBundle_en_US.properties @@ -510,7 +510,9 @@ mainWindow.swing.getState = Get State platform.window.probe-module = Probe Module platform.window.probe-module.tooltip = A suite of utilities to manage probe operations. probe.find-rate = Fast find rate +probe.find-rate.tooltip = The fast find rate for moving towards the probe probe.measure-rate = Slow measure rate +probe.measure-rate.tooltip = The slow measure rate for moving towards the probe probe.x-distance = Probe X Distance probe.y-distance = Probe Y Distance probe.retract-amount = Retract amount @@ -518,6 +520,7 @@ probe.retract-amount.tooltip = Distance to retract after the fast probe cycle be probe.hole-diameter = Approximate hole diameter probe.hole-center-hint = Move probe to approximate center probe.work-coordinates = Work Coordinates +probe.action.settings = Settings... probe.action.z = Probe and zero Z probe.action.z.confirmation = Are you sure you want to probe Z with current settings? probe.action.xy = Probe and zero XY diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java index 360ea2033c..7220d3ba5f 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java @@ -22,9 +22,18 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbp.lib.Mode; import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import static com.willwinder.ugs.nbp.lib.services.LocalizingService.lang; import com.willwinder.ugs.nbp.lib.services.TopComponentLocalizer; -import com.willwinder.ugs.platform.probe.renderable.*; -import com.willwinder.ugs.platform.probe.ui.*; +import com.willwinder.ugs.platform.probe.renderable.HoleCenterPathPreview; +import com.willwinder.ugs.platform.probe.renderable.ProbePreviewManager; +import com.willwinder.ugs.platform.probe.renderable.XYProbePathPreview; +import com.willwinder.ugs.platform.probe.renderable.XYZProbePathPreview; +import com.willwinder.ugs.platform.probe.renderable.ZProbePathPreview; +import com.willwinder.ugs.platform.probe.ui.ProbeHoleCenterPanel; +import com.willwinder.ugs.platform.probe.ui.ProbeOutsideXYPanel; +import com.willwinder.ugs.platform.probe.ui.ProbeXYZPanel; +import com.willwinder.ugs.platform.probe.ui.ProbeZPanel; +import com.willwinder.ugs.platform.probe.ui.SettingsPanel; import com.willwinder.universalgcodesender.i18n.Localization; import com.willwinder.universalgcodesender.listeners.UGSEventListener; import com.willwinder.universalgcodesender.model.BackendAPI; @@ -39,10 +48,9 @@ This file is part of Universal Gcode Sender (UGS). import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; -import javax.swing.*; -import java.awt.*; - -import static com.willwinder.ugs.nbp.lib.services.LocalizingService.lang; +import javax.swing.JTabbedPane; +import javax.swing.SwingConstants; +import java.awt.BorderLayout; /** * Top component which displays something. @@ -63,10 +71,10 @@ This file is part of Universal Gcode Sender (UGS). ) public final class ProbeTopComponent extends TopComponent implements UGSEventListener { public static final String preferredId = "AdvancedProbeTopComponent"; - public final static String ProbeTitle = Localization.getString("platform.window.probe-module", lang); - public final static String ProbeTooltip = Localization.getString("platform.window.probe-module.tooltip", lang); - public final static String ProbeActionId = "com.willwinder.ugs.platform.probe.ProbeTopComponent.renamed"; - public final static String ProbeCategory = LocalizingService.CATEGORY_WINDOW; + public static final String ProbeTitle = Localization.getString("platform.window.probe-module", lang); + public static final String ProbeTooltip = Localization.getString("platform.window.probe-module.tooltip", lang); + public static final String ProbeActionId = "com.willwinder.ugs.platform.probe.ProbeTopComponent.renamed"; + public static final String ProbeCategory = LocalizingService.CATEGORY_WINDOW; // hole diameter tab private static final String HC_TAB = "Hole center"; // xyz tab @@ -76,9 +84,9 @@ public final class ProbeTopComponent extends TopComponent implements UGSEventLis // z-probe tab private static final String Z_TAB = "Z"; private static final String SETTINGS_TAB = "Settings"; - private final ProbePreviewManager probePreviewManager; - private final JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT); - private final BackendAPI backend; + private transient final ProbePreviewManager probePreviewManager; + private final JTabbedPane jtp = new JTabbedPane(SwingConstants.LEFT); + private transient final BackendAPI backend; private ProbeHoleCenterPanel probeHoleCenterPanel; private ProbeXYZPanel probeXYZPanel; private ProbeOutsideXYPanel probeXYPanel; @@ -144,9 +152,9 @@ private void initComponents() { settingsPanel = new SettingsPanel(); jtp.add(Z_TAB, probeZPanel); - jtp.add(HC_TAB, probeHoleCenterPanel); - jtp.add(XYZ_TAB, probeXYZPanel); jtp.add(OUTSIDE_TAB, probeXYPanel); + jtp.add(XYZ_TAB, probeXYZPanel); + jtp.add(HC_TAB, probeHoleCenterPanel); jtp.add(SETTINGS_TAB, settingsPanel); jtp.setSelectedIndex(ProbeSettings.getSelectedTabIdx()); @@ -154,6 +162,11 @@ private void initComponents() { this.add(jtp); } + public void selectSettingsTab() { + // Select the settings tab (which is last) + jtp.setSelectedIndex(jtp.getTabCount() - 1); + } + @Override public void componentOpened() { controlChangeListener(); diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/OpenProbeSettingsAction.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/OpenProbeSettingsAction.java new file mode 100644 index 0000000000..f2fb103711 --- /dev/null +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/OpenProbeSettingsAction.java @@ -0,0 +1,63 @@ +/* + Copyright 2023 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS 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. + + UGS 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 UGS. If not, see . + */ +package com.willwinder.ugs.platform.probe.actions; + +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.ugs.platform.probe.ProbeTopComponent; +import com.willwinder.universalgcodesender.i18n.Localization; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.windows.WindowManager; + +import javax.swing.AbstractAction; +import java.awt.event.ActionEvent; + +/** + * Opens the probe module and highlights the settings tab. + * + * @author Joacim Breiler + */ +@ActionID( + category = LocalizingService.CATEGORY_MACHINE, + id = "com.willwinder.ugs.platform.probe.actions.OpenProbeSettingsAction") +@ActionRegistration( + displayName = "Settings", + lazy = false) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_MACHINE_PROBE, + position = 50, + separatorBefore = 49)}) +public class OpenProbeSettingsAction extends AbstractAction { + + public OpenProbeSettingsAction() { + putValue("menuText", Localization.getString("probe.action.settings")); + putValue(NAME, Localization.getString("probe.action.settings")); + } + + @Override + public void actionPerformed(ActionEvent e) { + ProbeTopComponent outputWindow = (ProbeTopComponent) WindowManager.getDefault().findTopComponent(ProbeTopComponent.preferredId); + outputWindow.open(); + outputWindow.requestActive(); + outputWindow.selectSettingsTab(); + } +} diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java index 44ce07713c..0cb32c082f 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java @@ -33,7 +33,7 @@ public AbstractProbePreview(int priority, String title) { probeService = Lookup.getDefault().lookup(ProbeService.class); } - public abstract void setContext(ProbeParameters pc, Position startWork, Position startMachine); + public abstract void setContext(ProbeParameters pc, Position startWork); public abstract void updateSettings(); diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java index 6b5dc716ca..e466d07bb8 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java @@ -40,7 +40,6 @@ public abstract class CornerProbePathPreview extends AbstractProbePreview { private final Position spacing = new Position(0, 0, 0); private final Position thickness = new Position(0, 0, 0); private Position startWork = null; - private Position startMachine = null; private ProbeParameters pc = null; private final GLUT glut; @@ -50,10 +49,9 @@ public CornerProbePathPreview(String title) { glut = new GLUT(); } - public void setContext(ProbeParameters pc, Position startWork, Position startMachine) { + public void setContext(ProbeParameters pc, Position startWork) { this.pc = pc; this.startWork = startWork; - this.startMachine = startMachine; } public void updateSpacing( diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java index cda47789eb..8c1bd6539f 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java @@ -22,15 +22,14 @@ This file is part of Universal Gcode Sender (UGS). import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.util.gl2.GLUT; import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; -import com.willwinder.ugs.nbm.visualizer.shared.Renderable; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW; import com.willwinder.ugs.platform.probe.ProbeParameters; import com.willwinder.ugs.platform.probe.ProbeSettings; -import com.willwinder.universalgcodesender.i18n.Localization; -import com.willwinder.universalgcodesender.model.Position; - -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW; import com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.Triangle; import static com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.drawArrow; +import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.Position; +import com.willwinder.universalgcodesender.model.UnitUtils; /** * @@ -217,14 +216,16 @@ public HoleCenterPathPreview() { ProbeSettings.addPreferenceChangeListener(e -> this.hcDiameter = ProbeSettings.getHcDiameter()); } - public void setContext(ProbeParameters pc, Position startWork, Position startMachine) { + public void setContext(ProbeParameters pc, Position startWork) { this.pc = pc; this.startWork = startWork; } @Override public void updateSettings() { - updateSpacing(ProbeSettings.getHcDiameter()); + UnitUtils.Units settingsUnits = ProbeSettings.getSettingsUnits(); + double scaleFactor = UnitUtils.scaleUnits(settingsUnits, UnitUtils.Units.MM); + updateSpacing(ProbeSettings.getHcDiameter() * scaleFactor); } @Override diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java index f160125744..bf0359d29c 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java @@ -56,7 +56,7 @@ public void inactivate() { public void updateContext(ProbeParameters probeParameters, Position workPosition, Position machinePosition) { AbstractProbePreview currentPreview = activePreview.get(); if (currentPreview != null) { - currentPreview.setContext(probeParameters, workPosition, machinePosition); + currentPreview.setContext(probeParameters, workPosition); } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbeRenderableHelpers.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbeRenderableHelpers.java index 088b1d7efb..14d604f88b 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbeRenderableHelpers.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbeRenderableHelpers.java @@ -103,7 +103,7 @@ public static void drawTouchPlate(GL2 gl, GLUT glut, Position at, double inset, gl.glTranslated( at.x + X.side(size-2*inset)/2, at.y + Y.side(size-2*inset)/2, - at.z + Math.signum(at.z) * (bumpThickness/2 - inset)); + at.z + Math.signum(at.z) * ((bumpThickness/2) - inset)); gl.glColor4d(.8, .8, .8, 1); // y bump @@ -126,7 +126,8 @@ public static void drawTouchPlate(GL2 gl, GLUT glut, Position at, double inset, // big piece gl.glPushMatrix(); - gl.glScaled(size-0.1, size-0.1, plateThickness); + gl.glTranslated(0, 0, (bumpThickness/2) - (plateThickness / 2)); + gl.glScaled(size-0.1, size-0.1, plateThickness - 0.1); glut.glutSolidCube(1); gl.glPopMatrix(); diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYProbePathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYProbePathPreview.java index f369a7c5e9..7167e31cab 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYProbePathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYProbePathPreview.java @@ -20,6 +20,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; public class XYProbePathPreview extends CornerProbePathPreview { public XYProbePathPreview() { @@ -28,12 +29,14 @@ public XYProbePathPreview() { @Override public void updateSettings() { + UnitUtils.Units settingsUnits = ProbeSettings.getSettingsUnits(); + double scaleFactor = UnitUtils.scaleUnits(settingsUnits, UnitUtils.Units.MM); updateSpacing( - ProbeSettings.getOutsideXDistance(), - ProbeSettings.getOutsideYDistance(), + ProbeSettings.getOutsideXDistance() * scaleFactor, + ProbeSettings.getOutsideYDistance() * scaleFactor, 0, - ProbeSettings.getOutsideXOffset(), - ProbeSettings.getOutsideYOffset(), + ProbeSettings.getOutsideXOffset() * scaleFactor, + ProbeSettings.getOutsideYOffset() * scaleFactor, 0); } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYZProbePathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYZProbePathPreview.java index 7dc4f0adf2..edcd73161c 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYZProbePathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/XYZProbePathPreview.java @@ -20,6 +20,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; public class XYZProbePathPreview extends CornerProbePathPreview { public XYZProbePathPreview() { @@ -28,12 +29,14 @@ public XYZProbePathPreview() { @Override public void updateSettings() { + UnitUtils.Units settingsUnits = ProbeSettings.getSettingsUnits(); + double scaleFactor = UnitUtils.scaleUnits(settingsUnits, UnitUtils.Units.MM); updateSpacing( - ProbeSettings.getXyzXDistance(), - ProbeSettings.getXyzYDistance(), - ProbeSettings.getXyzZDistance(), - ProbeSettings.getXyzXOffset(), - ProbeSettings.getXyzYOffset(), - ProbeSettings.getXyzZOffset()); + ProbeSettings.getXyzXDistance() * scaleFactor, + ProbeSettings.getXyzYDistance() * scaleFactor, + ProbeSettings.getXyzZDistance() * scaleFactor, + ProbeSettings.getXyzXOffset() * scaleFactor, + ProbeSettings.getXyzYOffset() * scaleFactor, + ProbeSettings.getXyzZOffset() * scaleFactor); } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java index b9b384caf6..d6ddec0f18 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java @@ -22,14 +22,12 @@ This file is part of Universal Gcode Sender (UGS). import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.util.gl2.GLUT; import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW; import com.willwinder.ugs.platform.probe.ProbeParameters; -import com.willwinder.ugs.platform.probe.ProbeService; import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.universalgcodesender.i18n.Localization; import com.willwinder.universalgcodesender.model.Position; -import org.openide.util.Lookup; - -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW; +import com.willwinder.universalgcodesender.model.UnitUtils; /** * @@ -48,13 +46,15 @@ public ZProbePathPreview() { } @Override - public void setContext(ProbeParameters pc, Position startWork, Position startMachine) { + public void setContext(ProbeParameters pc, Position startWork) { this.start = startWork; } @Override public void updateSettings() { - updateSpacing(ProbeSettings.getzDistance(), ProbeSettings.getzOffset()); + UnitUtils.Units settingsUnits = ProbeSettings.getSettingsUnits(); + double scaleFactor = UnitUtils.scaleUnits(settingsUnits, UnitUtils.Units.MM); + updateSpacing(ProbeSettings.getzDistance() * scaleFactor, ProbeSettings.getzOffset() * scaleFactor); } public void updateSpacing(double depth, double offset) { diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeHoleCenterPanel.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeHoleCenterPanel.java index f8cd89925e..2c785d7c29 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeHoleCenterPanel.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeHoleCenterPanel.java @@ -22,52 +22,57 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.ugs.platform.probe.actions.ProbeHoleCenterAction; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.uielements.TextFieldUnit; +import com.willwinder.universalgcodesender.uielements.components.UnitSpinner; import net.miginfocom.swing.MigLayout; -import javax.swing.*; -import javax.swing.event.ChangeEvent; - -import java.awt.*; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSeparator; +import javax.swing.SwingConstants; +import java.awt.Component; import java.util.prefs.PreferenceChangeEvent; -import static com.willwinder.universalgcodesender.utils.SwingHelpers.getDouble; - public class ProbeHoleCenterPanel extends JPanel { - private final SpinnerNumberModel hcDiameterModel; + private final UnitSpinner hcDiameterSpinner; public ProbeHoleCenterPanel() { - hcDiameterModel = new SpinnerNumberModel(ProbeSettings.getHcDiameter(), null, null, 0.1); + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + hcDiameterSpinner = new UnitSpinner(ProbeSettings.getHcDiameter(), units); createLayout(); registerListeners(); } private void registerListeners() { - hcDiameterModel.addChangeListener(e -> ProbeSettings.setHcDiameter(getDouble(hcDiameterModel))); + hcDiameterSpinner.addChangeListener(e -> ProbeSettings.setHcDiameter(hcDiameterSpinner.getDoubleValue())); ProbeSettings.addPreferenceChangeListener(this::onSettingsChanged); } @Override public void setEnabled(boolean enabled) { - for(Component component : getComponents()) { + for (Component component : getComponents()) { component.setEnabled(enabled); } } private void createLayout() { - JButton measureHC = new JButton(new ProbeHoleCenterAction()); - - setLayout(new MigLayout("wrap 2, insets 12")); + setLayout(new MigLayout("wrap 2, insets 12", "[shrink][120:120, sg1]")); add(new JLabel(Localization.getString("probe.hole-diameter"))); - add(new JSpinner(this.hcDiameterModel), "growx, wrap"); - add(new JSeparator(JSeparator.HORIZONTAL), "spanx 2, growx, growy, wrap"); + add(this.hcDiameterSpinner, "growx, wrap"); + add(new JSeparator(SwingConstants.HORIZONTAL), "spanx 2, growx, growy, wrap"); add(new HintLabel(Localization.getString("probe.hole-center-hint")), "spanx 2, growx, wrap, gapy 8"); - add(measureHC, "spanx 2, growx, growy, gapy 8"); + add(new JButton(new ProbeHoleCenterAction()), "spanx 2, growx, growy, gapy 8, height 40:40"); } private void onSettingsChanged(PreferenceChangeEvent e) { - if (e.getKey().equals(ProbeSettings.HC_DIAMETER)) { - hcDiameterModel.setValue(ProbeSettings.getHcDiameter()); + if (e.getKey().endsWith(ProbeSettings.SETTINGS_UNITS)) { + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + hcDiameterSpinner.setUnits(units); + } else if (e.getKey().equals(ProbeSettings.HC_DIAMETER)) { + hcDiameterSpinner.setValue(ProbeSettings.getHcDiameter()); } } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeOutsideXYPanel.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeOutsideXYPanel.java index e9570e2e9a..3d8884625e 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeOutsideXYPanel.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeOutsideXYPanel.java @@ -21,36 +21,39 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.ugs.platform.probe.actions.ProbeOutsideXYAction; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.uielements.TextFieldUnit; +import com.willwinder.universalgcodesender.uielements.components.UnitSpinner; import net.miginfocom.swing.MigLayout; -import javax.swing.*; - -import java.awt.*; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.awt.Component; import java.util.prefs.PreferenceChangeEvent; -import static com.willwinder.universalgcodesender.utils.SwingHelpers.getDouble; - public class ProbeOutsideXYPanel extends JPanel { - private final SpinnerNumberModel outsideXDistanceModel; - private final SpinnerNumberModel outsideYDistanceModel; - private final SpinnerNumberModel outsideXOffsetModel; - private final SpinnerNumberModel outsideYOffsetModel; + private final UnitSpinner outsideXDistanceSpinner; + private final UnitSpinner outsideYDistanceSpinner; + private final UnitSpinner outsideXOffsetSpinner; + private final UnitSpinner outsideYOffsetSpinner; public ProbeOutsideXYPanel() { - outsideXDistanceModel = new SpinnerNumberModel(ProbeSettings.getOutsideXDistance(), null, null, 0.1); - outsideYDistanceModel = new SpinnerNumberModel(ProbeSettings.getOutsideYDistance(), null, null, 0.1); - outsideXOffsetModel = new SpinnerNumberModel(ProbeSettings.getOutsideXOffset(), null, null, 0.1); - outsideYOffsetModel = new SpinnerNumberModel(ProbeSettings.getOutsideYOffset(), null, null, 0.1); + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + outsideXDistanceSpinner = new UnitSpinner(ProbeSettings.getOutsideXDistance(), units); + outsideYDistanceSpinner = new UnitSpinner(ProbeSettings.getOutsideYDistance(), units); + outsideXOffsetSpinner = new UnitSpinner(ProbeSettings.getOutsideXOffset(), units); + outsideYOffsetSpinner = new UnitSpinner(ProbeSettings.getOutsideYOffset(), units); createLayout(); registerListeners(); } private void registerListeners() { - outsideXDistanceModel.addChangeListener(l -> ProbeSettings.setOutsideXDistance(getDouble(outsideXDistanceModel))); - outsideYDistanceModel.addChangeListener(l -> ProbeSettings.setOutsideYDistance(getDouble(outsideYDistanceModel))); - outsideXOffsetModel.addChangeListener(l -> ProbeSettings.setOutsideXOffset(getDouble(outsideXOffsetModel))); - outsideYOffsetModel.addChangeListener(l -> ProbeSettings.setOutsideYOffset(getDouble(outsideYOffsetModel))); + outsideXDistanceSpinner.addChangeListener(l -> ProbeSettings.setOutsideXDistance(outsideXDistanceSpinner.getDoubleValue())); + outsideYDistanceSpinner.addChangeListener(l -> ProbeSettings.setOutsideYDistance(outsideYDistanceSpinner.getDoubleValue())); + outsideXOffsetSpinner.addChangeListener(l -> ProbeSettings.setOutsideXOffset(outsideXOffsetSpinner.getDoubleValue())); + outsideYOffsetSpinner.addChangeListener(l -> ProbeSettings.setOutsideYOffset(outsideYOffsetSpinner.getDoubleValue())); ProbeSettings.addPreferenceChangeListener(this::onSettingsChanged); } @@ -62,33 +65,40 @@ public void setEnabled(boolean enabled) { } private void createLayout() { - setLayout(new MigLayout("wrap 2, insets 10, gap 12")); + setLayout(new MigLayout("wrap 2, insets 10, gap 12", "[120:120, sg1][120:120, sg1]")); add(new JLabel(Localization.getString("probe.x-distance") + ":")); add(new JLabel(Localization.getString("probe.y-distance") + ":")); - add(new JSpinner(outsideXDistanceModel), "growx"); - add(new JSpinner(outsideYDistanceModel), "growx"); + add(outsideXDistanceSpinner, "growx"); + add(outsideYDistanceSpinner, "growx"); add(new JLabel(Localization.getString("autoleveler.option.offset-x") + ":")); add(new JLabel(Localization.getString("autoleveler.option.offset-y") + ":")); - add(new JSpinner(outsideXOffsetModel), "growx"); - add(new JSpinner(outsideYOffsetModel), "growx"); + add(outsideXOffsetSpinner, "growx"); + add(outsideYOffsetSpinner, "growx"); - add(new JButton(new ProbeOutsideXYAction()), "spanx 2, spany 2, growx, growy"); + add(new JButton(new ProbeOutsideXYAction()), "spanx 2, spany 2, growx, growy, height 40:40"); } private void onSettingsChanged(PreferenceChangeEvent e) { switch (e.getKey()) { + case ProbeSettings.SETTINGS_UNITS: + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + outsideXDistanceSpinner.setUnits(units); + outsideYDistanceSpinner.setUnits(units); + outsideXOffsetSpinner.setUnits(units); + outsideYOffsetSpinner.setUnits(units); + break; case ProbeSettings.OUTSIDE_X_DISTANCE: - outsideXDistanceModel.setValue(ProbeSettings.getOutsideXDistance()); + outsideXDistanceSpinner.setValue(ProbeSettings.getOutsideXDistance()); break; case ProbeSettings.OUTSIDE_Y_DISTANCE: - outsideYDistanceModel.setValue(ProbeSettings.getOutsideYDistance()); + outsideYDistanceSpinner.setValue(ProbeSettings.getOutsideYDistance()); break; case ProbeSettings.OUTSIDE_X_OFFSET: - outsideXOffsetModel.setValue(ProbeSettings.getOutsideXOffset()); + outsideXOffsetSpinner.setValue(ProbeSettings.getOutsideXOffset()); break; case ProbeSettings.OUTSIDE_Y_OFFSET: - outsideYOffsetModel.setValue(ProbeSettings.getOutsideYOffset()); + outsideYOffsetSpinner.setValue(ProbeSettings.getOutsideYOffset()); break; } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeXYZPanel.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeXYZPanel.java index f6c01d95a3..e638d157f1 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeXYZPanel.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeXYZPanel.java @@ -21,29 +21,33 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.ugs.platform.probe.actions.ProbeXYZAction; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.uielements.TextFieldUnit; +import com.willwinder.universalgcodesender.uielements.components.UnitSpinner; import net.miginfocom.swing.MigLayout; -import javax.swing.*; -import java.awt.*; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.awt.Component; import java.util.prefs.PreferenceChangeEvent; -import static com.willwinder.universalgcodesender.utils.SwingHelpers.getDouble; - public class ProbeXYZPanel extends JPanel { - private final SpinnerNumberModel xyzXDistanceModel; - private final SpinnerNumberModel xyzYDistanceModel; - private final SpinnerNumberModel xyzZDistanceModel; - private final SpinnerNumberModel xyzXOffsetModel; - private final SpinnerNumberModel xyzYOffsetModel; - private final SpinnerNumberModel xyzZOffsetModel; + private final UnitSpinner xyzXDistanceSpinner; + private final UnitSpinner xyzYDistanceSpinner; + private final UnitSpinner xyzZDistanceSpinner; + private final UnitSpinner xyzXOffsetSpinner; + private final UnitSpinner xyzYOffsetSpinner; + private final UnitSpinner xyzZOffsetSpinner; public ProbeXYZPanel() { - xyzXDistanceModel = new SpinnerNumberModel(ProbeSettings.getXyzXDistance(), null, null, 0.1); - xyzYDistanceModel = new SpinnerNumberModel(ProbeSettings.getXyzYDistance(), null, null, 0.1); - xyzZDistanceModel = new SpinnerNumberModel(ProbeSettings.getXyzZDistance(), null, null, 0.1); - xyzXOffsetModel = new SpinnerNumberModel(ProbeSettings.getXyzXOffset(), null, null, 0.1); - xyzYOffsetModel = new SpinnerNumberModel(ProbeSettings.getXyzYOffset(), null, null, 0.1); - xyzZOffsetModel = new SpinnerNumberModel(ProbeSettings.getXyzZOffset(), null, null, 0.1); + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + xyzXDistanceSpinner = new UnitSpinner(ProbeSettings.getXyzXDistance(), units); + xyzYDistanceSpinner = new UnitSpinner(ProbeSettings.getXyzYDistance(), units); + xyzZDistanceSpinner = new UnitSpinner(ProbeSettings.getXyzZDistance(), units); + xyzXOffsetSpinner = new UnitSpinner(ProbeSettings.getXyzXOffset(), units); + xyzYOffsetSpinner = new UnitSpinner(ProbeSettings.getXyzYOffset(), units); + xyzZOffsetSpinner = new UnitSpinner(ProbeSettings.getXyzZOffset(), units); createLayout(); registerListeners(); @@ -51,60 +55,69 @@ public ProbeXYZPanel() { @Override public void setEnabled(boolean enabled) { - for(Component component : getComponents()) { + for (Component component : getComponents()) { component.setEnabled(enabled); } } private void registerListeners() { - xyzXDistanceModel.addChangeListener(l -> ProbeSettings.setXyzXDistance(getDouble(xyzXDistanceModel))); - xyzYDistanceModel.addChangeListener(l -> ProbeSettings.setXyzYDistance(getDouble(xyzYDistanceModel))); - xyzZDistanceModel.addChangeListener(l -> ProbeSettings.setXyzZDistance(getDouble(xyzZDistanceModel))); - xyzXOffsetModel.addChangeListener(l -> ProbeSettings.setXyzXOffset(getDouble(xyzXOffsetModel))); - xyzYOffsetModel.addChangeListener(l -> ProbeSettings.setXyzYOffset(getDouble(xyzYOffsetModel))); - xyzZOffsetModel.addChangeListener(l -> ProbeSettings.setXyzZOffset(getDouble(xyzZOffsetModel))); + xyzXDistanceSpinner.addChangeListener(l -> ProbeSettings.setXyzXDistance(xyzXDistanceSpinner.getDoubleValue())); + xyzYDistanceSpinner.addChangeListener(l -> ProbeSettings.setXyzYDistance(xyzYDistanceSpinner.getDoubleValue())); + xyzZDistanceSpinner.addChangeListener(l -> ProbeSettings.setXyzZDistance(xyzZDistanceSpinner.getDoubleValue())); + xyzXOffsetSpinner.addChangeListener(l -> ProbeSettings.setXyzXOffset(xyzXOffsetSpinner.getDoubleValue())); + xyzYOffsetSpinner.addChangeListener(l -> ProbeSettings.setXyzYOffset(xyzYOffsetSpinner.getDoubleValue())); + xyzZOffsetSpinner.addChangeListener(l -> ProbeSettings.setXyzZOffset(xyzZOffsetSpinner.getDoubleValue())); ProbeSettings.addPreferenceChangeListener(this::onSettingsChanged); } private void createLayout() { - setLayout(new MigLayout("wrap 3, insets 10, gap 12")); + setLayout(new MigLayout("wrap 3, insets 10, gap 12", "[120:120, sg1][120:120, sg1][120:120, sg1]")); add(new JLabel(Localization.getString("probe.x-distance") + ":")); add(new JLabel(Localization.getString("probe.y-distance") + ":")); add(new JLabel(Localization.getString("probe.probe-distance") + ":")); - add(new JSpinner(xyzXDistanceModel), "growx"); - add(new JSpinner(xyzYDistanceModel), "growx"); - add(new JSpinner(xyzZDistanceModel), "growx"); + add(xyzXDistanceSpinner, "growx"); + add(xyzYDistanceSpinner, "growx"); + add(xyzZDistanceSpinner, "growx"); add(new JLabel(Localization.getString("autoleveler.option.offset-x") + ":")); add(new JLabel(Localization.getString("autoleveler.option.offset-y") + ":")); add(new JLabel(Localization.getString("probe.plate-thickness"))); - add(new JSpinner(xyzXOffsetModel), "growx"); - add(new JSpinner(xyzYOffsetModel), "growx"); - add(new JSpinner(xyzZOffsetModel), "growx"); + add(xyzXOffsetSpinner, "growx"); + add(xyzYOffsetSpinner, "growx"); + add(xyzZOffsetSpinner, "growx"); - add(new JButton(new ProbeXYZAction()), "spanx 2, growx, growy"); + add(new JButton(new ProbeXYZAction()), "spanx 2, growx, growy, height 40:40"); } private void onSettingsChanged(PreferenceChangeEvent e) { switch (e.getKey()) { + case ProbeSettings.SETTINGS_UNITS: + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + xyzXDistanceSpinner.setUnits(units); + xyzYDistanceSpinner.setUnits(units); + xyzZDistanceSpinner.setUnits(units); + xyzXOffsetSpinner.setUnits(units); + xyzYOffsetSpinner.setUnits(units); + xyzZOffsetSpinner.setUnits(units); + break; case ProbeSettings.XYZ_X_DISTANCE: - xyzXDistanceModel.setValue(ProbeSettings.getXyzXDistance()); + xyzXDistanceSpinner.setValue(ProbeSettings.getXyzXDistance()); break; case ProbeSettings.XYZ_Y_DISTANCE: - xyzYDistanceModel.setValue(ProbeSettings.getXyzYDistance()); + xyzYDistanceSpinner.setValue(ProbeSettings.getXyzYDistance()); break; case ProbeSettings.XYZ_Z_DISTANCE: - xyzZDistanceModel.setValue(ProbeSettings.getXyzZDistance()); + xyzZDistanceSpinner.setValue(ProbeSettings.getXyzZDistance()); break; case ProbeSettings.XYZ_X_OFFSET: - xyzXOffsetModel.setValue(ProbeSettings.getXyzXOffset()); + xyzXOffsetSpinner.setValue(ProbeSettings.getXyzXOffset()); break; case ProbeSettings.XYZ_Y_OFFSET: - xyzYOffsetModel.setValue(ProbeSettings.getXyzYOffset()); + xyzYOffsetSpinner.setValue(ProbeSettings.getXyzYOffset()); break; case ProbeSettings.XYZ_Z_OFFSET: - xyzZOffsetModel.setValue(ProbeSettings.getXyzZOffset()); + xyzZOffsetSpinner.setValue(ProbeSettings.getXyzZOffset()); break; } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeZPanel.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeZPanel.java index cc8d01c64c..5d281581db 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeZPanel.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/ProbeZPanel.java @@ -21,56 +21,63 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.ugs.platform.probe.actions.ProbeZAction; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.uielements.TextFieldUnit; +import com.willwinder.universalgcodesender.uielements.components.UnitSpinner; import net.miginfocom.swing.MigLayout; -import javax.swing.*; - -import java.awt.*; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.awt.Component; import java.util.prefs.PreferenceChangeEvent; -import static com.willwinder.universalgcodesender.utils.SwingHelpers.getDouble; - public class ProbeZPanel extends JPanel { - private final SpinnerNumberModel zProbeDistance; - private final SpinnerNumberModel zProbeOffset; + private final UnitSpinner zProbeDistanceSpinner; + private final UnitSpinner zProbeOffsetSpinner; public ProbeZPanel() { - zProbeDistance = new SpinnerNumberModel(ProbeSettings.getzDistance(), null, null, 0.1); - zProbeOffset = new SpinnerNumberModel(ProbeSettings.getzOffset(), null, null, 0.1); - + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + zProbeDistanceSpinner = new UnitSpinner(ProbeSettings.getzDistance(), units); + zProbeOffsetSpinner = new UnitSpinner(ProbeSettings.getzOffset(), units); createLayout(); registerListeners(); } @Override public void setEnabled(boolean enabled) { - for(Component component : getComponents()) { + for (Component component : getComponents()) { component.setEnabled(enabled); } } private void createLayout() { - setLayout(new MigLayout("insets 10, gap 12")); + setLayout(new MigLayout("insets 10, gap 12", "[shrink][120:120, sg1]")); add(new JLabel(Localization.getString("probe.plate-thickness"))); - add(new JSpinner(zProbeOffset), "growx, wrap"); + add(zProbeOffsetSpinner, "growx, wrap"); add(new JLabel(Localization.getString("probe.probe-distance") + ":")); - add(new JSpinner(zProbeDistance), "growx, wrap"); - add(new JButton(new ProbeZAction()), "spanx 2, growx, growy"); + add(zProbeDistanceSpinner, "growx, wrap"); + add(new JButton(new ProbeZAction()), "spanx 2, growx, growy, height 40:40"); } private void registerListeners() { - zProbeDistance.addChangeListener(l -> ProbeSettings.setzDistance(getDouble(zProbeDistance))); - zProbeOffset.addChangeListener(l -> ProbeSettings.setzOffset(getDouble(zProbeOffset))); + zProbeDistanceSpinner.addChangeListener(l -> ProbeSettings.setzDistance(zProbeDistanceSpinner.getDoubleValue())); + zProbeOffsetSpinner.addChangeListener(l -> ProbeSettings.setzOffset(zProbeOffsetSpinner.getDoubleValue())); ProbeSettings.addPreferenceChangeListener(this::onSettingsChanged); } private void onSettingsChanged(PreferenceChangeEvent event) { switch (event.getKey()) { + case ProbeSettings.SETTINGS_UNITS: + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + zProbeOffsetSpinner.setUnits(units); + zProbeDistanceSpinner.setUnits(units); + break; case ProbeSettings.Z_DISTANCE: - zProbeDistance.setValue(ProbeSettings.getzDistance()); + zProbeDistanceSpinner.setValue(ProbeSettings.getzDistance()); break; case ProbeSettings.Z_OFFSET: - zProbeOffset.setValue(ProbeSettings.getzOffset()); + zProbeOffsetSpinner.setValue(ProbeSettings.getzOffset()); break; } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java index 337e2c8263..bb3de3e236 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java @@ -20,64 +20,73 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.platform.probe.ProbeSettings; import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.UnitUtils; import com.willwinder.universalgcodesender.model.WorkCoordinateSystem; +import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G54; +import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G55; +import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G56; +import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G57; +import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G58; +import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G59; +import com.willwinder.universalgcodesender.uielements.TextFieldUnit; +import com.willwinder.universalgcodesender.uielements.components.UnitSpinner; import net.miginfocom.swing.MigLayout; -import javax.swing.*; - -import java.awt.*; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.awt.Component; import java.util.prefs.PreferenceChangeEvent; -import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.*; -import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G59; -import static com.willwinder.universalgcodesender.utils.SwingHelpers.getDouble; - public class SettingsPanel extends JPanel { private final JComboBox settingsWorkCoordinate; - private final SpinnerNumberModel settingsProbeDiameter; - private final SpinnerNumberModel settingsFastFindRate; - private final SpinnerNumberModel settingsSlowMeasureRate; - private final SpinnerNumberModel settingsRetractAmount; + private final UnitSpinner settingsProbeDiameter; + private final UnitSpinner settingsFastFindRate; + private final UnitSpinner settingsSlowMeasureRate; + private final UnitSpinner settingsRetractAmount; public SettingsPanel() { + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + var rateUnits = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM_PER_MINUTE : TextFieldUnit.INCHES_PER_MINUTE; + settingsWorkCoordinate = new JComboBox<>(new WorkCoordinateSystem[]{G54, G55, G56, G57, G58, G59}); settingsWorkCoordinate.setSelectedItem(ProbeSettings.getSettingsWorkCoordinate()); - settingsProbeDiameter = new SpinnerNumberModel(Math.max(ProbeSettings.getSettingsProbeDiameter(), 0), 0.d, null, 0.1); - settingsFastFindRate = new SpinnerNumberModel(Math.max(ProbeSettings.getSettingsFastFindRate(), 0.1), 0.1d, null, 1.); - settingsSlowMeasureRate = new SpinnerNumberModel(Math.max(ProbeSettings.getSettingsSlowMeasureRate(), 0.1), 0.1d, null, 1.); - settingsRetractAmount = new SpinnerNumberModel(Math.max(ProbeSettings.getSettingsRetractAmount(), 0.01), 0.01d, null, 0.1); - + settingsProbeDiameter = new UnitSpinner(Math.max(ProbeSettings.getSettingsProbeDiameter(), 0), units, 0.d, null, 0.1d); + settingsFastFindRate = new UnitSpinner(Math.max(ProbeSettings.getSettingsFastFindRate(), 0.1), rateUnits, 0.1d, null, 1.); + settingsSlowMeasureRate = new UnitSpinner(Math.max(ProbeSettings.getSettingsSlowMeasureRate(), 0.1), rateUnits, 0.1d, null, 1.); + settingsRetractAmount = new UnitSpinner(Math.max(ProbeSettings.getSettingsRetractAmount(), 0.01), units, 0.01d, null, 0.1); createLayout(); registerListeners(); } @Override public void setEnabled(boolean enabled) { - for(Component component : getComponents()) { + for (Component component : getComponents()) { component.setEnabled(enabled); } } private void createLayout() { - setLayout(new MigLayout("wrap 4, insets 10, gap 12", "[shrink][90:90, sg 1][shrink][90:90, sg 1]")); + setLayout(new MigLayout("wrap 2, insets 10, gap 12", "[shrink][140:140, sg 1]")); add(new JLabel(Localization.getString("gcode.setting.endmill-diameter") + ":"), "al right"); - add(new JSpinner(settingsProbeDiameter), "growx"); + add(settingsProbeDiameter, "growx"); add(new JLabel(Localization.getString("probe.find-rate") + ":"), "al right"); - add(new JSpinner(settingsFastFindRate), "growx"); - - add(new JLabel(Localization.getString("probe.work-coordinates") + ":"), "al right"); - add(settingsWorkCoordinate, "growx"); + settingsFastFindRate.setToolTipText(Localization.getString("probe.find-rate.tooltip")); + add(settingsFastFindRate, "growx"); add(new JLabel(Localization.getString("probe.measure-rate") + ":"), "al right"); - add(new JSpinner(settingsSlowMeasureRate), "growx"); + settingsSlowMeasureRate.setToolTipText(Localization.getString("probe.measure-rate.tooltip")); + add(settingsSlowMeasureRate, "growx"); add(new JLabel(Localization.getString("probe.retract-amount") + ":"), "al right"); - JSpinner retractSpinner = new JSpinner(settingsRetractAmount); - retractSpinner.setToolTipText(Localization.getString("probe.retract-amount.tooltip")); - add(retractSpinner, "growx"); + settingsRetractAmount.setToolTipText(Localization.getString("probe.retract-amount.tooltip")); + add(settingsRetractAmount, "growx"); + + add(new JLabel(Localization.getString("probe.work-coordinates") + ":"), "al right"); + add(settingsWorkCoordinate, "growx"); } private void registerListeners() { @@ -89,16 +98,24 @@ private void registerListeners() { ProbeSettings.setSettingsWorkCoordinate(selectedItem); }); - settingsProbeDiameter.addChangeListener(l -> ProbeSettings.setSettingsProbeDiameter(getDouble(settingsProbeDiameter))); - settingsFastFindRate.addChangeListener(l -> ProbeSettings.setSettingsFastFindRate(getDouble(settingsFastFindRate))); - settingsSlowMeasureRate.addChangeListener(l -> ProbeSettings.setSettingsSlowMeasureRate(getDouble(settingsSlowMeasureRate))); - settingsRetractAmount.addChangeListener(l -> ProbeSettings.setSettingsRetractAmount(getDouble(settingsRetractAmount))); + settingsProbeDiameter.addChangeListener(l -> ProbeSettings.setSettingsProbeDiameter(settingsProbeDiameter.getDoubleValue())); + settingsFastFindRate.addChangeListener(l -> ProbeSettings.setSettingsFastFindRate(settingsFastFindRate.getDoubleValue())); + settingsSlowMeasureRate.addChangeListener(l -> ProbeSettings.setSettingsSlowMeasureRate(settingsSlowMeasureRate.getDoubleValue())); + settingsRetractAmount.addChangeListener(l -> ProbeSettings.setSettingsRetractAmount(settingsRetractAmount.getDoubleValue())); ProbeSettings.addPreferenceChangeListener(this::onSettingsChanged); } private void onSettingsChanged(PreferenceChangeEvent e) { switch (e.getKey()) { + case ProbeSettings.SETTINGS_UNITS: + var units = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM : TextFieldUnit.INCH; + var rateUnits = ProbeSettings.getSettingsUnits() == UnitUtils.Units.MM ? TextFieldUnit.MM_PER_MINUTE : TextFieldUnit.INCHES_PER_MINUTE; + settingsProbeDiameter.setUnits(units); + settingsRetractAmount.setUnits(units); + settingsFastFindRate.setUnits(rateUnits); + settingsSlowMeasureRate.setUnits(rateUnits); + break; case ProbeSettings.SETTINGS_WORK_COORDINATE_SYSTEM: settingsWorkCoordinate.getModel().setSelectedItem(ProbeSettings.getSettingsWorkCoordinate()); break; diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java index 2747097d2d..8dd47d420b 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java @@ -31,6 +31,8 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.model.BackendAPI; import com.willwinder.universalgcodesender.model.Position; import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.uielements.components.PercentSpinner; +import com.willwinder.universalgcodesender.uielements.components.Spinner; import com.willwinder.universalgcodesender.utils.AutoLevelSettings; import net.miginfocom.swing.MigLayout; diff --git a/ugs-platform/ugs-platform-ugscore/src/main/java/com/willwinder/ugs/nbp/core/ui/HintLabel.java b/ugs-platform/ugs-platform-ugscore/src/main/java/com/willwinder/ugs/nbp/core/ui/HintLabel.java index 3cfe1cae61..88fd4b193d 100644 --- a/ugs-platform/ugs-platform-ugscore/src/main/java/com/willwinder/ugs/nbp/core/ui/HintLabel.java +++ b/ugs-platform/ugs-platform-ugscore/src/main/java/com/willwinder/ugs/nbp/core/ui/HintLabel.java @@ -32,15 +32,15 @@ public class HintLabel extends JPanel { private final RoundedPanel hintPanel; public HintLabel(String text) { - setLayout(new MigLayout("insets 0")); + setLayout(new MigLayout("fill, insets 0")); hintPanel = new RoundedPanel(8); hintPanel.setLayout(new MigLayout("fill, inset 10, gap 0")); hintPanel.setBackground(ThemeColors.VERY_LIGHT_BLUE_GREY); hintPanel.setForeground(ThemeColors.LIGHT_GREY); hintPanel.add(new JLabel(ImageUtilities.loadImageIcon("resources/icons/hint24.svg", false)), "gapright 10"); - hintPanel.add(new JLabel("" + text + "")); - add(hintPanel); + hintPanel.add(new JLabel("" + text + ""), "grow"); + add(hintPanel, "grow"); } @Override