Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * OfficeFloor - http://www.officefloor.net
   * Copyright (C) 2005-2011 Daniel Sagenschneider
   *
   * 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 3 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, see <http://www.gnu.org/licenses/>.
  */
 
 package net.officefloor.model;
 
 import java.util.List;

Provides top level functionality for all model elements.

Author(s):
Daniel Sagenschneider
 
 public class AbstractModel implements Model {

Support in handling property changes.
 
 			this);

The X location for the model.
 
 	private int x = -1;

The Y location for the model.
 
 	private int y = -1;

Fires a property change event.

Parameters:
property Property related to the event.
oldValue Old value of property.
newValue New value of property.
 
 	public void firePropertyChange(String propertyObject oldValue,
 			Object newValue) {
 		if (this..hasListeners(property)) {
 			this..firePropertyChange(propertyoldValue,
 					newValue);
 		}
 	}

Helper method to add an Item to a List.

Parameters:
item Item to add to list.
list List to have item to add.
addEvent Event to fire on item being added.
 
 	protected <T> void addItemToList(T itemList<T> listEnum<?> addEvent) {
 		if (!list.contains(item)) {
 			list.add(item);
 
 			// Notify item added
 			this.firePropertyChange(addEvent.name(), nullitem);
 		}
 	}

Helper method to remove an Item from a List.

Parameters:
item Item to remove from list.
list List to have item removed.
removeEvent Event to fire on item being removed.
 
 	protected <T> void removeItemFromList(T itemList<T> list,
 			Enum<?> removeEvent) {
 		if (list.contains(item)) {
 			list.remove(item);
 
			// Notify item removed
			this.firePropertyChange(removeEvent.name(), itemnull);
		}
	}

Helper method to change a field.

Parameters:
oldValue Old value of field.
newValue New value of field.
changeEvent Event to fire if field is being changed.
	protected <T> void changeField(T oldValue, T newValueEnum<?> changeEvent) {
		// Determine if both null
		if ((oldValue == null) && (newValue == null)) {
			// No change and values both null
			return;
else if ((oldValue != null) && (newValue != null)) {
			// Both not null thus check for equality
			if (oldValue.equals(newValue)) {
				// No change as values equal
				return;
else {
				// Values different
				this.firePropertyChange(changeEvent.name(), oldValuenewValue);
				return;
			}
else {
			// Either being set or nulled
			this.firePropertyChange(changeEvent.name(), oldValuenewValue);
			return;
		}
	}
	/*
	 * =================== Model ==========================================
	 */
	public int getX() {
		return this.;
	}
	public void setX(int x) {
		this. = x;
	}
	public int getY() {
		return this.;
	}
	public void setY(int y) {
		this. = y;
	}
	public synchronized void addPropertyChangeListener(
	}
	public synchronized void removePropertyChangeListener(
	}
New to GrepCode? Check out our FAQ X