X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fparticipant%2FBackgroundPainter.java;h=d524e628127a23ced2b92c38284ebbdbd5b530ac;hb=3598f987e691cb4f35ab8f283d4dfd760bcdd410;hp=0dea402fbefbdea02fb1dd676bc581672eb176da;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/BackgroundPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/BackgroundPainter.java index 0dea402fb..d524e6281 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/BackgroundPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/BackgroundPainter.java @@ -1,76 +1,76 @@ -/******************************************************************************* - * 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 java.awt.Color; -import java.awt.Paint; - -import org.simantics.g2d.canvas.Hints; -import org.simantics.g2d.canvas.SGDesignation; -import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; -import org.simantics.g2d.canvas.impl.HintReflection.HintListener; -import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup; -import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.scenegraph.g2d.nodes.BackgroundNode; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintObservable; - -/** - * Paints background wither with KEY_BACKGROUND_COLOR or KEY_BACKGROUND_PAINT. - * - * @see Hints#KEY_BACKGROUND_COLOR - * @see Hints#KEY_BACKGROUND_PAINT - * @author Toni Kalajainen - */ -public class BackgroundPainter extends AbstractCanvasParticipant { - - protected BackgroundNode node = null; - - @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_COLOR") - public void colorChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { - if (node != null) { - Color c = getHint(Hints.KEY_BACKGROUND_COLOR); - node.setColor(c); - setDirty(); - } - } - - @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_PAINT") - public void paintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { - if (node != null) { - Paint p = getHint(Hints.KEY_BACKGROUND_PAINT); - node.setPaint(p); - setDirty(); - } - } - - @SGInit(designation = SGDesignation.CONTROL) - public void initSG(G2DParentNode parent) { - node = parent.addNode("background", BackgroundNode.class); - node.setZIndex(Integer.MIN_VALUE / 2); - - Color c = getHint(Hints.KEY_BACKGROUND_COLOR); - Paint p = getHint(Hints.KEY_BACKGROUND_PAINT); - node.setColor(c); - node.setPaint(p); - } - - @SGCleanup - public void cleanupSG() { - if (node != null) { - node.remove(); - node = null; - } - } - +/******************************************************************************* + * 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 java.awt.Color; +import java.awt.Paint; + +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.canvas.SGDesignation; +import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; +import org.simantics.g2d.canvas.impl.HintReflection.HintListener; +import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup; +import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.BackgroundNode; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * Paints background wither with KEY_BACKGROUND_COLOR or KEY_BACKGROUND_PAINT. + * + * @see Hints#KEY_BACKGROUND_COLOR + * @see Hints#KEY_BACKGROUND_PAINT + * @author Toni Kalajainen + */ +public class BackgroundPainter extends AbstractCanvasParticipant { + + protected BackgroundNode node = null; + + @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_COLOR") + public void colorChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + if (node != null) { + Color c = getHint(Hints.KEY_BACKGROUND_COLOR); + node.setColor(c); + setDirty(); + } + } + + @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_PAINT") + public void paintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + if (node != null) { + Paint p = getHint(Hints.KEY_BACKGROUND_PAINT); + node.setPaint(p); + setDirty(); + } + } + + @SGInit(designation = SGDesignation.CONTROL) + public void initSG(G2DParentNode parent) { + node = parent.addNode("background", BackgroundNode.class); + node.setZIndex(Integer.MIN_VALUE / 2); + + Color c = getHint(Hints.KEY_BACKGROUND_COLOR); + Paint p = getHint(Hints.KEY_BACKGROUND_PAINT); + node.setColor(c); + node.setPaint(p); + } + + @SGCleanup + public void cleanupSG() { + if (node != null) { + node.remove(); + node = null; + } + } + } \ No newline at end of file