Package com.storedobject.vaadin
Class Svg
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Svg
com.storedobject.vaadin.Svg
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasStyle,Serializable
@Tag("svg")
public class Svg
extends com.vaadin.flow.component.Svg
An enhanced version of Vaadin's
Svg.
This class provides functionality to manage tooltips, click popups, and event listeners
for the components within an SVG structure.
The SVG structure's can be created/manipulated using the Document
and Node.
- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a click event triggered by user interaction with an SVG component.static classRepresents an abstract base class for events triggered by interactions with an SVG component.static classRepresents an event triggered when the mouse pointer exits the boundaries of an SVG element.static classRepresents a mouseover event triggered when the user moves the mouse pointer over an SVG element. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal com.vaadin.flow.shared.RegistrationaddClickListener(Node node, com.vaadin.flow.component.ComponentEventListener<Svg.ClickEvent> listener) Adds a click listener for the specified node.voidclear()Clears all stored SVG-related data and deregisters any active event listeners or popups associated with the Svg component.voidremoveClickPopup(Node node) Removes the click popup associated with the specified SVG node.final voidremoveTooltip(Node node) Removes the tooltip associated with the specified SVG node.final voidsetClickPopup(Node node, Function<Svg.ClickEvent, com.vaadin.flow.component.Component> clickPopupProvider) Associates a click popup with the specified SVG node.voidSets the SVG content of this component using the provided SVG document.voidSets the SVG content of this component using the provided node.final voidsetTooltip(Node node, Function<Svg.MouseOverEvent, com.vaadin.flow.component.Component> tooltipProvider) Associates a tooltip with the specified SVG node.Methods inherited from class com.vaadin.flow.component.Svg
setSvg, setSvgMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
Svg
public Svg()Constructs a new instance of the Svg component. -
Svg
Creates a new instance of the Svg component and initializes it with the provided node.- Parameters:
node- the SVG node to associate with this component
-
Svg
Creates a new instance of the Svg component and initializes it with the provided SVG document.- Parameters:
document- the SVG document to associate with this component
-
-
Method Details
-
setSvg
Sets the SVG content of this component using the provided node.- Parameters:
node- the SVG node from which the SVG content will be set
-
setSvg
Sets the SVG content of this component using the provided SVG document.- Parameters:
document- the SVG document from which the SVG content will be set
-
clear
public void clear()Clears all stored SVG-related data and deregisters any active event listeners or popups associated with the Svg component. This method ensures that the component is reset to its initial state.Note: When you set a new SVG content, this method may be called to ensure a clean slate for the new content.
Functionality: - Closes any active popovers. - Clears the internal map of SVG nodes. - Resets tooltip and click popup providers to null. - Clears out any registered click listeners. - Safely removes and nullifies popovers, tooltips, and mouse interactions' registrations, ensuring no memory leaks or unwanted event triggers remain.
-
addClickListener
public final com.vaadin.flow.shared.Registration addClickListener(Node node, com.vaadin.flow.component.ComponentEventListener<Svg.ClickEvent> listener) Adds a click listener for the specified node. This listener will be triggered when the associated node is clicked in the SVG component.- Parameters:
node- the SVG node for which the click listener is to be addedlistener- the listener to be executed when the node is clicked- Returns:
- a
Registrationobject that can be used to remove the listener
-
setTooltip
public final void setTooltip(Node node, Function<Svg.MouseOverEvent, com.vaadin.flow.component.Component> tooltipProvider) Associates a tooltip with the specified SVG node. The tooltip will be dynamically generated based on the provided function when the user hovers over the node.- Parameters:
node- the SVG node to which the tooltip will be attachedtooltipProvider- the function that generates the tooltip component based on theSvg.MouseOverEvent
-
removeTooltip
Removes the tooltip associated with the specified SVG node.- Parameters:
node- the SVG node for which the tooltip should be removed
-
setClickPopup
public final void setClickPopup(Node node, Function<Svg.ClickEvent, com.vaadin.flow.component.Component> clickPopupProvider) Associates a click popup with the specified SVG node. The popup will be dynamically generated based on the provided function when the node is clicked.- Parameters:
node- the SVG node for which the click popup should be associatedclickPopupProvider- the function that generates the popup component based on theSvg.ClickEvent
-
removeClickPopup
Removes the click popup associated with the specified SVG node. This method ensures that the popup provider for the given node is removed, and the click registration is updated as necessary.- Parameters:
node- the SVG node for which the associated click popup should be removed
-