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