FileDocCategorySizeDatePackage
BasicTextAreaUI.javaAPI DocJava SE 6 API11701Tue Jun 10 00:26:48 BST 2008javax.swing.plaf.basic

BasicTextAreaUI

public class BasicTextAreaUI extends BasicTextUI
Provides the look and feel for a plain text editor. In this implementation the default UI is extended to act as a simple view factory.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

author
Timothy Prinzing
version
1.75 04/20/06

Fields Summary
Constructors Summary
public BasicTextAreaUI()
Constructs a new BasicTextAreaUI object.

	super();
    
Methods Summary
public javax.swing.text.Viewcreate(javax.swing.text.Element elem)
Creates the view for an element. Returns a WrappedPlainView or PlainView.

param
elem the element
return
the view

	Document doc = elem.getDocument();
	Object i18nFlag = doc.getProperty("i18n"/*AbstractDocument.I18NProperty*/);
	if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
	    // build a view that support bidi
	    return createI18N(elem);
	} else {
	    JTextComponent c = getComponent();
	    if (c instanceof JTextArea) {
		JTextArea area = (JTextArea) c;
		View v;
		if (area.getLineWrap()) {
		    v = new WrappedPlainView(elem, area.getWrapStyleWord());
		} else {
		    v = new PlainView(elem);
		}
		return v;
	    }
	}
	return null;
    
javax.swing.text.ViewcreateI18N(javax.swing.text.Element elem)

	String kind = elem.getName();
	if (kind != null) {
	    if (kind.equals(AbstractDocument.ContentElementName)) {
		return new PlainParagraph(elem);
	    } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
		return new BoxView(elem, View.Y_AXIS);
	    }
	}
	return null;
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent ta)
Creates a UI for a JTextArea.

param
ta a text area
return
the UI

        return new BasicTextAreaUI();
    
public intgetBaseline(javax.swing.JComponent c, int width, int height)
Returns the baseline.

throws
NullPointerException {@inheritDoc}
throws
IllegalArgumentException {@inheritDoc}
see
javax.swing.JComponent#getBaseline(int, int)
since
1.6

        super.getBaseline(c, width, height);
	Object i18nFlag = ((JTextComponent)c).getDocument().
                                              getProperty("i18n");
        Insets insets = c.getInsets();
	if (Boolean.TRUE.equals(i18nFlag)) {
            View rootView = getRootView((JTextComponent)c);
            if (rootView.getViewCount() > 0) {
                height = height - insets.top - insets.bottom;
                int baseline = insets.top;
                int fieldBaseline = BasicHTML.getBaseline(
                        rootView.getView(0), width - insets.left -
                        insets.right, height);
                if (fieldBaseline < 0) {
                    return -1;
                }
                return baseline + fieldBaseline;
            }
            return -1;
        }
        FontMetrics fm = c.getFontMetrics(c.getFont());
        return insets.top + fm.getAscent();
    
public java.awt.Component$BaselineResizeBehaviorgetBaselineResizeBehavior(javax.swing.JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.

throws
NullPointerException {@inheritDoc}
see
javax.swing.JComponent#getBaseline(int, int)
since
1.6

        super.getBaselineResizeBehavior(c);
        return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
    
public java.awt.DimensiongetMinimumSize(javax.swing.JComponent c)
The method is overridden to take into account caret width.

param
c the editor component
return
the minimum size
throws
IllegalArgumentException if invalid value is passed
since
1.5

        return super.getMinimumSize(c);
        //the fix for 4785160 is undone
    
public java.awt.DimensiongetPreferredSize(javax.swing.JComponent c)
The method is overridden to take into account caret width.

param
c the editor component
return
the preferred size
throws
IllegalArgumentException if invalid value is passed
since
1.5

                    
        return super.getPreferredSize(c);                         
        //the fix for 4785160 is undone
    
protected java.lang.StringgetPropertyPrefix()
Fetches the name used as a key to look up properties through the UIManager. This is used as a prefix to all the standard text properties.

return
the name ("TextArea")

	return "TextArea";
    
protected voidinstallDefaults()

        super.installDefaults();
        //the fix for 4785160 is undone
    
protected voidpropertyChange(java.beans.PropertyChangeEvent evt)
This method gets called when a bound property is changed on the associated JTextComponent. This is a hook which UI implementations may change to reflect how the UI displays bound properties of JTextComponent subclasses. This is implemented to rebuild the View when the WrapLine or the WrapStyleWord property changes.

param
evt the property change event

        super.propertyChange(evt);
	if (evt.getPropertyName().equals("lineWrap") ||
	    evt.getPropertyName().equals("wrapStyleWord") ||
		evt.getPropertyName().equals("tabSize")) {
	    // rebuild the view
	    modelChanged();
	} else if ("editable".equals(evt.getPropertyName())) {
	    updateFocusTraversalKeys();
	}