001    /*
002     *    GeoAPI - Java interfaces for OGC/ISO standards
003     *    http://www.geoapi.org
004     *
005     *    Copyright (C) 2009-2012 Open Geospatial Consortium, Inc.
006     *    All Rights Reserved. http://www.opengeospatial.org/ogc/legal
007     *
008     *    Permission to use, copy, and modify this software and its documentation, with
009     *    or without modification, for any purpose and without fee or royalty is hereby
010     *    granted, provided that you include the following on ALL copies of the software
011     *    and documentation or portions thereof, including modifications, that you make:
012     *
013     *    1. The full text of this NOTICE in a location viewable to users of the
014     *       redistributed or derivative work.
015     *    2. Notice of any changes or modifications to the OGC files, including the
016     *       date changes were made.
017     *
018     *    THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE
019     *    NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
020     *    TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
021     *    THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
022     *    PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
023     *
024     *    COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
025     *    CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
026     *
027     *    The name and trademarks of copyright holders may NOT be used in advertising or
028     *    publicity pertaining to the software without specific, written prior permission.
029     *    Title to copyright in this software and any associated documentation will at all
030     *    times remain with copyright holders.
031     */
032    package org.opengis.display.container;
033    
034    import java.util.Collection;
035    import org.opengis.display.canvas.Canvas;
036    import org.opengis.display.primitive.Graphic;
037    import org.opengis.geometry.Envelope;
038    
039    
040    /**
041     * Holds a collection of {@linkplain Graphic graphics} to be drawn in a {@linkplain Canvas canvas}.
042     * The GraphicsContainer implementation typically depends on the canvas implementation. For example an AWT
043     * canvas may be associated to a GraphicsContainer using a {@link java.awt.Graphics2D} handler for drawing,
044     * while a SWT canvas may be associated to an other GraphicsContainer implementation using a different
045     * drawing toolkit.
046     * <p>
047     * Graphics can be {@linkplain Collection#add added} or {@linkplain Collection#remove removed} with
048     * method invocations on the collection returned by {@link #graphics}, which is a "live" collection.
049     * Note that a GraphicsContainer instance may restrict the acceptable graphic implementations.
050     *
051     * @author Open Geospatial Consortium
052     * @author Johann Sorel (Geomatys)
053     * @since  GeoAPI 2.2
054     */
055    public interface GraphicsContainer<G extends Graphic> {
056    
057        /**
058         * Returns the canvas where this GraphicsContainer will drawn the {@linkplain Graphic graphics}.
059         *
060         * @return The canvas where to drawn.
061         */
062        Canvas getCanvas();
063    
064        Envelope getGraphicsEnvelope();
065    
066        /**
067         * Returns the collection of all graphics. Changes to this collection (addition,
068         * removal) are reflected into the set of graphics to be rendered. Note that the returned
069         * collection must notifies the {@linkplain ContainerListener GraphicsContainer listener} about any
070         * addition or removal.
071         * <p>
072         * When new graphics are {@linkplain Collection#add added}, implementations shall respect
073         * the <var>z</var>-order retrieved by calling {@link Graphic#getZOrderHint()}. When two
074         * added graphics have the same <var>z</var>-order, the most recently added one should be
075         * on top.
076         *
077         * @return Collection of all graphics, as a live collection.
078         */
079        Collection<G> graphics();
080    
081        /**
082         * Adds a listener to be notified when a graphic is added or removed.
083         *
084         * @param listener The listener to add.
085         */
086        void addContainerListener(ContainerListener listener);
087    
088        /**
089         * Removes a listener.
090         *
091         * @param listener The listener to remove.
092         */
093        void removeContainerListener(ContainerListener listener);
094    
095        /**
096         * Provides a hint that a GraphicsContainer is no longer needed. Implementations may use this method to
097         * release resources, if needed. Implementations may also implement this method to return the
098         * GraphicsContainer to a GraphicsContainer pool.
099         * <p>
100         * It is an error to reference a {@link GraphicsContainer} in any way after its dispose method has been
101         * called.
102         */
103        void dispose();
104    }