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; } }
/** * {@inheritDoc} */ public Element getCharacterElement(int pos) { return ((StyledDocument) delegate).getCharacterElement(pos); }
/** * {@inheritDoc} */ @Override public Element getCharacterElement(int pos) { return ((StyledDocument) delegate).getCharacterElement(pos); }
/** * {@inheritDoc} */ @Override public Element getCharacterElement(int pos) { return ((StyledDocument) delegate).getCharacterElement(pos); }
/** 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); }
public Element getCharacterElement(int pos) { return ((StyledDocument) original).getCharacterElement(pos); }
public AttributeSet getCharacterAttributes() { StyledDocument doc = getStyledDocument(); Element run = doc.getCharacterElement(getCaretPosition()); if (run != null) { return run.getAttributes(); } return null; }
public AttributeSet getMyCharacterAttributes() { StyledDocument doc = parentTextPane.getStyledDocument(); Element run = doc.getCharacterElement(parentTextPane.getSelectionStart()); if (run != null) { return run.getAttributes(); } return null; }
StyledDocument doc = (StyledDocument)textPane.getDocument(); Element element = doc.getCharacterElement(position); Boolean isItalic = element.getAttributes().getAttribute(StyleConstants.Italic);
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);
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) {
private Element element(MouseEvent e) { JTextPane pane = (JTextPane)e.getSource(); StyledDocument doc = pane.getStyledDocument(); return doc.getCharacterElement(pane.viewToModel(e.getPoint())); }
private AttributeSet getStyleUnderCursor(MouseEvent e) { int i = textPane.viewToModel(e.getPoint()); return textPane.getStyledDocument().getCharacterElement(i).getAttributes(); } }
private ActionListener getAction(final MouseEvent event) { Element e = document.getCharacterElement(textPane.viewToModel(event.getPoint())); ActionListener action = (ActionListener)e.getAttributes().getAttribute(ACTION_ATTRIBUTE); return action; }
private String getLinkAt(final Point p) { final StyledDocument document = getStyledDocument(); final Element e = document.getCharacterElement(viewToModel(p)); return (String) e.getAttributes().getAttribute(LINK_ATTRIBUTE); }
@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(); } }
@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()); } } }
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)); }
@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)); } } };
@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"); } });