Skip to content

Commit c5cf252

Browse files
committed
fixes TableRowSorter
1 parent 56a602a commit c5cf252

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/table/TableRowSorter.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828
package javax.swing.table;
2929

30-
//import java.text.Collator;
3130
import java.util.Comparator;
3231

3332
import javax.swing.DefaultRowSorter;
@@ -131,11 +130,11 @@
131130
*/
132131
@SuppressWarnings({"rawtypes"})
133132
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;
139138

140139
/**
141140
* Underlying model.
@@ -222,16 +221,18 @@ public Comparator<?> getComparator(int column) {
222221
if (comparator != null) {
223222
return comparator;
224223
}
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();
235236
}
236237

237238
/**
@@ -311,10 +312,17 @@ public Integer getIdentifier(int index) {
311312
}
312313
}
313314

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+
}
320328
}

0 commit comments

Comments
 (0)