Package com.atlassian.adf.model.node
Class MediaSingle
- java.lang.Object
-
- com.atlassian.adf.model.node.AbstractNode<N>
-
- com.atlassian.adf.model.node.AbstractMarkedNode<MediaSingle,MediaSingleMark>
-
- com.atlassian.adf.model.node.MediaSingle
-
- All Implemented Interfaces:
Element,Node,DocContent,LayoutColumnContent,ListItemContent,Marked<MediaSingle,MediaSingleMark>,NestedExpandContent,NonNestableBlockContent,TableCellContent
public class MediaSingle extends AbstractMarkedNode<MediaSingle,MediaSingleMark> implements DocContent, LayoutColumnContent, ListItemContent, NestedExpandContent, NonNestableBlockContent, TableCellContent
A container for exactly one media item, optionally followed by acaption. This node enables the display of the content in full, in contrast to amediaGroupthat is intended for a list of attachments. A common use case is to display an image, but it can also be used for videos, or other types of content usually renderable by an@atlaskit/mediacard component.Example
Java
mediaSingle() .center() .width(50.0) .media( Media.Media.fileMedia()() fileMedia}() .id("ABC-123") .collection("some-collection-id") .occurrenceKey("some-occurrence-key") .size(640, 480) );ADF
{ "type": "mediaSingle", "content": [ { "type": "media", "attrs": { "width": 640, "height": 480, "id": "ABC-123", "type": "file", "collection": "some-collection-id", "occurrenceKey": "some-occurrence-key" } } ], "attrs": { "layout": "center", "width": 50.0 } }Implementation Note
Although `mediaSingle` uses the `content` section to wrap other nodes, its behaviour is very different from most other content nodes in that it can only contain exactly one or two nodes, the first node must be amedianode, and (when present) the second node must be acaption. This makes it really hard to do anything useful with the type system, so rather than do something really awkward, this class just doesn't bother to implementContentNodeat all.- See Also:
- Node - mediaSingle
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMediaSingle.PartialTypes that represent a partially constructedmediaSingle.static classMediaSingle.WidthTypeDetermines whether thewidthattribute should be interpreted as a percentage or pixel count.-
Nested classes/interfaces inherited from class com.atlassian.adf.model.node.AbstractNode
AbstractNode.ToStringHelper
-
-
Field Summary
-
Fields inherited from class com.atlassian.adf.model.node.AbstractMarkedNode
marks
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MediaSinglealignEnd()MediaSinglealignStart()Stream<Node>allNodes()This mimics the behavior ofContentNode.allNodes(), for convenience.<T extends Node>
Stream<T>allNodesOfType(Class<T> nodeClass)This mimics the behavior ofContentNode.allNodesOfType(Class).<T extends Node>
List<T>allNodesOfTypeAsList(Class<T> nodeClass)This mimics the behavior ofContentNode.allNodesOfTypeAsList(Class).protected voidappendMarkedNodeFields(AbstractNode.ToStringHelper buf)voidappendPlainText(StringBuilder sb)Renders this node as plain-text suitable for viewing by end users.Optional<Caption>caption()Returns the caption for the media item, if set.MediaSinglecaption(Caption caption)MediaSinglecaption(CaptionContent captionContent)MediaSinglecaption(CaptionContent... captionContent)MediaSinglecaption(Iterable<? extends CaptionContent> captionContent)MediaSinglecaption(String captionContent)MediaSinglecaption(String... captionContent)MediaSinglecaption(Stream<? extends CaptionContent> captionContent)MediaSinglecenter()MediaSinglecopy()Returns a deep copy of this element, including copies of any nodes or marks that it contains.StringelementType()Thetypevalue that identifies this element, such as"paragraph"or"strong".MediaSinglefullWidth()RichMedia.Layoutlayout()Returns theRichMedia.Layoutsetting for this single media item.MediaSinglelayout(RichMedia.Layout layout)MediaSinglelayout(String layout)Optional<Link>link()MediaSinglelink(Link link)MediaSinglelink(String href)MediaSinglemark(MediaSingleMark mark)Adds the given mark to this marked node.Class<MediaSingleMark>markClass()Returns the type of marks that may be applied to this node.protected booleanmarkedNodeEquals(MediaSingle other)protected intmarkedNodeHashCode()Mediamedia()MediaSinglemedia(Media media)static MediaSingle.Partial.NeedsMediamediaSingle()static MediaSinglemediaSingle(Media media)static MediaSingle.Partial.NeedsMediamediaSingle(RichMedia.Layout layout)Creates a new partially constructedmediaSinglenode with the given layout.static MediaSinglemediaSingle(RichMedia.Layout layout, Media media)Creates a newmediaSinglenode with the given layout and media item.static MediaSinglemediaSingle(String layout, Media media)Creates a newmediaSinglenode with the given layout and media item.Map<String,?>toMap()Transforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.MediaSinglewide()Optional<Number>width()Returns the display width for this single media item, if set.MediaSinglewidth(Number width)Sets the width of the single media node's display.MediaSinglewidthAsPercentage(Number width)Sets the width of the single media node's display, as apercentage.MediaSinglewidthInPixels(Number width)Sets the width of the single media node's display, as apixelcount.Optional<MediaSingle.WidthType>widthType()Returns the width type, which controls how thewidthis interpreted.MediaSinglewrapLeft()MediaSinglewrapRight()-
Methods inherited from class com.atlassian.adf.model.node.AbstractMarkedNode
appendNodeFields, createMarkHolder, mark, markedNodeValidate, marks, marks, markTypes, nodeEquals, nodeHashCode, parseMarks, unsupportedMarkFactory, validate
-
Methods inherited from class com.atlassian.adf.model.node.AbstractNode
doubleEq, doubleHash, equals, hashCode, isSupported, mapWithType, numberEq, numberHash, self, toPlainText, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.atlassian.adf.model.Element
isSupported, validate
-
Methods inherited from interface com.atlassian.adf.model.node.Node
toPlainText
-
-
-
-
Method Detail
-
mediaSingle
public static MediaSingle.Partial.NeedsMedia mediaSingle()
-
mediaSingle
public static MediaSingle mediaSingle(Media media)
-
mediaSingle
public static MediaSingle.Partial.NeedsMedia mediaSingle(RichMedia.Layout layout)
Creates a new partially constructedmediaSinglenode with the given layout.- Parameters:
layout- seeRichMedia.Layoutfor explanations of these values- Returns:
- a partially constructed
mediaSinglenode
-
mediaSingle
public static MediaSingle mediaSingle(String layout, Media media)
Creates a newmediaSinglenode with the given layout and media item.- Parameters:
layout- seeRichMedia.Layoutfor explanations of these valuesmedia- themedianode that it should contain- Returns:
- the new
mediaSinglecontainer, with the given media item as content
-
mediaSingle
public static MediaSingle mediaSingle(RichMedia.Layout layout, Media media)
Creates a newmediaSinglenode with the given layout and media item.- Parameters:
layout- seeRichMedia.Layoutfor explanations of these valuesmedia- themedianode that it should contain- Returns:
- the new
mediaSinglecontainer, with the given media item as content
-
width
public Optional<Number> width()
Returns the display width for this single media item, if set.- Returns:
- the display width for this single media item, or
empty()if not set.
-
widthType
public Optional<MediaSingle.WidthType> widthType()
Returns the width type, which controls how thewidthis interpreted. This is alwaysemptywhen thewidthis. If the width is set and this still returnsempty, then thewidthis interpreted as apercentage.
-
width
public MediaSingle width(@Nullable Number width)
Sets the width of the single media node's display. This clears thewidthTypeproperty, which causes the value to be interpreted as apercentagefor backward compatibility.- Parameters:
width- a value from0.0to100.0(inclusive)- Returns:
this
-
widthAsPercentage
public MediaSingle widthAsPercentage(@Nullable Number width)
Sets the width of the single media node's display, as apercentage.- Parameters:
width- a value from0.0to100.0(inclusive)- Returns:
this
-
widthInPixels
public MediaSingle widthInPixels(@Nullable Number width)
Sets the width of the single media node's display, as apixelcount.- Parameters:
width- a non-negative integer- Returns:
this
-
media
public Media media()
-
media
public MediaSingle media(Media media)
-
caption
public Optional<Caption> caption()
Returns the caption for the media item, if set.- Returns:
- the caption for the media item, or
empty()if not set.
-
caption
public MediaSingle caption(@Nullable Caption caption)
-
caption
public MediaSingle caption(String captionContent)
-
caption
public MediaSingle caption(String... captionContent)
-
caption
public MediaSingle caption(CaptionContent captionContent)
-
caption
public MediaSingle caption(CaptionContent... captionContent)
-
caption
public MediaSingle caption(Iterable<? extends CaptionContent> captionContent)
-
caption
public MediaSingle caption(Stream<? extends CaptionContent> captionContent)
-
layout
public RichMedia.Layout layout()
Returns theRichMedia.Layoutsetting for this single media item.- Returns:
- the
RichMedia.Layoutsetting for this single media item.
-
layout
public MediaSingle layout(String layout)
-
layout
public MediaSingle layout(RichMedia.Layout layout)
-
wrapLeft
public MediaSingle wrapLeft()
-
center
public MediaSingle center()
-
wrapRight
public MediaSingle wrapRight()
-
wide
public MediaSingle wide()
-
fullWidth
public MediaSingle fullWidth()
-
alignStart
public MediaSingle alignStart()
-
alignEnd
public MediaSingle alignEnd()
-
copy
public MediaSingle copy()
Description copied from interface:ElementReturns a deep copy of this element, including copies of any nodes or marks that it contains. The copy will not necessarily be in exactly the same state as the original in some cases. For example, atextnode that is used inside acodeBlockwill have the ability to use marks on it disabled, but a copy made of the text node using this method will not similarly disallow marks unless it is also added to a content node with those same restrictions.Implementations notes:
- Implementations should narrow the return type.
- Implementations should
return thisif the element is immutable. The@Immutableannotation should be used on the class to offer additional confirmation of this intent. - Implementations should
return parse(toMap())if they have state. - While there may be cases where it is worthwhile to do something more efficient than
the conversion to a map and back, this is discouraged because it would add yet another
fragile piece of code that breaks when new data is added to the node. The
parseandtoMapmethods already have to be updated in these circumstances, so it makes sense to take advantage of that.
- Specified by:
copyin interfaceElement- Specified by:
copyin interfaceMarked<MediaSingle,MediaSingleMark>- Specified by:
copyin interfaceNode- Specified by:
copyin classAbstractMarkedNode<MediaSingle,MediaSingleMark>- Returns:
- a copy of this element, or
thisif the element is immutable anyway
-
elementType
public String elementType()
Description copied from interface:ElementThetypevalue that identifies this element, such as"paragraph"or"strong".- Specified by:
elementTypein interfaceElement
-
markedNodeEquals
protected boolean markedNodeEquals(MediaSingle other)
- Overrides:
markedNodeEqualsin classAbstractMarkedNode<MediaSingle,MediaSingleMark>
-
markedNodeHashCode
protected int markedNodeHashCode()
- Overrides:
markedNodeHashCodein classAbstractMarkedNode<MediaSingle,MediaSingleMark>
-
appendMarkedNodeFields
protected void appendMarkedNodeFields(AbstractNode.ToStringHelper buf)
- Overrides:
appendMarkedNodeFieldsin classAbstractMarkedNode<MediaSingle,MediaSingleMark>
-
appendPlainText
public void appendPlainText(StringBuilder sb)
Description copied from interface:NodeRenders this node as plain-text suitable for viewing by end users. This is equivalent to callingNode.toPlainText()and appending the result to the given buffer, except that it may be slightly more efficient, since it will write directly to the existing buffer instead of using a temporary buffer and having to make a copy of the result.- Specified by:
appendPlainTextin interfaceNode- Overrides:
appendPlainTextin classAbstractNode<MediaSingle>- Parameters:
sb- where to write the result
-
markClass
public Class<MediaSingleMark> markClass()
Description copied from interface:MarkedReturns the type of marks that may be applied to this node.- Specified by:
markClassin interfaceMarked<MediaSingle,MediaSingleMark>- Specified by:
markClassin classAbstractMarkedNode<MediaSingle,MediaSingleMark>- Returns:
- the type of marks that may be applied to this node, which is the concrete type for the generic
type
<M>on this interface.
-
mark
public MediaSingle mark(MediaSingleMark mark)
Description copied from interface:MarkedAdds the given mark to this marked node.- Specified by:
markin interfaceMarked<MediaSingle,MediaSingleMark>- Overrides:
markin classAbstractMarkedNode<MediaSingle,MediaSingleMark>- Parameters:
mark- the mark to be added- Returns:
this
-
link
public MediaSingle link(@Nullable Link link)
-
link
public MediaSingle link(@Nullable String href)
-
toMap
public Map<String,?> toMap()
Description copied from interface:ElementTransforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.
-
allNodes
public Stream<Node> allNodes()
This mimics the behavior ofContentNode.allNodes(), for convenience.- Returns:
- a stream of this node and the deep expansion of its contents
- See Also:
Implementation Note
-
allNodesOfType
public <T extends Node> Stream<T> allNodesOfType(Class<T> nodeClass)
This mimics the behavior ofContentNode.allNodesOfType(Class).- See Also:
Implementation Note
-
allNodesOfTypeAsList
public <T extends Node> List<T> allNodesOfTypeAsList(Class<T> nodeClass)
This mimics the behavior ofContentNode.allNodesOfTypeAsList(Class).- See Also:
Implementation Note
-
-