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