1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.image.impl;
14 import java.util.EnumSet;
15 import java.util.concurrent.Executor;
16 import java.util.concurrent.LinkedBlockingQueue;
17 import java.util.concurrent.ThreadFactory;
18 import java.util.concurrent.ThreadPoolExecutor;
19 import java.util.concurrent.TimeUnit;
21 import org.simantics.g2d.image.DefaultImages;
22 import org.simantics.g2d.image.Image;
23 import org.simantics.utils.datastructures.cache.IProvider;
26 * AsyncImage acquires Image from IProvider asynchronously.
27 * Wait symbol is shown while symbol is acquired.
29 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
31 public class AsyncImage extends ImageProxy {
33 static EnumSet<Feature> caps = EnumSet.of(Feature.Volatile, Feature.Vector);
35 private static ThreadFactory tf = new ThreadFactory() {
37 public Thread newThread(Runnable r) {
38 Thread t = new Thread(new ThreadGroup("Renderer"), r);
43 private static Executor EXECUTOR =
44 new ThreadPoolExecutor(
48 new LinkedBlockingQueue<Runnable>(),
51 public AsyncImage(final IProvider<Image> imgProvider) {
52 super(DefaultImages.UNKNOWN.get());
53 EXECUTOR.execute(new Runnable() {
56 setSource(DefaultImages.GRAB.get());
57 setSource(imgProvider.get());
62 public EnumSet<Feature> getFeatures() {
63 return EnumSet.of(Feature.Volatile);