Features
API Compatibility with ArrayList
EventList implements the same List interface as ArrayList and Vector. There's less to learn and it will be easy for other programmers on your team to understand.
Simple usage of EventList
List myEventList = new BasicEventList();
myEventList.add("Mario");
myEventList.add("Donkey Kong");
myEventList.add(0, "Bowser");
myEventList.remove(0);
myEventList.remove("Donkey Kong");
if(myEventList.contains("Sonic")) {
myEventList.add("Tails");
}
for(Iterator i = myEventList.iterator(); i.hasNext(); ) {
System.out.println(i.next());
}
myEventList.clear();
Easy TableModels
EventTableModel allows you to use an EventList for the rows of your JTable, and leaves you responsible to define the columns.
EventList defines the rows
EventList rows = new BasicEventList();
rows.add(Color.green);
rows.add(Color.white);
rows.add(Color.darkGrey);
rows.add(Color.orange);
TableFormat defines the columns
public class ColorTableFormat implements TableFormat {
public int getColumnCount() {
return 3;
}
public String getColumnName(int column) {
if(column == 0) return "Red";
else if(column == 1) return "Green";
else return "Blue";
}
public Object getColumnValue(Object baseObject int column) {
Color color = (Color)baseObject;
if(column == 0) return color.getRed();
else if(column == 1) return color.getGreen();
else return color.getBlue();
}
}
...and build a table
ColorTableFormat columns = new ColorTableFormat();
EventTableModel tableModel = new EventTableModel(rows, columns);
JTable colorsTable = new JTable(tableModel);
Easy Dynamic Filtering
You can create a filtered copy of an EventList that responds to changes in the original. The filtered EventList listens for events from the original and updates itself as they happen.
Filter for "Found" and "New"
EventList everything = new BasicEventList();
TextFilterList filtered = new TextFilterList(everything);
filtered.getFilterEdit().setText("Found New");
everything.add("Newfoundland");
everything.add("Labrador");
everything.add("New Found Glory");
everything.add("A Simple Plan");
// should print "[NewfoundLand, New Found Glory]"
System.out.println(filtered);
Easy Dynamic Sorting
You can create a sorted copy of an EventList that responds to changes in the original. The sorted EventList listens for events from the original and updates itself as they happen.
Sort some Flintstones
EventList flintstones = new BasicEventList();
EventList sorted = new SortedList(flintstones);
flintstones.add("Fred");
flintstones.add("Barney");
flintstones.add("Wilma");
flintstones.add("Pebbles");
flintstones.add("Bam-Bam");
// should print "[Bam-Bam, Barney, Fred, Pebbles, Wilma]"
System.out.println(sorted);
Layer Multiple Transformations
Layering transformations like sorting and filtering makes it easy to implement powerful manipulations of your data.
Sort and filter some cars
EventList cars = new BasicEventList();
EventList sorted = new SortedList(cars);
TextFilterList filtered = new TextFilterList(sorted);
filtered.getFilterEdit().setText("Hybrid");
cars.add("Insight");
cars.add("EV1");
cars.add("Prius Hybrid");
cars.add("Jetta TDI");
cars.add("Escape Hybrid");
cars.add("Escalade");
// should print "[Escape Hybrid, Prius Hybrid]"
System.out.println(filtered);
High Performance
The EventList fires events that provide fine-grained detail describing the change. This is the secret to making Glazed Lists high performace. When you insert 5 elements into a SortedList containing 10,000 elements, only the new elements get sorted! Competing toolkits sort the entire list on every change.
Designed for concurrency
You can populate your EventList from one thread and read it from another. For GUI applications, you can populate your EventList on a background thread while safely browsing it using the user-interface thread.
Populate on a background thread
public class UpdateListTask extends TimerTask {
private EventList target;
public UpdateListTask(EventList target) {
this.target = target;
}
public void run() {
Collection results = doSomeReallySlowOperation();
target.getReadWriteLock().writeLock().lock();
target.clear();
target.addAll(results);
target.getReadWriteLock().writeLock().unlock();
}
}
Swing or SWT
You can use either Swing or SWT out of the box.
Includes useful transformations
You can take advantage of some built-in transformations that are more fun than sort & filter.
UniqueList removes duplicates. So [A, B, B, B, C, A, B] becomes [A, B, C].
PopularityList ranks elements by frequency. So [A, B, B, B, C, A, B] becomes [B, A, C].
CollectionList combines multiple lists. So [ABBB, CAB] becomes [A, B, B, B, C, A, B].
Easy custom filters wih FilterList and Matchers
You can create filters that are appropriate for your data.
Filter everything but four-letter words
public class FourLetterMatcher implements Matcher {
public boolean matches(Object element) {
String word = (String)element;
return (word.length() == 4);
}
}
Demonstrate FourLetterMatcher
EventList normalList = new BasicEventList();
Matcher fourLetterMatcher = new FourLetterMatcher();
FilterList fourLetterWords = new FilterList(normalList, fourLetterMatcher);
normalList.add("Nice");
normalList.add("Horrible");
normalList.add("Good");
normalList.add("Awful");
// should print "[Nice, Good]"
System.out.println(fourLetterWords);
Easy custom transformations
You can create transformations that are appropriate for your data.
Add "Eh" to all elements, Eh?
public class CanadianList extends TransformedList {
public TransformedList(EventList source) {
super(source);
source.addListEventListener(this);
}
public void listChanged(ListEvent e) {
updates.forwardEvent(e);
}
public Object get(int index) {
return source.get(index) + " Eh?";
}
}
Demonstrate CanadianList
EventList normalList = new BasicEventList();
EventList canadian = new CanadianList(normalList);
normalList.add("Moose");
normalList.add("Beaver");
normalList.add("Beer");
// should print "[Moose Eh?, Beaver Eh?, Beer Eh?]"
System.out.println(canadian);
Free and open
Free as in beer: You can use Glazed Lists for any purpose without paying anything!
Free as in speech: Glazed Lists includes full source code and is licensed under the business-friendly LGPL license. If you would like to distribute a modified version of Glazed Lists, you must share the your changes with the project.
Friendly developers In the unlikely event that you find a problem with Glazed Lists, send a message to the project developers via the mailing lists. You can expect a response within 24 hours.