-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed scaling in probe preview components * Added a new spinner that can show units and moved them to the generic package * Added unit abbreviation to all spinners * Fixed small styling problem and added action for opening the probe settings
- Loading branch information
Showing
22 changed files
with
443 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 24 additions & 1 deletion
25
...orm/surfacescanner/ui/PercentSpinner.java → ...uielements/components/PercentSpinner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
ugs-core/src/com/willwinder/universalgcodesender/uielements/components/UnitSpinner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...dule/src/main/java/com/willwinder/ugs/platform/probe/actions/OpenProbeSettingsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.