From 21d8de509e7cf595bc65224e09ccc43cddbf9952 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Sun, 24 Sep 2017 16:51:31 -0400 Subject: [PATCH 1/3] working on hanging issue on OSX due to JavaFX/Swing interaction --- blue-core/nbproject/project.xml | 8 +++ .../blueSynthBuilder/LineBoundaryDialog.java | 51 ++++++++++++++----- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/blue-core/nbproject/project.xml b/blue-core/nbproject/project.xml index a616cc02e..02c90eb81 100644 --- a/blue-core/nbproject/project.xml +++ b/blue-core/nbproject/project.xml @@ -6,6 +6,14 @@ com.kunstmusik.blue + + blue.jfx + + + + 1.0 + + blue.plugin diff --git a/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java b/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java index 6bf9bfadc..484c695a9 100644 --- a/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java +++ b/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java @@ -19,13 +19,22 @@ */ package blue.orchestra.blueSynthBuilder; +import blue.jfx.BlueFX; +import java.util.Optional; +import java.util.concurrent.CountDownLatch; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.application.Platform; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; /** * Copied from blue-ui-core to deal with having scaling options called when * setting values using getter/setters and PropertySheet. This is definitely not * ideal to have UI stuff like this in the blue-core package and requires a - * better solution. Using it for now... + * better solution. Using it for now... * * @author stevenyi */ @@ -36,19 +45,35 @@ public class LineBoundaryDialog { public static final String TRUNCATE = "Truncate"; public static String getLinePointMethod() { - int retVal = JOptionPane.showOptionDialog(null, - "Choose method for handling line points:", - "Line Boundaries Changed", JOptionPane.OK_CANCEL_OPTION, - JOptionPane.PLAIN_MESSAGE, null, new Object[]{RESCALE, - TRUNCATE}, RESCALE); - - switch (retVal) { - case 0: - return RESCALE; - case 1: - return TRUNCATE; + String retVal = null; + + if (Platform.isFxApplicationThread()) { + Alert alert = + new Alert(Alert.AlertType.NONE, + "Choose method for handling line points:", new ButtonType( + RESCALE), new ButtonType(TRUNCATE) + ); + alert.setTitle("Line Boundaries Changed"); + BlueFX.style(alert.getDialogPane()); + Optional bType = alert.showAndWait(); + retVal = bType.isPresent() ? bType.get().getText() : null; + } else { + int ret = JOptionPane.showOptionDialog(null, + "Choose method for handling line points:", + "Line Boundaries Changed", JOptionPane.OK_CANCEL_OPTION, + JOptionPane.PLAIN_MESSAGE, null, new Object[]{RESCALE, + TRUNCATE}, RESCALE); + + switch (ret) { + case 0: + retVal = RESCALE; + break; + case 1: + retVal = TRUNCATE; + break; + } } - return null; + return retVal; } } From 56779ac458b39b86bf2f3330cdbd365188005e9f Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Sun, 24 Sep 2017 18:15:09 -0400 Subject: [PATCH 2/3] fixed JFX/Swing issues when setting min/max on BSB Widgets by using JFX dialogs in affected areas --- ChangeLog | 10 +++++ .../blueSynthBuilder/ClampedValue.java | 42 +++++++++++++++---- .../blueSynthBuilder/LineBoundaryDialog.java | 6 ++- .../jfx/editors/NumberPropertyEditor.java | 39 +++++++++-------- 4 files changed, 69 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14924fbfc..cb4cb86fa 100755 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,16 @@ information. [CHANGE LOG] +> Notes for 2.7.1 < +[release 2017.09.24] + +FIX + +* BlueSynthBuilder - UI Editor would hang on OSX when setting Min/Max values on + widgets due to JavaFX/Swing UI threads interactions; replaced Swing code to + with JFX code in affected areas + + > Notes for 2.7.0 < [release 2017.09.22] diff --git a/blue-core/src/blue/orchestra/blueSynthBuilder/ClampedValue.java b/blue-core/src/blue/orchestra/blueSynthBuilder/ClampedValue.java index 8b179c534..70402c8b7 100644 --- a/blue-core/src/blue/orchestra/blueSynthBuilder/ClampedValue.java +++ b/blue-core/src/blue/orchestra/blueSynthBuilder/ClampedValue.java @@ -20,13 +20,18 @@ package blue.orchestra.blueSynthBuilder; import blue.components.lines.LineUtils; +import blue.jfx.BlueFX; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import javafx.application.Platform; import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoublePropertyBase; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ButtonType; import javax.swing.JOptionPane; /** @@ -175,7 +180,7 @@ public final void setValue(double val) { } value.set(val); - notifyListeners(ClampedValueListener.PropertyType.VALUE, + notifyListeners(ClampedValueListener.PropertyType.VALUE, ClampedValueListener.BoundaryType.NONE); } @@ -190,16 +195,25 @@ public final DoubleProperty valueProperty() { public final void setMin(double value) { if (value >= getMax()) { - JOptionPane.showMessageDialog(null, "Error: Min value " - + "can not be set greater or equals to Max value.", - "Error", JOptionPane.ERROR_MESSAGE); + if (Platform.isFxApplicationThread()) { + Alert a = new Alert(AlertType.NONE, + "Error: Min value can not be set greater or equals to Max value.", + ButtonType.OK); + a.setTitle("Error"); + BlueFX.style(a.getDialogPane()); + a.showAndWait(); + } else { + JOptionPane.showMessageDialog(null, "Error: Min value " + + "can not be set greater or equals to Max value.", + "Error", JOptionPane.ERROR_MESSAGE); + } return; } String retVal = LineBoundaryDialog.getLinePointMethod(); ClampedValueListener.BoundaryType bType; - if(retVal == null) { + if (retVal == null) { return; } @@ -232,17 +246,27 @@ public final DoubleProperty minProperty() { public final void setMax(double value) { if (value <= getMin()) { - JOptionPane.showMessageDialog(null, "Error: Max value " - + "can not be set less than or " + "equal to Min value.", - "Error", JOptionPane.ERROR_MESSAGE); + if (Platform.isFxApplicationThread()) { + Alert a = new Alert(AlertType.NONE, + "Error: Max value can not be set less than or " + + "equal to Min value.", + ButtonType.OK); + a.setTitle("Error"); + BlueFX.style(a.getDialogPane()); + a.showAndWait(); + } else { + JOptionPane.showMessageDialog(null, "Error: Max value " + + "can not be set less than or " + "equal to Min value.", + "Error", JOptionPane.ERROR_MESSAGE); + } return; } String retVal = LineBoundaryDialog.getLinePointMethod(); ClampedValueListener.BoundaryType bType; - if(retVal == null) { + if (retVal == null) { return; } diff --git a/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java b/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java index 484c695a9..13c83f1c6 100644 --- a/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java +++ b/blue-core/src/blue/orchestra/blueSynthBuilder/LineBoundaryDialog.java @@ -51,12 +51,14 @@ public static String getLinePointMethod() { Alert alert = new Alert(Alert.AlertType.NONE, "Choose method for handling line points:", new ButtonType( - RESCALE), new ButtonType(TRUNCATE) + RESCALE), new ButtonType(TRUNCATE), ButtonType.CANCEL ); alert.setTitle("Line Boundaries Changed"); BlueFX.style(alert.getDialogPane()); Optional bType = alert.showAndWait(); - retVal = bType.isPresent() ? bType.get().getText() : null; + if(bType.isPresent() && !bType.get().getButtonData().isCancelButton()) { + retVal = bType.get().getText(); + } } else { int ret = JOptionPane.showOptionDialog(null, "Choose method for handling line points:", diff --git a/blue-ui-core/src/blue/orchestra/editor/blueSynthBuilder/jfx/editors/NumberPropertyEditor.java b/blue-ui-core/src/blue/orchestra/editor/blueSynthBuilder/jfx/editors/NumberPropertyEditor.java index 95dfd39aa..91a16e419 100644 --- a/blue-ui-core/src/blue/orchestra/editor/blueSynthBuilder/jfx/editors/NumberPropertyEditor.java +++ b/blue-ui-core/src/blue/orchestra/editor/blueSynthBuilder/jfx/editors/NumberPropertyEditor.java @@ -38,15 +38,20 @@ public class NumberPropertyEditor extends TextField { public NumberPropertyEditor(PropertySheet.Item item) { this.item = item; - this.setOnAction(e -> updateTextFromTextField()); - this.focusedProperty().addListener((obs, o, n) -> { + ChangeListener focusListener = (obs, o, n) -> { if (o && !n) { editing = false; updateTextFromTextField(); } else { editing = true; } + }; + this.setOnAction(e -> { + focusedProperty().removeListener(focusListener); + updateTextFromTextField(); + focusedProperty().addListener(focusListener); }); + this.focusedProperty().addListener(focusListener); ChangeListener listener = (obs, old, newVal) -> { if (!editing) { @@ -65,10 +70,10 @@ public NumberPropertyEditor(PropertySheet.Item item) { }); } - private void updateTextFromTextField() { + private synchronized void updateTextFromTextField() { String newValue = this.getText(); String old = item.getValue().toString(); - if(old.equals(newValue)) { + if (old.equals(newValue)) { return; } if (validator == null || validator.test(newValue)) { @@ -88,22 +93,22 @@ public void setValidator(Predicate validator) { public Number getValueAsNumber() { Class type = item.getType(); - if (type == byte.class || type == Byte.class){ - return new Byte(getText()); - }else if(type == short.class || type == Short.class){ + if (type == byte.class || type == Byte.class) { + return new Byte(getText()); + } else if (type == short.class || type == Short.class) { return new Short(getText()); - } else if(type == int.class || type == Integer.class){ + } else if (type == int.class || type == Integer.class) { return new Integer(getText()); - } else if(type == long.class || type == Long.class){ + } else if (type == long.class || type == Long.class) { return new Long(getText()); - } else if(type == BigInteger.class) { - return new BigInteger(getText()); - } else if(type == BigDecimal.class) { - return new BigDecimal(getText()); - } else if(type == float.class || type == Float.class) { - return new Float(getText()); - } else if(type == double.class || type == Double.class) { - return new Double(getText()); + } else if (type == BigInteger.class) { + return new BigInteger(getText()); + } else if (type == BigDecimal.class) { + return new BigDecimal(getText()); + } else if (type == float.class || type == Float.class) { + return new Float(getText()); + } else if (type == double.class || type == Double.class) { + return new Double(getText()); } return null; From 4e5a7a53bf766771576d4ae0b104aa615d57fe52 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Sun, 24 Sep 2017 18:19:49 -0400 Subject: [PATCH 3/3] updated for release --- blue-core/src/blue/blueConstants.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blue-core/src/blue/blueConstants.properties b/blue-core/src/blue/blueConstants.properties index 14e1b4b99..1104e4536 100644 --- a/blue-core/src/blue/blueConstants.properties +++ b/blue-core/src/blue/blueConstants.properties @@ -1,2 +1,2 @@ -blueReleaseDate=2017.09.22. -blueVersion=2.7.0 +blueReleaseDate=2017.09.24 +blueVersion=2.7.1