/**
  * Overridden to use the editor's background if it's detected that the user isn't using white as
  * the editor bg, but the system's tool tip background is yellow-ish.
  *
  * @return The tool tip.
  */
 public JToolTip createToolTip() {
   JToolTip tip = super.createToolTip();
   Color textAreaBG = textArea.getBackground();
   if (textAreaBG != null && !Color.white.equals(textAreaBG)) {
     Color bg = TipUtil.getToolTipBackground();
     // If current L&F's tool tip color is close enough to "yellow",
     // and we're not using the default text background of white, use
     // the editor background as the tool tip background.
     if (bg.getRed() >= 240 && bg.getGreen() >= 240 && bg.getBlue() >= 200) {
       tip.setBackground(textAreaBG);
     }
   }
   return tip;
 }
  /**
   * Tweaks a <code>JEditorPane</code> so it can be used to render the content in a focusable
   * pseudo-tool tip. It is assumed that the editor pane is using an <code>HTMLDocument</code>.
   *
   * @param textArea The editor pane to tweak.
   */
  public static void tweakTipEditorPane(JEditorPane textArea) {

    // Jump through a few hoops to get things looking nice in Nimbus
    boolean isNimbus = isNimbusLookAndFeel();
    if (isNimbus) {
      Color selBG = textArea.getSelectionColor();
      Color selFG = textArea.getSelectedTextColor();
      textArea.setUI(new javax.swing.plaf.basic.BasicEditorPaneUI());
      textArea.setSelectedTextColor(selFG);
      textArea.setSelectionColor(selBG);
    }

    textArea.setEditable(false); // Required for links to work!
    textArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Make selection visible even though we are not (initially) focusable.
    textArea.getCaret().setSelectionVisible(true);

    // Set the foreground color.  Important because when rendering HTML,
    // default foreground becomes black, which may not match all LAF's
    // (e.g. Substance).
    Color fg = UIManager.getColor("Label.foreground");
    if (fg == null || (isNimbus && isDerivedColor(fg))) {
      fg = SystemColor.textText;
    }
    textArea.setForeground(fg);

    // Make it use the "tool tip" background color.
    textArea.setBackground(TipUtil.getToolTipBackground());

    // Force JEditorPane to use a certain font even in HTML.
    // All standard LookAndFeels, even Nimbus (!), define Label.font.
    Font font = UIManager.getFont("Label.font");
    if (font == null) { // Try to make a sensible default
      font = new Font("SansSerif", Font.PLAIN, 12);
    }
    HTMLDocument doc = (HTMLDocument) textArea.getDocument();
    setFont(doc, font, fg);

    // Always add link foreground rule.  Unfortunately these CSS rules
    // stack each time the LaF is changed (how can we overwrite them
    // without clearing out the important "standard" ones?).
    Color linkFG = RSyntaxUtilities.getHyperlinkForeground();
    doc.getStyleSheet().addRule("a { color: " + getHexString(linkFG) + "; }");
  }