functional/ControlsTests/src/javafx/scene/control/test/utils/ComponentsFactory.java

Print this page




  48  * has predefined size. can be used for cases, where screenshots are made.
  49  *
  50  * MultipleIndexFormComponent - can be used in tests, where you should provide
  51  * list of indices. (removeAll, selectAll functionality testing).
  52  */
  53 public class ComponentsFactory {
  54 
  55     public static final String CONTENT_RECTANGLE_ID = "CONTENT_RECTANGLE_ID";
  56     public static final String CONTENT_RECTANGLE_ID_PREFIX = "CONTENT_RECTANGLE_";
  57     public static final String FORM_BUTTON_ID = "FORM_BUTTON_ID";
  58     public static final String FORM_CLICK_TEXT_FIELD_ID = "FORM_CLICK_TEXT_FIELD_ID";
  59     public static final String FORM_SCROLLBAR_ID = "FORM_SCROLLBAR_ID";
  60     public static final String FORM_SCROLL_TEXT_FIELD_ID = "FORM_SCROLL_TEXT_FIELD_ID";
  61     public static final String FORM_TEXT_AREA_ID = "FORM_TEXT_AREA_ID";
  62     public static final String ID_SUFFIX = "_ID";
  63 
  64     public static VBox createFormComponent() {
  65         VBox vb = new VBox();
  66 
  67         HBox hb1 = new HBox();
  68         Button button = ButtonBuilder.create().id(FORM_BUTTON_ID).text("Press me").build();
  69         final TextField tf1 = TextFieldBuilder.create().id(FORM_CLICK_TEXT_FIELD_ID).prefWidth(50).text("0").build();



  70         button.setOnAction((ActionEvent t) -> {
  71             tf1.setText(String.valueOf(Integer.parseInt(tf1.getText()) + 1));
  72         });
  73         hb1.getChildren().addAll(button, tf1);
  74 
  75         HBox hb2 = new HBox();
  76         ScrollBar sb = new ScrollBar();
  77         sb.setMax(10);
  78         sb.setId(FORM_SCROLLBAR_ID);
  79         final TextField tf2 = TextFieldBuilder.create().id(FORM_SCROLL_TEXT_FIELD_ID).prefWidth(50).text("0").build();


  80         sb.addEventHandler(ScrollEvent.ANY, (ScrollEvent t) -> {
  81             tf2.setText(String.valueOf(Integer.parseInt(tf2.getText()) + 1));
  82         });
  83         hb2.getChildren().addAll(sb, tf2);
  84 
  85         TextArea ta = TextAreaBuilder.create().minHeight(50).prefHeight(100).prefWidth(50).id(FORM_TEXT_AREA_ID).build();




  86         for (int i = 0; i < 15; i++) {
  87             ta.appendText("text" + i + "\n");
  88         }
  89 
  90         vb.getChildren().addAll(hb1, hb2, ta);
  91         vb.setStyle("-fx-border-color: blue;");
  92         return vb;
  93     }
  94 
  95     public static Group createCustomContent(int height, int width) {
  96         Group res = new Group();
  97 
  98         Rectangle r = new Rectangle();
  99         r.setStroke(Color.BLACK);
 100         r.setStyle("-fx-border-color: GREEN;");
 101 
 102         res.getChildren().add(r);
 103 
 104         for (int i = 10; i < height; i += 10) {
 105             Line line1 = new Line(0, i, i - 5, i);




  48  * has predefined size. can be used for cases, where screenshots are made.
  49  *
  50  * MultipleIndexFormComponent - can be used in tests, where you should provide
  51  * list of indices. (removeAll, selectAll functionality testing).
  52  */
  53 public class ComponentsFactory {
  54 
  55     public static final String CONTENT_RECTANGLE_ID = "CONTENT_RECTANGLE_ID";
  56     public static final String CONTENT_RECTANGLE_ID_PREFIX = "CONTENT_RECTANGLE_";
  57     public static final String FORM_BUTTON_ID = "FORM_BUTTON_ID";
  58     public static final String FORM_CLICK_TEXT_FIELD_ID = "FORM_CLICK_TEXT_FIELD_ID";
  59     public static final String FORM_SCROLLBAR_ID = "FORM_SCROLLBAR_ID";
  60     public static final String FORM_SCROLL_TEXT_FIELD_ID = "FORM_SCROLL_TEXT_FIELD_ID";
  61     public static final String FORM_TEXT_AREA_ID = "FORM_TEXT_AREA_ID";
  62     public static final String ID_SUFFIX = "_ID";
  63 
  64     public static VBox createFormComponent() {
  65         VBox vb = new VBox();
  66 
  67         HBox hb1 = new HBox();
  68         Button button = new Button("Press me");
  69         button.setId(FORM_BUTTON_ID);
  70         final TextField tf1 = new TextField("0");
  71         tf1.setId(FORM_CLICK_TEXT_FIELD_ID);
  72         tf1.setPrefWidth(50);
  73         button.setOnAction((ActionEvent t) -> {
  74             tf1.setText(String.valueOf(Integer.parseInt(tf1.getText()) + 1));
  75         });
  76         hb1.getChildren().addAll(button, tf1);
  77 
  78         HBox hb2 = new HBox();
  79         ScrollBar sb = new ScrollBar();
  80         sb.setMax(10);
  81         sb.setId(FORM_SCROLLBAR_ID);
  82         final TextField tf2 = new TextField("0");
  83         tf2.setId(FORM_SCROLL_TEXT_FIELD_ID);
  84         tf2.setPrefWidth(50);
  85         sb.addEventHandler(ScrollEvent.ANY, (ScrollEvent t) -> {
  86             tf2.setText(String.valueOf(Integer.parseInt(tf2.getText()) + 1));
  87         });
  88         hb2.getChildren().addAll(sb, tf2);
  89 
  90         TextArea ta = new TextArea();
  91         ta.setMinHeight(50);
  92         ta.setPrefHeight(100);
  93         ta.setPrefWidth(50);
  94         ta.setId(FORM_TEXT_AREA_ID);
  95         for (int i = 0; i < 15; i++) {
  96             ta.appendText("text" + i + "\n");
  97         }
  98 
  99         vb.getChildren().addAll(hb1, hb2, ta);
 100         vb.setStyle("-fx-border-color: blue;");
 101         return vb;
 102     }
 103 
 104     public static Group createCustomContent(int height, int width) {
 105         Group res = new Group();
 106 
 107         Rectangle r = new Rectangle();
 108         r.setStroke(Color.BLACK);
 109         r.setStyle("-fx-border-color: GREEN;");
 110 
 111         res.getChildren().add(r);
 112 
 113         for (int i = 10; i < height; i += 10) {
 114             Line line1 = new Line(0, i, i - 5, i);