001/*
002 * ============================================================================
003 * Copyright © 2002-2023 by Thomas Thrien.
004 * All Rights Reserved.
005 * ============================================================================
006 * Licensed to the public under the agreements of the GNU Lesser General Public
007 * License, version 3.0 (the "License"). You may obtain a copy of the License at
008 *
009 *      http://www.gnu.org/licenses/lgpl.html
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package org.tquadrat.foundation.svg.internal;
019
020import static org.apiguardian.api.API.Status.INTERNAL;
021import static org.tquadrat.foundation.lang.Objects.nonNull;
022import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Class;
023import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_ExternalResourcesRequired;
024import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Id;
025import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_MarkerHeight;
026import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_MarkerUnits;
027import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_MarkerWidth;
028import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Orientation;
029import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Position;
030import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_PreserveAspectRatio;
031import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_ReferenceX;
032import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_ReferenceY;
033import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Style;
034import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Transform;
035import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_ViewBox;
036import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_AltGlyphDef;
037import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Anchor;
038import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_ClipPath;
039import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_ColorProfile;
040import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Cursor;
041import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Filter;
042import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Font;
043import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_FontFace;
044import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_ForeignObject;
045import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Image;
046import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Marker;
047import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Mask;
048import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Pattern;
049import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Script;
050import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Style;
051import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Switch;
052import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Text;
053import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_View;
054import static org.tquadrat.foundation.svg.type.SVGElementCategory.ANIMATION;
055import static org.tquadrat.foundation.svg.type.SVGElementCategory.DESCRIPTIVE;
056import static org.tquadrat.foundation.svg.type.SVGElementCategory.GRADIENT;
057import static org.tquadrat.foundation.svg.type.SVGElementCategory.SHAPE;
058import static org.tquadrat.foundation.svg.type.SVGElementCategory.STRUCTURAL;
059import static org.tquadrat.foundation.xml.builder.XMLElement.Flags.ALLOWS_CHILDREN;
060import static org.tquadrat.foundation.xml.builder.XMLElement.Flags.VALIDATES_ATTRIBUTES;
061import static org.tquadrat.foundation.xml.builder.XMLElement.Flags.VALIDATES_CHILDREN;
062
063import java.util.ArrayList;
064import java.util.Collection;
065import java.util.HashSet;
066import java.util.List;
067
068import org.apiguardian.api.API;
069import org.tquadrat.foundation.annotation.ClassVersion;
070import org.tquadrat.foundation.svg.AllowsPresentationAttributes;
071import org.tquadrat.foundation.svg.AllowsStyleAttributes;
072import org.tquadrat.foundation.svg.SVGMarker;
073import org.tquadrat.foundation.svg.type.SVGMarkerOrientation;
074import org.tquadrat.foundation.svg.type.SVGNumber;
075import org.tquadrat.foundation.svg.type.SVGNumber.SVGDegree;
076
077/**
078 *  The implementation for the interface
079 *  {@link SVGMarker}
080 *  for the SVG {@code <marker>}.
081 *
082 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
083 *  @version $Id: SVGMarkerImpl.java 1074 2023-10-02 12:05:06Z tquadrat $
084 *  @since 0.0.5
085 *
086 *  @UMLGraph.link
087 */
088@ClassVersion( sourceVersion = "$Id: SVGMarkerImpl.java 1074 2023-10-02 12:05:06Z tquadrat $" )
089@API( status = INTERNAL, since = "0.0.5" )
090public sealed class SVGMarkerImpl extends SVGElementImpl implements SVGMarker
091    permits SVGPositionedMarkerImpl
092{
093        /*--------------*\
094    ====** Constructors **=====================================================
095        \*--------------*/
096    /**
097     *  Creates a new {@code SVGMarkerImpl} instance.
098     */
099    public SVGMarkerImpl()
100    {
101        super( SVGELEMENT_Marker, ALLOWS_CHILDREN, VALIDATES_ATTRIBUTES, VALIDATES_CHILDREN );
102
103        //---* The children and attributes for the <marker> element *----------
104        final Collection<String> childElements = new HashSet<>();
105        childElements.addAll( ANIMATION.getElements() );
106        childElements.addAll( DESCRIPTIVE.getElements() );
107        childElements.addAll( SHAPE.getElements() );
108        childElements.addAll( STRUCTURAL.getElements() );
109        childElements.addAll( GRADIENT.getElements() );
110        childElements.addAll( List.of( SVGELEMENT_Anchor,
111            SVGELEMENT_AltGlyphDef, SVGELEMENT_ClipPath,
112            SVGELEMENT_ColorProfile, SVGELEMENT_Cursor, SVGELEMENT_Filter,
113            SVGELEMENT_Font, SVGELEMENT_FontFace, SVGELEMENT_ForeignObject,
114            SVGELEMENT_Image, SVGELEMENT_Marker, SVGELEMENT_Mask,
115            SVGELEMENT_Pattern, SVGELEMENT_Script, SVGELEMENT_Style,
116            SVGELEMENT_Switch, SVGELEMENT_Text, SVGELEMENT_View ) );
117
118        final Collection<String> attributes = new ArrayList<>();
119        attributes.addAll( List.of( SVGATTRIBUTE_Id,
120            SVGATTRIBUTE_PreserveAspectRatio, SVGATTRIBUTE_ViewBox,
121            SVGATTRIBUTE_MarkerUnits, SVGATTRIBUTE_ReferenceX,
122            SVGATTRIBUTE_ReferenceY, SVGATTRIBUTE_MarkerWidth,
123            SVGATTRIBUTE_MarkerHeight, SVGATTRIBUTE_Orientation,
124            SVGATTRIBUTE_Class, SVGATTRIBUTE_Style,
125            SVGATTRIBUTE_ExternalResourcesRequired, SVGATTRIBUTE_Transform,
126            SVGATTRIBUTE_Position ) );
127        attributes.addAll( CORE_ATTRIBUTES );
128        attributes.addAll( AllowsStyleAttributes.STYLE_ATTRIBUTES );
129        attributes.addAll( AllowsPresentationAttributes.PRESENTATION_ATTRIBUTES );
130
131        updateRegistries( childElements, attributes );
132    }   //  SVGMarkerImpl()
133
134        /*---------*\
135    ====** Methods **==========================================================
136        \*---------*/
137    /**
138     *  {@inheritDoc}
139     */
140    @SuppressWarnings( "UseOfConcreteClass" )
141    @Override
142    public final void setMarkerHeight( final SVGNumber value )
143    {
144        setAttribute( SVGATTRIBUTE_MarkerHeight, value );
145    }   //  setMarkerHeight()
146
147    /**
148     *  {@inheritDoc}
149     */
150    @Override
151    public final void setMarkerUnits( final boolean flag )
152    {
153        setAttribute( SVGATTRIBUTE_MarkerUnits, flag ? "userSpaceOnUse" : "strokeWidth" );
154    }   //  setMarkerUnits()
155
156    /**
157     *  {@inheritDoc}
158     */
159    @Override
160    public final void setMarkerWidth( @SuppressWarnings( "UseOfConcreteClass" ) final SVGNumber value )
161    {
162        setAttribute( SVGATTRIBUTE_MarkerWidth, value );
163    }   //  setMarkerWidth()
164
165    /**
166     *  {@inheritDoc}
167     */
168    @Override
169    public final void setOrientation( final SVGMarkerOrientation value )
170    {
171        setAttribute( SVGATTRIBUTE_Orientation, nonNull( value ) ? value.toString() : null );
172    }   //  setOrientation()
173
174    /**
175     *  {@inheritDoc}
176     */
177    @Override
178    public final void setOrientation( @SuppressWarnings( "UseOfConcreteClass" ) final SVGDegree value )
179    {
180        setAttribute( SVGATTRIBUTE_Orientation, nonNull( value ) ? value.toString() : null );
181    }   //  setOrientation()
182
183    /**
184     *  {@inheritDoc}
185     */
186    @Override
187    public final void setReferenceX( @SuppressWarnings( "UseOfConcreteClass" ) final SVGNumber value )
188    {
189        setAttribute( SVGATTRIBUTE_ReferenceX, value );
190    }   //  setReferenceX()
191
192    /**
193     *  {@inheritDoc}
194     */
195    @Override
196    public final void setReferenceY( @SuppressWarnings( "UseOfConcreteClass" ) final SVGNumber value )
197    {
198        setAttribute( SVGATTRIBUTE_ReferenceY, value );
199    }   //  setReferenceY()
200}
201//  class SVGMarkerImpl
202
203/*
204 *  End of File
205 */