コード例 #1
0
  public void actionPerformed(GpsActionEvent event) {
    String markerTitle = getParameters().get(0);
    Object source = event.getSource();
    if (source instanceof JToggleButton) {
      if (((JToggleButton) source).isSelected()) {
        markerTitle = tr("{0} start", markerTitle);
      } else {
        markerTitle = tr("{0} end", markerTitle);
      }
    }

    String iconName = getParameters().size() > 1 ? getParameters().get(1).trim() : null;

    long timeout = DialogClosingThread.DEFAULT_TIMEOUT;
    if (getParameters().size() > 2) {
      try {
        timeout = Integer.parseInt(getParameters().get(2));
      } catch (NumberFormatException e) {
        Main.error(e.getMessage());
      }
    }

    String markerText = markerTitle;

    if (timeout > 0) {
      if (dialog == null) {
        dialog = new WaypointDialog();
      }

      String inputText =
          dialog.openDialog(
              SurveyorPlugin.getSurveyorFrame(), tr("Waypoint Description"), timeout * 1000);
      if (inputText != null && inputText.length() > 0) {
        inputText = inputText.replaceAll("<", "_"); // otherwise the gpx file is ruined
        markerText = markerText + " " + inputText;
      }
    }

    // add the waypoint to the marker layer AND to the gpx layer
    // (easy export of data + waypoints):
    MarkerLayer layer = getMarkerLayer();
    GpxLayer gpsLayer = getGpxLayer();
    WayPoint waypoint = new WayPoint(event.getCoordinates());
    waypoint.attr.put("name", markerText);
    if (iconName != null && !iconName.isEmpty()) waypoint.attr.put("sym", iconName);
    synchronized (SurveyorLock.class) {
      layer.data.add(new Marker(event.getCoordinates(), markerText, iconName, null, -1.0, 0.0));
      if (gpsLayer != null) {
        gpsLayer.data.waypoints.add(waypoint);
      }
    }

    Main.map.repaint();
  }
コード例 #2
0
 @Override
 public void actionPerformed(GpsActionEvent event) {
   LatLon coordinates = event.getCoordinates();
   System.out.println(
       getClass().getSimpleName()
           + " KOORD: "
           + coordinates.lat()
           + ", "
           + coordinates.lon()
           + " params: "
           + getParameters());
 }