001/* Display an Black and White image on the screen using the Picture class.
002
003 @Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005
006 Permission is hereby granted, without written agreement and without
007 license or royalty fees, to use, copy, modify, and distribute this
008 software and its documentation for any purpose, provided that the
009 above copyright notice and the following two paragraphs appear in all
010 copies of this software.
011
012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016 SUCH DAMAGE.
017
018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023 ENHANCEMENTS, OR MODIFICATIONS.
024
025 PT_COPYRIGHT_VERSION 2
026 COPYRIGHTENDKEY
027 */
028package ptolemy.domains.sdf.lib.vq;
029
030import ptolemy.actor.injection.ActorModuleInitializer;
031import ptolemy.actor.injection.PtolemyInjector;
032import ptolemy.data.type.BaseType;
033import ptolemy.kernel.CompositeEntity;
034import ptolemy.kernel.util.IllegalActionException;
035import ptolemy.kernel.util.InternalErrorException;
036import ptolemy.kernel.util.NameDuplicationException;
037
038///////////////////////////////////////////////////////////////////
039//// ImageDisplay
040
041/**
042 Display an image on the screen using the ptolemy.media.Picture
043 class.  For a sequence of images that are all the same size, this
044 class will continually update the picture with new data.  If the
045 size of the input image changes, then a new Picture object is
046 created.  This class will only accept a IntMatrixToken on its
047 input, and assumes that the input image contains greyscale pixel
048 intensities between 0 and 255 (inclusive).  The token is
049 read in postfire().
050
051 <p>Note that this actor really should be replaced by a conversion
052 actor that converts IntMatrixTokens to ImageTokens.  However,
053 there is no easy way to do that without accessing the graphical
054 context of the actor.  An alternative would be to use the
055 Java Advanced Imaging package and create an actor like
056 $PTII/ptolemy/actor/lib/jai/DoubleMatrixToJAI.java.
057
058 @author Steve Neuendorffer, Christopher Brooks
059 @version $Id$
060 @since Ptolemy II 0.2
061 @Pt.ProposedRating Yellow (neuendor)
062 @Pt.AcceptedRating Red
063 */
064public class ImageDisplay extends ptolemy.actor.lib.image.ImageDisplay {
065    /** Construct an actor with the given container and name.
066     *  @param container The container.
067     *  @param name The name of this actor.
068     *  @exception IllegalActionException If the actor cannot be contained
069     *   by the proposed container.
070     *  @exception NameDuplicationException If the container already has an
071     *   actor with this name.
072     */
073    public ImageDisplay(CompositeEntity container, String name)
074            throws IllegalActionException, NameDuplicationException {
075        super(container, name);
076
077        input.setTypeEquals(BaseType.INT_MATRIX);
078    }
079
080    ///////////////////////////////////////////////////////////////////
081    ////                         private methods                   ////
082
083    /** Get the right instance of the implementation depending upon the
084     *  of the dependency specified through dependency injection.
085     *  If the instance has not been created, then it is created.
086     *  If the instance already exists then return the same.
087     *
088     *        <p>This code is used as part of the dependency injection needed for the
089     *  HandSimDroid project, see $PTII/ptserver.  This code uses dependency
090     *  inject to determine what implementation to use at runtime.
091     *  This method eventually reads ptolemy/actor/ActorModule.properties.
092     *  {@link ptolemy.actor.injection.ActorModuleInitializer#initializeInjector()}
093     *  should be called before this method is called.  If it is not
094     *  called, then a message is printed and initializeInjector() is called.</p>
095     *
096     *  @return the instance of the implementation.
097     */
098    @Override
099    protected ImageDisplayInterface _getImplementation() {
100        if (_implementation == null) {
101            if (PtolemyInjector.getInjector() == null) {
102                System.err.println("Warning: main() did not call "
103                        + "ActorModuleInitializer.initializeInjector(), "
104                        + "so ImageDisplay is calling it for you.");
105                ActorModuleInitializer.initializeInjector();
106            }
107            _implementation = PtolemyInjector.getInjector()
108                    .getInstance(ImageDisplayInterface.class);
109            try {
110                _implementation.init(this);
111            } catch (NameDuplicationException e) {
112                throw new InternalErrorException(this, e,
113                        "Failed to initialize implementation");
114            } catch (IllegalActionException e) {
115                throw new InternalErrorException(this, e,
116                        "Failed to initialize implementation");
117            }
118        }
119        return _implementation;
120    }
121
122    ///////////////////////////////////////////////////////////////////
123    ////                         private variables                 ////
124
125    // Implementation of the ImageDisplayInterface
126    private ImageDisplayInterface _implementation;
127}