--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.participant;\r
+\r
+import java.awt.Color;\r
+import java.awt.Paint;\r
+\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.canvas.SGDesignation;\r
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
+import org.simantics.g2d.canvas.impl.HintReflection.HintListener;\r
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;\r
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.nodes.BackgroundNode;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+\r
+/**\r
+ * Paints background wither with KEY_BACKGROUND_COLOR or KEY_BACKGROUND_PAINT.\r
+ * \r
+ * @see Hints#KEY_BACKGROUND_COLOR\r
+ * @see Hints#KEY_BACKGROUND_PAINT\r
+ * @author Toni Kalajainen\r
+ */\r
+public class BackgroundPainter extends AbstractCanvasParticipant {\r
+\r
+ protected BackgroundNode node = null;\r
+\r
+ @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_COLOR")\r
+ public void colorChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+ if (node != null) {\r
+ Color c = getHint(Hints.KEY_BACKGROUND_COLOR);\r
+ node.setColor(c);\r
+ setDirty();\r
+ }\r
+ }\r
+\r
+ @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_PAINT")\r
+ public void paintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+ if (node != null) {\r
+ Paint p = getHint(Hints.KEY_BACKGROUND_PAINT);\r
+ node.setPaint(p);\r
+ setDirty();\r
+ }\r
+ }\r
+\r
+ @SGInit(designation = SGDesignation.CONTROL)\r
+ public void initSG(G2DParentNode parent) {\r
+ node = parent.addNode("background", BackgroundNode.class);\r
+ node.setZIndex(Integer.MIN_VALUE / 2);\r
+\r
+ Color c = getHint(Hints.KEY_BACKGROUND_COLOR);\r
+ Paint p = getHint(Hints.KEY_BACKGROUND_PAINT);\r
+ node.setColor(c);\r
+ node.setPaint(p);\r
+ }\r
+\r
+ @SGCleanup\r
+ public void cleanupSG() {\r
+ if (node != null) {\r
+ node.remove();\r
+ node = null;\r
+ }\r
+ }\r
+\r
+}
\ No newline at end of file