コード例 #1
0
ファイル: NoteLayer.java プロジェクト: openstreetmap/josm
 @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);
 }
コード例 #2
0
ファイル: NoteLayer.java プロジェクト: openstreetmap/josm
 @Override
 public void visitBoundingBox(BoundingXYVisitor v) {
   for (Note note : noteData.getNotes()) {
     v.visit(note.getLatLon());
   }
 }
コード例 #3
0
ファイル: NoteLayer.java プロジェクト: openstreetmap/josm
  @Override
  public void paint(Graphics2D g, MapView mv, Bounds box) {
    final int iconHeight = ImageProvider.ImageSizes.SMALLICON.getAdjustedHeight();
    final int iconWidth = ImageProvider.ImageSizes.SMALLICON.getAdjustedWidth();

    for (Note note : noteData.getNotes()) {
      Point p = mv.getPoint(note.getLatLon());

      ImageIcon icon;
      if (note.getId() < 0) {
        icon = ImageProvider.get("dialogs/notes", "note_new", ImageProvider.ImageSizes.SMALLICON);
      } else if (note.getState() == State.CLOSED) {
        icon =
            ImageProvider.get("dialogs/notes", "note_closed", ImageProvider.ImageSizes.SMALLICON);
      } else {
        icon = ImageProvider.get("dialogs/notes", "note_open", ImageProvider.ImageSizes.SMALLICON);
      }
      int width = icon.getIconWidth();
      int height = icon.getIconHeight();
      g.drawImage(icon.getImage(), p.x - (width / 2), p.y - height, Main.map.mapView);
    }
    if (noteData.getSelectedNote() != null) {
      StringBuilder sb = new StringBuilder("<html>");
      sb.append(tr("Note")).append(' ').append(noteData.getSelectedNote().getId());
      for (NoteComment comment : noteData.getSelectedNote().getComments()) {
        String commentText = comment.getText();
        // closing a note creates an empty comment that we don't want to show
        if (commentText != null && !commentText.trim().isEmpty()) {
          sb.append("<hr/>");
          String userName = XmlWriter.encode(comment.getUser().getName());
          if (userName == null || userName.trim().isEmpty()) {
            userName = "******";
          }
          sb.append(userName);
          sb.append(" on ");
          sb.append(
              DateUtils.getDateFormat(DateFormat.MEDIUM).format(comment.getCommentTimestamp()));
          sb.append(":<br/>");
          String htmlText = XmlWriter.encode(comment.getText(), true);
          htmlText =
              htmlText.replace(
                  "&#xA;", "<br/>"); // encode method leaves us with entity instead of \n
          htmlText =
              htmlText.replace("/", "/\u200b"); // zero width space to wrap long URLs (see #10864)
          sb.append(htmlText);
        }
      }
      sb.append("</html>");
      JToolTip toolTip = new JToolTip();
      toolTip.setTipText(sb.toString());
      Point p = mv.getPoint(noteData.getSelectedNote().getLatLon());

      g.setColor(ColorHelper.html2color(Main.pref.get("color.selected")));
      g.drawRect(p.x - (iconWidth / 2), p.y - iconHeight, iconWidth - 1, iconHeight - 1);

      int tx = p.x + (iconWidth / 2) + 5;
      int ty = p.y - iconHeight - 1;
      g.translate(tx, ty);

      // Carried over from the OSB plugin. Not entirely sure why it is needed
      // but without it, the tooltip doesn't get sized correctly
      for (int x = 0; x < 2; x++) {
        Dimension d = toolTip.getUI().getPreferredSize(toolTip);
        d.width = Math.min(d.width, mv.getWidth() / 2);
        if (d.width > 0 && d.height > 0) {
          toolTip.setSize(d);
          try {
            toolTip.paint(g);
          } catch (IllegalArgumentException e) {
            // See #11123 - https://bugs.openjdk.java.net/browse/JDK-6719550
            // Ignore the exception, as Netbeans does:
            // http://hg.netbeans.org/main-silver/rev/c96f4d5fbd20
            Main.error(e, false);
          }
        }
      }
      g.translate(-tx, -ty);
    }
  }