All Downloads are FREE. Search and download functionalities are using the official Maven repository.

chameleon.playlist.smil.Layout Maven / Gradle / Ivy

There is a newer version: 1.2.1-RELEASE
Show newest version
/*
 * Copyright (c) 2008, Christophe Delory
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY CHRISTOPHE DELORY ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL CHRISTOPHE DELORY BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package chameleon.playlist.smil;

import java.util.ArrayList;
import java.util.List;

import chameleon.lang.StringUtils;

/**
 * Defines a collection of rendering regions that determine how the elements in the document's body are positioned on an abstract rendering surface.
 * @version $Revision: 92 $
 * @author Christophe Delory
 * @castor.class xml="layout"
 */
public class Layout extends Core
{
    /**
     * The list of top layouts which are associated to this layout.
     */
    private final List _topLayouts = new ArrayList();

    /**
     * The root layout associated to this layout.
     */
    private RootLayout _rootLayout = null;

    /**
     * The list of regions associated to this layout.
     */
    private final List _regions = new ArrayList();

    /**
     * The list of registration points which are associated to the layout.
     */
    private final List _regPoints = new ArrayList();

    /**
     * Specifies which layout language is used in the layout element.
     */
    private String _type = null;

    /**
     * Returns the list of top layouts defined in this layout.
     * @return a list of top layouts. May be empty but not null.
     * @see #addTopLayout
     * @castor.field
     *  get-method="getTopLayouts"
     *  set-method="addTopLayout"
     *  type="chameleon.playlist.smil.TopLayout"
     *  collection="arraylist"
     * @castor.field-xml
     *  name="topLayout"
     *  node="element"
     */
    public List getTopLayouts()
    {
        return _topLayouts;
    }

    /**
     * Adds the specified top layout to this layout.
     * @param topLayout a top layout. Shall not be null.
     * @throws NullPointerException if topLayout is null.
     * @see #getTopLayouts
     */
    public void addTopLayout(final TopLayout topLayout)
    {
        if (topLayout == null)
        {
            throw new NullPointerException("no top layout");
        }

        _topLayouts.add(topLayout);
    }

    /**
     * Returns the root layout defined in this layout.
     * @return a root layout. May be null.
     * @see #setRootLayout
     * @castor.field
     *  get-method="getRootLayout"
     *  set-method="setRootLayout"
     * @castor.field-xml
     *  name="root-layout"
     *  node="element"
     */
    public RootLayout getRootLayout()
    {
        return _rootLayout;
    }

    /**
     * Initializes the root layout associated to this layout.
     * @param rootLayout a root layout. May be null.
     * @see #getRootLayout
     */
    public void setRootLayout(final RootLayout rootLayout)
    {
        _rootLayout = rootLayout;
    }

    /**
     * Returns the list of regions defined in this layout.
     * @return a list of regions. May be empty but not null.
     * @see #addRegion
     * @castor.field
     *  get-method="getRegions"
     *  set-method="addRegion"
     *  type="chameleon.playlist.smil.Region"
     *  collection="arraylist"
     * @castor.field-xml
     *  name="region"
     *  node="element"
     */
    public List getRegions()
    {
        return _regions;
    }

    /**
     * Adds a region to this layout.
     * @param region a region. Shall not be null.
     * @throws NullPointerException if region is null.
     * @see #getRegions
     */
    public void addRegion(final Region region)
    {
        if (region == null)
        {
            throw new NullPointerException("no region");
        }

        _regions.add(region);
    }

    /**
     * Returns the first region found with the specified identifier.
     * @param regionId the region identifier. Shall not be null.
     * @return a region, or null if none is found.
     * @throws NullPointerException if regionId is null.
     * @see Region#getId
     */
    public Region findRegionById(final String regionId)
    {
        Region ret = null;

        for (Region region : _regions)
        {
            if (regionId.equals(region.getId())) // region.getId() may be null. Throws NullPointerException if regionId is null.
            {
                ret = region;
                break;
            }
        }

        return ret;
    }

    /**
     * Returns the list of registration points defined in this layout.
     * @return a list of registration points. May be empty but not null.
     * @see #addRegistrationPoint
     * @castor.field
     *  get-method="getRegistrationPoints"
     *  set-method="addRegistrationPoint"
     *  type="chameleon.playlist.smil.RegistrationPoint"
     *  collection="arraylist"
     * @castor.field-xml
     *  name="regPoint"
     *  node="element"
     */
    public List getRegistrationPoints()
    {
        return _regPoints;
    }

    /**
     * Adds a registration point to this layout.
     * @param regPoint a registration point. Shall not be null.
     * @throws NullPointerException if regPoint is null.
     * @see #getRegistrationPoints
     */
    public void addRegistrationPoint(final RegistrationPoint regPoint)
    {
        if (regPoint == null)
        {
            throw new NullPointerException("no registration point");
        }

        _regPoints.add(regPoint);
    }

    /**
     * Returns the type of layout language which is used in the layout element.
     * The default value is "text/smil-basic-layout".
     * If the type value equals "text/smil-basic-layout", it may contain the rootLayout and region elements.
     * @return the type of layout language. May be null.
     * @see #setType
     * @castor.field
     *  get-method="getType"
     *  set-method="setType"
     * @castor.field-xml
     *  name="type"
     *  node="attribute"
     */
    public String getType()
    {
        return _type;
    }

    /**
     * Initializes the type of layout language which is used in the layout element.
     * @param type the type of layout language. May be null.
     * @see #getType
     */
    public void setType(final String type)
    {
        _type = StringUtils.normalize(type);
    }

    /**
     * Accepts the specified SMIL playlist visitor.
     * @param visitor a SMIL playlist visitor. Shall not be null.
     * @throws NullPointerException if visitor is null.
     */
    public void acceptDown(final SmilVisitor visitor)
    {
        visitor.beginVisitLayout(this); // Throws NullPointerException if visitor is null.

        if (_rootLayout != null)
        {
            _rootLayout.acceptDown(visitor);
        }

        // First keep a local copy of the list, just in case the visitor modifies it.
        final Region[] regions = new Region[_regions.size()];
        _regions.toArray(regions); // Shall not throw NullPointerException, ArrayStoreException.

        // Then visit the regions defined in this layout.
        for (Region region : regions)
        {
            region.acceptDown(visitor);
        }

        visitor.endVisitLayout(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy