1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.participant;
\r
14 import java.awt.Color;
\r
15 import java.awt.Paint;
\r
17 import org.simantics.g2d.canvas.Hints;
\r
18 import org.simantics.g2d.canvas.SGDesignation;
\r
19 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
\r
20 import org.simantics.g2d.canvas.impl.HintReflection.HintListener;
\r
21 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
\r
22 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
\r
23 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
24 import org.simantics.scenegraph.g2d.nodes.BackgroundNode;
\r
25 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
26 import org.simantics.utils.datastructures.hints.IHintObservable;
\r
29 * Paints background wither with KEY_BACKGROUND_COLOR or KEY_BACKGROUND_PAINT.
\r
31 * @see Hints#KEY_BACKGROUND_COLOR
\r
32 * @see Hints#KEY_BACKGROUND_PAINT
\r
33 * @author Toni Kalajainen
\r
35 public class BackgroundPainter extends AbstractCanvasParticipant {
\r
37 protected BackgroundNode node = null;
\r
39 @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_COLOR")
\r
40 public void colorChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
\r
42 Color c = getHint(Hints.KEY_BACKGROUND_COLOR);
\r
48 @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_PAINT")
\r
49 public void paintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
\r
51 Paint p = getHint(Hints.KEY_BACKGROUND_PAINT);
\r
57 @SGInit(designation = SGDesignation.CONTROL)
\r
58 public void initSG(G2DParentNode parent) {
\r
59 node = parent.addNode("background", BackgroundNode.class);
\r
60 node.setZIndex(Integer.MIN_VALUE / 2);
\r
62 Color c = getHint(Hints.KEY_BACKGROUND_COLOR);
\r
63 Paint p = getHint(Hints.KEY_BACKGROUND_PAINT);
\r
69 public void cleanupSG() {
\r