1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element.handler.impl;
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;
25 * @See {@link TextFont}
26 * @author Marko Luukkainen
28 public class TextFontImpl implements TextFont, LifeCycle {
30 private static final long serialVersionUID = -6254972866736454459L;
32 public static TextFontImpl DEFAULT = new TextFontImpl();
35 public synchronized static TextFontImpl handlerOf(java.awt.Font f)
37 return new TextFontImpl(f);
40 java.awt.Font defaultFont;
42 public TextFontImpl() {
43 this.defaultFont = new Font("Arial", Font.PLAIN, 12);
45 public TextFontImpl(java.awt.Font defaultFont) {
46 this.defaultFont = defaultFont;
50 public java.awt.Font getFont(IElement e) {
51 return e.getHint(ElementHints.KEY_FONT);
55 public void setFont(IElement e, java.awt.Font f) {
56 e.setHint(ElementHints.KEY_FONT, f);
60 public void onElementActivated(IDiagram d, IElement e) {
63 public void onElementCreated(IElement e) {
64 if (defaultFont!=null)
65 e.setHint(ElementHints.KEY_FONT, defaultFont);
68 public void onElementDeactivated(IDiagram d, IElement e) {
71 public void onElementDestroyed(IElement e) {
75 public int hashCode() {
76 return ObjectUtils.hashCode(defaultFont);
79 public boolean equals(Object obj) {
84 if (getClass() != obj.getClass())
86 TextFontImpl other = (TextFontImpl) obj;
87 return ObjectUtils.objectEquals(defaultFont, other.defaultFont);