From: David ‘Bombe’ Roden Date: Fri, 16 May 2008 15:16:21 +0000 (+0000) Subject: extract abstract bean superclass X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ce32d41fc7a9b72674d2bb42d0064293b38f06db;p=jSite2.git extract abstract bean superclass git-svn-id: http://trooper/svn/projects/jSite/trunk@899 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/jsite/core/Node.java b/src/net/pterodactylus/jsite/core/Node.java index 2058d99..b7359ca 100644 --- a/src/net/pterodactylus/jsite/core/Node.java +++ b/src/net/pterodactylus/jsite/core/Node.java @@ -19,12 +19,9 @@ package net.pterodactylus.jsite.core; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import net.pterodactylus.util.beans.AbstractBean; import net.pterodactylus.util.beans.Comparer; /** @@ -34,10 +31,7 @@ import net.pterodactylus.util.beans.Comparer; * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ -public class Node { - - /** Property change listeners. */ - private final List propertyChangeListeners = Collections.synchronizedList(new ArrayList()); +public class Node extends AbstractBean { /** Name of the “name” property. */ public static final String PROPERTY_NAME = "name"; @@ -62,48 +56,6 @@ public class Node { // /** - * Adds a property change listener. - * - * @param propertyChangeListener - * The property change listener to add - */ - public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) { - propertyChangeListeners.add(propertyChangeListener); - } - - /** - * Removes a property change listener. - * - * @param propertyChangeListener - * The property change listener to remove - */ - public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) { - propertyChangeListeners.remove(propertyChangeListener); - } - - /** - * Notifies all listeners that a property has changed. - * - * @param property - * The name of the property - * @param oldValue - * The old value of the property - * @param newValue - * The new value of the property - */ - private void firePropertyChange(String property, Object oldValue, Object newValue) { - PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(this, property, oldValue, newValue); - for (PropertyChangeListener propertyChangeListener: propertyChangeListeners) { - propertyChangeListener.propertyChange(propertyChangeEvent); - } - - } - - // - // ACCESSORS - // - - /** * Returns the user-given name of the node. * * @return The name of the node diff --git a/src/net/pterodactylus/jsite/core/Project.java b/src/net/pterodactylus/jsite/core/Project.java index e57c298..186ecb6 100644 --- a/src/net/pterodactylus/jsite/core/Project.java +++ b/src/net/pterodactylus/jsite/core/Project.java @@ -19,12 +19,9 @@ package net.pterodactylus.jsite.core; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import net.pterodactylus.util.beans.AbstractBean; import net.pterodactylus.util.beans.Comparer; /** @@ -34,10 +31,8 @@ import net.pterodactylus.util.beans.Comparer; * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ -public class Project { - - /** Property change listeners. */ - private final List propertyChangeListeners = Collections.synchronizedList(new ArrayList()); +public class Project extends +AbstractBean { /** Name of the “name” property. */ public static final String PROPERTY_NAME = "name"; @@ -74,48 +69,6 @@ public class Project { // /** - * Adds a property change listener. - * - * @param propertyChangeListener - * The property change listener to add - */ - public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) { - propertyChangeListeners.add(propertyChangeListener); - } - - /** - * Removes a property change listener. - * - * @param propertyChangeListener - * The property change listener to remove - */ - public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) { - propertyChangeListeners.remove(propertyChangeListener); - } - - /** - * Notifies all listeners that a property has changed. - * - * @param property - * The name of the property - * @param oldValue - * The old value of the property - * @param newValue - * The new value of the property - */ - private void firePropertyChange(String property, Object oldValue, Object newValue) { - PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(this, property, oldValue, newValue); - for (PropertyChangeListener propertyChangeListener: propertyChangeListeners) { - propertyChangeListener.propertyChange(propertyChangeEvent); - } - - } - - // - // ACCESSORS - // - - /** * Returns the name of the project. * * @return The name of the project diff --git a/src/net/pterodactylus/jsite/core/Request.java b/src/net/pterodactylus/jsite/core/Request.java index 4a65631..703ba57 100644 --- a/src/net/pterodactylus/jsite/core/Request.java +++ b/src/net/pterodactylus/jsite/core/Request.java @@ -19,12 +19,8 @@ package net.pterodactylus.jsite.core; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import net.pterodactylus.util.beans.AbstractBean; import net.pterodactylus.util.beans.Comparer; /** @@ -33,7 +29,8 @@ import net.pterodactylus.util.beans.Comparer; * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ -public class Request { +public class Request extends +AbstractBean { /** * The type of a request. @@ -81,9 +78,6 @@ public class Request { /** Name of the “total finalized” property. */ public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized"; - /** Property change listeners. */ - private final List propertyChangeListeners = Collections.synchronizedList(new ArrayList()); - /** The node the request belongs to. */ private final Node node; @@ -132,47 +126,6 @@ public class Request { // /** - * Adds a property change listener. - * - * @param propertyChangeListener - * The property change listener to add - */ - public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) { - propertyChangeListeners.add(propertyChangeListener); - } - - /** - * Removes a property change listener. - * - * @param propertyChangeListener - * The property change listener to remove - */ - public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) { - propertyChangeListeners.remove(propertyChangeListener); - } - - /** - * Notifies all listeners that a property has changed. - * - * @param property - * The name of the property - * @param oldValue - * The old value of the property - * @param newValue - * The new value of the property - */ - private void firePropertyChange(String property, Object oldValue, Object newValue) { - PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(this, property, oldValue, newValue); - for (PropertyChangeListener propertyChangeListener: propertyChangeListeners) { - propertyChangeListener.propertyChange(propertyChangeEvent); - } - } - - // - // ACCESSORS - // - - /** * Returns the node the request belongs to. * * @return The node the request belongs to diff --git a/src/net/pterodactylus/util/beans/AbstractBean.java b/src/net/pterodactylus/util/beans/AbstractBean.java new file mode 100644 index 0000000..0438c6d --- /dev/null +++ b/src/net/pterodactylus/util/beans/AbstractBean.java @@ -0,0 +1,77 @@ +/* + * jSite2 - AbstractBean.java + * Copyright © 2008 David Roden + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.pterodactylus.util.beans; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Abstract bean super class that contains property change listener management. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public class AbstractBean { + + /** Property change listeners. */ + private final List propertyChangeListeners = Collections.synchronizedList(new ArrayList()); + + /** + * Adds a property change listener. + * + * @param propertyChangeListener + * The property change listener to add + */ + public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) { + propertyChangeListeners.add(propertyChangeListener); + } + + /** + * Removes a property change listener. + * + * @param propertyChangeListener + * The property change listener to remove + */ + public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) { + propertyChangeListeners.remove(propertyChangeListener); + } + + /** + * Notifies all listeners that a property has changed. + * + * @param property + * The name of the property + * @param oldValue + * The old value of the property + * @param newValue + * The new value of the property + */ + protected void firePropertyChange(String property, Object oldValue, Object newValue) { + PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(this, property, oldValue, newValue); + for (PropertyChangeListener propertyChangeListener: propertyChangeListeners) { + propertyChangeListener.propertyChange(propertyChangeEvent); + } + + } + +}