X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fparticipant%2FRenderingQualityInteractor.java;fp=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fparticipant%2FRenderingQualityInteractor.java;h=645308c63cb939343f1af5080b36b27c82ed1392;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RenderingQualityInteractor.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RenderingQualityInteractor.java new file mode 100644 index 000000000..645308c63 --- /dev/null +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RenderingQualityInteractor.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.participant; + +import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; +import org.simantics.g2d.canvas.impl.HintReflection.HintListener; +import org.simantics.g2d.scenegraph.SceneGraphConstants; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.G2DSceneGraph; +import org.simantics.scenegraph.g2d.nodes.NavigationNode; +import org.simantics.scenegraph.utils.Quality; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * Rendering quality interactor controls dynamic/static rendering quality of + * the canvas context's scene graph through {@link NavigationNode}. + * + * @author Tuukka Lehtonen + */ +public class RenderingQualityInteractor extends AbstractCanvasParticipant { + + /** + * Interpreted to be true if value is TRUE or not defined, false otherwise. + */ + public static final Key KEY_QUALITY_INTERACTOR_ENABLED = new KeyOf(Boolean.class); + + /** + * + */ + public static final Key KEY_STATIC_QUALITY = new KeyOf(Quality.class); + + public RenderingQualityInteractor() { + super(); + } + + public Quality setStaticQuality(Quality staticQuality) { + Quality old = getHint(KEY_STATIC_QUALITY); + if (staticQuality != null) + setHint(KEY_STATIC_QUALITY, staticQuality); + else + removeHint(KEY_STATIC_QUALITY); + return old; + } + + private void setStaticQuality0(Quality staticQuality) { + if (!isEnabled()) + return; + NavigationNode nav = getNavigationNode(); + if (nav == null) + return; + //System.out.println("static rendering quality: " + staticQuality); + nav.setStaticQualityMode(staticQuality); + nav.setDynamicQuality(staticQuality == null); + } + + public boolean isEnabled() { + Boolean qualityPaint = getHint(KEY_QUALITY_INTERACTOR_ENABLED); + return !Boolean.FALSE.equals(qualityPaint); + } + + private NavigationNode getNavigationNode() { + G2DSceneGraph sg = getContext().getSceneGraph(); + INode node = sg.lookupNode(SceneGraphConstants.NAVIGATION_NODE_NAME); + return node instanceof NavigationNode ? (NavigationNode) node : null; + } + + @HintListener(Class = RenderingQualityInteractor.class, Field = "KEY_STATIC_QUALITY") + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + setStaticQuality0((Quality) newValue); + } + + @HintListener(Class = RenderingQualityInteractor.class, Field = "KEY_STATIC_QUALITY") + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + setStaticQuality0(null); + } + +}