List of usage examples for javafx.scene.image ImageView ImageView
public ImageView()
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException { log.info("Caching " + dir.getAbsolutePath()); TreeItem<Path> root = new TreeItem<>(dir.toPath()); root.setExpanded(false);/* www.j av a2 s.c o m*/ File[] files = dir.listFiles(); final String I18N_CACHE_TEXT = I18N.getString("TokenTool.treeview.caching"); final Task<Void> task = new Task<Void>() { @Override protected Void call() throws Exception { for (File file : files) { if (loadOverlaysThread.isInterrupted()) break; if (file.isDirectory()) { cacheOverlays(file, root, THUMB_SIZE); } else { Path filePath = file.toPath(); TreeItem<Path> imageNode = new TreeItem<>(filePath, ImageUtil.getOverlayThumb(new ImageView(), filePath)); root.getChildren().add(imageNode); loadCount.getAndIncrement(); overlayTreeProgressBar.progressProperty().set(loadCount.doubleValue() / overlayCount); } } if (parent != null) { // When we show the overlay image, the TreeItem value is empty so we need to // sort those to the bottom for a cleaner look and keep sub dir's at the top. // If a node has no children then it's an overlay, otherwise it's a directory... root.getChildren().sort(new Comparator<TreeItem<Path>>() { @Override public int compare(TreeItem<Path> o1, TreeItem<Path> o2) { if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0) return 0; else if (o1.getChildren().size() == 0) return Integer.MAX_VALUE; else if (o2.getChildren().size() == 0) return Integer.MIN_VALUE; else return o1.getValue().compareTo(o2.getValue()); } }); parent.getChildren().add(root); parent.getChildren().sort(new Comparator<TreeItem<Path>>() { @Override public int compare(TreeItem<Path> o1, TreeItem<Path> o2) { if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0) return 0; else if (o1.getChildren().size() == 0) return Integer.MAX_VALUE; else if (o2.getChildren().size() == 0) return Integer.MIN_VALUE; else return o1.getValue().compareTo(o2.getValue()); } }); } return null; } }; overlayTreeProgressBar.progressProperty().addListener(observable -> { Platform.runLater(() -> progressBarLabel .setText(I18N_CACHE_TEXT + Math.round(overlayCount - loadCount.doubleValue()) + "...")); }); // Only add this listener to the parent task so it's only called once if (parent == null) { overlayTreeProgressBar.progressProperty().addListener(observable -> { Platform.runLater(() -> { if (overlayTreeProgressBar.getProgress() >= 1) treeViewFinish(); }); }); } executorService.execute(task); return root; }
From source file:ui.main.MainViewController.java
private void paintConversationMessage(Message msg) { //this method draws the recievied text message Task<HBox> recievedMessages = new Task<HBox>() { @Override//from w ww . j a v a2s.com protected HBox call() throws Exception { VBox vbox = new VBox(); //to add text String user = msg.getFrom(); user = user.substring(user.indexOf("/") + 1, user.length()); ImageView imageView = new ImageView(); //image imageView.setFitHeight(60); imageView.setFitWidth(50); VCard vcard = new VCard(); try { vcard.load(ConnectionManager.getConnectionManager().getXMPPConnection(), user.concat(AppData.serviceNameAt)); if (vcard.getAvatar() != null) { BufferedImage img = ImageIO.read(new ByteArrayInputStream(vcard.getAvatar())); Image image = SwingFXUtils.toFXImage(img, null); imageView.setImage(image); } else { Image defaultAvatar = new Image("resources/defaultAvatar.png", 50, 60, true, true); imageView.setImage(defaultAvatar); } } catch (XMPPException e) { Image defaultAvatar = new Image("resources/defaultAvatar.png", 50, 60, true, true); imageView.setImage(defaultAvatar); System.out.println(e); } Label chatterName = new Label(user); chatterName.setDisable(true); //chat message BubbledLabel bbl = new BubbledLabel(); bbl.setText(msg.getBody()); bbl.setBackground(new Background(new BackgroundFill(Color.GAINSBORO, null, null))); vbox.getChildren().addAll(chatterName, bbl); vbox.setAlignment(Pos.CENTER_RIGHT); HBox hbox = new HBox(); bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER); hbox.getChildren().addAll(imageView, vbox); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); Thread t = new Thread(recievedMessages); //t.setDaemon(true); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } Task t1 = new Task() { @Override protected Object call() throws Exception { Thread.sleep(500); return new Object(); } }; t1.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax())); Thread thread1 = new Thread(t1); thread1.start(); }