Ticket #6955: MapScene.java

File MapScene.java, 1.2 KB (added by jhuntley, 15 years ago)
Line 
1/**
2 *
3 */
4package org.openstreetmap.gui.jmapviewer.scene;
5
6import java.awt.Graphics;
7import java.util.Vector;
8
9import org.openstreetmap.gui.jmapviewer.JMapViewer;
10import org.openstreetmap.gui.jmapviewer.scene.entities.MapObject;
11
12/**
13 * Starting off with a really simple scene graph for rendering 2D
14 * objects.
15 *
16 * @author Jason Huntley
17 *
18 */
19public class MapScene {
20 protected Vector<MapObject> mapObjectList;
21 private JMapViewer view = null;
22
23 public MapScene(JMapViewer view) {
24 mapObjectList = new Vector<MapObject>();
25 this.view=view;
26 }
27
28 /**
29 * @return the view
30 */
31 public JMapViewer getView() {
32 return view;
33 }
34
35 public void addMapObject(MapObject obj) {
36 obj.initialize(getView());
37 mapObjectList.add(obj);
38 }
39
40 public void removeMapObject(MapObject obj) {
41 mapObjectList.remove(obj);
42 }
43
44 public void drawScene(Graphics g) {
45 for (MapObject object : mapObjectList) {
46 object.update(view);
47 object.draw(g, getView());
48 }
49 }
50
51 public void clear() {
52 mapObjectList.clear();
53 }
54}