View Javadoc

1   /*
2    * @(#) DistributedSingleImageRenderable.java Dec 09, 2004
3    * 
4    * 
5    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
6    * Delft, the Netherlands. All rights reserved.
7    * 
8    * See for project information <a href="http://www.simulation.tudelft.nl/">
9    * www.simulation.tudelft.nl </a>.
10   * 
11   * The source code and binary code of this software is proprietary information
12   * of Delft University of Technology.
13   */
14  package org.gscg.gameleader.animation2D;
15  
16  import java.awt.Dimension;
17  import java.awt.geom.Point2D;
18  import java.lang.reflect.Field;
19  import java.net.URL;
20  import java.rmi.RemoteException;
21  
22  import nl.tudelft.simulation.dsol.animation.LocatableInterface;
23  import nl.tudelft.simulation.dsol.animation.StaticLocation;
24  import nl.tudelft.simulation.dsol.animation.D2.ImageRenderable;
25  import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
26  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
27  import nl.tudelft.simulation.language.d3.BoundingBox;
28  import nl.tudelft.simulation.language.d3.DirectedPoint;
29  import nl.tudelft.simulation.language.reflection.ClassUtil;
30  import nl.tudelft.simulation.logger.Logger;
31  
32  import org.gscg.common.interactionlayer.ThreadedEventProducer;
33  
34  /***
35   * The DistributedSingleImageRenderable is used to show the contents of a single
36   * image renderable on a remote animation panel.
37   * <p>
38   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
39   * Delft, the Netherlands. All rights reserved.
40   * 
41   * See for project information <a href="http://www.simulation.tudelft.nl/">
42   * www.simulation.tudelft.nl </a>.
43   * 
44   * The source code and binary code of this software is proprietary information
45   * of Delft University of Technology.
46   * 
47   * @author <a
48   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
49   *         van Houten </a>
50   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:34:03 $
51   * @since 1.0.8
52   */
53  public class DistributedSingleImageRenderable extends ImageRenderable implements
54  		DistributedRenderable2DInterface
55  {
56  	/*** the serial version uid */
57  	private static final long serialVersionUID = 11L;
58  
59  	/*** the source field of the Renderable2D class */
60  	private static Field sourceField = null;
61  
62  	static
63  	{
64  		try
65  		{
66  			DistributedSingleImageRenderable.sourceField = ClassUtil
67  					.resolveField(Renderable2D.class, "source");
68  			sourceField.setAccessible(true);
69  		} catch (Exception exception)
70  		{
71  			Logger.severe(ThreadedEventProducer.class, "<clinit>", exception);
72  		}
73  	}
74  
75  	/*** the bounding box */
76  	protected BoundingBox box = null;
77  
78  	/***
79  	 * constructs a new SingleImageRenderable
80  	 * 
81  	 * @param source the moving source
82  	 * @param simulator the simulator
83  	 * @param image the image to animate
84  	 */
85  	public DistributedSingleImageRenderable(final LocatableInterface source,
86  			final SimulatorInterface simulator, final URL image)
87  	{
88  		super(source, simulator, new URL[]{image});
89  	}
90  
91  	/***
92  	 * constructs a new SingleImageRenderable
93  	 * 
94  	 * @param staticLocation the static location
95  	 * @param size the size
96  	 * @param simulator the simulator
97  	 * @param image the image
98  	 */
99  	public DistributedSingleImageRenderable(final Point2D staticLocation,
100 			final Dimension size, final SimulatorInterface simulator,
101 			final URL image)
102 	{
103 		super(staticLocation, size, simulator, new URL[]{image});
104 		this.box = new BoundingBox(size.getWidth(), size.getHeight(), 0.0);
105 	}
106 
107 	/***
108 	 * constructs a new SingleImageRenderable
109 	 * 
110 	 * @param staticLocation the static location
111 	 * @param size the size of the image
112 	 * @param simulator the simulator
113 	 * @param image the image
114 	 */
115 	public DistributedSingleImageRenderable(final DirectedPoint staticLocation,
116 			final Dimension size, final SimulatorInterface simulator,
117 			final URL image)
118 	{
119 		super(staticLocation, size, simulator, new URL[]{image});
120 		this.box = new BoundingBox(size.getWidth(), size.getHeight(), 0.0);
121 	}
122 
123 	/***
124 	 * @see nl.tudelft.simulation.dsol.animation.D2.ImageRenderable#selectImage()
125 	 */
126 	public int selectImage()
127 	{
128 		// We only have one image to show. Let's use this one.
129 		return 0;
130 	}
131 
132 	/***
133 	 * @see nl.tudelft.simulation.dsol.animation.D2.Renderable2D#bind2Context(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
134 	 */
135 	protected void bind2Context(final SimulatorInterface arg0)
136 	{
137 		// we explicitly do not call the super implementation
138 		// to prevent using the bind to context tool
139 	}
140 
141 	/***
142 	 * @see org.gscg.gameleader.animation2D.DistributedRenderable2DInterface#setLocation(nl.tudelft.simulation.language.d3.DirectedPoint)
143 	 */
144 	public void setLocation(final DirectedPoint location)
145 			throws RemoteException
146 	{
147 		try
148 		{
149 			DistributedSingleImageRenderable.sourceField.set(this,
150 					new StaticLocation(new DirectedPoint(location), this.box));
151 		} catch (Exception exception)
152 		{
153 			Logger.severe(this, "setLocation", exception);
154 		}
155 	}
156 }