1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation. Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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 package javafx.scene.control.test.ScrollPane;
  26 
  27 import javafx.event.ActionEvent;
  28 import javafx.event.EventHandler;
  29 import javafx.scene.Group;
  30 import javafx.scene.Node;
  31 import javafx.scene.Scene;
  32 import javafx.scene.control.*;
  33 import javafx.scene.control.test.utils.*;
  34 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  35 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  36 import javafx.scene.control.test.utils.ptables.SpecialTablePropertiesProvider;
  37 import javafx.scene.layout.GridPane;
  38 import javafx.scene.layout.HBox;
  39 import javafx.scene.layout.Pane;
  40 import javafx.scene.layout.VBox;
  41 import test.javaclient.shared.InteroperabilityApp;
  42 import test.javaclient.shared.Utils;
  43 
  44 /**
  45  * @author Alexander Kirov
  46  */
  47 public class NewScrollPaneApp extends InteroperabilityApp {
  48 
  49     public final static String CHANGE_CONTENT_BUTTON_ID = "CHANGE_CONTENT_BUTTON_ID";
  50     public final static String CONTENT_BUTTON = "CONTENT_BUTTON";
  51     public final static String CUSTOM_CONTENT_ID = "CUSTOM_CONTENT_ID";
  52     public final static String CONTENT_TEXT_AREA_ID = "CONTENT_TEXT_AREA_ID";
  53     public final static String CONTENT_TEXT_FIELD_ID = "CONTENT_TEXT_FIELD_ID";
  54     public final static String DECREASE_SCALE_BUTTON_ID = "DECREASE_SCALE_BUTTON_ID";
  55     public final static String DECREASE_SCROLLPANE_SCALE_BUTTON_ID = "DECREASE_SCROLLPANE_SCALE_BUTTON_ID";
  56     public final static String INCREASE_SCALE_BUTTON_ID = "INCREASE_SCALE_BUTTON_ID";
  57     public final static String INCREASE_SCROLLPANE_SCALE_BUTTON_ID = "INCREASE_SCROLLPANE_SCALE_BUTTON_ID";
  58     public final static String RESET_BUTTON_ID = "RESET_BUTTON_ID";
  59     public final static String ROTATE_BUTTON_ID = "ROTATE_BUTTON_ID";
  60     public final static String ROTATE_SCROLLPANE_BUTTON_ID = "ROTATE_SCROLLPANE_BUTTON_ID";
  61     public final static String START_MOTION_BUTTON_ID = "START_MOTION_BUTTON_ID";
  62     public final static String TESTED_SCROLLPANE_ID = "TESTED_SCROLLPANE_ID";
  63     public final static String WITHOUT_ACTION_BUTTON = "WITHOUT_ACTION_BUTTON";
  64     public final static String CHANGE_CONTENT_TO_RESIZABLE_BUTTON_ID = "CHANGE_CONTENT_TO_RESIZABLE_BUTTON_ID";
  65     public final static String CHANGE_CONTENT_TO_CUSTOM_BUTTON_ID = "CHANGE_CONTENT_TO_CUSTOM_BUTTON_ID";
  66     public final static String ADD_SIZE_BUTTON_ID = "ADD_SIZE_BUTTON_ID";
  67     public final static String GRID_DIMENSION_TEXTFIELD_ID = "GRID_DIMENSION_TEXTFIELD_ID";
  68     public final static String ADD_GRID_BUTTON_ID = "ADD_GRID_BUTTON_ID";
  69     private static int customContentWidth = 200;
  70     private static int customContentHeight = 200;
  71     private static int scrollPaneWidth = 0;
  72     private static int scrollPaneHeight = 0;
  73 
  74     public static void main(String[] args) {
  75         try {
  76             if (args != null) {
  77                 for (int i = 0; i < args.length; ++i) {
  78                     if (args[i].equals("--customContentWidth")) {
  79                         ++i;
  80                         customContentWidth = Integer.parseInt(args[i]);
  81                     }
  82                     if (args[i].equals("--customContentHeight")) {
  83                         ++i;
  84                         customContentHeight = Integer.parseInt(args[i]);
  85                     }
  86                     if (args[i].equals("--scrollPaneWidth")) {
  87                         ++i;
  88                         scrollPaneWidth = Integer.parseInt(args[i]);
  89                     }
  90                     if (args[i].equals("--scrollPaneHeight")) {
  91                         ++i;
  92                         scrollPaneHeight = Integer.parseInt(args[i]);
  93                     }
  94                 }
  95             }
  96         } catch (NumberFormatException ex) {
  97         }
  98 
  99         Utils.launch(NewScrollPaneApp.class, args);
 100     }
 101 
 102     @Override
 103     protected Scene getScene() {
 104         Utils.setTitleToStage(stage, "ScrollPaneTestApp");
 105         return new ScrollPaneScene();
 106     }
 107 
 108     class ScrollPaneScene extends CommonPropertiesScene {
 109 
 110         private PropertiesTable tb;
 111         //ScrollPane to be tested.
 112         private ScrollPane testedScrollPane;
 113 
 114         public ScrollPaneScene() {
 115             super("ScrollPane", 800, 600);


 116         }
 117 
 118         @Override
 119         protected final void prepareScene() {
 120             Utils.addBrowser(this);
 121             testedScrollPane = new ScrollPane();
 122             testedScrollPane.setId(TESTED_SCROLLPANE_ID);
 123             final Node content = setCustomContent(customContentHeight, customContentWidth);
 124 
 125             final ContentMotion cm = new ContentMotion();
 126             testedScrollPane.setContent(content);
 127             cm.applyTransition(content);
 128 
 129             tb = new PropertiesTable(testedScrollPane);
 130             PropertyTablesFactory.explorePropertiesList(testedScrollPane, tb);
 131             SpecialTablePropertiesProvider.provideForControl(testedScrollPane, tb);
 132 
 133             if ((scrollPaneWidth > 0) && (scrollPaneHeight > 0)) {
 134                 testedScrollPane.setPrefViewportWidth(scrollPaneWidth);
 135                 testedScrollPane.setPrefViewportHeight(scrollPaneHeight);
 136             }
 137 
 138             Button changeContentButton = new Button("ChangeContent");
 139             changeContentButton.setId(CHANGE_CONTENT_BUTTON_ID);
 140             changeContentButton.setOnAction(new EventHandler<ActionEvent>() {
 141                 public void handle(ActionEvent t) {
 142                     changeContent();
 143                     cm.applyTransition(content);
 144                 }
 145             });
 146 
 147             Button addPrefWidthAndHeightButton = new Button("Add pref sizes");
 148             addPrefWidthAndHeightButton.setId(ADD_SIZE_BUTTON_ID);
 149             addPrefWidthAndHeightButton.setOnAction(new EventHandler<ActionEvent>() {
 150                 public void handle(ActionEvent t) {
 151                     tb.addDoublePropertyLine(testedScrollPane.prefWidthProperty(), -100, 200, 100);
 152                     tb.addDoublePropertyLine(testedScrollPane.prefHeightProperty(), -100, 200, 100);
 153                 }
 154             });
 155 
 156             Button setTextAreaAsContentButton = new Button("Set blue pane as content");
 157             setTextAreaAsContentButton.setId(CHANGE_CONTENT_TO_RESIZABLE_BUTTON_ID);
 158             setTextAreaAsContentButton.setOnAction(new EventHandler<ActionEvent>() {
 159                 public void handle(ActionEvent t) {
 160                     setResizableContent();
 161                     Pane pane = (Pane) testedScrollPane.getContent();
 162                     tb.addDoublePropertyLine(pane.prefWidthProperty(), 0, 300, 100);
 163                     tb.addDoublePropertyLine(pane.prefHeightProperty(), 0, 300, 100);
 164                 }
 165             });
 166 
 167             Button setCustomContentButton = new Button("Set custom content");
 168             setCustomContentButton.setId(CHANGE_CONTENT_TO_CUSTOM_BUTTON_ID);
 169             setCustomContentButton.setOnAction(new EventHandler<ActionEvent>() {
 170                 public void handle(ActionEvent t) {
 171                     setCustomContent();
 172                 }
 173             });
 174 
 175             Button buttonStart = new Button("Start motion");
 176             buttonStart.setId(START_MOTION_BUTTON_ID);
 177             buttonStart.setOnAction(new EventHandler<ActionEvent>() {
 178                 public void handle(ActionEvent t) {
 179                     cm.getTimeline().play();
 180                 }
 181             });
 182 
 183             Button rotateButton = new Button("Rotate on 30deg");
 184             rotateButton.setId(ROTATE_BUTTON_ID);
 185             rotateButton.setOnAction(new EventHandler<ActionEvent>() {
 186                 public void handle(ActionEvent t) {
 187                     content.setRotate(content.getRotate() + 30);
 188                 }
 189             });
 190 
 191             Button rotateScrollPaneButton = new Button("Rotate scrollpane on 30deg");
 192             rotateScrollPaneButton.setId(ROTATE_SCROLLPANE_BUTTON_ID);
 193             rotateScrollPaneButton.setOnAction(new EventHandler<ActionEvent>() {
 194                 public void handle(ActionEvent t) {
 195                     testedScrollPane.setRotate(testedScrollPane.getRotate() + 30);
 196                 }
 197             });
 198 
 199             Button increaseScaleButton = new Button("Increase scale");
 200             increaseScaleButton.setId(INCREASE_SCALE_BUTTON_ID);
 201             increaseScaleButton.setOnAction(new EventHandler<ActionEvent>() {
 202                 public void handle(ActionEvent t) {
 203                     content.setScaleX(content.getScaleX() + 0.15);
 204                     content.setScaleY(content.getScaleY() + 0.15);
 205                 }
 206             });
 207 
 208             Button decreaseScaleButton = new Button("Decrease scale");
 209             decreaseScaleButton.setId(DECREASE_SCALE_BUTTON_ID);
 210             decreaseScaleButton.setOnAction(new EventHandler<ActionEvent>() {
 211                 public void handle(ActionEvent t) {
 212                     content.setScaleX(content.getScaleX() - 0.15);
 213                     content.setScaleY(content.getScaleY() - 0.15);
 214                 }
 215             });
 216 
 217             Button increaseScrollPaneScaleButton = new Button("Increase ScrollPane scale");
 218             increaseScrollPaneScaleButton.setId(INCREASE_SCROLLPANE_SCALE_BUTTON_ID);
 219             increaseScrollPaneScaleButton.setOnAction(new EventHandler<ActionEvent>() {
 220                 public void handle(ActionEvent t) {
 221                     testedScrollPane.setScaleX(testedScrollPane.getScaleX() + 0.15);
 222                     testedScrollPane.setScaleY(testedScrollPane.getScaleY() + 0.15);
 223                 }
 224             });
 225 
 226             Button decreaseScrollPaneScaleButton = new Button("Decrease ScrollPane scale");
 227             decreaseScrollPaneScaleButton.setId(DECREASE_SCROLLPANE_SCALE_BUTTON_ID);
 228             decreaseScrollPaneScaleButton.setOnAction(new EventHandler<ActionEvent>() {
 229                 public void handle(ActionEvent t) {
 230                     testedScrollPane.setScaleX(testedScrollPane.getScaleX() - 0.15);
 231                     testedScrollPane.setScaleY(testedScrollPane.getScaleY() - 0.15);
 232                 }
 233             });
 234 
 235             Button resetButton = new Button("Reset");
 236             resetButton.setId(RESET_BUTTON_ID);
 237             resetButton.setOnAction(new EventHandler<ActionEvent>() {
 238                 public void handle(ActionEvent t) {
 239                     HBox hb = (HBox) getRoot();
 240                     hb.getChildren().clear();
 241                     prepareMainSceneStructure();
 242                     prepareScene();
 243                 }
 244             });
 245 
 246             setTestedControl(testedScrollPane);
 247 
 248             VBox vb = new VBox();
 249             vb.setSpacing(5);
 250             vb.getChildren().addAll(changeContentButton, setCustomContentButton, setTextAreaAsContentButton,
 251                     buttonStart, rotateButton, rotateScrollPaneButton,
 252                     increaseScrollPaneScaleButton, decreaseScrollPaneScaleButton, getAddGridPaneForm(),
 253                     increaseScaleButton, decreaseScaleButton, resetButton, addPrefWidthAndHeightButton);
 254             setControllersContent(vb);
 255 
 256             setPropertiesContent(tb);
 257         }
 258 
 259         private Node getAddGridPaneForm() {
 260             final TextField dimension = new TextField();
 261             dimension.setId(GRID_DIMENSION_TEXTFIELD_ID);
 262             dimension.setPromptText("int-dimension");
 263             dimension.setMaxWidth(50);
 264             Button addButton = new Button("Add grid");
 265             addButton.setId(ADD_GRID_BUTTON_ID);
 266             addButton.setOnAction(new EventHandler<ActionEvent>() {
 267                 public void handle(ActionEvent t) {
 268                     int c = Integer.parseInt(dimension.getText());
 269 
 270                     GridPane gridPane = new GridPane();
 271                     for (int i = 0; i < c; i++) {
 272                         for (int j = 0; j < c; j++) {
 273                             final String name = "B-" + String.valueOf(i) + "-" + String.valueOf(j);
 274                             Button temp = new Button(name);
 275                             temp.setId(name);
 276                             temp.setMinHeight(10 * i);
 277                             temp.setMinWidth(10 * j);
 278                             gridPane.add(temp, i, j);
 279                         }
 280                     }
 281                     testedScrollPane.setContent(gridPane);
 282                 }
 283             });
 284 
 285             HBox hb = new HBox(5);
 286             hb.getChildren().addAll(dimension, addButton);
 287             return hb;
 288         }
 289 
 290         private void setResizableContent() {
 291             Pane canvas = new Pane();
 292             canvas.setStyle("-fx-background-color: blue;");
 293             testedScrollPane.setContent(canvas);
 294 
 295 
 296             canvas.setPrefHeight(100);
 297             canvas.setPrefWidth(100);
 298         }
 299 
 300         private Group setCustomContent(int height, int width) {
 301             Group g = ComponentsFactory.createCustomContent(height, width);
 302             g.setId(CUSTOM_CONTENT_ID);
 303             testedScrollPane.setContent(g);
 304             return g;
 305         }
 306 
 307         private Group setCustomContent() {
 308             return setCustomContent(200, 200);
 309         }
 310 
 311         private void changeContent() {
 312             VBox vb = new VBox();
 313             Button button = new Button("Press me");
 314             button.setId(CONTENT_BUTTON);
 315             final TextField tf1 = new TextField("0");
 316             tf1.setId(CONTENT_TEXT_FIELD_ID);
 317             button.setOnAction(new EventHandler<ActionEvent>() {
 318                 public void handle(ActionEvent t) {
 319                     tf1.setText(String.valueOf(Integer.parseInt(tf1.getText()) + 1));
 320                 }
 321             });
 322             TextArea tf2 = new TextArea();
 323             tf2.setPrefHeight(100);
 324             tf2.setId(CONTENT_TEXT_AREA_ID);
 325             for (int i = 0; i < 15; i++) {
 326                 tf2.appendText("text" + i + "\n");
 327             }
 328             Button empty = new Button("This is empty-action button");
 329             empty.setId(WITHOUT_ACTION_BUTTON);
 330 
 331             vb.getChildren().addAll(button, tf1, tf2, empty);
 332             vb.setStyle("-fx-border-color: blue;");
 333 
 334             testedScrollPane.setContent(vb);
 335         }
 336     }
 337 }
--- EOF ---