1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.gscg.gameleader.animation2D;
15
16 import java.awt.Color;
17 import java.awt.Dimension;
18 import java.awt.Graphics2D;
19 import java.awt.geom.Point2D;
20 import java.awt.geom.Rectangle2D;
21 import java.awt.image.ImageObserver;
22 import java.net.URL;
23 import java.rmi.RemoteException;
24
25 import nl.tudelft.simulation.actor.ActorInterface;
26 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
27 import nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface;
28 import nl.tudelft.simulation.dsol.animation.D2.SingleImageRenderable;
29 import nl.tudelft.simulation.dsol.context.ContextUtil;
30 import nl.tudelft.simulation.dsol.gui.animation2D.GridPanel;
31 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
32 import nl.tudelft.simulation.logger.Logger;
33
34 import org.gscg.gameactors.GameManufacturer;
35 import org.gscg.gameactors.GameMarket;
36 import org.gscg.gameactors.GameDistributorInteractive;
37 import org.gscg.gameactors.GameSupplier;
38
39 /***
40 * The GisActorAnimation is useful in combination with a GIS based map as a
41 * background image. Based on the zoom level of an animation panel, choices can
42 * be made what to show, or what not. It is comparable with showing layers when
43 * using a GIS map.
44 * <p>
45 *
46 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
47 * Delft, the Netherlands. All rights reserved.
48 *
49 * See for project information <a href="http://www.simulation.tudelft.nl/">
50 * www.simulation.tudelft.nl </a>.
51 *
52 * The source code and binary code of this software is proprietary information
53 * of Delft University of Technology.
54 *
55 * @author <a
56 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
57 * van Houten </a>
58 * @version $Revision: 1.3 $ $Date: 2005/08/10 11:23:30 $
59 * @since 1.0.7
60 */
61 public class GisActorAnimation extends SingleImageRenderable
62 {
63 /*** the serial version uid */
64 private static final long serialVersionUID = 11L;
65
66 /***
67 * constructs a new GisActorAnimation
68 *
69 * @param locatable the locatable
70 * @param simulator the simulator
71 * @param imageURL the image url
72 */
73 public GisActorAnimation(final LocatableInterface locatable,
74 final SimulatorInterface simulator, final URL imageURL)
75 {
76 super(locatable, simulator, imageURL);
77 if (super.contextName == null)
78 {
79 super.bind2Context(simulator);
80 } else
81 {
82 ContextUtil.bindToContext(super.contextName, this);
83 }
84 }
85
86 /***
87 * @see nl.tudelft.simulation.dsol.animation.D2.Renderable2D#bind2Context(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
88 */
89 protected void bind2Context(final SimulatorInterface simulator)
90 {
91
92 }
93
94 /***
95 * @see nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface#paint(java.awt.Graphics2D,
96 * java.awt.geom.Rectangle2D, java.awt.Dimension,
97 * java.awt.image.ImageObserver)
98 */
99 public synchronized void paint(final Graphics2D graphics,
100 final Rectangle2D rectangle, final Dimension dimension,
101 final ImageObserver observer)
102 {
103
104 GridPanel animationPanel = (GridPanel) observer;
105
106 double scale = Renderable2DInterface.Util.getScale(animationPanel
107 .getExtent(), animationPanel.getSize());
108
109
110 Point2D screenLocation = null;
111 try
112 {
113 screenLocation = Renderable2DInterface.Util.getScreenCoordinates(
114 super.source.getLocation().to2D(), animationPanel
115 .getExtent(), animationPanel.getSize());
116 } catch (RemoteException remoteException)
117 {
118 Logger.severe(this, "paint", remoteException);
119 }
120
121
122 if (scale < 0.05063)
123 {
124 super.setScale(true);
125
126 super.paint(graphics, rectangle, dimension, observer);
127
128 graphics.drawString(((ActorInterface) super.source).getName(),
129 (int) screenLocation.getX() + 10, (int) screenLocation
130 .getY());
131 } else
132 {
133
134 if (GameSupplier.class.isAssignableFrom(super.source.getClass()))
135 {
136 graphics.setColor(Color.YELLOW);
137 } else if (GameManufacturer.class.isAssignableFrom(super.source
138 .getClass()))
139 {
140 graphics.setColor(Color.BLUE);
141 } else if (GameMarket.class.isAssignableFrom(super.source
142 .getClass()))
143 {
144 graphics.setColor(Color.GREEN);
145 } else if (GameDistributorInteractive.class
146 .isAssignableFrom(super.source.getClass()))
147 {
148 graphics.setColor(Color.RED);
149 } else
150
151 {
152 graphics.setColor(Color.BLACK);
153 Logger.severe(this, "paint",
154 "We don't know what color to choose for actor class: "
155 + super.source.getClass());
156 }
157
158
159 graphics.fillOval((int) screenLocation.getX(), (int) screenLocation
160 .getY(), 10, 10);
161 if (scale < 0.111)
162 {
163
164 graphics.drawString(((ActorInterface) super.source).getName(),
165 (int) screenLocation.getX() + 10, (int) screenLocation
166 .getY());
167 }
168 }
169 }
170 }