TileSet tileset = (TileSet)tilesets.get(0); int twidth = tileset.getTileWidth() + 1; int theight = tileset.getTileHeight() + 1; int tx = x / twidth; int ty = y / theight; int tilesPerRow = (getWidth() - 1) / twidth; int tileId = ty * tilesPerRow + tx;
if (tileset != null) { int twidth = tileset.getTileWidth() + 1; int theight = tileset.getTileHeight() + 1; int tx = x / twidth; int ty = y / theight; int tilesPerRow = (getWidth() - 1) / twidth; int tileId = ty * tilesPerRow + tx;
    public Tile getTileAtPoint(int x, int y) {        Tile ret;        // TODO: This code only works if one and only one tileset is selected        // from the list.        TileSet tileset = (TileSet)tilesets.get(0);        int twidth = tileset.getTileWidth() + 1;        int theight = tileset.getTileHeight() + 1;        int tx = x / twidth;        int ty = y / theight;        int tilesPerRow = (getWidth() - 1) / twidth;        int tileId = ty * tilesPerRow + tx;        // Now that we're in the right "spot", find the next valid tile        // todo: Assumes to gab is so big that a tile can be found between the        // todo: right spot and the tile that was actually clicked, actually        // todo: I'm not sure whether this works at all. - Bjorn        while ((ret = tileset.getTile(tileId++)) == null) {            if (tileId > tileset.getMaxTileId()) break;        }        return ret;    }