javax.swing.text.Utilities类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(73)

本文整理了Java中javax.swing.text.Utilities类的一些代码示例,展示了Utilities类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities类的具体详情如下:
包路径:javax.swing.text.Utilities
类名称:Utilities

Utilities介绍

暂无

代码示例

代码示例来源:origin: skylot/jadx

g.setFont(font);
g.setColor(codeArea.getBackground());
g.fillRect(0, 0, size.width, size.height);
      g.drawString(lineNumber, x, y);
    rowStartOffset = Utilities.getRowEnd(codeArea, rowStartOffset) + 1;
  } catch (Exception e) {
    if (LOG.isDebugEnabled()) {

代码示例来源:origin: apache/pdfbox

private String getRowText(int offset)
  {
    try
    {
      int rowStart = Utilities.getRowStart(textComponent, offset);
      int rowEnd = Utilities.getRowEnd(textComponent, offset);
      return textComponent.getDocument().getText(rowStart, rowEnd - rowStart + 1);
    }
    catch (BadLocationException e)
    {
      e.printStackTrace();
    }
    return null;
  }
}

代码示例来源:origin: apache/pdfbox

private String getWord(int offset)
{
  try
  {
    int start = Utilities.getWordStart(textComponent, offset);
    int end = Utilities.getWordEnd(textComponent, offset);
    return textComponent.getDocument().getText(start, end - start + 1).trim();
  }
  catch (BadLocationException e)
  {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: groovy/groovy-core

public void actionPerformed(ActionEvent ae) {
    try {
      if (multiLineTab && TextEditor.this.getSelectedText() != null) {
        int end = Utilities.getRowEnd(TextEditor.this, getSelectionEnd());
        TextEditor.this.setSelectionEnd(end);
        Element el = Utilities.getParagraphElement(TextEditor.this, getSelectionStart());
        int start = el.getStartOffset();
        TextEditor.this.setSelectionStart(start);
        // remove text and reselect the text
        String text = tabsAsSpaces ?
            TAB_BACK_PATTERN.matcher(getSelectedText()).replaceAll("") :
            getSelectedText().replaceAll("^\t", "");
        TextEditor.this.replaceSelection(text);
        TextEditor.this.select(start, start + text.length());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: groovy/groovy-core

public void actionPerformed(ActionEvent ae) {
    try {
      Document doc = TextEditor.this.getDocument();
      String text = tabsAsSpaces ? TABBED_SPACES : "\t";
      if (multiLineTab && getSelectedText() != null) {
        int end = Utilities.getRowEnd(TextEditor.this, getSelectionEnd());
        TextEditor.this.setSelectionEnd(end);
        Element el = Utilities.getParagraphElement(TextEditor.this, getSelectionStart());
        int start = el.getStartOffset();
        TextEditor.this.setSelectionStart(start);
        String toReplace = TextEditor.this.getSelectedText();
        toReplace = LINE_START.matcher(toReplace).replaceAll(text);
        TextEditor.this.replaceSelection(toReplace);
        TextEditor.this.select(start, start + toReplace.length());
      } else {
        int pos = TextEditor.this.getCaretPosition();
        doc.insertString(pos, text, null);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: de.sciss/syntaxpane

graphics.setFont(graphics.getFont().deriveFont(getFontStyle()));
FontMetrics fontMetrics = graphics.getFontMetrics();
int a = fontMetrics.getAscent();
int h = a + fontMetrics.getDescent();
int w = Utilities.getTabbedTextWidth(segment, fontMetrics, 0, e, startOffset);
int rX = x - 1;
int rY = y - a;
graphics.setColor(getColor());
x = Utilities.drawTabbedText(segment, x, y, graphics, e, startOffset);
if ((getFontStyle() & 0x8) != 0) {
  graphics.setColor(Color.RED);

代码示例来源:origin: net.sf.jped/jedit-syntax

protected void paintPlainLine(Graphics gfx, int line, Font defaultFont,
  Color defaultColor, int x, int y)
{
  paintHighlight(gfx,line,y);
  textArea.getLineText(line,currentLine);
  gfx.setFont(defaultFont);
  gfx.setColor(defaultColor);
  y += fm.getHeight();
  x = Utilities.drawTabbedText(currentLine,x,y,gfx,this,0);
  if(eolMarkers)
  {
    gfx.setColor(eolMarkerColor);
    gfx.drawString(".",x,y);
  }
}

代码示例来源:origin: SonarSource/sonarqube

FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
Insets insets = getInsets();
int availableWidth = getSize().width - insets.left - insets.right;
Rectangle clip = g.getClipBounds();
int rowStartOffset = component.viewToModel(new Point(0, clip.y));
int endOffset = component.viewToModel(new Point(0, clip.y + clip.height));
 try {
  if (isCurrentLine(rowStartOffset))
   g.setColor(getCurrentLineForeground());
  else
   g.setColor(getForeground());
  rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
 } catch (Exception e) {
  break;

代码示例来源:origin: bobbylight/RSyntaxTextArea

g.setColor(Color.BLACK);
g.setFont(font!=null ? font : textComponent.getFont());
fm = g.getFontMetrics();
int fontHeight = fm.getHeight();
Document doc = textComponent.getDocument();
rootElement = doc.getDefaultRootElement();
    doc.getText(currentLineStart+startingOffset, currentLineEnd-(currentLineStart+startingOffset),
          currentLineSeg);
  } catch (BadLocationException ble) {
  int currentLineLengthInPixels = Utilities.getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander, 0);
            getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander, 0);
        } while (currentLineLengthInPixels <= lineLengthInPixels);
        currentPos--;
      currentLineLengthInPixels = Utilities.getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander, 0);
  if (numPrintedLines>startingLineNumber) {
    Utilities.drawTabbedText(currentLineSeg, xOffset,y, g, tabExpander, 0);
    y += fontHeight;
    if (numPrintedLines==startingLineNumber+maxLinesPerPage) {

代码示例来源:origin: matsim-org/matsim

String text = doc.getText(p0, p1 - p0);
    graphics.setColor(Color.black);
    doc.getText(p0 + i, start - i, segment);
    x = Utilities.drawTabbedText(segment, x, y, graphics, this, i);
  graphics.setColor(colorMap.get(start));
  i = end;
  doc.getText(p0 + start, i - start, segment);
  x = Utilities.drawTabbedText(segment, x, y, graphics, this, start);
  graphics.setColor(Color.black);
  doc.getText(p0 + i, text.length() - i, segment);
  x = Utilities.drawTabbedText(segment, x, y, graphics, this, i);

代码示例来源:origin: antlr/antlrworks

public void drawToken(ATERenderingView view, ATERenderingToken t,
             Graphics g, FontMetrics metrics,
             int x, int y, char c, Document doc,
             AttributeSet attribute, Segment text)
      throws BadLocationException
  {
    g.setColor(Color.blue);
    //g.drawLine(beginX, y+2, x, y+2);
    g.drawLine(startToken.getStartX(), y+1, x, y+1);
    // draw the text
    doc.getText(startToken.getStartIndex(), t.getIndex()-startToken.getStartIndex(), text);
    Utilities.drawTabbedText(text, startToken.getStartX(), y, g, view, startToken.getStartIndex());
  }
}

代码示例来源:origin: as0ler/Android-Tools

@Override
public void paintComponent(Graphics g) {
  super.paintComponent(g);
  FontMetrics fontMetrics = contentArea.getFontMetrics(contentArea.getFont());
  Insets insets = getInsets();
  int availableWidth = getSize().width - insets.left - insets.right;
  Rectangle clip = g.getClipBounds();
  int rowStartOffset = contentArea.viewToModel(new Point(0, clip.y));
  int endOffset = contentArea.viewToModel(new Point(0, clip.y + clip.height));
  while (rowStartOffset <= endOffset) {
    try {
      if (isCurrentLine(rowStartOffset)) {
        g.setColor(CURRENT_LINE_FOREGROUND);
      } else {
        g.setColor(FOREGROUND);
      }
      String lineNumber = getTextLineNumber(rowStartOffset);
      int stringWidth = fontMetrics.stringWidth(lineNumber);
      int x = availableWidth - stringWidth + insets.left;
      int y = getOffsetY(rowStartOffset, fontMetrics);
      g.drawString(lineNumber, x, y);
      rowStartOffset = Utilities.getRowEnd(contentArea, rowStartOffset) + 1;
    } catch (Exception e) {
      break;
    }
  }
}

代码示例来源:origin: RPTools/maptool

if (p != p0) {
  text = v.getText(p, p0);
  int width = Utilities.getTabbedTextWidth(text, metrics, x, expander, p);
  x += width;
Color fg = g.getColor();
if (bg == null) { // No color set, guess black or white
  float[] hsb = Color.RGBtoHSB(fg.getRed(), fg.getGreen(), fg.getBlue(), null);
  bg = hsb[2] > 0.7 ? Color.BLACK : Color.WHITE;
g.setColor(bg);
g.setFont(metrics.getFont());
Utilities.drawTabbedText(text, x + HORIZONTAL_OFFSET, y + VERTICAL_OFFSET, g, expander, p0);
g.setColor(fg);
Utilities.drawTabbedText(text, x, y, g, expander, p0);

代码示例来源:origin: OpenNMS/opennms

boolean        beep   = true;
if ((target != null) && (target.isEditable())) {
    int    offs    = target.getCaretPosition();
    int    endOffs;
    String s       = target.getDocument().getText(offs, 1);
      endOffs = Utilities.getNextWord(target, offs);
      endOffs = Utilities.getWordEnd(target, endOffs);
    } else {
      endOffs = Utilities.getWordEnd(target, offs);

代码示例来源:origin: RPTools/maptool

/**
   * @see javax.swing.text.PlainView#drawUnselectedText(java.awt.Graphics, int, int, int, int)
   */
  protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
    // Find the text segment
    Document doc = getDocument();
    Segment s = new Segment();
    doc.getText(p0, p1 - p0, s);
    // Calculate the background highlight, it gets painted first.
    TwoToneTextField host = (TwoToneTextField) getContainer();
    Color bg = host.getTwoToneColor();
    Color fg = g.getColor();
    if (bg == null) { // No color set, guess black or white
      float[] hsb = Color.RGBtoHSB(fg.getRed(), fg.getGreen(), fg.getBlue(), null);
      bg = hsb[2] > 0.7 ? Color.BLACK : Color.WHITE;
    } // endif
    g.setColor(bg);
    Utilities.drawTabbedText(s, x + HORIZONTAL_OFFSET, y + VERTICAL_OFFSET, g, this, p0);
    // Draw the foreground
    g.setColor(fg);
    return Utilities.drawTabbedText(s, x, y, g, this, p0);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf-testrunner-ui

private int drawText(Graphics g,
           int x, int y,
           int startOffset, int endOffset,
           boolean error,
           boolean selected,
           DocElement docElem) throws BadLocationException {
  Segment s = EventQueue.isDispatchThread() ? SEGMENT : new Segment(); 
  s.array = docElem.getChars();
  s.offset = startOffset - docElem.offset;
  s.count = endOffset - startOffset;
  g.setColor(getColor(error, selected));
  return Utilities.drawTabbedText(s, x, y, g, this, startOffset);
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

Element curPara = Utilities.getParagraphElement(textArea, offs);
  int end = textArea.getDocument().getLength();
  if (offs != end) {
    if(oldOffs != curPara.getEndOffset() - 1) {

代码示例来源:origin: org.wildfly.core/wildfly-cli

@Override
public void mouseClicked(MouseEvent me) {
  if (me.getClickCount() < 2) return;
  int pos = output.viewToModel(me.getPoint());
  try {
    int rowStart = Utilities.getRowStart(output, pos);
    int rowEnd = Utilities.getRowEnd(output, pos);
    String line = output.getDocument().getText(rowStart, rowEnd - rowStart);
    if (opListener.getCmdHistory().contains(line)) {
      output.select(rowStart, rowEnd);
      cliGuiCtx.getCommandLine().getCmdText().setText(line);
      systemClipboard.setContents(new StringSelection(line), this);
    }
  } catch (BadLocationException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: antlr/antlrworks

public int renderTextPortion(Graphics g, int x, int y, int start, int end, int max, Document doc, AttributeSet attribute)
      throws BadLocationException
  {
    if(g == null)
      return 0;
    int length = end - start;
    if(start + length > max)
      length = max - start;
    save(g);
    applyAttribute(g, attribute);
    Segment text = getLineBuffer();
    doc.getText(start, length, text);
    modelPos += Utilities.getTabbedTextOffset(text, g.getFontMetrics(), x, viewX, ATERenderingView.this, start);
    x +=Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, ATERenderingView.this, start);
    restore(g);
    return x;
  }
}

代码示例来源:origin: antlr/antlrworks

public int renderTextPortion(Graphics g, int x, int y, int start, int end, int max, Document doc, AttributeSet attribute)
      throws BadLocationException
  {
    if(g == null)
      return 0;
    int length = end - start;
    if(start + length > max)
      length = max - start;
    save(g);
    applyAttribute(g, attribute);
    Segment text = getLineBuffer();
    doc.getText(start, length, text);
    x += Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, ATERenderingView.this, start);
    restore(g);
    return x;
  }
}

相关文章