APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text

public Class ComponentView

extends View
Class Inheritance
Known Direct Subclasses
javax.swing.text.html.EditableView, javax.swing.text.html.FormView, javax.swing.text.html.FrameView, javax.swing.text.html.IsindexView, javax.swing.text.html.ObjectView
Imports
java.awt.*, java.beans.PropertyChangeEvent, .PropertyChangeListener, java.util.Set, javax.swing.SwingUtilities, javax.swing.event.*

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
ComponentView.Invalidator

This class feeds the invalidate back to the hosting View.

Field Summary

Modifier and TypeField and Description
private ComponentView.Invalidator
c

private Component
Inherited from javax.swing.text.View:
BadBreakWeightExcellentBreakWeightfirstUpdateIndexForcedBreakWeightGoodBreakWeightlastUpdateIndexsharedBiasReturnX_AXISY_AXIS

Constructor Summary

AccessConstructor and Description
public
ComponentView(Element
the element to decorate
elem
)

Creates a new ComponentView object.

Method Summary

Modifier and TypeMethod and Description
protected Component

Returns:

the component that is associated with this view
createComponent
()

Create the component that is associated with this view.

public float

Returns:

the desired alignment. This should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin. An alignment of 0.5 would be the center of the view.
getAlignment
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getAlignment.

Determines the desired alignment for this view along an axis.

public final Component

Returns:

the component associated with the view
getComponent
()

Fetch the component associated with the view.

public float

Returns:

the span the view would like to be rendered into >=0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
getMaximumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getMaximumSpan.

Determines the maximum span for this view along an axis.

public float

Returns:

the span the view would like to be rendered into >=0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
getMinimumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getMinimumSpan.

Determines the minimum span for this view along an axis.

public float

Returns:

the span the view would like to be rendered into >=0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
getPreferredSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Implements abstract javax.swing.text.View.getPreferredSpan.

Determines the preferred span for this view along an axis.

public Shape

Returns:

the bounding box of the given position is returned
modelToView
(int
the position to convert >=0
pos
,
Shape
the allocated region to render into
a
,
Position.Bias b)

Implements abstract javax.swing.text.View.modelToView.

Provides a mapping from the coordinate space of the model to that of the view.

public void
paint(Graphics
the graphics context
g
,
Shape
the shape
a
)

Implements abstract javax.swing.text.View.paint.

The real paint behavior occurs naturally from the association that the component has with its parent container (the same container hosting this view).

pack-priv void
setComponentParent()

Set the parent of the embedded component with assurance that it is thread-safe.

public void
setParent(View
the parent
p
)

Overrides javax.swing.text.View.setParent.

Sets the parent for a child view.

public int

Returns:

the location within the model that best represents the given point in the view
viewToModel
(float
the X coordinate >=0
x
,
float
the Y coordinate >=0
y
,
Shape
the allocated region to render into
a
,
Position.Bias[] bias)

Implements abstract javax.swing.text.View.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Inherited from javax.swing.text.View:
appendbreakViewcalculateUpdateIndexeschangedUpdatecreateFragmentforwardUpdateforwardUpdateToViewgetAttributesgetBreakWeightgetChildAllocationgetContainergetDocumentgetElementgetEndOffsetgetGraphicsgetNextVisualPositionFromgetParentgetResizeWeightgetStartOffsetgetToolTipTextgetViewgetViewCountgetViewFactorygetViewIndexgetViewIndexinsertinsertUpdateisVisiblemodelToViewmodelToViewpreferenceChangedremoveremoveAllremoveUpdatereplacesetSizeupdateAfterChangeupdateChildrenupdateLayoutviewToModel

Field Detail

cback to summary
private ComponentView.Invalidator c
createdCback to summary
private Component createdC

Constructor Detail

ComponentViewback to summary
public ComponentView(Element elem)

Creates a new ComponentView object.

Parameters
elem:Element

the element to decorate

Method Detail

createComponentback to summary
protected Component createComponent()

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.

Returns:Component

the component that is associated with this view

getAlignmentback to summary
public float getAlignment(int axis)

Overrides javax.swing.text.View.getAlignment.

Determines the desired alignment for this view along an axis. This is implemented to give the alignment of the embedded component.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the desired alignment. This should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin. An alignment of 0.5 would be the center of the view.

getComponentback to summary
public final Component getComponent()

Fetch the component associated with the view.

Returns:Component

the component associated with the view

getMaximumSpanback to summary
public float getMaximumSpan(int axis)

Overrides javax.swing.text.View.getMaximumSpan.

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:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >=0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.

Exceptions
IllegalArgumentException:
for an invalid axis
getMinimumSpanback to summary
public float getMinimumSpan(int axis)

Overrides javax.swing.text.View.getMinimumSpan.

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:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >=0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.

Exceptions
IllegalArgumentException:
for an invalid axis
getPreferredSpanback to summary
public float getPreferredSpan(int axis)

Implements abstract javax.swing.text.View.getPreferredSpan.

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:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >=0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.

Exceptions
IllegalArgumentException:
for an invalid axis
modelToViewback to summary
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException

Implements abstract javax.swing.text.View.modelToView.

Provides a mapping from the coordinate space of the model to that of the view.

Parameters
pos:int

the position to convert >=0

a:Shape

the allocated region to render into

Returns:Shape

the bounding box of the given position is returned

Exceptions
BadLocationException:
if the given position does not represent a valid location in the associated document
See Also
View#modelToView
paintback to summary
public void paint(Graphics g, Shape a)

Implements abstract javax.swing.text.View.paint.

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:Graphics

the graphics context

a:Shape

the shape

See Also
View#paint
setComponentParentback to summary
pack-priv void setComponentParent()

Set the parent of the embedded component with assurance that it is thread-safe.

setParentback to summary
public void setParent(View p)

Overrides javax.swing.text.View.setParent.

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:View

the parent

viewToModelback to summary
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)

Implements abstract javax.swing.text.View.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Parameters
x:float

the X coordinate >=0

y:float

the Y coordinate >=0

a:Shape

the allocated region to render into

Returns:int

the location within the model that best represents the given point in the view

See Also
View#viewToModel
javax.swing.text back to summary

pack-priv Class ComponentView.Invalidator

extends Container
implements PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener
Annotations
@SuppressWarnings:serial

This class feeds the invalidate back to the hosting View. This is needed to get the View hierarchy to consider giving the component a different size (i.e. layout may have been cached between the associated view and the container hosting this component).

Field Summary

Modifier and TypeField and Description
pack-priv Dimension
pack-priv Dimension
pack-priv Dimension
pack-priv float
pack-priv float

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
public void
doLayout()

Overrides java.awt.Container.doLayout.

Causes this container to lay out its components.

public float
getAlignmentX()

Overrides java.awt.Container.getAlignmentX.

Returns the alignment along the x axis.

public float
getAlignmentY()

Overrides java.awt.Container.getAlignmentY.

Returns the alignment along the y axis.

public Set<AWTKeyStroke>
getFocusTraversalKeys(int id)

Overrides java.awt.Container.getFocusTraversalKeys.

Returns the Set of focus traversal keys for a given traversal operation for this Container.

public Dimension
getMaximumSize()

Overrides java.awt.Container.getMaximumSize.

Returns the maximum size of this container.

public Dimension
getMinimumSize()

Overrides java.awt.Container.getMinimumSize.

Returns the minimum size of this container.

public Dimension
getPreferredSize()

Overrides java.awt.Container.getPreferredSize.

Returns the preferred size of this container.

public void
invalidate()

Overrides java.awt.Container.invalidate.

The components invalid layout needs to be propagated through the view hierarchy so the views (which position the component) can have their layout recomputed.

public boolean
isShowing()

Overrides java.awt.Component.isShowing.

Overridden to fix 4759054.

public void
propertyChange(PropertyChangeEvent ev)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

public void
setBounds(int x, int y, int w, int h)

Overrides java.awt.Component.setBounds.

Moves and resizes this component.

public void
setVisible(boolean
If true, shows this component; otherwise, hides this component.
b
)

Overrides java.awt.Component.setVisible.

Shows or hides this component depending on the value of parameter b.

public void
Inherited from java.awt.Container:
addaddaddaddaddaddContainerListeneraddImpladdNotifyaddPropertyChangeListeneraddPropertyChangeListenerapplyComponentOrientationareFocusTraversalKeysSetcountComponentsdeliverEventfindComponentAtfindComponentAtgetComponentgetComponentAtgetComponentAtgetComponentCountgetComponentsgetComponentZOrdergetContainerListenersgetFocusTraversalPolicygetInsetsgetLayoutgetListenersgetMousePositioninsetsisAncestorOfisFocusCycleRootisFocusCycleRootisFocusTraversalPolicyProviderisFocusTraversalPolicySetisValidateRootlayoutlistlistlocateminimumSizepaintpaintComponentsparamStringpreferredSizeprintprintComponentsprocessContainerEventprocessEventremoveremoveremoveAllremoveContainerListenerremoveNotifysetComponentZOrdersetFocusCycleRootsetFocusTraversalKeyssetFocusTraversalPolicysetFocusTraversalPolicyProvidersetFontsetLayouttransferFocusDownCycleupdatevalidatevalidateTree

Field Detail

maxback to summary
pack-priv Dimension max
minback to summary
pack-priv Dimension min
prefback to summary
pack-priv Dimension pref
xalignback to summary
pack-priv float xalign
yalignback to summary
pack-priv float yalign

Constructor Detail

Invalidatorback to summary
pack-priv Invalidator(Component child)

Method Detail

cacheChildSizesback to summary
private void cacheChildSizes()
doLayoutback to summary
public void doLayout()

Overrides java.awt.Container.doLayout.

Doc from java.awt.Container.doLayout.

Causes this container to lay out its components. Most programs should not call this method directly, but should invoke the validate method instead.

getAlignmentXback to summary
public float getAlignmentX()

Overrides java.awt.Container.getAlignmentX.

Doc from java.awt.Container.getAlignmentX.

Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

getAlignmentYback to summary
public float getAlignmentY()

Overrides java.awt.Container.getAlignmentY.

Doc from java.awt.Container.getAlignmentY.

Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

getFocusTraversalKeysback to summary
public Set<AWTKeyStroke> getFocusTraversalKeys(int id)

Overrides java.awt.Container.getFocusTraversalKeys.

Doc from java.awt.Container.getFocusTraversalKeys.

Returns the Set of focus traversal keys for a given traversal operation for this Container. (See setFocusTraversalKeys for a full description of each key.)

If a Set of traversal keys has not been explicitly defined for this Container, then this Container's parent's Set is returned. If no Set has been explicitly defined for any of this Container's ancestors, then the current KeyboardFocusManager's default Set is returned.

getMaximumSizeback to summary
public Dimension getMaximumSize()

Overrides java.awt.Container.getMaximumSize.

Doc from java.awt.Container.getMaximumSize.

Returns the maximum size of this container. If the maximum size has not been set explicitly by Component#setMaximumSize(Dimension) and the LayoutManager installed on this Container is an instance of LayoutManager2, then LayoutManager2#maximumLayoutSize(Container) is used to calculate the maximum size.

Note

some implementations may cache the value returned from the LayoutManager2. Implementations that cache need not invoke maximumLayoutSize on the LayoutManager2 every time this method is invoked, rather the LayoutManager2 will only be queried after the Container becomes invalid.

getMinimumSizeback to summary
public Dimension getMinimumSize()

Overrides java.awt.Container.getMinimumSize.

Doc from java.awt.Container.getMinimumSize.

Returns the minimum size of this container. If the minimum size has not been set explicitly by Component#setMinimumSize(Dimension) and this Container has a non-null LayoutManager, then LayoutManager#minimumLayoutSize(Container) is used to calculate the minimum size.

Note

some implementations may cache the value returned from the LayoutManager. Implementations that cache need not invoke minimumLayoutSize on the LayoutManager every time this method is invoked, rather the LayoutManager will only be queried after the Container becomes invalid.

getPreferredSizeback to summary
public Dimension getPreferredSize()

Overrides java.awt.Container.getPreferredSize.

Doc from java.awt.Container.getPreferredSize.

Returns the preferred size of this container. If the preferred size has not been set explicitly by Component#setPreferredSize(Dimension) and this Container has a non-null LayoutManager, then LayoutManager#preferredLayoutSize(Container) is used to calculate the preferred size.

Note

some implementations may cache the value returned from the LayoutManager. Implementations that cache need not invoke preferredLayoutSize on the LayoutManager every time this method is invoked, rather the LayoutManager will only be queried after the Container becomes invalid.

invalidateback to summary
public void invalidate()

Overrides java.awt.Container.invalidate.

The components invalid layout needs to be propagated through the view hierarchy so the views (which position the component) can have their layout recomputed.

isShowingback to summary
public boolean isShowing()

Overrides java.awt.Component.isShowing.

Overridden to fix 4759054. Must return true so that content is painted when inside a CellRendererPane which is normally invisible.

propertyChangeback to summary
public void propertyChange(PropertyChangeEvent ev)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

setBoundsback to summary
public void setBounds(int x, int y, int w, int h)

Overrides java.awt.Component.setBounds.

Doc from java.awt.Component.setBounds.

Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

setVisibleback to summary
public void setVisible(boolean b)

Overrides java.awt.Component.setVisible.

Shows or hides this component depending on the value of parameter b.

Parameters
b:boolean

If true, shows this component; otherwise, hides this component.

Since
1.1
See Also
isVisible
validateIfNecessaryback to summary
public void validateIfNecessary()