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

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 java.lang.reflect.Method;
  28 import javafx.beans.property.ReadOnlyProperty;
  29 import javafx.beans.value.ChangeListener;
  30 import javafx.beans.value.ObservableValue;
  31 import javafx.scene.control.LabelBuilder;
  32 import javafx.scene.control.TextField;
  33 import javafx.scene.control.TextFieldBuilder;
  34 import javafx.scene.control.Tooltip;
  35 import javafx.scene.control.TreeTableColumn;
  36 import javafx.scene.layout.HBox;
  37 import static javafx.scene.control.test.utils.ptables.StaticLogger.*;

  38 
  39 /**
  40  * @author Alexander Kirov
  41  *
  42  * How to use it: Use contructor to give this class owningObject (this is
  43  * something, usually control, which has getter, and method, which returns
  44  * property in API. And instance of property, which will be listened. Also, for
  45  * testing purposes, you will need to give an ID, and Small text, which will be
  46  * in the label, descripting, what this listener is doing.
  47  *
  48  * Listener will listen to changes of property values and put new values to the
  49  * TextField.
  50  *
  51  * You can take formed HBox, where all needed controls will be added.
  52  *
  53  * NOTION: this class should be instantiated on JavaFX thread.
  54  */
  55 public class PropertyValueListener<ValueType> extends HBox implements AbstractPropertyValueListener<ValueType> {
  56 
  57     public final static String LISTENER_SUFFIX = "_LISTENER_ID";
  58     private ReadOnlyProperty listenedProperty;
  59     private Object owningObject;
  60     private TextField receivedValueTF = TextFieldBuilder.create().minWidth(50).maxWidth(110).build();
  61     private boolean someStateWasRemembered = false;
  62     private ValueType rememberedState = null;
  63     private int rememberedChangeCountValue = -1;
  64     private AbstractPropertyValueChangeCounter counter;
  65 
  66     public <ValueType> PropertyValueListener(ReadOnlyProperty bindableProperty, Object owningObject) {
  67         this(bindableProperty, owningObject, true);
  68     }
  69 
  70     public <ValueType> PropertyValueListener(ReadOnlyProperty bindableProperty, Object owningObject, Boolean showCounters) {
  71         this(bindableProperty.getName().toLowerCase() + " : ", bindableProperty, bindableProperty.getName().toUpperCase() + LISTENER_SUFFIX, owningObject, showCounters);
  72     }
  73 
  74     public <ValueType> PropertyValueListener(String labelDescription, ReadOnlyProperty listenedProperty, String textFieldId, Object owningObject) {
  75         this(labelDescription, listenedProperty, textFieldId, owningObject, true);
  76     }
  77 
  78     public <ValueType> PropertyValueListener(String labelDescription, ReadOnlyProperty listenedProperty, String textFieldId, Object owningObject, Boolean showCounters) {
  79         this.owningObject = owningObject;


  80         receivedValueTF.setId(textFieldId);
  81         receivedValueTF.setTooltip(new Tooltip());
  82         if (listenedProperty.getName().contains("BOUNDS")) {
  83             //Make text field width, because bounds - big.
  84             receivedValueTF.setMinWidth(500);
  85         }
  86         this.listenedProperty = listenedProperty;
  87         counter = new PropertyValueCounter(listenedProperty);
  88         getChildren().add(LabelBuilder.create().text(labelDescription).prefWidth(100).build());


  89         if (showCounters) {
  90             getChildren().add(counter.getVisualRepresentation());
  91         }
  92         getChildren().add(receivedValueTF);
  93 
  94         listenedProperty.addListener(new ChangeListener() {
  95             public void changed(ObservableValue ov, Object t, Object t1) {
  96                 processNewValue(t1);
  97             }
  98         });
  99         processNewValue(listenedProperty.getValue());
 100     }
 101 
 102     public final void setListener() {
 103     }
 104 
 105     private void processNewValue(Object t1) {
 106         try {
 107             if (t1 != null) {
 108                 receivedValueTF.getTooltip().setText(t1.toString() + "\n" + receivedValueTF.getTooltip().getText());




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 java.lang.reflect.Method;
  28 import javafx.beans.property.ReadOnlyProperty;
  29 import javafx.beans.value.ChangeListener;
  30 import javafx.beans.value.ObservableValue;
  31 import javafx.scene.control.Label;
  32 import javafx.scene.control.TextField;

  33 import javafx.scene.control.Tooltip;


  34 import static javafx.scene.control.test.utils.ptables.StaticLogger.*;
  35 import javafx.scene.layout.HBox;
  36 
  37 /**
  38  * @author Alexander Kirov
  39  *
  40  * How to use it: Use contructor to give this class owningObject (this is
  41  * something, usually control, which has getter, and method, which returns
  42  * property in API. And instance of property, which will be listened. Also, for
  43  * testing purposes, you will need to give an ID, and Small text, which will be
  44  * in the label, descripting, what this listener is doing.
  45  *
  46  * Listener will listen to changes of property values and put new values to the
  47  * TextField.
  48  *
  49  * You can take formed HBox, where all needed controls will be added.
  50  *
  51  * NOTION: this class should be instantiated on JavaFX thread.
  52  */
  53 public class PropertyValueListener<ValueType> extends HBox implements AbstractPropertyValueListener<ValueType> {
  54 
  55     public final static String LISTENER_SUFFIX = "_LISTENER_ID";
  56     private ReadOnlyProperty listenedProperty;
  57     private Object owningObject;
  58     private TextField receivedValueTF = new TextField();
  59     private boolean someStateWasRemembered = false;
  60     private ValueType rememberedState = null;
  61     private int rememberedChangeCountValue = -1;
  62     private AbstractPropertyValueChangeCounter counter;
  63 
  64     public <ValueType> PropertyValueListener(ReadOnlyProperty bindableProperty, Object owningObject) {
  65         this(bindableProperty, owningObject, true);
  66     }
  67 
  68     public <ValueType> PropertyValueListener(ReadOnlyProperty bindableProperty, Object owningObject, Boolean showCounters) {
  69         this(bindableProperty.getName().toLowerCase() + " : ", bindableProperty, bindableProperty.getName().toUpperCase() + LISTENER_SUFFIX, owningObject, showCounters);
  70     }
  71 
  72     public <ValueType> PropertyValueListener(String labelDescription, ReadOnlyProperty listenedProperty, String textFieldId, Object owningObject) {
  73         this(labelDescription, listenedProperty, textFieldId, owningObject, true);
  74     }
  75 
  76     public <ValueType> PropertyValueListener(String labelDescription, ReadOnlyProperty listenedProperty, String textFieldId, Object owningObject, Boolean showCounters) {
  77         this.owningObject = owningObject;
  78         receivedValueTF.setMinWidth(50);
  79         receivedValueTF.setMaxWidth(110);
  80         receivedValueTF.setId(textFieldId);
  81         receivedValueTF.setTooltip(new Tooltip());
  82         if (listenedProperty.getName().contains("BOUNDS")) {
  83             //Make text field width, because bounds - big.
  84             receivedValueTF.setMinWidth(500);
  85         }
  86         this.listenedProperty = listenedProperty;
  87         counter = new PropertyValueCounter(listenedProperty);
  88         Label temp = new Label(labelDescription);
  89         temp.setPrefWidth(100);
  90         getChildren().add(temp);
  91         if (showCounters) {
  92             getChildren().add(counter.getVisualRepresentation());
  93         }
  94         getChildren().add(receivedValueTF);
  95 
  96         listenedProperty.addListener(new ChangeListener() {
  97             public void changed(ObservableValue ov, Object t, Object t1) {
  98                 processNewValue(t1);
  99             }
 100         });
 101         processNewValue(listenedProperty.getValue());
 102     }
 103 
 104     public final void setListener() {
 105     }
 106 
 107     private void processNewValue(Object t1) {
 108         try {
 109             if (t1 != null) {
 110                 receivedValueTF.getTooltip().setText(t1.toString() + "\n" + receivedValueTF.getTooltip().getText());