所有类


javax.swing.text
类 PlainView

java.lang.Object
  继承者 javax.swing.text.View
      继承者 javax.swing.text.PlainView
所有已实现的接口:
SwingConstants, TabExpander
直接已知子类:
FieldView

public class PlainView
   
   
   
   
extends View
implements TabExpander

实现简单的多行文本视图的 View 接口,该文本视图的文本只有一种字体和颜色。该视图用每个子元素表示文本的某一行。

另请参见:
View

字段摘要
protected  FontMetricsmetrics
          当前字体的字体规格。
 
从类 javax.swing.text.View 继承的字段
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
从接口 javax.swing.SwingConstants 继承的字段
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
构造方法摘要
PlainView(Element elem)
          构造在元素上包装的新 PlainView。
 
方法摘要
 voidchangedUpdate(DocumentEvent changes, Shape a, ViewFactory f)
          发出通知,通知文档中此视图负责的某个位置的属性已更改。
protected  voiddamageLineRange(int line0, int line1, Shape a, Component host)
          重新绘制给定的行范围。
protected  voiddrawLine(int lineIndex, Graphics g, int x, int y)
          呈现文本的某一行,取消末尾的空白并扩展所有的制表符。
protected  intdrawSelectedText(Graphics g, int x, int y, int p0, int p1)
          将模型中给定的范围呈现为选定文本。
protected  intdrawUnselectedText(Graphics g, int x, int y, int p0, int p1)
          将模型中给定的范围呈现为正常的未选定文本。
protected  SegmentgetLineBuffer()
          提供对可用于从相关文档获取文本的缓冲区的访问。
 floatgetPreferredSpan(int axis)
          确定此视图沿某轴的首选区域。
protected  intgetTabSize()
          返回文档中制表符大小的集合,默认值是 8。
 voidinsertUpdate(DocumentEvent changes, Shape a, ViewFactory f)
          发出通知,通知在文档中此视图负责的某个位置已插入内容。
protected  RectanglelineToRect(Shape a, int line)
          确定表示给定行的矩形。
 ShapemodelToView(int pos, Shape a, Position.Bias b)
          提供从文档模型坐标空间到所映射的视图坐标空间的映射。
 floatnextTabStop(float x, int tabOffset)
          在给定引用位置之后,返回下一个制表位的位置。
 voidpaint(Graphics g, Shape a)
          使用给定呈现面和该表面的区域呈现。
 voidremoveUpdate(DocumentEvent changes, Shape a, ViewFactory f)
          通知在文档中此视图负责的某个位置已插入内容。
 voidsetSize(float width, float height)
          设置视图的大小。
protected  voidupdateDamage(DocumentEvent changes, Shape a, ViewFactory f)
           
protected  voidupdateMetrics()
          检查字体规格和最长行是否最新。
 intviewToModel(float fx, float fy, Shape a, Position.Bias[] bias)
          提供从视图坐标空间到该模型的逻辑坐标空间的映射。
 
从类 javax.swing.text.View 继承的方法
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, replace, setParent, updateChildren, updateLayout, viewToModel
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

metrics

protected FontMetrics metrics
当前字体的字体规格。

构造方法详细信息

PlainView

public PlainView(Element elem)
构造在元素上包装的新 PlainView。

参数:
elem - 元素
方法详细信息

getTabSize

protected int getTabSize()
返回文档中制表符大小的集合,默认值是 8。

返回:
制表符大小

drawLine

protected void drawLine(int lineIndex,
                        Graphics g,
                        int x,
                        int y)
呈现文本的某一行,取消末尾的空白并扩展所有的制表符。实现此方法以调用方法 drawUnselectedTextdrawSelectedText,这样可自定义呈现选定和未选定文本的方法。

参数:
lineIndex - 要绘制的行,该值 >= 0
g - Graphics 上下文
x - 起始 X 位置,该值 >= 0
y - 起始 Y 位置 >= 0
另请参见:
drawUnselectedText(java.awt.Graphics, int, int, int, int), drawSelectedText(java.awt.Graphics, int, int, int, int)

drawUnselectedText

protected int drawUnselectedText(Graphics g,
                                 int x,
                                 int y,
                                 int p0,
                                 int p1)
                          throws BadLocationException
将模型中给定的范围呈现为正常的未选定文本。使用前景色或禁用的颜色呈现文本。

参数:
g - 图形上下文
x - 起始 X 坐标,该值 >= 0
y - 起始 Y 坐标,该值 >= 0
p0 - 模型中的起始位置,该值 >= 0
p1 - 模型中的结束位置,该值 >= 0
返回:
范围末尾的 X 位置,该值 >= 0
抛出:
BadLocationException - 如果范围无效

drawSelectedText

protected int drawSelectedText(Graphics g,
                               int x,
                               int y,
                               int p0,
                               int p1)
                        throws BadLocationException
将模型中给定的范围呈现为选定文本。实现此方法以使用承载组件中指定的颜色呈现文本。假定 highlighter 将呈现选定的背景。

参数:
g - 图形上下文
x - 起始 X 坐标,该值 >= 0
y - 起始 Y 坐标,该值 >= 0
p0 - 模型中的起始位置,该值 >= 0
p1 - 模型中的结束位置,该值 >= 0
返回:
范围末尾的位置
抛出:
BadLocationException - 如果范围无效

getLineBuffer

protected final Segment getLineBuffer()
提供对可用于从相关文档获取文本的缓冲区的访问。

返回:
缓冲区

updateMetrics

protected void updateMetrics()
检查字体规格和最长行是否最新。

从以下版本开始:
1.4

getPreferredSpan

public float getPreferredSpan(int axis)
确定此视图沿某轴的首选区域。

指定者:
View 中的 getPreferredSpan
参数:
axis - 可以是 View.X_AXIS 或 View.Y_AXIS
返回:
视图可能要在其中呈现的区域,该值 >= 0。通常会告知该视图在返回的区域中呈现,但不保证一定如此。父级可选择重新调整视图大小或拆分视图。
抛出:
IllegalArgumentException - 如果轴无效
另请参见:
View.getPreferredSpan(int)