Bläddra i källkod

Sort aliases in Alias Dialog.

pull/530/head
Greg Holmes 7 år sedan
förälder
incheckning
8f6d81399d

+ 6
- 3
ui_swing/src/main/java/com/dmdirc/addons/ui_swing/components/GenericListModel.java Visa fil

17
 
17
 
18
 package com.dmdirc.addons.ui_swing.components;
18
 package com.dmdirc.addons.ui_swing.components;
19
 
19
 
20
+import com.google.common.collect.Ordering;
20
 import java.util.ArrayList;
21
 import java.util.ArrayList;
21
 import java.util.Collection;
22
 import java.util.Collection;
22
 import java.util.Collections;
23
 import java.util.Collections;
23
 import java.util.List;
24
 import java.util.List;
24
-
25
 import javax.swing.AbstractListModel;
25
 import javax.swing.AbstractListModel;
26
 
26
 
27
 /**
27
 /**
40
      * Instantiates an empty generic list model.
40
      * Instantiates an empty generic list model.
41
      */
41
      */
42
     public GenericListModel() {
42
     public GenericListModel() {
43
-
44
         this.list = Collections.synchronizedList(new ArrayList<>());
43
         this.list = Collections.synchronizedList(new ArrayList<>());
45
     }
44
     }
46
 
45
 
50
      * @param list Data to be included in the model
49
      * @param list Data to be included in the model
51
      */
50
      */
52
     public GenericListModel(final Collection<T> list) {
51
     public GenericListModel(final Collection<T> list) {
53
-
54
         this.list = Collections.synchronizedList(new ArrayList<>(list));
52
         this.list = Collections.synchronizedList(new ArrayList<>(list));
53
+        this.list.sort(Ordering.natural());
55
     }
54
     }
56
 
55
 
57
     @Override
56
     @Override
152
     public void add(final T object) {
151
     public void add(final T object) {
153
         final int index = list.size();
152
         final int index = list.size();
154
         list.add(object);
153
         list.add(object);
154
+        this.list.sort(Ordering.usingToString());
155
         fireIntervalAdded(this, index, index);
155
         fireIntervalAdded(this, index, index);
156
     }
156
     }
157
 
157
 
180
     public void replace(final T oldValue, final T newValue) {
180
     public void replace(final T oldValue, final T newValue) {
181
         final int index = list.indexOf(oldValue);
181
         final int index = list.indexOf(oldValue);
182
         list.set(index, newValue);
182
         list.set(index, newValue);
183
+        this.list.sort(Ordering.usingToString());
183
         fireContentsChanged(this, index, index);
184
         fireContentsChanged(this, index, index);
184
     }
185
     }
185
 
186
 
233
     public void addAll(final Collection<T> collection) {
234
     public void addAll(final Collection<T> collection) {
234
         final int lastIndex = list.size() - 1;
235
         final int lastIndex = list.size() - 1;
235
         list.addAll(collection);
236
         list.addAll(collection);
237
+        this.list.sort(Ordering.usingToString());
236
         fireIntervalAdded(this, lastIndex < 0 ? 0 : lastIndex, collection.size());
238
         fireIntervalAdded(this, lastIndex < 0 ? 0 : lastIndex, collection.size());
237
     }
239
     }
238
 
240
 
244
      */
246
      */
245
     public void addAll(final int index, final Collection<T> collection) {
247
     public void addAll(final int index, final Collection<T> collection) {
246
         list.addAll(index, collection);
248
         list.addAll(index, collection);
249
+        this.list.sort(Ordering.usingToString());
247
         fireIntervalAdded(this, index, collection.size());
250
         fireIntervalAdded(this, index, collection.size());
248
     }
251
     }
249
 
252
 

Laddar…
Avbryt
Spara