< prev index next >

functional/ControlsTests/src/javafx/scene/control/test/utils/ptables/NumberPropertyValueSetter.java

Print this page




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.utils.ptables;
  26 
  27 import javafx.beans.property.DoubleProperty;
  28 import javafx.beans.property.IntegerProperty;
  29 import javafx.beans.property.Property;
  30 import javafx.beans.value.ChangeListener;
  31 import javafx.beans.value.ObservableValue;
  32 import javafx.event.EventHandler;
  33 import javafx.scene.Node;
  34 import javafx.scene.control.Label;
  35 import javafx.scene.control.Slider;
  36 import javafx.scene.control.SliderBuilder;
  37 import static javafx.scene.control.test.utils.ptables.StaticLogger.*;
  38 import javafx.scene.input.MouseEvent;
  39 import javafx.scene.layout.VBox;
  40 import javafx.stage.Popup;
  41 
  42 /**
  43  * @author Alexander Kirov
  44  *
  45  * You can use ctrl+LMBclick, to change min and max ranges of slider (additional
  46  * popup with logarithmic sliders must appear).
  47  */
  48 public class NumberPropertyValueSetter extends AbstractPropertyValueSetter<Number> {
  49 
  50     private DoubleProperty sliderMinProperty;
  51     private DoubleProperty sliderMaxProperty;
  52 
  53     public NumberPropertyValueSetter(Property listeningProperty, AbstractPropertyValueSetter.BindingType btype, Object testedControl, Number minValue, Number initialValue, Number maxValue) {
  54         try {
  55             this.initialValue1 = minValue;
  56             this.initialValue2 = initialValue;


  70                 sliderMaxProperty = slider.maxProperty();
  71                 leadingProperty = (Property) slider.valueProperty();
  72                 leadingControl = slider;
  73 
  74                 if (listeningProperty instanceof IntegerProperty) {
  75                     propertyValueType = PropertyValueType.INTEGER;
  76                 } else {
  77                     propertyValueType = PropertyValueType.DOUBLE;
  78                 }
  79 
  80                 bindComponent(btype, testedControl);
  81                 applyRangesChangers(slider);
  82             }
  83         } catch (Throwable ex) {
  84             log(ex);
  85         }
  86     }
  87 
  88     private void applyRangesChangers(final Slider slider) {
  89         final Popup popupWithControllers = new Popup();
  90         Slider minValue = SliderBuilder.create().prefWidth(300).min(1).max(9).minorTickCount(4).majorTickUnit(2).showTickLabels(true).showTickMarks(true).build();
  91         Slider maxValue = SliderBuilder.create().prefWidth(300).min(1).max(9).minorTickCount(4).majorTickUnit(2).showTickLabels(true).showTickMarks(true).build();














  92 
  93         maxValue.valueProperty().addListener(new ChangeListener() {
  94             public void changed(ObservableValue ov, Object t, Object t1) {
  95                 try {
  96                     slider.setMinorTickCount(0);
  97                     Double newValue = Math.pow(10, (Double) t1);
  98                     slider.setMajorTickUnit(Math.max((newValue - slider.getMin()), 1) / 4);
  99                     slider.maxProperty().setValue(Math.max(newValue, slider.getValue()));
 100                 } catch (Throwable ex) {
 101                     log(ex);
 102                 }
 103             }
 104         });
 105 
 106         minValue.valueProperty().addListener(new ChangeListener() {
 107             public void changed(ObservableValue ov, Object t, Object t1) {
 108                 try {
 109                     slider.setMinorTickCount(0);
 110                     Double newValue = -Math.pow(10, (Double) t1);
 111                     slider.setMajorTickUnit(Math.max((slider.getMax() - newValue), 1) / 4);


 126 
 127         slider.setOnMouseClicked(new EventHandler<MouseEvent>() {
 128             public void handle(MouseEvent t) {
 129                 try {
 130                     if (t.isControlDown()) {
 131                         popupWithControllers.show(slider, slider.getScene().getX() + slider.getLayoutX(), slider.getScene().getY() + slider.getLayoutY());
 132                     }
 133                 } catch (Throwable ex) {
 134                     log(ex);
 135                 }
 136             }
 137         });
 138     }
 139 
 140     private Slider createSlider(int minValue, int maxValue, int defaultValue, String sliderId) {
 141         return createSlider((double) minValue, (double) maxValue, (double) defaultValue, sliderId);
 142     }
 143 
 144     private Slider createSlider(double minValue, double maxValue, double defaultValue, String sliderId) {
 145         try {
 146             return SliderBuilder.create().prefWidth(100).id(sliderId).min(minValue).max(maxValue).value(defaultValue).minorTickCount(4).majorTickUnit((maxValue - minValue) / 4).showTickLabels(true).showTickMarks(true).build();










 147         } catch (Throwable ex) {
 148             log(ex);
 149         }
 150         return null;
 151     }
 152 
 153     public void refresh() {
 154         setBindingState(Boolean.FALSE);
 155         sliderMinProperty.setValue((Number) initialValue1);
 156         leadingProperty.setValue(initialValue2);
 157         sliderMaxProperty.setValue((Number) initialValue3);
 158     }
 159 
 160     public Node getVisualRepresentation() {
 161         return this;
 162     }
 163 }


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.utils.ptables;
  26 
  27 import javafx.beans.property.DoubleProperty;
  28 import javafx.beans.property.IntegerProperty;
  29 import javafx.beans.property.Property;
  30 import javafx.beans.value.ChangeListener;
  31 import javafx.beans.value.ObservableValue;
  32 import javafx.event.EventHandler;
  33 import javafx.scene.Node;
  34 import javafx.scene.control.Label;
  35 import javafx.scene.control.Slider;

  36 import static javafx.scene.control.test.utils.ptables.StaticLogger.*;
  37 import javafx.scene.input.MouseEvent;
  38 import javafx.scene.layout.VBox;
  39 import javafx.stage.Popup;
  40 
  41 /**
  42  * @author Alexander Kirov
  43  *
  44  * You can use ctrl+LMBclick, to change min and max ranges of slider (additional
  45  * popup with logarithmic sliders must appear).
  46  */
  47 public class NumberPropertyValueSetter extends AbstractPropertyValueSetter<Number> {
  48 
  49     private DoubleProperty sliderMinProperty;
  50     private DoubleProperty sliderMaxProperty;
  51 
  52     public NumberPropertyValueSetter(Property listeningProperty, AbstractPropertyValueSetter.BindingType btype, Object testedControl, Number minValue, Number initialValue, Number maxValue) {
  53         try {
  54             this.initialValue1 = minValue;
  55             this.initialValue2 = initialValue;


  69                 sliderMaxProperty = slider.maxProperty();
  70                 leadingProperty = (Property) slider.valueProperty();
  71                 leadingControl = slider;
  72 
  73                 if (listeningProperty instanceof IntegerProperty) {
  74                     propertyValueType = PropertyValueType.INTEGER;
  75                 } else {
  76                     propertyValueType = PropertyValueType.DOUBLE;
  77                 }
  78 
  79                 bindComponent(btype, testedControl);
  80                 applyRangesChangers(slider);
  81             }
  82         } catch (Throwable ex) {
  83             log(ex);
  84         }
  85     }
  86 
  87     private void applyRangesChangers(final Slider slider) {
  88         final Popup popupWithControllers = new Popup();
  89         Slider minValue = new Slider();
  90         minValue.setPrefWidth(300);
  91         minValue.setMin(1);
  92         minValue.setMax(9);
  93         minValue.setMinorTickCount(4);
  94         minValue.setMajorTickUnit(2);
  95         minValue.setShowTickLabels(true);
  96         minValue.setShowTickMarks(true);
  97         Slider maxValue = new Slider();
  98         maxValue.setPrefWidth(300);
  99         maxValue.setMin(1);
 100         maxValue.setMax(9);
 101         maxValue.setMinorTickCount(4);
 102         maxValue.setMajorTickUnit(2);
 103         maxValue.setShowTickLabels(true);
 104         maxValue.setShowTickMarks(true);
 105 
 106         maxValue.valueProperty().addListener(new ChangeListener() {
 107             public void changed(ObservableValue ov, Object t, Object t1) {
 108                 try {
 109                     slider.setMinorTickCount(0);
 110                     Double newValue = Math.pow(10, (Double) t1);
 111                     slider.setMajorTickUnit(Math.max((newValue - slider.getMin()), 1) / 4);
 112                     slider.maxProperty().setValue(Math.max(newValue, slider.getValue()));
 113                 } catch (Throwable ex) {
 114                     log(ex);
 115                 }
 116             }
 117         });
 118 
 119         minValue.valueProperty().addListener(new ChangeListener() {
 120             public void changed(ObservableValue ov, Object t, Object t1) {
 121                 try {
 122                     slider.setMinorTickCount(0);
 123                     Double newValue = -Math.pow(10, (Double) t1);
 124                     slider.setMajorTickUnit(Math.max((slider.getMax() - newValue), 1) / 4);


 139 
 140         slider.setOnMouseClicked(new EventHandler<MouseEvent>() {
 141             public void handle(MouseEvent t) {
 142                 try {
 143                     if (t.isControlDown()) {
 144                         popupWithControllers.show(slider, slider.getScene().getX() + slider.getLayoutX(), slider.getScene().getY() + slider.getLayoutY());
 145                     }
 146                 } catch (Throwable ex) {
 147                     log(ex);
 148                 }
 149             }
 150         });
 151     }
 152 
 153     private Slider createSlider(int minValue, int maxValue, int defaultValue, String sliderId) {
 154         return createSlider((double) minValue, (double) maxValue, (double) defaultValue, sliderId);
 155     }
 156 
 157     private Slider createSlider(double minValue, double maxValue, double defaultValue, String sliderId) {
 158         try {
 159             Slider temp = new Slider();
 160             temp.setPrefWidth(100);
 161             temp.setId(sliderId);
 162             temp.setMin(minValue);
 163             temp.setMax(maxValue);
 164             temp.setValue(defaultValue);
 165             temp.setMinorTickCount(4);
 166             temp.setMajorTickUnit((maxValue - minValue) / 4);
 167             temp.setShowTickLabels(true);
 168             temp.setShowTickMarks(true);
 169             return temp;
 170         } catch (Throwable ex) {
 171             log(ex);
 172         }
 173         return null;
 174     }
 175 
 176     public void refresh() {
 177         setBindingState(Boolean.FALSE);
 178         sliderMinProperty.setValue((Number) initialValue1);
 179         leadingProperty.setValue(initialValue2);
 180         sliderMaxProperty.setValue((Number) initialValue3);
 181     }
 182 
 183     public Node getVisualRepresentation() {
 184         return this;
 185     }
 186 }
< prev index next >