]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/TextColorSynchronizer.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / TextColorSynchronizer.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.synchronization.graph;
13
14 import java.awt.Color;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.Resource;
18 import org.simantics.diagram.synchronization.IModificationQueue;
19 import org.simantics.diagram.synchronization.ISynchronizationContext;
20 import org.simantics.g2d.element.ElementHints;
21 import org.simantics.utils.datastructures.hints.IHintObservable;
22 import org.simantics.utils.datastructures.hints.IHintContext.Key;
23
24 /**
25  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
26  */
27 public class TextColorSynchronizer extends ResourceSynchronizer {
28
29     public static final TextColorSynchronizer INSTANCE = new TextColorSynchronizer();
30
31     private static final Key[] SYNCHRONIZED_HINTS = {
32         ElementHints.KEY_TEXT_COLOR
33     };
34
35     @Override
36     public Key[] getSynchronizedHints() {
37         return SYNCHRONIZED_HINTS;
38     }
39
40     @Override
41     public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) {
42         if (ElementHints.KEY_TEXT_COLOR.equals(key)) {
43             BasicResources br = context.get(GraphSynchronizationHints.BASIC_RESOURCES);
44             Color color = (Color)newValue;
45             float array[] = color.getRGBComponents(null);
46             return queue.offer(new PropertyModification(object, br.G2D.HasColor, br.G2D.Color, array, Bindings.FLOAT_ARRAY), null);
47         }
48         return false;
49     }
50
51 }