javax.swing.text

Class View

Implemented Interfaces:
SwingConstants
Known Direct Subclasses:
ComponentView, CompositeView, GlyphView, IconView, PlainView

public abstract class View
extends Object
implements SwingConstants

Field Summary

static int
BadBreakWeight
static int
ExcellentBreakWeight
static int
ForcedBreakWeight
static int
GoodBreakWeight
static int
X_AXIS
static int
Y_AXIS

Fields inherited from interface 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

Constructor Summary

View(Element elem)
Creates a new View instance.

Method Summary

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
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)
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)
float
getMinimumSpan(int 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)
int
getResizeWeight(int axis)
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 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.
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.
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)
void
setParent(View parent)
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.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

BadBreakWeight

public static final int BadBreakWeight
Field Value:
0

ExcellentBreakWeight

public static final int ExcellentBreakWeight
Field Value:
2000

ForcedBreakWeight

public static final int ForcedBreakWeight
Field Value:
3000

GoodBreakWeight

public static final int GoodBreakWeight
Field Value:
1000

X_AXIS

public static final int X_AXIS
Field Value:
0

Y_AXIS

public static final int Y_AXIS
Field Value:
1

Constructor Details

View

public View(Element elem)
Creates a new View instance.
Parameters:
elem - an Element value

Method Details

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)

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 forwardUpdateToView(View,DocumentEvent,Shape,ViewFactory) for each View that must be forwarded to.
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 insertUpdate(DocumentEvent,Shape,ViewFactory), removeUpdate(DocumentEvent,Shape,ViewFactory) or changedUpdate(DocumentEvent,Shape,ViewFactory), 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)

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)

getMinimumSpan

public float getMinimumSpan(int axis)

getNextVisualPositionFrom

public int getNextVisualPositionFrom(int pos,
                                     Position.Bias b,
                                     Shape a,
                                     int d,
                                     Position.Bias[] biasRet)
            throws BadLocationException
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 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 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)

getResizeWeight

public int getResizeWeight(int 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 Shape modelToView(int pos,
                         Shape a)
            throws BadLocationException

Deprecated. Use 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 modelToView(int,Position.Bias,int,Position.Bias,Shape) with a bias of 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

modelToView

public abstract Shape modelToView(int pos,
                                  Shape a,
                                  Position.Bias b)
            throws BadLocationException
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 Position.Bias.Forward or 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)
            throws BadLocationException
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

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)

setParent

public void setParent(View parent)

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 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.
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 int viewToModel(float x,
                       float y,
                       Shape a)

Deprecated. Use 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

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

View.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.