setText method

void setText (String id, String text, String stroke)

Replaces the legend text with id by the new text. stroke defines the color of the text marker rectangle. If stroke is null, no rectangle will be drawn. If there is no legend text to replace, the legend text will be set initally from text.

Implementation

void setText(String id, String text, String stroke) {
//    if(text == null)
//    {
//      if(bgRectangle != null)
//        bgRectangle.remove(); // remove the one from the last draw
//      return;
//    }

  if (textElements.containsKey(id)) {
    TextElement te = textElements[id];
    te.text = text;
    te.replaceWith(te);
  } else {
    initSetText(id, text, stroke);
  }

  // BG rectangle must be drawn each time the text changes, because it's width
  // must be adapted to the text width. It will be added on top of the text
  // (and the text color marker rectangles)
  // Therefore the rectangle's opacity (BG_OPACITY) must be < 1.0, otherwise
  // the text will remain hidden.
  addBGRectangle_(dy);
}