Author: echatellier Date: 2012-06-29 23:36:18 +0200 (Fri, 29 Jun 2012) New Revision: 553 Url: http://nuiton.org/repositories/revision/sandbox/553 Log: Fix application init. Add test dialog. Added: textjfx/src/main/java/org/codelutin/jfx/ModalDialog.java Modified: textjfx/src/main/java/org/codelutin/jfx/MainView.java textjfx/src/main/resources/MainView.fxml Modified: textjfx/src/main/java/org/codelutin/jfx/MainView.java =================================================================== --- textjfx/src/main/java/org/codelutin/jfx/MainView.java 2012-06-29 19:58:58 UTC (rev 552) +++ textjfx/src/main/java/org/codelutin/jfx/MainView.java 2012-06-29 21:36:18 UTC (rev 553) @@ -18,12 +18,16 @@ package org.codelutin.jfx; import java.io.IOException; +import java.net.URL; import java.util.Arrays; +import java.util.ResourceBundle; import javafx.application.Application; +import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; import javafx.scene.Scene; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; @@ -37,60 +41,83 @@ * @author ceric35 * Date : 7 mai 2012 */ -public class MainView extends Application { +public class MainView extends Application implements Initializable { @FXML protected TreeView treeView; + protected Stage primaryStage; + public static void main(String[] args) { launch(args); } + public void initialize(URL arg0, ResourceBundle arg1) { + + final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); + treeRoot.getChildren().addAll(Arrays.asList( + new TreeItem<String>("Child Node 1"), + new TreeItem<String>("Child Node 2"), + new TreeItem<String>("Child Node 3"))); + + treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList( + new TreeItem<String>("Child Node 4"), + new TreeItem<String>("Child Node 5"), + new TreeItem<String>("Child Node 6"), + new TreeItem<String>("Child Node 7"), + new TreeItem<String>("Child Node 8"), + new TreeItem<String>("Child Node 9"), + new TreeItem<String>("Child Node 10"), + new TreeItem<String>("Child Node 11"), + new TreeItem<String>("Child Node 12"))); + treeView.setRoot(treeRoot); + + } + /* * @see javafx.application.Application#start(javafx.stage.Stage) */ @Override public void start(Stage primaryStage) throws Exception { + this.primaryStage = primaryStage; primaryStage.setTitle("fxTimer"); Scene scene = (Scene)FXMLLoader.load(getClass().getResource("/MainView.fxml")); primaryStage.setScene(scene); primaryStage.sizeToScene(); + + /*primaryStage.setOnShown(new EventHandler<WindowEvent>() { + public void handle(WindowEvent arg0) { + loadTree(null); + } + });*/ + primaryStage.show(); } @FXML protected void quit() { - System.exit(0); + Platform.exit(); } @FXML protected void loadTree(ActionEvent event) { - final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); - treeRoot.getChildren().addAll(Arrays.asList( - new TreeItem<String>("Child Node 1"), - new TreeItem<String>("Child Node 2"), - new TreeItem<String>("Child Node 3"))); - - treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList( - new TreeItem<String>("Child Node 4"), - new TreeItem<String>("Child Node 5"), - new TreeItem<String>("Child Node 6"), - new TreeItem<String>("Child Node 7"), - new TreeItem<String>("Child Node 8"), - new TreeItem<String>("Child Node 9"), - new TreeItem<String>("Child Node 10"), - new TreeItem<String>("Child Node 11"), - new TreeItem<String>("Child Node 12"))); - treeView.setRoot(treeRoot); + } - + @FXML + protected void newTask(ActionEvent event) { + ModalDialog d = new ModalDialog(primaryStage); + } + + @FXML protected void showReport(ActionEvent event) throws IOException { Stage newStage = new Stage(); Scene scene = (Scene)FXMLLoader.load(getClass().getResource("/ReportView.fxml")); newStage.setScene(scene); newStage.show(); } + + } Added: textjfx/src/main/java/org/codelutin/jfx/ModalDialog.java =================================================================== --- textjfx/src/main/java/org/codelutin/jfx/ModalDialog.java (rev 0) +++ textjfx/src/main/java/org/codelutin/jfx/ModalDialog.java 2012-06-29 21:36:18 UTC (rev 553) @@ -0,0 +1,47 @@ +package org.codelutin.jfx; + +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.Group; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.paint.Color; +import javafx.stage.Modality; +import javafx.stage.Stage; + +public class ModalDialog { + Button btn; + TextField textfield; + + public ModalDialog(final Stage stg) { + btn = new Button(); + + final Stage stage = new Stage(); + //Initialize the Stage with type of modal + stage.initModality(Modality.APPLICATION_MODAL); + //Set the owner of the Stage + stage.initOwner(stg); + stage.setTitle("Top Stage With Modality"); + Group root = new Group(); + Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN); + + btn.setOnAction(new EventHandler<ActionEvent>() { + + public void handle(ActionEvent event) { + stage.hide(); + + } + }); + + btn.setLayoutX(100); + btn.setLayoutY(80); + btn.setText("OK"); + + root.getChildren().add(btn); + stage.setScene(scene); + stage.show(); + + } + +} \ No newline at end of file Modified: textjfx/src/main/resources/MainView.fxml =================================================================== --- textjfx/src/main/resources/MainView.fxml 2012-06-29 19:58:58 UTC (rev 552) +++ textjfx/src/main/resources/MainView.fxml 2012-06-29 21:36:18 UTC (rev 553) @@ -23,15 +23,15 @@ </Menu> <Menu text="Project"> <items> - <MenuItem text="New _project" onAction="#loadTree"/> - <MenuItem text="Edit project" onAction="#loadTree"/> - <MenuItem text="Open/Close project" onAction="#loadTree"/> - <MenuItem text="Delete project" onAction="#loadTree"/> + <MenuItem text="New _project" /> + <MenuItem text="Edit project" /> + <MenuItem text="Open/Close project" /> + <MenuItem text="Delete project" /> </items> </Menu> <Menu text="Task"> <items> - <MenuItem text="_New task" mnemonicParsing="true" /> + <MenuItem text="_New task" mnemonicParsing="true" onAction="#newTask" /> <MenuItem text="Edit task"/> <MenuItem text="Open/Close task"/> <MenuItem text="Delete task"/>