/** Get element name if defined */ public String getName() { if (attrs.isDefined(ElementNameAttribute)) { return (String) attrs.getAttribute(ElementNameAttribute); } return null; }
/** Get element name if defined */ public String getName() { if (attrs.isDefined(ElementNameAttribute)) { return (String)attrs.getAttribute(ElementNameAttribute); } return null; }
@Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { super.insertString(fb, offset, string, attr); if (attr != null && attr.isDefined(StyleConstants.ComposedTextAttribute)) { // ignore } else { SwingUtilities.invokeLater(this::refreshPane); } }
private boolean noMatchForTagInAttributes(AttributeSet attr, HTML.Tag t, Object tagValue) { if (attr != null && attr.isDefined(t)) { Object newValue = attr.getAttribute(t); if ((tagValue == null) ? (newValue == null) : (newValue != null && tagValue.equals(newValue))) { return false; } } return true; }
/** Method tests whether the image within a link */ boolean isLink() { AttributeSet anchorAttr = (AttributeSet)fElement.getAttributes().getAttribute(HTML.Tag.A); if(anchorAttr != null) { return anchorAttr.isDefined(HTML.Attribute.HREF); } return false; }
if(attr.isDefined(name))
/** * Convenience method for getting an integer attribute from the elements * AttributeSet. */ private int getIntAttr(HTML.Attribute name, int deflt) { AttributeSet attr = getElement().getAttributes(); if (attr.isDefined(name)) { // does not check parents! int i; String val = (String) attr.getAttribute(name); if (val == null) { i = deflt; } else { try { i = Math.max(0, Integer.parseInt(val)); } catch (NumberFormatException x) { i = deflt; } } return i; } else { return deflt; } }
if (anchorAttr != null && anchorAttr.isDefined (HTML.Attribute.HREF)) { synchronized(this) {
/** * Convenience method for getting an integer attribute from the elements AttributeSet. */ private int getIntAttr(HTML.Attribute name, int deflt) { AttributeSet attr = getElement().getAttributes(); if (attr.isDefined(name)) { // does not check parents! int i; String val = (String) attr.getAttribute(name); if (val == null) { i = deflt; } else { try { i = Math.max(0, Integer.parseInt(val)); } catch (NumberFormatException x) { i = deflt; } } return i; } else return deflt; }
private static String getElemTextWithId(BaseDocument doc, DocumentElement de, String id) throws BadLocationException { String elemText; int startOffset = de.getStartOffset(); if (de.getAttributes().isDefined(SVGConstants.SVG_ID_ATTRIBUTE)) { elemText = doc.getText(startOffset, de.getEndOffset() - startOffset + 1); } else { String tag = de.getName(); startOffset += 1 + tag.length(); StringBuilder sb = new StringBuilder("<"); //NOI18N sb.append(tag); sb.append(' '); injectId(sb, id); sb.append(doc.getText(startOffset, de.getEndOffset() - startOffset + 1)); elemText = sb.toString(); } return elemText; }
/** * Gets the first element containing the given key in it's attributes, or * null if it wasn't found. * * @param parent The Element whose subelements are searched * @param key The key of the attributes the searched element should have * @return The found Element */ private static Element getElementContainingAttributeKey(Element parent, Object key) { for (int i = 0; i < parent.getElementCount(); i++) { Element element = parent.getElement(i); if (element.getAttributes().isDefined(key)) { return element; } } return null; }
@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 replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { UIThreadsUtil.mustBeSwingThread(); if (attrs != null) { ((Document3) fb.getDocument()).textBeingComposed = attrs .isDefined(StyleConstants.ComposedTextAttribute); } if (isPossible(fb.getDocument(), offset, length)) { super.replace(fb, offset, length, text, attrs); } }
@Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { UIThreadsUtil.mustBeSwingThread(); if (attr != null) { ((Document3) fb.getDocument()).textBeingComposed = attr .isDefined(StyleConstants.ComposedTextAttribute); } if (isPossible(fb.getDocument(), offset, 0)) { super.insertString(fb, offset, string, attr); } }
/** * Fetch a reasonable location to start scanning * given the desired start location. This allows * for adjustments needed to accomodate multiline * comments. */ public int getScannerStart( int p ) { Element elem = getDefaultRootElement(); int lineNum = elem.getElementIndex( p ); Element line = elem.getElement( lineNum ); AttributeSet a = line.getAttributes(); while( a.isDefined( CommentAttribute ) && lineNum > 0 ) { lineNum -= 1; line = elem.getElement( lineNum ); a = line.getAttributes(); } return line.getStartOffset(); }
/** * Fetch a reasonable location to start scanning * given the desired start location. This allows * for adjustments needed to accomodate multiline * comments. */ public int getScannerStart( int p ) { Element elem = getDefaultRootElement(); int lineNum = elem.getElementIndex( p ); Element line = elem.getElement( lineNum ); AttributeSet a = line.getAttributes(); while( a.isDefined( CommentAttribute ) && lineNum > 0 ) { lineNum -= 1; line = elem.getElement( lineNum ); a = line.getAttributes(); } return line.getStartOffset(); }
if (anchorAttr != null && anchorAttr.isDefined(HTML.Attribute.HREF)) { synchronized (this) { state |= LINK_FLAG;
private void blockURLTyping(MutableAttributeSet inputAttr, int dot, int mark) { StyledDocument doc = getStyledDocument(); int begin = (dot < mark) ? dot - 1 : mark - 1; if(begin >= 0) { Element dotEl = doc.getCharacterElement(begin); Element markEl = doc.getCharacterElement((dot < mark) ? mark : dot); AttributeSet dotAttr = dotEl.getAttributes(); AttributeSet markAttr = markEl.getAttributes(); if(dotAttr.isDefined(HTML.Attribute.HREF)) // Ensure atleast one of them isn't null { if(dotAttr.getAttribute(HTML.Attribute.HREF) == markAttr.getAttribute(HTML.Attribute.HREF)) { inputAttr.addAttribute(HTML.Attribute.HREF, dotAttr.getAttribute(HTML.Attribute.HREF)); inputAttr.addAttribute(StyleConstants.Foreground, Color.BLUE); inputAttr.addAttribute(StyleConstants.Underline, true); return; } } } if(inputAttr.isDefined(HTML.Attribute.HREF)) // In all other cases => remove { inputAttr.removeAttribute(HTML.Attribute.HREF); inputAttr.removeAttribute(StyleConstants.Foreground); inputAttr.removeAttribute(StyleConstants.Underline); } }
public void insertUpdate(final DocumentEvent de) { final Document d; //Runnable r; d = de.getDocument(); final int i1, i2; final int l; i1 = de.getOffset(); i2 = de.getLength(); l = d.getLength(); if (l == i1 + i2) { Element e1 = d.getDefaultRootElement(); Element e2 = e1.getElement(e1.getElementIndex(i1)); while (!e2.isLeaf()) e2 = e2.getElement(e2.getElementIndex(i1)); final Element e3 = e2; AttributeSet as = e3.getAttributes(); if (as.isDefined(tubeSortieFenetre)) if (getCaretPosition() != l) { setCaretPosition(l); } } }