001/* A token that contains a java.awt.Image. 002 003 Copyright (c) 2002-2015 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 */ 027package ptolemy.data; 028 029import java.awt.Image; 030 031import ptolemy.data.type.BaseType; 032import ptolemy.data.type.Type; 033 034/////////////////////////////////////////////////////////////////// 035//// AWTImageToken 036 037/** 038 A token that contains a java.awt.Image. This token is used in the 039 standard image processing library. 040 041 @author James Yeh 042 @version $Id$ 043 @since Ptolemy II 3.0 044 @Pt.ProposedRating Red (cxh) 045 @Pt.AcceptedRating Red (cxh) 046 */ 047public class AWTImageToken extends ImageToken { 048 /** Construct a token with a specified java.awt.Image. 049 * @param value The given value 050 */ 051 public AWTImageToken(Image value) { 052 _value = value; 053 } 054 055 /////////////////////////////////////////////////////////////////// 056 //// public methods //// 057 058 /** Because all tokens that contain images must extend ImageToken, 059 * we must include the following method. 060 */ 061 @Override 062 public Image asAWTImage() { 063 return ((Image) _value); 064 } 065 066 @Override 067 public Type getType() { 068 return BaseType.OBJECT; 069 } 070 071 /** Return the java.awt.Image object associated with this token. 072 * @return the java.awt.Image object. 073 */ 074 @Override 075 public Image getValue() { 076 return (Image) _value; 077 } 078 079 /** Return a description of the token. 080 * If possible, derived classes should override this method and 081 * return the value of this token as a string that can be parsed 082 * by the expression language to recover a token with the same value. 083 * Unfortunately, in this base class, we can only return the 084 * classname, the width and the height as a string representation of 085 * a record. 086 * @return The classname, width and height as string representation 087 * of a record. 088 */ 089 @Override 090 public String toString() { 091 return "{type=\"" + getClass() + "\", width=\"" 092 + (_value == null ? -1 : ((Image) _value).getWidth(null)) 093 + "\", height=\"" 094 + (_value == null ? -1 : ((Image) _value).getHeight(null)) 095 + "\"}"; 096 } 097}