]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RenderingQualityInteractor.java
Fixed invalid comparisons which were identified by Eclipse IDE 2018-09
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / participant / RenderingQualityInteractor.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.participant;
13
14 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
15 import org.simantics.g2d.canvas.impl.HintReflection.HintListener;
16 import org.simantics.g2d.scenegraph.SceneGraphConstants;
17 import org.simantics.scenegraph.INode;
18 import org.simantics.scenegraph.g2d.G2DSceneGraph;
19 import org.simantics.scenegraph.g2d.nodes.NavigationNode;
20 import org.simantics.scenegraph.utils.Quality;
21 import org.simantics.utils.datastructures.hints.IHintContext.Key;
22 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
23 import org.simantics.utils.datastructures.hints.IHintObservable;
24
25 /**
26  * Rendering quality interactor controls dynamic/static rendering quality of
27  * the canvas context's scene graph through {@link NavigationNode}.
28  * 
29  * @author Tuukka Lehtonen
30  */
31 public class RenderingQualityInteractor extends AbstractCanvasParticipant {
32
33     /**
34      * Interpreted to be true if value is TRUE or not defined, false otherwise.
35      */
36     public static final Key KEY_QUALITY_INTERACTOR_ENABLED = new KeyOf(Boolean.class);
37
38     /**
39      * 
40      */
41     public static final Key KEY_STATIC_QUALITY = new KeyOf(Quality.class);
42
43     public RenderingQualityInteractor() {
44         super();
45     }
46
47     public Quality setStaticQuality(Quality staticQuality) {
48         Quality old = getHint(KEY_STATIC_QUALITY);
49         if (staticQuality != null)
50             setHint(KEY_STATIC_QUALITY, staticQuality);
51         else
52             removeHint(KEY_STATIC_QUALITY);
53         return old;
54     }
55
56     private void setStaticQuality0(Quality staticQuality) {
57         if (!isEnabled())
58             return;
59         NavigationNode nav = getNavigationNode();
60         if (nav == null)
61             return;
62         //System.out.println("static rendering quality: " + staticQuality);
63         nav.setStaticQualityMode(staticQuality);
64         nav.setDynamicQuality(staticQuality == null);
65     }
66
67     public boolean isEnabled() {
68         Boolean qualityPaint = getHint(KEY_QUALITY_INTERACTOR_ENABLED);
69         return !Boolean.FALSE.equals(qualityPaint);
70     }
71
72     private NavigationNode getNavigationNode() {
73         G2DSceneGraph sg = getContext().getSceneGraph();
74         INode node = sg.lookupNode(SceneGraphConstants.NAVIGATION_NODE_NAME);
75         return node instanceof NavigationNode ? (NavigationNode) node : null;
76     }
77
78     @HintListener(Class = RenderingQualityInteractor.class, Field = "KEY_STATIC_QUALITY")
79     public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
80         setStaticQuality0((Quality) newValue);
81     }
82
83     @HintListener(Class = RenderingQualityInteractor.class, Field = "KEY_STATIC_QUALITY")
84     public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {
85         setStaticQuality0(null);
86     }
87
88 }