View Javadoc

1   /*
2    * @(#) DistributedGisLegendRenderable.java Dec 14, 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.Color;
17  import java.awt.Dimension;
18  import java.awt.Graphics2D;
19  import java.awt.geom.Rectangle2D;
20  import java.awt.image.ImageObserver;
21  import java.io.Serializable;
22  import java.rmi.RemoteException;
23  
24  import javax.vecmath.Point2d;
25  
26  import nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface;
27  import nl.tudelft.simulation.dsol.gui.animation2D.GridPanel;
28  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
29  import nl.tudelft.simulation.language.d3.DirectedPoint;
30  import nl.tudelft.simulation.logger.Logger;
31  
32  /***
33   * Displays the legend on a non-remote animation panel.
34   * <p>
35   * 
36   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
37   * Delft, the Netherlands. All rights reserved.
38   * 
39   * See for project information <a href="http://www.simulation.tudelft.nl/">
40   * www.simulation.tudelft.nl </a>.
41   * 
42   * The source code and binary code of this software is proprietary information
43   * of Delft University of Technology.
44   * 
45   * @author <a
46   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
47   *         van Houten </a>
48   * @version $Revision: 1.2 $ $Date: 2005/08/10 11:23:30 $
49   * @since 1.0
50   */
51  public class GisLegendRenderable extends GisGraphicsRenderable implements
52  		Serializable
53  {
54  	/*** the serial version uid */
55  	private static final long serialVersionUID = 11L;
56  
57  	/***
58  	 * constructs a new GisLegendRenderable; this emtpy constructor is needed
59  	 * for persistency reasons
60  	 */
61  	public GisLegendRenderable()
62  	{
63  		super();
64  	}
65  
66  	/***
67  	 * constructs a new DistributedGisLegendRenderable
68  	 * 
69  	 * @param location the location
70  	 * @param simulator the simulator
71  	 * @param contextName the name of the context to bind the renderale into
72  	 *        should only be used in case of deserialization; should be null
73  	 *        otherwise
74  	 */
75  	public GisLegendRenderable(final DirectedPoint location,
76  			final SimulatorInterface simulator, final String contextName)
77  	{
78  		super(location, simulator, contextName);
79  	}
80  
81  	/***
82  	 * @see nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface#paint(java.awt.Graphics2D,
83  	 *      java.awt.geom.Rectangle2D, java.awt.Dimension,
84  	 *      java.awt.image.ImageObserver)
85  	 */
86  	public synchronized void paint(final Graphics2D graphics,
87  			final Rectangle2D rectangle, final Dimension dimension,
88  			final ImageObserver observer)
89  	{
90  
91  		GridPanel animationPanel = (GridPanel) observer;
92  
93  		double scale = Renderable2DInterface.Util.getScale(animationPanel
94  				.getExtent(), animationPanel.getSize());
95  		// System.out.println("Scale: " + scale);
96  
97  		Point2d screenLocation = null;
98  		try
99  		{
100 			screenLocation = new Point2d(super.locatable.getLocation().x,
101 					super.locatable.getLocation().y);
102 		} catch (RemoteException remoteException)
103 		{
104 			Logger.severe(this, "paint", remoteException);
105 		}
106 
107 		// we only draw our images if there is a certain zoom level
108 		if (scale >= 0.05063)
109 		{
110 			// supplier
111 			graphics.setColor(Color.YELLOW);
112 			graphics.fillOval((int) screenLocation.x, (int) screenLocation.y,
113 					10, 10);
114 			graphics.drawString("Supplier", (int) screenLocation.x + 25,
115 					(int) screenLocation.y + 10);
116 
117 
118 			// manufacturer
119 			graphics.setColor(Color.BLUE);
120 			graphics.fillOval((int) screenLocation.x,
121 					(int) screenLocation.y + 15, 10, 10);
122 			graphics.drawString("Manufacturer", (int) screenLocation.x + 25,
123 					(int) screenLocation.y + 25);
124 
125 			// distributor
126 			graphics.setColor(Color.RED);
127 			graphics.fillOval((int) screenLocation.x,
128 					(int) screenLocation.y + 30, 10, 10);
129 			graphics.drawString("Distributor", (int) screenLocation.x + 25,
130 					(int) screenLocation.y + 40);
131 
132 			// market
133 			graphics.setColor(Color.GREEN);
134 			graphics.fillOval((int) screenLocation.x,
135 					(int) screenLocation.y + 45, 10, 10);
136 			graphics.drawString("Market", (int) screenLocation.x + 25,
137 					(int) screenLocation.y + 55);
138 		}
139 	}
140 }