Changeset 20815 in osm for applications/editors


Ignore:
Timestamp:
2010-04-07T14:38:36+02:00 (14 years ago)
Author:
roland
Message:

Public TRansport Plugin: Making UndoRedo possible

Location:
applications/editors/josm/plugins/public_transport/src/public_transport
Files:
1 added
9 edited

Legend:

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

    r20772 r20815  
    5858      for (int i = 0; i < track.stoplistTM.getRowCount(); ++i)
    5959      {
    60         if ((Node)track.stoplistTM.nodes.elementAt(i) != null)
     60        if (track.stoplistTM.nodeAt(i) != null)
    6161        {
    62           Node node = (Node)track.stoplistTM.nodes.elementAt(i);
     62          Node node = track.stoplistTM.nodeAt(i);
    6363          oldStrings.add(new HighwayRailway(node));
    6464          StopImporterAction.setTagsWrtType(node, type);
  • applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterAction.java

    r20791 r20815  
    155155      Main.main.undoRedo.add(new TrackSuggestStopsCommand(this));
    156156    else if ("stopImporter.stoplistFind".equals(event.getActionCommand()))
    157       findNodesInTable(dialog.getStoplistTable(), currentTrack.stoplistTM.nodes);
     157      findNodesInTable(dialog.getStoplistTable(), currentTrack.stoplistTM.getNodes());
    158158    else if ("stopImporter.stoplistShow".equals(event.getActionCommand()))
    159       showNodesFromTable(dialog.getStoplistTable(), currentTrack.stoplistTM.nodes);
     159      showNodesFromTable(dialog.getStoplistTable(), currentTrack.stoplistTM.getNodes());
    160160    else if ("stopImporter.stoplistMark".equals(event.getActionCommand()))
    161       markNodesFromTable(dialog.getStoplistTable(), currentTrack.stoplistTM.nodes);
     161      markNodesFromTable(dialog.getStoplistTable(), currentTrack.stoplistTM.getNodes());
    162162    else if ("stopImporter.stoplistDetach".equals(event.getActionCommand()))
    163163    {
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackReference.java

    r20773 r20815  
    3131  public double threshold;
    3232  private StopImporterAction controller = null;
     33  public boolean inEvent = false;
    3334   
    3435  public TrackReference(GpxTrack track, StopImporterAction controller)
     
    100101    if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() >= 0))
    101102    {
     103      if (inEvent)
     104        return;
     105     
    102106      double time = StopImporterDialog.parseTime
    103107            ((String)stoplistTM.getValueAt(e.getFirstRow(), 0));
    104108      if (time < 0)
    105109      {
     110        stoplistTM.setValueAt
     111            (stoplistTM.timeAt(e.getFirstRow()), e.getFirstRow(), 0);
    106112        JOptionPane.showMessageDialog
    107113            (null, "Can't parse a time from this string.", "Invalid value",
     
    110116      }
    111117
    112       LatLon latLon = computeCoor(time);
    113        
    114       if (stoplistTM.nodes.elementAt(e.getFirstRow()) == null)
    115       {
    116         Node node = controller.createNode
    117             (latLon, (String)stoplistTM.getValueAt(e.getFirstRow(), 1));
    118         stoplistTM.nodes.set(e.getFirstRow(), node);
    119       }
    120       else
    121       {
    122         Node node = new Node(stoplistTM.nodes.elementAt(e.getFirstRow()));
    123         node.setCoor(latLon);
    124         node.put("name", (String)stoplistTM.getValueAt(e.getFirstRow(), 1));
    125         Command cmd = new ChangeCommand(stoplistTM.nodes.elementAt(e.getFirstRow()), node);
    126         if (cmd != null) {
    127           Main.main.undoRedo.add(cmd);
    128         }
    129       }
     118      Main.main.undoRedo.add(new TrackStoplistNameCommand
     119              (this, e.getFirstRow(),
     120               (String)stoplistTM.getValueAt(e.getFirstRow(), 0),
     121               (String)stoplistTM.getValueAt(e.getFirstRow(), 1)));
     122      stoplistTM.setTimeAt
     123          (e.getFirstRow(), (String)stoplistTM.getValueAt(e.getFirstRow(), 0));
    130124    }
    131125  }
     
    186180  public void relocateNodes()
    187181  {
    188     for (int i = 0; i < stoplistTM.nodes.size(); ++i)
    189     {
    190       Node node = stoplistTM.nodes.elementAt(i);
     182    for (int i = 0; i < stoplistTM.getNodes().size(); ++i)
     183    {
     184      Node node = stoplistTM.nodeAt(i);
    191185      if (node == null)
    192186        continue;
     
    195189            ((String)stoplistTM.getValueAt(i, 0));
    196190      LatLon latLon = computeCoor(time);
    197        
     191
    198192      Node newNode = new Node(node);
    199193      newNode.setCoor(latLon);
     
    205199    }
    206200  }
    207    
    208   public void suggestStops()
    209   {
    210     Vector< WayPoint > wayPoints = new Vector< WayPoint >();
    211     Iterator< GpxTrackSegment > siter = track.getSegments().iterator();
    212     while (siter.hasNext())
    213     {
    214       Iterator< WayPoint > witer = siter.next().getWayPoints().iterator();
    215       while (witer.hasNext())
    216         wayPoints.add(witer.next());
    217     }
    218     Vector< Double > wayPointsDist = new Vector< Double >(wayPoints.size());
    219      
    220     int i = 0;
    221     double time = -48*60*60;
    222     double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime);
    223     while ((i < wayPoints.size()) && (time < dGpsStartTime + timeWindow/2))
    224     {
    225       if (wayPoints.elementAt(i).getString("time") != null)
    226         time = StopImporterDialog.parseTime(wayPoints.elementAt(i)
    227             .getString("time").substring(11,19));
    228       if (time < dGpsStartTime)
    229         time += 24*60*60;
    230       wayPointsDist.add(Double.valueOf(Double.POSITIVE_INFINITY));
    231       ++i;
    232     }
    233     while (i < wayPoints.size())
    234     {
    235       int j = i;
    236       double time2 = time;
    237       while ((j > 0) && (time - timeWindow/2 < time2))
    238       {
    239         --j;
    240         if (wayPoints.elementAt(j).getString("time") != null)
    241           time2 = StopImporterDialog.parseTime(wayPoints.elementAt(j)
    242               .getString("time").substring(11,19));
    243         if (time2 < dGpsStartTime)
    244           time2 += 24*60*60;
    245       }
    246       int k = i + 1;
    247       time2 = time;
    248       while ((k < wayPoints.size()) && (time + timeWindow/2 > time2))
    249       {
    250         if (wayPoints.elementAt(k).getString("time") != null)
    251           time2 = StopImporterDialog.parseTime(wayPoints.elementAt(k)
    252               .getString("time").substring(11,19));
    253         if (time2 < dGpsStartTime)
    254           time2 += 24*60*60;
    255         ++k;
    256       }
    257        
    258       if (j < k)
    259       {
    260         double dist = 0;
    261         LatLon latLonI = wayPoints.elementAt(i).getCoor();
    262         for (int l = j; l < k; ++l)
    263         {
    264           double distL = latLonI.greatCircleDistance(wayPoints.elementAt(l).getCoor());
    265           if (distL > dist)
    266             dist = distL;
    267         }
    268         wayPointsDist.add(Double.valueOf(dist));
    269       }
    270       else
    271         wayPointsDist.add(Double.valueOf(Double.POSITIVE_INFINITY));
    272        
    273       if (wayPoints.elementAt(i).getString("time") != null)
    274         time = StopImporterDialog.parseTime(wayPoints.elementAt(i)
    275             .getString("time").substring(11,19));
    276       if (time < dGpsStartTime)
    277         time += 24*60*60;
    278       ++i;
    279     }
    280      
    281     Vector< Node > toDelete = new Vector< Node >();
    282     for (i = 0; i < stoplistTM.getRowCount(); ++i)
    283     {
    284       if ((Node)stoplistTM.nodes.elementAt(i) != null)
    285         toDelete.add((Node)stoplistTM.nodes.elementAt(i));
    286     }
    287     if (!toDelete.isEmpty())
    288     {
    289       Command cmd = DeleteCommand.delete
    290           (Main.main.getEditLayer(), toDelete);
    291       if (cmd == null)
    292         return;
    293       Main.main.undoRedo.add(cmd);
    294     }
    295     stoplistTM.clear();
    296      
    297     LatLon lastStopCoor = null;
    298     for (i = 1; i < wayPoints.size()-1; ++i)
    299     {
    300       if (wayPointsDist.elementAt(i).doubleValue() >= threshold)
    301         continue;
    302       if ((wayPointsDist.elementAt(i).compareTo(wayPointsDist.elementAt(i-1)) != -1)
    303            || (wayPointsDist.elementAt(i).compareTo(wayPointsDist.elementAt(i+1)) != -1))
    304         continue;
    305        
    306       LatLon latLon = wayPoints.elementAt(i).getCoor();
    307       if ((lastStopCoor != null) &&  (lastStopCoor.greatCircleDistance(latLon) < threshold))
    308         continue;
    309        
    310       if (wayPoints.elementAt(i).getString("time") != null)
    311       {
    312         time = StopImporterDialog.parseTime(wayPoints.elementAt(i)
    313             .getString("time").substring(11,19));
    314         double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime);
    315         if (gpsSyncTime < dGpsStartTime - 12*60*60)
    316           gpsSyncTime += 24*60*60;
    317         double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart);
    318         time -= timeDelta;
    319         stoplistTM.insertRow(-1, StopImporterAction.timeOf(time));
    320         Node node = controller.createNode(latLon, "");
    321         stoplistTM.nodes.set(stoplistTM.getRowCount()-1, node);
    322       }
    323        
    324       lastStopCoor = latLon;
    325     }
    326   }
    327201};
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistAddCommand.java

    r20772 r20815  
    3333    if (workingLine < 0)
    3434      workingLine = stoplistTM.getRowCount()-1;
    35     stoplistTM.nodes.removeElementAt(workingLine);
    3635    stoplistTM.removeRow(workingLine);
    3736  }
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistDeleteCommand.java

    r20772 r20815  
    5959    {
    6060      int j = workingLines.elementAt(i).intValue();
    61       Node node = stoplistTM.nodes.elementAt(j);
     61      Node node = stoplistTM.nodeAt(j);
    6262      nodesForUndo.add(new NodeTimeName
    6363          (node, (String)stoplistTM.getValueAt(j, 0),
    6464           (String)stoplistTM.getValueAt(j, 1)));
    65       stoplistTM.nodes.removeElementAt(j);
    6665      stoplistTM.removeRow(j);
    6766      if (node == null)
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistDetachCommand.java

    r20772 r20815  
    4040    for (int i = 0; i < consideredLines.size(); ++i)
    4141    {
    42       if (stoplistTM.nodes.elementAt(consideredLines.elementAt(i)) != null)
     42      if (stoplistTM.nodeAt(consideredLines.elementAt(i)) != null)
    4343        workingLines.add(consideredLines.elementAt(i));
    4444    }
     
    5151    {
    5252      int j = workingLines.elementAt(i).intValue();
    53       Node node = stoplistTM.nodes.elementAt(j);
     53      Node node = stoplistTM.nodeAt(j);
    5454      nodesForUndo.add(node);
    55       stoplistTM.nodes.set(j, null);
     55      stoplistTM.setNodeAt(j, null);
    5656    }
    5757    return true;
     
    6464      int j = workingLines.elementAt(i).intValue();
    6565      Node node = nodesForUndo.elementAt(i);
    66       stoplistTM.nodes.set(j, node);
     66      stoplistTM.setNodeAt(j, node);
    6767    }
    6868  }
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistSortCommand.java

    r20772 r20815  
    1919  private Vector< Vector< Object > > tableDataModel = null;
    2020  private Vector< Node > nodes = null;
     21  private Vector< String > times = null;
    2122  private Vector< Integer > workingLines = null;
    2223  private int insPos;
     
    4950    tableDataModel = (Vector< Vector< Object > >)stoplistTM.getDataVector()
    5051        .clone();
    51     nodes = (Vector< Node >)stoplistTM.nodes.clone();
     52    nodes = (Vector< Node >)stoplistTM.getNodes().clone();
     53    times = (Vector< String >)stoplistTM.getTimes().clone();
    5254   
    5355    Vector< NodeSortEntry > nodesToSort = new Vector< NodeSortEntry >();
     
    5658      int j = workingLines.elementAt(i).intValue();
    5759      nodesToSort.add(new NodeSortEntry
    58           (stoplistTM.nodes.elementAt(j), (String)stoplistTM.getValueAt(j, 0),
     60          (stoplistTM.nodeAt(j), (String)stoplistTM.getValueAt(j, 0),
    5961            (String)stoplistTM.getValueAt(j, 1),
    6062             StopImporterDialog.parseTime(stopwatchStart)));
    61       stoplistTM.nodes.removeElementAt(j);
    6263      stoplistTM.removeRow(j);
    6364    }
     
    8081  {
    8182    stoplistTM.setDataVector(tableDataModel);
    82     stoplistTM.nodes = nodes;
     83    stoplistTM.setNodes(nodes);
     84    stoplistTM.setTimes(times);
    8385  }
    8486 
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistTableModel.java

    r20772 r20815  
    1111public class TrackStoplistTableModel extends DefaultTableModel
    1212{
    13   public Vector< Node > nodes = new Vector< Node >();
    14   public Vector< String > columns = null;
     13  private Vector< Node > nodes = null;
     14  private Vector< String > times = null;
     15  private Vector< String > columns = null;
    1516   
    1617  public TrackStoplistTableModel(TrackReference tr)
     
    2223      columns.add("Name");
    2324    }
     25    nodes = new Vector< Node >();
     26    times = new Vector< String >();
    2427     
    2528    setColumnIdentifiers(columns);
     
    4750    insertRow(insPos, null, time, "");
    4851  }
    49    
     52
     53  public void removeRow(int pos)
     54  {
     55    super.removeRow(pos);
     56    nodes.removeElementAt(pos);
     57    times.removeElementAt(pos);
     58  }
     59
     60  public Node nodeAt(int i)
     61  {
     62    return nodes.elementAt(i);
     63  }
     64
     65  public void setNodeAt(int i, Node node)
     66  {
     67    nodes.set(i, node);
     68  }
     69
     70  public final Vector< Node > getNodes()
     71  {
     72    return nodes;
     73  }
     74
     75  public void setNodes(Vector< Node > nodes)
     76  {
     77    this.nodes = nodes;
     78  }
     79
     80  public String timeAt(int i)
     81  {
     82    return times.elementAt(i);
     83  }
     84
     85  public void setTimeAt(int i, String time)
     86  {
     87    times.set(i, time);
     88  }
     89
     90  public final Vector< String > getTimes()
     91  {
     92    return times;
     93  }
     94
     95  public void setTimes(Vector< String > times)
     96  {
     97    this.times = times;
     98  }
     99
    50100  public void insertRow(int insPos, Node node, String time, String name)
    51101  {
     
    56106    {
    57107      nodes.addElement(node);
     108      times.addElement(time);
    58109      super.addRow(buf);
    59110    }
     
    61112    {
    62113      nodes.insertElementAt(node, insPos);
     114      times.insertElementAt(time, insPos);
    63115      super.insertRow(insPos, buf);
    64116    }
     
    68120  {
    69121    nodes.clear();
     122    times.clear();
    70123    super.setRowCount(0);
    71124  }
  • applications/editors/josm/plugins/public_transport/src/public_transport/TrackSuggestStopsCommand.java

    r20773 r20815  
    2929  private Vector< Vector< Object > > tableDataModel = null;
    3030  private Vector< Node > nodes = null;
     31  private Vector< String > times = null;
    3132 
    3233  public TrackSuggestStopsCommand(StopImporterAction controller)
     
    4950    tableDataModel = (Vector< Vector< Object > >)stoplistTM.getDataVector()
    5051        .clone();
    51     nodes = (Vector< Node >)stoplistTM.nodes.clone();
    52    
    53     for (int i = 0; i < stoplistTM.nodes.size(); ++i)
    54     {
    55       Node node = stoplistTM.nodes.elementAt(i);
    56       stoplistTM.nodes.set(i, null);
     52    nodes = (Vector< Node >)stoplistTM.getNodes().clone();
     53    times = (Vector< String >)stoplistTM.getTimes().clone();
     54   
     55    for (int i = 0; i < stoplistTM.getNodes().size(); ++i)
     56    {
     57      Node node = stoplistTM.nodeAt(i);
    5758      if (node == null)
    5859        continue;
     
    155156        double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart);
    156157        time -= timeDelta;
    157         stoplistTM.insertRow(-1, StopImporterAction.timeOf(time));
    158158        Node node = StopImporterAction.createNode(latLon, type, "");
    159         stoplistTM.nodes.set(stoplistTM.getRowCount()-1, node);
     159        stoplistTM.insertRow(-1, node, StopImporterAction.timeOf(time), "");
    160160      }
    161161       
     
    168168  public void undoCommand()
    169169  {
    170     for (int i = 0; i < stoplistTM.nodes.size(); ++i)
    171     {
    172       Node node = stoplistTM.nodes.elementAt(i);
    173       stoplistTM.nodes.set(i, null);
     170    for (int i = 0; i < stoplistTM.getNodes().size(); ++i)
     171    {
     172      Node node = stoplistTM.nodeAt(i);
    174173      if (node == null)
    175174        continue;
     
    179178   
    180179    stoplistTM.setDataVector(tableDataModel);
    181     stoplistTM.nodes = nodes;
    182    
    183     for (int i = 0; i < stoplistTM.nodes.size(); ++i)
    184     {
    185       Node node = stoplistTM.nodes.elementAt(i);
     180    stoplistTM.setNodes(nodes);
     181    stoplistTM.setTimes(times);
     182   
     183    for (int i = 0; i < stoplistTM.getNodes().size(); ++i)
     184    {
     185      Node node = stoplistTM.nodeAt(i);
    186186      if (node == null)
    187187        continue;
     
    199199  public MutableTreeNode description()
    200200  {
    201     return new DefaultMutableTreeNode("public_transport.TrackStoplist.Sort");
     201    return new DefaultMutableTreeNode("public_transport.TrackStoplist.SuggestStops");
    202202  }
    203203 
Note: See TracChangeset for help on using the changeset viewer.