| 
 | JavaTM Platform Standard Ed. 6 | |||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjavax.swing.plaf.ComponentUI
javax.swing.plaf.TextUI
javax.swing.plaf.basic.BasicTextUI
public abstract class BasicTextUI
此类是文本组件外观的基础。它提供基本的编辑器视图和控制器服务,在为 JTextComponent 的扩展类创建外观时非常有用。
 
大多数状态作为绑定 (bound) 属性保存在关联的 JTextComponent 中,UI 为各种属性安装默认值。此默认值将为所有属性安装某些内容。但是,通常 LAF 实现所做的不止如此。LAF 一般至少会安装键绑定。
 
如果与 JTextComponent 关联的 Document 是 AbstractDocument 的子类,则此类还将提供某些并发支持。在任一更改模型的线程与 Swing 事件线程(希望用来呈现、进行模型/视图坐标转换等)之间,对 View(或 View 层次结构)的访问都是序列化的。对根视图的任何访问首先应该获取一个 AbstractDocument 上的读锁 (read-lock),并在 finally 代码块中释放该锁。
 
要定义的一个重要方法是 getPropertyPrefix() 方法,该方法作为从 UIManager 获取默认值的键的基础。字符串应该反映 TextUI(例如,TextField、TextArea 等)的类型,并且不带名称的特定 LAF 部分(例如,Metal、Motif 等)。
 
要构建模型的视图,可以使用以下策略之一。
create(javax.swing.text.Element) 方法。
 
警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
| 嵌套类摘要 | |
|---|---|
| static class | BasicTextUI.BasicCaret | 
| static class | BasicTextUI.BasicHighlighter | 
| 构造方法摘要 | |
|---|---|
| BasicTextUI()创建新的 UI。 | |
| 方法摘要 | |
|---|---|
|  View | create(Element elem)创建元素的视图。 | 
|  View | create(Element elem,
       int p0,
       int p1)创建元素的视图。 | 
| protected  Caret | createCaret()创建用于插入符的对象。 | 
| protected  Highlighter | createHighlighter()创建用于添加高亮显示的对象。 | 
| protected  Keymap | createKeymap()创建用于文本组件的 keymap,并在其中安装必需的绑定。 | 
|  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)获取 UI 的 EditorKit。 | 
| protected  String | getKeymapName()获取默认情况下为此 UI 安装或用于此 UI 的 keymap 的名称。 | 
|  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)获取分配了相关文本组件(即层次结构的根)的 View,可通过遍历该视图确定模型在空间中的表示形式。 | 
|  String | getToolTipText(JTextComponent t,
               Point pt)返回在传入位置上用作工具提示的字符串。 | 
| protected  Rectangle | getVisibleEditorRect()获取给出根 View 的分配。 | 
| protected  void | installDefaults()初始化组件属性,例如,字体、前景、背景、插入符颜色、选择颜色、所选文本颜色、禁用文本颜色,以及边框颜色。 | 
| protected  void | installKeyboardActions() | 
| protected  void | installListeners()安装 UI 的侦听器。 | 
|  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 上有一个绑定属性更改时,此方法被调用。 | 
| 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)将视图坐标系统中的给定位置转换成模型中最有代表性的位置。 | 
| 从类 javax.swing.plaf.ComponentUI 继承的方法 | 
|---|
| contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior | 
| 从类 java.lang.Object 继承的方法 | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| 构造方法详细信息 | 
|---|
public BasicTextUI()
| 方法详细信息 | 
|---|
protected Caret createCaret()
protected Highlighter createHighlighter()
protected String getKeymapName()
protected Keymap createKeymap()
用于创建 keymap 的绑定集从 UIManager 获取,方法是使用通过组合 getPropertyPrefix() 方法和字符串 .keyBindings 而形成的键。期望的类型为 JTextComponent.KeyBinding[]。
getKeymapName(), 
JTextComponentprotected void propertyChange(PropertyChangeEvent evt)
evt - 属性更改事件protected abstract String getPropertyPrefix()
protected void installDefaults()
uninstallDefaults(), 
installUI(javax.swing.JComponent)protected void uninstallDefaults()
installDefaults(), 
uninstallUI(javax.swing.JComponent)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)
ComponentUI 中的 installUIc - 编辑器组件ComponentUI.installUI(javax.swing.JComponent)public void uninstallUI(JComponent c)
ComponentUI 中的 uninstallUIc - 编辑器组件ComponentUI.uninstallUI(javax.swing.JComponent)
public void update(Graphics g,
                   JComponent c)
注: 超类在其背景呈现中也不是线程安全的,尽管在默认呈现中不存在这样的问题。
ComponentUI 中的 updateg - 将在其中进行绘制的 Graphics 上下文c - 将绘制的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数ComponentUI.paint(java.awt.Graphics, javax.swing.JComponent), 
JComponent.paintComponent(java.awt.Graphics)
public final void paint(Graphics g,
                        JComponent c)
ComponentUI 中的 paintg - 图形上下文c - 编辑器组件ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)public Dimension getPreferredSize(JComponent c)
ComponentUI 中的 getPreferredSizec - 编辑器组件
JComponent.getPreferredSize(), 
LayoutManager.preferredLayoutSize(java.awt.Container)public Dimension getMinimumSize(JComponent c)
ComponentUI 中的 getMinimumSizec - 编辑器组件
JComponent.getMinimumSize(), 
LayoutManager.minimumLayoutSize(java.awt.Container), 
ComponentUI.getPreferredSize(javax.swing.JComponent)public Dimension getMaximumSize(JComponent c)
ComponentUI 中的 getMaximumSizec - 编辑器组件
JComponent.getMaximumSize(), 
LayoutManager2.maximumLayoutSize(java.awt.Container)protected Rectangle getVisibleEditorRect()
public Rectangle modelToView(JTextComponent tc,
                             int pos)
                      throws BadLocationException
TextUI 中的 modelToViewtc - 文本组件,为其安装此 UIpos - 要转换的模型中的本地位置,该值 >= 0
BadLocationException - 如果给定位置不表示关联文档中的有效位置TextUI.modelToView(javax.swing.text.JTextComponent, int)
public Rectangle modelToView(JTextComponent tc,
                             int pos,
                             Position.Bias bias)
                      throws BadLocationException
TextUI 中的 modelToViewtc - 文本组件,为其安装此 UIpos - 要转换的模型中的本地位置,该值 >= 0
BadLocationException - 如果给定位置不表示关联文档中的有效位置TextUI.modelToView(javax.swing.text.JTextComponent, int)
public int viewToModel(JTextComponent tc,
                       Point pt)
TextUI 中的 viewToModeltc - 文本组件,为其安装此 UIpt - 视图中要转换的位置。此位置应该与鼠标事件在同一坐标系统中。
TextUI.viewToModel(javax.swing.text.JTextComponent, java.awt.Point)
public int viewToModel(JTextComponent tc,
                       Point pt,
                       Position.Bias[] biasReturn)
TextUI 中的 viewToModeltc - 为其安装此 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
TextUI 中的 getNextVisualPositionFromt - 为其安装此 UI 的文本组件pos - 要转换的位置,该位置 >= 0b - 位置的偏差direction - 以当前位置开始的方向,可以将它们设想为通常出现在键盘上的箭头键。该参数可以是 SwingConstants.WEST、SwingConstants.EAST、SwingConstants.NORTH 或 SwingConstants.SOUTHbiasRet - 包含返回位置偏差的数组
BadLocationException
public void damageRange(JTextComponent tc,
                        int p0,
                        int p1)
TextUI 中的 damageRangetc - 文本组件,为其安装此 UIp0 - 范围的开头,该值 >= 0p1 - 范围的结尾,该值 >= p0TextUI.damageRange(javax.swing.text.JTextComponent, int, int)
public void damageRange(JTextComponent t,
                        int p0,
                        int p1,
                        Position.Bias p0Bias,
                        Position.Bias p1Bias)
TextUI 中的 damageRangep0 - 范围的起始位置,该值 >= 0p1 - 范围的结束位置,该值 >= p0public EditorKit getEditorKit(JTextComponent tc)
TextUI 中的 getEditorKittc - 文本组件,为其安装此 UI
TextUI.getEditorKit(javax.swing.text.JTextComponent)public View getRootView(JTextComponent tc)
注:可以从根视图遍历 View 层次结构,其他操作也可以如此。以此方式完成的操作不会像通过 TextUI 的简单方法调用那样受到保护。因此,存在并发操作时必须按照调用此方法的逻辑安排适当的操作!
TextUI 中的 getRootViewtc - 文本组件,为其安装此 UI
TextUI.getRootView(javax.swing.text.JTextComponent)
public String getToolTipText(JTextComponent t,
                             Point pt)
TextUI 中的 getToolTipTextJTextComponent.getToolTipText(java.awt.event.MouseEvent), 
View.getToolTipText(float, float, java.awt.Shape)public View create(Element elem)
ViewFactory 中的 createelem - 元素
View
public View create(Element elem,
                   int p0,
                   int p1)
elem - 元素p0 - 开始偏移量,该值 >= 0p1 - 结束偏移量,该值 >= p0
| 
 | JavaTM Platform Standard Ed. 6 | |||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。