/** * La méthode initLayouts permet de récupérer notre vue AjoutCompetition.fxml et appelle le * controller qui lui est lié. */ public void initLayouts() { try { FXMLLoader loader = new FXMLLoader(); loader.setLocation( AjoutCompetition.class.getResource("../../view/Competition/AjoutCompetition.fxml")); GridPane panelPrincipal = (GridPane) loader.load(); panelPrincipal.setStyle("-fx-background-color : " + MonAppli.COLORFENETRE + ";"); rootLayout = new BorderPane(); rootLayout.setPrefWidth(panelPrincipal.getWidth()); rootLayout.setPrefHeight(panelPrincipal.getHeight()); Scene scene = new Scene(rootLayout); this.setScene(scene); rootLayout.setCenter(panelPrincipal); AjoutCompetitionController controller = loader.getController(); controller.setStagesCompetition(this, stageGestion); } catch (IOException e) { e.printStackTrace(); } }
private BorderPane webViewScene() { url = new TextField(); url.setPrefWidth(800); browser = new WebView(); engine = browser.getEngine(); url.setText(fileUrl); engine.load(fileUrl); history = browser.getEngine().getHistory(); backButton = new Button(null, new ImageView(new Image("res/BrowserIcons/back.png"))); backButton.setOnAction( (ActionEvent e) -> { if (!checkIntConnection(defaultUrl)) { alert(); } else browser.getEngine().load(goBack()); }); backButton.addEventHandler( MouseEvent.MOUSE_ENTERED, event -> backButton.setEffect(new DropShadow())); backButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> backButton.setEffect(null)); forwardButton = new Button(null, new ImageView(new Image("res/BrowserIcons/forward.png"))); forwardButton.setOnAction( (ActionEvent e) -> { if (!checkIntConnection(defaultUrl)) { alert(); } else browser.getEngine().load(goForward()); }); forwardButton.addEventHandler( MouseEvent.MOUSE_ENTERED, event -> forwardButton.setEffect(new DropShadow())); forwardButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> forwardButton.setEffect(null)); reloadButton = new Button(null, new ImageView(new Image("res/BrowserIcons/reload.png"))); reloadButton.setOnAction( event -> { if (!checkIntConnection(defaultUrl)) { alert(); } else browser.getEngine().reload(); }); reloadButton.addEventHandler( MouseEvent.MOUSE_ENTERED, event -> reloadButton.setEffect(new DropShadow())); reloadButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> reloadButton.setEffect(null)); goButton = new Button(null, new ImageView(new Image("res/BrowserIcons/go.jpg"))); goButton.setOnAction( event -> { // adding the http or https prefix if user didn't type it if (!checkIntConnection(defaultUrl)) { alert(); } else { if (url.getText().length() > 7 && (url.getText(0, 7).equals("http://") || url.getText(0, 8).equals("https://"))) { browser.getEngine().load(url.getText()); } else if (url.getText().length() > 7 && !url.getText(0, 7).equals("http://")) { browser.getEngine().load("http://" + url.getText()); } else { browser.getEngine().load("https://" + url.getText()); } } }); goButton.addEventHandler( MouseEvent.MOUSE_ENTERED, event -> goButton.setEffect(new DropShadow())); goButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> goButton.setEffect(null)); webHistoryComboBox = new ComboBox(); webHistoryComboBox.setPromptText("Web History"); webHistoryComboBox.setPrefWidth(200); webHistoryComboBox.setOnAction( event -> { // Navigate to the link in the history index int offset = webHistoryComboBox.getSelectionModel().getSelectedIndex() - history.getCurrentIndex(); history.go(offset); }); // Displying browse history in a combo box history .getEntries() .addListener( (ListChangeListener<WebHistory.Entry>) c -> { c.next(); for (WebHistory.Entry e : c.getRemoved()) webHistoryComboBox.getItems().remove(e.getUrl()); for (WebHistory.Entry e : c.getAddedSubList()) webHistoryComboBox.getItems().add(e.getUrl()); }); // Enabling and Disabling back and forward buttons browser .getEngine() .getLoadWorker() .stateProperty() .addListener( (observable, oldValue, newValue) -> { if (!browser.getEngine().getHistory().getEntries().isEmpty()) { int index = browser.getEngine().getHistory().getCurrentIndex(); url.setText(browser.getEngine().getHistory().getEntries().get(index).getUrl()); if (index == 0) { backButton.setDisable(true); } else { backButton.setDisable(false); } if (browser.getEngine().getHistory().getEntries().size() == 1) { forwardButton.setDisable(true); } else if (index < browser.getEngine().getHistory().getEntries().size() - 2) { forwardButton.setDisable(false); } else if (index < browser.getEngine().getHistory().getEntries().size() - 1) { forwardButton.setDisable(false); } else if (index == browser.getEngine().getHistory().getEntries().size() - 1) { forwardButton.setDisable(true); } } }); progress.setPrefSize(25, 25); progress.visibleProperty().bind(browser.getEngine().getLoadWorker().runningProperty()); BorderPane border = new BorderPane(); HBox topBar = new HBox(); topBar.setAlignment(Pos.CENTER); topBar.setSpacing(10); topBar.setPadding(new Insets(10, 10, 10, 10)); topBar .getChildren() .addAll( progress, reloadButton, url, goButton, backButton, forwardButton, webHistoryComboBox); border.setTop(topBar); border.setCenter(browser); border.setPrefHeight(Screen.getPrimary().getVisualBounds().getHeight()); border.setPrefWidth(Screen.getPrimary().getVisualBounds().getWidth()); return border; }