List of utility methods to do Swing Text Style
Style | createStyle(String logicalName) create Style Style result = styleContext.addStyle(logicalName, null);
return result;
|
Boolean | getBooleanValue(Element element, Object constant) Checks whether an Element has a boolean property AttributeSet attributes = element.getAttributes();
return (attributes.getAttribute(constant) != null
&& ((Boolean) attributes.getAttribute(constant)).booleanValue());
|
Integer | getIntegerValue(Element element, Object constant) Gets a integer value of an attribute (e.g. AttributeSet attributes = element.getAttributes(); Object obj = attributes.getAttribute(constant); if (obj == null) return null; return (Integer) obj; |
int | getNextVisualPosition(final View v, final int pos, final Position.Bias b0, final int direction, final Position.Bias[] biasRet) get Next Visual Position boolean toWest = (direction == SwingConstants.WEST); Document document = v.getDocument(); int length = document.getLength(); if (!isBidirectional(document)) { return getTrivialVisualPosition(toWest, pos, b0, length, biasRet, true); Element bidiRoot = ((AbstractDocument) document).getBidiRootElement(); Element elem = getElementByPosition(bidiRoot, pos); ... |
boolean | hasDifferentCharacterAttributes(AttributeSet style, AttributeSet base) has Different Character Attributes return (StyleConstants.isBold(style) != StyleConstants.isBold(base))
|| (StyleConstants.isItalic(style) != StyleConstants.isItalic(base))
|| (StyleConstants.isUnderline(style) != StyleConstants.isUnderline(base))
|| (StyleConstants.getFontSize(style) != StyleConstants.getFontSize(base))
|| (!StyleConstants.getForeground(style).equals(StyleConstants.getForeground(base)));
|
boolean | isCentered(AttributeSet attributes) is Centered if (attributes != null) { if (attributes.getAttribute(StyleConstants.Alignment) != null) { Integer value = (Integer) attributes.getAttribute(StyleConstants.Alignment); if (value == StyleConstants.ALIGN_CENTER) { return true; return false; |
boolean | isLTR(final int level) is LTR return (level & 1) == 0;
|
void | overrideStyle(Style originalStyle, Style newStyle) override Style overrideStyleElement(originalStyle, newStyle, StyleConstants.FontFamily); overrideStyleElement(originalStyle, newStyle, StyleConstants.Family); overrideStyleElement(originalStyle, newStyle, StyleConstants.FontSize); overrideStyleElement(originalStyle, newStyle, StyleConstants.Size); overrideStyleElement(originalStyle, newStyle, StyleConstants.Foreground); overrideStyleElement(originalStyle, newStyle, StyleConstants.Background); overrideStyleElement(originalStyle, newStyle, StyleConstants.Bold); overrideStyleElement(originalStyle, newStyle, StyleConstants.Italic); ... |
AttributeSet | resolveAttributes(AttributeSet style) resolve Attributes SimpleAttributeSet set = new SimpleAttributeSet(); if (style != null) { Enumeration<?> names = style.getAttributeNames(); Object value; Object key; while (names.hasMoreElements()) { key = names.nextElement(); value = style.getAttribute(key); ... |
String | unRTF(String s) Extract text from RTF if (s == null) return null; DefaultStyledDocument doc = new DefaultStyledDocument(); RTFEditorKit kit = new RTFEditorKit(); try { kit.read(new StringReader(s), doc, 0); } catch (Exception ex) { throw new RuntimeException(ex); ... |