]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/layers/SimpleLayer.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / layers / SimpleLayer.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.layers;
13
14 import java.util.concurrent.CopyOnWriteArrayList;
15
16 /**
17  * @author Antti Villberg
18  */
19 public class SimpleLayer implements IEditableLayer {
20
21     private CopyOnWriteArrayList<ILayerListener> listeners = new CopyOnWriteArrayList<ILayerListener>();
22
23     private String name;
24
25     public SimpleLayer(String name) {
26         if (name == null)
27             throw new IllegalArgumentException("null name");
28         this.name = name;
29     }
30
31     @Override
32     public String getName() {
33         return name;
34     }
35
36     @Override
37     public void setName(String name) {
38         if (name == null)
39             throw new IllegalArgumentException("null name");
40         String oldName = this.name;
41         this.name = name;
42         if (!name.equals(oldName)) {
43             fireLayerChanged(new LayerChangeEvent(this, PROP_NAME, oldName, name));
44         }
45     }
46
47     @Override
48     public int hashCode() {
49         return name.hashCode();
50     }
51
52     @Override
53     public boolean equals(Object obj) {
54         if (this == obj)
55             return true;
56         if (obj == null)
57             return false;
58         if (getClass() != obj.getClass())
59             return false;
60         SimpleLayer other = (SimpleLayer) obj;
61         return name.equals(other.name);
62     }
63
64     @Override
65     public void addLayerListener(ILayerListener l) {
66         listeners.add(l);
67     }
68
69     @Override
70     public void removeLayerListener(ILayerListener l) {
71         listeners.remove(l);
72     }
73
74     protected void fireLayerChanged(LayerChangeEvent event) {
75         for (ILayerListener l : listeners) {
76             l.layerChanged(event);
77         }
78     }
79
80     @Override
81     public String toString() {
82         return getClass().getSimpleName() + "[" + name + "]";
83     }
84
85 }