Package javafx.concurrent

Examples of javafx.concurrent.Task


        /**
         * Per prima cosa riordino in base alla priorita.
         */
        Collections.sort(data_table, table_comparator);

        Task task = new Task<Void>() {
            @Override
            protected Void call() throws Exception {
                String message = "";
                backup_running = true;
                try {

                    List<File> fileList = Collections.synchronizedList(new ArrayList<>());

                    long millis = System.currentTimeMillis();

                    int prec = 0;
                    int total = data_table.size();

                    for (int i = 0; i < total; i++) {

                        //----------------------------------------------------//
                        EncryptedNode node = data_table.get(i).getNode();
                        String source_path = node.getProperties().get("source");
                        String dest_path = node.getProperties().get("destination");
                        String action = node.getProperties().get("action");
                        //----------------------------------------------------//

                        File file_source = new File(source_path);
                        File file_dest = new File(dest_path);

                        if (!file_source.exists()) {
                            ini.store("last_result_bck", "Error - " + Utility.data());
                            message = "Can't find souce path: " + file_source + "\n";
                            showMessage(message);
                            return null;
                        }

                        if (!file_dest.exists()) {
                            ini.store("last_result_bck", "Error - " + Utility.data());
                            message = message + "Can't find dest. path: " + file_dest;
                            showMessage(message);
                            return null;
                        }
                    }

                    for (int i = 0; i < total; i++) {

                        //----------------------------------------------------//
                        EncryptedNode node = data_table.get(i).getNode();
                        String source_path = node.getProperties().get("source");
                        String dest_path = node.getProperties().get("destination");
                        String action = node.getProperties().get("action");
                        //----------------------------------------------------//

                        File file_source = new File(source_path);
                        File file_dest = new File(dest_path);
                        boolean exits_all = true;

                        if (!file_source.exists()) {
                            ini.store("last_result_bck", "Error - " + Utility.data());
                            message = "Can't find souce path: " + file_source + "\n";
                            exits_all = false;
                        }

                        if (!file_dest.exists()) {
                            ini.store("last_result_bck", "Error - " + Utility.data());
                            message = message + "Can't find dest. path: " + file_dest;
                            exits_all = false;
                        }

                        if (exits_all) {

                            //------------------------------------------------//
                            //------------------------------------------------//
                            //------------------------------------------------//
                            node.getProperties().put("status", "Running");
                            updateTable();

                            fileList.clear();

                            if (!fileList.isEmpty()) {
                                Utility.log("ERROR CAN'T CLEAR FILE LIST!");
                                showMessage("Application Error, can't clear file list.");
                                return null;
                            }

                            //------------------------------------------------//
                            //------------------------------------------------//
                            //------------------------------------------------//
                            /**
                             * Da ricordare che: 1) NIO nella copia dei file mi
                             * da' dei problemi su alcuni attributi per win7,
                             * quindi in caso di errore faccio la copia
                             * "normale" 2) Lo Zip mi dava problemi con le
                             * cartelle vuote quindi le creo io con il path
                             * "cartella/"
                             */
                            switch (action) {
                                case ACTION_ZIP: {
                                    visitor.setAction("Analyse");
                                    Utility.listFiles(file_source, fileList, visitor);
                                    File result = new File(file_dest + File.separator + file_source.getName() + ".zip");
                                    visitor.setAction("Processing");
                                    Utility.createZipFile(result, file_source, fileList, visitor);
                                    break;
                                }
                                case ACTION_COPY: {
                                    if (file_source.isFile()) {
                                        visitor.setAction("Processing");
                                        Utility.copyFile(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
                                    } else {
                                        visitor.setAction("Processing");
                                        Utility.copyRecursively(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
                                    }
                                    break;
                                }
                            }
                            node.getProperties().put("status", "Done");
                            updateTable();

                        } else {
                            showMessage(message);
                            return null;
                        }

                        prec += (i + 1 * 100) / total;
                        updateProgress(prec, 100);
                        setPercentValue(prec);
                    }

                    String __val_total_time = String.format("%d hour, %d min, %d sec",
                            TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis() - millis),
                            TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis),
                            TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - millis)
                            - TimeUnit.MINUTES.toSeconds(
                                    TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis)));

                    setCenterMessage("Backup completed. Time Total: " + __val_total_time);

                    ini.store("last_result_bck", "OK - " + Utility.data());

                } catch (Exception exc) {

                    Utility.exc(exc);
                    exc.printStackTrace();

                    message = exc.getMessage();
                    showMessage(message);

                    ini.store("last_result_bck", "Error - " + Utility.data());

                } finally {
                    Thread.currentThread().sleep(5000);
                    setLastResult();
                }
                return null;
            }

            @Override
            protected void succeeded() {

                backup_running = false;
                setAllStatusValue("");
                setPercentValue(0);
                endProg();
                __btn_bck_add.setDisable(false);
                __btn_bck_remove.setDisable(false);
                __btn_bck_remove_all.setDisable(false);
                __btn_bck_start_backup.setDisable(false);
                super.succeeded();
            }
        };

        prog_bk_total.progressProperty().unbind();
        prog_bk_total.progressProperty().bind(task.progressProperty());

        __btn_bck_add.setDisable(true);
        __btn_bck_remove.setDisable(true);
        __btn_bck_remove_all.setDisable(true);
        __btn_bck_start_backup.setDisable(true);
View Full Code Here


            stopClearClipboardTimer();

            __copy_pane_message.initialize(__main_pane);

            Task task = new Task<Void>() {
                @Override protected Void call() throws Exception {
                    try {

                        boolean fake = false;
                        Map<String, String> settings = getSettings();

                        if (settings != null) {
                            fake = "true".equals(settings.get("key.random.keys"));
                        }

                        if (fake) {

                            final List<String> percent = new ArrayList<>();

                            __copy_pane_message.show();

                            EffectFX.beep();

                            Thread.currentThread().sleep(2000);

                            int[] range_security = {4, 8};
                            int max = Utility.random(range_security[0], range_security[1]);

                            for (int i = 0, prec = 0; i < max; i++) {

                                String rs = Utility.makeStringValue(Utility.random(6, 12));
                                Thread.currentThread().sleep(Utility.random(50, 100));
                                copy(rs);

                                String random = Utility.makeStringValue(Utility.random(3, 5));
                                Thread.currentThread().sleep(Utility.random(50, 100));
                                __robot.paste();
                                __robot.writeDataValue(random);

                                __robot.sLeftCurs(random.length() - 2);
                                __robot.del(Utility.random(1, 2));
                                __robot.enter();

                                prec += (i + 1 * 100) / max;
                                updateProgress(prec, 100);
                                percent.clear();
                                percent.add(prec + "%");
                                Platform.runLater(() -> {
                                    __copy_pane_message.getLblPerc().setText(percent.get(0));
                                });

                                log("updateProgress - prec:" + prec);
                            }
                            updateProgress(100, 100);
                        }

                        copy(value);
                        Thread.currentThread().sleep(200);

                    } catch (Exception exc) {
                        exc.printStackTrace();
                    } finally {
                        if (__copy_pane_message != null) {
                            __copy_pane_message.getProg().progressProperty().unbind();
                            __copy_pane_message.dispose();
                        }
                        startClearClipboardTimer();
                    }

                    return null;
                }
            };

            __copy_pane_message.getProg().progressProperty().unbind();
            __copy_pane_message.getProg().progressProperty().bind(task.progressProperty());
            Thread t = new Thread(task);
            t.setName("TH-copyToClipboard");
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();

View Full Code Here

            stopClearClipboardTimer();

            __copy_pane_message.initialize(__main_pane);

            Task task = new Task<Void>() {
                @Override protected Void call() throws Exception {
                    try {

                        boolean fake = false;
                        Map<String, String> settings = getSettings();

                        if (settings != null) {
                            fake = "true".equals(settings.get("key.random.keys"));
                        }

                        if (fake) {

                            final List<String> percent = new ArrayList<>();

                            __copy_pane_message.show();

                            EffectFX.beep();

                            Thread.currentThread().sleep(2000);

                            int[] range_security = {4, 8};
                            int max = UtilityFX.random(range_security[0], range_security[1]);

                            for (int i = 0, prec = 0; i < max; i++) {

                                String rs = UtilityFX.makeStringValue(UtilityFX.random(6, 12));
                                Thread.currentThread().sleep(UtilityFX.random(50, 100));
                                copy(rs);

                                String random = UtilityFX.makeStringValue(UtilityFX.random(3, 5));
                                Thread.currentThread().sleep(UtilityFX.random(50, 100));
                                __robot.paste();
                                __robot.writeDataValue(random);

                                __robot.sLeftCurs(random.length() - 2);
                                __robot.del(UtilityFX.random(1, 2));
                                __robot.enter();

                                prec += (i + 1 * 100) / max;
                                updateProgress(prec, 100);
                                percent.clear();
                                percent.add(prec + "%");
                                Platform.runLater(() -> {
                                    __copy_pane_message.getLblPerc().setText(percent.get(0));
                                });

                                log("updateProgress - prec:" + prec);
                            }
                            updateProgress(100, 100);
                        }

                        copy(value);
                        Thread.currentThread().sleep(200);

                    } catch (Exception exc) {
                        exc.printStackTrace();
                    } finally {
                        if (__copy_pane_message != null) {
                            __copy_pane_message.getProg().progressProperty().unbind();
                            __copy_pane_message.dispose();
                        }
                        startClearClipboardTimer();
                    }

                    return null;
                }
            };

            __copy_pane_message.getProg().progressProperty().unbind();
            __copy_pane_message.getProg().progressProperty().bind(task.progressProperty());
            Thread t = new Thread(task);
            t.setName("TH-copyToClipboard");
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();

View Full Code Here

        /**
         * Per prima cosa riordino in base alla priorita.
         */
        Collections.sort(data_table, table_comparator);

        Task task = new Task<Void>() {
            @Override
            protected Void call() throws Exception {
                String message = "";
                backup_running = true;
                try {

                    List<File> fileList = Collections.synchronizedList(new ArrayList<>());

                    long millis = System.currentTimeMillis();

                    int prec = 0;
                    int total = data_table.size();

                    for (int i = 0; i < total; i++) {

                        //----------------------------------------------------//
                        EncryptedNode node = data_table.get(i).getNode();
                        String source_path = node.getProperties().get("source");
                        String dest_path = node.getProperties().get("destination");
                        String action = node.getProperties().get("action");
                        //----------------------------------------------------//

                        File file_source = new File(source_path);
                        File file_dest = new File(dest_path);

                        if (!file_source.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = "Can't find souce path: " + file_source + "\n";
                            showMessage(message);
                            return null;
                        }

                        if (!file_dest.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = message + "Can't find dest. path: " + file_dest;
                            showMessage(message);
                            return null;
                        }
                    }

                    for (int i = 0; i < total; i++) {

                        //----------------------------------------------------//
                        EncryptedNode node = data_table.get(i).getNode();
                        String source_path = node.getProperties().get("source");
                        String dest_path = node.getProperties().get("destination");
                        String action = node.getProperties().get("action");
                        //----------------------------------------------------//

                        File file_source = new File(source_path);
                        File file_dest = new File(dest_path);
                        boolean exits_all = true;

                        if (!file_source.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = "Can't find souce path: " + file_source + "\n";
                            exits_all = false;
                        }

                        if (!file_dest.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = message + "Can't find dest. path: " + file_dest;
                            exits_all = false;
                        }

                        if (exits_all) {

                            //------------------------------------------------//
                            //------------------------------------------------//
                            //------------------------------------------------//
                            node.getProperties().put("status", "Running");
                            updateTable();

                            fileList.clear();

                            if (!fileList.isEmpty()) {
                                UtilityFX.log("ERROR CAN'T CLEAR FILE LIST!");
                                showMessage("Application Error, can't clear file list.");
                                return null;
                            }

                            //------------------------------------------------//
                            //------------------------------------------------//
                            //------------------------------------------------//
                            /**
                             * Da ricordare che: 1) NIO nella copia dei file mi
                             * da' dei problemi su alcuni attributi per win7,
                             * quindi in caso di errore faccio la copia
                             * "normale" 2) Lo Zip mi dava problemi con le
                             * cartelle vuote quindi le creo io con il path
                             * "cartella/"
                             */
                            switch (action) {
                                case ACTION_ZIP: {
                                    visitor.setAction("Analyse");
                                    UtilityFX.listFiles(file_source, fileList, visitor);
                                    File result = new File(file_dest + File.separator + file_source.getName() + ".zip");
                                    visitor.setAction("Processing");
                                    UtilityFX.createZipFile(result, file_source, fileList, visitor);
                                    break;
                                }
                                case ACTION_COPY: {
                                    if (file_source.isFile()) {
                                        visitor.setAction("Processing");
                                        UtilityFX.copyFile(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
                                    } else {
                                        visitor.setAction("Processing");
                                        UtilityFX.copyRecursively(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
                                    }
                                    break;
                                }
                            }
                            node.getProperties().put("status", "Done");
                            updateTable();

                        } else {
                            showMessage(message);
                            return null;
                        }

                        prec += (i + 1 * 100) / total;
                        updateProgress(prec, 100);
                        setPercentValue(prec);
                    }

                    String __val_total_time = String.format("%d hour, %d min, %d sec",
                            TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis() - millis),
                            TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis),
                            TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - millis)
                            - TimeUnit.MINUTES.toSeconds(
                                    TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis)));

                    setCenterMessage("Backup completed. Time Total: " + __val_total_time);

                    ini.store("last_result_bck", "OK - " + UtilityFX.data());

                } catch (Exception exc) {

                    UtilityFX.exc(exc);
                    exc.printStackTrace();

                    message = exc.getMessage();
                    showMessage(message);

                    ini.store("last_result_bck", "Error - " + UtilityFX.data());

                } finally {
                    Thread.currentThread().sleep(5000);
                    setLastResult();
                }
                return null;
            }

            @Override
            protected void succeeded() {

                backup_running = false;
                setAllStatusValue("");
                setPercentValue(0);
                endProg();
                __btn_bck_add.setDisable(false);
                __btn_bck_remove.setDisable(false);
                __btn_bck_remove_all.setDisable(false);
                __btn_bck_start_backup.setDisable(false);
                super.succeeded();
            }
        };

        prog_bk_total.progressProperty().unbind();
        prog_bk_total.progressProperty().bind(task.progressProperty());

        __btn_bck_add.setDisable(true);
        __btn_bck_remove.setDisable(true);
        __btn_bck_remove_all.setDisable(true);
        __btn_bck_start_backup.setDisable(true);
View Full Code Here

            stopClearClipboardTimer();

            __copy_pane_message.initialize(__main_pane);

            Task task = new Task<Void>() {
                @Override protected Void call() throws Exception {
                    try {

                        boolean fake = false;
                        Map<String, String> settings = getSettings();

                        if (settings != null) {
                            fake = "true".equals(settings.get("key.random.keys"));
                        }

                        if (fake) {

                            final List<String> percent = new ArrayList<>();

                            __copy_pane_message.show();

                            EffectFX.beep();

                            Thread.currentThread().sleep(2000);

                            int[] range_security = {4, 8};
                            int max = UtilityFX.random(range_security[0], range_security[1]);

                            for (int i = 0, prec = 0; i < max; i++) {

                                String rs = UtilityFX.makeStringValue(UtilityFX.random(6, 12));
                                Thread.currentThread().sleep(UtilityFX.random(50, 100));
                                copy(rs);

                                String random = UtilityFX.makeStringValue(UtilityFX.random(3, 5));
                                Thread.currentThread().sleep(UtilityFX.random(50, 100));
                                __robot.paste();
                                __robot.writeDataValue(random);

                                __robot.sLeftCurs(random.length() - 2);
                                __robot.del(UtilityFX.random(1, 2));
                                __robot.enter();

                                prec += (i + 1 * 100) / max;
                                updateProgress(prec, 100);
                                percent.clear();
                                percent.add(prec + "%");
                                Platform.runLater(() -> {
                                    __copy_pane_message.getLblPerc().setText(percent.get(0));
                                });

                                log("updateProgress - prec:" + prec);
                            }
                            updateProgress(100, 100);
                        }

                        copy(value);
                        Thread.currentThread().sleep(200);

                    } catch (Exception exc) {
                        exc.printStackTrace();
                    } finally {
                        if (__copy_pane_message != null) {
                            __copy_pane_message.getProg().progressProperty().unbind();
                            __copy_pane_message.dispose();
                        }
                        startClearClipboardTimer();
                    }

                    return null;
                }
            };

            __copy_pane_message.getProg().progressProperty().unbind();
            __copy_pane_message.getProg().progressProperty().bind(task.progressProperty());
            Thread t = new Thread(task);
            t.setName("TH-copyToClipboard");
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();

View Full Code Here

        /**
         * Per prima cosa riordino in base alla priorita.
         */
        Collections.sort(data_table, table_comparator);

        Task task = new Task<Void>() {
            @Override
            protected Void call() throws Exception {
                String message = "";
                backup_running = true;
                try {

                    List<File> fileList = Collections.synchronizedList(new ArrayList<>());

                    long millis = System.currentTimeMillis();

                    int prec = 0;
                    int total = data_table.size();

                    for (int i = 0; i < total; i++) {

                        //----------------------------------------------------//
                        EncryptedNode node = data_table.get(i).getNode();
                        String source_path = node.getProperties().get("source");
                        String dest_path = node.getProperties().get("destination");
                        String action = node.getProperties().get("action");
                        //----------------------------------------------------//

                        File file_source = new File(source_path);
                        File file_dest = new File(dest_path);

                        if (!file_source.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = "Can't find souce path: " + file_source + "\n";
                            showMessage(message);
                            return null;
                        }

                        if (!file_dest.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = message + "Can't find dest. path: " + file_dest;
                            showMessage(message);
                            return null;
                        }
                    }

                    for (int i = 0; i < total; i++) {

                        //----------------------------------------------------//
                        EncryptedNode node = data_table.get(i).getNode();
                        String source_path = node.getProperties().get("source");
                        String dest_path = node.getProperties().get("destination");
                        String action = node.getProperties().get("action");
                        //----------------------------------------------------//

                        File file_source = new File(source_path);
                        File file_dest = new File(dest_path);
                        boolean exits_all = true;

                        if (!file_source.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = "Can't find souce path: " + file_source + "\n";
                            exits_all = false;
                        }

                        if (!file_dest.exists()) {
                            ini.store("last_result_bck", "Error - " + UtilityFX.data());
                            message = message + "Can't find dest. path: " + file_dest;
                            exits_all = false;
                        }

                        if (exits_all) {

                            //------------------------------------------------//
                            //------------------------------------------------//
                            //------------------------------------------------//
                            node.getProperties().put("status", "Running");
                            updateTable();

                            fileList.clear();

                            if (!fileList.isEmpty()) {
                                UtilityFX.log("ERROR CAN'T CLEAR FILE LIST!");
                                showMessage("Application Error, can't clear file list.");
                                return null;
                            }

                            //------------------------------------------------//
                            //------------------------------------------------//
                            //------------------------------------------------//
                            /**
                             * Da ricordare che: 1) NIO nella copia dei file mi
                             * da' dei problemi su alcuni attributi per win7,
                             * quindi in caso di errore faccio la copia
                             * "normale" 2) Lo Zip mi dava problemi con le
                             * cartelle vuote quindi le creo io con il path
                             * "cartella/"
                             */
                            switch (action) {
                                case ACTION_ZIP: {
                                    visitor.setAction("Analyse");
                                    UtilityFX.listFiles(file_source, fileList, visitor);
                                    File result = new File(file_dest + File.separator + file_source.getName() + ".zip");
                                    visitor.setAction("Processing");
                                    UtilityFX.createZipFile(result, file_source, fileList, visitor);
                                    break;
                                }
                                case ACTION_COPY: {
                                    if (file_source.isFile()) {
                                        visitor.setAction("Processing");
                                        UtilityFX.copyFile(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
                                    } else {
                                        visitor.setAction("Processing");
                                        UtilityFX.copyRecursively(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
                                    }
                                    break;
                                }
                            }
                            node.getProperties().put("status", "Done");
                            updateTable();

                        } else {
                            showMessage(message);
                            return null;
                        }

                        prec += (i + 1 * 100) / total;
                        updateProgress(prec, 100);
                        setPercentValue(prec);
                    }

                    String __val_total_time = String.format("%d hour, %d min, %d sec",
                            TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis() - millis),
                            TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis),
                            TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - millis)
                            - TimeUnit.MINUTES.toSeconds(
                                    TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis)));

                    setCenterMessage("Backup completed. Time Total: " + __val_total_time);

                    ini.store("last_result_bck", "OK - " + UtilityFX.data());

                } catch (Exception exc) {

                    UtilityFX.exc(exc);
                    exc.printStackTrace();

                    message = exc.getMessage();
                    showMessage(message);

                    ini.store("last_result_bck", "Error - " + UtilityFX.data());

                } finally {
                    Thread.currentThread().sleep(5000);
                    setLastResult();
                }
                return null;
            }

            @Override
            protected void succeeded() {

                backup_running = false;
                setAllStatusValue("");
                setPercentValue(0);
                endProg();
                __btn_bck_add.setDisable(false);
                __btn_bck_remove.setDisable(false);
                __btn_bck_remove_all.setDisable(false);
                __btn_bck_start_backup.setDisable(false);
                super.succeeded();
            }
        };

        prog_bk_total.progressProperty().unbind();
        prog_bk_total.progressProperty().bind(task.progressProperty());

        __btn_bck_add.setDisable(true);
        __btn_bck_remove.setDisable(true);
        __btn_bck_remove_all.setDisable(true);
        __btn_bck_start_backup.setDisable(true);
View Full Code Here

//           
//        }
    }

    public Task fileSenderTask() {
        return new Task() {
            @Override
            protected Object call() throws Exception {
                StringBuilder line = new StringBuilder();
                int gcodeCharLength = data.size();
                String tmp;
View Full Code Here

    @FXML
    private void handleRunFile(ActionEvent evt) {
        if (!isSendingFile.get()) {
            isSendingFile.set(true); //disables jogging while file is running
            taskActive = true; //Set the thread condition to start
            Task fileSend = fileSenderTask();
            Thread fsThread = new Thread(fileSend);
            fsThread.setName("FileSender");
            timeStartDt = new Date();
//            updateProgress(1);
            fsThread.start();
View Full Code Here

        br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8")));
        br2 = new BufferedReader(new InputStreamReader(fis2, Charset.forName("UTF-8")));


        Task task;
        task = new Task<Void>() {
            @Override
            public Void call() throws IOException, Exception {
                String line;
                int maxElements = 0;
                int currentElement = 0;
                String filename = new String();

                while ((line = br2.readLine()) != null) {
                    JSONObject j = new JSONObject(line);
                    maxElements = maxElements + getElementCount(j);
                }

                while ((line = br.readLine()) != null) {
                    if (TinygDriver.getInstance().isConnected().get()) {
                        if (line.startsWith("{\"name")) {
                            //This is the name of the CONFIG lets not write this to TinyG
                            filename = line.split(":")[1];
                            tgfx.Main.postConsoleMessage("[+]Loading " + filename + " config into TinyG... Please Wait...");
                        } else {

                            JSONObject j = new JSONObject(line);

                            String topLevelParent;
                            topLevelParent = (String) j.names().get(0);
                            Iterator it = j.getJSONObject(topLevelParent).keys();

                            while (it.hasNext()) {
                                String k = (String) it.next();
                                Double value = (Double) j.getJSONObject(topLevelParent).getDouble(k);
                                System.out.println("This is the value " + k + " " + decimalFormat.format(value));
                                Main.postConsoleMessage("Applied: " + k + ":" + decimalFormat.format(value));
                                //value = Double.valueOf(decimalFormatjunctionDeviation.format(value));

                                String singleJsonSetting = "{\"" + topLevelParent + k + "\":" + value + "}\n";
                                TinygDriver.getInstance().write(singleJsonSetting);
                                updateProgress(currentElement, maxElements);
                                Thread.sleep(400); //Writing Values to eeprom can take a bit of time..
                                currentElement++;
                            }
                        }
                    }
                }
                updateProgress(0, 0); //reset the progress bar
                Main.postConsoleMessage("Finished Loading " + filename + ".");
                loadbutton.setDisable(false);
                return null;
               
            }
        };
       
        if (TinygDriver.getInstance().isConnected().get()) {
            configProgress.progressProperty().bind(task.progressProperty());
            loadbutton.setDisable(true);
            new Thread(task).start();
        }

      
View Full Code Here

    private static String avrdudePath = new String();
    private static String avrconfigPath = new String();
    static HashMap<String, String> platformSetup = new HashMap<>();

    private static Task updateFirmware() {
        Task task;
        task = new Task<Void>() {
            @Override
            public Void call() throws IOException, Exception {
               
                File avc = new File("tools" + File.separator + "config" + File.separator + "avrdude.conf");
View Full Code Here

TOP

Related Classes of javafx.concurrent.Task

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.