]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/TextColorImpl.java
Sync git svn branch with SVN repository r33324.
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / TextColorImpl.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.element.handler.impl;\r
13 \r
14 import org.simantics.g2d.diagram.IDiagram;\r
15 import org.simantics.g2d.element.ElementHints;\r
16 import org.simantics.g2d.element.IElement;\r
17 import org.simantics.g2d.element.handler.LifeCycle;\r
18 import org.simantics.g2d.element.handler.TextColor;\r
19 \r
20 /**\r
21  * \r
22  * @See {@link TextColor}\r
23  * @author Toni Kalajainen\r
24  */\r
25 public class TextColorImpl implements TextColor, LifeCycle {\r
26         \r
27     private static final long serialVersionUID = -3684758508037189899L;\r
28 \r
29     public static final TextColorImpl UNSET = new TextColorImpl(null);\r
30     public static final TextColorImpl BLACK = new TextColorImpl(java.awt.Color.BLACK);\r
31     public static final TextColorImpl WHITE = new TextColorImpl(java.awt.Color.WHITE);\r
32     public static final TextColorImpl RED = new TextColorImpl(java.awt.Color.RED);\r
33     public static final TextColorImpl BLUE = new TextColorImpl(java.awt.Color.BLUE);\r
34 \r
35     public synchronized static TextColorImpl handlerOf(java.awt.Color c)\r
36     {\r
37         return new TextColorImpl(c);\r
38     }\r
39 \r
40     java.awt.Color defaultColor = java.awt.Color.BLACK;\r
41 \r
42     public TextColorImpl() {}\r
43     public TextColorImpl(java.awt.Color defaultColor) {\r
44         this.defaultColor = defaultColor;\r
45     }\r
46 \r
47     @Override\r
48     public java.awt.Color getTextColor(IElement e) {            \r
49         return e.getHint(ElementHints.KEY_TEXT_COLOR);\r
50     }\r
51 \r
52     @Override\r
53     public void setTextColor(IElement e, java.awt.Color c) {\r
54         e.setHint(ElementHints.KEY_TEXT_COLOR, c);\r
55     }\r
56 \r
57     @Override\r
58     public void onElementActivated(IDiagram d, IElement e) {\r
59     }\r
60     @Override\r
61     public void onElementCreated(IElement e) {\r
62         if (defaultColor!=null)\r
63             e.setHint(ElementHints.KEY_TEXT_COLOR, defaultColor);\r
64     }\r
65     @Override\r
66     public void onElementDeactivated(IDiagram d, IElement e) {\r
67     }\r
68     @Override\r
69     public void onElementDestroyed(IElement e) {\r
70     }\r
71 }\r