當前位置: 首頁>>代碼示例>>Java>>正文


Java UIUtil.splitText方法代碼示例

本文整理匯總了Java中com.intellij.util.ui.UIUtil.splitText方法的典型用法代碼示例。如果您正苦於以下問題:Java UIUtil.splitText方法的具體用法?Java UIUtil.splitText怎麽用?Java UIUtil.splitText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.util.ui.UIUtil的用法示例。


在下文中一共展示了UIUtil.splitText方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: splitText

import com.intellij.util.ui.UIUtil; //導入方法依賴的package包/類
private static String splitText(final JLabel label, final String text, final int widthLimit) {
  final FontMetrics fontMetrics = label.getFontMetrics(label.getFont());

  final String[] lines = UIUtil.splitText(text, fontMetrics, widthLimit, ' ');

  final StringBuilder result = new StringBuilder();
  for (int i = 0; i < lines.length; i++) {
    final String line = lines[i];
    if (i > 0) {
      result.append('\n');
    }
    result.append(line);
  }
  return result.toString();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:TextPanel.java

示例2: setup

import com.intellij.util.ui.UIUtil; //導入方法依賴的package包/類
private String setup(String text,
                     Function<String, String> escapeFunction,
                     int highlightStartOffset,
                     int highlightEndOffset,
                     boolean isDisabled,
                     boolean strikeout,
                     boolean isDisabledBeforeHighlight,
                     Color background) {
  StringBuilder buf = new StringBuilder();
  removeAll();

  String[] lines = UIUtil.splitText(text, getFontMetrics(BOLD_FONT), myWidthLimit, ',');

  myOneLineComponents = new OneLineComponent[lines.length];

  int lineOffset = 0;

  boolean hasHighlighting = highlightStartOffset >= 0 && highlightEndOffset > highlightStartOffset;
  TextRange highlightingRange = hasHighlighting ? new TextRange(highlightStartOffset, highlightEndOffset) : null;

  for (int i = 0; i < lines.length; i++) {
    String line = lines[i];

    myOneLineComponents[i] = new OneLineComponent();

    TextRange lRange = new TextRange(lineOffset, lineOffset + line.length());
    TextRange hr = highlightingRange == null ? null : lRange.intersection(highlightingRange);
    hr = hr == null ? null : hr.shiftRight(-lineOffset);

    String before = escapeString(hr == null ? line : line.substring(0, hr.getStartOffset()), escapeFunction);
    String in = hr == null ? "" : escapeString(hr.substring(line), escapeFunction);
    String after = hr == null ? "" : escapeString(line.substring(hr.getEndOffset(), line.length()), escapeFunction);

    TextRange escapedHighlightingRange = in.isEmpty() ? null : TextRange.create(before.length(), before.length() + in.length());
    buf.append(myOneLineComponents[i].setup(before + in + after, isDisabled, strikeout, background, escapedHighlightingRange));

    if (isDisabledBeforeHighlight) {
      if (highlightStartOffset < 0 || highlightEndOffset > lineOffset) {
        myOneLineComponents[i].setDisabledBeforeHighlight();
      }
    }

    add(myOneLineComponents[i], new GridBagConstraints(0,i,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(0,0,0,0),0,0));

    lineOffset += line.length();
  }
  return buf.toString();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:49,代碼來源:ParameterInfoComponent.java


注:本文中的com.intellij.util.ui.UIUtil.splitText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。