001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: KListModelAdapter.java,v $
023   Revision 1.1  2004/05/13 21:40:21  markl
024   new classes
025
026   ----------------------------------------------------------------------------
027*/
028
029package kiwi.ui.model;
030
031import java.util.*;
032import javax.swing.event.*;
033
034import kiwi.event.*;
035
036/** A base class for <code>KListModel</code> adapters. See subclasses for
037 * details.
038 *
039 * @author Mark Lindner
040 * @since Kiwi 2.0
041 */
042
043public abstract class KListModelAdapter implements KListModelListener
044  {
045  /**
046   * The <code>KListModel</code> which is wrapped by this adapter.
047   */
048  protected KListModel model = null;
049  /**
050   * The model-specific list of listeners for this adapter.
051   */
052  protected Vector listeners = new Vector();
053
054  /** Construct a new <code>KListModelAdapter</code>.
055   */
056
057  protected KListModelAdapter()
058    {
059    }
060  
061  /** Set the <code>KListModel</code> for this adapter.
062   *
063   * @param model The model.
064   */
065  
066  public void setListModel(KListModel model)
067    {
068    if(this.model != null)
069      this.model.removeListModelListener(this);
070    this.model = model;
071    _init();
072    }
073
074  /* initialization code */
075
076  private void _init()
077    {
078    if(model != null)
079      model.addListModelListener(this);
080
081    fireModelChangedEvent();
082    }
083
084  /** Get the <code>KListModel</code> for this adapter.
085   *
086   * @return The model.
087   */
088  
089  public KListModel getListModel()
090    {
091    return(model);
092    }
093
094  /** Fire the appropriate event to indicate that the wrapped data model
095   * has changed significantly. This method is called whenever the
096   * <code>KListModel</code> for this adapter is changed.
097   */
098
099  protected abstract void fireModelChangedEvent();
100
101  /*
102   */
103
104  public abstract void itemsAdded(KListModelEvent evt);
105
106  /*
107   */
108  
109  public abstract void itemsChanged(KListModelEvent evt);
110
111  /*
112   */
113
114  public abstract void itemsRemoved(KListModelEvent evt);
115
116  /*
117   */
118
119  public abstract void dataChanged(KListModelEvent evt);
120
121  /** Add a list model listener. Adds a <code>ListDataListener</code> to
122    * this adapter's list of list model listeners.
123    *
124    * @param listener The listener to add.
125    */
126  
127  public void addListDataListener(ListDataListener listener)
128    {
129    listeners.addElement(listener);
130    }
131
132  /** Remove a list model listener. Removes a <code>ListDataListener</code>
133    * from this adapter's list of list model listeners.
134    *
135    * @param listener The listener to remove.
136    */
137  
138  public void removeListDataListener(ListDataListener listener)
139    {
140    listeners.removeElement(listener);
141    }
142  
143  }
144
145/* end of source file */