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.layers;
14 import java.util.concurrent.CopyOnWriteArrayList;
17 * @author Antti Villberg
19 public class SimpleLayer implements IEditableLayer {
21 private CopyOnWriteArrayList<ILayerListener> listeners = new CopyOnWriteArrayList<ILayerListener>();
25 public SimpleLayer(String name) {
27 throw new IllegalArgumentException("null name");
32 public String getName() {
37 public void setName(String name) {
39 throw new IllegalArgumentException("null name");
40 String oldName = this.name;
42 if (!name.equals(oldName)) {
43 fireLayerChanged(new LayerChangeEvent(this, PROP_NAME, oldName, name));
48 public int hashCode() {
49 return name.hashCode();
53 public boolean equals(Object obj) {
58 if (getClass() != obj.getClass())
60 SimpleLayer other = (SimpleLayer) obj;
61 return name.equals(other.name);
65 public void addLayerListener(ILayerListener l) {
70 public void removeLayerListener(ILayerListener l) {
74 protected void fireLayerChanged(LayerChangeEvent event) {
75 for (ILayerListener l : listeners) {
76 l.layerChanged(event);
81 public String toString() {
82 return getClass().getSimpleName() + "[" + name + "]";