List of usage examples for javafx.scene.layout Pane setVisible
public final void setVisible(boolean value)
From source file:com.github.vatbub.tictactoe.view.Main.java
@FXML // This method is called by the FXMLLoader when initialization is complete void initialize() { // modify the default exception handler to show a good error message on every uncaught exception final Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread .getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> { if (currentUncaughtExceptionHandler != null) { // execute current handler as we only want to append it currentUncaughtExceptionHandler.uncaughtException(thread, exception); }//from ww w.ja va2 s . c o m Platform.runLater(() -> new ExceptionAlert(exception).showAndWait()); }); opponentsTurnHBox.heightProperty() .addListener((observable, oldValue, newValue) -> updateOpponentsTurnHBox(false)); aiLevelLabelClipRectangle = new Rectangle(0, 0, 0, 0); aiLevelLabelClipRectangle.setEffect(new MotionBlur(0, 10)); aiLevelLabelPane.setClip(aiLevelLabelClipRectangle); aiLevelLabelClipRectangle.heightProperty().bind(aiLevelLabelPane.heightProperty()); aiLevelLabelPane.widthProperty().addListener((observable, oldValue, newValue) -> updateAILevelLabel(true)); Rectangle menuSubBoxClipRectangle = new Rectangle(0, 0, 0, 0); menuSubBox.setClip(menuSubBoxClipRectangle); menuSubBoxClipRectangle.heightProperty().bind(menuSubBox.heightProperty()); menuSubBoxClipRectangle.widthProperty().bind(menuSubBox.widthProperty()); Rectangle playOnlineClipRectangle = new Rectangle(0, 0, 0, 0); playOnlineClipAnchorPane.setClip(playOnlineClipRectangle); playOnlineClipRectangle.heightProperty().bind(playOnlineClipAnchorPane.heightProperty()); playOnlineClipRectangle.widthProperty().bind(playOnlineClipAnchorPane.widthProperty()); player1SetSampleName(); player2SetSampleName(); gameTable.heightProperty() .addListener((observable, oldValue, newValue) -> refreshedNodes.refreshAll(gameTable.getWidth(), oldValue.doubleValue(), gameTable.getWidth(), newValue.doubleValue())); gameTable.widthProperty() .addListener((observable, oldValue, newValue) -> refreshedNodes.refreshAll(oldValue.doubleValue(), gameTable.getHeight(), newValue.doubleValue(), gameTable.getHeight())); player1AIToggle.selectedProperty().addListener((observable, oldValue, newValue) -> { showHideAILevelSlider(newValue, player2AIToggle.isSelected()); player1SetSampleName(); }); player2AIToggle.selectedProperty().addListener((observable, oldValue, newValue) -> { showHideAILevelSlider(player1AIToggle.isSelected(), newValue); player2SetSampleName(); }); gameTable.setSelectionModel(null); gameTable.heightProperty().addListener((observable, oldValue, newValue) -> { Pane header = (Pane) gameTable.lookup("TableHeaderRow"); if (header.isVisible()) { header.setMaxHeight(0); header.setMinHeight(0); header.setPrefHeight(0); header.setVisible(false); } renderRows(); }); gameTable.setRowFactory(param -> { TableRow<Row> row = new TableRow<>(); row.styleProperty().bind(style); if (rowFont == null) { rowFont = new SimpleObjectProperty<>(); rowFont.bind(row.fontProperty()); } return row; }); looseImage.fitHeightProperty().bind(looserPane.heightProperty()); looseImage.fitWidthProperty().bind(looserPane.widthProperty()); looseImage.fitHeightProperty().addListener((observable, oldValue, newValue) -> reloadImage(looseImage, getClass().getResource("loose.png").toString(), looseImage.getFitWidth(), newValue.doubleValue())); looseImage.fitWidthProperty().addListener((observable, oldValue, newValue) -> reloadImage(looseImage, getClass().getResource("loose.png").toString(), newValue.doubleValue(), looseImage.getFitWidth())); confetti.fitHeightProperty().bind(winPane.heightProperty()); confetti.fitWidthProperty().bind(winPane.widthProperty()); confetti.fitHeightProperty().addListener((observable, oldValue, newValue) -> reloadImage(confetti, getClass().getResource("confetti.png").toString(), confetti.getFitWidth(), newValue.doubleValue())); confetti.fitWidthProperty().addListener((observable, oldValue, newValue) -> reloadImage(confetti, getClass().getResource("confetti.png").toString(), newValue.doubleValue(), confetti.getFitWidth())); aiLevelSlider.valueProperty().addListener((observable, oldValue, newValue) -> updateAILevelLabel()); playOnlineHyperlink.widthProperty().addListener((observable, oldValue, newValue) -> { if (playOnlineAnchorPane.isVisible()) { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true); } }); playOnlineHyperlink.heightProperty().addListener((observable, oldValue, newValue) -> { if (playOnlineAnchorPane.isVisible()) { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true); } }); playOnlineHyperlink.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.equals(oldValue)) { if (newValue.contains("ff")) { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true, 1); } else { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true, -1); } } }); // Kunami code root.setOnKeyPressed(event -> { if (KunamiCode.isCompleted(event.getCode())) { if (root.getEffect() != null && root.getEffect() instanceof Blend) { BlendMode currentMode = ((Blend) root.getEffect()).getMode(); BlendMode nextMode; if (currentMode == BlendMode.values()[BlendMode.values().length - 1]) { nextMode = BlendMode.values()[0]; } else { nextMode = BlendMode.values()[Arrays.asList(BlendMode.values()).indexOf(currentMode) + 1]; } ((Blend) root.getEffect()).setMode(nextMode); } else { root.setEffect(new Blend(BlendMode.EXCLUSION)); } } }); // prompt text of the my username field in the online multiplayer menu onlineMyUsername.promptTextProperty().bind(player1Name.promptTextProperty()); onlineMyUsername.textProperty().bindBidirectional(player1Name.textProperty()); setAccessibleTextsForNodesThatDoNotChange(); updateAccessibleTexts(); initBoard(); initNewGame(); }
From source file:snpviewer.SnpViewer.java
public void refreshView(String chrom, boolean forceRedraw) { //if forceRedraw is false look for existing png files for each snpFile if (chrom == null) { /*if null is passed then select/reselect chromosome from * chromosomeSelector, return and let chromosomeSelector's * listener refire this method/*from w ww . j a v a 2s . c om*/ */ if (chromosomeSelector.getSelectionModel().isEmpty()) { chromosomeSelector.getSelectionModel().selectFirst(); } else { int sel = chromosomeSelector.getSelectionModel().getSelectedIndex(); chromosomeSelector.getSelectionModel().clearSelection(); chromosomeSelector.getSelectionModel().select(sel); } return; } int totalFiles = affFiles.size() + unFiles.size(); if (totalFiles < 1) { return; } ArrayList<Pane> panesToAdd = new ArrayList<>(); ArrayList<ScrollPane> labelsToAdd = new ArrayList<>(); clearSplitPanes(); setProgressMode(true); nextChromMenu.setDisable(false); nextChromMenu.setDisable(false); for (final SnpFile f : affFiles) { Pane sPane = new Pane(); sPane.setMinHeight(chromSplitPane.getHeight() / totalFiles); sPane.setMinWidth(chromSplitPane.getWidth()); sPane.setVisible(true); panesToAdd.add(sPane); ScrollPane labelPane = new ScrollPane(); Label fileLabel = new Label(f.inputFile.getName() + "\n(Affected)"); fileLabel.setTextFill(Color.WHITE); labelPane.setMinHeight(labelSplitPane.getHeight() / totalFiles); labelPane.setPrefWidth(labelSplitPane.getWidth()); labelPane.minHeightProperty().bind(labelSplitPane.heightProperty().divide(totalFiles)); VBox vbox = new VBox(); vbox.setSpacing(10); vbox.getChildren().add(fileLabel); final TextField textField = new TextField(); textField.setStyle("-fx-text-fill: white; -fx-background-color: " + "rgba(90%,90%,90%,0.3); -fx-border-color:white"); textField.setPromptText("Sample Name"); if (f.getSampleName() != null) { textField.setText(f.getSampleName()); } textField.setFocusTraversable(true); textField.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.ENTER)) { if (!textField.getText().isEmpty()) { String name = textField.getText().trim(); if (name.length() > 0) { f.setSampleName(name); } textField.getParent().requestFocus(); saveProject(); } } } }); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!textField.isFocused()) { if (!textField.getText().isEmpty()) { String name = textField.getText().trim(); if (name.length() > 0) { f.setSampleName(name); } saveProject(); } } } }); vbox.getChildren().add(textField); Label noCalls = new Label(); if (f.getPercentNoCall() != null) { noCalls.setText("No Calls: " + DecimalFormat.getInstance().format(f.getPercentNoCall()) + " %"); } else { noCalls.setText("No Calls: none"); } Label meanQual = new Label(); if (f.getMeanQuality() != null) { meanQual.setText("Av. Call Conf: " + DecimalFormat.getInstance().format(100 - (f.getMeanQuality() * 100)) + " %"); } else { meanQual.setText("No Call Confidence Data"); } vbox.getChildren().add(noCalls); vbox.getChildren().add(meanQual); labelPane.setContent(vbox); // labelPane.getChildren().add(fileLabel); // labelPane.getChildren().add(new TextField()); labelsToAdd.add(labelPane); } for (final SnpFile f : unFiles) { Pane sPane = new Pane(); sPane.setMinHeight(chromSplitPane.getHeight() / totalFiles); sPane.setMinWidth(chromSplitPane.getWidth()); sPane.setVisible(true); panesToAdd.add(sPane); ScrollPane labelPane = new ScrollPane(); Label fileLabel = new Label(f.inputFile.getName() + "\n(Unaffected)"); fileLabel.setStyle("-fx-text-fill: black"); labelPane.setMinHeight(labelSplitPane.getHeight() / totalFiles); labelPane.setPrefWidth(labelSplitPane.getWidth()); labelPane.minHeightProperty().bind(labelSplitPane.heightProperty().divide(totalFiles)); VBox vbox = new VBox(); vbox.setSpacing(10); vbox.getChildren().add(fileLabel); final TextField textField = new TextField(); textField.setStyle("-fx-text-fill: black; " + "-fx-background-color: rgba(90%,90%,90%,0.3);" + " -fx-border-color:white"); textField.setPromptText("Sample Name"); if (f.getSampleName() != null) { textField.setText(f.getSampleName()); } textField.setFocusTraversable(true); textField.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.ENTER)) { if (!textField.getText().isEmpty()) { f.setSampleName(textField.getText()); textField.getParent().requestFocus(); saveProject(); } } } }); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!textField.isFocused()) { if (!textField.getText().isEmpty()) { f.setSampleName(textField.getText()); saveProject(); } } } }); vbox.getChildren().add(textField); Label noCalls = new Label(); if (f.getPercentNoCall() != null) { noCalls.setText("No Calls: " + DecimalFormat.getInstance().format(f.getPercentNoCall()) + " %"); } else { noCalls.setText("No Calls: none"); } Label meanQual = new Label(); if (f.getMeanQuality() != null) { meanQual.setText("Av. Call Conf: " + DecimalFormat.getInstance().format(100 - (f.getMeanQuality() * 100)) + " %"); } else { meanQual.setText("No Call Confidence Data"); } vbox.getChildren().add(noCalls); vbox.getChildren().add(meanQual); labelPane.setContent(vbox); // labelPane.getChildren().add(fileLabel); labelsToAdd.add(labelPane); } if (panesToAdd.size() > 0) { chromSplitPane.getItems().addAll(panesToAdd); labelSplitPane.getItems().addAll(labelsToAdd); ArrayList<SnpFile> bothFiles = new ArrayList<>(affFiles); bothFiles.addAll(unFiles); final Iterator<SnpFile> fileIter = bothFiles.iterator(); final Iterator<Pane> paneIter = panesToAdd.iterator(); SnpFile firstFileToProcess = fileIter.next(); Pane firstPaneToProcess = paneIter.next(); String pngPath = null; if (qualityFilter != null) { Integer percent = new Integer(100 - (int) (qualityFilter * 100)); pngPath = percent.toString(); } drawWithIterator(firstFileToProcess, firstPaneToProcess, pngPath, fileIter, paneIter, 1, totalFiles, chrom, forceRedraw, chromSplitPane); } else { setProgressMode(false); } }
From source file:snpviewer.SnpViewer.java
public void drawCoordinatesWithIterator(final SnpFile sfile, final Pane pane, final String pngPath, final Iterator<SnpFile> sIter, final Iterator<Pane> pIter, final int currentFile, final int totalFiles, final String chrom, final Double start, final Double end, final boolean forceRedraw, final SplitPane splitPane) { Stage stage = (Stage) splitPane.getScene().getWindow(); fixStageSize(stage, true);// www . ja v a 2 s . c o m //stage.setResizable(false);//we have to disable this when using windows due to a bug (in javafx?) File pngFile = new File(sfile.getOutputDirectoryName() + "/" + chrom + ".png"); if (pngPath != null && pngPath.length() > 0) { pngFile = new File(sfile.getOutputDirectoryName() + "/" + pngPath + "/" + chrom + ".png"); } if (!forceRedraw && pngFile.exists()) { try { progressBar.progressProperty().unbind(); progressBar.setProgress((double) currentFile / (double) totalFiles); BufferedImage bufferedImage = ImageIO.read(pngFile); Image image = SwingFXUtils.toFXImage(bufferedImage, null); ImageView chromImage = new ImageView(image); //chromImage.setCache(true); pane.getChildren().clear(); pane.getChildren().add(chromImage); //pane.setCache(true); chromImage.fitWidthProperty().bind(pane.widthProperty()); chromImage.fitHeightProperty().bind(pane.heightProperty()); pane.minHeightProperty().bind(splitPane.heightProperty().divide(totalFiles)); pane.minWidthProperty().bind(splitPane.widthProperty()); if (sIter.hasNext()) { SnpFile nextFile = sIter.next(); Pane nextPane = pIter.next(); drawCoordinatesWithIterator(nextFile, nextPane, pngPath, sIter, pIter, currentFile + 1, totalFiles, chrom, start, end, forceRedraw, splitPane); } else { progressBar.progressProperty().unbind(); progressBar.setProgress(0); setProgressMode(false); fixStageSize(stage, false);//for windows only stage.setResizable(true); } } catch (IOException ex) { Dialogs.showErrorDialog(null, "IO error reading cached image", "Error displaying chromosome image", "SnpViewer", ex); return; } } else { final DrawSnpsToPane draw = new DrawSnpsToPane(pane, sfile, chrom, Colors.aa.value, Colors.bb.value, Colors.ab.value, start, end); progressBar.progressProperty().unbind(); //progressBar.setProgress(0); //progressBar.progressProperty().bind(draw.progressProperty()); progressTitle.setText("Drawing " + currentFile + " of " + totalFiles); progressMessage.textProperty().bind(draw.messageProperty()); cancelButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { draw.cancel(); } }); draw.setOnCancelled(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { progressBar.progressProperty().unbind(); progressBar.setProgress(0); progressTitle.setText("Drawing Cancelled"); progressMessage.textProperty().unbind(); progressMessage.setText("Drawing Cancelled"); setProgressMode(false); selectionOverlayPane.getChildren().clear(); selectionOverlayPane.getChildren().add(dragSelectRectangle); Stage stage = (Stage) splitPane.getScene().getWindow(); stage.setResizable(true); fixStageSize(stage, false);//for windows only } }); draw.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { ArrayList<HashMap<String, Double>> result = (ArrayList<HashMap<String, Double>>) t.getSource() .getValue(); progressBar.progressProperty().unbind(); progressBar.setProgress((double) currentFile / (2 * (double) totalFiles)); progressTitle.setText(""); progressMessage.textProperty().unbind(); progressMessage.setText(""); /*if (pane.getMinHeight() < 200){ pane.setMinHeight(200); } if (pane.getMinWidth() < 800){ pane.setMinWidth(800); }*/ if (result != null) { List<Line> lines = drawLinesToPane(pane, result); pane.getChildren().addAll(lines); pane.setVisible(true); convertSampleViewToImage(sfile, pane, chrom, pngPath); /*for (Line l: lines){ l.startXProperty().unbind(); l.startYProperty().unbind(); l.endXProperty().unbind(); l.endYProperty().unbind(); }*/ lines.clear(); } progressBar.setProgress((double) currentFile / (double) totalFiles); pane.minWidthProperty().bind(splitPane.widthProperty()); pane.minHeightProperty().bind(splitPane.heightProperty().divide(totalFiles)); // pane.setCache(true); if (sIter.hasNext()) { SnpFile nextFile = sIter.next(); Pane nextPane = pIter.next(); drawCoordinatesWithIterator(nextFile, nextPane, pngPath, sIter, pIter, currentFile + 1, totalFiles, chrom, start, end, forceRedraw, splitPane); } else { setProgressMode(false); progressBar.progressProperty().unbind(); progressBar.setProgress(0); Stage stage = (Stage) splitPane.getScene().getWindow(); stage.setResizable(true); fixStageSize(stage, false);//for windows only } } }); draw.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { draw.reset(); progressBar.progressProperty().unbind(); progressBar.setProgress(0); progressTitle.setText("ERROR!"); progressMessage.textProperty().unbind(); progressMessage.setText("Drawing failed!"); setProgressMode(false); selectionOverlayPane.getChildren().clear(); selectionOverlayPane.getChildren().add(dragSelectRectangle); // Stage stage = (Stage) chromSplitPane.getScene().getWindow(); // stage.setResizable(true); } }); draw.start(); } }