|
27 | 27 | */ |
28 | 28 | package javax.swing.table; |
29 | 29 |
|
30 | | -//import java.text.Collator; |
31 | 30 | import java.util.Comparator; |
32 | 31 |
|
33 | 32 | import javax.swing.DefaultRowSorter; |
|
131 | 130 | */ |
132 | 131 | @SuppressWarnings({"rawtypes"}) |
133 | 132 | public class TableRowSorter<M extends TableModel> extends DefaultRowSorter<M, Integer> { |
134 | | -// /** |
135 | | -// * Comparator that uses compareTo on the contents. |
136 | | -// */ |
137 | | -// private static final Comparator COMPARABLE_COMPARATOR = |
138 | | -// new ComparableComparator(); |
| 133 | + /** |
| 134 | + * Comparator that uses compareTo on the contents. |
| 135 | + */ |
| 136 | + private static Comparator COMPARABLE_COMPARATOR; |
| 137 | + private static Comparator STRING_COMPARATOR; |
139 | 138 |
|
140 | 139 | /** |
141 | 140 | * Underlying model. |
@@ -222,16 +221,18 @@ public Comparator<?> getComparator(int column) { |
222 | 221 | if (comparator != null) { |
223 | 222 | return comparator; |
224 | 223 | } |
225 | | - return null; |
226 | | -// SwingJS ignore |
227 | | -// Class columnClass = getModel().getColumnClass(column); |
228 | | -// if (columnClass == String.class) { |
229 | | -// return Collator.getInstance(); |
230 | | -// } |
231 | | -// if (Comparable.class.isAssignableFrom(columnClass)) { |
232 | | -// return COMPARABLE_COMPARATOR; |
233 | | -// } |
234 | | -// return Collator.getInstance(); |
| 224 | + Class columnClass = getModel().getColumnClass(column); |
| 225 | + if (columnClass == String.class) { |
| 226 | + if (STRING_COMPARATOR == null) |
| 227 | + STRING_COMPARATOR = new StringComparator(); |
| 228 | + return STRING_COMPARATOR;//Collator.getInstance(); |
| 229 | + } |
| 230 | + if (Comparable.class.isAssignableFrom(columnClass)) { |
| 231 | + if (COMPARABLE_COMPARATOR == null) |
| 232 | + COMPARABLE_COMPARATOR = new ComparableComparator(); |
| 233 | + return COMPARABLE_COMPARATOR; |
| 234 | + } |
| 235 | + return null;//Collator.getInstance(); |
235 | 236 | } |
236 | 237 |
|
237 | 238 | /** |
@@ -311,10 +312,17 @@ public Integer getIdentifier(int index) { |
311 | 312 | } |
312 | 313 | } |
313 | 314 |
|
314 | | -// private static class ComparableComparator implements Comparator { |
315 | | -// @Override |
316 | | -// public int compare(Object o1, Object o2) { |
317 | | -// return ((Comparable)o1).compareTo(o2); |
318 | | -// } |
319 | | -// } |
| 315 | + private static class StringComparator implements Comparator { |
| 316 | + @Override |
| 317 | + public int compare(Object o1, Object o2) { |
| 318 | + return ((String)o1).compareTo((String)o2); |
| 319 | + } |
| 320 | + } |
| 321 | + |
| 322 | + private static class ComparableComparator implements Comparator { |
| 323 | + @Override |
| 324 | + public int compare(Object o1, Object o2) { |
| 325 | + return ((Comparable)o1).compareTo(o2); |
| 326 | + } |
| 327 | + } |
320 | 328 | } |
0 commit comments