diff options
author | Andrew Su <[email protected]> | 2011-05-10 11:16:17 -0400 |
---|---|---|
committer | Andrew Su <[email protected]> | 2011-05-10 11:16:17 -0400 |
commit | a78e3962bcb462b2cdb4e0f9f36a00e513dc8a49 (patch) | |
tree | b49a6afadb8825e0edeef13612946bad15c54ad2 /netx/net/sourceforge | |
parent | 758132c5c84f359ddd824573ad2ec5944d51559e (diff) |
Fix sorting in itw-settings' cache viewer
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/controlpanel/CachePane.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java index e31b2bb..ef65a0b 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java +++ b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java @@ -30,8 +30,11 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.channels.FileLock; +import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Comparator; import java.util.Enumeration; import java.util.List; @@ -43,6 +46,7 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; import net.sourceforge.jnlp.cache.CacheDirectory; import net.sourceforge.jnlp.cache.DirectoryNode; @@ -96,7 +100,6 @@ public class CachePane extends JPanel { }; cacheTable = new JTable(model); - cacheTable.setAutoCreateRowSorter(true); cacheTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cacheTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); cacheTable.setPreferredScrollableViewportSize(new Dimension(600, 200)); @@ -105,6 +108,28 @@ public class CachePane extends JPanel { populateTable(); + TableRowSorter<DefaultTableModel> tableSorter = new TableRowSorter<DefaultTableModel>(model); + tableSorter.setComparator(4, new Comparator<Long>() { // Comparator for size column. + @Override + public int compare(Long o1, Long o2) { + return o1.compareTo(o2); + } + }); + tableSorter.setComparator(5, new Comparator<String>() { // Comparator for date column. + @Override + public int compare(String o1, String o2) { + DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); + try { + Long time1 = format.parse(o1).getTime(); + Long time2 = format.parse(o2).getTime(); + return time1.compareTo(time2); + } catch (ParseException e) { + return 0; + } + } + }); + cacheTable.setRowSorter(tableSorter); + c.weightx = 1; c.weighty = 1; c.gridx = 0; |