FileDocCategorySizeDatePackage
CommentView.javaAPI DocJava SE 5 API3233Fri Aug 26 14:58:18 BST 2005javax.swing.text.html

CommentView

public class CommentView extends HiddenTagView
CommentView subclasses HiddenTagView to contain a JTextArea showing a comment. When the textarea is edited the comment is reset. As this inherits from EditableView if the JTextComponent is not editable, the textarea will not be visible.
author
Scott Violet
version
1.13, 03/05/04

Fields Summary
static final Border
CBorder
static final int
commentPadding
static final int
commentPaddingD
Constructors Summary
CommentView(Element e)

	super(e);
    
Methods Summary
void_updateModelFromText()
This is subclassed to put the text on the Comment attribute of the Element's AttributeSet.

	JTextComponent textC = getTextComponent();
	Document doc = getDocument();
	if (textC != null && doc != null) {
	    String text = textC.getText();
	    SimpleAttributeSet sas = new SimpleAttributeSet();
	    isSettingAttributes = true;
	    try {
		sas.addAttribute(HTML.Attribute.COMMENT, text);
		((StyledDocument)doc).setCharacterAttributes
		    (getStartOffset(), getEndOffset() -
		     getStartOffset(), sas, false);
	    }
	    finally {
		isSettingAttributes = false;
	    }
	}
    
protected java.awt.ComponentcreateComponent()

        Container host = getContainer();
        if (host != null && !((JTextComponent)host).isEditable()) {
            return null;
        }
	JTextArea ta = new JTextArea(getRepresentedText());
	Document doc = getDocument();
	Font font;
	if (doc instanceof StyledDocument) {
	    font = ((StyledDocument)doc).getFont(getAttributes());
	    ta.setFont(font);
	}
	else {
	    font = ta.getFont();
	}
	updateYAlign(font);
	ta.setBorder(CBorder);
	ta.getDocument().addDocumentListener(this);
	ta.setFocusable(isVisible());
	return ta;
    
java.lang.StringgetRepresentedText()

	AttributeSet as = getElement().getAttributes();
	if (as != null) {
	    Object comment = as.getAttribute(HTML.Attribute.COMMENT);
	    if (comment instanceof String) {
		return (String)comment;
	    }
	}
	return "";
    
javax.swing.text.JTextComponentgetTextComponent()

	return (JTextComponent)getComponent();
    
voidresetBorder()