-
-
Save mosababdo/7cd1fe94edc02c5301b5e1744c9b5017 to your computer and use it in GitHub Desktop.
Revisions
-
jewelsea revised this gist
Sep 6, 2013 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,11 @@ } #vista1 { -fx-background-color: aliceblue; } #vista2 { -fx-background-color: coral; } .button { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ <?import javafx.scene.control.Button?> <?import javafx.scene.layout.StackPane?> <StackPane fx:id="vista2" xmlns:fx="http://javafx.com/fxml" fx:controller="Vista2Controller"> <children> <Button mnemonicParsing="false" onAction="#previousPane" text="Previous Pane" /> </children> -
jewelsea revised this gist
Sep 6, 2013 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,9 @@ public class Vista1Controller { /** * Event handler fired when the user requests a new vista. * * @param event the event that triggered the handler. */ @FXML void nextPane(ActionEvent event) { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,9 @@ public class Vista2Controller { /** * Event handler fired when the user requests a previous vista. * * @param event the event that triggered the handler. */ @FXML void previousPane(ActionEvent event) { -
jewelsea created this gist
Sep 6, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; import java.io.IOException; /** * Main application class. */ public class Main extends Application { @Override public void start(Stage stage) throws Exception{ stage.setTitle("Vista Viewer"); stage.setScene( createScene( loadMainPane() ) ); stage.show(); } /** * Loads the main fxml layout. * Sets up the vista switching VistaNavigator. * Loads the first vista into the fxml layout. * * @return the loaded pane. * @throws IOException if the pane could not be loaded. */ private Pane loadMainPane() throws IOException { FXMLLoader loader = new FXMLLoader(); Pane mainPane = (Pane) loader.load( getClass().getResourceAsStream( VistaNavigator.MAIN ) ); MainController mainController = loader.getController(); VistaNavigator.setMainController(mainController); VistaNavigator.loadVista(VistaNavigator.VISTA_1); return mainPane; } /** * Creates the main application scene. * * @param mainPane the main application layout. * * @return the created scene. */ private Scene createScene(Pane mainPane) { Scene scene = new Scene( mainPane ); scene.getStylesheets().setAll( getClass().getResource("vista.css").toExternalForm() ); return scene; } public static void main(String[] args) { launch(args); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.layout.StackPane; /** * Main controller class for the entire layout. */ public class MainController { /** Holder of a switchable vista. */ @FXML private StackPane vistaHolder; /** * Replaces the vista displayed in the vista holder with a new vista. * * @param node the vista node to be swapped in. */ public void setVista(Node node) { vistaHolder.getChildren().setAll(node); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; /** * Controller class for the first vista. */ public class Vista1Controller { /** * Event handler fires when the user requests a new vista. * * @param event the event the triggered the handler. */ @FXML void nextPane(ActionEvent event) { VistaNavigator.loadVista(VistaNavigator.VISTA_2); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; /** * Controller class for the second vista. */ public class Vista2Controller { /** * Event handler fires when the user requests a previous vista. * * @param event the event the triggered the handler. */ @FXML void previousPane(ActionEvent event) { VistaNavigator.loadVista(VistaNavigator.VISTA_1); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ import javafx.fxml.FXMLLoader; import java.io.IOException; /** * Utility class for controlling navigation between vistas. * * All methods on the navigator are static to facilitate * simple access from anywhere in the application. */ public class VistaNavigator { /** * Convenience constants for fxml layouts managed by the navigator. */ public static final String MAIN = "main.fxml"; public static final String VISTA_1 = "vista1.fxml"; public static final String VISTA_2 = "vista2.fxml"; /** The main application layout controller. */ private static MainController mainController; /** * Stores the main controller for later use in navigation tasks. * * @param mainController the main application layout controller. */ public static void setMainController(MainController mainController) { VistaNavigator.mainController = mainController; } /** * Loads the vista specified by the fxml file into the * vistaHolder pane of the main application layout. * * Previously loaded vista for the same fxml file are not cached. * The fxml is loaded anew and a new vista node hierarchy generated * every time this method is invoked. * * A more sophisticated load function could potentially add some * enhancements or optimizations, for example: * cache FXMLLoaders * cache loaded vista nodes, so they can be recalled or reused * allow a user to specify vista node reuse or new creation * allow back and forward history like a browser * * @param fxml the fxml file to be loaded. */ public static void loadVista(String fxml) { try { mainController.setVista( FXMLLoader.load( VistaNavigator.class.getResource( fxml ) ) ); } catch (IOException e) { e.printStackTrace(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?scenebuilder-stylesheet vista.css?> <VBox prefHeight="200.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml" fx:controller="MainController"> <children> <Label fx:id="headerLabel" maxWidth="1.7976931348623157E308" text="Header" VBox.vgrow="NEVER" /> <StackPane fx:id="vistaHolder" VBox.vgrow="ALWAYS" /> </children> </VBox> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ /** * vista.css * Place in the same source directory as Main.java * Ensure that your build system copies this file to your build output directory. */ #headerLabel { -fx-background-color: steelblue; -fx-text-fill: white; -fx-padding: 5px; } #vistaHolder { -fx-background-color: lightgrey; } #vista1 { -fx-background-color: coral; } #vista2 { -fx-background-color: aliceblue; } .button { -fx-base: lightblue; -fx-font-size: 20px; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?scenebuilder-stylesheet vista.css?> <StackPane fx:id="vista1" xmlns:fx="http://javafx.com/fxml" fx:controller="Vista1Controller"> <children> <Button mnemonicParsing="false" onAction="#nextPane" text="Next Pane" /> </children> </StackPane> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <?scenebuilder-stylesheet vista.css?> <?import javafx.scene.control.Button?> <?import javafx.scene.layout.StackPane?> <StackPane fx:id="vista1" xmlns:fx="http://javafx.com/fxml" fx:controller="Vista2Controller"> <children> <Button mnemonicParsing="false" onAction="#previousPane" text="Previous Pane" /> </children> </StackPane>