]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/TextFontImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / TextFontImpl.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.Font;
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.LifeCycle;
20 import org.simantics.g2d.element.handler.TextFont;
21 import org.simantics.utils.ObjectUtils;
22
23 /**
24  * 
25  * @See {@link TextFont}
26  * @author Marko Luukkainen
27  */
28 public class TextFontImpl implements TextFont, LifeCycle {
29
30     private static final long serialVersionUID = -6254972866736454459L;
31
32     public static TextFontImpl DEFAULT = new TextFontImpl();
33
34
35     public synchronized static TextFontImpl handlerOf(java.awt.Font f)
36     {
37         return new TextFontImpl(f);
38     }
39
40     java.awt.Font defaultFont;
41
42     public TextFontImpl() {
43         this.defaultFont = new Font("Arial", Font.PLAIN, 12);
44     }
45     public TextFontImpl(java.awt.Font defaultFont) {
46         this.defaultFont = defaultFont;
47     }
48
49     @Override
50     public java.awt.Font getFont(IElement e) {          
51         return e.getHint(ElementHints.KEY_FONT);
52     }
53
54     @Override
55     public void setFont(IElement e, java.awt.Font f) {
56         e.setHint(ElementHints.KEY_FONT, f);
57     }
58
59     @Override
60     public void onElementActivated(IDiagram d, IElement e) {
61     }
62     @Override
63     public void onElementCreated(IElement e) {
64         if (defaultFont!=null)
65             e.setHint(ElementHints.KEY_FONT, defaultFont);
66     }
67     @Override
68     public void onElementDeactivated(IDiagram d, IElement e) {
69     }
70     @Override
71     public void onElementDestroyed(IElement e) {
72     }
73
74     @Override
75     public int hashCode() {
76         return ObjectUtils.hashCode(defaultFont);
77     }
78     @Override
79     public boolean equals(Object obj) {
80         if (this == obj)
81             return true;
82         if (obj == null)
83             return false;
84         if (getClass() != obj.getClass())
85             return false;
86         TextFontImpl other = (TextFontImpl) obj;
87         return ObjectUtils.objectEquals(defaultFont, other.defaultFont);
88     }
89 }