public abstract class BasicTextUI extends TextUI implements ViewFactory
 文本元素的外观和感觉的基础。 这提供了基本的编辑器视图和控制器服务,在为JTextComponent的JTextComponent创建外观时可能很有用。 
 大多数状态作为绑定属性保存在关联的JTextComponent中,UI会为各种属性安装默认值。 此默认值将为所有属性安装。 通常,LAF实现将会更多。 至少,LAF通常会安装密钥绑定。 
 此类还提供了一些支持并发如果Document与相关的JTextComponent是的子类AbstractDocument 。 访问视图(或视图层次结构)在任何使模型突变的线程与Swing事件线程(预期呈现,执行模型/视图坐标转换等)之间进行序列化。 对根视图的任何访问应该首先在AbstractDocument上获取一个读锁,并释放该finally锁中的锁。 
 一个重要的定义方法是getPropertyPrefix()方法,该方法用作从UIManager获取默认值的密钥的基础。 字符串应该反映TextUI的类型(例如TextField,TextArea等),而不包含名称的特定LAF部分(例如Metal,Motif等)。 
要建立模型视图,可以采用以下策略之一。
create(javax.swing.text.Element)的方法。  警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已被添加到java.beans包中。 请参阅XMLEncoder 。 
| Modifier and Type | Class and Description | 
|---|---|
| static class  | BasicTextUI.BasicCaret | 
| static class  | BasicTextUI.BasicHighlighter | 
| Constructor and Description | 
|---|
| BasicTextUI()
              创建一个新的UI。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| View | create(Element elem)
              创建元素的视图。 
             | 
| View | create(Element elem, int p0, int p1)
              创建元素的视图。 
             | 
| protected Caret | createCaret()
              创建用于插入符号的对象。 
             | 
| protected Highlighter | createHighlighter()
              创建用于添加高光的对象。 
             | 
| protected Keymap | createKeymap()
              创建要用于文本组件的键盘映射,并在其中安装任何必需的绑定。 
             | 
| void | damageRange(JTextComponent tc, int p0, int p1)
              导致部分视图对模型的给定部分负责。 
             | 
| void | damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias)
              导致部分视图对模型的给定部分负责。 
             | 
| protected JTextComponent | getComponent()
              获取与此UI实现相关联的文本组件。 
             | 
| EditorKit | getEditorKit(JTextComponent tc)
              获取用户界面的EditorKit。 
             | 
| protected String | getKeymapName()
              获取此UI将默认安装/使用的键盘映射的名称。 
             | 
| Dimension | getMaximumSize(JComponent c)
              获取编辑器组件的最大大小。 
             | 
| Dimension | getMinimumSize(JComponent c)
              获取编辑器组件的最小大小。 
             | 
| int | getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet)
              提供一种方法来确定可能放置插入符号的下一个视觉表示的模型位置。 
             | 
| Dimension | getPreferredSize(JComponent c)
              获取编辑器组件的首选大小。 
             | 
| protected abstract String | getPropertyPrefix()
              获取通过UIManager查找属性的键。 
             | 
| View | getRootView(JTextComponent tc)
              通过分配相关的文本组件获取视图(即 
             | 
| String | getToolTipText(JTextComponent t, Point pt)
              返回要用作传入位置的工具提示的字符串。 
             | 
| protected Rectangle | getVisibleEditorRect()
              获取分配给根视图。 
             | 
| protected void | installDefaults()
              初始化组件属性,如字体,前景,背景,插入符号颜色,选择颜色,选定的文本颜色,禁用的文本颜色和边框颜色。 
             | 
| protected void | installKeyboardActions() | 
| protected void | installListeners()
              安装用户界面的侦听器。 
             | 
| void | installUI(JComponent c)
              安装组件的UI。 
             | 
| protected void | modelChanged()
              标志模型更改。 
             | 
| Rectangle | modelToView(JTextComponent tc, int pos)
              将模型中的给定位置转换为视图坐标系中的一个位置。 
             | 
| Rectangle | modelToView(JTextComponent tc, int pos, Position.Bias bias)
              将模型中的给定位置转换为视图坐标系中的一个位置。 
             | 
| void | paint(Graphics g, JComponent c)
              绘制界面。 
             | 
| protected void | paintBackground(Graphics g)
              绘制视图的背景。 
             | 
| protected void | paintSafely(Graphics g)
              保证界面安全,保证模型不会从此线程的视图中改变。 
             | 
| protected void | propertyChange(PropertyChangeEvent evt)
              当在关联的JTextComponent上更改bound属性时,将调用此方法。 
             | 
| protected void | setView(View v)
              设置视图层次结构的当前根,并调用invalidate()。 
             | 
| protected void | uninstallDefaults()
              将未明确覆盖的组件属性设置为 
              null。 | 
| protected void | uninstallKeyboardActions() | 
| protected void | uninstallListeners()
              卸载UI的监听器。 
             | 
| void | uninstallUI(JComponent c)
              卸载组件的UI。 
             | 
| void | update(Graphics g, JComponent c)
              超级油漆以不可控制的方式涂抹背景(即 
             | 
| int | viewToModel(JTextComponent tc, Point pt)
              将视图坐标系中的给定位置转换为模型中最近的代表位置。 
             | 
| int | viewToModel(JTextComponent tc, Point pt, Position.Bias[] biasReturn)
              将视图坐标系中的给定位置转换为模型中最近的代表位置。 
             | 
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehaviorprotected Caret createCaret()
protected Highlighter createHighlighter()
protected String getKeymapName()
protected Keymap createKeymap()
 用于创建密钥映射的绑定集由UIManager使用通过组合getPropertyPrefix()方法和字符串.keyBindings形成的密钥来.keyBindings 。 预计类型为JTextComponent.KeyBinding[] 。 
getKeymapName() , JTextComponent 
           protected void propertyChange(PropertyChangeEvent evt)
evt - 财产变更事件 
           protected abstract String getPropertyPrefix()
protected void installDefaults()
protected void uninstallDefaults()
null 。 
           如果某个属性的当前值不是UIResource,则该属性被视为被UIResource 。 
          protected void installListeners()
protected void uninstallListeners()
protected void installKeyboardActions()
protected void uninstallKeyboardActions()
protected void paintBackground(Graphics g)
g - 图形上下文 
           protected final JTextComponent getComponent()
protected void modelChanged()
protected final void setView(View v)
v - 根视图 
           protected void paintSafely(Graphics g)
g - 图形上下文 
           public void installUI(JComponent c)
null或null的实例时才会设置 。 installUI在 
            ComponentUI 
           c - 编辑器组件 
           ComponentUI.installUI(javax.swing.JComponent) 
           public void uninstallUI(JComponent c)
uninstallUI在 
            ComponentUI 
           c - 编辑器组件 
           ComponentUI.uninstallUI(javax.swing.JComponent) 
           public void update(Graphics g, JComponent c)
注意:注意:超类在渲染背景时也不是线程安全的,尽管这不是默认渲染的问题。
update在 
            ComponentUI 
           g - 要绘画的 
            Graphics上下文 
           c - 正在涂漆的部件; 
            这个参数经常被忽略,但如果UI对象是无状态的并且被多个组件共享,则可能会被使用 
           ComponentUI.paint(java.awt.Graphics, javax.swing.JComponent) , 
            JComponent.paintComponent(java.awt.Graphics) 
           public final void paint(Graphics g, JComponent c)
paint在 
            ComponentUI 
           g - 图形上下文 
           c - 编辑器组件 
           ComponentUI.update(java.awt.Graphics, javax.swing.JComponent) 
           public Dimension getPreferredSize(JComponent c)
getPreferredSize在 
            ComponentUI 
           c - 编辑器组件 
           JComponent.getPreferredSize() , 
            LayoutManager.preferredLayoutSize(java.awt.Container) 
           public Dimension getMinimumSize(JComponent c)
getMinimumSize在 
            ComponentUI类 
           c - 编辑器组件 
           JComponent.getMinimumSize() , 
            LayoutManager.minimumLayoutSize(java.awt.Container) , 
            ComponentUI.getPreferredSize(javax.swing.JComponent) 
           public Dimension getMaximumSize(JComponent c)
getMaximumSize在 
            ComponentUI类 
           c - 编辑器组件 
           JComponent.getMaximumSize() , 
            LayoutManager2.maximumLayoutSize(java.awt.Container) 
           protected Rectangle getVisibleEditorRect()
public Rectangle modelToView(JTextComponent tc, int pos) throws BadLocationException
modelToView在 
            TextUI 
           tc - 安装此UI的文本组件 
           pos - 模型中的本地位置翻译> = 0 
           BadLocationException - 如果给定的位置不表示相关文档中的有效位置 
           TextUI.modelToView(javax.swing.text.JTextComponent, int) 
           public Rectangle modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException
modelToView在 
            TextUI 
           tc - 安装此UI的文本组件 
           pos - 模型中的本地位置翻译> = 0 
           BadLocationException - 如果给定的位置不表示相关文档中的有效位置 
           TextUI.modelToView(javax.swing.text.JTextComponent, int) 
           public int viewToModel(JTextComponent tc, Point pt)
viewToModel在 
            TextUI 
           tc - 安装此UI的文本组件 
           pt - 视图中的位置翻译。 
            这应该在与鼠标事件相同的坐标系统中。 
           TextUI.viewToModel(javax.swing.text.JTextComponent, java.awt.Point) 
           public int viewToModel(JTextComponent tc, Point pt, Position.Bias[] biasReturn)
viewToModel在 
            TextUI 
           tc - 安装此UI的文本组件 
           pt - 视图中的位置翻译。 
            这应该在与鼠标事件相同的坐标系统中。 
           biasReturn - 用这种方法填写,以指示给定的点是否更接近模型中的上一个或下一个字符 
           TextUI.viewToModel(javax.swing.text.JTextComponent, java.awt.Point) 
           public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException
getNextVisualPositionFrom在 
            TextUI 
           t - 安装此UI的文本组件 
           pos - 转换> = 0的位置 
           b - 位置的偏差 
           direction - 从当前位置的方向,可以被认为是通常在键盘上找到的箭头键。 
            这可能是SwingConstants.WEST,SwingConstants.EAST,SwingConstants.NORTH或SwingConstants.SOUTH 
           biasRet - 一个数组,用于包含返回位置的偏置 
           BadLocationException 
           public void damageRange(JTextComponent tc, int p0, int p1)
damageRange在 
            TextUI类 
           tc - 安装此UI的文本组件 
           p0 - 范围的开始> = 0 
           p1 - 范围的结束> = p0 
           TextUI.damageRange(javax.swing.text.JTextComponent, int, int) 
           public void damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias)
damageRange在 
            TextUI 
           p0 - 范围的开始> = 0 
           p1 - 范围的结束> = p0 
           public EditorKit getEditorKit(JTextComponent tc)
getEditorKit在 
            TextUI 
           tc - 安装此UI的文本组件 
           TextUI.getEditorKit(javax.swing.text.JTextComponent) 
           public View getRootView(JTextComponent tc)
注意:视图层次结构可以从根视图中遍历,其他的事情也可以完成。 以这种方式完成的事情不能通过TextUI进行简单的方法调用来保护。 因此,存在并发性的正确操作必须由调用此方法的任何逻辑排列!
getRootView在 
            TextUI 
           tc - 安装此UI的文本组件 
           TextUI.getRootView(javax.swing.text.JTextComponent) 
           public String getToolTipText(JTextComponent t, Point pt)
public View create(Element elem)
create在界面 
            ViewFactory 
           elem - 元素 
           View 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.