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 java.awt.Color;
15 import java.awt.Paint;
17 import org.simantics.g2d.canvas.Hints;
18 import org.simantics.g2d.canvas.SGDesignation;
19 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
20 import org.simantics.g2d.canvas.impl.HintReflection.HintListener;
21 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
22 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
23 import org.simantics.scenegraph.g2d.G2DParentNode;
24 import org.simantics.scenegraph.g2d.nodes.BackgroundNode;
25 import org.simantics.utils.datastructures.hints.IHintContext.Key;
26 import org.simantics.utils.datastructures.hints.IHintObservable;
29 * Paints background wither with KEY_BACKGROUND_COLOR or KEY_BACKGROUND_PAINT.
31 * @see Hints#KEY_BACKGROUND_COLOR
32 * @see Hints#KEY_BACKGROUND_PAINT
33 * @author Toni Kalajainen
35 public class BackgroundPainter extends AbstractCanvasParticipant {
37 protected BackgroundNode node = null;
39 @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_COLOR")
40 public void colorChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
42 Color c = getHint(Hints.KEY_BACKGROUND_COLOR);
48 @HintListener(Class=Hints.class, Field="KEY_BACKGROUND_PAINT")
49 public void paintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
51 Paint p = getHint(Hints.KEY_BACKGROUND_PAINT);
57 @SGInit(designation = SGDesignation.CONTROL)
58 public void initSG(G2DParentNode parent) {
59 node = parent.addNode("background", BackgroundNode.class);
60 node.setZIndex(Integer.MIN_VALUE / 2);
62 Color c = getHint(Hints.KEY_BACKGROUND_COLOR);
63 Paint p = getHint(Hints.KEY_BACKGROUND_PAINT);
69 public void cleanupSG() {