List of usage examples for javafx.scene.image ImageView fitWidthProperty
public final DoubleProperty fitWidthProperty()
From source file:org.jevis.jeconfig.JEConfig.java
/** * Get an imge in the given size from the common * * @param icon//from ww w . j a v a 2 s . c o m * @param height * @param width * @return */ public static ImageView getImage(String icon, double height, double width) { ImageView image = new ImageView(JEConfig.getImage(icon)); image.fitHeightProperty().set(height); image.fitWidthProperty().set(width); return image; }
From source file:snpviewer.SnpViewer.java
private void clearSplitPanes() { for (Iterator it = chromSplitPane.getItems().iterator(); it.hasNext();) { Object child = it.next(); if (child instanceof Pane) { Pane p = (Pane) child;/* ww w .java2 s . c om*/ for (Iterator pit = p.getChildren().iterator(); pit.hasNext();) { Object pChild = pit.next(); if (pChild instanceof ImageView) { ImageView i = (ImageView) pChild; i.fitHeightProperty().unbind(); i.fitWidthProperty().unbind(); } else if (pChild instanceof Line) { Line l = (Line) pChild; l.startXProperty().unbind(); l.endXProperty().unbind(); l.startYProperty().unbind(); l.endYProperty().unbind(); } } p.minWidthProperty().unbind(); p.minHeightProperty().unbind(); } } for (Iterator it = labelSplitPane.getItems().iterator(); it.hasNext();) { Object child = it.next(); if (child instanceof Pane) { Pane p = (Pane) child; p.minWidthProperty().unbind(); p.minHeightProperty().unbind(); } } chromSplitPane.getItems().clear(); labelSplitPane.getItems().clear(); }
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);//from w ww . j a v a2 s . c om //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(); } }
From source file:snpviewer.SnpViewer.java
public void convertSampleViewToImage(final SnpFile s, final Pane pane, final String chrom, final String path) { WritableImage image;/*from w w w .j a v a 2 s . co m*/ try { image = pane.snapshot(null, null); } catch (IllegalStateException ex) { Dialogs.showErrorDialog(null, "Error while attempting to convert" + " view to image file", "PNG conversion failed", "SNP Viewer", ex); return; } final DrawPaneToPng drawToPng = new DrawPaneToPng(image); drawToPng.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { File pngFile; if (path != null && path.length() > 0) { pngFile = new File(s.getOutputDirectoryName() + "/" + path + "/" + chrom + ".png"); } else { pngFile = new File(s.getOutputDirectoryName() + "/" + chrom + ".png"); } try { if (!pngFile.getParentFile().exists()) { boolean madeDir = pngFile.getParentFile().mkdir(); if (madeDir == false) { Dialogs.showErrorDialog(null, "Unable to make sub directory" + " when converting dynamic view to image file. Please " + "check permissions.", "PNG conversion failed", "SNP Viewer"); return; } } Files.copy(drawToPng.getImageFile().toPath(), pngFile.toPath(), REPLACE_EXISTING); BufferedImage bufferedImage = ImageIO.read(pngFile); Image image = SwingFXUtils.toFXImage(bufferedImage, null); ImageView chromImage = new ImageView(image); // chromImage.setCache(true); for (Iterator it = pane.getChildren().iterator(); it.hasNext();) { Object line = it.next(); if (line instanceof Line) { /*Line l = (Line) line; l.startXProperty().unbind(); l.endXProperty().unbind(); l.endYProperty().unbind();*/ } else if (line instanceof ImageView) { ImageView l = (ImageView) line; l.fitHeightProperty().unbind(); l.fitWidthProperty().unbind(); } } pane.getChildren().clear(); pane.getChildren().add(chromImage); chromImage.fitWidthProperty().bind(pane.widthProperty()); chromImage.fitHeightProperty().bind(pane.heightProperty()); } catch (IOException ex) { Dialogs.showErrorDialog(null, "IOException while attempting to convert" + " dynamic view to image file", "PNG conversion failed", "SNP Viewer", ex); } } }); drawToPng.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { Dialogs.showErrorDialog(null, "Error attempting to convert" + " dynamic view to image file", "PNG conversion failed", "SNP Viewer"); } }); drawToPng.start(); }