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
26 package javafx.scene.control;
27
28
29 import javafx.css.ParsedValue;
30 import javafx.css.CssMetaData;
31 import com.sun.javafx.css.parser.CSSParser;
32 import com.sun.javafx.pgstub.StubToolkit;
33 import com.sun.javafx.tk.Toolkit;
34 import javafx.css.StyleableProperty;
35 import javafx.scene.Parent;
36 import javafx.scene.Scene;
37 import javafx.scene.layout.StackPane;
38 import javafx.stage.Stage;
39 import javafx.util.StringConverter;
40 import static org.junit.Assert.assertEquals;
41 import org.junit.Assert;
42 import org.junit.Before;
43 import org.junit.Test;
44
45 /**
46 * @author smarks
47 */
48 public class SliderTest {
49
50
51 private Slider slider;
53 private Scene scene;
54 private Stage stage;
55
56 @Before public void setup() {
57 tk = (StubToolkit)Toolkit.getToolkit();//This step is not needed (Just to make sure StubToolkit is loaded into VM)
58 slider = new Slider();
59 }
60
61 protected void startApp(Parent root) {
62 scene = new Scene(root,800,600);
63 stage = new Stage();
64 stage.setScene(scene);
65 stage.show();
66 tk.firePulse();
67 }
68 @Test public void testSettingMinorTickCountViaCSS() {
69 StackPane pane = new StackPane();
70 pane.getChildren().add(slider);
71 startApp(pane);
72
73 ParsedValue pv = CSSParser.getInstance().parseExpr("-fx-minor-tick-count","2");
74 Object val = pv.convert(null);
75 try {
76 ((StyleableProperty)slider.minorTickCountProperty()).applyStyle(null, val);
77 assertEquals(2, slider.getMinorTickCount(), 0.);
78 } catch (Exception e) {
79 Assert.fail(e.toString());
80 }
81 }
82
83 @Test public void testSettingTickLabelFormatter() {
84 StackPane pane = new StackPane();
85 pane.getChildren().add(slider);
86 slider.setShowTickLabels(true);
87 slider.setShowTickMarks(true);
88 slider.setLabelFormatter(new StringConverter<Double>() {
89 @Override public String toString(Double t) {
90 return "Ok.";
91 }
92 @Override public Double fromString(String string) {
93 return 10.0;
|
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
26 package javafx.scene.control;
27
28
29 import javafx.css.ParsedValue;
30 import javafx.css.CssMetaData;
31 import javafx.css.CssParser;
32 import com.sun.javafx.pgstub.StubToolkit;
33 import com.sun.javafx.tk.Toolkit;
34 import javafx.css.StyleableProperty;
35 import javafx.scene.Parent;
36 import javafx.scene.Scene;
37 import javafx.scene.layout.StackPane;
38 import javafx.stage.Stage;
39 import javafx.util.StringConverter;
40 import static org.junit.Assert.assertEquals;
41 import org.junit.Assert;
42 import org.junit.Before;
43 import org.junit.Test;
44
45 /**
46 * @author smarks
47 */
48 public class SliderTest {
49
50
51 private Slider slider;
53 private Scene scene;
54 private Stage stage;
55
56 @Before public void setup() {
57 tk = (StubToolkit)Toolkit.getToolkit();//This step is not needed (Just to make sure StubToolkit is loaded into VM)
58 slider = new Slider();
59 }
60
61 protected void startApp(Parent root) {
62 scene = new Scene(root,800,600);
63 stage = new Stage();
64 stage.setScene(scene);
65 stage.show();
66 tk.firePulse();
67 }
68 @Test public void testSettingMinorTickCountViaCSS() {
69 StackPane pane = new StackPane();
70 pane.getChildren().add(slider);
71 startApp(pane);
72
73 ParsedValue pv = new CssParser().parseExpr("-fx-minor-tick-count","2");
74 Object val = pv.convert(null);
75 try {
76 ((StyleableProperty)slider.minorTickCountProperty()).applyStyle(null, val);
77 assertEquals(2, slider.getMinorTickCount(), 0.);
78 } catch (Exception e) {
79 Assert.fail(e.toString());
80 }
81 }
82
83 @Test public void testSettingTickLabelFormatter() {
84 StackPane pane = new StackPane();
85 pane.getChildren().add(slider);
86 slider.setShowTickLabels(true);
87 slider.setShowTickMarks(true);
88 slider.setLabelFormatter(new StringConverter<Double>() {
89 @Override public String toString(Double t) {
90 return "Ok.";
91 }
92 @Override public Double fromString(String string) {
93 return 10.0;
|