private static void updateShortcuts(StringBuffer text) {
   int lastIndex = 0;
   while (true) {
     lastIndex = text.indexOf(SHORTCUT_ENTITY, lastIndex);
     if (lastIndex < 0) return;
     final int actionIdStart = lastIndex + SHORTCUT_ENTITY.length();
     int actionIdEnd = text.indexOf(";", actionIdStart);
     if (actionIdEnd < 0) {
       return;
     }
     final String actionId = text.substring(actionIdStart, actionIdEnd);
     String shortcutText =
         getShortcutText(actionId, KeymapManager.getInstance().getActiveKeymap());
     if (shortcutText == null) {
       Keymap defKeymap =
           KeymapManager.getInstance()
               .getKeymap(DefaultKeymap.getInstance().getDefaultKeymapName());
       if (defKeymap != null) {
         shortcutText = getShortcutText(actionId, defKeymap);
         if (shortcutText != null) {
           shortcutText += " in default keymap";
         }
       }
     }
     if (shortcutText == null) {
       shortcutText = "<no shortcut for action " + actionId + ">";
     }
     text.replace(lastIndex, actionIdEnd + 1, shortcutText);
     lastIndex += shortcutText.length();
   }
 }
  private static void updateImages(StringBuffer text, ClassLoader tipLoader) {
    final boolean dark = UIUtil.isUnderDarcula();
    final boolean retina = UIUtil.isRetina();
    //    if (!dark && !retina) {
    //      return;
    //    }

    String suffix = "";
    if (retina) suffix += "@2x";
    if (dark) suffix += "_dark";
    int index = text.indexOf("<img", 0);
    while (index != -1) {
      final int end = text.indexOf(">", index + 1);
      if (end == -1) return;
      final String img = text.substring(index, end + 1).replace('\r', ' ').replace('\n', ' ');
      final int srcIndex = img.indexOf("src=");
      final int endIndex = img.indexOf(".png", srcIndex);
      if (endIndex != -1) {
        String path = img.substring(srcIndex + 5, endIndex);
        if (!path.endsWith("_dark") && !path.endsWith("@2x")) {
          path += suffix + ".png";
          URL url = ResourceUtil.getResource(tipLoader, "/tips/", path);
          if (url != null) {
            String newImgTag = "<img src=\"" + path + "\" ";
            if (retina) {
              try {
                final BufferedImage image = ImageIO.read(url.openStream());
                final int w = image.getWidth() / 2;
                final int h = image.getHeight() / 2;
                newImgTag += "width=\"" + w + "\" height=\"" + h + "\"";
              } catch (Exception ignore) {
                newImgTag += "width=\"400\" height=\"200\"";
              }
            }
            newImgTag += "/>";
            text.replace(index, end + 1, newImgTag);
          }
        }
      }
      index = text.indexOf("<img", index + 1);
    }
  }
  /**
   * Makes the label clickable or makes it unclickable. Clickable label features bold and underlined
   * text
   *
   * @param clickable Is the label clickable
   * @param action Action to be performed on click
   * @param rolloverIcon Icon to display on rollover
   * @since Jun 13, 2006 2:00:57 AM
   */
  public void setClickable(
      final boolean clickable, final ActionListener action, final Icon rolloverIcon) {
    if (clickable) {
      //  Set the action
      this.action = action;

      //  Set the offIcon;
      this.offIcon = getIcon();
      setIcon(offIcon);

      //  Add a Mouse Listener
      addMouseListener(this);

      //  Set the text (Undelined and Bolded)
      setText(
          new StringBuffer("<html><b><u>").append(getText()).append("</u></b></html>").toString());

      //  Set the rollover icon
      this.rolloverIcon = rolloverIcon;

      //  Init the Color and Mouse Cursor
      setForeground(offColor);
    } else {
      // Set the action to null
      this.action = null;

      // Remove the Mouse Listener
      removeMouseListener(this);

      //  Change the text back to normal
      final StringBuffer textBuffer = new StringBuffer(getText());
      final int msgEnd = textBuffer.indexOf("</u></b></html>");
      setText(textBuffer.substring(12, msgEnd));

      //  Set the rollover icon
      this.rolloverIcon = null;
    }

    // Repaint the Label
    repaint();
  }
  private void changed() {

    double price = 1.0500;
    double spread = 0.0004;

    CandleDataPoint candle = new CandleDataPoint();
    candle.setInstrument(Instrument.AUDUSD);
    candle.setPeriod(Period.FifteenMin);

    double low = price;
    double high = price + sldSize.getValue() / 10000.0;
    double open = price + sldSize.getValue() * (sldOpen.getValue() / 100.0) / 10000.0;
    double close = price + sldSize.getValue() * (sldClose.getValue() / 100.0) / 10000.0;

    candle.setBuyOpen(open - spread);
    candle.setSellOpen(open + spread);
    candle.setBuyClose(close - spread);
    candle.setSellClose(close + spread);
    candle.setBuyHigh(high - spread);
    candle.setSellHigh(high + spread);
    candle.setBuyLow(low - spread);
    candle.setSellLow(low + spread);

    StringBuffer buf =
        new StringBuffer(
            String.format(
                "%.4f / %.4f / %.4f / %.4f %n",
                candle.getOpen(), candle.getHigh(), candle.getLow(), candle.getClose()));

    for (CandleType candleType : CandleType.values()) {
      if (candleType.is(candle)) {
        buf.append(candleType.toString()).append(", ");
      }
    }

    if (buf.length() > 2) txt.setText(buf.substring(0, buf.length() - 2));
    else txt.setText("None");
  }