View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.common.model;
19  
20  import com.google.gwt.user.client.rpc.IsSerializable;
21  
22  /**
23   * Class to represent a graphical attribute such as line width
24   * or line color
25   */
26  public class Attribute implements IsSerializable {
27  	public static final Attribute LINE_STYLE = new Attribute("stroke.style", null);
28  	public static final Attribute LINE_OPACITY = new Attribute("stroke.opacity", new FloatAttributeValue(1.0f));
29  	public static final Attribute LINE_PATTERN = new Attribute("stroke.pattern", null);
30  	public static final Attribute LINE_CAP = new Attribute("stroke.cap", null);
31  	public static final Attribute LINE_WIDTH = new Attribute("stroke.width", new FloatAttributeValue(1.0f));
32  	public static final Attribute FILL_STYLE = new Attribute("fill.style", null);
33  	public static final Attribute FILL_OPACITY = new Attribute("fill.opacity", new FloatAttributeValue(1.0f));
34  	private String _id;
35  	private transient String _name;
36  	private IAttributeValue _defaultValue;
37  	
38  	public Attribute() {
39  		// For GWT serialization.
40  	}
41  	private Attribute(String id, IAttributeValue defaultValue) {
42  		_id = id;
43  		_defaultValue = defaultValue;
44  	}
45  	
46  	@Override
47  	public boolean equals(Object obj) {
48  		if (obj instanceof Attribute) {
49  			return _id.equals(((Attribute)obj)._id);
50  		}
51  		return false;
52  	}
53  	
54  	@Override
55  	public int hashCode() {
56  		return _id.hashCode();
57  	}
58  	
59  	/**
60  	 * Returns the attribute immutable identifier
61  	 * @return
62  	 * the attribute immutable identifier
63  	 */
64  	public String getId() {
65  		return _id;
66  	}
67  	
68  	/**
69  	 * Returns the attribute display name
70  	 * @return
71  	 * the attribute display name
72  	 */
73  	public String getName() {
74  		return _name;
75  	}
76  	
77  	/**
78  	 * Sets the attribute display name
79  	 * @param name
80  	 * the attribute display name
81  	 */
82  	public void setName(String name) {
83  		_name = name;
84  	}
85  	
86  	public IAttributeValue getDefaultValue() {
87  		return _defaultValue;
88  	}
89  	
90  	@Override
91  	public String toString() {
92  		return _id;
93  	}
94  }