Java Code Examples for javax.swing.text.StyleConstants#isSubscript()

The following examples show how to use javax.swing.text.StyleConstants#isSubscript() . 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 vote down vote up
/**
    * 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: HTMLDocumentEditor.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
	JEditorPane editor = getEditor(ae);
	if (editor != null) {
		StyledEditorKit kit = getStyledEditorKit(editor);
		MutableAttributeSet attr = kit.getInputAttributes();
		boolean subscript = (StyleConstants.isSubscript(attr)) ? false
				: true;
		SimpleAttributeSet sas = new SimpleAttributeSet();
		StyleConstants.setSubscript(sas, subscript);
		setCharacterAttributes(editor, sas, false);
	}
}
 
Example 3
Source File: JEditorPaneHtmlMarkupProcessor.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected Map<Attribute,Object> getAttributes(AttributeSet attrSet) 
{
	Map<Attribute,Object> attrMap = new HashMap<Attribute,Object>();
	if (attrSet.isDefined(StyleConstants.FontFamily))
	{
		attrMap.put(
			TextAttribute.FAMILY,
			StyleConstants.getFontFamily(attrSet)
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Bold))
	{
		attrMap.put(
			TextAttribute.WEIGHT,
			StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Italic))
	{
		attrMap.put(
			TextAttribute.POSTURE,
			StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Underline))
	{
		attrMap.put(
			TextAttribute.UNDERLINE,
			StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null
			);
	}
				
	if (attrSet.isDefined(StyleConstants.StrikeThrough))
	{
		attrMap.put(
			TextAttribute.STRIKETHROUGH,
			StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null
			);
	}
				
	if (attrSet.isDefined(StyleConstants.FontSize))
	{
		attrMap.put(
			TextAttribute.SIZE,
			StyleConstants.getFontSize(attrSet)
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Foreground))
	{
		attrMap.put(
			TextAttribute.FOREGROUND,
			StyleConstants.getForeground(attrSet)
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Background))
	{
		attrMap.put(
			TextAttribute.BACKGROUND,
			StyleConstants.getBackground(attrSet)
			);
	}
	
	//FIXME: why StyleConstants.isSuperscript(attrSet) does return false
	if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet))
	{
		attrMap.put(
			TextAttribute.SUPERSCRIPT,
			TextAttribute.SUPERSCRIPT_SUPER
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet))
	{
		attrMap.put(
			TextAttribute.SUPERSCRIPT,
			TextAttribute.SUPERSCRIPT_SUB
			);
	}
				
	return attrMap;
}
 
Example 4
Source File: JEditorPaneMarkupProcessor.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 
 */
protected Map<Attribute,Object> getAttributes(AttributeSet attrSet) 
{
	Map<Attribute,Object> attrMap = new HashMap<Attribute,Object>();
	if (attrSet.isDefined(StyleConstants.FontFamily))
	{
		attrMap.put(
			TextAttribute.FAMILY,
			StyleConstants.getFontFamily(attrSet)
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Bold))
	{
		attrMap.put(
			TextAttribute.WEIGHT,
			StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Italic))
	{
		attrMap.put(
			TextAttribute.POSTURE,
			StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Underline))
	{
		attrMap.put(
			TextAttribute.UNDERLINE,
			StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null
			);
	}
				
	if (attrSet.isDefined(StyleConstants.StrikeThrough))
	{
		attrMap.put(
			TextAttribute.STRIKETHROUGH,
			StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null
			);
	}
				
	if (attrSet.isDefined(StyleConstants.FontSize))
	{
		attrMap.put(
			TextAttribute.SIZE,
			StyleConstants.getFontSize(attrSet)
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Foreground))
	{
		attrMap.put(
			TextAttribute.FOREGROUND,
			StyleConstants.getForeground(attrSet)
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Background))
	{
		attrMap.put(
			TextAttribute.BACKGROUND,
			StyleConstants.getBackground(attrSet)
			);
	}
	
	//FIXME: why StyleConstants.isSuperscript(attrSet) does return false
	if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet))
	{
		attrMap.put(
			TextAttribute.SUPERSCRIPT,
			TextAttribute.SUPERSCRIPT_SUPER
			);
	}
				
	if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet))
	{
		attrMap.put(
			TextAttribute.SUPERSCRIPT,
			TextAttribute.SUPERSCRIPT_SUB
			);
	}
				
	return attrMap;
}