Exemple #1
0
 @Override
 public void mouseClicked(MouseEvent e) {
   if (SwingUtilities.isRightMouseButton(e) && noteData.getSelectedNote() != null) {
     final String url =
         OsmApi.getOsmApi().getBaseUrl() + "notes/" + noteData.getSelectedNote().getId();
     ClipboardUtils.copyString(url);
     return;
   } else if (!SwingUtilities.isLeftMouseButton(e)) {
     return;
   }
   Point clickPoint = e.getPoint();
   double snapDistance = 10;
   double minDistance = Double.MAX_VALUE;
   final int iconHeight = ImageProvider.ImageSizes.SMALLICON.getAdjustedHeight();
   Note closestNote = null;
   for (Note note : noteData.getNotes()) {
     Point notePoint = Main.map.mapView.getPoint(note.getLatLon());
     // move the note point to the center of the icon where users are most likely to click when
     // selecting
     notePoint.setLocation(notePoint.getX(), notePoint.getY() - iconHeight / 2);
     double dist = clickPoint.distanceSq(notePoint);
     if (minDistance > dist && clickPoint.distance(notePoint) < snapDistance) {
       minDistance = dist;
       closestNote = note;
     }
   }
   noteData.setSelectedNote(closestNote);
 }
/**
 * A special form of {@link LayerTransferData} that ensures you that the layer is an OSM data layer
 *
 * @author Michael Zangl
 * @since 10605
 */
public class OsmLayerTransferData extends LayerTransferData {

  /**
   * This is a data flavor specific for OSM data layers.
   *
   * @see LayerTransferData#FLAVOR
   * @see #FLAVORS
   */
  public static final DataFlavor OSM_FLAVOR =
      ClipboardUtils.newDataFlavor(OsmLayerTransferData.class, "Layer");

  /** The flavors that are supported by this data type. */
  public static final List<DataFlavor> FLAVORS =
      Collections.unmodifiableList(
          Arrays.asList(OSM_FLAVOR, LayerTransferData.FLAVOR, LayerTransferable.LAYER_DATA));

  private final OsmDataLayer osmLayer;

  /**
   * Create a new {@link OsmLayerTransferData} object
   *
   * @param layerManager The layer manager
   * @param layer The layer that is moved.
   */
  public OsmLayerTransferData(LayerManager layerManager, OsmDataLayer layer) {
    super(layerManager, layer);
    osmLayer = layer;
  }

  /**
   * Gets the OSM data layer.
   *
   * @return The layer
   */
  public OsmDataLayer getOsmLayer() {
    return osmLayer;
  }

  @Override
  public List<DataFlavor> getSupportedFlavors() {
    return FLAVORS;
  }

  @Override
  public String toString() {
    return "OsmLayerTransferData [osmLayer=" + osmLayer + ']';
  }
}