Process manager without undo/redo.

JAVA PRIMER
JCommands: A Flexible Undo Framework for Java

Andreas Bäcker
Listing 1. Process manager without undo/redo.


class ProcessManager extends java.util.Observable {
	// The notification message identifiers
	public static final int ADDED = 0;
	public static final int REMOVED = 1;

	// The collection of process descriptors
	private Vector processes;

	// Adds a descriptor and notifies observers
	public void add(ProcessDesc p) {
		processes.addElement(p);
		setChanged(); // raises the changed flag
		notifyObservers(new CmdArg1(ADDED, p));
	}

	// Removes a descriptor and notifies
	// the process manager's observers
	public void remove(ProcessDesc p) {
		if( processes.removeObject(p) ) {
			setChanged();
			notifyObservers(new CmdArg1(REMOVED, p));
		}
	}

	// Removes a number of descriptors
	public void removeMany(Collection c) {
		Iterator it = c.iterator();
		while( it.hasNext() )
			remove((ProcessDesc)it.next());
	}
}

Featured

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.