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.
| Method from javax.swing.plaf.basic.BasicTextAreaUI Detail: |
public View create(Element elem) {
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;
}
Creates the view for an element. Returns a WrappedPlainView or
PlainView. |
View createI18N(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 ComponentUI createUI(JComponent ta) {
return new BasicTextAreaUI();
}
Creates a UI for a JTextArea. |
public int getBaseline(JComponent c,
int width,
int height) {
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 Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) {
super.getBaselineResizeBehavior(c);
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
Returns an enum indicating how the baseline of the component
changes as the size changes. |
public Dimension getMinimumSize(JComponent c) {
return super.getMinimumSize(c);
//the fix for 4785160 is undone
}
The method is overridden to take into account caret width. |
public Dimension getPreferredSize(JComponent c) {
return super.getPreferredSize(c);
//the fix for 4785160 is undone
}
The method is overridden to take into account caret width. |
protected String getPropertyPrefix() {
return "TextArea";
}
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. |
protected void installDefaults() {
super.installDefaults();
//the fix for 4785160 is undone
}
|
protected void propertyChange(PropertyChangeEvent evt) {
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();
}
}
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. |