functional/ControlsTests/src/javafx/scene/control/test/ToggleButtonNewApp.java

Print this page




  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;
  26 
  27 import javafx.beans.InvalidationListener;
  28 import javafx.beans.Observable;
  29 import javafx.beans.property.BooleanProperty;
  30 import javafx.event.ActionEvent;
  31 import javafx.event.EventHandler;
  32 import javafx.scene.Scene;
  33 import javafx.scene.control.Button;
  34 import javafx.scene.control.ButtonBuilder;
  35 import javafx.scene.control.CheckBox;
  36 import javafx.scene.control.CheckBoxBuilder;
  37 import javafx.scene.control.Label;
  38 import javafx.scene.control.LabelBuilder;
  39 import javafx.scene.control.RadioButtonBuilder;
  40 import javafx.scene.control.ToggleButton;
  41 import javafx.scene.control.ToggleButtonBuilder;
  42 import javafx.scene.control.ToggleGroup;
  43 import javafx.scene.input.MouseEvent;
  44 import javafx.scene.layout.HBox;
  45 import javafx.scene.layout.VBox;
  46 import test.javaclient.shared.InteroperabilityApp;
  47 import test.javaclient.shared.Utils;
  48 
  49 /**
  50  * @author Alexander Kirov
  51  */
  52 public class ToggleButtonNewApp extends InteroperabilityApp {
  53 
  54     public enum ControlType {
  55 
  56         TOGGLE_BUTTON, RADIO_BUTTON
  57     };
  58     public static String TOGGLE_BUTTON_1_ID = "toggle button 1";
  59     public static String TOGGLE_BUTTON_2_ID = "toggle button 2";
  60     public static String BINDING_SET_TOGGLE_BUTTON_ID = "binding set button";
  61     public static String GROUPING_TOGGLE_BUTTON_ID = "grouping button";


  63     public static String SETTING_CONTROL_TOGGLE_BUTTON_ID = "ToggleButton which sets tested control";
  64     public static String CHECK_BOX_LISTENING_1_ID = "check box listening to toggle button 1";
  65     public static String CHECK_BOX_LISTENING_2_ID = "check box listening to toggle button 2";
  66     public static String CHECK_BOX_SETTING_1_BIDIR_ID = "check box setting toggle button 1 bidirectionaly";
  67     public static String CHECK_BOX_SETTING_2_UNIDIR_ID = "check box setting toggle button 2 unirectionaly";
  68     public static String MOUSE_EVENTS_LOGGER_LABEL_ID = "label logs mouse events";
  69 
  70     public static void main(String[] args) {
  71         Utils.launch(ToggleButtonNewApp.class, args);
  72     }
  73 
  74     @Override
  75     protected Scene getScene() {
  76         return new ToggleButtonNewAppScene();
  77     }
  78 
  79     class ToggleButtonNewAppScene extends Scene {
  80 
  81         ToggleButton toggleButton1;
  82         ToggleButton toggleButton2;
  83         CheckBox checkBox1 = CheckBoxBuilder.create().wrapText(true).text("Unidirectionally binded to\ntoggle button 1 selection property").id(CHECK_BOX_LISTENING_1_ID).build();
  84         CheckBox checkBox2 = CheckBoxBuilder.create().wrapText(true).text("Unidirectionally binded to\ntoggle button 2 selection property").id(CHECK_BOX_LISTENING_2_ID).build();
  85         CheckBox checkBox3 = CheckBoxBuilder.create().wrapText(true).text("This check box is bidirectionally binded\nto Toggle Button 1 selection property").id(CHECK_BOX_SETTING_1_BIDIR_ID).build();
  86         CheckBox checkBox4 = CheckBoxBuilder.create().wrapText(true).text("This check box unidirectionally sets\ntoggle button 2 selection property").id(CHECK_BOX_SETTING_2_UNIDIR_ID).build();
  87         ToggleGroup toggleGroup = new ToggleGroup();
  88         ToggleButton bindingsSettingButton = ToggleButtonBuilder.create().text("State: Unbinded").id(BINDING_SET_TOGGLE_BUTTON_ID).build();
  89         ToggleButton groupingButton = ToggleButtonBuilder.create().text("State: Ungrouped").id(GROUPING_TOGGLE_BUTTON_ID).build();
  90         ToggleButton testedControlChangeButton = ToggleButtonBuilder.create().text("Control: radio button").id(SETTING_CONTROL_TOGGLE_BUTTON_ID).build();
  91         Button resetButton = ButtonBuilder.create().text("Reset state").id(RESET_BUTTON_ID).build();
  92         Label mouseEventsLogger = LabelBuilder.create().text("0").id(MOUSE_EVENTS_LOGGER_LABEL_ID).build();
  93         VBox vb1 = new VBox();
  94 
  95         public ToggleButtonNewAppScene() {
  96             super(new HBox(), 800, 320);
  97 
























  98             setControl(ControlType.RADIO_BUTTON);
  99 
 100             addButtonsListeners();
 101             bindListeningBindings();
 102             addToggleButtonActionEventListener();
 103 
 104             checkBox1.setDisable(true);
 105             checkBox2.setDisable(true);
 106             Label label1 = new Label("These CheckBoxes listens\n to \"selected\""
 107                     + " property of according\n toggle button "
 108                     + "by binding");
 109             Label label2 = new Label("Next Checkboxes set its\n "
 110                     + "values to toggle buttons. \n"
 111                     + "Before using press button for binding");
 112             label1.setWrapText(true);
 113             label2.setWrapText(true);
 114 
 115             vb1.setSpacing(10);
 116 
 117             VBox vb2 = new VBox();
 118             vb2.setSpacing(10);
 119             vb2.getChildren().addAll(label1, checkBox1, checkBox2, label2, bindingsSettingButton, checkBox3, checkBox4);
 120 
 121             VBox vb3 = new VBox();
 122             vb3.setSpacing(10);
 123             vb3.getChildren().addAll(groupingButton, testedControlChangeButton, resetButton);
 124 
 125             HBox hb = (HBox) getRoot();
 126             hb.setSpacing(10);
 127             hb.setLayoutX(10);
 128             hb.setLayoutY(10);
 129             hb.getChildren().addAll(vb1, vb2, vb3, new Label("Action events handled : "), mouseEventsLogger);
 130         }
 131 
 132         private void setControl(ControlType type) {
 133             if (type == ControlType.RADIO_BUTTON) {
 134                 toggleButton1 = RadioButtonBuilder.create().text("Radio button 1").id(TOGGLE_BUTTON_1_ID).build();
 135                 toggleButton2 = RadioButtonBuilder.create().text("Radio button 2").id(TOGGLE_BUTTON_2_ID).build();


 136             } else {
 137                 toggleButton1 = ToggleButtonBuilder.create().text("Toggle button 1").id(TOGGLE_BUTTON_1_ID).build();
 138                 toggleButton2 = ToggleButtonBuilder.create().text("Toggle button 2").id(TOGGLE_BUTTON_2_ID).build();


 139             }
 140 
 141             vb1.getChildren().clear();
 142             vb1.getChildren().addAll(toggleButton1, toggleButton2);
 143         }
 144 
 145         private void addButtonsListeners() {
 146 
 147             bindingsSettingButton.selectedProperty().addListener(new InvalidationListener() {
 148                 public void invalidated(Observable o) {
 149                     if (((BooleanProperty) o).getValue() == true) {
 150                         bindSettingBindings();
 151                         bindingsSettingButton.setText("State: Binded");
 152                     } else {
 153                         removeBindings();
 154                         bindListeningBindings();
 155                         bindingsSettingButton.setText("State: Unbinded");
 156                     }
 157                 }
 158             });




  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;
  26 
  27 import javafx.beans.InvalidationListener;
  28 import javafx.beans.Observable;
  29 import javafx.beans.property.BooleanProperty;
  30 import javafx.event.ActionEvent;
  31 import javafx.event.EventHandler;
  32 import javafx.scene.Scene;
  33 import javafx.scene.control.Button;

  34 import javafx.scene.control.CheckBox;

  35 import javafx.scene.control.Label;
  36 import javafx.scene.control.RadioButton;

  37 import javafx.scene.control.ToggleButton;

  38 import javafx.scene.control.ToggleGroup;
  39 import javafx.scene.input.MouseEvent;
  40 import javafx.scene.layout.HBox;
  41 import javafx.scene.layout.VBox;
  42 import test.javaclient.shared.InteroperabilityApp;
  43 import test.javaclient.shared.Utils;
  44 
  45 /**
  46  * @author Alexander Kirov
  47  */
  48 public class ToggleButtonNewApp extends InteroperabilityApp {
  49 
  50     public enum ControlType {
  51 
  52         TOGGLE_BUTTON, RADIO_BUTTON
  53     };
  54     public static String TOGGLE_BUTTON_1_ID = "toggle button 1";
  55     public static String TOGGLE_BUTTON_2_ID = "toggle button 2";
  56     public static String BINDING_SET_TOGGLE_BUTTON_ID = "binding set button";
  57     public static String GROUPING_TOGGLE_BUTTON_ID = "grouping button";


  59     public static String SETTING_CONTROL_TOGGLE_BUTTON_ID = "ToggleButton which sets tested control";
  60     public static String CHECK_BOX_LISTENING_1_ID = "check box listening to toggle button 1";
  61     public static String CHECK_BOX_LISTENING_2_ID = "check box listening to toggle button 2";
  62     public static String CHECK_BOX_SETTING_1_BIDIR_ID = "check box setting toggle button 1 bidirectionaly";
  63     public static String CHECK_BOX_SETTING_2_UNIDIR_ID = "check box setting toggle button 2 unirectionaly";
  64     public static String MOUSE_EVENTS_LOGGER_LABEL_ID = "label logs mouse events";
  65 
  66     public static void main(String[] args) {
  67         Utils.launch(ToggleButtonNewApp.class, args);
  68     }
  69 
  70     @Override
  71     protected Scene getScene() {
  72         return new ToggleButtonNewAppScene();
  73     }
  74 
  75     class ToggleButtonNewAppScene extends Scene {
  76 
  77         ToggleButton toggleButton1;
  78         ToggleButton toggleButton2;
  79         CheckBox checkBox1;
  80         CheckBox checkBox2;
  81         CheckBox checkBox3;
  82         CheckBox checkBox4;
  83         ToggleGroup toggleGroup = new ToggleGroup();
  84         ToggleButton bindingsSettingButton;
  85         ToggleButton groupingButton;
  86         ToggleButton testedControlChangeButton;
  87         Button resetButton;
  88         Label mouseEventsLogger;
  89         VBox vb1 = new VBox();
  90 
  91         public ToggleButtonNewAppScene() {
  92             super(new HBox(), 800, 320);
  93 
  94             checkBox1 = new CheckBox("Unidirectionally binded to\ntoggle button 1 selection property");
  95             checkBox1.setWrapText(true);
  96             checkBox1.setId(CHECK_BOX_LISTENING_1_ID);
  97             checkBox2 = new CheckBox("Unidirectionally binded to\ntoggle button 2 selection property");
  98             checkBox2.setWrapText(true);
  99             checkBox2.setId(CHECK_BOX_LISTENING_2_ID);
 100             checkBox3 = new CheckBox("This check box is bidirectionally binded\nto Toggle Button 1 selection property");
 101             checkBox3.setWrapText(true);
 102             checkBox3.setId(CHECK_BOX_SETTING_1_BIDIR_ID);
 103             checkBox4 = new CheckBox("This check box unidirectionally sets\ntoggle button 2 selection property");
 104             checkBox4.setWrapText(true);
 105             checkBox4.setId(CHECK_BOX_SETTING_2_UNIDIR_ID);
 106 
 107             bindingsSettingButton = new ToggleButton("State: Unbinded");
 108             bindingsSettingButton.setId(BINDING_SET_TOGGLE_BUTTON_ID);
 109             groupingButton = new ToggleButton("State: Ungrouped");
 110             groupingButton.setId(GROUPING_TOGGLE_BUTTON_ID);
 111             testedControlChangeButton = new ToggleButton("Control: radio button");
 112             testedControlChangeButton.setId(SETTING_CONTROL_TOGGLE_BUTTON_ID);
 113             resetButton = new Button("Reset state");
 114             resetButton.setId(RESET_BUTTON_ID);
 115             mouseEventsLogger = new Label("0");
 116             mouseEventsLogger.setId(MOUSE_EVENTS_LOGGER_LABEL_ID);
 117 
 118             setControl(ControlType.RADIO_BUTTON);
 119 
 120             addButtonsListeners();
 121             bindListeningBindings();
 122             addToggleButtonActionEventListener();
 123 
 124             checkBox1.setDisable(true);
 125             checkBox2.setDisable(true);
 126             Label label1 = new Label("These CheckBoxes listens\n to \"selected\""
 127                     + " property of according\n toggle button "
 128                     + "by binding");
 129             Label label2 = new Label("Next Checkboxes set its\n "
 130                     + "values to toggle buttons. \n"
 131                     + "Before using press button for binding");
 132             label1.setWrapText(true);
 133             label2.setWrapText(true);
 134 
 135             vb1.setSpacing(10);
 136 
 137             VBox vb2 = new VBox();
 138             vb2.setSpacing(10);
 139             vb2.getChildren().addAll(label1, checkBox1, checkBox2, label2, bindingsSettingButton, checkBox3, checkBox4);
 140 
 141             VBox vb3 = new VBox();
 142             vb3.setSpacing(10);
 143             vb3.getChildren().addAll(groupingButton, testedControlChangeButton, resetButton);
 144 
 145             HBox hb = (HBox) getRoot();
 146             hb.setSpacing(10);
 147             hb.setLayoutX(10);
 148             hb.setLayoutY(10);
 149             hb.getChildren().addAll(vb1, vb2, vb3, new Label("Action events handled : "), mouseEventsLogger);
 150         }
 151 
 152         private void setControl(ControlType type) {
 153             if (type == ControlType.RADIO_BUTTON) {
 154                 toggleButton1 = new RadioButton("Radio button 1");
 155                 toggleButton1.setId(TOGGLE_BUTTON_1_ID);
 156                 toggleButton2 = new RadioButton("Radio button 2");
 157                 toggleButton2.setId(TOGGLE_BUTTON_2_ID);
 158             } else {
 159                 toggleButton1 = new ToggleButton("Toggle button 1");
 160                 toggleButton1.setId(TOGGLE_BUTTON_1_ID);
 161                 toggleButton2 = new ToggleButton("Toggle button 2");
 162                 toggleButton2.setId(TOGGLE_BUTTON_2_ID);
 163             }
 164 
 165             vb1.getChildren().clear();
 166             vb1.getChildren().addAll(toggleButton1, toggleButton2);
 167         }
 168 
 169         private void addButtonsListeners() {
 170 
 171             bindingsSettingButton.selectedProperty().addListener(new InvalidationListener() {
 172                 public void invalidated(Observable o) {
 173                     if (((BooleanProperty) o).getValue() == true) {
 174                         bindSettingBindings();
 175                         bindingsSettingButton.setText("State: Binded");
 176                     } else {
 177                         removeBindings();
 178                         bindListeningBindings();
 179                         bindingsSettingButton.setText("State: Unbinded");
 180                     }
 181                 }
 182             });