Java Reference
In-Depth Information
public void
addEntity(MapEntity entity) {
entityList.add(entity);
}
// gets the entity found in location posX,posY
public
MapEntity getEntity(
int
posX,
int
posY) {
Iterator iterator
#
entityList.iterator();
while
(iterator.hasNext()) {
MapEntity entity
#
(MapEntity) iterator.next();
if
(entity.contains(posX, posY))
return
entity;
}
return null
;
}
public void
paint(Graphics2D g, Color color) { . . . }
// converts the list of entities in XML format
public
String toXML(String entityType) {
StringBuffer stream
#
new StringBuffer();
stream.append("\n <LIST TYPE
#
"
!
'"'
!
entityType
!
'"'
!
">");
Iterator iterator
#
entityList.iterator();
while
(iterator.hasNext())
stream.append(((MapEntity) iterator.next()).toXML());
stream.append("\n </LIST>");
return
stream.toString();
}
}
public class
MapLayer {
// name of the layer; "xxx" when not initialized
private
String name
#
"xxx";
private
String colorName
#
""; // colour of the entities
private
Color color
#
null
;
private boolean
visible
#
false
;
private
MapEntitySet siteSet
#
new
MapEntitySet();
private
MapEntitySet linkSet
#
new
MapEntitySet();
private
MapEntitySet areaSet
#
new
MapEntitySet();
// this constructor is invoked when a new layer is created
public
MapLayer(String name, String colorName) {
this
.name
#
name;
this
.colorName
#
colorName;
}
// this constructor is used to load a layer from file
public
MapLayer(String line, BufferedReader lineReader) {
// extracts the name of the layer
String docLine
#
line;
int
indexInit
#
docLine.indexOf("NAME
#
");
docLine
#
docLine.substring(indexInit
!
6);