001/* 002 * ============================================================================ 003 * Copyright © 2002-2025 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.AllowsStyleAttributes; 071import org.tquadrat.foundation.svg.SVGMarker; 072import org.tquadrat.foundation.svg.type.SVGMarkerOrientation; 073import org.tquadrat.foundation.svg.type.SVGNumber; 074import org.tquadrat.foundation.svg.type.SVGNumber.SVGDegree; 075 076/** 077 * The implementation for the interface 078 * {@link SVGMarker} 079 * for the SVG {@code <marker>}. 080 * 081 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 082 * @version $Id: SVGMarkerImpl.java 1151 2025-10-01 21:32:15Z tquadrat $ 083 * @since 0.0.5 084 * 085 * @UMLGraph.link 086 */ 087@ClassVersion( sourceVersion = "$Id: SVGMarkerImpl.java 1151 2025-10-01 21:32:15Z tquadrat $" ) 088@API( status = INTERNAL, since = "0.0.5" ) 089public sealed class SVGMarkerImpl extends SVGElementImpl implements SVGMarker 090 permits SVGPositionedMarkerImpl 091{ 092 /*--------------*\ 093 ====** Constructors **===================================================== 094 \*--------------*/ 095 /** 096 * Creates a new {@code SVGMarkerImpl} instance. 097 */ 098 public SVGMarkerImpl() 099 { 100 super( SVGELEMENT_Marker, ALLOWS_CHILDREN, VALIDATES_ATTRIBUTES, VALIDATES_CHILDREN ); 101 102 //---* The children and attributes for the <marker> element *---------- 103 final Collection<String> childElements = new HashSet<>(); 104 childElements.addAll( ANIMATION.getElements() ); 105 childElements.addAll( DESCRIPTIVE.getElements() ); 106 childElements.addAll( SHAPE.getElements() ); 107 childElements.addAll( STRUCTURAL.getElements() ); 108 childElements.addAll( GRADIENT.getElements() ); 109 childElements.addAll( List.of( SVGELEMENT_Anchor, 110 SVGELEMENT_AltGlyphDef, SVGELEMENT_ClipPath, 111 SVGELEMENT_ColorProfile, SVGELEMENT_Cursor, SVGELEMENT_Filter, 112 SVGELEMENT_Font, SVGELEMENT_FontFace, SVGELEMENT_ForeignObject, 113 SVGELEMENT_Image, SVGELEMENT_Marker, SVGELEMENT_Mask, 114 SVGELEMENT_Pattern, SVGELEMENT_Script, SVGELEMENT_Style, 115 SVGELEMENT_Switch, SVGELEMENT_Text, SVGELEMENT_View ) ); 116 117 final Collection<String> attributes = new ArrayList<>(); 118 attributes.addAll( List.of( SVGATTRIBUTE_Id, 119 SVGATTRIBUTE_PreserveAspectRatio, SVGATTRIBUTE_ViewBox, 120 SVGATTRIBUTE_MarkerUnits, SVGATTRIBUTE_ReferenceX, 121 SVGATTRIBUTE_ReferenceY, SVGATTRIBUTE_MarkerWidth, 122 SVGATTRIBUTE_MarkerHeight, SVGATTRIBUTE_Orientation, 123 SVGATTRIBUTE_Class, SVGATTRIBUTE_Style, 124 SVGATTRIBUTE_ExternalResourcesRequired, SVGATTRIBUTE_Transform, 125 SVGATTRIBUTE_Position ) ); 126 attributes.addAll( CORE_ATTRIBUTES ); 127 attributes.addAll( AllowsStyleAttributes.STYLE_ATTRIBUTES ); 128 attributes.addAll( PRESENTATION_ATTRIBUTES ); 129 130 updateRegistries( childElements, attributes ); 131 } // SVGMarkerImpl() 132 133 /*---------*\ 134 ====** Methods **========================================================== 135 \*---------*/ 136 /** 137 * {@inheritDoc} 138 */ 139 @SuppressWarnings( "UseOfConcreteClass" ) 140 @Override 141 public final void setMarkerHeight( final SVGNumber value ) 142 { 143 setAttribute( SVGATTRIBUTE_MarkerHeight, value ); 144 } // setMarkerHeight() 145 146 /** 147 * {@inheritDoc} 148 */ 149 @Override 150 public final void setMarkerUnits( final boolean flag ) 151 { 152 setAttribute( SVGATTRIBUTE_MarkerUnits, flag ? "userSpaceOnUse" : "strokeWidth" ); 153 } // setMarkerUnits() 154 155 /** 156 * {@inheritDoc} 157 */ 158 @Override 159 public final void setMarkerWidth( @SuppressWarnings( "UseOfConcreteClass" ) final SVGNumber value ) 160 { 161 setAttribute( SVGATTRIBUTE_MarkerWidth, value ); 162 } // setMarkerWidth() 163 164 /** 165 * {@inheritDoc} 166 */ 167 @Override 168 public final void setOrientation( final SVGMarkerOrientation value ) 169 { 170 setAttribute( SVGATTRIBUTE_Orientation, nonNull( value ) ? value.toString() : null ); 171 } // setOrientation() 172 173 /** 174 * {@inheritDoc} 175 */ 176 @Override 177 public final void setOrientation( @SuppressWarnings( "UseOfConcreteClass" ) final SVGDegree value ) 178 { 179 setAttribute( SVGATTRIBUTE_Orientation, nonNull( value ) ? value.toString() : null ); 180 } // setOrientation() 181 182 /** 183 * {@inheritDoc} 184 */ 185 @Override 186 public final void setReferenceX( @SuppressWarnings( "UseOfConcreteClass" ) final SVGNumber value ) 187 { 188 setAttribute( SVGATTRIBUTE_ReferenceX, value ); 189 } // setReferenceX() 190 191 /** 192 * {@inheritDoc} 193 */ 194 @Override 195 public final void setReferenceY( @SuppressWarnings( "UseOfConcreteClass" ) final SVGNumber value ) 196 { 197 setAttribute( SVGATTRIBUTE_ReferenceY, value ); 198 } // setReferenceY() 199} 200// class SVGMarkerImpl 201 202/* 203 * End of File 204 */