Skip to content

Commit

Permalink
Remember the last unit of measure
Browse files Browse the repository at this point in the history
  • Loading branch information
ccavanaugh committed Mar 31, 2019
1 parent 1a54c33 commit 77609a3
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.math.BigDecimal;
import java.util.prefs.Preferences;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
Expand Down Expand Up @@ -50,6 +51,8 @@
*/
public class PageFormatDialogController {

private static final String LAST_UNIT = "lastUnit";

@InjectFXML
private final ObjectProperty<Scene> parent = new SimpleObjectProperty<>();

Expand Down Expand Up @@ -99,6 +102,8 @@ public class PageFormatDialogController {
// anything less than 2 inches is considered bad
private final DoubleProperty minWidthPoints = new SimpleDoubleProperty(Constants.POINTS_PER_INCH * 2);

private final Preferences preferences = Preferences.userNodeForPackage(PageFormatDialogController.class);

@FXML
void initialize() {

Expand Down Expand Up @@ -132,6 +137,9 @@ void initialize() {
pageSizeComboBox.valueProperty().addListener((observable, oldValue, newValue) -> handlePageSizeChange());
unitsComboBox.valueProperty().addListener((observable, oldValue, newValue) -> handleUnitChange());

// restore the defaults
unitsComboBox.setValue(Unit.values()[preferences.getInt(LAST_UNIT, Unit.INCHES.ordinal())]);

// bindings to prevent math mischief from occurring
minWidth.bind(minWidthPoints.divide(unitScaleProperty));

Expand Down Expand Up @@ -231,6 +239,8 @@ private void handlePageSizeChange() {
private void handleUnitChange() {
final Unit newUnit = unitsComboBox.getValue();

preferences.putInt(LAST_UNIT, newUnit.ordinal());

unitScaleProperty.set(newUnit.scale); // update binding

handleUnitChange(widthField, lastUnit, newUnit);
Expand Down

0 comments on commit 77609a3

Please sign in to comment.