| java.lang.Object javax.swing.text.View javax.swing.text.ComponentView
All known Subclasses: javax.swing.text.html.FrameView, javax.swing.text.html.ObjectView, javax.swing.text.html.IsindexView, javax.swing.text.html.FormView, javax.swing.text.html.EditableView,
ComponentView | public class ComponentView extends View (Code) | | Component decorator that implements the view interface. The
entire element is used to represent the component. This acts
as a gateway from the display-only View implementations to
interactive lightweight components (ie it allows components
to be embedded into the View hierarchy).
The component is placed relative to the text baseline
according to the value returned by
Component.getAlignmentY . For Swing components
this value can be conveniently set using the method
JComponent.setAlignmentY . For example, setting
a value of 0.75 will cause 75 percent of the
component to be above the baseline, and 25 percent of the
component to be below the baseline.
This class is implemented to do the extra work necessary to
work properly in the presence of multiple threads (i.e. from
asynchronous notification of model changes for example) by
ensuring that all component access is done on the event thread.
The component used is determined by the return value of the
createComponent method. The default implementation of this
method is to return the component held as an attribute of
the element (by calling StyleConstants.getComponent). A
limitation of this behavior is that the component cannot
be used by more than one text component (i.e. with a shared
model). Subclasses can remove this constraint by implementing
the createComponent to actually create a component based upon
some kind of specification contained in the attributes. The
ObjectView class in the html package is an example of a
ComponentView implementation that supports multiple component
views of a shared model.
author: Timothy Prinzing version: 1.60 05/05/07 |
Method Summary | |
protected Component | createComponent() Create the component that is associated with
this view. | public float | getAlignment(int axis) Determines the desired alignment for this view along an
axis. | final public Component | getComponent() Fetch the component associated with the view. | public float | getMaximumSpan(int axis) Determines the maximum span for this view along an
axis. | public float | getMinimumSpan(int axis) Determines the minimum span for this view along an
axis. | public float | getPreferredSpan(int axis) Determines the preferred span for this view along an
axis. | public Shape | modelToView(int pos, Shape a, Position.Bias b) Provides a mapping from the coordinate space of the model to
that of the view. | public void | paint(Graphics g, Shape a) The real paint behavior occurs naturally from the association
that the component has with its parent container (the same
container hosting this view). | void | setComponentParent() Set the parent of the embedded component
with assurance that it is thread-safe. | public void | setParent(View p) Sets the parent for a child view.
The parent calls this on the child to tell it who its
parent is, giving the view access to things like
the hosting Container. | public int | viewToModel(float x, float y, Shape a, Position.Bias[] bias) Provides a mapping from the view coordinate space to the logical
coordinate space of the model. |
ComponentView | public ComponentView(Element elem)(Code) | | Creates a new ComponentView object.
Parameters: elem - the element to decorate |
createComponent | protected Component createComponent()(Code) | | Create the component that is associated with
this view. This will be called when it has
been determined that a new component is needed.
This would result from a call to setParent or
as a result of being notified that attributes
have changed.
|
getAlignment | public float getAlignment(int axis)(Code) | | Determines the desired alignment for this view along an
axis. This is implemented to give the alignment of the
embedded component.
Parameters: axis - may be either View.X_AXIS or View.Y_AXIS the desired alignment. This should be a valuebetween 0.0 and 1.0 where 0 indicates alignment at theorigin and 1.0 indicates alignment to the full spanaway from the origin. An alignment of 0.5 would be thecenter of the view. |
getComponent | final public Component getComponent()(Code) | | Fetch the component associated with the view.
|
getMaximumSpan | public float getMaximumSpan(int axis)(Code) | | Determines the maximum span for this view along an
axis. This is implemented to return the value
returned by Component.getMaximumSize along the
axis of interest.
Parameters: axis - may be either View.X_AXIS or View.Y_AXIS the span the view would like to be rendered into >= 0.Typically the view is told to render into the spanthat is returned, although there is no guarantee. The parent may choose to resize or break the view. exception: IllegalArgumentException - for an invalid axis |
getMinimumSpan | public float getMinimumSpan(int axis)(Code) | | Determines the minimum span for this view along an
axis. This is implemented to return the value
returned by Component.getMinimumSize along the
axis of interest.
Parameters: axis - may be either View.X_AXIS or View.Y_AXIS the span the view would like to be rendered into >= 0.Typically the view is told to render into the spanthat is returned, although there is no guarantee. The parent may choose to resize or break the view. exception: IllegalArgumentException - for an invalid axis |
getPreferredSpan | public float getPreferredSpan(int axis)(Code) | | Determines the preferred span for this view along an
axis. This is implemented to return the value
returned by Component.getPreferredSize along the
axis of interest.
Parameters: axis - may be either View.X_AXIS or View.Y_AXIS the span the view would like to be rendered into >= 0.Typically the view is told to render into the spanthat is returned, although there is no guarantee.The parent may choose to resize or break the view. exception: IllegalArgumentException - for an invalid axis |
modelToView | public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException(Code) | | Provides a mapping from the coordinate space of the model to
that of the view.
Parameters: pos - the position to convert >= 0 Parameters: a - the allocated region to render into the bounding box of the given position is returned exception: BadLocationException - if the given position does notrepresent a valid location in the associated document See Also: View.modelToView |
paint | public void paint(Graphics g, Shape a)(Code) | | The real paint behavior occurs naturally from the association
that the component has with its parent container (the same
container hosting this view). This is implemented to do nothing.
Parameters: g - the graphics context Parameters: a - the shape See Also: View.paint |
setComponentParent | void setComponentParent()(Code) | | Set the parent of the embedded component
with assurance that it is thread-safe.
|
setParent | public void setParent(View p)(Code) | | Sets the parent for a child view.
The parent calls this on the child to tell it who its
parent is, giving the view access to things like
the hosting Container. The superclass behavior is
executed, followed by a call to createComponent if
the parent view parameter is non-null and a component
has not yet been created. The embedded components parent
is then set to the value returned by getContainer .
If the parent view parameter is null, this view is being
cleaned up, thus the component is removed from its parent.
The changing of the component hierarchy will
touch the component lock, which is the one thing
that is not safe from the View hierarchy. Therefore,
this functionality is executed immediately if on the
event thread, or is queued on the event queue if
called from another thread (notification of change
from an asynchronous update).
Parameters: p - the parent |
viewToModel | public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)(Code) | | Provides a mapping from the view coordinate space to the logical
coordinate space of the model.
Parameters: x - the X coordinate >= 0 Parameters: y - the Y coordinate >= 0 Parameters: a - the allocated region to render into the location within the model that best representsthe given point in the view See Also: View.viewToModel |
Methods inherited from javax.swing.text.View | public void append(View v)(Code)(Java Doc) public View breakView(int axis, int offset, float pos, float len)(Code)(Java Doc) public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)(Code)(Java Doc) public View createFragment(int p0, int p1)(Code)(Java Doc) protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory f)(Code)(Java Doc) protected void forwardUpdateToView(View v, DocumentEvent e, Shape a, ViewFactory f)(Code)(Java Doc) public float getAlignment(int axis)(Code)(Java Doc) public AttributeSet getAttributes()(Code)(Java Doc) public int getBreakWeight(int axis, float pos, float len)(Code)(Java Doc) public Shape getChildAllocation(int index, Shape a)(Code)(Java Doc) public Container getContainer()(Code)(Java Doc) public Document getDocument()(Code)(Java Doc) public Element getElement()(Code)(Java Doc) public int getEndOffset()(Code)(Java Doc) public Graphics getGraphics()(Code)(Java Doc) public float getMaximumSpan(int axis)(Code)(Java Doc) public float getMinimumSpan(int axis)(Code)(Java Doc) public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException(Code)(Java Doc) public View getParent()(Code)(Java Doc) abstract public float getPreferredSpan(int axis)(Code)(Java Doc) public int getResizeWeight(int axis)(Code)(Java Doc) public int getStartOffset()(Code)(Java Doc) public String getToolTipText(float x, float y, Shape allocation)(Code)(Java Doc) public View getView(int n)(Code)(Java Doc) public int getViewCount()(Code)(Java Doc) public ViewFactory getViewFactory()(Code)(Java Doc) public int getViewIndex(int pos, Position.Bias b)(Code)(Java Doc) public int getViewIndex(float x, float y, Shape allocation)(Code)(Java Doc) public void insert(int offs, View v)(Code)(Java Doc) public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)(Code)(Java Doc) public boolean isVisible()(Code)(Java Doc) abstract public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException(Code)(Java Doc) public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException(Code)(Java Doc) public Shape modelToView(int pos, Shape a) throws BadLocationException(Code)(Java Doc) abstract public void paint(Graphics g, Shape allocation)(Code)(Java Doc) public void preferenceChanged(View child, boolean width, boolean height)(Code)(Java Doc) public void remove(int i)(Code)(Java Doc) public void removeAll()(Code)(Java Doc) public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)(Code)(Java Doc) public void replace(int offset, int length, View[] views)(Code)(Java Doc) public void setParent(View parent)(Code)(Java Doc) public void setSize(float width, float height)(Code)(Java Doc) protected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f)(Code)(Java Doc) protected void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a)(Code)(Java Doc) abstract public int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn)(Code)(Java Doc) public int viewToModel(float x, float y, Shape a)(Code)(Java Doc)
|
|
|