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