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