refactor swing version
git-svn-id: https://osmand.googlecode.com/svn/trunk@56 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
690d60a782
commit
5322550b13
14 changed files with 406 additions and 85 deletions
18
DataExtractionOSM/src/com/osmand/ExceptionHandler.java
Normal file
18
DataExtractionOSM/src/com/osmand/ExceptionHandler.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.osmand;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
public class ExceptionHandler {
|
||||||
|
private static final Log log = LogUtil.getLog(ExceptionHandler.class);
|
||||||
|
|
||||||
|
public static void handle(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("Error occurred", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handle(String msg, Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -39,14 +39,18 @@ public class City {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Street registerStreet(String street){
|
||||||
|
if(!streets.containsKey(street)){
|
||||||
|
streets.put(street, new Street(street));
|
||||||
|
}
|
||||||
|
return streets.get(street);
|
||||||
|
}
|
||||||
|
|
||||||
public Street registerBuilding(LatLon point, Entity e){
|
public Street registerBuilding(LatLon point, Entity e){
|
||||||
String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
|
String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
|
||||||
String street = e.getTag(OSMTagKey.ADDR_STREET);
|
String street = e.getTag(OSMTagKey.ADDR_STREET);
|
||||||
if( street != null && number != null){
|
if( street != null && number != null){
|
||||||
if(!streets.containsKey(street)){
|
registerStreet(street).registerBuilding(point, e);
|
||||||
streets.put(street, new Street(street));
|
|
||||||
}
|
|
||||||
streets.get(street).registerBuilding(point, e);
|
|
||||||
return streets.get(street);
|
return streets.get(street);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -119,6 +119,10 @@ public class DataTileManager<T> {
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty(){
|
||||||
|
return objects.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.osmand.data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -20,9 +22,18 @@ public class Region {
|
||||||
|
|
||||||
private DataTileManager<Amenity> amenities = new DataTileManager<Amenity>();
|
private DataTileManager<Amenity> amenities = new DataTileManager<Amenity>();
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
private OsmBaseStorage storage;
|
private OsmBaseStorage storage;
|
||||||
|
|
||||||
private Map<CityType, Collection<City>> cities = new HashMap<CityType, Collection<City>>();
|
private static class CityComparator implements Comparator<City>{
|
||||||
|
@Override
|
||||||
|
public int compare(City o1, City o2) {
|
||||||
|
return o1.getName().compareTo(o2.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<CityType, List<City>> cities = new HashMap<CityType, List<City>>();
|
||||||
{
|
{
|
||||||
for(CityType type : CityType.values()){
|
for(CityType type : CityType.values()){
|
||||||
cities.put(type, new ArrayList<City>());
|
cities.put(type, new ArrayList<City>());
|
||||||
|
@ -48,13 +59,35 @@ public class Region {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
|
if(name != null){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
return entity == null ? "" : entity.getTag(OSMTagKey.NAME);
|
return entity == null ? "" : entity.getTag(OSMTagKey.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<City> getCitiesByType(CityType type){
|
public Collection<City> getCitiesByType(CityType type){
|
||||||
return cities.get(type);
|
return cities.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCitiesCount(CityType type) {
|
||||||
|
if (type == null) {
|
||||||
|
int am = 0;
|
||||||
|
for (CityType t : cities.keySet()) {
|
||||||
|
am += cities.get(t).size();
|
||||||
|
}
|
||||||
|
return am;
|
||||||
|
} else if (!cities.containsKey(type)) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return cities.get(type).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<City> getCitiesByName(String name){
|
public Collection<City> getCitiesByName(String name){
|
||||||
return getCityByName(name, true, Integer.MAX_VALUE);
|
return getCityByName(name, true, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
@ -121,6 +154,12 @@ public class Region {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void doDataPreparation(){
|
||||||
|
CityComparator comp = new CityComparator();
|
||||||
|
for(CityType t : cities.keySet()){
|
||||||
|
Collections.sort(cities.get(t), comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
package com.osmand.data;
|
package com.osmand.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
|
import com.osmand.osm.Node;
|
||||||
|
|
||||||
public class Street {
|
public class Street {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private Map<Entity, LatLon> buildings = new HashMap<Entity, LatLon>();
|
private Map<Entity, LatLon> buildings = new HashMap<Entity, LatLon>();
|
||||||
|
private List<Node> wayNodes = new ArrayList<Node>();
|
||||||
|
|
||||||
public Street(String name){
|
public Street(String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -31,5 +35,9 @@ public class Street {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Node> getWayNodes() {
|
||||||
|
return wayNodes;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.osmand;
|
package com.osmand.data.preparation;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -17,10 +17,13 @@ import org.apache.tools.bzip2.CBZip2InputStream;
|
||||||
import org.apache.tools.bzip2.CBZip2OutputStream;
|
import org.apache.tools.bzip2.CBZip2OutputStream;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.osmand.DefaultLauncherConstants;
|
||||||
|
import com.osmand.IProgress;
|
||||||
import com.osmand.data.Amenity;
|
import com.osmand.data.Amenity;
|
||||||
import com.osmand.data.City;
|
import com.osmand.data.City;
|
||||||
import com.osmand.data.DataTileManager;
|
import com.osmand.data.DataTileManager;
|
||||||
import com.osmand.data.Region;
|
import com.osmand.data.Region;
|
||||||
|
import com.osmand.data.Street;
|
||||||
import com.osmand.impl.ConsoleProgressImplementation;
|
import com.osmand.impl.ConsoleProgressImplementation;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
|
@ -79,7 +82,7 @@ public class DataExtraction {
|
||||||
|
|
||||||
private static boolean parseSmallFile = true;
|
private static boolean parseSmallFile = true;
|
||||||
private static boolean parseOSM = true;
|
private static boolean parseOSM = true;
|
||||||
private ArrayList<Way> mapWays;
|
private ArrayList<Way> ways;
|
||||||
private ArrayList<Amenity> amenities;
|
private ArrayList<Amenity> amenities;
|
||||||
private ArrayList<Entity> buildings;
|
private ArrayList<Entity> buildings;
|
||||||
private ArrayList<Node> places;
|
private ArrayList<Node> places;
|
||||||
|
@ -153,7 +156,7 @@ public class DataExtraction {
|
||||||
buildings = new ArrayList<Entity>();
|
buildings = new ArrayList<Entity>();
|
||||||
amenities = new ArrayList<Amenity>();
|
amenities = new ArrayList<Amenity>();
|
||||||
// highways count
|
// highways count
|
||||||
mapWays = new ArrayList<Way>();
|
ways = new ArrayList<Way>();
|
||||||
|
|
||||||
OsmBaseStorage storage = new OsmBaseStorage(){
|
OsmBaseStorage storage = new OsmBaseStorage(){
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,7 +190,7 @@ public class DataExtraction {
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptWayToLoad(Way w) {
|
public boolean acceptWayToLoad(Way w) {
|
||||||
if (OSMSettings.wayForCar(w.getTag(OSMTagKey.HIGHWAY))) {
|
if (OSMSettings.wayForCar(w.getTag(OSMTagKey.HIGHWAY))) {
|
||||||
mapWays.add(w);
|
ways.add(w);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -239,14 +242,23 @@ public class DataExtraction {
|
||||||
|
|
||||||
|
|
||||||
waysManager = new DataTileManager<Way>();
|
waysManager = new DataTileManager<Way>();
|
||||||
for (Way w : mapWays) {
|
for (Way w : ways) {
|
||||||
if (w.getTag(OSMTagKey.NAME) != null) {
|
if (w.getTag(OSMTagKey.NAME) != null) {
|
||||||
LatLon latLon = MapUtils.getWeightCenterForNodes(w.getNodes());
|
String street = w.getTag(OSMTagKey.NAME);
|
||||||
waysManager.registerObject(latLon.getLatitude(), latLon.getLongitude(), w);
|
LatLon center = MapUtils.getWeightCenterForNodes(w.getNodes());
|
||||||
|
City city = country.getClosestCity(center);
|
||||||
|
if (city != null) {
|
||||||
|
Street str = city.registerStreet(street);
|
||||||
|
for(Node n : w.getNodes()){
|
||||||
|
str.getWayNodes().add(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waysManager.registerObject(center.getLatitude(), center.getLongitude(), w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// way with name : МЗОР, ул. ...,
|
/// way with name : МЗОР, ул. ...,
|
||||||
|
|
||||||
|
country.doDataPreparation();
|
||||||
return country;
|
return country;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.osmand.data.preparation;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
|
||||||
|
import org.apache.tools.bzip2.CBZip2OutputStream;
|
||||||
|
|
||||||
|
import com.osmand.DefaultLauncherConstants;
|
||||||
|
import com.osmand.data.Amenity;
|
||||||
|
import com.osmand.data.Region;
|
||||||
|
import com.osmand.osm.io.OSMStorageWriter;
|
||||||
|
|
||||||
|
|
||||||
|
public class DataIndexBuilder {
|
||||||
|
|
||||||
|
private final File workingDir;
|
||||||
|
private final Region region;
|
||||||
|
private boolean zipped = true;
|
||||||
|
|
||||||
|
public DataIndexBuilder(File workingDir, Region region){
|
||||||
|
this.workingDir = workingDir;
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZipped(boolean zipped) {
|
||||||
|
this.zipped = zipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isZipped() {
|
||||||
|
return zipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected OutputStream checkFile(String name) throws IOException {
|
||||||
|
if (zipped && !name.endsWith(".bz2")) {
|
||||||
|
name += ".bz2";
|
||||||
|
}
|
||||||
|
File f = new File(workingDir, name);
|
||||||
|
f.mkdirs();
|
||||||
|
// remove existing file
|
||||||
|
if (f.exists()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
OutputStream output = new FileOutputStream(f);
|
||||||
|
if (DefaultLauncherConstants.writeTestOsmFile.endsWith(".bz2")) {
|
||||||
|
output.write('B');
|
||||||
|
output.write('Z');
|
||||||
|
output = new CBZip2OutputStream(output);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DataIndexBuilder buildPOI() throws XMLStreamException, IOException{
|
||||||
|
|
||||||
|
List<Amenity> list = region.getAmenityManager().getAllObjects();
|
||||||
|
List<Long> interestedObjects = new ArrayList<Long>(list.size());
|
||||||
|
for(Amenity a : list) {
|
||||||
|
interestedObjects.add(a.getNode().getId());
|
||||||
|
}
|
||||||
|
OutputStream output = checkFile("POI/"+region.getName()+".osm");
|
||||||
|
try {
|
||||||
|
OSMStorageWriter writer = new OSMStorageWriter(region.getStorage().getRegisteredEntities());
|
||||||
|
writer.saveStorage(output, interestedObjects, false);
|
||||||
|
} finally {
|
||||||
|
output.close();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.osmand;
|
package com.osmand.data.preparation;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -16,6 +16,10 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import com.osmand.Algoritms;
|
||||||
|
import com.osmand.DefaultLauncherConstants;
|
||||||
|
import com.osmand.LogUtil;
|
||||||
|
|
||||||
public class MapTileDownloader {
|
public class MapTileDownloader {
|
||||||
|
|
||||||
private static MapTileDownloader downloader = null;
|
private static MapTileDownloader downloader = null;
|
|
@ -58,6 +58,35 @@ public class TileSourceManager {
|
||||||
public String getUrlToLoad(int x, int y, int zoom) {
|
public String getUrlToLoad(int x, int y, int zoom) {
|
||||||
return MessageFormat.format(urlToLoad, zoom+"", x+"", y+"");
|
return MessageFormat.format(urlToLoad, zoom+"", x+"", y+"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
TileSourceTemplate other = (TileSourceTemplate) obj;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,6 @@ import java.awt.Color;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Menu;
|
|
||||||
import java.awt.MenuBar;
|
|
||||||
import java.awt.MenuItem;
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
@ -30,7 +27,10 @@ import java.util.Map;
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBoxMenuItem;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@ import org.apache.commons.logging.Log;
|
||||||
import com.osmand.DefaultLauncherConstants;
|
import com.osmand.DefaultLauncherConstants;
|
||||||
import com.osmand.IMapLocationListener;
|
import com.osmand.IMapLocationListener;
|
||||||
import com.osmand.LogUtil;
|
import com.osmand.LogUtil;
|
||||||
import com.osmand.MapTileDownloader;
|
|
||||||
import com.osmand.MapTileDownloader.DownloadRequest;
|
|
||||||
import com.osmand.MapTileDownloader.IMapDownloaderCallback;
|
|
||||||
import com.osmand.data.DataTileManager;
|
import com.osmand.data.DataTileManager;
|
||||||
|
import com.osmand.data.preparation.MapTileDownloader;
|
||||||
|
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||||
|
import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
|
||||||
import com.osmand.map.ITileSource;
|
import com.osmand.map.ITileSource;
|
||||||
import com.osmand.map.TileSourceManager;
|
import com.osmand.map.TileSourceManager;
|
||||||
import com.osmand.map.TileSourceManager.TileSourceTemplate;
|
import com.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||||
|
@ -55,18 +55,28 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
|
|
||||||
protected static final Log log = LogUtil.getLog(MapPanel.class);
|
protected static final Log log = LogUtil.getLog(MapPanel.class);
|
||||||
|
|
||||||
public static Menu getMenuToChooseSource(final MapPanel panel){
|
public static JMenu getMenuToChooseSource(final MapPanel panel){
|
||||||
Menu tiles = new Menu("Source tile");
|
final JMenu tiles = new JMenu("Source tile");
|
||||||
List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
|
final List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
|
||||||
for(final TileSourceTemplate l : list){
|
for(final TileSourceTemplate l : list){
|
||||||
MenuItem menuItem = new MenuItem(l.getName());
|
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(l.getName());
|
||||||
menuItem.addActionListener(new ActionListener(){
|
menuItem.addActionListener(new ActionListener(){
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
for(int i=0; i<tiles.getItemCount(); i++){
|
||||||
|
if(list.get(i).equals(l)){
|
||||||
|
((JCheckBoxMenuItem)tiles.getItem(i)).setSelected(true);
|
||||||
|
} else {
|
||||||
|
((JCheckBoxMenuItem)tiles.getItem(i)).setSelected(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
panel.setMapName(l);
|
panel.setMapName(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if(l.equals(DefaultLauncherConstants.MAP_defaultTileSource)){
|
||||||
|
menuItem.setSelected(true);
|
||||||
|
}
|
||||||
tiles.add(menuItem);
|
tiles.add(menuItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +100,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
|
|
||||||
content.add(panel, BorderLayout.CENTER);
|
content.add(panel, BorderLayout.CENTER);
|
||||||
|
|
||||||
MenuBar bar = new MenuBar();
|
JMenuBar bar = new JMenuBar();
|
||||||
bar.add(getMenuToChooseSource(panel));
|
bar.add(getMenuToChooseSource(panel));
|
||||||
frame.setMenuBar(bar);
|
frame.setJMenuBar(bar);
|
||||||
frame.setSize(512, 512);
|
frame.setSize(512, 512);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,7 @@ package com.osmand.swing;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Menu;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.MenuBar;
|
|
||||||
import java.awt.MenuItem;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
|
@ -17,16 +15,23 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.EventObject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSplitPane;
|
import javax.swing.JSplitPane;
|
||||||
|
@ -35,21 +40,27 @@ import javax.swing.JTree;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import javax.swing.event.TreeModelEvent;
|
||||||
|
import javax.swing.event.TreeModelListener;
|
||||||
import javax.swing.event.TreeSelectionEvent;
|
import javax.swing.event.TreeSelectionEvent;
|
||||||
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.event.TreeSelectionListener;
|
||||||
import javax.swing.event.UndoableEditEvent;
|
import javax.swing.event.UndoableEditEvent;
|
||||||
import javax.swing.event.UndoableEditListener;
|
import javax.swing.event.UndoableEditListener;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.DefaultTreeCellEditor;
|
||||||
|
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
|
import javax.swing.tree.TreeCellEditor;
|
||||||
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.osmand.Algoritms;
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.DataExtraction;
|
|
||||||
import com.osmand.DefaultLauncherConstants;
|
import com.osmand.DefaultLauncherConstants;
|
||||||
|
import com.osmand.ExceptionHandler;
|
||||||
import com.osmand.IMapLocationListener;
|
import com.osmand.IMapLocationListener;
|
||||||
import com.osmand.data.Amenity;
|
import com.osmand.data.Amenity;
|
||||||
import com.osmand.data.City;
|
import com.osmand.data.City;
|
||||||
|
@ -57,6 +68,8 @@ import com.osmand.data.Region;
|
||||||
import com.osmand.data.Street;
|
import com.osmand.data.Street;
|
||||||
import com.osmand.data.Amenity.AmenityType;
|
import com.osmand.data.Amenity.AmenityType;
|
||||||
import com.osmand.data.City.CityType;
|
import com.osmand.data.City.CityType;
|
||||||
|
import com.osmand.data.preparation.DataExtraction;
|
||||||
|
import com.osmand.data.preparation.DataIndexBuilder;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
import com.osmand.osm.MapUtils;
|
import com.osmand.osm.MapUtils;
|
||||||
|
@ -75,7 +88,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
protected City selectedCity;
|
protected City selectedCity;
|
||||||
private MapPanel mapPanel = new MapPanel(new File(DefaultLauncherConstants.pathToDirWithTiles));
|
private MapPanel mapPanel = new MapPanel(new File(DefaultLauncherConstants.pathToDirWithTiles));
|
||||||
|
|
||||||
private DefaultMutableTreeNode amenitiesTree;
|
private DataExtractionTreeNode amenitiesTree;
|
||||||
private JTree treePlaces;
|
private JTree treePlaces;
|
||||||
private JList searchList;
|
private JList searchList;
|
||||||
private JTextField searchTextField;
|
private JTextField searchTextField;
|
||||||
|
@ -85,8 +98,10 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
|
|
||||||
private Region region;
|
private Region region;
|
||||||
private File workingDir;
|
private File workingDir;
|
||||||
private JLabel workingDirLabel;
|
|
||||||
private JButton generateDataButton;
|
private JButton generateDataButton;
|
||||||
|
private JCheckBox buildPoiIndex;
|
||||||
|
private JCheckBox buildAddressIndex;
|
||||||
|
private TreeModelListener treeModelListener;
|
||||||
|
|
||||||
|
|
||||||
public OsmExtractionUI(final Region r){
|
public OsmExtractionUI(final Region r){
|
||||||
|
@ -143,7 +158,10 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
updateListCities(region, searchTextField.getText(), searchList);
|
updateListCities(region, searchTextField.getText(), searchList);
|
||||||
}
|
}
|
||||||
mapPanel.repaint();
|
mapPanel.repaint();
|
||||||
treePlaces.setModel(new DefaultTreeModel(root, false));
|
DefaultTreeModel newModel = new DefaultTreeModel(root, false);
|
||||||
|
newModel.addTreeModelListener(treeModelListener);
|
||||||
|
treePlaces.setModel(newModel);
|
||||||
|
updateButtonsBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,12 +178,14 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
frame.addWindowListener(new ExitListener());
|
frame.addWindowListener(new ExitListener());
|
||||||
Container content = frame.getContentPane();
|
Container content = frame.getContentPane();
|
||||||
frame.setFocusable(true);
|
frame.setFocusable(true);
|
||||||
|
|
||||||
statusBarLabel = new JLabel();
|
statusBarLabel = new JLabel();
|
||||||
content.add(statusBarLabel, BorderLayout.SOUTH);
|
content.add(statusBarLabel, BorderLayout.SOUTH);
|
||||||
treePlaces = new JTree();
|
statusBarLabel.setText(workingDir == null ? "<working directory unspecified>" : "Working directory : " + workingDir.getAbsolutePath());
|
||||||
treePlaces.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Region"), false));
|
|
||||||
|
|
||||||
|
|
||||||
JSplitPane panelForTreeAndMap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePlaces), mapPanel);
|
JSplitPane panelForTreeAndMap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(createTree(content)), mapPanel);
|
||||||
panelForTreeAndMap.setResizeWeight(0.2);
|
panelForTreeAndMap.setResizeWeight(0.2);
|
||||||
mapPanel.setFocusable(true);
|
mapPanel.setFocusable(true);
|
||||||
mapPanel.addMapLocationListener(this);
|
mapPanel.addMapLocationListener(this);
|
||||||
|
@ -180,36 +200,50 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
} else {
|
} else {
|
||||||
content.add(panelForTreeAndMap, BorderLayout.CENTER);
|
content.add(panelForTreeAndMap, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JMenuBar bar = new JMenuBar();
|
||||||
|
fillMenuWithActions(bar);
|
||||||
|
|
||||||
|
frame.setJMenuBar(bar);
|
||||||
treePlaces.addTreeSelectionListener(new TreeSelectionListener(){
|
}
|
||||||
|
|
||||||
|
public JTree createTree(Container content) {
|
||||||
|
treePlaces = new JTree();
|
||||||
|
treePlaces.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Region"), false));
|
||||||
|
treePlaces.setEditable(true);
|
||||||
|
treePlaces.setCellEditor(new RegionCellEditor(treePlaces, (DefaultTreeCellRenderer) treePlaces.getCellRenderer()));
|
||||||
|
treePlaces.addTreeSelectionListener(new TreeSelectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(TreeSelectionEvent e) {
|
public void valueChanged(TreeSelectionEvent e) {
|
||||||
if (e.getPath() != null) {
|
if (e.getPath() != null) {
|
||||||
if (e.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) {
|
if (e.getPath().getLastPathComponent() instanceof DataExtractionTreeNode) {
|
||||||
Object o = ((DefaultMutableTreeNode) e.getPath().getLastPathComponent()).getUserObject();
|
Object o = ((DataExtractionTreeNode) e.getPath().getLastPathComponent()).getModelObject();
|
||||||
|
|
||||||
if (o instanceof City) {
|
if (o instanceof City) {
|
||||||
City c = (City) o;
|
City c = (City) o;
|
||||||
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
||||||
mapPanel.requestFocus();
|
mapPanel.requestFocus();
|
||||||
}
|
} else if (o instanceof Street) {
|
||||||
if (o instanceof Amenity) {
|
Street s = (Street) o;
|
||||||
|
LatLon center = MapUtils.getWeightCenterForNodes(s.getWayNodes());
|
||||||
|
if(center != null){
|
||||||
|
mapPanel.setLatLon(center.getLatitude(), center.getLongitude());
|
||||||
|
mapPanel.requestFocus();
|
||||||
|
}
|
||||||
|
} else if (o instanceof Amenity) {
|
||||||
Amenity c = (Amenity) o;
|
Amenity c = (Amenity) o;
|
||||||
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
||||||
mapPanel.requestFocus();
|
mapPanel.requestFocus();
|
||||||
}
|
} else if (o instanceof Entity) {
|
||||||
|
|
||||||
if (o instanceof Entity) {
|
|
||||||
Entity c = (Entity) o;
|
Entity c = (Entity) o;
|
||||||
if (c instanceof Node) {
|
if (c instanceof Node) {
|
||||||
mapPanel.setLatLon(((Node) c).getLatitude(), ((Node) c).getLongitude());
|
mapPanel.setLatLon(((Node) c).getLatitude(), ((Node) c).getLongitude());
|
||||||
mapPanel.requestFocus();
|
mapPanel.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.getPath().getPathComponent(
|
DataExtractionTreeNode n = (DataExtractionTreeNode) e.getPath().getPathComponent(
|
||||||
e.getPath().getPathCount() - 2);
|
e.getPath().getPathCount() - 2);
|
||||||
if (n.getUserObject() instanceof Street) {
|
if (n.getModelObject() instanceof Street) {
|
||||||
Street str = (Street) n.getUserObject();
|
Street str = (Street) n.getModelObject();
|
||||||
LatLon l = str.getLocationBuilding(c);
|
LatLon l = str.getLocationBuilding(c);
|
||||||
mapPanel.setLatLon(l.getLatitude(), l.getLongitude());
|
mapPanel.setLatLon(l.getLatitude(), l.getLongitude());
|
||||||
mapPanel.requestFocus();
|
mapPanel.requestFocus();
|
||||||
|
@ -218,23 +252,84 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
treeModelListener = new TreeModelListener() {
|
||||||
|
public void treeNodesChanged(TreeModelEvent e) {
|
||||||
|
DefaultMutableTreeNode node;
|
||||||
|
node = (DefaultMutableTreeNode)
|
||||||
|
(e.getTreePath().getLastPathComponent());
|
||||||
|
if(node instanceof DataExtractionTreeNode && ((DataExtractionTreeNode) node).getModelObject() instanceof Region){
|
||||||
|
Region r = (Region) ((DataExtractionTreeNode) node).getModelObject();
|
||||||
|
r.setName(node.getUserObject().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void treeNodesInserted(TreeModelEvent e) {
|
||||||
|
}
|
||||||
|
public void treeNodesRemoved(TreeModelEvent e) {
|
||||||
|
}
|
||||||
|
public void treeStructureChanged(TreeModelEvent e) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
treePlaces.getModel().addTreeModelListener(treeModelListener);
|
||||||
|
return treePlaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateButtonsBar() {
|
||||||
|
generateDataButton.setEnabled(workingDir != null && region != null);
|
||||||
|
buildAddressIndex.setEnabled(generateDataButton.isEnabled() && region.getCitiesCount(null) > 0);
|
||||||
|
buildPoiIndex.setEnabled(generateDataButton.isEnabled() && !region.getAmenityManager().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createButtonsBar(Container content){
|
public void createButtonsBar(Container content){
|
||||||
JPanel panel = new JPanel(new BorderLayout());
|
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
content.add(panel, BorderLayout.NORTH);
|
content.add(panel, BorderLayout.NORTH);
|
||||||
|
|
||||||
generateDataButton = new JButton();
|
generateDataButton = new JButton();
|
||||||
generateDataButton.setText("Generate data ");
|
generateDataButton.setText("Generate data ");
|
||||||
|
generateDataButton.setToolTipText("Data with selected preferences will be generated in working directory." +
|
||||||
|
" The index files will be named as region in tree. All existing data will be overwritten.");
|
||||||
panel.add(generateDataButton);
|
panel.add(generateDataButton);
|
||||||
generateDataButton.setEnabled(workingDir != null);
|
|
||||||
|
|
||||||
workingDirLabel = new JLabel();
|
generateDataButton.addActionListener(new ActionListener(){
|
||||||
workingDirLabel.setText(workingDir == null ? "<working dir unspecified>" : workingDir.getAbsolutePath());
|
|
||||||
panel.add(workingDirLabel);
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
DataIndexBuilder builder = new DataIndexBuilder(workingDir, region);
|
||||||
|
StringBuilder msg = new StringBuilder();
|
||||||
|
try {
|
||||||
|
msg.append("Indices checked for ").append(region.getName());
|
||||||
|
if(buildPoiIndex.isEnabled()){
|
||||||
|
builder.buildPOI();
|
||||||
|
msg.append(", POI index ").append("successfully created");
|
||||||
|
}
|
||||||
|
msg.append(".");
|
||||||
|
JOptionPane pane = new JOptionPane(msg);
|
||||||
|
JDialog dialog = pane.createDialog(frame, "Generation data");
|
||||||
|
dialog.setVisible(true);
|
||||||
|
} catch (XMLStreamException e1) {
|
||||||
|
ExceptionHandler.handle(e1);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
ExceptionHandler.handle(e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
buildPoiIndex = new JCheckBox();
|
||||||
|
buildPoiIndex.setText("Build POI index");
|
||||||
|
panel.add(buildPoiIndex);
|
||||||
|
buildPoiIndex.setSelected(true);
|
||||||
|
|
||||||
|
buildAddressIndex = new JCheckBox();
|
||||||
|
buildAddressIndex.setText("Build Address index");
|
||||||
|
panel.add(buildAddressIndex);
|
||||||
|
buildAddressIndex.setSelected(true);
|
||||||
|
|
||||||
|
updateButtonsBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createCitySearchPanel(Container content){
|
public void createCitySearchPanel(Container content){
|
||||||
|
@ -292,14 +387,12 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
if(selectedCity != null){
|
if(selectedCity != null){
|
||||||
text += " distance " + MapUtils.getDistance(selectedCity.getNode(), node);
|
text += " distance " + MapUtils.getDistance(selectedCity.getNode(), node);
|
||||||
}
|
}
|
||||||
statusBarLabel.setText(text);
|
|
||||||
mapPanel.setLatLon(node.getLatitude(), node.getLongitude());
|
mapPanel.setLatLon(node.getLatitude(), node.getLongitude());
|
||||||
} else {
|
|
||||||
String text = selectedCity == null ? "" : selectedCity.getName();
|
|
||||||
statusBarLabel.setText(text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runUI(){
|
public void runUI(){
|
||||||
|
@ -307,15 +400,15 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillMenuWithActions(MenuBar bar){
|
public void fillMenuWithActions(JMenuBar bar){
|
||||||
Menu menu = new Menu("File");
|
JMenu menu = new JMenu("File");
|
||||||
bar.add(menu);
|
bar.add(menu);
|
||||||
MenuItem loadFile = new MenuItem("Load osm file...");
|
JMenuItem loadFile = new JMenuItem("Load osm file...");
|
||||||
menu.add(loadFile);
|
menu.add(loadFile);
|
||||||
MenuItem specifyWorkingDir = new MenuItem("Specify working directory...");
|
JMenuItem specifyWorkingDir = new JMenuItem("Specify working directory...");
|
||||||
menu.add(specifyWorkingDir);
|
menu.add(specifyWorkingDir);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
MenuItem exitMenu= new MenuItem("Exit");
|
JMenuItem exitMenu= new JMenuItem("Exit");
|
||||||
menu.add(exitMenu);
|
menu.add(exitMenu);
|
||||||
|
|
||||||
bar.add(MapPanel.getMenuToChooseSource(mapPanel));
|
bar.add(MapPanel.getMenuToChooseSource(mapPanel));
|
||||||
|
@ -326,7 +419,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
frame.setVisible(false);
|
frame.setVisible(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
specifyWorkingDir.addActionListener(new ActionListener(){
|
specifyWorkingDir.addActionListener(new ActionListener(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -340,8 +432,8 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
if(fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null &&
|
if(fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null &&
|
||||||
fc.getSelectedFile().isDirectory()){
|
fc.getSelectedFile().isDirectory()){
|
||||||
workingDir = fc.getSelectedFile();
|
workingDir = fc.getSelectedFile();
|
||||||
workingDirLabel.setText(fc.getSelectedFile().getAbsolutePath());
|
statusBarLabel.setText("Working directory : " + fc.getSelectedFile().getAbsolutePath());
|
||||||
generateDataButton.setEnabled(true);
|
updateButtonsBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +492,10 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
Region region = (Region) dlg.run();
|
Region region = (Region) dlg.run();
|
||||||
if(region != null){
|
if(region != null){
|
||||||
int i = f.getName().indexOf('.');
|
int i = f.getName().indexOf('.');
|
||||||
setRegion(region, Algoritms.capitalizeFirstLetterAndLowercase(f.getName().substring(0, i)));
|
if(region.getName().isEmpty()){
|
||||||
|
region.setName(Algoritms.capitalizeFirstLetterAndLowercase(f.getName().substring(0, i)));
|
||||||
|
}
|
||||||
|
setRegion(region, region.getName());
|
||||||
frame.setTitle("OsmAnd Map Creator - " + f.getName());
|
frame.setTitle("OsmAnd Map Creator - " + f.getName());
|
||||||
} else {
|
} else {
|
||||||
//frame.setTitle("OsmAnd Map Creator");
|
//frame.setTitle("OsmAnd Map Creator");
|
||||||
|
@ -415,7 +510,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
@Override
|
@Override
|
||||||
public void locationChanged(final double newLatitude, final double newLongitude, Object source){
|
public void locationChanged(final double newLatitude, final double newLongitude, Object source){
|
||||||
if (amenitiesTree != null) {
|
if (amenitiesTree != null) {
|
||||||
Region reg = (Region) amenitiesTree.getUserObject();
|
Region reg = (Region) amenitiesTree.getModelObject();
|
||||||
List<Amenity> closestAmenities = reg.getClosestAmenities(newLatitude, newLongitude);
|
List<Amenity> closestAmenities = reg.getClosestAmenities(newLatitude, newLongitude);
|
||||||
Collections.sort(closestAmenities, new Comparator<Amenity>() {
|
Collections.sort(closestAmenities, new Comparator<Amenity>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -436,7 +531,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
|
|
||||||
|
|
||||||
for (int i = 1; i < amenitiesTree.getChildCount(); i++) {
|
for (int i = 1; i < amenitiesTree.getChildCount(); i++) {
|
||||||
AmenityType type = (AmenityType) ((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).getUserObject();
|
AmenityType type = (AmenityType) ((DataExtractionTreeNode) amenitiesTree.getChildAt(i)).getModelObject();
|
||||||
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).removeAllChildren();
|
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).removeAllChildren();
|
||||||
if (filter.get(type) != null) {
|
if (filter.get(type) != null) {
|
||||||
for (Amenity n : filter.get(type)) {
|
for (Amenity n : filter.get(type)) {
|
||||||
|
@ -480,19 +575,41 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
|
|
||||||
public static class DataExtractionTreeNode extends DefaultMutableTreeNode {
|
public static class DataExtractionTreeNode extends DefaultMutableTreeNode {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private String name;
|
private final Object modelObject;
|
||||||
|
|
||||||
public DataExtractionTreeNode(String name, Object userObject){
|
public DataExtractionTreeNode(String name, Object modelObject){
|
||||||
super(userObject);
|
super(name);
|
||||||
this.name = name;
|
this.modelObject = modelObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public Object getModelObject(){
|
||||||
this.name = name;
|
return modelObject;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public String toString() {
|
}
|
||||||
return name;
|
|
||||||
|
public static class RegionCellEditor extends DefaultTreeCellEditor {
|
||||||
|
|
||||||
|
public RegionCellEditor(JTree tree, DefaultTreeCellRenderer renderer) {
|
||||||
|
super(tree, renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) {
|
||||||
|
super(tree, renderer, editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCellEditable(EventObject event) {
|
||||||
|
boolean returnValue = super.isCellEditable(event);
|
||||||
|
if (returnValue) {
|
||||||
|
Object node = tree.getLastSelectedPathComponent();
|
||||||
|
if (node instanceof DataExtractionTreeNode) {
|
||||||
|
DataExtractionTreeNode treeNode = (DataExtractionTreeNode) node;
|
||||||
|
if (treeNode.getModelObject() instanceof Region) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry excluding="**/MapPanel*|com/osmand/LogUtil.java|com/osmand/osm/io/OSMStorageWriter.java|com/osmand/DataExtraction.java|com/osmand/swing/" kind="src" path="use"/>
|
<classpathentry excluding="**/MapPanel*|com/osmand/LogUtil.java|com/osmand/osm/io/OSMStorageWriter.java|com/osmand/DataExtraction.java|com/osmand/swing/|com/osmand/data/preparation/DataExtraction.java" kind="src" path="use"/>
|
||||||
<classpathentry kind="src" path="gen"/>
|
<classpathentry kind="src" path="gen"/>
|
||||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
<classpathentry kind="lib" path="lib/bzip2-20090327.jar"/>
|
<classpathentry kind="lib" path="lib/bzip2-20090327.jar"/>
|
||||||
|
|
|
@ -18,9 +18,10 @@ import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import com.osmand.MapTileDownloader.DownloadRequest;
|
|
||||||
import com.osmand.data.Amenity;
|
import com.osmand.data.Amenity;
|
||||||
import com.osmand.data.DataTileManager;
|
import com.osmand.data.DataTileManager;
|
||||||
|
import com.osmand.data.preparation.MapTileDownloader;
|
||||||
|
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||||
import com.osmand.map.ITileSource;
|
import com.osmand.map.ITileSource;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.Node;
|
import com.osmand.osm.Node;
|
||||||
|
|
|
@ -23,11 +23,11 @@ import android.view.SurfaceHolder.Callback;
|
||||||
import com.osmand.DefaultLauncherConstants;
|
import com.osmand.DefaultLauncherConstants;
|
||||||
import com.osmand.IMapLocationListener;
|
import com.osmand.IMapLocationListener;
|
||||||
import com.osmand.LogUtil;
|
import com.osmand.LogUtil;
|
||||||
import com.osmand.MapTileDownloader;
|
|
||||||
import com.osmand.OsmandSettings;
|
import com.osmand.OsmandSettings;
|
||||||
import com.osmand.ResourceManager;
|
import com.osmand.ResourceManager;
|
||||||
import com.osmand.MapTileDownloader.DownloadRequest;
|
import com.osmand.data.preparation.MapTileDownloader;
|
||||||
import com.osmand.MapTileDownloader.IMapDownloaderCallback;
|
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||||
|
import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
|
||||||
import com.osmand.map.ITileSource;
|
import com.osmand.map.ITileSource;
|
||||||
import com.osmand.osm.MapUtils;
|
import com.osmand.osm.MapUtils;
|
||||||
import com.osmand.views.AnimateDraggingMapThread.AnimateDraggingCallback;
|
import com.osmand.views.AnimateDraggingMapThread.AnimateDraggingCallback;
|
||||||
|
|
Loading…
Reference in a new issue