Example usage for javafx.concurrent Task getValue

List of usage examples for javafx.concurrent Task getValue

Introduction

In this page you can find the example usage for javafx.concurrent Task getValue.

Prototype

@Override
    public final V getValue() 

Source Link

Usage

From source file:benedict.zhang.addon.soundmanager.controller.SoundManagerController.java

public void doSearchAction(ActionEvent e) {
    soundList.clear();//from ww  w .j  ava 2  s  . c  o  m
    this.btnSearch.setDisable(true);
    Task<List> queryTask = new SoundQueryTask(this.soundName.getText(), this.actor.getText());
    queryTask.setOnSucceeded((WorkerStateEvent event) -> {
        List<Sound> resultList = queryTask.getValue();
        for (int i = 0; i < resultList.size(); i++) {
            resultList.get(i).setNo(new Integer(i + 1));
        }
        this.btnSearch.setDisable(false);
        soundList.setAll(resultList);
    });
    queryTask.run();
}

From source file:ninja.eivind.hotsreplayuploader.window.HomeController.java

private void checkNewVersion() {
    final Task<Optional<GitHubRelease>> task = new Task<Optional<GitHubRelease>>() {
        @Override/*from   ww  w  . j  a  va 2 s  . c  om*/
        protected Optional<GitHubRelease> call() throws Exception {
            return releaseManager.getNewerVersionIfAny();
        }
    };
    task.setOnSucceeded(event -> task.getValue().ifPresent(this::displayUpdateMessage));
    new Thread(task).start();
}

From source file:frontend.GUIController.java

public Thread processInput(Runnable rSuccess, Runnable rFail) throws Exception {
    System.out.println("Steping to next step...");
    progressBar.progressProperty().unbind();
    progressMessage.textProperty().unbind();
    next1.setDisable(true);//  w  w w.j av  a  2 s .  c  om
    final ArrayList<String> comboBoxValues = new ArrayList<String>();
    for (ComboBox<String> c : comboBoxes) {
        comboBoxValues.add(c.getValue());
    }
    Task<Boolean> t = new Task<Boolean>() {
        @Override
        protected Boolean call() throws Exception {
            updateMessage("Doing Prediction");
            updateProgress(3, 10);
            int status = at.processAfterLoadFile(comboBoxValues, predModel.getValue(), visualize.isSelected(),
                    predicted.isSelected());
            if (status > 0) {
                System.err.println("ProcessAfterLoadFile Error occured.");
                return false;
            }
            updateMessage("Finished Prediction");
            if (visualize.isSelected()) {
                updateProgress(5, 10);
                at.showVisualization();
                updateMessage("Finished Visualization");
                updateProgress(8, 10);
            }
            updateProgress(10, 10);
            updateMessage("Done");

            //webpage.getChildren().add(new Browser(url));
            //at.addTweets(at.outputDir+"/visualization/Sentiment.tsv", personData);
            return true;
        };

        @Override
        protected void succeeded() {
            super.succeeded();
            updateMessage("Done!");
        }

        @Override
        protected void cancelled() {
            super.cancelled();
            updateMessage("Cancelled!");
        }

        @Override
        protected void failed() {
            super.failed();
            updateMessage("Failed!");
        }

        @Override
        protected void done() {
            super.done();
            updateMessage("Done!");
        }
    };
    progressBar.progressProperty().bind(t.progressProperty());
    progressMessage.textProperty().bind(t.messageProperty());

    t.setOnSucceeded(new EventHandler<WorkerStateEvent>() {

        @Override
        public void handle(WorkerStateEvent event) {
            if (t.getValue()) {
                Platform.runLater(rSuccess);
            } else {
                Platform.runLater(rFail);
            }
        }
    });

    Thread mythread = new Thread(t);
    mythread.start();
    return mythread;
}

From source file:poe.trade.assist.Main.java

public void manualTaskRun(Search search) {
    String url = search.getUrl();
    if (isNotBlank(url)) {
        Task<Search> task = new Task<Search>() {
            @Override//w  w w  .  j a  va2s . c om
            protected Search call() throws Exception {
                String html = AutoSearchService.doDownload(search.getUrl(), search.getSort());
                search.setHtml(html);
                search.parseHtml();
                return search;
            }
        };
        resultPane.progressIndicator.visibleProperty().unbind();
        resultPane.progressIndicator.visibleProperty().bind(task.runningProperty());
        task.setOnSucceeded(e -> {
            resultPane.setSearch(task.getValue());
            //            refreshResultColumn();
        });
        task.setOnFailed(e -> {
            Dialogs.showError(task.getException());
            //            refreshResultColumn();
        });
        new Thread(task).start();
    } else {
        resultPane.setSearch(search);
    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintDate(Chat chat, String day) {
    //this method draws the recievied text message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//from  w  w  w.ja  v a2s . c  o  m
        protected HBox call() throws Exception {

            VBox vbox = new VBox(); //to add text

            //chat message
            Label l = new Label(day);
            l.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null)));

            HBox hbox = new HBox();
            hbox.setAlignment(Pos.CENTER);
            hbox.getChildren().addAll(l);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());

    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
        //t.setDaemon(true);
        t.start();
        scrollPane.setVvalue(scrollPane.getHmax());
    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedMessage(Chat chat, String msg, String time) {
    //this method draws the recievied text message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//from   w ww  .jav a 2  s  .co  m
        protected HBox call() throws Exception {

            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            //chat message
            BubbledLabel bbl = new BubbledLabel();
            bbl.setText(msg);
            bbl.setBackground(new Background(new BackgroundFill(Color.GAINSBORO, null, null)));

            vbox.getChildren().addAll(chatterName, bbl, timeL);
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());

    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        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);
        }
        scrollPane.setVvalue(scrollPane.getHmax());
    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintWarningInRecieve(Chat chat, String Warning, String time) {
    //this method draws the recievied text message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//w  ww .ja  v a 2 s.c  om
        protected HBox call() throws Exception {

            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            //chat message
            BubbledLabel bbl = new BubbledLabel();
            bbl.setText(Warning);
            bbl.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));

            vbox.getChildren().addAll(chatterName, bbl, timeL);
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
        scrollPane.setVvalue(scrollPane.getHmax());
        scrollPane.setVvalue(scrollPane.getHmax());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
        //t.setDaemon(true);

    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedPhotoLoad(Chat chat, File recievedFile, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override/* w  w w  .  ja v a2 s .c  o  m*/
        protected HBox call() throws Exception {
            Thread.sleep(100);
            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            try {
                Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null);
                ImageView receivedImageView = new ImageView(recievedImage);
                receivedImageView.setFitHeight(300);
                receivedImageView.setFitWidth(300);
                receivedImageView.setPreserveRatio(true);

                receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Desktop dt = Desktop.getDesktop();
                            try {
                                dt.open(recievedFile);
                            } catch (IOException ex) {
                                Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }
                });

                receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.HAND);
                    }
                });

                receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.DEFAULT);
                    }
                });

                vbox.getChildren().addAll(chatterName, receivedImageView, timeL);
            } catch (IOException e) {
                e.printStackTrace();
            }
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedPhotoOnTransmit(Chat chat, File recievedFile, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//w ww  .  j  a  v  a  2 s. c  o m
        protected HBox call() throws Exception {
            VBox vbox = new VBox(); //to add text
            Thread.sleep(2000);
            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            try {
                Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null);
                ImageView receivedImageView = new ImageView(recievedImage);
                receivedImageView.setFitHeight(300);
                receivedImageView.setFitWidth(300);
                receivedImageView.setPreserveRatio(true);

                receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Desktop dt = Desktop.getDesktop();
                            try {
                                dt.open(recievedFile);
                            } catch (IOException ex) {
                                Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }
                });

                receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.HAND);
                    }
                });

                receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.DEFAULT);
                    }
                });

                vbox.getChildren().addAll(chatterName, receivedImageView, timeL);
            } catch (IOException e) {
                e.printStackTrace();
            }
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });
    //set the received chat message appear on the screen
    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
    }
    Task t = new Task() {
        @Override
        protected Object call() throws Exception {
            Thread.sleep(2500);
            return new Object();
        }
    };

    t.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax()));

    Thread thread1 = new Thread(t);
    thread1.start();
}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedFile(Chat chat, String path, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//w  w  w  . j  a  v a  2 s. co m
        protected HBox call() throws Exception {
            Thread.sleep(100);
            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            Hyperlink link = new Hyperlink("File Recieved: " + path);
            link.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<javafx.scene.input.MouseEvent>() {
                @Override
                public void handle(javafx.scene.input.MouseEvent event) {
                    try {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Runtime.getRuntime().exec("explorer.exe /select," + path);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
            vbox.getChildren().addAll(chatterName, link, timeL);
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        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);
        }
    }
    //set the received chat message appear on the screen
    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
    }
    Task t = new Task() {
        @Override
        protected Object call() throws Exception {
            Thread.sleep(2500);
            return new Object();
        }
    };

    t.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax()));

    Thread thread1 = new Thread(t);
    thread1.start();

}