javax.swing.text
public abstract class View extends Object implements SwingConstants
Modifier and Type | Field and Description |
---|---|
static int |
BadBreakWeight |
static int |
ExcellentBreakWeight |
static int |
ForcedBreakWeight |
static int |
GoodBreakWeight |
static int |
X_AXIS |
static int |
Y_AXIS |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
Constructor and Description |
---|
View(Element elem)
Creates a new
View instance. |
Modifier and Type | Method and Description |
---|---|
void |
append(View view) |
View |
breakView(int axis,
int offset,
float pos,
float len) |
void |
changedUpdate(DocumentEvent ev,
Shape shape,
ViewFactory vf)
Receive notification about a change update to the text model.
|
View |
createFragment(int p0,
int p1) |
protected void |
dump()
Dumps the complete View hierarchy.
|
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.
|
protected void |
forwardUpdateToView(View view,
DocumentEvent ev,
Shape shape,
ViewFactory vf)
Forwards an update event to the given child view.
|
float |
getAlignment(int axis)
Returns the alignment of this view along the baseline of the parent view.
|
AttributeSet |
getAttributes() |
int |
getBreakWeight(int axis,
float pos,
float len) |
Shape |
getChildAllocation(int index,
Shape a) |
Container |
getContainer() |
Document |
getDocument() |
Element |
getElement() |
int |
getEndOffset() |
Graphics |
getGraphics() |
float |
getMaximumSpan(int axis)
Returns the maximum span along the specified axis.
|
float |
getMinimumSpan(int axis)
Returns the minimum span along the specified axis.
|
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 . |
View |
getParent() |
abstract float |
getPreferredSpan(int axis)
Returns the preferred span along the specified axis.
|
int |
getResizeWeight(int axis)
Returns the resize weight of this view.
|
int |
getStartOffset() |
String |
getToolTipText(float x,
float y,
Shape allocation) |
View |
getView(int index) |
int |
getViewCount() |
ViewFactory |
getViewFactory() |
int |
getViewIndex(float x,
float y,
Shape allocation) |
int |
getViewIndex(int pos,
Position.Bias b) |
void |
insert(int offset,
View view) |
void |
insertUpdate(DocumentEvent ev,
Shape shape,
ViewFactory vf)
Receive notification about an insert update to the text model.
|
boolean |
isVisible() |
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.
|
Shape |
modelToView(int pos,
Shape a)
Deprecated.
Use
modelToView(int, Shape, Position.Bias) instead. |
abstract Shape |
modelToView(int pos,
Shape a,
Position.Bias b)
Maps a position in the document into the coordinate space of the View.
|
abstract void |
paint(Graphics g,
Shape s) |
void |
preferenceChanged(View child,
boolean width,
boolean height) |
void |
remove(int index) |
void |
removeAll() |
void |
removeUpdate(DocumentEvent ev,
Shape shape,
ViewFactory vf)
Receive notification about a remove update to the text model.
|
void |
replace(int offset,
int length,
View[] views)
Replaces a couple of child views with new child views.
|
void |
setParent(View parent)
Sets the parent for this view.
|
void |
setSize(float width,
float height) |
protected boolean |
updateChildren(DocumentEvent.ElementChange ec,
DocumentEvent ev,
ViewFactory vf)
Updates the list of children that is returned by
getView(int)
and getViewCount() . |
protected void |
updateLayout(DocumentEvent.ElementChange ec,
DocumentEvent ev,
Shape shape)
Updates the layout.
|
int |
viewToModel(float x,
float y,
Shape a)
Deprecated.
Use
viewToModel(float, float, Shape, Position.Bias[])
instead. |
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. |
public static final int BadBreakWeight
public static final int ExcellentBreakWeight
public static final int ForcedBreakWeight
public static final int GoodBreakWeight
public static final int X_AXIS
public static final int Y_AXIS
public void setParent(View parent)
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.parent
- the parent to set, null
when this view is
beeing disconnected from the view hierarchypublic Container getContainer()
public Document getDocument()
public Element getElement()
public abstract float getPreferredSpan(int axis)
axis
- the axispublic int getResizeWeight(int axis)
0
or less
means this view is not resizeable. Positive values make the view
resizeable. The default implementation returns 0
unconditionally.axis
- the axispublic float getMaximumSpan(int axis)
getPreferredSpan(int)
unless getResizeWeight(int)
returns a value > 0, in which case this returns Integer.MIN_VALUE
.axis
- the axispublic float getMinimumSpan(int axis)
getPreferredSpan(int)
unless getResizeWeight(int)
returns a value > 0, in which case this returns 0
.axis
- the axispublic void setSize(float width, float height)
public float getAlignment(int axis)
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.axis
- the axispublic AttributeSet getAttributes()
public boolean isVisible()
public int getViewCount()
public ViewFactory getViewFactory()
public void replace(int offset, int length, View[] views)
length == 0
then this is a simple insertion, if
views == null
this only removes some child views.offset
- the offset at which to replacelength
- the number of child views to be removedviews
- the new views to be inserted, may be null
public void removeAll()
public void remove(int index)
public View createFragment(int p0, int p1)
public int getStartOffset()
public int getEndOffset()
public Shape getChildAllocation(int index, Shape a)
public int getViewIndex(float x, float y, Shape allocation)
public String getToolTipText(float x, float y, Shape allocation)
public Graphics getGraphics()
public void preferenceChanged(View child, boolean width, boolean height)
public int getBreakWeight(int axis, float pos, float len)
public int getViewIndex(int pos, Position.Bias b)
public void insertUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
updateChildren(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, javax.swing.text.ViewFactory)
if the element that this view is
responsible for has changed. This makes sure that the children can
correctly represent the model.forwardUpdate(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
. This forwards the DocumentEvent to
the child views.updateLayout(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, java.awt.Shape)
. Gives the view a chance to either
repair its layout, reschedule layout or do nothing at all.ev
- the DocumentEvent that describes the changeshape
- the shape of the viewvf
- the ViewFactory for creating child viewspublic void removeUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
updateChildren(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, javax.swing.text.ViewFactory)
if the element that this view is
responsible for has changed. This makes sure that the children can
correctly represent the model.forwardUpdate(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
. This forwards the DocumentEvent to
the child views.updateLayout(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, java.awt.Shape)
. Gives the view a chance to either
repair its layout, reschedule layout or do nothing at all.ev
- the DocumentEvent that describes the changeshape
- the shape of the viewvf
- the ViewFactory for creating child viewspublic void changedUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
updateChildren(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, javax.swing.text.ViewFactory)
if the element that this view is
responsible for has changed. This makes sure that the children can
correctly represent the model.forwardUpdate(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
. This forwards the DocumentEvent to
the child views.updateLayout(javax.swing.event.DocumentEvent.ElementChange, javax.swing.event.DocumentEvent, java.awt.Shape)
. Gives the view a chance to either
repair its layout, reschedule layout or do nothing at all.ev
- the DocumentEvent that describes the changeshape
- the shape of the viewvf
- the ViewFactory for creating child viewsprotected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent ev, ViewFactory vf)
getView(int)
and 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.ec
- the ElementChange record that describes the change of the
elementev
- the DocumentEvent describing the change of the document modelvf
- the ViewFactory to use for creating new viewsprotected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent ev, Shape shape, ViewFactory vf)
forwardUpdateToView(javax.swing.text.View, javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
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.ec
- the ElementChange describing the element changes (may be
null
if there were no changes)ev
- the DocumentEvent describing the changes to the modelshape
- the current allocation of the viewvf
- the ViewFactory used to create new Viewsprotected void forwardUpdateToView(View view, DocumentEvent ev, Shape shape, ViewFactory vf)
insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
, removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
or changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
,
depending on the type of document event.view
- the View to forward the event toev
- the DocumentEvent to forwardshape
- the current allocation of the Viewvf
- the ViewFactory used to create new Viewsprotected void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent ev, Shape shape)
ec
- the ElementChange that describes the changes to the elementev
- the DocumentEvent that describes the changes to the modelshape
- the current allocation for this viewpublic abstract Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
pos
- the position of the character in the modela
- the area that is occupied by the viewb
- either Position.Bias.Forward
or
Position.Bias.Backward
depending on the preferred
direction bias. If null
this defaults to
Position.Bias.Forward
BadLocationException
- if pos
is invalidIllegalArgumentException
- if b is not one of the above listed
valid valuespublic Shape modelToView(int p1, Position.Bias b1, int p2, Position.Bias b2, Shape a) throws BadLocationException
p1
- the beginning position inside the documentb1
- the direction bias for the beginning positionp2
- the end position inside the documentb2
- the direction bias for the end positiona
- the area that is occupied by the viewBadLocationException
- if p1
or p2
are
invalidIllegalArgumentException
- if b1 or b2 is not one of the above
listed valid valuespublic Shape modelToView(int pos, Shape a) throws BadLocationException
modelToView(int, Shape, Position.Bias)
instead.modelToView(int, Position.Bias, int, Position.Bias, Shape)
with
a bias of Position.Bias.Forward
.pos
- the position of the character in the modela
- the area that is occupied by the viewBadLocationException
- if pos
is invalidpublic abstract int viewToModel(float x, float y, Shape a, Position.Bias[] b)
View
's space into a position
in the document model.x
- the x coordinate in the view spacey
- the y coordinate in the view spacea
- the allocation of this View
b
- the bias to usex, y
public int viewToModel(float x, float y, Shape a)
viewToModel(float, float, Shape, Position.Bias[])
instead.View
's space into a position
in the document model. This method is deprecated and only there for
compatibility.x
- the x coordinate in the view spacey
- the y coordinate in the view spacea
- the allocation of this View
x, y
protected void dump()
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int d, Position.Bias[] biasRet) throws BadLocationException
pos
in the given direction d
.pos
- the document positionb
- the bias for pos
a
- the allocation for this viewd
- the direction, must be either SwingConstants.NORTH
,
SwingConstants.SOUTH
, SwingConstants.WEST
or
SwingConstants.EAST
biasRet
- an array of Position.Bias
that can hold at least
one element, which is filled with the bias of the return position
on method exitpos
in the given direction
d
BadLocationException
- if pos
is not a valid offset in
the document modelIllegalArgumentException
- if d
is not a valid direction