Java Code Examples for javax.swing.text.StyleConstants#getFontFamily()
The following examples show how to use
javax.swing.text.StyleConstants#getFontFamily() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserDisplayer.java From netbeans with Apache License 2.0 | 6 votes |
/** * Gets the font from an attribute set. This is * implemented to try and fetch a cached font * for the given AttributeSet, and if that fails * the font features are resolved and the * font is fetched from the low-level font cache. * Font's are cached in the StyleSheet of a document * * @param attr the attribute set * @return the font */ private Font getAttributeSetFont(AttributeSet attr) { // PENDING(prinz) add cache behavior int style = Font.PLAIN; if (StyleConstants.isBold(attr)) { style |= Font.BOLD; } if (StyleConstants.isItalic(attr)) { style |= Font.ITALIC; } String family = StyleConstants.getFontFamily(attr); int size = StyleConstants.getFontSize(attr); /** * if either superscript or subscript is * is set, we need to reduce the font size * by 2. */ if (StyleConstants.isSuperscript(attr) || StyleConstants.isSubscript(attr)) { size -= 2; } // fonts are cached in the StyleSheet so use that return doc.getStyleSheet().getFont(family, style, size); }
Example 2
Source File: XMLTextComponentHighlighter.java From pumpernickel with MIT License | 5 votes |
/** * Create a new JavaTextComponentHighlighter. * * @param jtc * the text component to apply formatting to. */ public XMLTextComponentHighlighter(JTextComponent jtc) { super(jtc); jtc.putClientProperty("caretWidth", new Integer(3)); jtc.getCaret().setBlinkRate(500); initializeAttributes(); Font defaultFont = new Font( StyleConstants.getFontFamily(defaultAttributes), 0, StyleConstants.getFontSize(defaultAttributes)); jtc.setFont(defaultFont); }
Example 3
Source File: JavaTextComponentHighlighter.java From pumpernickel with MIT License | 5 votes |
/** * Create a new JavaTextComponentHighlighter. * * @param jtc * the text component to apply formatting to. */ public JavaTextComponentHighlighter(JTextComponent jtc) { super(jtc); jtc.putClientProperty("caretWidth", new Integer(3)); jtc.getCaret().setBlinkRate(500); initializeAttributes(); Font defaultFont = new Font( StyleConstants.getFontFamily(defaultAttributes), 0, StyleConstants.getFontSize(defaultAttributes)); jtc.setFont(defaultFont); }
Example 4
Source File: FormattedTextHelper.java From PolyGlot with MIT License | 5 votes |
/** * Recursing method implementing functionality of storageFormat() * @param e element to be cycled through * @param pane top parent JTextPane * @return string format value of current node and its children * @throws BadLocationException if unable to create string format */ private static String storeFormatRecurse(Element e, JTextPane pane) throws Exception { String ret = ""; int ec = e.getElementCount(); if (ec == 0) { // if more media addable in the future, this is where to process it... // hard coded values because they're hard coded in Java. Eh. if (e.getAttributes().getAttribute("$ename") != null && e.getAttributes().getAttribute("$ename").equals("icon")) { if (e.getAttributes().getAttribute(PGTUtil.IMAGE_ID_ATTRIBUTE) == null) { throw new Exception("ID For image not stored. Unable to store section."); } ret += "<img src=\"" + e.getAttributes().getAttribute(PGTUtil.IMAGE_ID_ATTRIBUTE) + "\">"; } else { int start = e.getStartOffset(); int len = e.getEndOffset() - start; if (start < pane.getDocument().getLength()) { AttributeSet a = e.getAttributes(); String font = StyleConstants.getFontFamily(a); String fontColor = colorToText(StyleConstants.getForeground(a)); int fontSize = StyleConstants.getFontSize(a); ret += "<font face=\"" + font + "\"" + "size=\"" + fontSize + "\"" + "color=\"" + fontColor + "\"" + ">"; ret += pane.getDocument().getText(start, len); ret += "</font>"; } } } else { for (int i = 0; i < ec; i++) { ret += storeFormatRecurse(e.getElement(i), pane); } } return ret; }
Example 5
Source File: BrowserDisplayer.java From netbeans with Apache License 2.0 | 4 votes |
/** * Returns the text Font family name of the activator text */ public String getTextFontFamily() { return StyleConstants.getFontFamily(textAttribs); }
Example 6
Source File: TextPaneAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public String getFontName() { AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO); return StyleConstants.getFontFamily(attrSet); }