QJCC homepage

biz.chitec.quarterback.swing
Class NumberedStringListModel

java.lang.Object
  extended byjavax.swing.AbstractListModel
      extended bybiz.chitec.quarterback.swing.NumberedStringListModel
All Implemented Interfaces:
ChangeableListModel, javax.swing.ListModel, java.io.Serializable
Direct Known Subclasses:
NumberedStringComboBoxModel

public class NumberedStringListModel
extends javax.swing.AbstractListModel
implements ChangeableListModel

List model for Lists of NumberedStrings. Has nice special methods for handling the lists (e.g. intelligent insertion) and several methods to transform between GUI indices and NumberedString indices

Version:
$Id: 80b67f6cbed6f3197d1c7890704cceb640479cd6 $
Author:
Dirk Hillbrecht/chitec 1997-2000. Distributed under the terms of the GNU LGPL.
See Also:
Serialized Form

Field Summary
protected  boolean addnrfirst
           
protected  boolean dosort
           
protected  java.util.List mydata
           
protected  javax.swing.JList mylist
           
protected  boolean showaddnr
           
protected  boolean sortbyname
           
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
NumberedStringListModel()
          initializes with neither data list nor show-additional-number-flag
NumberedStringListModel(boolean sad)
          initializes with show-additional-number-flag only
NumberedStringListModel(ChatSymbolHolder csh)
          Initialize with symbols from given ChatSymbolHolder, take all symbols.
NumberedStringListModel(ChatSymbolHolder csh, int[] idxx)
          Initialize with symbols from given ChatSymbolHolder.
NumberedStringListModel(java.util.List v)
          initializes with data list only
NumberedStringListModel(java.util.List v, boolean sad)
          initializes with data list and show-additional-number-flag given
 
Method Summary
 void add(java.lang.Object element)
          Adds a single element to the model.
 void addAll(java.util.List v)
           
 void addContent(java.util.List newdata)
          adds some content at the end of already existing one.
 void addFromChatSymbolHolder(ChatSymbolHolder csh)
          Adds all symbols from the given ChatSymbolHolder to the model.
 void addFromChatSymbolHolder(ChatSymbolHolder csh, int[] idxx)
          Add content to the chat data model from a chat symbol holder.
 int Addnr2GUIIdx(int addnr)
          Translates NumberedString's addnr into the GUI index of the NumberedString.
 boolean changeContent(java.util.List v)
          replace content with new content.
private static void changeInIntArray(int[] a, int swap1, int swap2)
           
 void clear()
          Removes all elements.
 boolean containsNSIdx(int nsidx)
          Checks if there is a NumberedString with the given internal index.
private static int[] deleteFromIntArray(int[] a, int delval)
           
 boolean getAddNrFirst()
           
 java.util.List getContent()
          returns the content list
 java.lang.Object getElementAt(int idx)
          returns an element with GUI index This is a list model interface method.
 javax.swing.JList getList()
           
 NumberedString getNSbyNSIdx(int nsidx)
          Returns one NumberedString by its own index field.
 boolean getShowAddNr()
           
 int getSize()
          returns size of data list.
 int GUI2NSAddNr(int guiidx)
          Translates GUI index into additional number of NumberedString at that position.
 int GUI2NSIdx(int guiidx)
          Translates GUI index into index of NumberedString at that position.
 int[] GUI2NSIdx(int[] guiidx)
          Translates several GUI indices into their internal NumberedString counterparts.
 boolean isSortByName()
           
 boolean isSorting()
           
 int[] lazyNS2GUIIdx(int[] nsidx)
          Converts elements of given int array to GUI index.
 int[] lazyNS2GUIIdx(java.util.List nsidx)
          Converts elements of given List to GUI index.
 int NS2GUIIdx(int nsidx)
          Translates internal NumberedString index into the GUI index of the NumberedString.
 int[] NS2GUIIdx(int[] guiidx)
          Translates several internal NumberedString indices into their GUI counterparts.
 java.lang.Object remove(int index)
          Removes a certain element from the model.
 void removeContent()
          removes all content.
 void setAddNrFirst(boolean addnrfirstx)
           
 void setContent(java.util.List newdata)
          sets new content.
 void setList(javax.swing.JList lx)
           
 void setShowAddNr(boolean sad)
           
 void setSortByName(boolean s)
           
 void setSorting(boolean s)
           
private  void sortMe()
           
 void trimToExternalList(java.util.List v)
          Trims contents of this model to external List.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

mydata

protected java.util.List mydata

showaddnr

protected boolean showaddnr

addnrfirst

protected boolean addnrfirst

mylist

protected javax.swing.JList mylist

dosort

protected boolean dosort

sortbyname

protected boolean sortbyname
Constructor Detail

NumberedStringListModel

public NumberedStringListModel(java.util.List v,
                               boolean sad)
initializes with data list and show-additional-number-flag given


NumberedStringListModel

public NumberedStringListModel(boolean sad)
initializes with show-additional-number-flag only


NumberedStringListModel

public NumberedStringListModel(java.util.List v)
initializes with data list only


NumberedStringListModel

public NumberedStringListModel()
initializes with neither data list nor show-additional-number-flag


NumberedStringListModel

public NumberedStringListModel(ChatSymbolHolder csh,
                               int[] idxx)
Initialize with symbols from given ChatSymbolHolder.


NumberedStringListModel

public NumberedStringListModel(ChatSymbolHolder csh)
Initialize with symbols from given ChatSymbolHolder, take all symbols.

Method Detail

setList

public void setList(javax.swing.JList lx)
Specified by:
setList in interface ChangeableListModel

getList

public javax.swing.JList getList()
Specified by:
getList in interface ChangeableListModel

setShowAddNr

public void setShowAddNr(boolean sad)

getShowAddNr

public boolean getShowAddNr()

setAddNrFirst

public void setAddNrFirst(boolean addnrfirstx)

getAddNrFirst

public boolean getAddNrFirst()

setSorting

public void setSorting(boolean s)

isSorting

public boolean isSorting()

setSortByName

public void setSortByName(boolean s)

isSortByName

public boolean isSortByName()

changeInIntArray

private static void changeInIntArray(int[] a,
                                     int swap1,
                                     int swap2)

deleteFromIntArray

private static int[] deleteFromIntArray(int[] a,
                                        int delval)

sortMe

private void sortMe()

trimToExternalList

public void trimToExternalList(java.util.List v)
Trims contents of this model to external List. Quite complex operation: Test for each element of the model, whether it is also in the given List. If it is, remove it from the external list, if it is not, remove it from the model.

This method is needed to trim the model's content against any changes in the data underlying the model's filling. The method is given the new basic data, it decides for each currently included value whether it continues to be valid or not (e.g. whether it is in the new data or not). If it is not valid any more, it is removed (that's logical). If it continues to be valid, it is removed from the (new) data, so that that list contains only those elements which are really new and not yet in the model. Having it changed that way allows us just to append that list to the currently available data at the end (e.g. using addContent()) to ensure that all new data is in the model.

Specified by:
trimToExternalList in interface ChangeableListModel

getElementAt

public java.lang.Object getElementAt(int idx)
returns an element with GUI index This is a list model interface method.

Specified by:
getElementAt in interface javax.swing.ListModel

getSize

public int getSize()
returns size of data list. If no data are given, 0 is returned.

Specified by:
getSize in interface javax.swing.ListModel

setContent

public void setContent(java.util.List newdata)
sets new content. Informs all interested objects through a contents changed event.


addContent

public void addContent(java.util.List newdata)
adds some content at the end of already existing one. Informs all interested objects through a contents changed event.


addAll

public void addAll(java.util.List v)
Specified by:
addAll in interface ChangeableListModel

removeContent

public void removeContent()
removes all content. Fires event also.


getContent

public java.util.List getContent()
returns the content list


changeContent

public boolean changeContent(java.util.List v)
replace content with new content. return true if content had really to be replaced (there were differences), false if new and old content didn't differ. Different sequence of the same items is a difference.


add

public void add(java.lang.Object element)
Adds a single element to the model. From ChangeableListModel

Specified by:
add in interface ChangeableListModel

remove

public java.lang.Object remove(int index)
Removes a certain element from the model. From ChangeableListModel. THIS IS AN UGLY IMPLEMENTATION!!!

Specified by:
remove in interface ChangeableListModel

clear

public void clear()
Removes all elements.

Specified by:
clear in interface ChangeableListModel

getNSbyNSIdx

public NumberedString getNSbyNSIdx(int nsidx)
Returns one NumberedString by its own index field. Returns null if NumberedString is not available.


GUI2NSIdx

public int GUI2NSIdx(int guiidx)
Translates GUI index into index of NumberedString at that position. Returns -1 if no NumberedString is at that position.


GUI2NSAddNr

public int GUI2NSAddNr(int guiidx)
Translates GUI index into additional number of NumberedString at that position. Returns -1 if no additional number is at that position.


GUI2NSIdx

public int[] GUI2NSIdx(int[] guiidx)
Translates several GUI indices into their internal NumberedString counterparts. Indices with no NumberedString at them are set to -1 in the result array.


NS2GUIIdx

public int NS2GUIIdx(int nsidx)
Translates internal NumberedString index into the GUI index of the NumberedString. Returns -1 if no NumberedString has the given internal index.


Addnr2GUIIdx

public int Addnr2GUIIdx(int addnr)
Translates NumberedString's addnr into the GUI index of the NumberedString. Returns -1 if no NumberedString has the given addnr.


NS2GUIIdx

public int[] NS2GUIIdx(int[] guiidx)
Translates several internal NumberedString indices into their GUI counterparts. For not available NumberedString indices, the result field is -1.


containsNSIdx

public boolean containsNSIdx(int nsidx)
Checks if there is a NumberedString with the given internal index.


lazyNS2GUIIdx

public int[] lazyNS2GUIIdx(java.util.List nsidx)
Converts elements of given List to GUI index. The List may contain Integer objects, NumberedString objects of which the internal index is taken. Other objects are ignored. The method does only convert those internal indices which have a GUI counterpart. The result array may therefore have less entries than the original list.


lazyNS2GUIIdx

public int[] lazyNS2GUIIdx(int[] nsidx)
Converts elements of given int array to GUI index. Semantics are the same as with the list parameter method.


addFromChatSymbolHolder

public void addFromChatSymbolHolder(ChatSymbolHolder csh,
                                    int[] idxx)
Add content to the chat data model from a chat symbol holder. The added elements are NumberedStrings where the nr contains the symbol's numeric value and the name contains the symbolic value. If the ChatSymbolHolder is an IntChatSymbolHolder, name is set to the I18N'd representation instead of the symbolic value.

Parameters:
csh - ChatSymbolHolder to get the symbols from
idxx - Numeric constants to actually add to the list

addFromChatSymbolHolder

public void addFromChatSymbolHolder(ChatSymbolHolder csh)
Adds all symbols from the given ChatSymbolHolder to the model. The symbols are taken from the ChatSymbolHolder.getAllSymbols() method which must therefore be implemented.

Parameters:
csh - ChatSymbolHolder to get the symbols from

QJCC homepage