]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/chassis/AbstractChassis.java
Merge "Fixed invalid comparisons which were identified by Eclipse IDE 2018-09"
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / chassis / AbstractChassis.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.chassis;
13
14 import org.simantics.g2d.canvas.ICanvasContext;
15 import org.simantics.utils.datastructures.hints.HintContext;
16 import org.simantics.utils.datastructures.hints.IHintContext;
17 import org.simantics.utils.threads.IThreadWorkQueue;
18 import org.simantics.utils.threads.SyncListenerList;
19
20 /**
21  * @author Toni Kalajainen
22  */
23 public abstract class AbstractChassis implements ICanvasChassis {
24
25     /** Hint context */
26     protected IHintContext                        hintCtx   = new HintContext();
27     
28     protected SyncListenerList<IChassisListener>  listeners = new SyncListenerList<IChassisListener>(IChassisListener.class);
29     
30     protected ICanvasContext                      canvasContext;
31     
32     public void setCanvasContext(ICanvasContext canvasContext) {
33         assert (this.canvasContext == null);
34         assert (canvasContext != null);
35         this.canvasContext = canvasContext;
36         // Create canvas context and a layer of interactors
37         canvasContext.getHintStack().addHintContext(hintCtx, 0);
38     }
39     
40     @Override
41     public ICanvasContext getCanvasContext() {
42         return canvasContext;
43     }
44     
45     @Override
46     public void addChassisListener(IThreadWorkQueue thread, IChassisListener listener) {
47         listeners.add(thread, listener);
48     }
49
50     @Override
51     public void removeChassisListener(IThreadWorkQueue thread, IChassisListener listener) {
52         listeners.remove(thread, listener);
53     }
54
55     @Override
56     public void addChassisListener(IChassisListener listener) {
57         listeners.add(listener);
58     }
59
60     @Override
61     public void removeChassisListener(IChassisListener listener) {
62         listeners.remove(listener);
63     }    
64
65     @Override
66     public IHintContext getHintContext() {
67         return hintCtx;
68     }
69     
70 }