当前位置: 首页>>代码示例>>Java>>正文


Java FxTimer类代码示例

本文整理汇总了Java中org.reactfx.util.FxTimer的典型用法代码示例。如果您正苦于以下问题:Java FxTimer类的具体用法?Java FxTimer怎么用?Java FxTimer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FxTimer类属于org.reactfx.util包,在下文中一共展示了FxTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setScale

import org.reactfx.util.FxTimer; //导入依赖的package包/类
/**
 * Set the maps scale.
 *
 * @param scale of map
 */
public void setScale(double scale) {
    if (scale < ZOOM_MAX) {
        if (scale > ZOOM_MIN) {
            this.scale = scale;
        } else {
            this.scale = ZOOM_MIN;
        }
    } else {
        this.scale = ZOOM_MAX;
    }

    setDragMode(true);
    redraw();

    lastScrollTime = System.currentTimeMillis();

    FxTimer.runLater(Duration.ofSeconds(REDRAW_DELAY_SECONDS), () -> {
        if (isInDragMode() && System.currentTimeMillis() - lastScrollTime > REDRAW_DELAY_SECONDS * 500) {
            setDragMode(false);
            redraw();
        }
    });
}
 
开发者ID:floric,项目名称:HTWK_Visu,代码行数:29,代码来源:BasicCanvas.java

示例2: setupNvidiaListener

import org.reactfx.util.FxTimer; //导入依赖的package包/类
private void setupNvidiaListener() {
    log.log(Level.FINER, "Setting nvidia ram listener.");
    EventStreams.nonNullValuesOf(nvidiaService.progressProperty())
            .filter(vramUsage -> vramUsage.doubleValue() > 0)
            .subscribe(vramUsage -> vramBar.setProgress(vramUsage.doubleValue()));

    log.log(Level.FINER, "Setting nvidia timer.");
    nvidiaTimer = FxTimer.createPeriodic(Duration.ofMillis(1000), () -> {
        log.log(Level.FINER, "Timer: checking service");
        if (nvidiaService == null || nvidiaService.isRunning())
            return;

        log.log(Level.FINER, "Timer: starting service");
        nvidiaService.restart();
        nvidiaTimer.restart();
    });
    nvidiaTimer.restart();
}
 
开发者ID:cameronleger,项目名称:neural-style-gui,代码行数:19,代码来源:MainController.java

示例3: restartableTicks

import org.reactfx.util.FxTimer; //导入依赖的package包/类
/**
 * Returns a {@link #ticks(Duration)} EventStream whose timer restarts whenever
 * impulse emits an event.
 * @param interval - the amount of time that passes until this stream emits its next tick
 * @param impulse - the EventStream that resets this EventStream's internal timer
 */
public static EventStream<?> restartableTicks(Duration interval, EventStream<?> impulse) {
    return new EventStreamBase<Void>() {
        private final Timer timer = FxTimer.createPeriodic(
                interval, () -> emit(null));

        @Override
        protected Subscription observeInputs() {
            timer.restart();
            return Subscription.multi(
                    impulse.subscribe(x -> timer.restart()),
                    timer::stop
            );
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:22,代码来源:EventStreams.java

示例4: restartableTicks0

import org.reactfx.util.FxTimer; //导入依赖的package包/类
/**
 * Returns a {@link #ticks0(Duration)} EventStream whose timer restarts whenever
 * impulse emits an event. Note: since {@link #ticks0(Duration)} is used, restarting
 * the timer will make the returned EventStream immediately emit a new tick.
 * @param interval - the amount of time that passes until this stream emits its next tick
 * @param impulse - the EventStream that resets this EventStream's internal timer
 */
public static EventStream<?> restartableTicks0(Duration interval, EventStream<?> impulse) {
    return new EventStreamBase<Void>() {
        private final Timer timer = FxTimer.createPeriodic0(
                interval, () -> emit(null));

        @Override
        protected Subscription observeInputs() {
            timer.restart();
            return Subscription.multi(
                    impulse.subscribe(x -> timer.restart()),
                    timer::stop
            );
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:23,代码来源:EventStreams.java

示例5: fxRestartableTicksTest

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@Test
public void fxRestartableTicksTest() throws InterruptedException, ExecutionException {
    CompletableFuture<Integer> nTicks = new CompletableFuture<>();
    Platform.runLater(() -> {
        EventCounter counter = new EventCounter();
        EventSource<?> impulse = new EventSource<Void>();
        Subscription sub = EventStreams.restartableTicks(Duration.ofMillis(100), impulse)
                .subscribe(counter::accept);
        FxTimer.runLater(Duration.ofMillis(400), sub::unsubscribe);
        FxTimer.runLater(Duration.ofMillis(80),() -> impulse.push(null));
        FxTimer.runLater(Duration.ofMillis(260),() -> impulse.push(null));
        // 000: Start -> 80 (restart)
        // 080: Start
        // 180: End (tick)
        // 180: Start -> 80 (restart)
        // 260: Start
        // 360: End (tick)
        // 400: unsubscribed: 2 ticks
        // wait a little more to test that no more ticks arrive anyway
        FxTimer.runLater(Duration.ofMillis(550), () -> nTicks.complete(counter.get()));
    });
    assertEquals(2, nTicks.get().intValue());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:24,代码来源:TicksTest.java

示例6: fxRestartableTicks0Test

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@Test
public void fxRestartableTicks0Test() throws InterruptedException, ExecutionException {
    CompletableFuture<Integer> nTicks = new CompletableFuture<>();
    Platform.runLater(() -> {
        EventCounter counter = new EventCounter();
        EventSource<?> impulse = new EventSource<Void>();
        Subscription sub = EventStreams.restartableTicks0(Duration.ofMillis(100), impulse)
                .subscribe(counter::accept);
        FxTimer.runLater(Duration.ofMillis(400), sub::unsubscribe);
        FxTimer.runLater(Duration.ofMillis(80), () -> impulse.push(null));
        FxTimer.runLater(Duration.ofMillis(260), () -> impulse.push(null));
        // 000: 0 (tick) -> 80 (restart)
        // 080: 0 (tick)
        // 180: 0 (tick) -> 80 (restart)
        // 260: 0 (tick)
        // 360: 0 (tick)
        // 400: unsubscribed: 5 ticks
        // wait a little more to test that no more ticks arrive anyway
        FxTimer.runLater(Duration.ofMillis(550), () -> nTicks.complete(counter.get()));
    });
    assertEquals(5, nTicks.get().intValue());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:23,代码来源:TicksTest.java

示例7: setupOutputImageListeners

import org.reactfx.util.FxTimer; //导入依赖的package包/类
private void setupOutputImageListeners() {
    imageView.fitWidthProperty().bind(imageViewSizer.widthProperty());
    imageView.fitHeightProperty().bind(imageViewSizer.heightProperty());

    log.log(Level.FINER, "Setting image timer.");
    imageOutputTimer = FxTimer.createPeriodic(Duration.ofMillis(250), () -> {
        log.log(Level.FINER, "Timer: checking service");

        if (imageOutputService != null && !imageOutputService.isRunning()) {
            imageOutputService.reset();
            imageOutputService.start();
        }
    });
}
 
开发者ID:cameronleger,项目名称:neural-style-gui,代码行数:15,代码来源:MainController.java

示例8: runLater

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@Override
public Timer runLater(Duration delay, Runnable runnable) {
    if (timer == null) {
        timer = FxTimer.create(delay, runnable);
        timer.restart();
    } else {
        log.warn("runLater called on an already running timer.");
    }
    return this;
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:11,代码来源:UITimer.java

示例9: runPeriodically

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@Override
public Timer runPeriodically(Duration interval, Runnable runnable) {
    if (timer == null) {
        timer = FxTimer.createPeriodic(interval, runnable);
        timer.restart();
    } else {
        log.warn("runPeriodically called on an already running timer.");
    }
    return this;
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:11,代码来源:UITimer.java

示例10: thenAccumulateFor

import org.reactfx.util.FxTimer; //导入依赖的package包/类
/**
 * Returns an event stream that emits the first event emitted from this
 * stream and then, if the next event arrives within the given duration
 * since the last emitted event, it is converted to an accumulator value
 * using {@code initialTransformation}. Any further events that still
 * arrive within {@code duration} are accumulated to the accumulator value
 * using the given reduction function. After {@code duration} has passed
 * since the last emitted event, the accumulator value is deconstructed
 * into a series of events using the given {@code deconstruction} function
 * and these events are emitted, the accumulator value is cleared and any
 * events that arrive within {@code duration} are accumulated, and so on.
 */
default <A> AwaitingEventStream<T> thenAccumulateFor(
        Duration duration,
        Function<? super T, ? extends A> initialTransformation,
        BiFunction<? super A, ? super T, ? extends A> reduction,
        Function<? super A, List<T>> deconstruction) {
    return new ThenAccumulateForStream<>(
            this,
            initialTransformation,
            reduction,
            deconstruction,
            action -> FxTimer.create(duration, action));
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:25,代码来源:EventStream.java

示例11: ticks

import org.reactfx.util.FxTimer; //导入依赖的package包/类
/**
 * Returns an event stream that emits periodic <i>ticks</i>. The first tick
 * is emitted after {@code interval} amount of time has passed.
 * The returned stream may only be used on the JavaFX application thread.
 *
 * <p>As with all lazily bound streams, ticks are emitted only when there
 * is at least one subscriber to the returned stream. This means that to
 * release associated resources, it suffices to unsubscribe from the
 * returned stream.
 */
public static EventStream<?> ticks(Duration interval) {
    return new EventStreamBase<Void>() {
        private final Timer timer = FxTimer.createPeriodic(
                interval, () -> emit(null));

        @Override
        protected Subscription observeInputs() {
            timer.restart();
            return timer::stop;
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:23,代码来源:EventStreams.java

示例12: ticks0

import org.reactfx.util.FxTimer; //导入依赖的package包/类
/**
 * Returns an event stream that emits periodic <i>ticks</i>. The first tick
 * is emitted at time 0.
 * The returned stream may only be used on the JavaFX application thread.
 *
 * <p>As with all lazily bound streams, ticks are emitted only when there
 * is at least one subscriber to the returned stream. This means that to
 * release associated resources, it suffices to unsubscribe from the
 * returned stream.
 */
public static EventStream<?> ticks0(Duration interval) {
    return new EventStreamBase<Void>() {
        private final Timer timer = FxTimer.createPeriodic0(
                interval, () -> emit(null));

        @Override
        protected Subscription observeInputs() {
            timer.restart();
            return timer::stop;
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:23,代码来源:EventStreams.java

示例13: fxTicksTest

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@Test
public void fxTicksTest() throws InterruptedException, ExecutionException {
    CompletableFuture<Integer> nTicks = new CompletableFuture<>();
    Platform.runLater(() -> {
        EventCounter counter = new EventCounter();
        Subscription sub = EventStreams.ticks(Duration.ofMillis(100)).subscribe(counter::accept);
        FxTimer.runLater(Duration.ofMillis(350), sub::unsubscribe); // stop after 3 ticks
        // wait a little more to test that no more than 3 ticks arrive anyway
        FxTimer.runLater(Duration.ofMillis(550), () -> nTicks.complete(counter.get()));
    });
    assertEquals(3, nTicks.get().intValue());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:13,代码来源:TicksTest.java

示例14: fxTicks0Test

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@Test
public void fxTicks0Test() throws InterruptedException, ExecutionException {
    CompletableFuture<Integer> nTicks = new CompletableFuture<>();
    Platform.runLater(() -> {
     EventCounter counter = new EventCounter();
     Subscription sub = EventStreams.ticks0(Duration.ofMillis(100)).subscribe(counter::accept);
     // 000 (tick 1) -> 100 (tick 2) -> 200 (tick 3) -> 300 (tick 4) -> 350 (interrupted) = 4 ticks
     FxTimer.runLater(Duration.ofMillis(350), sub::unsubscribe); // stop after 4 ticks
     // wait a little more to test that no more than 4 ticks arrive anyway
     FxTimer.runLater(Duration.ofMillis(550), () -> nTicks.complete(counter.get()));
    });
    assertEquals(4, nTicks.get().intValue());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:14,代码来源:TicksTest.java

示例15: alertDialog

import org.reactfx.util.FxTimer; //导入依赖的package包/类
@SuppressWarnings("restriction")
public void alertDialog(String title, String header, StringProperty msg,
	ConstructionManager constructionManager, ConstructionSite site, boolean hasTimer,
	ConstructionStageInfo stageInfo, int constructionSkill){
	//System.out.println("ConstructionWizard : Calling alertDialog()");
	Alert alert = new Alert(AlertType.CONFIRMATION);
	//alert.setOnCloseRequest((event) -> event.consume());
	//alert.initStyle(StageStyle.UNDECORATED);
	alert.initOwner(mainScene.getStage());
	alert.initModality(Modality.NONE); // users can zoom in/out, move around the settlement map and move a vehicle elsewhere
	//alert.initModality(Modality.APPLICATION_MODAL);
	double x = mainScene.getStage().getWidth();
	double y = mainScene.getStage().getHeight();
	double xx = alert.getDialogPane().getWidth();
	double yy = alert.getDialogPane().getHeight();

	alert.setX((x - xx)/2D);
	alert.setY((y - yy)*3D/4D);
	alert.setTitle(title);
	alert.setHeaderText(header);
	alert.setContentText(msg.get());
	// 2015-12-19 Used JavaFX binding
	alert.getDialogPane().contentTextProperty().bind(msg);
	//alert.getDialogPane().headerTextProperty().bind(arg0);

	ButtonType buttonTypeYes = new ButtonType("Yes");
	ButtonType buttonTypeNo = new ButtonType("No");
	ButtonType buttonTypeMouseKB = new ButtonType("Use Mouse");
	ButtonType buttonTypeCancelTimer = null;

	Timer timer = null;
	if (hasTimer) {
		buttonTypeCancelTimer = new ButtonType("Cancel Timer");
		alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo, buttonTypeMouseKB, buttonTypeCancelTimer);

		IntegerProperty i = new SimpleIntegerProperty(wait_time_in_secs);
		// 2015-12-19 Added ReactFX's Timer and FxTimer
		timer = FxTimer.runPeriodically(java.time.Duration.ofMillis(1000), () -> {
        	int num = i.get() - 1;
        	if (num >= 0) {
        		i.set(num);
        	}
        	//System.out.println(num);
        	if (num == 0) {
        		Button button = (Button) alert.getDialogPane().lookupButton(buttonTypeYes);
        	    button.fire();
        	}
        	msg.set("Notes: (1) Will default to \"Yes\" in " + num + " secs unless timer is cancelled."
        			+ " (2) To manually place a site, use Mouse Control.");
		});
	}
	else {
		msg.set("Note: To manually place a site, use Mouse Control.");
		alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo, buttonTypeMouseKB);
	}

	Optional<ButtonType> result = null;
	result = alert.showAndWait();

	if (result.isPresent() && result.get() == buttonTypeYes) {
		logger.info(site.getName() + " is put in place in " + constructionManager.getSettlement());

	} else if (result.isPresent() && result.get() == buttonTypeNo) {
		//constructionManager.removeConstructionSite(site);
    	//System.out.println("just removing building");
		site = positionNewSite(site);//, constructionSkill);
		confirmSiteLocation(site, constructionManager, false, stageInfo, constructionSkill);

	} else if (result.isPresent() && result.get() == buttonTypeMouseKB) {
		placementDialog(title,header, site);

	} else if (hasTimer && result.isPresent() && result.get() == buttonTypeCancelTimer) {
		timer.stop();
		alertDialog(title, header, msg, constructionManager, site, false, stageInfo, constructionSkill);
	}

}
 
开发者ID:mars-sim,项目名称:mars-sim,代码行数:78,代码来源:ConstructionWizard.java


注:本文中的org.reactfx.util.FxTimer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。