Skip to content

Commit

Permalink
Reworked the auto leveler UI (winder#2277)
Browse files Browse the repository at this point in the history
* Extracted UI to its own panel and made it more decoupled from the logic.
* Actions are now extracted to their own action classes
* UI now listens to the state of the controller and enables/disables actions that can be used
* Added feature for saving/loading/clearing the scanned probe data
  • Loading branch information
breiler authored Aug 13, 2023
1 parent 2543f82 commit f39402d
Show file tree
Hide file tree
Showing 73 changed files with 3,643 additions and 761 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ public void applyCommandProcessor(CommandProcessor commandProcessor) throws Exce
@Override
public void removeCommandProcessor(CommandProcessor commandProcessor) throws Exception {
gcp.removeCommandProcessor(commandProcessor);
processGcodeFile();

if (gcodeFile != null) {
processGcodeFile();
Expand All @@ -473,7 +472,7 @@ public File getGcodeFile() {

@Override
public File getProcessedGcodeFile() {
logger.log(Level.INFO, String.format("Getting processed gcode file (%s).", this.processedGcodeFile));
logger.log(Level.FINEST, String.format("Getting processed gcode file (%s).", this.processedGcodeFile));
return this.processedGcodeFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ 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 <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.designer.gui;
package com.willwinder.universalgcodesender.uielements;

/**
* @author Joacim Breiler
*/
public enum Unit {
public enum TextFieldUnit {
MM("mm"),
INCH("\""),
MM_PER_MINUTE("mm/min"),
Expand All @@ -32,7 +32,7 @@ public enum Unit {

private final String abbreviation;

Unit(String abbreviation) {
TextFieldUnit(String abbreviation) {
this.abbreviation = abbreviation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.designer.gui;
package com.willwinder.universalgcodesender.uielements;

import com.willwinder.universalgcodesender.Utils;
import com.willwinder.universalgcodesender.utils.MathUtils;
Expand All @@ -28,35 +28,35 @@ This file is part of Universal Gcode Sender (UGS).
/**
* @author Joacim Breiler
*/
public class UnitFormatter extends JFormattedTextField.AbstractFormatter {
public class TextFieldUnitFormatter extends JFormattedTextField.AbstractFormatter {

private final Unit unit;
private final TextFieldUnit unit;
private final int numberOfDecimals;
private final boolean showAbbreviation;

public UnitFormatter(Unit unit, int numberOfDecimals) {
public TextFieldUnitFormatter(TextFieldUnit unit, int numberOfDecimals) {
this(unit, numberOfDecimals, true);
}

public UnitFormatter(Unit unit, int numberOfDecimals, boolean showAbbreviation) {
public TextFieldUnitFormatter(TextFieldUnit unit, int numberOfDecimals, boolean showAbbreviation) {
this.unit = unit;
this.numberOfDecimals = numberOfDecimals;
this.showAbbreviation = showAbbreviation;
}

@Override
public Object stringToValue(String text) throws ParseException {
String value = StringUtils.removeEnd(text, Unit.MM.getAbbreviation());
String value = StringUtils.removeEnd(text, TextFieldUnit.MM.getAbbreviation());
value = StringUtils.replace(value, ",", ".");
value = StringUtils.removeEnd(value, Unit.INCH.getAbbreviation());
value = StringUtils.removeEnd(value, Unit.INCHES_PER_MINUTE.getAbbreviation());
value = StringUtils.removeEnd(value, Unit.MM_PER_MINUTE.getAbbreviation());
value = StringUtils.removeEnd(value, Unit.ROTATIONS_PER_MINUTE.getAbbreviation());
value = StringUtils.removeEnd(value, Unit.PERCENT.getAbbreviation());
value = StringUtils.removeEnd(value, TextFieldUnit.INCH.getAbbreviation());
value = StringUtils.removeEnd(value, TextFieldUnit.INCHES_PER_MINUTE.getAbbreviation());
value = StringUtils.removeEnd(value, TextFieldUnit.MM_PER_MINUTE.getAbbreviation());
value = StringUtils.removeEnd(value, TextFieldUnit.ROTATIONS_PER_MINUTE.getAbbreviation());
value = StringUtils.removeEnd(value, TextFieldUnit.PERCENT.getAbbreviation());
value = StringUtils.trim(value);
double numericValue = MathUtils.round(Utils.formatter.parse(value).doubleValue(), numberOfDecimals);

if (unit == Unit.PERCENT) {
if (unit == TextFieldUnit.PERCENT) {
numericValue = numericValue / 100d;
}
return numericValue;
Expand All @@ -65,7 +65,7 @@ public Object stringToValue(String text) throws ParseException {
@Override
public String valueToString(Object text) throws ParseException {
double value = Utils.formatter.parse(text.toString()).doubleValue();
if (unit == Unit.PERCENT) {
if (unit == TextFieldUnit.PERCENT) {
value = value * 100d;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ 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 <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.designer.gui;
package com.willwinder.universalgcodesender.uielements;

import com.willwinder.universalgcodesender.uielements.TextFieldUnit;
import com.willwinder.universalgcodesender.uielements.TextFieldUnitFormatter;

import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;
Expand All @@ -25,11 +28,11 @@ This file is part of Universal Gcode Sender (UGS).
* @author Joacim Breiler
*/
public class TextFieldWithUnit extends JFormattedTextField {
public TextFieldWithUnit(Unit unit, int numberOfDecimals, double value) {
public TextFieldWithUnit(TextFieldUnit unit, int numberOfDecimals, double value) {
super(new DefaultFormatterFactory(
new UnitFormatter(unit, numberOfDecimals),
new UnitFormatter(unit, numberOfDecimals),
new UnitFormatter(unit, numberOfDecimals, false)
new TextFieldUnitFormatter(unit, numberOfDecimals),
new TextFieldUnitFormatter(unit, numberOfDecimals),
new TextFieldUnitFormatter(unit, numberOfDecimals, false)
), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Spinner(String text, SpinnerModel model) {
label = new JLabel(text);
spinner = new JSpinner(model);
setLayout(new MigLayout("insets 0, wrap 2"));
add(spinner, "w 70");
add(spinner, "w 90");
add(label);
}

Expand Down
Loading

0 comments on commit f39402d

Please sign in to comment.