- java.lang.Object
-
- javax.swing.text.View
-
- javax.swing.text.CompositeView
-
- javax.swing.text.BoxView
-
- javax.swing.text.ZoneView
-
- All Implemented Interfaces:
- SwingConstants
public class ZoneView extends BoxView
ZoneView is a View implementation that creates zones for which the child views are not created or stored until they are needed for display or model/view translations. This enables a substantial reduction in memory consumption for situations where the model being represented is very large, by building view objects only for the region being actively viewed/edited. The size of the children can be estimated in some way, or calculated asynchronously with only the result being saved.ZoneView extends BoxView to provide a box that implements zones for its children. The zones are special View implementations (the children of an instance of this class) that represent only a portion of the model that an instance of ZoneView is responsible for. The zones don't create child views until an attempt is made to display them. A box shaped view is well suited to this because:
- Boxes are a heavily used view, and having a box that provides this behavior gives substantial opportunity to plug the behavior into a view hierarchy from the view factory.
- Boxes are tiled in one direction, so it is easy to divide them into zones in a reliable way.
- Boxes typically have a simple relationship to the model (i.e. they create child views that directly represent the child elements).
- Boxes are easier to estimate the size of than some other shapes.
The default behavior is controled by two properties, maxZoneSize and maxZonesLoaded. Setting maxZoneSize to Integer.MAX_VALUE would have the effect of causing only one zone to be created. This would effectively turn the view into an implementation of the decorator pattern. Setting maxZonesLoaded to a value of Integer.MAX_VALUE would cause zones to never be unloaded. For simplicity, zones are created on boundaries represented by the child elements of the element the view is responsible for. The zones can be any View implementation, but the default implementation is based upon AsyncBoxView which supports fairly large zones efficiently.
- Since:
- 1.3
- See Also:
View
-
-
Field Summary
-
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, 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
Constructors Constructor and Description ZoneView(Element elem, int axis)
Constructs a ZoneView.
-
Method Summary
Methods Modifier and Type Method and Description protected View
createZone(int p0, int p1)
Create a view to represent a zone for the given range within the model (which should be within the range of this objects responsibility).int
getMaximumZoneSize()
Get the current maximum zone size.int
getMaxZonesLoaded()
Get the current setting of the number of zones allowed to be loaded at the same time.protected int
getViewIndexAtPosition(int pos)
Returns the child view index representing the given position in the model.void
insertUpdate(DocumentEvent changes, Shape a, ViewFactory f)
Gives notification that something was inserted into the document in a location that this view is responsible for.protected boolean
isZoneLoaded(View zone)
Determine if a zone is in the loaded state.protected void
loadChildren(ViewFactory f)
Loads all of the children to initialize the view.void
removeUpdate(DocumentEvent changes, Shape a, ViewFactory f)
Gives notification that something was removed from the document in a location that this view is responsible for.void
setMaximumZoneSize(int size)
Set the desired maximum zone size.void
setMaxZonesLoaded(int mzl)
Sets the current setting of the number of zones allowed to be loaded at the same time.protected void
unloadZone(View zone)
Unload a zone (Convert the zone to its memory saving state).protected boolean
updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f)
The superclass behavior will try to update the child views which is not desired in this case, since the children are zones and not directly effected by the changes to the associated element.protected void
zoneWasLoaded(View zone)
Called by a zone when it gets loaded.-
Methods inherited from class javax.swing.text.BoxView
baselineLayout, baselineRequirements, calculateMajorAxisRequirements, calculateMinorAxisRequirements, childAllocation, flipEastAndWestAtEnds, forwardUpdate, getAlignment, getAxis, getChildAllocation, getHeight, getMaximumSpan, getMinimumSpan, getOffset, getPreferredSpan, getResizeWeight, getSpan, getViewAtPoint, getWidth, isAfter, isAllocationValid, isBefore, isLayoutValid, layout, layoutChanged, layoutMajorAxis, layoutMinorAxis, modelToView, paint, paintChild, preferenceChanged, replace, setAxis, setSize, viewToModel
-
Methods inherited from class javax.swing.text.CompositeView
getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewAtPosition, getViewCount, getViewIndex, modelToView, setInsets, setParagraphInsets, setParent
-
Methods inherited from class javax.swing.text.View
append, breakView, changedUpdate, createFragment, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, isVisible, modelToView, remove, removeAll, updateLayout, viewToModel
-
-
-
-
Constructor Detail
-
ZoneView
public ZoneView(Element elem, int axis)
Constructs a ZoneView.- Parameters:
elem
- the element this view is responsible foraxis
- either View.X_AXIS or View.Y_AXIS
-
-
Method Detail
-
getMaximumZoneSize
public int getMaximumZoneSize()
Get the current maximum zone size.
-
setMaximumZoneSize
public void setMaximumZoneSize(int size)
Set the desired maximum zone size. A zone may get larger than this size if a single child view is larger than this size since zones are formed on child view boundaries.- Parameters:
size
- the number of characters the zone may represent before attempting to break the zone into a smaller size.
-
getMaxZonesLoaded
public int getMaxZonesLoaded()
Get the current setting of the number of zones allowed to be loaded at the same time.
-
setMaxZonesLoaded
public void setMaxZonesLoaded(int mzl)
Sets the current setting of the number of zones allowed to be loaded at the same time. This will throw anIllegalArgumentException
ifmzl
is less than 1.- Parameters:
mzl
- the desired maximum number of zones to be actively loaded, must be greater than 0- Throws:
IllegalArgumentException
- ifmzl
is < 1
-
zoneWasLoaded
protected void zoneWasLoaded(View zone)
Called by a zone when it gets loaded. This happens when an attempt is made to display or perform a model/view translation on a zone that was in an unloaded state. This is imlemented to check if the maximum number of zones was reached and to unload the oldest zone if so.- Parameters:
zone
- the child view that was just loaded.
-
unloadZone
protected void unloadZone(View zone)
Unload a zone (Convert the zone to its memory saving state). The zones are expected to represent a subset of the child elements of the element this view is responsible for. Therefore, the default implementation is to simple remove all the children.- Parameters:
zone
- the child view desired to be set to an unloaded state.
-
isZoneLoaded
protected boolean isZoneLoaded(View zone)
Determine if a zone is in the loaded state. The zones are expected to represent a subset of the child elements of the element this view is responsible for. Therefore, the default implementation is to return true if the view has children.
-
createZone
protected View createZone(int p0, int p1)
Create a view to represent a zone for the given range within the model (which should be within the range of this objects responsibility). This is called by the zone management logic to create new zones. Subclasses can provide a different implementation for a zone by changing this method.- Parameters:
p0
- the start of the desired zone. This should be >= getStartOffset() and < getEndOffset(). This value should also be < p1.p1
- the end of the desired zone. This should be > getStartOffset() and <= getEndOffset(). This value should also be > p0.
-
loadChildren
protected void loadChildren(ViewFactory f)
Loads all of the children to initialize the view. This is called by thesetParent
method. This is reimplemented to not load any children directly (as they are created by the zones). This method creates the initial set of zones. Zones don't actually get populated however until an attempt is made to display them or to do model/view coordinate translation.- Overrides:
loadChildren
in classCompositeView
- Parameters:
f
- the view factory- See Also:
CompositeView.setParent(javax.swing.text.View)
-
getViewIndexAtPosition
protected int getViewIndexAtPosition(int pos)
Returns the child view index representing the given position in the model.- Overrides:
getViewIndexAtPosition
in classCompositeView
- Parameters:
pos
- the position >= 0- Returns:
- index of the view representing the given position, or -1 if no view represents that position
-
updateChildren
protected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f)
The superclass behavior will try to update the child views which is not desired in this case, since the children are zones and not directly effected by the changes to the associated element. This is reimplemented to do nothing and return false.- Overrides:
updateChildren
in classView
- Parameters:
ec
- the change information for the element this view is responsible for. This should not benull
if this method gets callede
- the change information from the associated documentf
- the factory to use to build child views- Returns:
- whether or not the child views represent the child elements of the element this view is responsible for. Some views create children that represent a portion of the element they are responsible for, and should return false. This information is used to determine if views in the range of the added elements should be forwarded to or not
- See Also:
View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
,View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
,View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
-
insertUpdate
public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f)
Gives notification that something was inserted into the document in a location that this view is responsible for. This is largely delegated to the superclass, but is reimplemented to update the relevant zone (i.e. determine if a zone needs to be split into a set of 2 or more zones).- Overrides:
insertUpdate
in classView
- Parameters:
changes
- the change information from the associated documenta
- the current allocation of the viewf
- the factory to use to rebuild if the view has children- See Also:
View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
-
removeUpdate
public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f)
Gives notification that something was removed from the document in a location that this view is responsible for. This is largely delegated to the superclass, but is reimplemented to update the relevant zones (i.e. determine if zones need to be removed or joined with another zone).- Overrides:
removeUpdate
in classView
- Parameters:
changes
- the change information from the associated documenta
- the current allocation of the viewf
- the factory to use to rebuild if the view has children- See Also:
View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
25/11/2024 04:08:58 Cette version de la page est en cache (à la date du 25/11/2024 04:08:58) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/text/ZoneView.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.