Ignore:
Timestamp:
2010-02-12T10:36:44+01:00 (14 years ago)
Author:
roland
Message:

Public Transport Plugin: now in the overview tab the entries are sorted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/public_transport/src/public_transport/RoutePatternAction.java

    r19976 r19977  
    7171  };
    7272 
     73  private class RouteReference implements Comparable< RouteReference > {
     74    Relation route;
     75   
     76    public RouteReference(Relation route) {
     77      this.route = route;
     78    }
     79   
     80    public int compareTo(RouteReference rr) {
     81      if (route.get("route") != null)
     82      {
     83        int result = route.get("route").compareTo(rr.route.get("route"));
     84        if (result != 0)
     85          return result;
     86      }
     87      else if (rr.route.get("route") != null)
     88        return 1;
     89      if (route.get("ref") != null)
     90      {
     91        int result = route.get("ref").compareTo(rr.route.get("ref"));
     92        if (result != 0)
     93          return result;
     94      }
     95      else if (rr.route.get("ref") != null)
     96        return 1;
     97      if (route.get("to") != null)
     98      {
     99        int result = route.get("to").compareTo(rr.route.get("to"));
     100        if (result != 0)
     101          return result;
     102      }
     103      else if (rr.route.get("to") != null)
     104        return 1;
     105      if (route.get("direction") != null)
     106      {
     107        int result = route.get("direction").compareTo(rr.route.get("direction"));
     108        if (result != 0)
     109          return result;
     110      }
     111      else if (rr.route.get("direction") != null)
     112        return 1;
     113      if (route.getId() < rr.route.getId())
     114        return -1;
     115      else if (route.getId() > rr.route.getId())
     116        return 1;
     117      return 0;
     118    }
     119   
     120    public String toString() {
     121      String buf = route.get("route");
     122      if ((route.get("ref") != null) && (route.get("ref") != ""))
     123      {
     124        if ((route.get("to") != null) && (route.get("to") != ""))
     125        {
     126          buf += " " + route.get("ref") + ": " + route.get("to");
     127        }
     128        else if ((route.get("direction") != null) && (route.get("direction") != ""))
     129        {
     130          buf += " " + route.get("ref") + ": " + route.get("direction");
     131        }
     132        else
     133        {
     134          buf += " " + route.get("ref");
     135        }
     136      }
     137      buf += " [ID " + Long.toString(route.getId()) + "]";
     138     
     139      return buf;
     140    }
     141  };
     142 
    73143  private class TagTableModel extends DefaultTableModel implements TableModelListener {
    74144    Relation relation = null;
     
    385455  private static JDialog jDialog = null;
    386456  private static JTabbedPane tabbedPane = null;
    387   private static DefaultListModel dlm = null;
     457  private static DefaultListModel relsListModel = null;
    388458  private static TagTableModel requiredTagsData = null;
    389459  private static CustomCellEditorTable requiredTagsTable = null;
     
    397467  private static StoplistTableModel stoplistData = null;
    398468  private static JTable stoplistTable = null;
    399   private static JList rpJList = null;
     469  private static JList relsList = null;
    400470  private static JCheckBox cbRight = null;
    401471  private static JCheckBox cbLeft = null;
    402472  private static JTextField tfSuggestStopsLimit = null;
    403   private static Vector< Relation > routes = new Vector< Relation >();
     473/*  private static Vector< Relation > routes = new Vector< Relation >();*/
    404474  private static Relation currentRoute = null;
    405475  private static Vector< RelationMember > markedWays = new Vector< RelationMember >();
     
    452522      contentPane.add(headline);
    453523       
    454       dlm = new DefaultListModel();
    455       rpJList = new JList(dlm);
    456       JScrollPane rpListSP = new JScrollPane(rpJList);
     524      relsListModel = new DefaultListModel();
     525      relsList = new JList(relsListModel);
     526      JScrollPane rpListSP = new JScrollPane(relsList);
    457527      String[] data = {"1", "2", "3", "4", "5", "6"};
    458       dlm.copyInto(data);
    459       rpJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    460       rpJList.addListSelectionListener(new RoutesLSL(this));
     528      relsListModel.copyInto(data);
     529      relsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     530      relsList.addListSelectionListener(new RoutesLSL(this));
    461531     
    462532      layoutCons.gridx = 0;
     
    566636      commonTagsData.addColumn("Value");
    567637      rowContent = new Vector< String >();
    568       rowContent.add(0, "description");
    569       tagBlacklist.add("description");
     638      rowContent.add(0, "direction");
     639      tagBlacklist.add("direction");
    570640      rowContent.add(1, "");
    571641      commonTagsData.addRow(rowContent);
     
    16141684 
    16151685  private void refreshData() {
    1616     dlm.clear();
     1686    relsListModel.clear();
    16171687       
    16181688    DataSet mainDataSet = Main.main.getCurrentDataSet();
    16191689    if (mainDataSet != null)
    16201690    {
    1621       routes.clear();
    1622       Vector<String> rpLines = new Vector<String>();
    1623       Collection<Relation> relCollection = mainDataSet.getRelations();
    1624       Iterator<Relation> relIter = relCollection.iterator();
     1691      Vector< RouteReference > relRefs = new Vector< RouteReference >();
     1692      Collection< Relation > relCollection = mainDataSet.getRelations();
     1693      Iterator< Relation > relIter = relCollection.iterator();
     1694     
    16251695      while (relIter.hasNext())
    16261696      {
     
    16281698        String routeVal = currentRel.get("route");
    16291699        if ("bus".equals(routeVal))
    1630         {
    1631           routes.addElement(currentRel);
    1632           String relDesc = currentRel.get("ref");
    1633           if (relDesc == null)
    1634             relDesc = "";
    1635           relDesc = "bus: " + relDesc + " ["+ currentRel.getId() + "]";
    1636           rpLines.addElement(relDesc);
    1637         }
    1638       }
    1639       Iterator<String> rplIter = rpLines.iterator();
    1640       while (rplIter.hasNext())
    1641       {
    1642         dlm.addElement(rplIter.next());
    1643       }
     1700          relRefs.add(new RouteReference(currentRel));
     1701        else if ("tram".equals(routeVal))
     1702          relRefs.add(new RouteReference(currentRel));
     1703        else if ("light_rail".equals(routeVal))
     1704          relRefs.add(new RouteReference(currentRel));
     1705        else if ("subway".equals(routeVal))
     1706          relRefs.add(new RouteReference(currentRel));
     1707        else if ("rail".equals(routeVal))
     1708          relRefs.add(new RouteReference(currentRel));
     1709      }
     1710     
     1711      Collections.sort(relRefs);
     1712     
     1713      Iterator< RouteReference > iter = relRefs.iterator();
     1714      while (iter.hasNext())
     1715        relsListModel.addElement(iter.next());
    16441716    }
    16451717    else
     
    18251897 
    18261898  private void routesSelectionChanged() {
    1827     int selectedPos = rpJList.getAnchorSelectionIndex();
    1828     if (rpJList.isSelectedIndex(selectedPos))
    1829     {
    1830       currentRoute = routes.elementAt(selectedPos);
     1899    int selectedPos = relsList.getAnchorSelectionIndex();
     1900    if (relsList.isSelectedIndex(selectedPos))
     1901    {
     1902      currentRoute = ((RouteReference)relsListModel.elementAt(selectedPos)).route;
    18311903      tabbedPane.setEnabledAt(1, true);
    18321904      tabbedPane.setEnabledAt(2, true);
Note: See TracChangeset for help on using the changeset viewer.