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 test.css.stylesheets; 26 27 import com.sun.javafx.runtime.VersionInfo; 28 import javafx.application.Application; 29 import javafx.event.EventHandler; 30 import javafx.geometry.Pos; 31 import javafx.scene.Scene; 32 import javafx.scene.input.MouseEvent; 33 import javafx.scene.layout.Pane; 34 import javafx.scene.layout.StackPane; 35 import javafx.scene.layout.VBoxBuilder; 36 import javafx.scene.text.Text; 37 import javafx.stage.Stage; 38 import test.javaclient.shared.Utils; 39 40 /** 41 * 42 * @author sergey.lugovoy@oracle.com 43 */ 44 public class StylesheetApp extends Application { 45 public final static String EXAMPLE_ID = "example"; 46 private static int WIDTH = 300; 47 private static int HEIGHT = 300; 48 49 50 private static String[] styles = new String[]{ 51 StylesheetApp.class.getResource("/test/css/resources/rt-17348_1.css").toExternalForm(), 52 StylesheetApp.class.getResource("/test/css/resources/rt-17348_2.css").toExternalForm() 53 }; 54 55 private int styleIndex = 0; 56 57 @Override 58 public void start(Stage stage) throws Exception { 59 StackPane pane = new StackPane(); 60 Pane golden = new Pane(); 61 golden.setId(EXAMPLE_ID); 62 golden.setMinSize(WIDTH, 120); 63 Text button = new Text("Change CSS"); 64 final Scene scene = new Scene(pane, HEIGHT, WIDTH); 65 button.setOnMouseClicked(new EventHandler<MouseEvent>() { 66 67 @Override 68 public void handle(MouseEvent t) { 69 styleIndex = styleIndex == 0 ? 1 : 0; 70 scene.getStylesheets().set(0, styles[styleIndex]); 71 } 72 }); 73 scene.getStylesheets().add(styles[styleIndex]); 74 pane.getChildren().add(VBoxBuilder.create().alignment(Pos.CENTER).spacing(50).children(golden, button).build()); 75 stage.setScene(scene); 76 stage.setTitle("Test for RT-17348." + VersionInfo.getRuntimeVersion()); 77 stage.show(); 78 } 79 80 public static void main(String[] args) { 81 Utils.launch(StylesheetApp.class, null); 82 } 83 } | 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 test.css.stylesheets; 26 27 import com.sun.javafx.runtime.VersionInfo; 28 import javafx.application.Application; 29 import javafx.event.EventHandler; 30 import javafx.geometry.Pos; 31 import javafx.scene.Scene; 32 import javafx.scene.input.MouseEvent; 33 import javafx.scene.layout.Pane; 34 import javafx.scene.layout.StackPane; 35 import javafx.scene.layout.VBox; 36 import javafx.scene.text.Text; 37 import javafx.stage.Stage; 38 import test.javaclient.shared.Utils; 39 40 /** 41 * 42 * @author sergey.lugovoy@oracle.com 43 */ 44 public class StylesheetApp extends Application { 45 public final static String EXAMPLE_ID = "example"; 46 private static int WIDTH = 300; 47 private static int HEIGHT = 300; 48 49 50 private static String[] styles = new String[]{ 51 StylesheetApp.class.getResource("/test/css/resources/rt-17348_1.css").toExternalForm(), 52 StylesheetApp.class.getResource("/test/css/resources/rt-17348_2.css").toExternalForm() 53 }; 54 55 private int styleIndex = 0; 56 57 @Override 58 public void start(Stage stage) throws Exception { 59 StackPane pane = new StackPane(); 60 Pane golden = new Pane(); 61 golden.setId(EXAMPLE_ID); 62 golden.setMinSize(WIDTH, 120); 63 Text button = new Text("Change CSS"); 64 final Scene scene = new Scene(pane, HEIGHT, WIDTH); 65 button.setOnMouseClicked(new EventHandler<MouseEvent>() { 66 67 @Override 68 public void handle(MouseEvent t) { 69 styleIndex = styleIndex == 0 ? 1 : 0; 70 scene.getStylesheets().set(0, styles[styleIndex]); 71 } 72 }); 73 scene.getStylesheets().add(styles[styleIndex]); 74 VBox temp = new VBox(golden, button); 75 temp.setAlignment(Pos.CENTER); 76 temp.setSpacing(50); 77 pane.getChildren().add(temp); 78 stage.setScene(scene); 79 stage.setTitle("Test for RT-17348." + VersionInfo.getRuntimeVersion()); 80 stage.show(); 81 } 82 83 public static void main(String[] args) { 84 Utils.launch(StylesheetApp.class, null); 85 } 86 } |