]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/impl/PaintableContextImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / canvas / impl / PaintableContextImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.canvas.impl;
13
14 import java.lang.reflect.Method;
15
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;
21
22 /**
23  * 
24  * @See {@link IContentContext}
25  * 
26  * @author Toni Kalajainen
27  */
28 public class PaintableContextImpl implements IContentContext {
29
30         @Override
31         public void setDirty() {
32                 fireSetDirty();         
33         }
34         
35         protected ListenerList<IContentListener> list =
36         new ListenerList<IContentListener>(IContentListener.class);
37         protected SyncListenerList<IContentListener> list2 =
38         new SyncListenerList<IContentListener>(IContentListener.class);
39
40         @Override
41     public void addPaintableContextListener(IContentListener listener) {
42         list.add(listener);
43     }
44         @Override
45     public void addPaintableContextListener(IContentListener listener, IThreadWorkQueue thread) {
46                 if (thread==CurrentThread.getThreadAccess()) 
47                         addPaintableContextListener(listener);
48                 else
49                         list2.add(thread, listener);
50     }    
51         @Override
52     public void removePaintableContextListener(IContentListener listener) {
53         list.remove(listener);
54     }
55         @Override
56     public void removePaintableContextListener(IContentListener listener, IThreadWorkQueue thread) {
57                 if (thread==CurrentThread.getThreadAccess()) 
58                         addPaintableContextListener(listener);
59                 else
60                         list2.remove(thread, listener);
61     }
62     private final static Method onDirty = SyncListenerList.getMethod(IContentListener.class, "onDirty");
63     protected void fireSetDirty() {
64         for (IContentListener l : list.getListeners())
65                 l.onDirty(this);
66         list2.fireEventSync(onDirty, this);
67     }
68     protected void fireAsyncSetDirty() {
69         list2.fireEventAsync(onDirty, this);
70     }
71
72         
73             
74 }