Better preserve column order between runs. It would do it before, but it wasn't consistent. Now it processes column ordering from first to last, so later column reorders don't affect earlier ones.
[#317 state:resolved]
There are a bunch of other tickets on this problem, all throughout the ticket system, which I'll link to this checkin later.
| 599 | 607 | |
|---|---|---|
| 13 | 13 | import java.awt.event.MouseListener; |
| 14 | 14 | import java.awt.Point; |
| 15 | 15 | import java.awt.Dimension; |
| 16 | import java.util.TreeMap; | |
| 16 | import java.util.*; | |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Created by IntelliJ IDEA. |
| --- | --- | |
| 152 | 152 | |
| 153 | 153 | private static int notify_delay = 0; |
| 154 | 154 | |
| 155 | private class Pair<K,V> { | |
| 156 | private K mFirst; | |
| 157 | private V mLast; | |
| 158 | ||
| 159 | public Pair(K k, V v) { | |
| 160 | mFirst = k; | |
| 161 | mLast = v; | |
| 162 | } | |
| 163 | ||
| 164 | public K getFirst() { | |
| 165 | return mFirst; | |
| 166 | } | |
| 167 | ||
| 168 | public V getLast() { | |
| 169 | return mLast; | |
| 170 | } | |
| 171 | } | |
| 172 | ||
| 173 | private class ColumnIndex extends Pair<String,Integer> { | |
| 174 | public ColumnIndex(String s, Integer i) { super(s, i); } | |
| 175 | } | |
| 176 | ||
| 155 | 177 | private void loadColumnSettings(String prefix, TableModel atm) { |
| 156 | 178 | String curColumnName = ""; |
| 157 | 179 | |
| 158 | TreeMap<String, Integer> initialToSaved = new TreeMap<String, Integer>(); | |
| 180 | List<ColumnIndex> initialToSaved = new LinkedList<ColumnIndex>(); | |
| 159 | 181 | // This code would need to be somewhat revamped if we allowed |
| 160 | 182 | // arbitrary, or user-selected column names. |
| 161 | 183 | try { |
| --- | --- | |
| 171 | 193 | if (dotIndex != -1) { |
| 172 | 194 | String colIndex = colWidth.substring(0, dotIndex); |
| 173 | 195 | colWidth = colWidth.substring(dotIndex + 1); |
| 174 | initialToSaved.put(curColumnName, Integer.parseInt(colIndex)); | |
| 196 | initialToSaved.add(new ColumnIndex(curColumnName, Integer.parseInt(colIndex))); | |
| 175 | 197 | } |
| 176 | 198 | makeNewColumn(curColumnName, colWidth); |
| 177 | 199 | } |
| --- | --- | |
| 198 | 220 | } |
| 199 | 221 | |
| 200 | 222 | if(!initialToSaved.isEmpty()) { |
| 201 | for (String colName : initialToSaved.keySet()) { | |
| 202 | int colFrom = getColumnModel().getColumnIndex(colName); | |
| 203 | int colTo = initialToSaved.get(colName); | |
| 223 | Collections.sort(initialToSaved, new Comparator<ColumnIndex>() { | |
| 224 | public int compare(ColumnIndex o1, ColumnIndex o2) { | |
| 225 | if(o1.getLast() < o2.getLast()) return -1; | |
| 226 | if(o1.getLast() > o2.getLast()) return 1; | |
| 227 | return 0; | |
| 228 | } | |
| 229 | }); | |
| 230 | for (ColumnIndex pair : initialToSaved) { | |
| 231 | int colFrom = getColumnModel().getColumnIndex(pair.getFirst()); | |
| 232 | int colTo = pair.getLast(); | |
| 233 | System.err.println("Moving column " + colFrom + " to " + colTo); | |
| 204 | 234 | try { |
| 205 | 235 | moveColumn(colFrom, colTo); |
| 206 | 236 | } catch (IllegalArgumentException iae) { |
