Simulator/src/view/MapPanel.java
/**
	 * Adds a {@link MapComponent} to the map. It is a recursive method that at
	 * takes a component and a value as an input. The value represents the
	 * number of super classes above the component we want to add a
	 * visualization of. This is used, because some map components do not have a
	 * specific visualization. For instance, the {@link Passenger} does not have
	 * a view corresponding to it, but the {@link HumanAgent} (the superclass of
	 * {@link Passenger}) does have a corresponding view.
	 * 
	 * @param component
	 *            The component.
	 * @param superClasses
	 *            The number of super classes above.
	 */
Adds a  MapComponent to the map. It is a recursive method that at
takes a component and a value as an input. The value represents the
number of super classes above the component we want to add a
visualization of. This is used, because some map components do not have a
specific visualization. For instance, the  Passenger does not have
a view corresponding to it, but the  HumanAgent (the superclass of
Passenger) does have a corresponding view.

@param component
The component.
@param superClasses
The number of super classes above.
Adds a MapComponent to the map . It is a recursive method that at takes a component and a value as an input . The value represents the number of super classes above the component we want to add a visualization of . This is used because some map components do not have a specific visualization . For instance the Passenger does not have a view corresponding to it but the HumanAgent ( the superclass of Passenger ) does have a corresponding view . @param component The component . @param superClasses The number of super classes above .
private void addMapComponent(MapComponent component, int superClasses) {
		try {
			String className = component.getClass().getSimpleName();
			Class<?> myClass = component.getClass();
			for (int i = 0; i < superClasses; i++) {
				myClass = myClass.getSuperclass();
				className = myClass.getSimpleName();
			}
			if (className.equals("MapComponent"))
				return;
			Constructor<?> cons = null;
			for (Class<? extends MapComponentView> v : views) {
				if (v.getSimpleName().substring(0, v.getSimpleName().length() - 4).equals(className)) {
					cons = v.getConstructor(myClass);
				}
			}
			if (cons == null) {
				Class<?> c = Class.forName("view.mapComponents." + className + "View");
				cons = c.getConstructor(myClass);
			}
			Object object = cons.newInstance(component);
			mapComponents.put(component, (MapComponentView) object);
			if (component instanceof Area)
				drawingOrder.add(0, component);
			else
				drawingOrder.add(component);
		} catch (ClassNotFoundException e) {
			addMapComponent(component, superClasses + 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		repaint();
	}
private void addMapComponent ( MapComponent component , int superClasses ) { try { String className = component . getClass ( ) . getSimpleName ( ) ; Class < ? > myClass = component . getClass ( ) ; for ( int i = 0 ; i < superClasses ; i ++ ) { myClass = myClass . getSuperclass ( ) ; className = myClass . getSimpleName ( ) ; } if ( className . equals ( "MapComponent" ) ) return ; Constructor < ? > cons = null ; for ( Class < ? extends MapComponentView > v : views ) { if ( v . getSimpleName ( ) . substring ( 0 , v . getSimpleName ( ) . length ( ) - 4 ) . equals ( className ) ) { cons = v . getConstructor ( myClass ) ; } } if ( cons == null ) { Class < ? > c = Class . forName ( "view.mapComponents." + className + "View" ) ; cons = c . getConstructor ( myClass ) ; } Object object = cons . newInstance ( component ) ; mapComponents . put ( component , ( MapComponentView ) object ) ; if ( component instanceof Area ) drawingOrder . add ( 0 , component ) ; else drawingOrder . add ( component ) ; } catch ( ClassNotFoundException e ) { addMapComponent ( component , superClasses + 1 ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } repaint ( ) ; }
Adds a {@link MapComponent} to the map.
Adds a { @link MapComponent } to the map .
// safeguard // if not in our list of added views