public void focusGained(FocusEvent fe) { textComponent = (JTextComponent) fe.getSource(); attributeSet = textComponent.getDocument().getDefaultRootElement().getAttributes(); } };
for (int i = 0; i < line.getElementCount(); i++) { Element child = line.getElement(i); AttributeSet as = child.getAttributes(); String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily); Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize);
public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent) ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument) tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
AttributeSet as = child.getAttributes(); String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily); Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize);
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; } }
private long getTimeAgo(Element element) { Long timestamp = (Long)element.getAttributes().getAttribute(Attribute.TIMESTAMP); if (timestamp != null) { return System.currentTimeMillis() - timestamp; } return Long.MAX_VALUE; }
/** * Gets the id attached to the message. * * @param element * @return The ID element, or null if none was found */ public static String getIdFromElement(Element element) { if (element != null) { return (String)element.getAttributes().getAttribute(Attribute.ID); } return null; }
/** * Checks if the given line contains an attribute indicating that the line * is already deleted. * * @param line The element representing this line * @return */ private boolean isLineDeleted(Element line) { return line.getAttributes().containsAttribute(Attribute.DELETED_LINE, true); }
private boolean isEndtag(final Element elem) { final AttributeSet attributes = elem.getAttributes(); final Object endTag = attributes.getAttribute(HTML.Attribute.ENDTAG); final boolean isEndtag = (endTag instanceof String) && ((String) endTag).equals("true"); return isEndtag; }
private boolean isUrlDeleted(Element e) { Boolean deleted = (Boolean) e.getAttributes().getAttribute(ChannelTextPane.Attribute.URL_DELETED); if (deleted == null) { return false; } return deleted; }
public void focusGained(FocusEvent fe) { textComponent = (JTextComponent) fe.getSource(); attributeSet = textComponent.getDocument().getDefaultRootElement().getAttributes(); } };
public void focusGained(FocusEvent fe) { textComponent = (JTextComponent) fe.getSource(); attributeSet = textComponent.getDocument().getDefaultRootElement().getAttributes(); } };
public void focusGained(FocusEvent fe) { textComponent = (JTextComponent)fe.getSource(); attributeSet = textComponent.getDocument().getDefaultRootElement().getAttributes(); } };
/** 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; }
@Override protected void startTag(Element elem) throws IOException, BadLocationException { if (bodyStarted) { super.startTag(elem); } if (HTML.Tag.BODY == elem.getAttributes().getAttribute(StyleConstants.NameAttribute)) { bodyStarted = true; } }
private AttributeSet getStyleUnderCursor(MouseEvent e) { int i = textPane.viewToModel(e.getPoint()); return textPane.getStyledDocument().getCharacterElement(i).getAttributes(); } }
public static void getImageIds(Element element, Set<Long> ids) { Long id = (Long)element.getAttributes().getAttribute(ChannelTextPane.Attribute.IMAGE_ID); if (id != null) { ids.add(id); } for (int i=0; i<element.getElementCount(); i++) { getImageIds(element.getElement(i), ids); } }
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) { 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"); } });
private void clearImages(Element element) { Long imageId = (Long)element.getAttributes().getAttribute(Attribute.IMAGE_ID); if (imageId != null) { kit.clearImage(imageId); } if (!element.isLeaf()) { for (int i=0; i<element.getElementCount(); i++) { clearImages(element.getElement(i)); } } }