Search in sources :

Example 1 with Task

use of javafx.concurrent.Task in project Retrospector by NonlinearFruit.

the class Retrospector method start.

@Override
public void start(final Stage initStage) throws Exception {
    final Task<Parent> task = new Task<Parent>() {

        @Override
        protected Parent call() throws InterruptedException, IOException {
            updateProgress(0, 8);
            updateMessage("Loading Database . . .");
            DataManager.startDB();
            updateProgress(1, 8);
            updateMessage("Loading Core . . .");
            FXMLLoader ldr = new FXMLLoader(getClass().getResource("/retrospector/fxml/Core.fxml"));
            Parent root = ldr.load();
            CoreController core = ldr.getController();
            updateProgress(2, 8);
            updateMessage("Loading Search . . .");
            FXMLLoader searchldr = new FXMLLoader(getClass().getResource("/retrospector/fxml/search/SearchTab.fxml"));
            searchldr.load();
            core.setSearchController(searchldr);
            updateProgress(3, 8);
            updateMessage("Loading Media . . .");
            FXMLLoader medialdr = new FXMLLoader(getClass().getResource("/retrospector/fxml/media/MediaTab.fxml"));
            medialdr.load();
            core.setMediaController(medialdr);
            updateProgress(4, 8);
            updateMessage("Loading Review . . .");
            FXMLLoader reviewldr = new FXMLLoader(getClass().getResource("/retrospector/fxml/ReviewTab.fxml"));
            reviewldr.load();
            core.setReviewController(reviewldr);
            updateProgress(5, 8);
            updateMessage("Loading Chart . . .");
            FXMLLoader statldr = new FXMLLoader(getClass().getResource("/retrospector/fxml/chart/StatsTab.fxml"));
            statldr.load();
            core.setStatsController(statldr);
            updateProgress(6, 8);
            updateMessage("Loading List . . .");
            FXMLLoader listldr = new FXMLLoader(getClass().getResource("/retrospector/fxml/ListsTab.fxml"));
            listldr.load();
            core.setListController(listldr);
            updateProgress(7, 8);
            updateMessage("Loading Achievements . . .");
            FXMLLoader achieveldr = new FXMLLoader(getClass().getResource("/retrospector/fxml/achievements/AchievementTab.fxml"));
            achieveldr.load();
            core.setAchieveController(achieveldr);
            updateProgress(8, 8);
            updateMessage("Done!");
            return root;
        }
    };
    showSplash(initStage, task, () -> showMainStage(task.valueProperty().get()));
    new Thread(task).start();
}
Also used : Task(javafx.concurrent.Task) Parent(javafx.scene.Parent) CoreController(retrospector.fxml.CoreController) FXMLLoader(javafx.fxml.FXMLLoader)

Example 2 with Task

use of javafx.concurrent.Task in project Gargoyle by callakrsos.

the class SkinPreviewViewComposite method previewTabInit.

@FxPostInitialize
public void previewTabInit() {
    Task<Void> task = new Task<Void>() {

        @Override
        protected Void call() throws Exception {
            Thread.sleep(5000L);
            Platform.runLater(() -> {
                //메뉴바 배경.
                {
                    Background background = mbSample.getBackground();
                    Color fill = (Color) background.getFills().get(0).getFill();
                    colorMbSample.setValue(fill);
                    //메뉴바 텍스트
                    {
                        Label lookup = (Label) mbSample.lookup(".label");
                        Color textFill = (Color) lookup.getTextFill();
                        colorMbLabelSample.setValue(textFill);
                    }
                }
                //Hbox 배경.
                {
                    Background background = hboxSample.getBackground();
                    Color fill = (Color) background.getFills().get(0).getFill();
                    colorHboxSample.setValue(fill);
                }
                {
                    //선택디지않는 탭 색상 처리.
                    Set<Node> lookupAll = tabpaneSample.lookupAll(".tab:top");
                    lookupAll.forEach(lookup -> {
                        Optional<PseudoClass> findFirst = lookup.getPseudoClassStates().stream().filter(v -> {
                            return "selected".equals(v.getPseudoClassName());
                        }).findFirst();
                        if (findFirst.isPresent()) {
                            Label selectedTabLabel = (Label) lookup.lookup(".tab-label");
                            Color textFill = (Color) selectedTabLabel.getTextFill();
                            colorSelectedTabText.setValue(textFill);
                        } else {
                            Label selectedTabLabel = (Label) lookup.lookup(".tab-label");
                            Color textFill = (Color) selectedTabLabel.getTextFill();
                            colorUnSelectedTabText.setValue(textFill);
                        }
                    });
                    {
                        lookupAll.stream().findFirst().ifPresent(n -> {
                            Pane p = (Pane) n;
                            Background background = p.getBackground();
                            Color fill = (Color) background.getFills().get(0).getFill();
                            colorTabSample1Selected.setValue(fill);
                        });
                    }
                }
            });
            return null;
        }
    };
    Window window = this.getScene().getWindow();
    if (window != null) {
        FxUtil.showLoading(window, task);
    } else
        FxUtil.showLoading(task);
}
Also used : Button(javafx.scene.control.Button) TextArea(javafx.scene.control.TextArea) PseudoClass(javafx.css.PseudoClass) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) TableColumn(javafx.scene.control.TableColumn) Task(javafx.concurrent.Task) TabPane(javafx.scene.control.TabPane) Map(java.util.Map) FileUtil(com.kyj.fx.voeditor.visual.util.FileUtil) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) ColorPicker(javafx.scene.control.ColorPicker) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) Pair(javafx.util.Pair) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuBar(javafx.scene.control.MenuBar) Node(javafx.scene.Node) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) Set(java.util.Set) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) JFXToggleButton(com.jfoenix.controls.JFXToggleButton) Background(javafx.scene.layout.Background) File(java.io.File) FxPostInitialize(com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) Stage(javafx.stage.Stage) Optional(java.util.Optional) Window(javafx.stage.Window) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) Window(javafx.stage.Window) Task(javafx.concurrent.Task) Set(java.util.Set) Background(javafx.scene.layout.Background) Optional(java.util.Optional) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) TabPane(javafx.scene.control.TabPane) Pane(javafx.scene.layout.Pane) BorderPane(javafx.scene.layout.BorderPane) FxPostInitialize(com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize)

Example 3 with Task

use of javafx.concurrent.Task in project Gargoyle by callakrsos.

the class NrchRealtimeSrchFlowComposite method defineService.

private void defineService() {
    /*
		 * 비동기 실시간 검색어 조회 처리가 기술.
		 */
    service = new Service<List<RealtimeSearchVO>>() {

        @Override
        protected Task<List<RealtimeSearchVO>> createTask() {
            return new Task<List<RealtimeSearchVO>>() {

                @Override
                protected List<RealtimeSearchVO> call() throws Exception {
                    List<RealtimeSearchVO> meta = Collections.emptyList();
                    try {
                        meta = NaverRealtimeSrchSupplier.getInstance().getMeta();
                    } catch (Exception e) {
                        DialogUtil.showExceptionDailog(e);
                    }
                    return meta;
                }
            };
        }
    };
    service.setOnCancelled(stat -> {
        if (State.CANCELLED == stat.getSource().getState()) {
            LOGGER.debug("Cancel Requested");
        }
    });
    service.setOnSucceeded(stat -> {
        applyResponseTime(DateUtil.getCurrentDateString());
        FlowCardComposite value = new FlowCardComposite();
        flowCardComposite.set(value);
        this.getParent().setCenter(flowCardComposite.get());
        FlowCardComposite tmp = flowCardComposite.get();
        ObservableList<Node> flowChildrens = tmp.getFlowChildrens();
        tmp.setLimitColumn(20);
        data.setAll((List<RealtimeSearchVO>) stat.getSource().getValue());
        List<VBox> collect = data.stream().map(nodeConverter::apply).flatMap(v -> v.stream()).collect(Collectors.toList());
        flowChildrens.setAll(collect);
        if (isRecycle.get()) {
            WaitThread waitThread = new WaitThread(THREAD_RUNNER_GROUP, choWaitItems.getValue()) {

                @Override
                public boolean isContinue() {
                    return isRecycle.get();
                }

                @Override
                public void execute() {
                    Platform.runLater(() -> {
                        if (isContinue())
                            service.restart();
                    });
                }

                @Override
                public boolean isRecycle() {
                    return isRecycle.get();
                }
            };
            waitThread.setDaemon(true);
            waitThread.start();
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) MouseButton(javafx.scene.input.MouseButton) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) VBox(javafx.scene.layout.VBox) Function(java.util.function.Function) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Task(javafx.concurrent.Task) Insets(javafx.geometry.Insets) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextMenu(javafx.scene.control.ContextMenu) State(javafx.concurrent.Worker.State) ExecutorService(java.util.concurrent.ExecutorService) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) TitledPane(javafx.scene.control.TitledPane) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) Node(javafx.scene.Node) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Service(javafx.concurrent.Service) Collectors(java.util.stream.Collectors) ChoiceBox(javafx.scene.control.ChoiceBox) GoogleTrendComposite(com.kyj.fx.voeditor.visual.component.google.trend.GoogleTrendComposite) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) NaverRealtimeSrchSupplier(com.kyj.fx.voeditor.visual.suppliers.NaverRealtimeSrchSupplier) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) FlowCardComposite(com.kyj.fx.voeditor.visual.component.FlowCardComposite) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) Collections(java.util.Collections) ExecutorDemons(com.kyj.fx.voeditor.visual.framework.thread.ExecutorDemons) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) Task(javafx.concurrent.Task) Node(javafx.scene.Node) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) FlowCardComposite(com.kyj.fx.voeditor.visual.component.FlowCardComposite) List(java.util.List) ObservableList(javafx.collections.ObservableList) VBox(javafx.scene.layout.VBox)

Example 4 with Task

use of javafx.concurrent.Task in project loinc2hpo by monarch-initiative.

the class MainController method downloadHPO.

@FXML
public void downloadHPO(ActionEvent e) {
    String dirpath = Loinc2HpoPlatform.getLOINC2HPODir().getAbsolutePath();
    File f = new File(dirpath);
    if (f == null || !(f.exists() && f.isDirectory())) {
        logger.trace("Cannot download hp.obo, because directory not existing at " + f.getAbsolutePath());
        return;
    }
    String BASENAME = "hp.obo";
    String BASENAME_OWL = "hp.owl";
    ProgressIndicator pb = new ProgressIndicator();
    javafx.scene.control.Label label = new javafx.scene.control.Label("downloading hp.obo/.owl...");
    FlowPane root = new FlowPane();
    root.setPadding(new Insets(10));
    root.setHgap(10);
    root.getChildren().addAll(label, pb);
    Scene scene = new Scene(root, 400, 100);
    Stage window = new Stage();
    window.setTitle("HPO download");
    window.setScene(scene);
    Task hpodownload = new Downloader(dirpath, HP_OBO_URL, BASENAME, pb);
    new Thread(hpodownload).start();
    hpodownload = new Downloader(dirpath, HP_OWL_URL, BASENAME_OWL, pb);
    new Thread(hpodownload).start();
    window.show();
    hpodownload.setOnSucceeded(event -> {
        window.close();
        logger.trace(String.format("Successfully downloaded hpo to %s", dirpath));
        String fullpath = String.format("%s%shp.obo", dirpath, File.separator);
        String fullpath_owl = String.format("%s%shp.owl", dirpath, File.separator);
        model.setPathToHpOboFile(fullpath);
        model.setPathToHpOwlFile(fullpath_owl);
        model.writeSettings();
        configurationComplete.set(isConfigurationCompleted());
    });
    hpodownload.setOnFailed(event -> {
        window.close();
        logger.error("Unable to download HPO obo file");
    });
    // Thread thread = new Thread(hpodownload);
    // thread.start();
    e.consume();
}
Also used : Task(javafx.concurrent.Task) Insets(javafx.geometry.Insets) Downloader(org.monarchinitiative.loinc2hpo.io.Downloader) javafx.scene.control(javafx.scene.control) Scene(javafx.scene.Scene) FlowPane(javafx.scene.layout.FlowPane) Stage(javafx.stage.Stage) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) FXML(javafx.fxml.FXML)

Example 5 with Task

use of javafx.concurrent.Task in project Entitas-Java by Rubentxu.

the class CodeGeneratorApp method handleGenerate.

@FXML
public void handleGenerate(ActionEvent actionEvent) throws IOException {
    result.setText("");
    progress.setVisible(true);
    result.setText("Generating...");
    if (props != null)
        saveProperties();
    // loads the items at another thread, asynchronously
    Task loader = new Task<List<CodeGenFile>>() {

        {
            setOnSucceeded(workerStateEvent -> {
                progress.setVisible(false);
                result.setText("Success");
            });
            setOnFailed(workerStateEvent -> {
                result.setText("Failed");
                getException().printStackTrace();
            });
        }

        @Override
        protected List<CodeGenFile> call() throws Exception {
            List<ICodeGenerator> codeGenerators = new ArrayList<>();
            if (componentsGenerator.isSelected())
                codeGenerators.add(new EntityGenerator());
            if (componentIndicesGenerator.isSelected())
                codeGenerators.add(new ComponentIndicesGenerator());
            if (contextsGenerator.isSelected())
                codeGenerators.add(new ContextGenerator());
            codeGenerators.add(new MatcherGenerator());
            codeGenerators.add(new EntitasGenerator());
            TypeReflectionProvider provider = new TypeReflectionProvider(fieldComponentFolder.getText());
            CodeGeneratorOld generator = new CodeGeneratorOld();
            return generator.generate(provider, fieldGeneratedFolder.getText(), codeGenerators);
        }
    };
    Thread loadingThread = new Thread(loader, "generated-loader");
    loadingThread.setDaemon(true);
    loadingThread.start();
}
Also used : Task(javafx.concurrent.Task) ArrayList(java.util.ArrayList) TypeReflectionProvider(com.ilargia.games.entitas.codeGenerator.providers.TypeReflectionProvider) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) FXML(javafx.fxml.FXML)

Aggregations

Task (javafx.concurrent.Task)30 FXML (javafx.fxml.FXML)9 File (java.io.File)8 List (java.util.List)5 IOException (java.io.IOException)4 Collectors (java.util.stream.Collectors)4 TRexClient (com.cisco.trex.stateless.TRexClient)3 ServiceModeRequiredException (com.cisco.trex.stateless.exception.ServiceModeRequiredException)3 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)3 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)3 ResourceBundle (java.util.ResourceBundle)3 Platform (javafx.application.Platform)3 ObservableList (javafx.collections.ObservableList)3 Node (javafx.scene.Node)3 Label (javafx.scene.control.Label)3 ImageView (javafx.scene.image.ImageView)3 Ipv6Node (com.cisco.trex.stateless.model.Ipv6Node)2 ActivePGIdsRPCResult (com.cisco.trex.stateless.model.stats.ActivePGIdsRPCResult)2 IPv6Host (com.cisco.trex.stl.gui.models.IPv6Host)2 DialogUtil (com.kyj.fx.voeditor.visual.util.DialogUtil)2