001/*
002 * ============================================================================
003 * Copyright © 2002-2020 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.svg.SVGUtils.SVGATTRIBUTE_Class;
022import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_ClipPathUnits;
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_Style;
026import static org.tquadrat.foundation.svg.SVGUtils.SVGATTRIBUTE_Transform;
027import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_ClipPath;
028import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Text;
029import static org.tquadrat.foundation.svg.SVGUtils.SVGELEMENT_Use;
030import static org.tquadrat.foundation.svg.type.SVGElementCategory.ANIMATION;
031import static org.tquadrat.foundation.svg.type.SVGElementCategory.DESCRIPTIVE;
032import static org.tquadrat.foundation.svg.type.SVGElementCategory.SHAPE;
033import static org.tquadrat.foundation.xml.builder.XMLElement.Flags.ALLOWS_CHILDREN;
034import static org.tquadrat.foundation.xml.builder.XMLElement.Flags.VALIDATES_ATTRIBUTES;
035import static org.tquadrat.foundation.xml.builder.XMLElement.Flags.VALIDATES_CHILDREN;
036
037import java.util.ArrayList;
038import java.util.Collection;
039import java.util.HashSet;
040import java.util.List;
041
042import org.apiguardian.api.API;
043import org.tquadrat.foundation.annotation.ClassVersion;
044import org.tquadrat.foundation.svg.AllowsConditionalProcessingAttributes;
045import org.tquadrat.foundation.svg.AllowsPresentationAttributes;
046import org.tquadrat.foundation.svg.SVGClipPath;
047
048/**
049 *  The implementation of the interface
050 *  {@link SVGClipPath}
051 *  for the SVG {@code <clipPath>} element.
052 *
053 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
054 *  @version $Id: SVGClipPathImpl.java 820 2020-12-29 20:34:22Z tquadrat $
055 *  @since 0.0.5
056 *
057 *  @UMLGraph.link
058 */
059@ClassVersion( sourceVersion = "$Id: SVGClipPathImpl.java 820 2020-12-29 20:34:22Z tquadrat $" )
060@API( status = INTERNAL, since = "0.0.5" )
061public final class SVGClipPathImpl extends SVGElementImpl implements SVGClipPath
062{
063        /*--------------*\
064    ====** Constructors **=====================================================
065        \*--------------*/
066    /**
067     *  Creates a new {@code SVGClipPathImpl} instance.
068     *
069     *  @param  id  The mandatory id for the {@code <svg>} element.
070     */
071    public SVGClipPathImpl( final String id )
072    {
073        super( SVGELEMENT_ClipPath, ALLOWS_CHILDREN, VALIDATES_ATTRIBUTES, VALIDATES_CHILDREN );
074
075        //---* The children and attributes for the <clipPatt> element *--------
076        final Collection<String> childElements = new HashSet<>();
077        childElements.addAll( ANIMATION.getElements() );
078        childElements.addAll( DESCRIPTIVE.getElements() );
079        childElements.addAll( SHAPE.getElements() );
080        childElements.add( SVGELEMENT_Text );
081        childElements.add( SVGELEMENT_Use );
082
083        final Collection<String> attributes = new ArrayList<>();
084        attributes.addAll( List.of( SVGATTRIBUTE_Id, SVGATTRIBUTE_Class,
085            SVGATTRIBUTE_Style, SVGATTRIBUTE_ExternalResourcesRequired,
086            SVGATTRIBUTE_Transform, SVGATTRIBUTE_ClipPathUnits ) );
087        attributes.addAll( CORE_ATTRIBUTES );
088        attributes.addAll( AllowsConditionalProcessingAttributes.CONDITIONALPROCESSING_ATTRIBUTES );
089        attributes.addAll( AllowsPresentationAttributes.PRESENTATION_ATTRIBUTES );
090
091        updateRegistries( childElements, attributes );
092
093        setId( id );
094    }   //  SVGClipPathImpl()
095
096        /*---------*\
097    ====** Methods **==========================================================
098        \*---------*/
099    /**
100     *  {@inheritDoc}
101     */
102    @Override
103    public final void setClipPathUnits( final boolean flag )
104    {
105        setAttribute( SVGATTRIBUTE_ClipPathUnits, flag ? "objectBoundingBox" : "userSpaceOnUse" );
106    }   //  setClipPathUnits()
107}
108//  class SVGClipPathImpl
109
110/*
111 *  End of File
112 */