V
VisionSet
I've just been looking over the newish (Feb '04) TableModel implementation
that Sun have in their swing tutorial.
<http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>
<http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/Ta
bleSorter.java>
It is superb. It Decorates any existing TableModel with very flexible
sorting abilities.
It extracts any Comparators that exist for the given column class types
If that fails it creates its own from your classes comparable
If that fails it uses a default lexical comparator.
You can also add new Comparators to the model for any particular class at
any time.
The only slight niggle I could see, is that the Comparators are stored keyed
by class type, so you can only have one Comparator at a time for each class
type.
You could fit an interface to column classes that need this functionality
and watch for this in the TableSorter, then ask the column class object for
its preferred comparator.
It sorts in both directions and returns the list to the original unsorted
state, by cycling through mouse clicks on the header. It also does compound
sorts if you hold down <ctrl> And you get pretty icons to show column/sorted
state.
And all in 250 lines of code!
that Sun have in their swing tutorial.
<http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>
<http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/Ta
bleSorter.java>
It is superb. It Decorates any existing TableModel with very flexible
sorting abilities.
It extracts any Comparators that exist for the given column class types
If that fails it creates its own from your classes comparable
If that fails it uses a default lexical comparator.
You can also add new Comparators to the model for any particular class at
any time.
The only slight niggle I could see, is that the Comparators are stored keyed
by class type, so you can only have one Comparator at a time for each class
type.
You could fit an interface to column classes that need this functionality
and watch for this in the TableSorter, then ask the column class object for
its preferred comparator.
It sorts in both directions and returns the list to the original unsorted
state, by cycling through mouse clicks on the header. It also does compound
sorts if you hold down <ctrl> And you get pretty icons to show column/sorted
state.
And all in 250 lines of code!