Example #1
0
 @Override
 public String acceptsDocumentationSummary() {
   StringBuilder buff = new StringBuilder("<tr><td>");
   buff.append(getTitle()).append(":</td><td>");
   String[] patterns = getPatterns();
   if (patterns.length > 0) {
     buff.append("<ul>");
     for (String pattern : patterns) {
       buff.append("<li>").append(XmlWriter.encode(pattern)).append("</li>");
     }
     buff.append("</ul>");
   }
   buff.append("</td></tr>");
   return buff.toString();
 }
Example #2
0
  @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);
    }
  }