Java Code Examples for com.intellij.xml.util.XmlStringUtil#wrapInHtml()

The following examples show how to use com.intellij.xml.util.XmlStringUtil#wrapInHtml() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   File: LineTooltipRenderer.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String colorizeSeparators(@Nonnull String html) {
  String body = UIUtil.getHtmlBody(html);
  List<String> parts = StringUtil.split(body, UIUtil.BORDER_LINE, true, false);
  if (parts.size() <= 1) return html;
  StringBuilder b = new StringBuilder();
  for (String part : parts) {
    boolean addBorder = b.length() > 0;
    b.append("<div");
    if (addBorder) {
      b.append(" style='margin-top:6; padding-top:6; border-top: thin solid #");
      b.append(ColorUtil.toHex(UIUtil.getTooltipSeparatorColor()));
      b.append("'");
    }
    b.append("'>").append(part).append("</div>");
  }
  return XmlStringUtil.wrapInHtml(b.toString());
}
 
Example 2
@Override
public String getTooltipText() {
  final Library library = myEntry.getLibrary();
  if (library == null) return null;

  final String name = library.getName();
  if (name != null) {
    final List<String> invalidUrls = ((LibraryEx)library).getInvalidRootUrls(BinariesOrderRootType.getInstance());
    if (!invalidUrls.isEmpty()) {
      return ProjectBundle.message("project.roots.tooltip.library.has.broken.paths", name, invalidUrls.size());
    }
  }

  final List<String> descriptions = LibraryPresentationManager.getInstance().getDescriptions(library, myContext);
  if (descriptions.isEmpty()) return null;

  return XmlStringUtil.wrapInHtml(StringUtil.join(descriptions, "<br>"));
}
 
Example 3
@Nullable
@Override
protected JComponent createCenterPanel() {
  JLabel label = new JLabel(XmlStringUtil.wrapInHtml("The encoding you've chosen ('" +
                                                     charset.displayName() +
                                                     "') may change the contents of '" +
                                                     virtualFile.getName() +
                                                     "'.<br>" +
                                                     "Do you want to<br>" +
                                                     "1. <b>Reload</b> the file from disk in the new encoding '" +
                                                     charset.displayName() +
                                                     "' and overwrite editor contents or<br>" +
                                                     "2. <b>Convert</b> the text and overwrite file in the new encoding" +
                                                     "?"));
  label.setIcon(Messages.getQuestionIcon());
  label.setIconTextGap(10);
  return label;
}
 
Example 4
Source Project: consulo   File: HighlightInfoComposite.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static String createCompositeTooltip(@Nonnull List<? extends HighlightInfo> infos) {
  StringBuilder result = new StringBuilder();
  for (HighlightInfo info : infos) {
    String toolTip = info.getToolTip();
    if (toolTip != null) {
      if (result.length() != 0) {
        result.append(LINE_BREAK);
      }
      toolTip = XmlStringUtil.stripHtml(toolTip);
      result.append(toolTip);
    }
  }
  if (result.length() == 0) {
    return null;
  }
  return XmlStringUtil.wrapInHtml(result);
}
 
Example 5
Source Project: consulo   File: ArtifactErrorPanel.java    License: Apache License 2.0 6 votes vote down vote up
public void showError(@Nonnull String message, @Nonnull List<? extends ConfigurationErrorQuickFix> quickFixes) {
  myErrorLabel.setVisible(true);
  final String errorText = XmlStringUtil.wrapInHtml(message);
  if (myErrorLabel.isShowing()) {
    myErrorLabel.setText(errorText);
  }
  else {
    myErrorText = errorText;
  }
  myMainPanel.setVisible(true);
  myCurrentQuickFixes = quickFixes;
  myFixButton.setVisible(!quickFixes.isEmpty());
  if (!quickFixes.isEmpty()) {
    myFixButton.setText(quickFixes.size() == 1 ? ContainerUtil.getFirstItem(quickFixes, null).getActionName() : "Fix...");
  }
}
 
Example 6
@Nullable
private Annotation createAnnotation(@NotNull HighlightSeverity severity, @NotNull TextRange range, @Nullable String message) {
    // Skip duplicate messages.
    if (!messages.add(message)) return null;
    String tooltip = message == null ? null : XmlStringUtil.wrapInHtml(escapeSpacesForHtml(XmlStringUtil.escapeString(message)));
    return holder.createAnnotation(severity, range, message, tooltip);
}
 
Example 7
Source Project: intellij-haxe   File: HaxeAnnotation.java    License: Apache License 2.0 5 votes vote down vote up
public Annotation toAnnotation() {
  String tooltip = this.tooltip;
  if (null == tooltip && null != message && !message.isEmpty()) {
    tooltip = XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(message));
  }
  Annotation anno = new Annotation(range.getStartOffset(), range.getEndOffset(), severity, message, tooltip);

  for (IntentionAction action : intentions) {
    anno.registerFix(action);
  }
  return anno;
}
 
Example 8
Source Project: consulo   File: DependenciesPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  @NonNls final String delim = "&nbsp;-&gt;&nbsp;";
  final StringBuffer buf = new StringBuffer();
  processDependencies(getSelectedScope(myLeftTree), getSelectedScope(myRightTree), new Processor<List<PsiFile>>() {
    @Override
    public boolean process(final List<PsiFile> path) {
      if (buf.length() > 0) buf.append("<br>");
      buf.append(StringUtil.join(path, new Function<PsiFile, String>() {
        @Override
        public String fun(final PsiFile psiFile) {
          return psiFile.getName();
        }
      }, delim));
      return true;
    }
  });
  final JEditorPane pane = new JEditorPane(UIUtil.HTML_MIME, XmlStringUtil.wrapInHtml(buf));
  pane.setForeground(JBColor.foreground());
  pane.setBackground(HintUtil.INFORMATION_COLOR);
  pane.setOpaque(true);
  final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
  final Dimension dimension = pane.getPreferredSize();
  scrollPane.setMinimumSize(new Dimension(dimension.width, dimension.height + 20));
  scrollPane.setPreferredSize(new Dimension(dimension.width, dimension.height + 20));
  JBPopupFactory.getInstance().createComponentPopupBuilder(scrollPane, pane).setTitle("Dependencies")
    .setMovable(true).createPopup().showInBestPositionFor(e.getDataContext());
}
 
Example 9
Source Project: consulo   File: HighlightInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public String getToolTip() {
  String toolTip = this.toolTip;
  String description = this.description;
  if (toolTip == null || description == null || !toolTip.contains(DESCRIPTION_PLACEHOLDER)) return toolTip;
  String decoded = StringUtil.replace(toolTip, DESCRIPTION_PLACEHOLDER, XmlStringUtil.escapeString(description));
  return XmlStringUtil.wrapInHtml(decoded);
}
 
Example 10
Source Project: consulo   File: NotificationsUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String buildHtml(@Nullable String title,
                               @Nullable String subtitle,
                               @Nullable String content,
                               @Nullable String style,
                               @Nullable String titleColor,
                               @Nullable String contentColor,
                               @Nullable String contentStyle) {
  if (StringUtil.isEmpty(title) && !StringUtil.isEmpty(subtitle)) {
    title = subtitle;
    subtitle = null;
  }
  else if (!StringUtil.isEmpty(title) && !StringUtil.isEmpty(subtitle)) {
    title += ":";
  }

  StringBuilder result = new StringBuilder();
  if (style != null) {
    result.append("<div style=\"").append(style).append("\">");
  }
  if (!StringUtil.isEmpty(title)) {
    result.append("<b").append(titleColor == null ? ">" : " color=\"" + titleColor + "\">").append(title).append("</b>");
  }
  if (!StringUtil.isEmpty(subtitle)) {
    result.append("&nbsp;").append(titleColor == null ? "" : "<span color=\"" + titleColor + "\">").append(subtitle)
            .append(titleColor == null ? "" : "</span>");
  }
  if (!StringUtil.isEmpty(content)) {
    result.append("<p").append(contentStyle == null ? "" : " style=\"" + contentStyle + "\"")
            .append(contentColor == null ? ">" : " color=\"" + contentColor + "\">").append(content).append("</p>");
  }
  if (style != null) {
    result.append("</div>");
  }
  return XmlStringUtil.wrapInHtml(result.toString());
}
 
Example 11
Source Project: consulo   File: UndoApplyPatchDialog.java    License: Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout());
  int numFiles = myFailedFilePaths.size();
  JPanel labelsPanel = new JPanel(new BorderLayout());
  String detailedText = numFiles == 0 ? "" : String.format("Failed to apply %s below.<br>", StringUtil.pluralize("file", numFiles));
  final JLabel infoLabel = new JBLabel(XmlStringUtil.wrapInHtml(detailedText + "Would you like to rollback all applied?"));
  labelsPanel.add(infoLabel, BorderLayout.NORTH);
  if (myShouldInformAboutBinaries) {
    JLabel warningLabel = new JLabel("Rollback will not affect binaries");
    warningLabel.setIcon(AllIcons.General.BalloonWarning);
    labelsPanel.add(warningLabel, BorderLayout.CENTER);
  }
  panel.add(labelsPanel, BorderLayout.NORTH);
  if (numFiles > 0) {
    FilePathChangesTreeList browser = new FilePathChangesTreeList(myProject, myFailedFilePaths, false, false, null, null) {
      @Override
      public Dimension getPreferredSize() {
        return new Dimension(infoLabel.getPreferredSize().width, 50);
      }
    };
    browser.setChangesToDisplay(myFailedFilePaths);
    panel.add(ScrollPaneFactory.createScrollPane(browser), BorderLayout.CENTER);
  }
  return panel;
}
 
Example 12
Source Project: consulo   File: LocalInspectionsPass.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private HighlightInfo createHighlightInfo(@Nonnull ProblemDescriptor descriptor,
                                          @Nonnull LocalInspectionToolWrapper tool,
                                          @Nonnull HighlightInfoType level,
                                          @Nonnull Set<Pair<TextRange, String>> emptyActionRegistered,
                                          @Nonnull PsiElement element) {
  @NonNls String message = ProblemDescriptorUtil.renderDescriptionMessage(descriptor, element);

  final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
  final InspectionProfile inspectionProfile = myProfileWrapper.getInspectionProfile();
  if (!inspectionProfile.isToolEnabled(key, getFile())) return null;

  HighlightInfoType type = new HighlightInfoType.HighlightInfoTypeImpl(level.getSeverity(element), level.getAttributesKey());
  final String plainMessage = message.startsWith("<html>") ? StringUtil.unescapeXml(XmlStringUtil.stripHtml(message).replaceAll("<[^>]*>", "")) : message;
  @NonNls final String link = " <a " +
                              "href=\"#inspection/" +
                              tool.getShortName() +
                              "\"" +
                              (UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "") +
                              ">" +
                              DaemonBundle.message("inspection.extended.description") +
                              "</a> " +
                              myShortcutText;

  @NonNls String tooltip = null;
  if (descriptor.showTooltip()) {
    tooltip = XmlStringUtil.wrapInHtml((message.startsWith("<html>") ? XmlStringUtil.stripHtml(message) : XmlStringUtil.escapeString(message)) + link);
  }
  HighlightInfo highlightInfo = highlightInfoFromDescriptor(descriptor, type, plainMessage, tooltip, element);
  if (highlightInfo != null) {
    registerQuickFixes(tool, descriptor, highlightInfo, emptyActionRegistered);
  }
  return highlightInfo;
}
 
Example 13
Source Project: consulo   File: DaemonTooltipRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected String dressDescription(@Nonnull final Editor editor, @Nonnull String tooltipText, boolean expand) {
  if (!expand) {
    return super.dressDescription(editor, tooltipText, false);
  }

  final List<String> problems = getProblems(tooltipText);
  StringBuilder text = new StringBuilder();
  for (String problem : problems) {
    final String ref = getLinkRef(problem);
    if (ref != null) {
      String description = TooltipLinkHandlerEP.getDescription(ref, editor);
      if (description != null) {
        description = InspectionNodeInfo.stripUIRefsFromInspectionDescription(UIUtil.getHtmlBody(new Html(description).setKeepFont(true)));
        text.append(getHtmlForProblemWithLink(problem)).append(END_MARKER).append("<p>").append("<span style=\"color:").append(ColorUtil.toHex(getDescriptionTitleColor())).append("\">")
                .append(TooltipLinkHandlerEP.getDescriptionTitle(ref, editor)).append(":</span>").append(description).append(UIUtil.BORDER_LINE);
      }
    }
    else {
      text.append(UIUtil.getHtmlBody(new Html(problem).setKeepFont(true))).append(UIUtil.BORDER_LINE);
    }
  }
  if (text.length() > 0) { //otherwise do not change anything
    return XmlStringUtil.wrapInHtml(StringUtil.trimEnd(text.toString(), UIUtil.BORDER_LINE));
  }
  return super.dressDescription(editor, tooltipText, true);
}
 
Example 14
private static String createInvalidRootsDescription(List<String> invalidClasses, String rootName, String libraryName) {
  StringBuilder buffer = new StringBuilder();
  buffer.append("Library '").append(StringUtil.escapeXml(libraryName)).append("' has broken " + rootName + " " + StringUtil.pluralize("path", invalidClasses.size()) + ":");
  for (String url : invalidClasses) {
    buffer.append("<br>&nbsp;&nbsp;");
    buffer.append(PathUtil.toPresentableUrl(url));
  }
  return XmlStringUtil.wrapInHtml(buffer);
}
 
Example 15
Source Project: consulo   File: ShowUsagesAction.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String suggestSecondInvocation(@Nonnull FindUsagesOptions options, @Nonnull FindUsagesHandler handler, @Nonnull String text) {
  final String title = getSecondInvocationTitle(options, handler);

  if (title != null) {
    text += "<br><small> " + title + "</small>";
  }
  return XmlStringUtil.wrapInHtml(UIUtil.convertSpace2Nbsp(text));
}
 
Example 16
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {
    IElementType elementType = CsvHelper.getElementType(element);
    if ((elementType != CsvTypes.FIELD && elementType != CsvTypes.COMMA) || !(element.getContainingFile() instanceof CsvFile)) {
        return;
    }

    CsvFile csvFile = (CsvFile) element.getContainingFile();
    if (handleSeparatorElement(element, holder, elementType, csvFile)) {
        return;
    }

    CsvColumnInfo<PsiElement> columnInfo = csvFile.getColumnInfoMap().getColumnInfo(element);

    if (columnInfo != null) {
        PsiElement headerElement = columnInfo.getHeaderElement();
        String message = FontUtil.getHtmlWithFonts(
                XmlStringUtil.escapeString(headerElement == null ? "" : headerElement.getText(), true)
        );
        String tooltip = null;
        if (showInfoBalloon(holder.getCurrentAnnotationSession())) {
            tooltip = XmlStringUtil.wrapInHtml(
                    String.format("%s<br /><br />Header: %s<br />Index: %d",
                            FontUtil.getHtmlWithFonts(
                                XmlStringUtil.escapeString(element.getText(), true)
                            ),
                            message,
                            columnInfo.getColumnIndex() + (CsvEditorSettings.getInstance().isZeroBasedColumnNumbering() ? 0 : 1)
                    )
            );
        }
        TextRange textRange = columnInfo.getRowInfo(element).getTextRange();
        if (textRange.getStartOffset() - csvFile.getTextLength() == 0 && textRange.getStartOffset() > 0) {
            textRange = TextRange.from(textRange.getStartOffset() - 1, 1);
        }

        Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip);
        annotation.setEnforcedTextAttributes(
                CsvEditorSettings.getInstance().isColumnHighlightingEnabled() ?
                        CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) :
                        null
        );
        annotation.setNeedsUpdateOnTyping(false);
    }
}
 
Example 17
@Override
public Annotation createAnnotation(@NotNull HighlightSeverity severity, @NotNull TextRange range, @Nullable String s) {
  @NonNls String tooltip = s == null ? null : XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(s));
  return createAnnotation(severity, range, s, tooltip);
}
 
Example 18
Source Project: consulo   File: DetailsComponent.java    License: Apache License 2.0 4 votes vote down vote up
public DetailsComponent setEmptyContentText(@Nullable final String emptyContentText) {
  @NonNls final String s = XmlStringUtil.wrapInHtml("<center>" + (emptyContentText != null ? emptyContentText : "") + "</center>");
  myEmptyContentLabel.setText(s);
  return this;
}
 
Example 19
Source Project: consulo   File: BoldLabel.java    License: Apache License 2.0 4 votes vote down vote up
private static String toHtml(String text) {
  if (text.startsWith("<html>")) return text;
  return XmlStringUtil.wrapInHtml(
    "<b>" + text.replaceAll("\\n", "<br>") + "</b>"
  );
}
 
Example 20
Source Project: consulo   File: HighlightInfo.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
private static String htmlEscapeToolTip(@Nullable String unescapedTooltip) {
  return unescapedTooltip == null ? null : XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(unescapedTooltip));
}