- Timestamp:
- 2014-04-05T17:37:26+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
r6717 r6958 14 14 import java.awt.event.MouseListener; 15 15 import java.util.Arrays; 16 import java.util.Comparator; 16 17 import java.util.Map; 17 18 … … 26 27 import javax.swing.event.ListSelectionEvent; 27 28 import javax.swing.event.ListSelectionListener; 29 import javax.swing.table.DefaultTableModel; 28 30 import javax.swing.table.TableCellRenderer; 31 import javax.swing.table.TableRowSorter; 29 32 30 33 import org.openstreetmap.josm.Main; … … 56 59 this.layer = layer; 57 60 putValue("help", ht("/Action/ChooseTrackVisibility")); 61 } 62 63 /** 64 * Class to format a length according to SystemOfMesurement. 65 */ 66 private final class TrackLength { 67 private double value; 68 69 /** 70 * Constructs a new {@code TrackLength} object with a given length. 71 * @param value length of the track 72 */ 73 TrackLength(double value) { 74 this.value = value; 75 } 76 77 /** 78 * Provides string representation. 79 * @return String representation depending of SystemOfMeasurement 80 */ 81 @Override 82 public String toString() { 83 return NavigatableComponent.getSystemOfMeasurement().getDistText(value); 84 } 85 } 86 87 /** 88 * Comparator for TrackLength objects 89 */ 90 private final class LengthContentComparator implements Comparator<TrackLength> { 91 92 /** 93 * Compare 2 TrackLength objects relative to the real length 94 */ 95 @Override 96 public int compare(TrackLength l0, TrackLength l1) { 97 if(l0.value < l1.value) 98 return -1; 99 else if(l0.value > l1.value) 100 return 1; 101 return 0; 102 } 58 103 } 59 104 … … 69 114 String desc = (String) (attr.containsKey("desc") ? attr.get("desc") : ""); 70 115 String time = GpxLayer.getTimespanForTrack(trk); 71 String length = NavigatableComponent.getSystemOfMeasurement().getDistText(trk.length());116 TrackLength length = new TrackLength(trk.length()); 72 117 String url = (String) (attr.containsKey("url") ? attr.get("url") : ""); 73 tracks[i] = new String[]{name, desc, time, length, url};118 tracks[i] = new Object[]{name, desc, time, length, url}; 74 119 i++; 75 120 } … … 82 127 private JTable buildTable(Object[][] content) { 83 128 final String[] headers = {tr("Name"), tr("Description"), tr("Timespan"), tr("Length"), tr("URL")}; 84 final JTable t = new JTable(content, headers) { 129 DefaultTableModel model = new DefaultTableModel(content, headers); 130 final JTable t = new JTable(model) { 85 131 @Override 86 132 public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { … … 88 134 if (c instanceof JComponent) { 89 135 JComponent jc = (JComponent) c; 90 jc.setToolTipText( (String) getValueAt(row, col));136 jc.setToolTipText(getValueAt(row, col).toString()); 91 137 } 92 138 return c; … … 98 144 } 99 145 }; 146 // define how to sort row 147 TableRowSorter<DefaultTableModel> rowSorter = new TableRowSorter<DefaultTableModel>(); 148 t.setRowSorter(rowSorter); 149 rowSorter.setModel(model); 150 rowSorter.setComparator(3, new LengthContentComparator()); 100 151 // default column widths 101 152 t.getColumnModel().getColumn(0).setPreferredWidth(220); … … 124 175 } 125 176 }; 126 t.setAutoCreateRowSorter(true);127 177 t.addMouseListener(urlOpener); 128 178 t.setFillsViewportHeight(true);
Note:
See TracChangeset
for help on using the changeset viewer.