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.participant;
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;
26 * Rendering quality interactor controls dynamic/static rendering quality of
27 * the canvas context's scene graph through {@link NavigationNode}.
29 * @author Tuukka Lehtonen
31 public class RenderingQualityInteractor extends AbstractCanvasParticipant {
34 * Interpreted to be true if value is TRUE or not defined, false otherwise.
36 public static final Key KEY_QUALITY_INTERACTOR_ENABLED = new KeyOf(Boolean.class);
41 public static final Key KEY_STATIC_QUALITY = new KeyOf(Quality.class);
43 public RenderingQualityInteractor() {
47 public Quality setStaticQuality(Quality staticQuality) {
48 Quality old = getHint(KEY_STATIC_QUALITY);
49 if (staticQuality != null)
50 setHint(KEY_STATIC_QUALITY, staticQuality);
52 removeHint(KEY_STATIC_QUALITY);
56 private void setStaticQuality0(Quality staticQuality) {
59 NavigationNode nav = getNavigationNode();
62 //System.out.println("static rendering quality: " + staticQuality);
63 nav.setStaticQualityMode(staticQuality);
64 nav.setDynamicQuality(staticQuality == null);
67 public boolean isEnabled() {
68 Boolean qualityPaint = getHint(KEY_QUALITY_INTERACTOR_ENABLED);
69 return !Boolean.FALSE.equals(qualityPaint);
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;
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);
83 @HintListener(Class = RenderingQualityInteractor.class, Field = "KEY_STATIC_QUALITY")
84 public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {
85 setStaticQuality0(null);