sl = new SelectionLayer(map.getWidth(), map.getHeight());
Rectangle bounds = new Rectangle();
final Iterator<MapLayer> itr = map.getLayers();
while (itr.hasNext()) {
MapLayer layer = itr.next();
if (layer instanceof TileLayer) {
layer.getBounds(bounds);
for (int y = 0; y < bounds.height; y++) {
for (int x = 0; x < bounds.width; x++) {
if (((TileLayer) layer).getTileAt(x, y) == searchCBox.getSelectedItem()) {
sl.select(x, y);
}
}
}
}
}
map.addLayerSpecial(sl);
map.touch();
} else if (command.equals(REPLACE_ALL_BUTTON)) {
if (!(searchCBox.getSelectedItem() instanceof TileSet) && !(replaceCBox.getSelectedItem() instanceof TileSet))
replaceAll((Tile) searchCBox.getSelectedItem(), (Tile) replaceCBox.getSelectedItem());
} else if (command.equals(REPLACE_BUTTON)) {
if (searchCBox.getSelectedItem() instanceof Tile && replaceCBox.getSelectedItem() instanceof Tile) {
if (currentMatch == null) {
find((Tile) searchCBox.getSelectedItem());
}
// run through the layers, look for the first instance of the
// tile we need to replace
final Iterator<MapLayer> itr = map.getLayers();
while (itr.hasNext()) {
MapLayer layer = itr.next();
if (layer instanceof TileLayer) {
if (((TileLayer) layer).getTileAt(currentMatch.x, currentMatch.y) == searchCBox.getSelectedItem()) {
((TileLayer) layer).setTileAt(currentMatch.x, currentMatch.y, (Tile) replaceCBox.getSelectedItem());
break;
}