PageRenderTime 69ms CodeModel.GetById 66ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/CommonControls/common/gui/util/SortedListModel.java

#
Java | 30 lines | 24 code | 6 blank | 0 comment | 3 complexity | b3685c7a076fa2ae7418e39d473d8332 MD5 | raw file
 1package common.gui.util;
 2
 3import javax.swing.*;
 4import java.util.*;
 5
 6public class SortedListModel extends AbstractListModel {
 7	private ArrayList _elements = new ArrayList();
 8	private Comparator comparator;
 9
10	public void addElement(Object element) {
11		_elements.add(element);
12		sort();
13	}
14
15	private void sort() {
16		if (comparator == null) {
17			Collections.sort(_elements);
18		} else {
19			Collections.sort(_elements,comparator);
20		}
21	}
22
23	public Object getElementAt(int i) {
24		return _elements.get(i);
25	}
26
27	public int getSize() {
28		return _elements.size();
29	}
30}