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.

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