All Implemented Interfaces:
A very important part of the text package is the
As the name suggests it represents a view of the text model,
or a piece of the text model.
It is this class that is responsible for the look of the text component.
The view is not intended to be some completely new thing that one must
learn, but rather is much like a lightweight component.
By default, a view is very light. It contains a reference to the parent
view from which it can fetch many things without holding state, and it
contains a reference to a portion of the model (
A view does not
have to exactly represent an element in the model, that is simply a typical
and therefore convenient mapping. A view can alternatively maintain a couple
of Position objects to maintain its location in the model (i.e. represent
a fragment of an element). This is typically the result of formatting where
views have been broken down into pieces. The convenience of a substantial
relationship to the element makes it easier to build factories to produce the
views, and makes it easier to keep track of the view pieces as the model is
changed and the view must be changed to reflect the model. Simple views
therefore represent an Element directly and complex views do not.
A view has the following responsibilities:
The view has a
setSize method which is like
The view has a
preferenceChanged method which is
Component except that one can
invalidate just one axis
and the child requesting the change is identified.
A View expresses the size that it would like to be in terms of three values, a minimum, a preferred, and a maximum span. Layout in a view is can be done independently upon each axis. For a properly functioning View implementation, the minimum span will be <= the preferred span which in turn will be <= the maximum span.
The minimum set of methods for layout are:
setSize method should be prepared to be called a number of times
(i.e. It may be called even if the size didn't change).
is generally called to make sure the View layout is complete prior to trying
to perform an operation on it that requires an up-to-date layout. A view's
size should always be set to a value within the minimum and maximum
span specified by that view. Additionally, the view must always call the
preferenceChanged method on the parent if it has changed the
values for the
layout it would like, and expects the parent to honor. The parent View is
not required to recognize a change until the
has been sent.
This allows parent View implementations to cache the child requirements if
desired. The calling sequence looks something like the following:
The exact calling sequence is up to the layout functionality of the parent view (if the view has any children). The view may collect the preferences of the children prior to determining what it will give each child, or it might iteratively update the children one at a time.
This is done in the paint method, which is pretty much like a component
paint method. Views are expected to potentially populate a fairly large
View has the following semantics for rendering:
Componentreturned by the getContainer method). This means a child view lives in the same coordinate system as the parent view unless the parent has explicitly changed the coordinate system. To schedule itself to be repainted a view can call repaint on the hosting
Graphicsobject given is not initialized in any way. A view should set any settings needed.
Viewis inherently transparent. While a view may render into its entire allocation, typically a view does not. Rendering is performed by tranversing down the tree of
Viewis responsible for rendering its children. This behavior is depended upon for thread safety. While view implementations do not necessarily have to be implemented with thread safety in mind, other view implementations that do make use of concurrency can depend upon a tree traversal to guarantee thread safety.
The methods for rendering are:
Because the view objects are produced from a factory and therefore cannot necessarily be counted upon to be in a particular pattern, one must be able to perform translation to properly locate spatial representation of the model. The methods for doing this are:
The layout must be valid prior to attempting to make the translation.
The translation is not valid, and must not be attempted while changes
are being broadcasted from the model via a
If the overall view is represented by many pieces (which is the best situation
if one want to be able to change the view and write the least amount of new code),
it would be impractical to have a huge number of
view listened to the model, only a few would actually be interested in the
changes broadcasted at any given time. Since the model has no knowledge of
views, it has no way to filter the broadcast of change information. The view
hierarchy itself is instead responsible for propagating the change information.
At any level in the view hierarchy, that view knows enough about its children to
best distribute the change information further. Changes are therefore broadcasted
starting from the root of the view hierarchy.
The methods for doing this are:
|public static final int||BadBreakWeight||The weight to indicate a view is a bad break opportunity for the purpose of formatting. This value indicates that no attempt should be made to break the view into fragments as the view has not been written to support fragmenting.|
|public static final int||GoodBreakWeight||The weight to indicate a view supports breaking, but better opportunities probably exist.|
|public static final int||ExcellentBreakWeight||The weight to indicate a view supports breaking, and this represents a very attractive place to break.|
|public static final int||ForcedBreakWeight||The weight to indicate a view supports breaking, and must be broken to be represented properly when placed in a view that formats its children by breaking them.|
|public static final int||X_AXIS||Axis for format/break operations.|
|public static final int||Y_AXIS||Axis for format/break operations.|
|static final Bias||sharedBiasReturn|
public View(Element elem)
|Method from javax.swing.text.View Summary:|
|append, breakView, changedUpdate, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getPreferredSpan, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, modelToView, paint, preferenceChanged, remove, removeAll, removeUpdate, replace, setParent, setSize, updateChildren, updateLayout, viewToModel, viewToModel|
|Methods from java.lang.Object:|
|clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait|
|Method from javax.swing.text.View Detail:|
This is implemented to return the view itself, which represents the default behavior on not being breakable. If the view does support breaking, the starting offset of the view returned should be the given offset, and the end offset should be less than or equal to the end offset of the view being broken.
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
protected void forwardUpdate(ElementChange ec, DocumentEvent e, Shape a, ViewFactory f)
protected void forwardUpdateToView(View v, DocumentEvent e, Shape a, ViewFactory f)
public float getAlignment(int axis)
public AttributeSet getAttributes()
This is implemented to provide the default behavior
public Shape getChildAllocation(int index, Shape a)
public Container getContainer()
public Document getDocument()
public Element getElement()
public int getEndOffset()
public Graphics getGraphics()
public float getMaximumSpan(int axis)
public float getMinimumSpan(int axis)
public int getNextVisualPositionFrom(int pos, Bias b, Shape a, int direction, Bias biasRet) throws BadLocationException
public View getParent()
abstract public float getPreferredSpan(int axis)
public int getResizeWeight(int axis)
public int getStartOffset()
public String getToolTipText(float x, float y, Shape allocation)
public View getView(int n)
public int getViewCount()
public ViewFactory getViewFactory()
public int getViewIndex(int pos, Bias b)
public int getViewIndex(float x, float y, Shape allocation)
public void insert(int offs, View v)
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)
public boolean isVisible()
public Shape modelToView(int pos, Shape a) throws BadLocationExceptionDeprecated!
abstract public Shape modelToView(int pos, Shape a, Bias b) throws BadLocationException
public Shape modelToView(int p0, Bias b0, int p1, Bias b1, Shape a) throws BadLocationException
public void preferenceChanged(View child, boolean width, boolean height)
public void remove(int i)
public void removeAll()
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)
public void replace(int offset, int length, View views)
public void setParent(View parent)
public void setSize(float width, float height)
protected boolean updateChildren(ElementChange ec, DocumentEvent e, ViewFactory f)
protected void updateLayout(ElementChange ec, DocumentEvent e, Shape a)
public int viewToModel(float x, float y, Shape a)Deprecated!
abstract public int viewToModel(float x, float y, Shape a, Bias biasReturn)