List of usage examples for javafx.fxml FXMLLoader load
public <T> T load() throws IOException
From source file:gmailclientfx.controllers.NedovrseneController.java
public void fetchNedovrsene() { ObservableList<MyMessage> data = FXCollections.observableArrayList(); stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId")); stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject")); stupacTo.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender")); stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived")); nedovrseneTable.setItems(data);// ww w . j a v a 2s . co m nedovrseneTable.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isPrimaryButtonDown() && event.getClickCount() == 2) { MyMessage selectedMsg = nedovrseneTable.getSelectionModel().getSelectedItem(); PregledEmailaHelper.setMsg(selectedMsg); try { Parent root; FXMLLoader loader = new FXMLLoader(); loader.setLocation( getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml")); root = loader.load(); Stage stage = new Stage(); stage.setScene(new Scene(root)); stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - " + PregledEmailaHelper.getMsg().getSender()); stage.show(); PregledEmailaController pgec = loader.getController(); stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { pgec.bodyWebViewEngine.load(null); System.out.println("Closing form!"); } }); } catch (IOException ex) { Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex); } } } }); try { IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(), GmailClient.getAccesToken(), true); Folder nedovrsene = null; Folder[] folders = store.getDefaultFolder().list("*"); for (Folder f : folders) { IMAPFolder imapFolder = (IMAPFolder) f; for (String att : imapFolder.getAttributes()) { if ("\\Drafts".equals(att)) { nedovrsene = f; } } } nedovrsene.open(Folder.READ_WRITE); MimeMessage[] seenMessages = (MimeMessage[]) nedovrsene .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true)); for (int i = 0; i < seenMessages.length; i++) { MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "DRAFT"); data.add(msg); } MimeMessage[] unseenMessages = (MimeMessage[]) nedovrsene .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); for (int i = 0; i < unseenMessages.length; i++) { MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "DRAFT"); data.add(msg); } nedovrsene.close(false); store.close(); } catch (Exception ex) { Logger.getLogger(NedovrseneController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:aajavafx.EmployeeController.java
@FXML private void handleGoBack(ActionEvent event) { //labelError.setText(null); try {//from w w w. ja v a 2 s . c om Node node = (Node) event.getSource(); Stage stage = (Stage) node.getScene().getWindow(); FXMLLoader loader = new FXMLLoader(getClass().getResource("MainPageTab.fxml")); Parent root = loader.load(); Scene scene = new Scene(root, 879, 599); stage.setScene(scene); stage.setTitle("Main menu"); stage.show(); } catch (Exception ex) { Logger.getLogger(MainPageController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.bekwam.mavenpomupdater.Main.java
@Override public void start(Stage primaryStage) throws Exception { ////from w w w. j av a 2 s .c o m // handle command line options // Application.Parameters params = getParameters(); List<String> unnamedList = params.getUnnamed(); Options options = new Options(); options.addOption("help", false, "Print this message"); options.addOption("hidpi", false, "Use high-DPI scaling"); CommandLineParser p = new BasicParser(); CommandLine cmd = p.parse(options, unnamedList.toArray(new String[0])); HelpFormatter formatter = new HelpFormatter(); if (cmd.hasOption("help")) { if (log.isDebugEnabled()) { log.debug("[START] running as help command"); } formatter.printHelp("Main", options); return; } AbstractModule module = null; if (runningAsJNLP()) { if (log.isInfoEnabled()) { log.info("using jnlp module and jnlp favorites store"); } module = new MPUJNLPModule(); } else { if (log.isInfoEnabled()) { log.info("using standalone module and in-memory favorites store"); } module = new MPUStandaloneModule(); } // // setup google guice // final Injector injector = Guice.createInjector(module); BuilderFactory builderFactory = new JavaFXBuilderFactory(); Callback<Class<?>, Object> guiceControllerFactory = clazz -> injector.getInstance(clazz); // // setup icons // primaryStage.getIcons().add(new Image("images/mpu_icon_64.png")); // // load fxml and wire controllers // FXMLLoader mainViewLoader = new FXMLLoader(getClass().getResource("mavenpomupdater.fxml"), null, builderFactory, guiceControllerFactory); Parent mainView = mainViewLoader.load(); MainViewController mainViewController = mainViewLoader.getController(); FXMLLoader alertViewLoader = new FXMLLoader(getClass().getResource("alert.fxml"), null, builderFactory, guiceControllerFactory); Parent alertView = alertViewLoader.load(); // // i'm continuing this manual wiring to 1) accommodate a potential // bi-directional reference problem and 2) to make sure that guice // doesn't return different object for the main -> alert and alert -> // main dependency injections // final AlertController alertController = alertViewLoader.getController(); mainViewController.alertController = alertController; alertController.mainViewControllerRef = new WeakReference<MainViewController>(mainViewController); // // add FlowPane, StackPane objects (defined in program and outside of // FXML) // final FlowPane fp = new FlowPane(); fp.setAlignment(Pos.CENTER); fp.getChildren().add(alertView); fp.getStyleClass().add("alert-background-pane"); final StackPane sp = new StackPane(); sp.getChildren().add(fp); // initially hide the alert sp.getChildren().add(mainView); // // setup scene // Scene scene = new Scene(sp); scene.getStylesheets().add("com/bekwam/mavenpomupdater/mpu.css"); scene.setOnKeyPressed(keyEvent -> { KeyCode key = keyEvent.getCode(); if (key == KeyCode.ESCAPE && (sp.getChildren().get(1) == fp)) { if (log.isDebugEnabled()) { log.debug("[ESCAPE]"); } alertController.action(); } }); // // setup stage // primaryStage.setTitle("Maven POM Version Updater"); primaryStage.setScene(scene); if (cmd.hasOption("hidpi")) { if (log.isInfoEnabled()) { log.info("running in Hi-DPI display mode"); } primaryStage.setWidth(2560.0); primaryStage.setHeight(1440.0); primaryStage.setMinWidth(1920.0); primaryStage.setMinHeight(1080.0); mainViewController.adjustForHiDPI(); } else { if (log.isInfoEnabled()) { log.info("running in normal display mode"); } primaryStage.setWidth(1280.0); primaryStage.setHeight(800.0); primaryStage.setMinWidth(1024.0); primaryStage.setMinHeight(768.0); } primaryStage.show(); }
From source file:sonicScream.controllers.CategoryTabController.java
public CategoryTabController(Category category) { URL location = getClass().getResource("/sonicScream/views/CategoryTab.fxml"); FXMLLoader loader = new FXMLLoader(location); loader.setRoot(this); loader.setController(this); try {// w ww. j a v a2s . c om loader.load(); } catch (IOException ex) { throw new RuntimeException(ex); } _category = category; this.textProperty().bind(_category.categoryNameProperty()); CategoryTabComboBox.setItems(_category.getCategoryScripts()); //These two bindings handle changing between categories with only a single //script (items) and those with multiple (everything else) SimpleListProperty bindableList = new SimpleListProperty(); bindableList.bind(new SimpleObjectProperty<>(_category.getCategoryScripts())); CategoryTabComboBox.visibleProperty().bind(Bindings.greaterThan(bindableList.sizeProperty(), 1)); selectedScriptNodeProperty().bind(CategoryTabTreeView.getSelectionModel().selectedItemProperty()); selectedScript.bind(CategoryTabComboBox.getSelectionModel().selectedItemProperty()); if (_category.getCategoryScripts() != null && !_category.getCategoryScripts().isEmpty()) { CategoryTabComboBox.valueProperty().set(_category.getCategoryScripts().get(0)); handleComboBoxChanged(null); } SwapDisplayModeButton.textProperty().bind(Bindings.when(displayMode.isEqualTo(CategoryDisplayMode.SIMPLE)) .then("Advanced >>").otherwise("<< Simple")); CategoryTabTreeView.getSelectionModel().selectedItemProperty() .addListener((observable, oldValue, newValue) -> { if (newValue != null) { TreeItem<String> scriptValue = TreeUtils.getRootMinusOne((TreeItem<String>) newValue); TreeItem<String> selectedValue = (TreeItem<String>) newValue; CategoryTabScriptValueLabel.setText(scriptValue.getValue()); selectedScriptNodeIsLeaf.set(selectedValue.isLeaf()); } }); }
From source file:gmailclientfx.controllers.InboxController.java
public void fetchInbox() { ObservableList<MyMessage> data = FXCollections.observableArrayList(); stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId")); stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject")); stupacPosiljatelj.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender")); stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived")); Platform.runLater(() -> {/*from w w w . java2s .c o m*/ inboxTable.setItems(data); }); inboxTable.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isPrimaryButtonDown() && event.getClickCount() == 2) { MyMessage selectedMsg = inboxTable.getSelectionModel().getSelectedItem(); PregledEmailaHelper.setMsg(selectedMsg); try { Parent root; FXMLLoader loader = new FXMLLoader(); loader.setLocation( getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml")); root = loader.load(); Stage stage = new Stage(); stage.setScene(new Scene(root)); stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - " + PregledEmailaHelper.getMsg().getSender()); stage.show(); PregledEmailaController pgec = loader.getController(); stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { pgec.bodyWebViewEngine.load(null); System.out.println("Closing form!"); } }); } catch (IOException ex) { Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex); } } } }); try { IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(), GmailClient.getAccesToken(), true); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); int getSeenCount = inbox.getMessageCount(); FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfileItem.FLAGS); fp.add(FetchProfileItem.CONTENT_INFO); fp.add("X-mailer"); MimeMessage[] seenMessages = (MimeMessage[]) inbox .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true)); for (int i = 0; i < seenMessages.length; i++) { MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "INBOX"); data.add(msg); } MimeMessage[] unseenMessages = (MimeMessage[]) inbox .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); for (int i = 0; i < unseenMessages.length; i++) { MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "INBOX"); data.add(msg); } inbox.close(false); store.close(); } catch (Exception ex) { Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.rptools.tokentool.client.TokenTool.java
@Override public void start(Stage primaryStage) throws IOException { stage = primaryStage;/*w ww . ja v a 2 s. c o m*/ setUserAgentStylesheet(STYLESHEET_MODENA); // Setting the style back to the new Modena FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(AppConstants.TOKEN_TOOL_FXML), ResourceBundle.getBundle(AppConstants.TOKEN_TOOL_BUNDLE)); root = fxmlLoader.load(); tokentool_Controller = (TokenTool_Controller) fxmlLoader.getController(); Scene scene = new Scene(root); primaryStage.setTitle(I18N.getString("TokenTool.stage.title")); primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(AppConstants.TOKEN_TOOL_ICON))); primaryStage.setScene(scene); primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaX += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaX > 1 || deltaX < -1) { if (deltaX % 2 == 0) { tokentool_Controller.updatePortraitLocation(deltaX, 0); deltaX = 0; } else { tokentool_Controller.updatePortraitLocation(deltaX - 1, 0); deltaX = 1; } } }); primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaY += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaY > 1 || deltaY < -1) { if (deltaY % 2 == 0) { tokentool_Controller.updatePortraitLocation(0, deltaY); deltaY = 0; } else { tokentool_Controller.updatePortraitLocation(0, deltaY - 1); deltaY = 1; } } }); primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { tokentool_Controller.exitApplication(); } }); // Load all the overlays into the treeview tokentool_Controller.updateOverlayTreeview(overlayTreeItems); // Restore saved settings AppPreferences.restorePreferences(tokentool_Controller); // Add recent list to treeview tokentool_Controller.updateOverlayTreeViewRecentFolder(true); // Set the Overlay Options accordion to be default open view tokentool_Controller.expandOverlayOptionsPane(true); primaryStage.show(); // Finally, update token preview image after everything is done loading Platform.runLater(() -> tokentool_Controller.updateTokenPreviewImageView()); }
From source file:ca.wumbo.doommanager.client.controller.CoreController.java
/** * The starting point of the application. The Core should pass the first * stage (what should be the primary stage) to this method, which will in * turn cascade and create all the /* ww w. j av a2 s .c o m*/ * * @param primaryStage * The stage created by the main JavaFX thread at the beginning. * * @throws IOException * If there is an error loading the FXML file. * * @throws NullPointerException * If the argument is null. */ public void start(Stage primaryStage) throws IOException { if (primaryStage == null) throw new NullPointerException("Passed a null stage to start."); // Load the required data into ourselves. FXMLLoader loader = new FXMLLoader(Client.class.getResource(fxmlPath)); loader.setControllerFactory((cls) -> { return this; }); loader.load(); // Add the loaded tab panes into their respective tabs. mainTab.setContent(startController.getRootPane()); fileEditorTab.setContent(fileEditorController.getRootPane()); mapEditorTab.setContent(mapEditorController.getRootPane()); textureDatabaseTab.setContent(textureDatabaseController.getRootPane()); serverBrowserTab.setContent(serverBrowserController.getRootPane()); ircTab.setContent(ircController.getRootPane()); optionsTab.setContent(optionsController.getRootPane()); consoleTab.setContent(consoleController.getRootPane()); // Set up the scene and stage and display it. ClientConfig clientConfig = config.getClientConfig(); Scene primaryScene = new Scene(rootBorderPane, clientConfig.getStartingWidth(), clientConfig.getStartingHeight()); scene = primaryScene; scene.getStylesheets().add(cssPath); stage = primaryStage; stage.setTitle(applicationTitle + " v" + applicationVersion); stage.setMaximized(clientConfig.isStartMaximized()); stage.setScene(scene); stage.show(); // Start the ticker now that everything is ready to go. ticker = new JavaFXTicker((int) (TICRATE_NANO / MS_PER_NANO), event -> tick()); ticker.start(); // Set up the network connections by starting the selector. if (clientSelector.errorOccured()) { Alert alert = new Alert(Alert.AlertType.WARNING, "Unable to request network channels from OS."); // TODO - make less cryptic. alert.show(); } else if (!clientSelector.selectorIsOpen()) { Alert alert = new Alert(Alert.AlertType.WARNING, "Unable to open network channels."); // TODO - make less cryptic. alert.show(); } // Set up the stage exit handling. stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> ticker.stop()); log.info("Welcome to " + applicationTitle + " v" + applicationVersion + "!"); }
From source file:com.sunkur.springjavafxcontroller.screen.ScreensContoller.java
public void loadScreen(String fxml) { BaseScreenController oldScreenController = this.getCurrentController(); try {/*from ww w. ja va2s . c o m*/ Class controllerClass = FXMLUtils.getControllerClass(fxml); final BaseScreenController fxmlController = (BaseScreenController) applicationContext .getBean(controllerClass); if (this.screens.get(fxmlController.getScreenId()) == null) { FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml)); loader.setControllerFactory(new Callback<Class<?>, Object>() { @Override public Object call(Class<?> aClass) { return fxmlController; } }); Parent root = loader.load(); fxmlController.setRoot(root); this.screens.put(fxmlController.getScreenId(), fxmlController); } this.currentScreenId = fxmlController.getScreenId(); swapScreen(getCurrentController().getRoot()); if (oldScreenController != null) { if (oldScreenController.getClass().isAnnotationPresent(ScreenScoped.class)) { this.screens.remove(oldScreenController.getScreenId()); this.screenScope.remove(oldScreenController.getScreenId()); } } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java
private void initGenerateXPathFromStackTrace() { ContextMenu menu = new ContextMenu(); MenuItem item = new MenuItem("Generate from stack trace..."); item.setOnAction(e -> {/* w ww. j ava 2s .c om*/ try { Stage popup = new Stage(); FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("generate-xpath-from-stack-trace.fxml")); Parent root = loader.load(); Button button = (Button) loader.getNamespace().get("generateButton"); TextArea area = (TextArea) loader.getNamespace().get("stackTraceArea"); ValidationSupport validation = new ValidationSupport(); validation.registerValidator(area, Validator.createEmptyValidator("The stack trace may not be empty")); button.disableProperty().bind(validation.invalidProperty()); button.setOnAction(f -> { DesignerUtil.stackTraceToXPath(area.getText()).ifPresent(xpathExpressionArea::replaceText); popup.close(); }); popup.setScene(new Scene(root)); popup.initStyle(StageStyle.UTILITY); popup.initModality(Modality.WINDOW_MODAL); popup.initOwner(designerRoot.getMainStage()); popup.show(); } catch (IOException e1) { throw new RuntimeException(e1); } }); menu.getItems().add(item); xpathExpressionArea.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> { if (t.getButton() == MouseButton.SECONDARY) { menu.show(xpathExpressionArea, t.getScreenX(), t.getScreenY()); } }); }