javax.swing.text.StyledDocument.getCharacterElement()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(190)

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

StyledDocument.getCharacterElement介绍

暂无

代码示例

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

public int findTabLocation(int offset) {
    // find first {
    boolean cont = true;
    while (offset > -1 && cont) {
      Element el = doc.getCharacterElement(offset);
      Object color =
          el.getAttributes().getAttribute(StyleConstants.Foreground);
      if (!COMMENT_COLOR.equals(color)) {
        cont = segment.array[offset] != '{' &&
            segment.array[offset] != '}';
      }
      offset -= cont ? 1 : 0;
    }
    if (offset > -1 && segment.array[offset] == '{') {
      while (offset > -1 &&
          !Character.isWhitespace(segment.array[offset--])) {
      }
    }
    int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
    if (offset > -1) {
      Element top = doc.getDefaultRootElement();
      offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
      while (Character.isWhitespace(segment.array[offset++])) {
        index++;
      }
    }
    return index;
  }
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

/**
 * {@inheritDoc}
 */
public Element getCharacterElement(int pos) {
  return ((StyledDocument) delegate).getCharacterElement(pos);
}

代码示例来源:origin: tmyroadctfig/swingx

/**
 * {@inheritDoc}
 */
@Override
public Element getCharacterElement(int pos) {
  return ((StyledDocument) delegate).getCharacterElement(pos);
}

代码示例来源:origin: org.swinglabs.swingx/swingx-all

/**
 * {@inheritDoc}
 */
@Override
public Element getCharacterElement(int pos) {
  return ((StyledDocument) delegate).getCharacterElement(pos);
}

代码示例来源:origin: net.sf.jt400/jt400

/**
Returns the element that represents the character that is at
a given offset within the document.

@param offset   The offset to the character.
@return         The element.
**/
  public synchronized Element getCharacterElement (int offset)
  {
    return document_.getCharacterElement (offset);
  }

代码示例来源:origin: org.netbeans.api/org-openide-text

public Element getCharacterElement(int pos) {
  return ((StyledDocument) original).getCharacterElement(pos);
}

代码示例来源:origin: stackoverflow.com

public AttributeSet getCharacterAttributes() {
  StyledDocument doc = getStyledDocument();
  Element run = doc.getCharacterElement(getCaretPosition());
  if (run != null) {
    return run.getAttributes();
  }
  return null;
}

代码示例来源:origin: stackoverflow.com

public AttributeSet getMyCharacterAttributes() {
  StyledDocument doc = parentTextPane.getStyledDocument();
  Element run = doc.getCharacterElement(parentTextPane.getSelectionStart());
  if (run != null) {
    return run.getAttributes();
  }
  return null;
}

代码示例来源:origin: stackoverflow.com

StyledDocument doc = (StyledDocument)textPane.getDocument();
Element element = doc.getCharacterElement(position);

Boolean isItalic = element.getAttributes().getAttribute(StyleConstants.Italic);

代码示例来源:origin: stackoverflow.com

StyledDocument doc = (StyledDocument) jTextpane.getDocument();
Style logicalStyle = doc.getLogicalStyle(jTextpane.getSelectionStart());
Element element = doc.getCharacterElement(start);
AttributeSet as = element.getAttributes();
Checking the Text,which is Bold and Italic

boolean isBold = StyleConstants.isBold(as) ? false : true;
boolean isItalic = StyleConstants.isItalic(as);
System.out.println("selected value is isItalic?"+isItalic);
System.out.println("selected value is isBold?"+isBold);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

private Element element(MouseEvent e) {
  JTextPane pane = (JTextPane)e.getSource();
  StyledDocument doc = pane.getStyledDocument();
  return doc.getCharacterElement(pane.viewToModel(e.getPoint()));
}
private void showMenu(MouseEvent e) {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

private Element element(MouseEvent e) {
  JTextPane pane = (JTextPane)e.getSource();
  StyledDocument doc = pane.getStyledDocument();
  return doc.getCharacterElement(pane.viewToModel(e.getPoint()));
}

代码示例来源:origin: otros-systems/otroslogviewer

private AttributeSet getStyleUnderCursor(MouseEvent e) {
  int i = textPane.viewToModel(e.getPoint());
  return textPane.getStyledDocument().getCharacterElement(i).getAttributes();
 }
}

代码示例来源:origin: net.imagej/imagej-ui-swing

private ActionListener getAction(final MouseEvent event) {
  Element e = document.getCharacterElement(textPane.viewToModel(event.getPoint()));
  ActionListener action = (ActionListener)e.getAttributes().getAttribute(ACTION_ATTRIBUTE);
  return action;
}

代码示例来源:origin: net.imagej/imagej-ui-swing

private String getLinkAt(final Point p) {
  final StyledDocument document = getStyledDocument();
  final Element e = document.getCharacterElement(viewToModel(p));
  return (String) e.getAttributes().getAttribute(LINK_ATTRIBUTE);
}

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

@Override
public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
  boolean refresh = true;
  final AttributeSet attr = ((StyledDocument) fb.getDocument()).getCharacterElement(offset).getAttributes();
  if (attr != null && attr.isDefined(StyleConstants.ComposedTextAttribute)) {
    refresh = false;
  }
  super.remove(fb, offset, length);
  if (refresh && length != 0 && fb.getDocument().getLength() != 0) {
    timer.restart();
  }
}

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

@Override
  public void mouseMoved(final MouseEvent e) {
    final StyledDocument doc = jTextPane.getStyledDocument();
    final Element characterElement = doc.getCharacterElement(jTextPane.viewToModel(e.getPoint()));
    final AttributeSet as = characterElement.getAttributes();
    final Object attr = as.getAttribute(ATTR_LINK);
    if (attr instanceof IAttributeAction) {
      jTextPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else {
      jTextPane.setCursor(Cursor.getDefaultCursor());
    }
  }
}

代码示例来源:origin: protegeproject/protege

private static Style getStyleAtPoint(JTextPane text, Point point) {
  int pos = text.viewToModel(point);
  StyledDocument doc = text.getStyledDocument();
  Element element = doc.getCharacterElement(pos);
  AttributeSet addtributes = element.getAttributes();
  return doc.getStyle((String) addtributes
      .getAttribute(StyleConstants.NameAttribute));
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

@Override
  public void mouseMoved(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
    AttributeSet as = elem.getAttributes();
    if (StyleConstants.isUnderline(as)) {
      pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else {
      pane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
  }
};

代码示例来源:origin: protegeproject/protege

@Override
  public void mouseMoved(MouseEvent e) {
    int pos = previewText.viewToModel(e.getPoint());
    StyledDocument doc = previewText.getStyledDocument();
    Element element = doc.getCharacterElement(pos);
    AttributeSet addtributes = element.getAttributes();
    Style style = doc.getStyle((String) addtributes
        .getAttribute(StyleConstants.NameAttribute));
    previewText.setToolTipText(
        "Click to change the " + style.getName() + " color");
  }
});

相关文章