Element child = line.getElement(i); AttributeSet as = child.getAttributes(); String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily); Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize); String key = fontFamily + fontSize; FontMetrics fm = fonts.computeIfAbsent(key, k -> {
private static AttributeSet adjustAttributes(AttributeSet as) { Collection<Object> attrs = new LinkedList<Object>(); for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) { Object key = e.nextElement(); Object value = as.getAttribute(key); if (value != Boolean.FALSE) { attrs.add(key); attrs.add(value); } } return AttributesUtilities.createImmutable(attrs.toArray()); }
Element child = line.getElement(i); AttributeSet as = child.getAttributes(); String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily); Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize); String key = fontFamily + 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; } }
public class MyStyleContext extends javax.swing.text.StyleContext { @Override public Font getFont(AttributeSet attr) { Font font = attr.getAttribute("MyFont"); if (font != null) return font; else return super.getFont(attr); } }
private static Color getColor(AttributeSet attr, Attribute key) { Object value = attr.getAttribute(key); if (value instanceof Color) { return (Color)value; } return null; }
private static int getInteger(AttributeSet attr, Attribute key) { Object value = attr.getAttribute(key); if (value instanceof Integer) { return (Integer)value; } return -1; }
private static boolean getBoolean(AttributeSet attr, Attribute key) { Object value = attr.getAttribute(key); if (value instanceof Boolean) { return (Boolean)value; } return false; } }
public void mouseClicked(MouseEvent e) { Element ele = doc.getCharacterElement(chatbox.viewToModel(e.getPoint())); AttributeSet as = ele.getAttributes(); ChatLinkListener fla = (ChatLinkListener)as.getAttribute("linkact"); if(fla != null) { fla.execute(); } }
private Optional<String> getExceptionNameAndMsgUnderCursor(MouseEvent e) { AttributeSet styleUnderCursor = getStyleUnderCursor(e); final String exceptionMessage = (String) styleUnderCursor.getAttribute("exceptionMessage"); return Optional.ofNullable(exceptionMessage); }
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; }
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 static Color getColoring(FontColorSettings fcs, String tokenName) { AttributeSet as = fcs.getTokenFontColors(tokenName); if (as != null) { return (Color) as.getAttribute(StyleConstants.Background); //NOI18N } return null; }
public static boolean isHiddenElement(DocumentElement de) { AttributeSet attrs = de.getAttributes(); String visible = (String) attrs.getAttribute(SVGConstants.SVG_VISIBILITY_ATTRIBUTE); if (visible != null && visible.equals(SVGConstants.CSS_HIDDEN_VALUE)) { return true; } return false; }
private boolean isUrlDeleted(Element e) { Boolean deleted = (Boolean) e.getAttributes().getAttribute(ChannelTextPane.Attribute.URL_DELETED); if (deleted == null) { return false; } return deleted; }
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); } }
@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 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)); }
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)); } } }