[jsword-devel] Patch for sidebar delete problem
DM Smith
dmsmith555 at yahoo.com
Wed Aug 25 09:11:53 MST 2004
It is not a bug in JList, but perhaps in my explanation. Let me try to
be clearer. I will probably go overboard and state the obvious.
JList in and of itself is read-only. Using the MVC paradigm, the view
(JList) has a model (ListModel). The interface of a ListModel is also
read-only. However, the JList listens to the ListModel for changes and
responds to them appropriately. AbstractListModel is an implementation
of ListModel that provides this listening ability.
Java provides DefaultListModel for a dynamic list. This list model has
methods for adding to, removing from and updating elements in the list.
The typical pattern of these is:
public void removeElementAt(int index) {
delegate.removeElementAt(index);
fireIntervalRemoved(this, index, index);
}
In this implementation delegate is a Vector. So the element is removed
from the list and then the event is fired and the JList then responds
appropriately by asking the list model for fresh data as needed.
In the case of PassageListModel (PLM) there are some significant
differences from this pattern.
PLM does not provide an interface for modifying its data.
PLM has a model (a Passage) to which it listens for changes.
These are neither wrong or bad, just different.
However, the PLM does not maintain its notion of the change.
Specifically, (and I think by talking it through, I found the bug) it
does not track the change in the size of the Passage.
So while the hack works, it works because it causes size to be set
correctly. If in each of the PLM.verses[Added|Removed|Changed] were to
set the size to the current value, then the code will work.
I will send the patch in another e-mail. It fixes the real problem.
Joe Walker wrote:
>Sorry DM, I dont understand. Are you saying that JList makes untrue
>assumptions about how the model changes, so sometimes the model
>changes and JList gets confused? That sounds like quite a serious bug
>in JList.
>
>It looks to me as though BitwisePassage.remove(...) calls
>fireIntervalAdded(...) which calls PassageListModel.versesRemoved(...)
>which calls the JList model listener, so it doesn't seem to be our
>fault.
>Rather than clone the Passage, shouldn't we have a kickJList() method
>to do the work (and why can't we call that automatically??)
>
>Confused.
>
>
More information about the jsword-devel
mailing list