*Gets regions from an overlay document
*@param doc the document from which the overlayRegions should be taken
*@return vector with overlayRegions
*/
public Hashtable getOverlayRegionsFromDocument(Document doc) {
String x, y;
Vector xvector = new Vector();
Vector yvector = new Vector();
Vector overlayRegionVector = new Vector();
Vector returnVector = new Vector();
Vector pointVector = new Vector();
Vector neighbourVector = new Vector();
String topNeighbour = new String();
String bottomNeighbour = new String();
String rightNeighbour = new String();
String leftNeighbour = new String();
if (doc != null) {
//get root element named overlayRegions
NodeList overlayRegionsList = doc.getElementsByTagName("Overlay");
if (overlayRegionsList != null) {
Node overlayRegions = overlayRegionsList.item(0);
NodeList overlayRegionList = overlayRegions.getChildNodes();
//get all nodes that are childnodes of overlayRegions and named "overlayRegion"
//and store them in vector
for (int i = 0; i < overlayRegionList.getLength(); i++) {
if (overlayRegionList.item(i).getNodeName().equals("OverlayRegion")) {
overlayRegionVector.add(overlayRegionList.item(i));
}
}
for (int e = 0; e < overlayRegionVector.size(); e++) {
Node overlayRegion = (Node) overlayRegionVector.elementAt(e);
NodeList overlayRegionPropertyList = overlayRegion.getChildNodes();
pointVector.clear();
String overlayRegionName = new String();
String overlayRegionTarget = new String();
String overlayRegionNumber = new String();
for (int r = 0; r < overlayRegionPropertyList.getLength(); r++) {
//add points into the point vector
if (overlayRegionPropertyList.item(r).getNodeName().equals("Point")) {
pointVector.add(overlayRegionPropertyList.item(r));
} else
//get name of overlayRegion
if (overlayRegionPropertyList.item(r).getNodeName().equals("Name")) {
if (hasNodeValue(overlayRegionPropertyList.item(r))) {
overlayRegionName = getNodeValue(overlayRegionPropertyList.item(r));
} else {
overlayRegionName = RecordStrings.NO_ENTRY;
}
} else
//get destination of overlayRegion
if (overlayRegionPropertyList.item(r).getNodeName().equals("TargetImage")) {
if (hasNodeValue(overlayRegionPropertyList.item(r))) {
overlayRegionTarget = getNodeValue(overlayRegionPropertyList.item(r));
} else {
overlayRegionTarget = RecordStrings.NO_ENTRY;
}
} else if (overlayRegionPropertyList.item(r).getNodeName().equals("Number")) {
if (hasNodeValue(overlayRegionPropertyList.item(r))) {
overlayRegionNumber = getNodeValue(overlayRegionPropertyList.item(r));
} else {
overlayRegionNumber = RecordStrings.NO_ENTRY;
}
} else if (overlayRegionPropertyList.item(r).getNodeName().equals("Neighbours")) {
neighbourVector.add(overlayRegionPropertyList.item(r));
for (int we = 0; we < neighbourVector.size(); we++) {
Node neighbourNode = (Node) neighbourVector.elementAt(we);
NodeList neighbourNodeList = neighbourNode.getChildNodes();
for (int uu = 0; uu < neighbourNodeList.getLength(); uu++) {
Node neighboursAroundNode = neighbourNodeList.item(uu);
if (neighboursAroundNode.getNodeName().equals("Top")) {
if (hasNodeValue(neighboursAroundNode)) {
topNeighbour = getNodeValue(neighbourNodeList.item(uu));
} else {
topNeighbour = RecordStrings.NO_ENTRY;
}
} else if (neighboursAroundNode.getNodeName().equals("Bottom")) {
if (hasNodeValue(neighboursAroundNode)) {
bottomNeighbour = getNodeValue(neighbourNodeList.item(uu));
} else {
bottomNeighbour = RecordStrings.NO_ENTRY;
}
} else if (neighboursAroundNode.getNodeName().equals("Right")) {
if (hasNodeValue(neighboursAroundNode)) {
rightNeighbour = getNodeValue(neighbourNodeList.item(uu));
} else {
rightNeighbour = RecordStrings.NO_ENTRY;
}
} else if (neighboursAroundNode.getNodeName().equals("Left")) {
if (hasNodeValue(neighboursAroundNode)) {
leftNeighbour = getNodeValue(neighbourNodeList.item(uu));
} else {
leftNeighbour = RecordStrings.NO_ENTRY;
}
}
}
}
}
}
xvector.clear();
yvector.clear();
//points of the overlayRegion are examined
for (int t = 0; t < pointVector.size(); t++) {
Node point = (Node) pointVector.elementAt(t);
NodeList coordList = point.getChildNodes();
//coordinates of the points are examined
int xCoordCounter = 0;
int yCoordCounter = 0;
for (int u = 0; u < coordList.getLength(); u++) {
//coordinates are taken first in a vector ....
if (coordList.item(u).getNodeName().equals("X")) {
if (hasNodeValue(coordList.item(u))) {
xvector.add(getNodeValue(coordList.item(u)));
xCoordCounter++;
} else {
System.out.println("Warning! Missing x-Coordinate in overlay document!");
}
} else if (coordList.item(u).getNodeName().equals("Y")) {
if (hasNodeValue(coordList.item(u))) {
yvector.add(getNodeValue(coordList.item(u)));
yCoordCounter++;
} else {
System.out.println("Warning! Missing y-Coordinate in overlay document!");
}
}
}
}
//...and then into an array
int[] xarray = new int[xvector.size()];
int[] yarray = new int[yvector.size()];
for (int p = 0; p < xvector.size(); p++) {
try {
xarray[p] = Integer.parseInt((String) xvector.elementAt(p));
yarray[p] = Integer.parseInt((String) yvector.elementAt(p));
} catch (Exception exception) {
}
}
//new imageoverlayRegions are created with the specific properties
OverlayRegion imageMapOverlayRegion = new OverlayRegion(xarray, yarray, xvector.size());
imageMapOverlayRegion.set(OverlayRegion.NAME, overlayRegionName);
imageMapOverlayRegion.set(OverlayRegion.TARGET, overlayRegionTarget);
imageMapOverlayRegion.set(OverlayRegion.NUMBER, overlayRegionNumber);
imageMapOverlayRegion.set(OverlayRegion.RIGHT_NEIGHBOUR, rightNeighbour);
imageMapOverlayRegion.set(OverlayRegion.LEFT_NEIGHBOUR, leftNeighbour);
imageMapOverlayRegion.set(OverlayRegion.TOP_NEIGHBOUR, topNeighbour);
imageMapOverlayRegion.set(OverlayRegion.BOTTOM_NEIGHBOUR, bottomNeighbour);
returnVector.add(imageMapOverlayRegion);
}
Hashtable returnHashtable = new Hashtable(returnVector.size());
for (int z = 0; z < returnVector.size(); z++) {
String overlayRegionName = ((OverlayRegion) returnVector.elementAt(z)).getName();
returnHashtable.put(overlayRegionName, (OverlayRegion) returnVector.elementAt(z));
}
return returnHashtable;
} else {
System.out.println("Overlay besitzt nicht die richtige Struktur. Root-Element <overlay> fehlt.");