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.canvas.impl;
14 import java.lang.reflect.Method;
16 import org.simantics.g2d.canvas.IContentContext;
17 import org.simantics.utils.datastructures.ListenerList;
18 import org.simantics.utils.threads.CurrentThread;
19 import org.simantics.utils.threads.IThreadWorkQueue;
20 import org.simantics.utils.threads.SyncListenerList;
24 * @See {@link IContentContext}
26 * @author Toni Kalajainen
28 public class PaintableContextImpl implements IContentContext {
31 public void setDirty() {
35 protected ListenerList<IContentListener> list =
36 new ListenerList<IContentListener>(IContentListener.class);
37 protected SyncListenerList<IContentListener> list2 =
38 new SyncListenerList<IContentListener>(IContentListener.class);
41 public void addPaintableContextListener(IContentListener listener) {
45 public void addPaintableContextListener(IContentListener listener, IThreadWorkQueue thread) {
46 if (thread==CurrentThread.getThreadAccess())
47 addPaintableContextListener(listener);
49 list2.add(thread, listener);
52 public void removePaintableContextListener(IContentListener listener) {
53 list.remove(listener);
56 public void removePaintableContextListener(IContentListener listener, IThreadWorkQueue thread) {
57 if (thread==CurrentThread.getThreadAccess())
58 addPaintableContextListener(listener);
60 list2.remove(thread, listener);
62 private final static Method onDirty = SyncListenerList.getMethod(IContentListener.class, "onDirty");
63 protected void fireSetDirty() {
64 for (IContentListener l : list.getListeners())
66 list2.fireEventSync(onDirty, this);
68 protected void fireAsyncSetDirty() {
69 list2.fireEventAsync(onDirty, this);