Additional Code - zip file

Listing 1

public void add(int index, E element) {
	super.add(index, e);
	fireIntervalAdded(index, index);
}

public Object remove(int index) {
	Object obj = super.remove(index);
	if (obj != null) {
		fireIntervalRemoved(index, index);
	}
	return obj;
}

public E set(int index, E element) {
	element = super.set(index, element);
	fireIntervalUpdated(index, index);
	return element;
}


Listing 2

protected void fireIntervalAdded(int firstIndex, int lastIndex) {
	if (listDataListeners != null) {
ListDataEvent e = new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, firstIndex,
 lastIndex);
		for (ListDataListener listener: listDataListeners) {
				listener.intervalAdded(e);
		}
}
}

protected void fireIntervalRemoved(int firstIndex, int lastIndex) {
	if (listDataListeners != null) {
ListDataEvent e = new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, firstIndex,
 lastIndex);
		for (ListDataListener listener: listDataListeners) {
				listener.intervalRemoved(e);
		}
}
}

protected void fireIntervalUpdated(int firstIndex, int lastIndex) {
	if (listDataListeners != null) {
ListDataEvent e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, firstIndex,
 lastIndex);
		for (ListDataListener listener: listDataListeners) {
				listener.contentsChanged(e);
		}
	}
}


Listing 3]

private static class ColorItem {
	private String name;
	private ColorIcon icon;
	public ColorItem(String name, Color color) {
		this.name = name;
		icon = new ColorIcon(color);
	}
	public String toString() {
		return name;
	}
	public Icon getIcon() {
		return icon;
	}
}


Listing 4

private static JToolBar getToolBar(Iterator
	 colorItems, final List list) {
	JToolBar toolBar = new JToolBar();
	toolBar.setFloatable(false);
	while (colorItems.hasNext()) {
		final ColorItem item = colorItems.next();
		final JToggleButton toggle = new ToggleButton(item.getIcon());
		toolBar.add(toggle);
		toggle.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (toggle.isSelected()) {
					list.add(item);
				} else {
					list.remove(item);
				}
			}
		});
	}
	return toolBar;
}


Listing 5

public interface UIElement {
	Object getItem();
	String getDescription();
	Icon   getSmallIcon();
	Icon   getLargeIcon();
	JComponent getComponent();
}

Additional Code - zip file