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.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.List;
32 import javafx.beans.property.DoubleProperty;
33 import javafx.beans.property.IntegerProperty;
34 import javafx.beans.property.ObjectProperty;
35 import javafx.beans.property.Property;
36 import javafx.beans.property.ReadOnlyProperty;
37 import javafx.scene.Node;
38 import javafx.scene.layout.FlowPane;
39 import javafx.scene.layout.FlowPaneBuilder;
40 import javafx.scene.layout.VBox;
41 import static javafx.scene.control.test.utils.ptables.AbstractApplicationPropertiesRegystry.DEFAULT_DOMAIN_NAME;
42
43 /**
44 * @author Alexander Kirov
45 *
46 * This class provide functionality, which is used for creating scene component,
47 * which provide control over different tested control's (node's) properties.
48 *
49 * NOTION: this class should be instantiated on JavaFX thread.
50 *
51 * Use case: PropertiesTable axisProperties = new PropertiesTable(axis);
52 * axisProperties.addBooleanPropertyLine(axis.animatedProperty());
53 * axisProperties.addDoublePropertyLine(axis.tickLengthProperty(), -5, 50, 5);
54 * axisProperties.addStringLine(axis.labelProperty(), "Label");
55 * axisProperties.addSimpleListener(axis.hoverProperty(), axis);
56 * axisProperties.addObjectEnumPropertyLine(axis.sideProperty(),
57 * Arrays.asList(Side.values()));
58 * someContainer.getChildren().add(axisProperties.getContent());//To see it on
59 * scene.
61 * Automated PropertiesTable generation can be used: PropertiesTable tb = new
62 * PropertiesTable(testedSlider); Slider testedSlider = new Slider();
63 * PropertyTablesFactory.explorePropertiesList(testedSlider, tb);
64 * SpecialTablePropertiesProvider.provideForControl(testedSlider, tb); Thus you
65 * can get control over all properties of slider.
66 *
67 * Also you can use functionality of counter. Counters can count increments:
68 * tb.addCounter(SET_ON_HIDING_COUNTER); testedComboBox.setOnHiding(new
69 * EventHandler<Event>() { public void handle(Event t) {
70 * tb.incrementCounter(SET_ON_HIDING_COUNTER); } }); Thus, you can count, how
71 * many times onHiding event happend.
72 *
73 * Look at class javafx.scene.control.test.util.UtilTestFunctions to see, which
74 * functionality of this PropertiesTable can be accessed from tests side (it
75 * contains different checkers, value setters, etc).
76 */
77 public class PropertiesTable extends VBox implements AbstractPropertiesTable, Refreshable {
78
79 public final static String PROPERTIES_TABLE_SUFFIX_ID = "_PROPERTY_TABLE_ID";
80 private final VBox linesVBox = new VBox(5);
81 private final FlowPane countersFlowPane = FlowPaneBuilder.create().vgap(5).hgap(5).build();
82 private final FlowPane listenersFlowPane = FlowPaneBuilder.create().vgap(5).hgap(5).build();
83 private final Object testedControl;
84 private String domainName;
85 /**
86 * Matches property name, on its controller.
87 */
88 private HashMap<String, AbstractPropertyController> propertyControllers = new HashMap<String, AbstractPropertyController>();
89 /**
90 * Matches counter name on its counter representation.
91 */
92 private HashMap<String, AbstractEventsCounter> eventCounters = new HashMap<String, AbstractEventsCounter>();
93 /**
94 * Matches property name on its listener (for read-only properties).
95 */
96 private HashMap<String, AbstractPropertyValueListener> readonlyPropertyListeners = new HashMap<String, AbstractPropertyValueListener>();
97
98 public PropertiesTable(Object testedControl) {
99 super(5);
100 this.domainName = DEFAULT_DOMAIN_NAME;
101 this.setId(DEFAULT_DOMAIN_NAME + PROPERTIES_TABLE_SUFFIX_ID);
102 getChildren().add(0, countersFlowPane);
103 getChildren().add(1, listenersFlowPane);
104 getChildren().add(2, linesVBox);
105 this.testedControl = testedControl;
106 }
107
108 public void refresh() {
109 for (AbstractPropertyController controller : propertyControllers.values()) {
110 controller.refresh();
111 }
112 for (AbstractEventsCounter counter : eventCounters.values()) {
113 counter.refresh();
114 }
115 for (AbstractPropertyValueListener listener : readonlyPropertyListeners.values()) {
116 listener.refresh();
117 }
118 }
119
134 @Override
135 public void addStringLine(Property bindableProperty, String initialText) {
136 addStringLine(bindableProperty, initialText, testedControl);
137 }
138
139 @Override
140 public void addStringLine(Property bindableProperty, String initialText, Object owningObject) {
141 AbstractPropertyController controller = new PropertyValueController(bindableProperty, owningObject, initialText);
142 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
143 linesVBox.getChildren().add(controller.getVisualRepresentation());
144 }
145
146 @Override
147 public void addDoublePropertyLine(final DoubleProperty bindableProperty, double min, double max, double initial) {
148 addDoublePropertyLine(bindableProperty, min, max, initial, testedControl);
149 }
150
151 @Override
152 public void addDoublePropertyLine(final DoubleProperty bindableProperty, double min, double max, double initial, Object owningObject) {
153 AbstractPropertyController controller = new PropertyValueController(bindableProperty, testedControl, min, initial, max);
154 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
155 linesVBox.getChildren().add(controller.getVisualRepresentation());
156 }
157
158 @Override
159 public void addIntegerPropertyLine(final IntegerProperty bindableProperty, int min, int max, int initial) {
160 AbstractPropertyController controller = new PropertyValueController(bindableProperty, testedControl, min, initial, max);
161 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
162 linesVBox.getChildren().add(controller.getVisualRepresentation());
163 }
164
165 @Override
166 public <T> void addObjectEnumPropertyLine(ObjectProperty<T> bindableProperty, List<T> valuesList) {
167 addObjectEnumPropertyLine(bindableProperty, valuesList, testedControl);
168 }
169
170 @Override
171 public <T> void addObjectEnumPropertyLine(ObjectProperty<T> bindableProperty, List<T> valuesList, Object owningObject) {
172 AbstractPropertyController controller = new PropertyValueController<T>(bindableProperty, owningObject, valuesList);
173 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
174 linesVBox.getChildren().add(controller.getVisualRepresentation());
|
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.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.List;
32 import javafx.beans.property.DoubleProperty;
33 import javafx.beans.property.IntegerProperty;
34 import javafx.beans.property.ObjectProperty;
35 import javafx.beans.property.Property;
36 import javafx.beans.property.ReadOnlyProperty;
37 import javafx.scene.Node;
38 import javafx.scene.layout.FlowPane;
39 import javafx.scene.layout.VBox;
40 import static javafx.scene.control.test.utils.ptables.AbstractApplicationPropertiesRegystry.DEFAULT_DOMAIN_NAME;
41
42 /**
43 * @author Alexander Kirov
44 *
45 * This class provide functionality, which is used for creating scene component,
46 * which provide control over different tested control's (node's) properties.
47 *
48 * NOTION: this class should be instantiated on JavaFX thread.
49 *
50 * Use case: PropertiesTable axisProperties = new PropertiesTable(axis);
51 * axisProperties.addBooleanPropertyLine(axis.animatedProperty());
52 * axisProperties.addDoublePropertyLine(axis.tickLengthProperty(), -5, 50, 5);
53 * axisProperties.addStringLine(axis.labelProperty(), "Label");
54 * axisProperties.addSimpleListener(axis.hoverProperty(), axis);
55 * axisProperties.addObjectEnumPropertyLine(axis.sideProperty(),
56 * Arrays.asList(Side.values()));
57 * someContainer.getChildren().add(axisProperties.getContent());//To see it on
58 * scene.
60 * Automated PropertiesTable generation can be used: PropertiesTable tb = new
61 * PropertiesTable(testedSlider); Slider testedSlider = new Slider();
62 * PropertyTablesFactory.explorePropertiesList(testedSlider, tb);
63 * SpecialTablePropertiesProvider.provideForControl(testedSlider, tb); Thus you
64 * can get control over all properties of slider.
65 *
66 * Also you can use functionality of counter. Counters can count increments:
67 * tb.addCounter(SET_ON_HIDING_COUNTER); testedComboBox.setOnHiding(new
68 * EventHandler<Event>() { public void handle(Event t) {
69 * tb.incrementCounter(SET_ON_HIDING_COUNTER); } }); Thus, you can count, how
70 * many times onHiding event happend.
71 *
72 * Look at class javafx.scene.control.test.util.UtilTestFunctions to see, which
73 * functionality of this PropertiesTable can be accessed from tests side (it
74 * contains different checkers, value setters, etc).
75 */
76 public class PropertiesTable extends VBox implements AbstractPropertiesTable, Refreshable {
77
78 public final static String PROPERTIES_TABLE_SUFFIX_ID = "_PROPERTY_TABLE_ID";
79 private final VBox linesVBox = new VBox(5);
80 private final FlowPane countersFlowPane;
81 private final FlowPane listenersFlowPane;
82 private final Object testedControl;
83 private String domainName;
84 /**
85 * Matches property name, on its controller.
86 */
87 private HashMap<String, AbstractPropertyController> propertyControllers = new HashMap<String, AbstractPropertyController>();
88 /**
89 * Matches counter name on its counter representation.
90 */
91 private HashMap<String, AbstractEventsCounter> eventCounters = new HashMap<String, AbstractEventsCounter>();
92 /**
93 * Matches property name on its listener (for read-only properties).
94 */
95 private HashMap<String, AbstractPropertyValueListener> readonlyPropertyListeners = new HashMap<String, AbstractPropertyValueListener>();
96
97 public PropertiesTable(Object testedControl) {
98 super(5);
99 countersFlowPane = new FlowPane();
100 countersFlowPane.setVgap(5);
101 countersFlowPane.setHgap(5);
102 listenersFlowPane = new FlowPane();
103 listenersFlowPane.setVgap(5);
104 listenersFlowPane.setHgap(5);
105 this.domainName = DEFAULT_DOMAIN_NAME;
106 this.setId(DEFAULT_DOMAIN_NAME + PROPERTIES_TABLE_SUFFIX_ID);
107 getChildren().add(0, countersFlowPane);
108 getChildren().add(1, listenersFlowPane);
109 getChildren().add(2, linesVBox);
110 this.testedControl = testedControl;
111 }
112
113 public void refresh() {
114 for (AbstractPropertyController controller : propertyControllers.values()) {
115 controller.refresh();
116 }
117 for (AbstractEventsCounter counter : eventCounters.values()) {
118 counter.refresh();
119 }
120 for (AbstractPropertyValueListener listener : readonlyPropertyListeners.values()) {
121 listener.refresh();
122 }
123 }
124
139 @Override
140 public void addStringLine(Property bindableProperty, String initialText) {
141 addStringLine(bindableProperty, initialText, testedControl);
142 }
143
144 @Override
145 public void addStringLine(Property bindableProperty, String initialText, Object owningObject) {
146 AbstractPropertyController controller = new PropertyValueController(bindableProperty, owningObject, initialText);
147 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
148 linesVBox.getChildren().add(controller.getVisualRepresentation());
149 }
150
151 @Override
152 public void addDoublePropertyLine(final DoubleProperty bindableProperty, double min, double max, double initial) {
153 addDoublePropertyLine(bindableProperty, min, max, initial, testedControl);
154 }
155
156 @Override
157 public void addDoublePropertyLine(final DoubleProperty bindableProperty, double min, double max, double initial, Object owningObject) {
158 AbstractPropertyController controller = new PropertyValueController(bindableProperty, testedControl, min, initial, max);
159 AbstractPropertyController old_controller = propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
160 if (old_controller != null) {
161 linesVBox.getChildren().remove(old_controller.getVisualRepresentation());
162 }
163 linesVBox.getChildren().add(controller.getVisualRepresentation());
164 }
165
166 @Override
167 public void addIntegerPropertyLine(final IntegerProperty bindableProperty, int min, int max, int initial) {
168 AbstractPropertyController controller = new PropertyValueController(bindableProperty, testedControl, min, initial, max);
169 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
170 linesVBox.getChildren().add(controller.getVisualRepresentation());
171 }
172
173 @Override
174 public <T> void addObjectEnumPropertyLine(ObjectProperty<T> bindableProperty, List<T> valuesList) {
175 addObjectEnumPropertyLine(bindableProperty, valuesList, testedControl);
176 }
177
178 @Override
179 public <T> void addObjectEnumPropertyLine(ObjectProperty<T> bindableProperty, List<T> valuesList, Object owningObject) {
180 AbstractPropertyController controller = new PropertyValueController<T>(bindableProperty, owningObject, valuesList);
181 propertyControllers.put(bindableProperty.getName().toUpperCase(), controller);
182 linesVBox.getChildren().add(controller.getVisualRepresentation());
|