Class WrappingProvider
- All Implemented Interfaces:
Serializable
,UIDependent
,RolloverRenderer
IconValue
s and
StringValue, respectively.
An example of how to configure a file tree by using the system icons and display names
TreeCellRenderer r = new DefaultTreeRenderer(
IconValues.FILE_ICON, StringValues.FILE_NAME);
tree.setCellRenderer(r);
treeTable.setTreeCellRenderer(r);
PENDING: ui specific focus rect variation (draw rect around icon) missing- See Also:
-
Field Summary
FieldsFields inherited from class org.jdesktop.swingx.renderer.ComponentProvider
alignment, defaultVisuals, iconValue, rendererComponent, stringValue
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a WrappingProvider with default delegate provider.WrappingProvider
(ComponentProvider<?> delegate) Instantiates a WrappingProvider with the given delegate provider for the node content.WrappingProvider
(ComponentProvider<?> delegate, boolean unwrapUserObject) Instantiates a WrappingProvider with the given delegate provider for the node content and unwrapUserObject property.WrappingProvider
(IconValue iconValue) Instantiates a WrappingProvider with default wrappee.WrappingProvider
(IconValue iv, ComponentProvider<?> delegate, boolean unwrapUserObject) Instantiates a WrappingProvider with the given delegate provider for the node content and unwrapUserObject property.WrappingProvider
(IconValue iconValue, StringValue wrappeeStringValue) Instantiates a WrappingProvider with default wrappee, configured to use the wrappeeStringValue.WrappingProvider
(IconValue iv, StringValue delegateStringValue, boolean unwrapUserObject) Instantiates a WrappingProvider with the given delegate provider for the node content and unwrapUserObject property.WrappingProvider
(StringValue wrappeeStringValue) Instantiates a WrappingProvider with default wrappee configured with the given StringValue. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
adjustContextValue
(CellContext context) Replace the context's value with the userobject if the value is a type supporting the notion of userObject and this provider's unwrapUserObject property is true.protected void
configureState
(CellContext context) Configures the rendering component's state from the given cell context.protected WrappingIconPanel
Factory method to create and return the component to use for rendering.void
doClick()
Same as AbstractButton.doClick().protected void
format
(CellContext context) Formats the renderering component's content from the given cell context.boolean
getRendererComponent
(CellContext context) Configures and returns an appropriate component to render a cell in the given context.Returns a string representation of the content.protected Object
getUnwrappedValue
(Object value) Returns the value as it should be passed to the delegate.boolean
Returns a boolean indicating whether this provider tries to unwrap a userObject from a tree/table/node type value before delegating the context.protected Icon
getValueAsIcon
(CellContext context) Returns a Icon representation of the content.Returns the delegate provider used to render the node content.boolean
protected void
restoreContextValue
(CellContext context, Object oldValue) Restores the context value to the old value.void
setExtendsComponentOpacity
(boolean extendsComponentOpacity) Sets a boolean indicating whether or not the main component's opacity should be applied to the Icon region.void
setUnwrapUserObject
(boolean unwrap) Sets the unwrapUserObject property.void
setWrappee
(ComponentProvider<?> delegate) Sets the given provider as delegate for the node content.Methods inherited from class org.jdesktop.swingx.renderer.ComponentProvider
configureContent, configureVisuals, createDefaultVisuals, getDefaultVisuals, getHorizontalAlignment, getStringValue, getValueAsString, setHorizontalAlignment, setIconValue, setStringValue, updateUI
-
Field Details
-
wrappee
-
-
Constructor Details
-
WrappingProvider
public WrappingProvider()Instantiates a WrappingProvider with default delegate provider. -
WrappingProvider
Instantiates a WrappingProvider with default wrappee, configured to use the wrappeeStringValue. Uses the given IconValue to configure the icon.- Parameters:
iconValue
- the IconValue to use for configuring the icon.wrappeeStringValue
- the StringValue to use in the wrappee.
-
WrappingProvider
Instantiates a WrappingProvider with default wrappee. Uses the given IconValue to configure the icon.- Parameters:
iconValue
- the IconValue to use for configuring the icon.
-
WrappingProvider
Instantiates a WrappingProvider with default wrappee configured with the given StringValue. PENDING: we have a slight semantic glitch compared to super because the given StringValue is not for use in this provider but for use in the wrappee!- Parameters:
wrappeeStringValue
- the StringValue to use in the wrappee.
-
WrappingProvider
Instantiates a WrappingProvider with the given delegate provider for the node content. If null, a default LabelProvider will be used.- Parameters:
delegate
- the provider to use as delegate
-
WrappingProvider
Instantiates a WrappingProvider with the given delegate provider for the node content and unwrapUserObject property. If the delegate is null, a default LabelProvider will be used.- Parameters:
delegate
- the provider to use as delegateunwrapUserObject
- a flag indicating whether this provider should auto-unwrap the userObject from the context value.
-
WrappingProvider
Instantiates a WrappingProvider with the given delegate provider for the node content and unwrapUserObject property. If the delegate is null, a default LabelProvider will be used.- Parameters:
iv
- the icon converter to use for this providerdelegate
- the provider to use as delegateunwrapUserObject
- a flag indicating whether this provider should auto-unwrap the userObject from the context value.
-
WrappingProvider
Instantiates a WrappingProvider with the given delegate provider for the node content and unwrapUserObject property. If the delegate is null, a default LabelProvider will be used.- Parameters:
iv
- the icon converter to use for this providerdelegateStringValue
- the StringValue to use in the wrappee.unwrapUserObject
- a flag indicating whether this provider should auto-unwrap the userObject from the context value.
-
-
Method Details
-
setWrappee
Sets the given provider as delegate for the node content. If the delegate is null, a default LabelProvider is set.PENDING: rename to setDelegate?
- Parameters:
delegate
- the provider to use as delegate.
-
getWrappee
Returns the delegate provider used to render the node content.- Returns:
- the provider used for rendering the node content.
-
setUnwrapUserObject
public void setUnwrapUserObject(boolean unwrap) Sets the unwrapUserObject property. If true, this provider replaces a context value of type XXNode with its user object before delegating to the wrappee. Otherwise the value is passed as-is always.The default value is true.
- Parameters:
unwrap
-- See Also:
-
getUnwrapUserObject
public boolean getUnwrapUserObject()Returns a boolean indicating whether this provider tries to unwrap a userObject from a tree/table/node type value before delegating the context.- Returns:
- a flag indicating the auto-unwrap property.
- See Also:
-
getString
Returns a string representation of the content.This method guarantees to return the same string representation as would appear in the renderer, given that the corresponding cellContext has the same value as the parameter passed-in here. That is (assuming that the rendering component has a getText())
This implementation simply delegates to its StringValue. Subclasses might need to override to comply.if (equals(value, context.getValue()) { assertEquals(provider.getString(value), provider.getRenderingComponent(context).getText()); }
This is a second attempt - the driving force is the need for a consistent string representation across all (new and old) themes: rendering, (pattern) filtering/highlighting, searching, auto-complete ...
Overridden to comply to contract: returns the string representation as provided by the wrappee (as this level has no string rep). Must do the same unwrapping magic as in configuring the rendering component if the unwrapUserObject property is true.
- Overrides:
getString
in classComponentProvider<WrappingIconPanel>
- Parameters:
value
- the Object to get a String representation for.- Returns:
- a appropriate string representation of the cell's content.
- See Also:
-
setExtendsComponentOpacity
public void setExtendsComponentOpacity(boolean extendsComponentOpacity) Sets a boolean indicating whether or not the main component's opacity should be applied to the Icon region.The default value is false. This covers the main use case in a JTree.
- Parameters:
extendsComponentOpacity
-
-
getExtendsComponentOpacity
public boolean getExtendsComponentOpacity()- Returns:
- the extendsComponentOpacity
-
getUnwrappedValue
Returns the value as it should be passed to the delegate. If the unwrapUserObject property is true, tries return a userObject as appropriate for the value type. Returns the given value itself, ff the property is false or the type does not support the notion of userObjectHere: unwraps userObject of DefaultMutableTreeNode and TreeTableNode.
- Parameters:
value
- the value to possibly unwrap- Returns:
- the userObject if the value has an appropriate type and the unwrapUserObject property is true, otherwise returns the value unchanged.
- See Also:
-
getRendererComponent
Configures and returns an appropriate component to render a cell in the given context. If the context is null, returns the component in its current state.- Overrides:
getRendererComponent
in classComponentProvider<WrappingIconPanel>
- Parameters:
context
- the cell context to configure from- Returns:
- a component to render a cell in the given context.
-
restoreContextValue
Restores the context value to the old value.- Parameters:
context
- the CellContext to restore.oldValue
- the value to restore the context to.
-
adjustContextValue
Replace the context's value with the userobject if the value is a type supporting the notion of userObject and this provider's unwrapUserObject property is true. Otherwise does nothing.Subclasses may override but must guarantee to return the original value for restoring.
- Parameters:
context
- the context to adjust- Returns:
- the old context value
- See Also:
-
configureState
Description copied from class:ComponentProvider
Configures the rendering component's state from the given cell context.- Specified by:
configureState
in classComponentProvider<WrappingIconPanel>
- Parameters:
context
- the cell context to configure from, must not be null.
-
createRendererComponent
Description copied from class:ComponentProvider
Factory method to create and return the component to use for rendering.- Specified by:
createRendererComponent
in classComponentProvider<WrappingIconPanel>
- Returns:
- the component to use for rendering.
-
format
Formats the renderering component's content from the given cell context.Here: implemented to set the icon.
- Specified by:
format
in classComponentProvider<WrappingIconPanel>
- Parameters:
context
- the cell context to configure from, must not be null.
-
getValueAsIcon
Returns a Icon representation of the content.This method messages the
IconValue
to get the Icon rep. Meant as a convenience for subclasses.Overridden to fallback to the default icons supplied by the context if super returns null.
- Overrides:
getValueAsIcon
in classComponentProvider<WrappingIconPanel>
- Parameters:
context
- the cell context, must not be null.- Returns:
- a appropriate icon representation of the cell's content, or null if non if available.
-
doClick
public void doClick()Same as AbstractButton.doClick(). It's up to client code to prepare the renderer's component before calling this method.- Specified by:
doClick
in interfaceRolloverRenderer
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabled
in interfaceRolloverRenderer
- Returns:
- true if rollover effects are on and clickable.
-