javax.swing.text

Class View

public abstract class View extends Object implements SwingConstants

Field Summary
static intBadBreakWeight
static intExcellentBreakWeight
static intForcedBreakWeight
static intGoodBreakWeight
static intX_AXIS
static intY_AXIS
Constructor Summary
View(Element elem)
Creates a new View instance.
Method Summary
voidappend(View view)
ViewbreakView(int axis, int offset, float pos, float len)
voidchangedUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
Receive notification about a change update to the text model.
ViewcreateFragment(int p0, int p1)
protected voiddump()
Dumps the complete View hierarchy.
protected voidforwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent ev, Shape shape, ViewFactory vf)
Forwards the DocumentEvent to child views that need to get notified of the change to the model.
protected voidforwardUpdateToView(View view, DocumentEvent ev, Shape shape, ViewFactory vf)
Forwards an update event to the given child view.
floatgetAlignment(int axis)
Returns the alignment of this view along the baseline of the parent view.
AttributeSetgetAttributes()
intgetBreakWeight(int axis, float pos, float len)
ShapegetChildAllocation(int index, Shape a)
ContainergetContainer()
DocumentgetDocument()
ElementgetElement()
intgetEndOffset()
GraphicsgetGraphics()
floatgetMaximumSpan(int axis)
Returns the maximum span along the specified axis.
floatgetMinimumSpan(int axis)
Returns the minimum span along the specified axis.
intgetNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int d, Position.Bias[] biasRet)
Returns the document position that is (visually) nearest to the given document position pos in the given direction d.
ViewgetParent()
abstract floatgetPreferredSpan(int axis)
Returns the preferred span along the specified axis.
intgetResizeWeight(int axis)
Returns the resize weight of this view.
intgetStartOffset()
StringgetToolTipText(float x, float y, Shape allocation)
ViewgetView(int index)
intgetViewCount()
ViewFactorygetViewFactory()
intgetViewIndex(float x, float y, Shape allocation)
intgetViewIndex(int pos, Position.Bias b)
voidinsert(int offset, View view)
voidinsertUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
Receive notification about an insert update to the text model.
booleanisVisible()
abstract ShapemodelToView(int pos, Shape a, Position.Bias b)
Maps a position in the document into the coordinate space of the View.
ShapemodelToView(int p1, Position.Bias b1, int p2, Position.Bias b2, Shape a)
Maps a region in the document into the coordinate space of the View.
ShapemodelToView(int pos, Shape a)
Maps a position in the document into the coordinate space of the View.
abstract voidpaint(Graphics g, Shape s)
voidpreferenceChanged(View child, boolean width, boolean height)
voidremove(int index)
voidremoveAll()
voidremoveUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
Receive notification about a remove update to the text model.
voidreplace(int offset, int length, View[] views)
Replaces a couple of child views with new child views.
voidsetParent(View parent)
Sets the parent for this view.
voidsetSize(float width, float height)
protected booleanupdateChildren(DocumentEvent.ElementChange ec, DocumentEvent ev, ViewFactory vf)
Updates the list of children that is returned by {@link #getView} and {@link #getViewCount}.
protected voidupdateLayout(DocumentEvent.ElementChange ec, DocumentEvent ev, Shape shape)
Updates the layout.
abstract intviewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from the View's space into a position in the document model.
intviewToModel(float x, float y, Shape a)
Maps coordinates from the View's space into a position in the document model.

Field Detail

BadBreakWeight

public static final int BadBreakWeight

ExcellentBreakWeight

public static final int ExcellentBreakWeight

ForcedBreakWeight

public static final int ForcedBreakWeight

GoodBreakWeight

public static final int GoodBreakWeight

X_AXIS

public static final int X_AXIS

Y_AXIS

public static final int Y_AXIS

Constructor Detail

View

public View(Element elem)
Creates a new View instance.

Parameters: elem an Element value

Method Detail

append

public void append(View view)

breakView

public View breakView(int axis, int offset, float pos, float len)

changedUpdate

public void changedUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
Receive notification about a change update to the text model. The default implementation of this method does the following:

Parameters: ev the DocumentEvent that describes the change shape the shape of the view vf the ViewFactory for creating child views

createFragment

public View createFragment(int p0, int p1)

dump

protected void dump()
Dumps the complete View hierarchy. This method can be used for debugging purposes.

forwardUpdate

protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent ev, Shape shape, ViewFactory vf)
Forwards the DocumentEvent to child views that need to get notified of the change to the model. This calles {@link #forwardUpdateToView} for each View that must be forwarded to. If ec is not null (this means there have been structural changes to the element that this view is responsible for) this method should recognize this and don't notify newly added child views.

Parameters: ec the ElementChange describing the element changes (may be null if there were no changes) ev the DocumentEvent describing the changes to the model shape the current allocation of the view vf the ViewFactory used to create new Views

Since: 1.3

forwardUpdateToView

protected void forwardUpdateToView(View view, DocumentEvent ev, Shape shape, ViewFactory vf)
Forwards an update event to the given child view. This calls {@link #insertUpdate}, {@link #removeUpdate} or {@link #changedUpdate}, depending on the type of document event.

Parameters: view the View to forward the event to ev the DocumentEvent to forward shape the current allocation of the View vf the ViewFactory used to create new Views

Since: 1.3

getAlignment

public float getAlignment(int axis)
Returns the alignment of this view along the baseline of the parent view. An alignment of 0.0 will align this view with the left edge along the baseline, an alignment of 0.5 will align it centered to the baseline, an alignment of 1.0 will align the right edge along the baseline. The default implementation returns 0.5 unconditionally.

Parameters: axis the axis

Returns: the alignment of this view along the parents baseline for the specified axis

getAttributes

public AttributeSet getAttributes()

getBreakWeight

public int getBreakWeight(int axis, float pos, float len)

getChildAllocation

public Shape getChildAllocation(int index, Shape a)

getContainer

public Container getContainer()

getDocument

public Document getDocument()

getElement

public Element getElement()

getEndOffset

public int getEndOffset()

getGraphics

public Graphics getGraphics()

Since: 1.3

getMaximumSpan

public float getMaximumSpan(int axis)
Returns the maximum span along the specified axis. The default implementation will forward to {@link #getPreferredSpan(int)} unless {@link #getResizeWeight(int)} returns a value > 0, in which case this returns {@link Integer#MIN_VALUE}.

Parameters: axis the axis

Returns: the maximum span along the specified axis

getMinimumSpan

public float getMinimumSpan(int axis)
Returns the minimum span along the specified axis. The default implementation will forward to {@link #getPreferredSpan(int)} unless {@link #getResizeWeight(int)} returns a value > 0, in which case this returns 0.

Parameters: axis the axis

Returns: the minimum span along the specified axis

getNextVisualPositionFrom

public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int d, Position.Bias[] biasRet)
Returns the document position that is (visually) nearest to the given document position pos in the given direction d.

Parameters: pos the document position b the bias for pos a the allocation for this view d the direction, must be either {@link SwingConstants#NORTH}, {@link SwingConstants#SOUTH}, {@link SwingConstants#WEST} or {@link SwingConstants#EAST} biasRet an array of {@link Position.Bias} that can hold at least one element, which is filled with the bias of the return position on method exit

Returns: the document position that is (visually) nearest to the given document position pos in the given direction d

Throws: BadLocationException if pos is not a valid offset in the document model IllegalArgumentException if d is not a valid direction

getParent

public View getParent()

getPreferredSpan

public abstract float getPreferredSpan(int axis)
Returns the preferred span along the specified axis. Normally the view is rendered with the span returned here if that is possible.

Parameters: axis the axis

Returns: the preferred span along the specified axis

getResizeWeight

public int getResizeWeight(int axis)
Returns the resize weight of this view. A value of 0 or less means this view is not resizeable. Positive values make the view resizeable. The default implementation returns 0 unconditionally.

Parameters: axis the axis

Returns: the resizability of this view along the specified axis

getStartOffset

public int getStartOffset()

getToolTipText

public String getToolTipText(float x, float y, Shape allocation)

Since: 1.4

getView

public View getView(int index)

getViewCount

public int getViewCount()

getViewFactory

public ViewFactory getViewFactory()

getViewIndex

public int getViewIndex(float x, float y, Shape allocation)

Since: 1.4

getViewIndex

public int getViewIndex(int pos, Position.Bias b)

Since: 1.3

insert

public void insert(int offset, View view)

insertUpdate

public void insertUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
Receive notification about an insert update to the text model. The default implementation of this method does the following:

Parameters: ev the DocumentEvent that describes the change shape the shape of the view vf the ViewFactory for creating child views

isVisible

public boolean isVisible()

modelToView

public abstract Shape modelToView(int pos, Shape a, Position.Bias b)
Maps a position in the document into the coordinate space of the View. The output rectangle usually reflects the font height but has a width of zero.

Parameters: pos the position of the character in the model a the area that is occupied by the view b either {@link Position.Bias#Forward} or {@link Position.Bias#Backward} depending on the preferred direction bias. If null this defaults to Position.Bias.Forward

Returns: a rectangle that gives the location of the document position inside the view coordinate space

Throws: BadLocationException if pos is invalid IllegalArgumentException if b is not one of the above listed valid values

modelToView

public Shape modelToView(int p1, Position.Bias b1, int p2, Position.Bias b2, Shape a)
Maps a region in the document into the coordinate space of the View.

Parameters: p1 the beginning position inside the document b1 the direction bias for the beginning position p2 the end position inside the document b2 the direction bias for the end position a the area that is occupied by the view

Returns: a rectangle that gives the span of the document region inside the view coordinate space

Throws: BadLocationException if p1 or p2 are invalid IllegalArgumentException if b1 or b2 is not one of the above listed valid values

modelToView

public Shape modelToView(int pos, Shape a)

Deprecated: Use {@link #modelToView(int, Shape, Position.Bias)} instead.

Maps a position in the document into the coordinate space of the View. The output rectangle usually reflects the font height but has a width of zero. This method is deprecated and calls {@link #modelToView(int, Position.Bias, int, Position.Bias, Shape)} with a bias of {@link Position.Bias#Forward}.

Parameters: pos the position of the character in the model a the area that is occupied by the view

Returns: a rectangle that gives the location of the document position inside the view coordinate space

Throws: BadLocationException if pos is invalid

paint

public abstract void paint(Graphics g, Shape s)

preferenceChanged

public void preferenceChanged(View child, boolean width, boolean height)

remove

public void remove(int index)

removeAll

public void removeAll()

removeUpdate

public void removeUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
Receive notification about a remove update to the text model. The default implementation of this method does the following:

Parameters: ev the DocumentEvent that describes the change shape the shape of the view vf the ViewFactory for creating child views

replace

public void replace(int offset, int length, View[] views)
Replaces a couple of child views with new child views. If length == 0 then this is a simple insertion, if views == null this only removes some child views.

Parameters: offset the offset at which to replace length the number of child views to be removed views the new views to be inserted, may be null

setParent

public void setParent(View parent)
Sets the parent for this view. This is the first method that is beeing called on a view to setup the view hierarchy. This is also the last method beeing called when the view is disconnected from the view hierarchy, in this case parent is null. If parent is null, a call to this method also calls setParent on the children, thus disconnecting them from the view hierarchy. That means that super must be called when this method is overridden.

Parameters: parent the parent to set, null when this view is beeing disconnected from the view hierarchy

setSize

public void setSize(float width, float height)

updateChildren

protected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent ev, ViewFactory vf)
Updates the list of children that is returned by {@link #getView} and {@link #getViewCount}. Element that are specified as beeing added in the ElementChange record are assigned a view for using the ViewFactory. Views of Elements that are specified as beeing removed are removed from the list.

Parameters: ec the ElementChange record that describes the change of the element ev the DocumentEvent describing the change of the document model vf the ViewFactory to use for creating new views

Returns: whether or not the child views represent the child elements of the element that this view is responsible for. Some views may create views that are responsible only for parts of the element that they are responsible for and should then return false.

Since: 1.3

updateLayout

protected void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent ev, Shape shape)
Updates the layout.

Parameters: ec the ElementChange that describes the changes to the element ev the DocumentEvent that describes the changes to the model shape the current allocation for this view

Since: 1.3

viewToModel

public abstract int viewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from the View's space into a position in the document model.

Parameters: x the x coordinate in the view space y the y coordinate in the view space a the allocation of this View b the bias to use

Returns: the position in the document that corresponds to the screen coordinates x, y

viewToModel

public int viewToModel(float x, float y, Shape a)

Deprecated: Use {@link #viewToModel(float, float, Shape, Position.Bias[])} instead.

Maps coordinates from the View's space into a position in the document model. This method is deprecated and only there for compatibility.

Parameters: x the x coordinate in the view space y the y coordinate in the view space a the allocation of this View

Returns: the position in the document that corresponds to the screen coordinates x, y