import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import java.util.Timer;
-import java.util.TimerTask;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import org.simantics.g2d.canvas.Hints;
import org.simantics.g2d.canvas.ICanvasContext;
import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
import org.simantics.g2d.canvas.impl.HintReflection.HintListener;
import org.simantics.utils.datastructures.disposable.DisposeState;
-import org.simantics.utils.datastructures.hints.IHintObservable;
import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintObservable;
import org.simantics.utils.threads.IThreadWorkQueue;
/**
long lastTrigger;
Point2D centerPoint = new Point2D.Double();
- transient Timer timer = new Timer("Rotate restore");
+ transient ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
transient boolean checkRotatePending = false;
- TimerTask task = new TimerTask() {
+ Runnable task = new Runnable() {
@Override
public void run() {
ICanvasContext ctx = getContext();
@Override
public void removedFromContext(ICanvasContext ctx) {
- timer.cancel();
+ timer.shutdown();
+ try {
+ if (!timer.awaitTermination(1, TimeUnit.SECONDS)) {
+ timer.shutdownNow();
+ }
+ } catch (InterruptedException e) {
+ // Ignore
+ }
super.removedFromContext(ctx);
}
@Override
public void addedToContext(ICanvasContext ctx) {
super.addedToContext(ctx);
- long delay = 1000 / 25;
+// long delay = 1000 / 25; this sounds quite frequent
+ long delay = 1000 / 10;
lastTrigger = System.currentTimeMillis();
- timer.scheduleAtFixedRate(task, delay, delay);
+ timer.scheduleAtFixedRate(task, delay, delay, TimeUnit.MILLISECONDS);
}
@HintListener(Class = Hints.class, Field = "KEY_CANVAS_BOUNDS")