--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.image.impl;\r
+\r
+import java.util.EnumSet;\r
+import java.util.concurrent.Executor;\r
+import java.util.concurrent.LinkedBlockingQueue;\r
+import java.util.concurrent.ThreadFactory;\r
+import java.util.concurrent.ThreadPoolExecutor;\r
+import java.util.concurrent.TimeUnit;\r
+\r
+import org.simantics.g2d.image.DefaultImages;\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.utils.datastructures.cache.IProvider;\r
+\r
+/**\r
+ * AsyncImage acquires Image from IProvider asynchronously.\r
+ * Wait symbol is shown while symbol is acquired.\r
+ *\r
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
+ */\r
+public class AsyncImage extends ImageProxy {\r
+\r
+ static EnumSet<Feature> caps = EnumSet.of(Feature.Volatile, Feature.Vector);\r
+\r
+ private static ThreadFactory tf = new ThreadFactory() {\r
+ @Override\r
+ public Thread newThread(Runnable r) {\r
+ Thread t = new Thread(new ThreadGroup("Renderer"), r);\r
+ t.setDaemon(false);\r
+ return t;\r
+ }\r
+ };\r
+ private static Executor EXECUTOR =\r
+ new ThreadPoolExecutor(\r
+ 0,\r
+ 1,\r
+ 3L, TimeUnit.SECONDS,\r
+ new LinkedBlockingQueue<Runnable>(),\r
+ tf);\r
+\r
+ public AsyncImage(final IProvider<Image> imgProvider) {\r
+ super(DefaultImages.UNKNOWN.get());\r
+ EXECUTOR.execute(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ setSource(DefaultImages.GRAB.get());\r
+ setSource(imgProvider.get());\r
+ }});\r
+ }\r
+\r
+ @Override\r
+ public EnumSet<Feature> getFeatures() {\r
+ return EnumSet.of(Feature.Volatile);\r
+ }\r
+\r
+}\r
+\r