1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.layers;
\r
14 import java.util.concurrent.CopyOnWriteArrayList;
\r
17 * @author Antti Villberg
\r
19 public class SimpleLayer implements IEditableLayer {
\r
21 private CopyOnWriteArrayList<ILayerListener> listeners = new CopyOnWriteArrayList<ILayerListener>();
\r
23 private String name;
\r
25 public SimpleLayer(String name) {
\r
27 throw new IllegalArgumentException("null name");
\r
32 public String getName() {
\r
37 public void setName(String name) {
\r
39 throw new IllegalArgumentException("null name");
\r
40 String oldName = this.name;
\r
42 if (!name.equals(oldName)) {
\r
43 fireLayerChanged(new LayerChangeEvent(this, PROP_NAME, oldName, name));
\r
48 public int hashCode() {
\r
49 return name.hashCode();
\r
53 public boolean equals(Object obj) {
\r
58 if (getClass() != obj.getClass())
\r
60 SimpleLayer other = (SimpleLayer) obj;
\r
61 return name.equals(other.name);
\r
65 public void addLayerListener(ILayerListener l) {
\r
70 public void removeLayerListener(ILayerListener l) {
\r
71 listeners.remove(l);
\r
74 protected void fireLayerChanged(LayerChangeEvent event) {
\r
75 for (ILayerListener l : listeners) {
\r
76 l.layerChanged(event);
\r
81 public String toString() {
\r
82 return getClass().getSimpleName() + "[" + name + "]";
\r