functional/ControlsTests/src/javafx/factory/ControlsFactory.java

Print this page




  29 
  30 import com.sun.javafx.collections.ObservableListWrapper;
  31 import java.lang.reflect.Constructor;
  32 import java.lang.reflect.Method;
  33 import java.time.LocalDate;
  34 import java.time.Month;
  35 import java.util.Arrays;
  36 import java.util.EnumSet;
  37 import java.util.Set;
  38 import javafx.beans.property.SimpleObjectProperty;
  39 import javafx.beans.property.SimpleStringProperty;
  40 import javafx.beans.property.StringProperty;
  41 import javafx.beans.value.ObservableValue;
  42 import javafx.collections.FXCollections;
  43 import javafx.collections.ObservableList;
  44 import javafx.geometry.HPos;
  45 import javafx.geometry.Rectangle2D;
  46 import javafx.scene.Node;
  47 import javafx.scene.control.Accordion;
  48 import javafx.scene.control.Button;
  49 import javafx.scene.control.ButtonBuilder;
  50 import javafx.scene.control.CheckBox;
  51 import javafx.scene.control.CheckBoxBuilder;
  52 import javafx.scene.control.ChoiceBox;
  53 import javafx.scene.control.ColorPicker;
  54 import javafx.scene.control.ComboBox;
  55 import javafx.scene.control.Control;
  56 import javafx.scene.control.DatePicker;
  57 import javafx.scene.control.Hyperlink;
  58 import javafx.scene.control.HyperlinkBuilder;
  59 import javafx.scene.control.Label;
  60 import javafx.scene.control.LabelBuilder;
  61 import javafx.scene.control.ListView;
  62 import javafx.scene.control.Menu;
  63 import javafx.scene.control.MenuBar;
  64 import javafx.scene.control.MenuItem;
  65 import javafx.scene.control.Pagination;
  66 import javafx.scene.control.PasswordField;
  67 import javafx.scene.control.PasswordFieldBuilder;
  68 import javafx.scene.control.ProgressBar;
  69 import javafx.scene.control.ProgressBarBuilder;
  70 import javafx.scene.control.ProgressIndicator;
  71 import javafx.scene.control.ProgressIndicatorBuilder;
  72 import javafx.scene.control.RadioButton;
  73 import javafx.scene.control.RadioButtonBuilder;
  74 import javafx.scene.control.ScrollBar;
  75 import javafx.scene.control.ScrollBarBuilder;
  76 import javafx.scene.control.ScrollPane;
  77 import javafx.scene.control.Separator;
  78 import javafx.scene.control.SeparatorBuilder;
  79 import javafx.scene.control.Slider;
  80 import javafx.scene.control.SliderBuilder;
  81 import javafx.scene.control.SplitMenuButton;
  82 import javafx.scene.control.SplitMenuButtonBuilder;
  83 import javafx.scene.control.SplitPane;
  84 import javafx.scene.control.SplitPaneBuilder;
  85 import javafx.scene.control.Tab;
  86 import javafx.scene.control.TabPane;
  87 import javafx.scene.control.TableColumn;
  88 import javafx.scene.control.TableColumn.CellDataFeatures;
  89 import javafx.scene.control.TableView;
  90 import javafx.scene.control.TextArea;
  91 import javafx.scene.control.TextAreaBuilder;
  92 import javafx.scene.control.TextField;
  93 import javafx.scene.control.TextFieldBuilder;
  94 import javafx.scene.control.TitledPane;
  95 import javafx.scene.control.ToggleButton;
  96 import javafx.scene.control.ToggleButtonBuilder;
  97 import javafx.scene.control.ToolBar;
  98 import javafx.scene.control.TreeItem;
  99 import javafx.scene.control.TreeTableColumn;
 100 import javafx.scene.control.TreeTableView;
 101 import javafx.scene.control.TreeView;
 102 import javafx.scene.image.Image;
 103 import javafx.scene.image.ImageView;
 104 import javafx.scene.layout.HBox;
 105 import javafx.scene.layout.StackPaneBuilder;
 106 import javafx.scene.layout.VBox;
 107 import javafx.scene.paint.Color;
 108 import javafx.scene.shape.Circle;
 109 import javafx.scene.shape.Rectangle;
 110 import javafx.scene.text.TextAlignment;
 111 import javafx.util.Callback;
 112 
 113 public enum ControlsFactory implements NodeFactory {
 114 
 115     Buttons(new ControlFactory() {
 116         public Control createControl() {
 117             return ButtonBuilder.create().text("Button the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).graphic(new Rectangle(10, 10, Color.RED)).build();



 118         }
 119 
 120         public Class getControlClass() {
 121             return Button.class;
 122         }
 123     }),
 124     ChoiceBoxes(new ControlFactory() {
 125         public Control createControl() {
 126             return new ChoiceBox() {
 127                 {
 128                     getItems().addAll(Arrays.asList("one", "two", "three"));
 129                     setFocusTraversable(false);
 130                     getSelectionModel().select(0);
 131                 }
 132             };
 133         }
 134 
 135         public Class getControlClass() {
 136             return ChoiceBox.class;
 137         }


 166             ps.maxPageIndicatorCountProperty().set(3);
 167             return ps;
 168         }
 169 
 170         public Class getControlClass() {
 171             return Pagination.class;
 172         }
 173     }),
 174     ColorPickers(new ControlFactory() {
 175         public Control createControl() {
 176             ColorPicker cp = new ColorPicker();
 177             return cp;
 178         }
 179 
 180         public Class getControlClass() {
 181             return ColorPicker.class;
 182         }
 183     }),
 184     CheckBoxes(new ControlFactory() {
 185         public Control createControl() {
 186             return CheckBoxBuilder.create().text("Check box the first line" + "\nthe sec long line" + "\nthe third line").graphic(new Rectangle(20, 20, Color.web("lightblue"))).focusTraversable(false).build();



 187         }
 188 
 189         public Class getControlClass() {
 190             return CheckBox.class;
 191         }
 192     }),
 193     RadioButtons(new ControlFactory() {
 194         public Control createControl() {
 195             return RadioButtonBuilder.create().text("Radio the first line" + "\nthe sec long line" + "\nthe third line").graphic(new Rectangle(20, 20, Color.web("lightblue"))).focusTraversable(false).textAlignment(TextAlignment.RIGHT).build();




 196         }
 197 
 198         public Class getControlClass() {
 199             return RadioButton.class;
 200         }
 201     }),
 202     TextFields(new ControlFactory() {
 203         public Control createControl() {
 204             return TextFieldBuilder.create().text("Text box the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).build();


 205         }
 206 
 207         public Class getControlClass() {
 208             return TextField.class;
 209         }
 210     }),
 211     TextAreas(new ControlFactory() {
 212         public Control createControl() {
 213             return TextAreaBuilder.create().maxWidth(100).maxHeight(50).text("Text area the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).build();



 214         }
 215 
 216         public Class getControlClass() {
 217             return TextArea.class;
 218         }
 219     }),
 220     PasswordFields(new ControlFactory() {
 221         public Control createControl() {
 222             return PasswordFieldBuilder.create().promptText("Password box the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).build();



 223         }
 224 
 225         public Class getControlClass() {
 226             return PasswordField.class;
 227         }
 228     }),
 229     Sliders(new ControlFactory() {
 230         public Control createControl() {
 231             return SliderBuilder.create().min(0).max(100).value(20).focusTraversable(false).build();





 232         }
 233 
 234         public Class getControlClass() {
 235             return Slider.class;
 236         }
 237     }),
 238     Labels(new ControlFactory() {
 239         public Control createControl() {
 240             return LabelBuilder.create().text("Label the first line" + "\nthe sec longlong line" + "\nthe third line").focusTraversable(false).graphic(new Rectangle(20, 20, Color.web("lightblue"))).build();



 241         }
 242 
 243         public Class getControlClass() {
 244             return Label.class;
 245         }
 246     }),
 247     Hyperlinks(new ControlFactory() {
 248         public Control createControl() {
 249             return HyperlinkBuilder.create().text("Hyperlink the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).graphic(new Circle(10, Color.BLUE)).build();



 250         }
 251 
 252         public Class getControlClass() {
 253             return Hyperlink.class;
 254         }
 255     }),
 256     ImageView(new ControlFactory() {
 257         public Node createControl() {
 258             return new ImageView(new Image(ControlsFactory.class.getResourceAsStream("big_tiger_e0.gif")));
 259         }
 260 
 261         public Class getControlClass() {
 262             return ImageView.class;
 263         }
 264     }),
 265     MediaView(new ControlFactory() {
 266         public Node createControl() {
 267 //    Lines are disabled due to impossibleness of stream using.
 268 //    String path = System.getProperty("user.dir");
 269 //    while (path.indexOf("\\") != -1) {


 282                 Method setViewport = mediaViewCl.getDeclaredMethod("setViewport", Rectangle2D.class);
 283                 setViewport.invoke(node, new Rectangle2D(0, 0, 100, 100));
 284                 node.setStyle("-fx-stroke: black;");
 285             } catch (Exception ignored) {
 286                 ignored.printStackTrace();
 287             }
 288             return node;
 289         }
 290 
 291         public Class getControlClass() {
 292             Class controlClass = null;
 293             try {
 294                 controlClass = Class.forName("javafx.scene.media.MediaView");
 295             } catch (Exception ignored) {
 296             }
 297             return controlClass;
 298         }
 299     }),
 300     Separators(new ControlFactory() {
 301         public Control createControl() {
 302             Separator sep = SeparatorBuilder.create().halignment(HPos.CENTER).build();

 303             sep.setPrefWidth(80);
 304             return sep;
 305         }
 306 
 307         public Class getControlClass() {
 308             return Separator.class;
 309         }
 310     }),
 311     ScrollBars(new ControlFactory() {
 312         public Control createControl() {
 313             return ScrollBarBuilder.create().value(45).min(0).max(100).focusTraversable(false).build();





 314         }
 315 
 316         public Class getControlClass() {
 317             return ScrollBar.class;
 318         }
 319     }),
 320     ScrollPanes(new ControlFactory() {
 321         public Node createControl() {
 322             ScrollPane pane = new ScrollPane();
 323             HBox hbox = new HBox(30);
 324             VBox vbox1 = new VBox(10);
 325             vbox1.getChildren().addAll(new Label("one"), new Button("two"), new CheckBox("three"), new RadioButton("four"), new Label("five"));
 326             VBox vbox2 = new VBox(10);
 327             vbox2.getChildren().addAll(new Label("one"), new Button("two"), new CheckBox("three"), new RadioButton("four"), new Label("five"));
 328             hbox.getChildren().addAll(vbox1, vbox2);
 329             pane.setContent(hbox);
 330             pane.setFocusTraversable(false);
 331             return pane;
 332         }
 333 
 334         public Class getControlClass() {
 335             return ScrollPane.class;
 336         }
 337     }),
 338     ProgressIndicators(new ControlFactory() {
 339         public Node createControl() {
 340             return ProgressIndicatorBuilder.create().progress(0.85).focusTraversable(false).build();


 341         }
 342 
 343         public Class getControlClass() {
 344             return ProgressIndicator.class;
 345         }
 346     }),
 347     ProgressBars(new ControlFactory() {
 348         public Node createControl() {
 349             return ProgressBarBuilder.create().progress(0.25).focusTraversable(false).build();


 350         }
 351 
 352         public Class getControlClass() {
 353             return ProgressBar.class;
 354         }
 355     }),
 356     ListViews(new ControlFactory() {
 357         public Node createControl() {
 358             ListView list = new ListView();


 359             ObservableListWrapper<String> items = new ObservableListWrapper<String>(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six", "long line long line long line long line"));
 360             list.setItems(items);
 361             list.setPrefWidth(100);
 362             list.setPrefHeight(100);
 363             list.setFocusTraversable(false);
 364             return list;
 365         }
 366 
 367         public Class getControlClass() {
 368             return ListView.class;
 369         }
 370     }),
 371     PressedToggleButtons(new ControlFactory() {
 372         public Control createControl() {
 373             return ToggleButtonBuilder.create().selected(true).text("Button the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).graphic(new Rectangle(10, 10, Color.RED)).build();




 374         }
 375 
 376         public Class getControlClass() {
 377             return ToggleButton.class;
 378         }
 379     }),
 380     UnPressedToggleButtons(new ControlFactory() {
 381         public Control createControl() {
 382             return ToggleButtonBuilder.create().selected(false).text("Button the first line" + "\nthe sec long line" + "\nthe third line").focusTraversable(false).graphic(new Rectangle(10, 10, Color.RED)).build();




 383         }
 384 
 385         public Class getControlClass() {
 386             return ToggleButton.class;
 387         }
 388     }),
 389     Toolbars(new ControlFactory() {
 390         public Node createControl() {
 391             ToolBar toolbar = new ToolBar();
 392             toolbar.getItems().addAll(new Button("One"), new Button("Two"), new Separator(), SplitMenuButtonBuilder.create().text("three").build());


 393             toolbar.setFocusTraversable(false);
 394             return toolbar;
 395         }
 396 
 397         public Class getControlClass() {
 398             return ToolBar.class;
 399         }
 400     }),
 401     Menubars(new ControlFactory() {
 402         public Node createControl() {
 403             MenuBar menubar = new MenuBar();
 404             menubar.getMenus().addAll(new Menu("File"));
 405             menubar.setFocusTraversable(false);
 406             return menubar;
 407         }
 408 
 409         public Class getControlClass() {
 410             return MenuBar.class;
 411         }
 412     }),
 413     SplitMenuButtons(new ControlFactory() {
 414         public Node createControl() {
 415             SplitMenuButton smb = SplitMenuButtonBuilder.create()
 416                     .text("Split box the first line" + "\nthe sec long line" + "\nthe third line")
 417                     .items(new MenuItem("Split box the first line" + "\nthe sec long line" + "\nthe third line",
 418                     new Rectangle(10, 10, Color.BLUE)))
 419                     .graphic(new Rectangle(10, 10, Color.RED))
 420                     .build();
 421             smb.setMinWidth(100);
 422             smb.setFocusTraversable(false);
 423             return smb;
 424         }
 425 
 426         public Class getControlClass() {
 427             return SplitMenuButton.class;
 428         }
 429     }),
 430     TabPanes(new ControlFactory() {
 431         public Node createControl() {
 432             TabPane pane = new TabPane();
 433             Tab tab = new Tab();
 434             tab.setText("tab 1");
 435             HBox content1 = new HBox(10);
 436             content1.getChildren().addAll(new Button("Button"), new Label("Label"), new Rectangle(40, 40, Color.TOMATO));
 437             tab.setContent(content1);
 438             Tab tab2 = new Tab();
 439             tab2.setText("tab 2");
 440             tab2.setContent(new Circle(40, Color.RED));


 474                 @Override
 475                 public ObservableValue<Node> call(final CellDataFeatures<Person, Node> p) {
 476                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 477                     text.setValue(new Label(p.getValue().getFirstName()));
 478                     return text;
 479                 }
 480             });
 481             TableColumn<Person, Node> column2 = new TableColumn<Person, Node>("Last Name");
 482             column2.setCellValueFactory(new Callback<CellDataFeatures<Person, Node>, ObservableValue<Node>>() {
 483                 @Override
 484                 public ObservableValue<Node> call(final CellDataFeatures<Person, Node> p) {
 485                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 486                     text.setValue(new Label(p.getValue().getLastName()));
 487                     return text;
 488                 }
 489             });
 490             TableView table = new TableView(items);
 491             table.getColumns().setAll(column1, column2);
 492             table.setPrefHeight(100);
 493             table.setPrefWidth(100);
 494             table.setMinHeight(Control.USE_PREF_SIZE);
 495             table.setFocusTraversable(false);
 496             return table;
 497         }
 498 
 499         public Class getControlClass() {
 500             return TableView.class;
 501         }
 502     }),
 503     TreeTableViews(new ControlFactory() {
 504         public Node createControl() {
 505             ObservableList<TreeItem> items = FXCollections.observableArrayList();
 506             for (int i = 0; i < 10; i++) {
 507                 items.add(new TreeItem(new Person("name " + i, "surname " + i)));
 508             }
 509             TreeTableColumn<Person, Node> column1 = new TreeTableColumn<Person, Node>("First Name");
 510             column1.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, Node>, ObservableValue<Node>>() {
 511                 @Override
 512                 public ObservableValue<Node> call(final TreeTableColumn.CellDataFeatures<Person, Node> p) {
 513                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 514                     text.setValue(new Label(p.getValue().getValue().getFirstName()));
 515                     return text;
 516                 }
 517             });
 518             TreeTableColumn<Person, Node> column2 = new TreeTableColumn<Person, Node>("Last Name");
 519             column2.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, Node>, ObservableValue<Node>>() {
 520                 @Override
 521                 public ObservableValue<Node> call(final TreeTableColumn.CellDataFeatures<Person, Node> p) {
 522                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 523                     text.setValue(new Label(p.getValue().getValue().getLastName()));
 524                     return text;
 525                 }
 526             });
 527             TreeTableView treeTable = new TreeTableView();
 528             treeTable.setRoot(new TreeItem(new Person("root", "root")));
 529             treeTable.getRoot().getChildren().addAll(items);
 530             treeTable.getRoot().setExpanded(true);
 531             treeTable.getColumns().setAll(column1, column2);
 532             treeTable.setPrefHeight(100);
 533             treeTable.setPrefWidth(100);
 534             treeTable.setMinHeight(Control.USE_PREF_SIZE);
 535             treeTable.setFocusTraversable(false);
 536             return treeTable;
 537         }
 538 
 539         public Class getControlClass() {
 540             return TreeTableView.class;
 541         }
 542     }),
 543     TreeViews(new ControlFactory() {
 544         public Node createControl() {
 545             TreeItem<String> root = new TreeItem<String>("ROOT", new Rectangle(20, 20, Color.CHOCOLATE));
 546             root.setExpanded(true);
 547             TreeItem<String> firstBrunch = new TreeItem<String>("brunch 1");
 548             firstBrunch.setExpanded(true);
 549             firstBrunch.getChildren().addAll(new TreeItem<String>("first item"), new TreeItem<String>("second item", new Rectangle(20, 20, Color.DARKGREY)));
 550             root.getChildren().addAll(firstBrunch);
 551             TreeItem<String> secondBrunch = new TreeItem<String>("brunch 2");
 552             secondBrunch.getChildren().addAll(new TreeItem<String>("first item"), new TreeItem<String>("second item", new Rectangle(20, 20, Color.DARKGREY)));
 553             root.getChildren().addAll(secondBrunch);
 554             TreeView tree = new TreeView(root);


 567             pane1.setGraphic(new Label("title 1\nLong text long text"));
 568             pane1.setContent(new Rectangle(100, 40, Color.SKYBLUE));
 569             TitledPane pane2 = new TitledPane();
 570             pane2.setGraphic(new Label("title 2\nLong text long text"));
 571             pane2.setContent(new Rectangle(100, 40, Color.BLUEVIOLET));
 572             Accordion acc = new Accordion();
 573             acc.getPanes().addAll(pane1, pane2);
 574             acc.setExpandedPane(pane2);
 575             pane2.setAnimated(false);
 576             acc.setFocusTraversable(false);
 577             acc.setMinWidth(100);
 578             return acc;
 579         }
 580 
 581         public Class getControlClass() {
 582             return Accordion.class;
 583         }
 584     }),
 585     SplitPanes(new ControlFactory() {
 586         public Node createControl() {
 587             SplitPane pane = SplitPaneBuilder.create().items(
 588                     StackPaneBuilder.create().children(new Rectangle(40, 40, Color.WHITESMOKE)).build(),
 589                     StackPaneBuilder.create().children(new Rectangle(40, 40, Color.BLUE)).build(),
 590                     StackPaneBuilder.create().children(new Rectangle(40, 40, Color.RED)).build()).prefWidth(150).prefHeight(150).build();

 591             pane.setMinWidth(100);
 592             pane.setDividerPositions(0.33, 0.67);
 593             pane.setFocusTraversable(false);
 594             return pane;
 595         }
 596 
 597         public Class getControlClass() {
 598             return SplitPane.class;
 599         }
 600     }),
 601     DatePickers(new ControlFactory() {
 602         public Node createControl() {
 603             final DatePicker datePicker = new DatePicker();
 604             datePicker.setFocusTraversable(false);
 605             datePicker.setValue(LocalDate.of(2042, Month.MAY, 9));
 606             return datePicker;
 607         }
 608 
 609         public Class getControlClass() {
 610             return DatePicker.class;




  29 
  30 import com.sun.javafx.collections.ObservableListWrapper;
  31 import java.lang.reflect.Constructor;
  32 import java.lang.reflect.Method;
  33 import java.time.LocalDate;
  34 import java.time.Month;
  35 import java.util.Arrays;
  36 import java.util.EnumSet;
  37 import java.util.Set;
  38 import javafx.beans.property.SimpleObjectProperty;
  39 import javafx.beans.property.SimpleStringProperty;
  40 import javafx.beans.property.StringProperty;
  41 import javafx.beans.value.ObservableValue;
  42 import javafx.collections.FXCollections;
  43 import javafx.collections.ObservableList;
  44 import javafx.geometry.HPos;
  45 import javafx.geometry.Rectangle2D;
  46 import javafx.scene.Node;
  47 import javafx.scene.control.Accordion;
  48 import javafx.scene.control.Button;

  49 import javafx.scene.control.CheckBox;

  50 import javafx.scene.control.ChoiceBox;
  51 import javafx.scene.control.ColorPicker;
  52 import javafx.scene.control.ComboBox;
  53 import javafx.scene.control.Control;
  54 import javafx.scene.control.DatePicker;
  55 import javafx.scene.control.Hyperlink;

  56 import javafx.scene.control.Label;

  57 import javafx.scene.control.ListView;
  58 import javafx.scene.control.Menu;
  59 import javafx.scene.control.MenuBar;
  60 import javafx.scene.control.MenuItem;
  61 import javafx.scene.control.Pagination;
  62 import javafx.scene.control.PasswordField;

  63 import javafx.scene.control.ProgressBar;

  64 import javafx.scene.control.ProgressIndicator;

  65 import javafx.scene.control.RadioButton;

  66 import javafx.scene.control.ScrollBar;

  67 import javafx.scene.control.ScrollPane;
  68 import javafx.scene.control.Separator;

  69 import javafx.scene.control.Slider;

  70 import javafx.scene.control.SplitMenuButton;

  71 import javafx.scene.control.SplitPane;

  72 import javafx.scene.control.Tab;
  73 import javafx.scene.control.TabPane;
  74 import javafx.scene.control.TableColumn;
  75 import javafx.scene.control.TableColumn.CellDataFeatures;
  76 import javafx.scene.control.TableView;
  77 import javafx.scene.control.TextArea;

  78 import javafx.scene.control.TextField;

  79 import javafx.scene.control.TitledPane;
  80 import javafx.scene.control.ToggleButton;

  81 import javafx.scene.control.ToolBar;
  82 import javafx.scene.control.TreeItem;
  83 import javafx.scene.control.TreeTableColumn;
  84 import javafx.scene.control.TreeTableView;
  85 import javafx.scene.control.TreeView;
  86 import javafx.scene.image.Image;
  87 import javafx.scene.image.ImageView;
  88 import javafx.scene.layout.HBox;
  89 import javafx.scene.layout.StackPane;
  90 import javafx.scene.layout.VBox;
  91 import javafx.scene.paint.Color;
  92 import javafx.scene.shape.Circle;
  93 import javafx.scene.shape.Rectangle;
  94 import javafx.scene.text.TextAlignment;
  95 import javafx.util.Callback;
  96 
  97 public enum ControlsFactory implements NodeFactory {
  98 
  99     Buttons(new ControlFactory() {
 100         public Control createControl() {
 101             Button b = new Button("Button the first line" + "\nthe sec long line" + "\nthe third line");
 102             b.setFocusTraversable(false);
 103             b.setGraphic(new Rectangle(10, 10, Color.RED));
 104             return b;
 105         }
 106 
 107         public Class getControlClass() {
 108             return Button.class;
 109         }
 110     }),
 111     ChoiceBoxes(new ControlFactory() {
 112         public Control createControl() {
 113             return new ChoiceBox() {
 114                 {
 115                     getItems().addAll(Arrays.asList("one", "two", "three"));
 116                     setFocusTraversable(false);
 117                     getSelectionModel().select(0);
 118                 }
 119             };
 120         }
 121 
 122         public Class getControlClass() {
 123             return ChoiceBox.class;
 124         }


 153             ps.maxPageIndicatorCountProperty().set(3);
 154             return ps;
 155         }
 156 
 157         public Class getControlClass() {
 158             return Pagination.class;
 159         }
 160     }),
 161     ColorPickers(new ControlFactory() {
 162         public Control createControl() {
 163             ColorPicker cp = new ColorPicker();
 164             return cp;
 165         }
 166 
 167         public Class getControlClass() {
 168             return ColorPicker.class;
 169         }
 170     }),
 171     CheckBoxes(new ControlFactory() {
 172         public Control createControl() {
 173             CheckBox cb = new CheckBox("Check box the first line" + "\nthe sec long line" + "\nthe third line");
 174             cb.setFocusTraversable(false);
 175             cb.setGraphic(new Rectangle(20, 20, Color.web("lightblue")));
 176             return cb;
 177         }
 178 
 179         public Class getControlClass() {
 180             return CheckBox.class;
 181         }
 182     }),
 183     RadioButtons(new ControlFactory() {
 184         public Control createControl() {
 185             RadioButton rb = new RadioButton("Radio the first line" + "\nthe sec long line" + "\nthe third line");
 186             rb.setFocusTraversable(false);
 187             rb.setGraphic(new Rectangle(20, 20, Color.web("lightblue")));
 188             rb.setTextAlignment(TextAlignment.RIGHT);
 189             return rb;
 190         }
 191 
 192         public Class getControlClass() {
 193             return RadioButton.class;
 194         }
 195     }),
 196     TextFields(new ControlFactory() {
 197         public Control createControl() {
 198             TextField tf = new TextField("Text box the first line" + "\nthe sec long line" + "\nthe third line");
 199             tf.setFocusTraversable(false);
 200             return tf;
 201         }
 202 
 203         public Class getControlClass() {
 204             return TextField.class;
 205         }
 206     }),
 207     TextAreas(new ControlFactory() {
 208         public Control createControl() {
 209             TextArea ta = new TextArea("Text area the first line" + "\nthe sec long line" + "\nthe third line");
 210             ta.setFocusTraversable(false);
 211             ta.setMaxSize(100, 50);
 212             return ta;
 213         }
 214 
 215         public Class getControlClass() {
 216             return TextArea.class;
 217         }
 218     }),
 219     PasswordFields(new ControlFactory() {
 220         public Control createControl() {
 221             PasswordField pf = new PasswordField();
 222             pf.setPromptText("Password box the first line" + "\nthe sec long line" + "\nthe third line");
 223             pf.setFocusTraversable(false);
 224             return pf;
 225         }
 226 
 227         public Class getControlClass() {
 228             return PasswordField.class;
 229         }
 230     }),
 231     Sliders(new ControlFactory() {
 232         public Control createControl() {
 233             Slider s = new Slider();
 234             s.setMin(0);
 235             s.setMax(100);
 236             s.setValue(20);
 237             s.setFocusTraversable(false);
 238             return s;
 239         }
 240 
 241         public Class getControlClass() {
 242             return Slider.class;
 243         }
 244     }),
 245     Labels(new ControlFactory() {
 246         public Control createControl() {
 247             Label l = new Label("Label the first line" + "\nthe sec longlong line" + "\nthe third line");
 248             l.setFocusTraversable(false);
 249             l.setGraphic(new Rectangle(20, 20, Color.web("lightblue")));
 250             return l;
 251         }
 252 
 253         public Class getControlClass() {
 254             return Label.class;
 255         }
 256     }),
 257     Hyperlinks(new ControlFactory() {
 258         public Control createControl() {
 259             Hyperlink hl = new Hyperlink("Hyperlink the first line" + "\nthe sec long line" + "\nthe third line");
 260             hl.setFocusTraversable(false);
 261             hl.setGraphic(new Circle(10, Color.BLUE));
 262             return hl;
 263         }
 264 
 265         public Class getControlClass() {
 266             return Hyperlink.class;
 267         }
 268     }),
 269     ImageView(new ControlFactory() {
 270         public Node createControl() {
 271             return new ImageView(new Image(ControlsFactory.class.getResourceAsStream("big_tiger_e0.gif")));
 272         }
 273 
 274         public Class getControlClass() {
 275             return ImageView.class;
 276         }
 277     }),
 278     MediaView(new ControlFactory() {
 279         public Node createControl() {
 280 //    Lines are disabled due to impossibleness of stream using.
 281 //    String path = System.getProperty("user.dir");
 282 //    while (path.indexOf("\\") != -1) {


 295                 Method setViewport = mediaViewCl.getDeclaredMethod("setViewport", Rectangle2D.class);
 296                 setViewport.invoke(node, new Rectangle2D(0, 0, 100, 100));
 297                 node.setStyle("-fx-stroke: black;");
 298             } catch (Exception ignored) {
 299                 ignored.printStackTrace();
 300             }
 301             return node;
 302         }
 303 
 304         public Class getControlClass() {
 305             Class controlClass = null;
 306             try {
 307                 controlClass = Class.forName("javafx.scene.media.MediaView");
 308             } catch (Exception ignored) {
 309             }
 310             return controlClass;
 311         }
 312     }),
 313     Separators(new ControlFactory() {
 314         public Control createControl() {
 315             Separator sep = new Separator();
 316             sep.setHalignment(HPos.CENTER);
 317             sep.setPrefWidth(80);
 318             return sep;
 319         }
 320 
 321         public Class getControlClass() {
 322             return Separator.class;
 323         }
 324     }),
 325     ScrollBars(new ControlFactory() {
 326         public Control createControl() {
 327             ScrollBar sb = new ScrollBar();
 328             sb.setValue(45);
 329             sb.setMin(0);
 330             sb.setMax(100);
 331             sb.setFocusTraversable(false);
 332             return sb;
 333         }
 334 
 335         public Class getControlClass() {
 336             return ScrollBar.class;
 337         }
 338     }),
 339     ScrollPanes(new ControlFactory() {
 340         public Node createControl() {
 341             ScrollPane pane = new ScrollPane();
 342             HBox hbox = new HBox(30);
 343             VBox vbox1 = new VBox(10);
 344             vbox1.getChildren().addAll(new Label("one"), new Button("two"), new CheckBox("three"), new RadioButton("four"), new Label("five"));
 345             VBox vbox2 = new VBox(10);
 346             vbox2.getChildren().addAll(new Label("one"), new Button("two"), new CheckBox("three"), new RadioButton("four"), new Label("five"));
 347             hbox.getChildren().addAll(vbox1, vbox2);
 348             pane.setContent(hbox);
 349             pane.setFocusTraversable(false);
 350             return pane;
 351         }
 352 
 353         public Class getControlClass() {
 354             return ScrollPane.class;
 355         }
 356     }),
 357     ProgressIndicators(new ControlFactory() {
 358         public Node createControl() {
 359             ProgressIndicator pi = new ProgressIndicator(0.85);
 360             pi.setFocusTraversable(false);
 361             return pi;
 362         }
 363 
 364         public Class getControlClass() {
 365             return ProgressIndicator.class;
 366         }
 367     }),
 368     ProgressBars(new ControlFactory() {
 369         public Node createControl() {
 370             ProgressBar pb = new ProgressBar(0.25);
 371             pb.setFocusTraversable(false);
 372             return pb;
 373         }
 374 
 375         public Class getControlClass() {
 376             return ProgressBar.class;
 377         }
 378     }),
 379     ListViews(new ControlFactory() {
 380         public Node createControl() {
 381             ListView list = new ListView();
 382 
 383             // The following requires --add-exports javafx.base/com.sun.javafx.collections=ALL-UNNAMED
 384             ObservableListWrapper<String> items = new ObservableListWrapper<String>(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six", "long line long line long line long line"));
 385             list.setItems(items);
 386             list.setPrefWidth(100);
 387             list.setPrefHeight(100);
 388             list.setFocusTraversable(false);
 389             return list;
 390         }
 391 
 392         public Class getControlClass() {
 393             return ListView.class;
 394         }
 395     }),
 396     PressedToggleButtons(new ControlFactory() {
 397         public Control createControl() {
 398             ToggleButton tb = new ToggleButton("Button the first line" + "\nthe sec long line" + "\nthe third line");
 399             tb.setFocusTraversable(false);
 400             tb.setGraphic(new Rectangle(10, 10, Color.RED));
 401             tb.setSelected(true);
 402             return tb;
 403         }
 404 
 405         public Class getControlClass() {
 406             return ToggleButton.class;
 407         }
 408     }),
 409     UnPressedToggleButtons(new ControlFactory() {
 410         public Control createControl() {
 411             ToggleButton tb = new ToggleButton("Button the first line" + "\nthe sec long line" + "\nthe third line");
 412             tb.setFocusTraversable(false);
 413             tb.setGraphic(new Rectangle(10, 10, Color.RED));
 414             tb.setSelected(false);
 415             return tb;
 416         }
 417 
 418         public Class getControlClass() {
 419             return ToggleButton.class;
 420         }
 421     }),
 422     Toolbars(new ControlFactory() {
 423         public Node createControl() {
 424             ToolBar toolbar = new ToolBar();
 425             SplitMenuButton smb = new SplitMenuButton();
 426             smb.setText("three");
 427             toolbar.getItems().addAll(new Button("One"), new Button("Two"), new Separator(), smb);
 428             toolbar.setFocusTraversable(false);
 429             return toolbar;
 430         }
 431 
 432         public Class getControlClass() {
 433             return ToolBar.class;
 434         }
 435     }),
 436     Menubars(new ControlFactory() {
 437         public Node createControl() {
 438             MenuBar menubar = new MenuBar();
 439             menubar.getMenus().addAll(new Menu("File"));
 440             menubar.setFocusTraversable(false);
 441             return menubar;
 442         }
 443 
 444         public Class getControlClass() {
 445             return MenuBar.class;
 446         }
 447     }),
 448     SplitMenuButtons(new ControlFactory() {
 449         public Node createControl() {
 450             SplitMenuButton smb = new SplitMenuButton(new MenuItem("Split box the first line" + "\nthe sec long line" + "\nthe third line",
 451                     new Rectangle(10, 10, Color.BLUE)));
 452             smb.setText("Split box the first line" + "\nthe sec long line" + "\nthe third line");
 453             smb.setGraphic(new Rectangle(10, 10, Color.RED));


 454             smb.setMinWidth(100);
 455             smb.setFocusTraversable(false);
 456             return smb;
 457         }
 458 
 459         public Class getControlClass() {
 460             return SplitMenuButton.class;
 461         }
 462     }),
 463     TabPanes(new ControlFactory() {
 464         public Node createControl() {
 465             TabPane pane = new TabPane();
 466             Tab tab = new Tab();
 467             tab.setText("tab 1");
 468             HBox content1 = new HBox(10);
 469             content1.getChildren().addAll(new Button("Button"), new Label("Label"), new Rectangle(40, 40, Color.TOMATO));
 470             tab.setContent(content1);
 471             Tab tab2 = new Tab();
 472             tab2.setText("tab 2");
 473             tab2.setContent(new Circle(40, Color.RED));


 507                 @Override
 508                 public ObservableValue<Node> call(final CellDataFeatures<Person, Node> p) {
 509                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 510                     text.setValue(new Label(p.getValue().getFirstName()));
 511                     return text;
 512                 }
 513             });
 514             TableColumn<Person, Node> column2 = new TableColumn<Person, Node>("Last Name");
 515             column2.setCellValueFactory(new Callback<CellDataFeatures<Person, Node>, ObservableValue<Node>>() {
 516                 @Override
 517                 public ObservableValue<Node> call(final CellDataFeatures<Person, Node> p) {
 518                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 519                     text.setValue(new Label(p.getValue().getLastName()));
 520                     return text;
 521                 }
 522             });
 523             TableView table = new TableView(items);
 524             table.getColumns().setAll(column1, column2);
 525             table.setPrefHeight(100);
 526             table.setPrefWidth(100);

 527             table.setFocusTraversable(false);
 528             return table;
 529         }
 530 
 531         public Class getControlClass() {
 532             return TableView.class;
 533         }
 534     }),
 535     TreeTableViews(new ControlFactory() {
 536         public Node createControl() {
 537             ObservableList<TreeItem> items = FXCollections.observableArrayList();
 538             for (int i = 0; i < 10; i++) {
 539                 items.add(new TreeItem(new Person("name " + i, "surname " + i)));
 540             }
 541             TreeTableColumn<Person, Node> column1 = new TreeTableColumn<Person, Node>("First Name");
 542             column1.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, Node>, ObservableValue<Node>>() {
 543                 @Override
 544                 public ObservableValue<Node> call(final TreeTableColumn.CellDataFeatures<Person, Node> p) {
 545                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 546                     text.setValue(new Label(p.getValue().getValue().getFirstName()));
 547                     return text;
 548                 }
 549             });
 550             TreeTableColumn<Person, Node> column2 = new TreeTableColumn<Person, Node>("Last Name");
 551             column2.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, Node>, ObservableValue<Node>>() {
 552                 @Override
 553                 public ObservableValue<Node> call(final TreeTableColumn.CellDataFeatures<Person, Node> p) {
 554                     SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>();
 555                     text.setValue(new Label(p.getValue().getValue().getLastName()));
 556                     return text;
 557                 }
 558             });
 559             TreeTableView treeTable = new TreeTableView();
 560             treeTable.setRoot(new TreeItem(new Person("root", "root")));
 561             treeTable.getRoot().getChildren().addAll(items);
 562             treeTable.getRoot().setExpanded(true);
 563             treeTable.getColumns().setAll(column1, column2);
 564             treeTable.setPrefHeight(100);
 565             treeTable.setPrefWidth(100);

 566             treeTable.setFocusTraversable(false);
 567             return treeTable;
 568         }
 569 
 570         public Class getControlClass() {
 571             return TreeTableView.class;
 572         }
 573     }),
 574     TreeViews(new ControlFactory() {
 575         public Node createControl() {
 576             TreeItem<String> root = new TreeItem<String>("ROOT", new Rectangle(20, 20, Color.CHOCOLATE));
 577             root.setExpanded(true);
 578             TreeItem<String> firstBrunch = new TreeItem<String>("brunch 1");
 579             firstBrunch.setExpanded(true);
 580             firstBrunch.getChildren().addAll(new TreeItem<String>("first item"), new TreeItem<String>("second item", new Rectangle(20, 20, Color.DARKGREY)));
 581             root.getChildren().addAll(firstBrunch);
 582             TreeItem<String> secondBrunch = new TreeItem<String>("brunch 2");
 583             secondBrunch.getChildren().addAll(new TreeItem<String>("first item"), new TreeItem<String>("second item", new Rectangle(20, 20, Color.DARKGREY)));
 584             root.getChildren().addAll(secondBrunch);
 585             TreeView tree = new TreeView(root);


 598             pane1.setGraphic(new Label("title 1\nLong text long text"));
 599             pane1.setContent(new Rectangle(100, 40, Color.SKYBLUE));
 600             TitledPane pane2 = new TitledPane();
 601             pane2.setGraphic(new Label("title 2\nLong text long text"));
 602             pane2.setContent(new Rectangle(100, 40, Color.BLUEVIOLET));
 603             Accordion acc = new Accordion();
 604             acc.getPanes().addAll(pane1, pane2);
 605             acc.setExpandedPane(pane2);
 606             pane2.setAnimated(false);
 607             acc.setFocusTraversable(false);
 608             acc.setMinWidth(100);
 609             return acc;
 610         }
 611 
 612         public Class getControlClass() {
 613             return Accordion.class;
 614         }
 615     }),
 616     SplitPanes(new ControlFactory() {
 617         public Node createControl() {
 618             StackPane sp1 = new StackPane(new Rectangle(40, 40, Color.WHITESMOKE));
 619             StackPane sp2 = new StackPane(new Rectangle(40, 40, Color.BLUE));
 620             StackPane sp3 = new StackPane(new Rectangle(40, 40, Color.RED));
 621             SplitPane pane = new SplitPane(sp1, sp2, sp3);
 622             pane.setPrefSize(150, 150);
 623             pane.setMinWidth(100);
 624             pane.setDividerPositions(0.33, 0.67);
 625             pane.setFocusTraversable(false);
 626             return pane;
 627         }
 628 
 629         public Class getControlClass() {
 630             return SplitPane.class;
 631         }
 632     }),
 633     DatePickers(new ControlFactory() {
 634         public Node createControl() {
 635             final DatePicker datePicker = new DatePicker();
 636             datePicker.setFocusTraversable(false);
 637             datePicker.setValue(LocalDate.of(2042, Month.MAY, 9));
 638             return datePicker;
 639         }
 640 
 641         public Class getControlClass() {
 642             return DatePicker.class;