Changeset 20895 in osm for applications
- Timestamp:
- 2010-04-13T03:54:52+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/public_transport/src/public_transport
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/RoutePatternAction.java
r20729 r20895 260 260 }; 261 261 262 private class ItineraryTableModel extends DefaultTableModel {263 public Vector<Way> ways = new Vector<Way>();264 265 public boolean isCellEditable(int row, int column) {266 if (column != 1)267 return false;268 if (ways.elementAt(row) == null)269 return false;270 return true;271 }272 273 public void addRow(Object[] obj) {274 ways.addElement(null);275 super.addRow(obj);276 }277 278 public void insertRow(int insPos, Object[] obj) {279 if (insPos == -1)280 {281 ways.addElement(null);282 super.addRow(obj);283 }284 else285 {286 ways.insertElementAt(null, insPos);287 super.insertRow(insPos, obj);288 }289 }290 291 public void addRow(Way way, String role) {292 insertRow(-1, way, role);293 }294 295 public void insertRow(int insPos, Way way, String role) {296 String[] buf = { "", "" };297 String curName = way.get("name");298 if (way.isIncomplete())299 {300 buf[0] = "[incomplete]";301 }302 else if (way.getNodesCount() < 1)303 {304 buf[0] = "[empty way]";305 }306 else if (curName != null)307 {308 buf[0] = curName;309 }310 else311 {312 buf[0] = "[ID] " + (new Long(way.getId())).toString();313 }314 buf[1] = role;315 if (insPos == -1)316 {317 ways.addElement(way);318 super.addRow(buf);319 }320 else321 {322 ways.insertElementAt(way, insPos);323 super.insertRow(insPos, buf);324 }325 }326 327 public void clear()328 {329 ways.clear();330 super.setRowCount(0);331 }332 };333 334 private class ItineraryTableModelListener implements TableModelListener {335 public void tableChanged(TableModelEvent e)336 {337 if (e.getType() == TableModelEvent.UPDATE)338 {339 cleanupGaps();340 rebuildWays();341 }342 }343 };344 345 262 private class StoplistTableModel extends DefaultTableModel { 346 263 public Vector<Node> nodes = new Vector<Node>(); … … 808 725 itineraryTable.getColumnModel().getColumn(1) 809 726 .setCellEditor(new DefaultCellEditor(comboBox)); 810 itineraryData.addTableModelListener( new ItineraryTableModelListener());727 itineraryData.addTableModelListener(itineraryData); 811 728 812 729 layoutCons.gridx = 0; … … 1344 1261 } 1345 1262 1346 cleanupGaps();1263 itineraryData.cleanupGaps(); 1347 1264 rebuildWays(); 1348 1265 } … … 1358 1275 } 1359 1276 1360 cleanupGaps();1277 itineraryData.cleanupGaps(); 1361 1278 rebuildWays(); 1362 1279 } … … 1435 1352 } 1436 1353 1437 cleanupGaps();1354 itineraryData.cleanupGaps(); 1438 1355 rebuildWays(); 1439 1356 } … … 1502 1419 itineraryTable.addRowSelectionInterval(startPos, insPos-1); 1503 1420 1504 cleanupGaps();1421 itineraryData.cleanupGaps(); 1505 1422 rebuildWays(); 1506 1423 } … … 1975 1892 1976 1893 //Rebuild ways in the relation currentRoute 1977 p rivatevoid rebuildWays() {1894 public static void rebuildWays() { 1978 1895 currentRoute.setModified(true); 1979 for (int i = currentRoute.getMembersCount()-1; i >=0; --i)1980 {1981 if (currentRoute.getMember(i).isWay())1982 1983 currentRoute.removeMember(i); 1984 } 1896 List< RelationMember > members = currentRoute.getMembers(); 1897 ListIterator< RelationMember > iter = members.listIterator(); 1898 while (iter.hasNext()) 1899 { 1900 if (iter.next().isWay()) 1901 iter.remove(); 1985 1902 } 1986 1903 for (int i = 0; i < itineraryData.getRowCount(); ++i) … … 1989 1906 { 1990 1907 RelationMember member = new RelationMember 1991 ((String)(itineraryData.getValueAt(i, 1)), itineraryData.ways.elementAt(i)); 1992 currentRoute.addMember(member); 1993 } 1994 } 1908 ((String)(itineraryData.getValueAt(i, 1)), 1909 itineraryData.ways.elementAt(i)); 1910 members.add(member); 1911 } 1912 } 1913 currentRoute.setMembers(members); 1995 1914 } 1996 1915 … … 2214 2133 } 2215 2134 2216 private void cleanupGaps()2217 {2218 long lastNodeId = 0;2219 2220 for (int i = 0; i < itineraryData.getRowCount(); ++i)2221 {2222 if (itineraryData.ways.elementAt(i) == null)2223 {2224 ++i;2225 if (i >= itineraryData.getRowCount())2226 break;2227 }2228 while ((itineraryData.ways.elementAt(i) == null) &&2229 ((i == 0) || (itineraryData.ways.elementAt(i-1) == null)))2230 {2231 itineraryData.ways.removeElementAt(i);2232 itineraryData.removeRow(i);2233 if (i >= itineraryData.getRowCount())2234 break;2235 }2236 if (i >= itineraryData.getRowCount())2237 break;2238 2239 boolean gapRequired = gapNecessary2240 (itineraryData.ways.elementAt(i), (String)(itineraryData.getValueAt(i, 1)),2241 lastNodeId);2242 if ((i > 0) && (!gapRequired) && (itineraryData.ways.elementAt(i-1) == null))2243 {2244 itineraryData.ways.removeElementAt(i-1);2245 itineraryData.removeRow(i-1);2246 --i;2247 }2248 else if ((i > 0) && gapRequired && (itineraryData.ways.elementAt(i-1) != null))2249 {2250 String[] buf = { "", "" };2251 buf[0] = "[gap]";2252 itineraryData.insertRow(i, buf);2253 ++i;2254 }2255 lastNodeId = getLastNodeId2256 (itineraryData.ways.elementAt(i), (String)(itineraryData.getValueAt(i, 1)));2257 }2258 while ((itineraryData.getRowCount() > 0) &&2259 (itineraryData.ways.elementAt(itineraryData.getRowCount()-1) == null))2260 {2261 itineraryData.ways.removeElementAt(itineraryData.getRowCount()-1);2262 itineraryData.removeRow(itineraryData.getRowCount()-1);2263 }2264 }2265 2266 2135 private int insertGapIfNecessary(Way way, String role, long lastNodeId, int insPos) 2267 2136 { … … 2306 2175 { 2307 2176 if ("backward".equals(role)) 2308 {2309 2177 return way.getNode(0).getId(); 2310 }2311 2178 else 2312 {2313 2179 return way.getNode(way.getNodesCount() - 1).getId(); 2314 }2315 2180 } 2316 2181 }
Note:
See TracChangeset
for help on using the changeset viewer.