001/*
002 * ============================================================================
003 *  Copyright © 2002-2024 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.fx.internal;
019
020import static org.apiguardian.api.API.Status.INTERNAL;
021import static org.tquadrat.foundation.lang.Objects.isNull;
022import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument;
023import static org.tquadrat.foundation.lang.Objects.requireNotBlankArgument;
024
025import org.apiguardian.api.API;
026import org.tquadrat.foundation.annotation.ClassVersion;
027import javafx.scene.control.Control;
028
029/**
030 *  <p>{@summary The abstract base class for the custom controls introduced by
031 *  the Foundation FX project.}</p>
032 *
033 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
034 *  @inspired  {@href https://controlsfx.github.io/ ControlsFX Project}
035 *  @version $Id: FoundationFXControl.java 1112 2024-03-10 14:16:51Z tquadrat $
036 *  @since 0.4.6
037 *
038 *  @UMLGraph.link
039 */
040@ClassVersion( sourceVersion = "$Id: FoundationFXControl.java 1112 2024-03-10 14:16:51Z tquadrat $" )
041@API( status = INTERNAL, since = "0.4.6" )
042public abstract class FoundationFXControl extends Control
043{
044        /*------------*\
045    ====** Attributes **=======================================================
046        \*------------*/
047    /**
048     *  The cache URL for the <i>User Agent Stylesheet</i>.
049     *
050     *  @see #getUserAgentStylesheet(Class,String)
051     */
052    private String m_Stylesheet;
053
054        /*--------------*\
055    ====** Constructors **=====================================================
056        \*--------------*/
057    /**
058     *  Creates a new instance of {@code FoundationFXControl}.
059     */
060    protected FoundationFXControl() { /* Just exists */ }
061
062        /*---------*\
063    ====** Methods **==========================================================
064        \*---------*/
065    /**
066     *  <p>{@summary A helper method that ensures that the resource based
067     *  lookup of the <i>User Agent Stylesheet</i> only happens once.} It
068     *  caches the external form of the resource URL.</p>
069     *
070     *  @param  lookupClass The class that is used for the resource lookup.
071     *  @param  fileName    The name of the user agent stylesheet.
072     *  @return The external form of the URL for user agent stylesheet (the
073     *      path).
074     */
075    protected final String getUserAgentStylesheet( final Class<?> lookupClass, final String fileName)
076    {
077        if( isNull( m_Stylesheet ) )
078        {
079            m_Stylesheet = requireNonNullArgument( lookupClass, "lookupClass" ).getResource( requireNotBlankArgument( fileName, "fileName" ) ).toExternalForm();
080        }
081
082        //---* Done *----------------------------------------------------------
083        return m_Stylesheet;
084    }   //  getUserAgentStylesheet()
085}
086//  class FoundationFXControl