001: /*--
002:
003: Copyright (C) 2000-2003 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The name "EdenLib" must not be used to endorse or promote products
019: derived from this software without prior written permission. For
020: written permission, please contact me@anthonyeden.com.
021:
022: 4. Products derived from this software may not be called "EdenLib", nor
023: may "EdenLib" appear in their name, without prior written permission
024: from Anthony Eden (me@anthonyeden.com).
025:
026: In addition, I request (but do not require) that you include in the
027: end-user documentation provided with the redistribution and/or in the
028: software itself an acknowledgement equivalent to the following:
029: "This product includes software developed by
030: Anthony Eden (http://www.anthonyeden.com/)."
031:
032: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
033: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
034: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
035: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
036: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
037: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
038: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
039: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
040: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
041: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
042: POSSIBILITY OF SUCH DAMAGE.
043:
044: For more information on EdenLib, please see <http://edenlib.sf.net/>.
045:
046: */
047:
048: package com.anthonyeden.lib.util;
049:
050: import javax.swing.ListModel;
051: import javax.swing.AbstractListModel;
052: import javax.swing.event.ListDataEvent;
053: import javax.swing.event.ListDataListener;
054:
055: /** A wrapper for a list model.
056:
057: @author Anthony Eden
058: */
059:
060: public class ListMap extends AbstractListModel implements
061: ListDataListener {
062:
063: /** The wrapped ListMode. */
064:
065: protected ListModel model;
066:
067: /** Get the model.
068:
069: @return The ListModel
070: */
071:
072: public ListModel getModel() {
073: return model;
074: }
075:
076: /** Set the model.
077:
078: @param model The list model
079: */
080:
081: public void setModel(ListModel model) {
082: this .model = model;
083: model.addListDataListener(this );
084: }
085:
086: /** Get the element at the given index.
087:
088: @param index The index
089: @return The element
090: */
091:
092: public Object getElementAt(int index) {
093: return model.getElementAt(index);
094: }
095:
096: /** Get the list model size.
097:
098: @return The size
099: */
100:
101: public int getSize() {
102: return model.getSize();
103: }
104:
105: /** This method can be called to signal that an interval specified
106: in the given event object has been added.
107:
108: @param evt The ListDataEvent object
109: */
110:
111: public void intervalAdded(ListDataEvent evt) {
112: fireIntervalAdded(evt.getSource(), evt.getIndex0(), evt
113: .getIndex1());
114: }
115:
116: /** This method can be called to signal that an interval specified
117: in the given event object has been removed.
118:
119: @param evt The ListDataEvent object
120: */
121:
122: public void intervalRemoved(ListDataEvent evt) {
123: fireIntervalRemoved(evt.getSource(), evt.getIndex0(), evt
124: .getIndex1());
125: }
126:
127: /** This method can be called to signal that an interval specified
128: in the given event object has been changed.
129:
130: @param evt The ListDataEvent object
131: */
132:
133: public void contentsChanged(ListDataEvent evt) {
134: fireIntervalRemoved(evt.getSource(), evt.getIndex0(), evt
135: .getIndex1());
136: }
137:
138: }
|