redesign swing UI to support new index creator mechanism

git-svn-id: https://osmand.googlecode.com/svn/trunk@509 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-09-19 10:42:16 +00:00
parent 0afdfa96dc
commit ce36617681
8 changed files with 358 additions and 1929 deletions

View file

@ -0,0 +1,23 @@
package net.osmand.data;
import java.text.Collator;
import java.util.Comparator;
public class CityComparator implements Comparator<City>{
private final boolean en;
Collator collator = Collator.getInstance();
public CityComparator(boolean en){
this.en = en;
}
@Override
public int compare(City o1, City o2) {
if(en){
return collator.compare(o1.getEnName(), o2.getEnName());
} else {
return collator.compare(o1.getName(), o2.getName());
}
}
}

View file

@ -1,188 +0,0 @@
package net.osmand.data;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.Algoritms;
import net.osmand.data.City.CityType;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
import net.osmand.osm.Node;
import net.osmand.osm.io.OsmBaseStorage;
public class Region extends MapObject {
private DataTileManager<Amenity> amenities = new DataTileManager<Amenity>();
private OsmBaseStorage storage;
private DataTileManager<City> cityManager = new DataTileManager<City>();
private Map<String, List<TransportRoute>> routes = new LinkedHashMap<String, List<TransportRoute>>();
private Map<CityType, List<City>> cities = new HashMap<CityType, List<City>>();
{
cityManager.setZoom(10);
for(CityType type : CityType.values()){
cities.put(type, new ArrayList<City>());
}
}
public static class CityComparator implements Comparator<City>{
private final boolean en;
public CityComparator(boolean en){
this.en = en;
}
Collator collator = Collator.getInstance();
@Override
public int compare(City o1, City o2) {
if(en){
return collator.compare(o1.getEnName(), o2.getEnName());
} else {
return collator.compare(o1.getName(), o2.getName());
}
}
}
public Region(){
name = "Region"; //$NON-NLS-1$
}
public OsmBaseStorage getStorage() {
return storage;
}
public void setStorage(OsmBaseStorage storage) {
this.storage = storage;
}
public Collection<City> getCitiesByType(CityType 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){
return getCityByName(name, true, Integer.MAX_VALUE);
}
public Collection<City> getSuggestedCities(String name, int number){
return getCityByName(name, false, number);
}
protected Collection<City> getCityByName(String name, boolean exactMatch, int number){
List<City> l = new ArrayList<City>();
for(CityType type : CityType.values()){
for(City c : cities.get(type)){
if( (exactMatch && c.getName().equalsIgnoreCase(name)) ||
(!exactMatch && c.getName().toLowerCase().startsWith(name.toLowerCase())
)){
l.add(c);
if(l.size() >= number){
break;
}
}
}
}
return l;
}
public City getClosestCity(LatLon point) {
City closest = null;
double relDist = Double.POSITIVE_INFINITY;
for (City c : cityManager.getClosestObjects(point.getLatitude(), point.getLongitude())) {
double rel = MapUtils.getDistance(c.getLocation(), point) / c.getType().getRadius();
if (rel < relDist) {
closest = c;
relDist = rel;
if(relDist < 0.2d){
break;
}
}
}
return closest;
}
public DataTileManager<Amenity> getAmenityManager(){
return amenities;
}
public void registerAmenity(Amenity a){
LatLon location = a.getLocation();
if(location != null){
amenities.registerObject(location.getLatitude(), location.getLongitude(), a);
}
}
public void registerCity(City city){
if(city.getType() != null && !Algoritms.isEmpty(city.getName()) && city.getLocation() != null){
LatLon l = city.getLocation();
cityManager.registerObject(l.getLatitude(), l.getLongitude(), city);
cities.get(city.getType()).add(city);
}
}
public void unregisterCity(City city){
if(city != null && city.getType() != null){
LatLon l = city.getLocation();
cityManager.unregisterObject(l.getLatitude(), l.getLongitude(), city);
cities.get(city.getType()).remove(city);
}
}
public City registerCity(Node c){
City city = new City(c);
if(city.getType() != null && !Algoritms.isEmpty(city.getName())){
cityManager.registerObject(c.getLatitude(), c.getLongitude(), city);
cities.get(city.getType()).add(city);
return city;
}
return null;
}
public Map<String, List<TransportRoute>> getTransportRoutes() {
return routes;
}
public void doDataPreparation(){
CityComparator comp = new CityComparator(false);
for(CityType t : cities.keySet()){
Collections.sort(cities.get(t), comp);
for(City c : cities.get(t)){
c.doDataPreparation();
}
}
for(String s : routes.keySet()){
List<TransportRoute> trans = routes.get(s);
Collections.sort(trans, new Comparator<TransportRoute>(){
@Override
public int compare(TransportRoute o1, TransportRoute o2) {
int i1 = Algoritms.extractFirstIntegerNumber(o1.getRef());
int i2 = Algoritms.extractFirstIntegerNumber(o2.getRef());
return i1 - i2;
}
});
}
}
}

View file

@ -1,30 +1,21 @@
package net.osmand.data.index;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.osmand.Algoritms;
import net.osmand.LogUtil;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.Building;
import net.osmand.data.City;
import net.osmand.data.Region;
import net.osmand.data.Street;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.data.City.CityType;
@ -44,75 +35,13 @@ import net.osmand.osm.Node;
import net.osmand.osm.Relation;
import net.osmand.osm.Way;
import org.apache.commons.logging.Log;
public class DataIndexWriter {
private final File workingDir;
private final Region region;
private static final Log log = LogUtil.getLog(DataIndexWriter.class);
private static final int BATCH_SIZE = 1000;
public DataIndexWriter(File workingDir, Region region){
this.workingDir = workingDir;
this.region = region;
}
protected File checkFile(String name) throws IOException {
String fileName = name;
File f = new File(workingDir, fileName);
f.getParentFile().mkdirs();
// remove existing file
if (f.exists()) {
log.warn("Remove existing index : " + f.getAbsolutePath()); //$NON-NLS-1$
f.delete();
}
return f;
}
public DataIndexWriter writePOI() throws IOException, SQLException {
return writePOI(IndexConstants.POI_INDEX_DIR+region.getName()+IndexConstants.POI_INDEX_EXT, null);
}
public DataIndexWriter writePOI(String fileName, Long date) throws IOException, SQLException {
File file = checkFile(fileName);
long now = System.currentTimeMillis();
try {
Class.forName("org.sqlite.JDBC"); //$NON-NLS-1$
} catch (ClassNotFoundException e) {
log.error("Illegal configuration", e); //$NON-NLS-1$
throw new IllegalStateException(e);
}
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+file.getAbsolutePath()); //$NON-NLS-1$
try {
createPoiIndexStructure(conn);
PreparedStatement prep = createStatementAmenityInsert(conn);
Map<PreparedStatement, Integer> map = new LinkedHashMap<PreparedStatement, Integer>();
map.put(prep, 0);
conn.setAutoCommit(false);
for (Amenity a : region.getAmenityManager().getAllObjects()) {
insertAmenityIntoPoi(prep, map, a, BATCH_SIZE);
}
if(map.get(prep) > 0){
prep.executeBatch();
}
prep.close();
conn.setAutoCommit(true);
} finally {
conn.close();
log.info(String.format("Indexing poi done in %s ms.", System.currentTimeMillis() - now)); //$NON-NLS-1$
}
if(date != null){
file.setLastModified(date);
}
return this;
}
public static void insertAmenityIntoPoi(PreparedStatement prep, Map<PreparedStatement, Integer> map, Amenity amenity, int batchSize) throws SQLException {
prep.setLong(IndexPoiTable.ID.ordinal() + 1, amenity.getId());
@ -140,91 +69,6 @@ public class DataIndexWriter {
stat.close();
}
public DataIndexWriter writeAddress() throws IOException, SQLException{
return writeAddress(IndexConstants.ADDRESS_INDEX_DIR+region.getName()+IndexConstants.ADDRESS_INDEX_EXT, null, true);
}
public DataIndexWriter writeAddress(String fileName, Long date, boolean writeWayNodes) throws IOException, SQLException{
File file = checkFile(fileName);
long now = System.currentTimeMillis();
try {
Class.forName("org.sqlite.JDBC"); //$NON-NLS-1$
} catch (ClassNotFoundException e) {
log.error("Illegal configuration", e); //$NON-NLS-1$
throw new IllegalStateException(e);
}
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+file.getAbsolutePath()); //$NON-NLS-1$
try {
createAddressIndexStructure(conn);
PreparedStatement prepCity = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexCityTable.getTable(), IndexCityTable.values().length));
PreparedStatement prepStreet = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexStreetTable.getTable(), IndexStreetTable.values().length));
PreparedStatement prepBuilding = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexBuildingTable.getTable(), IndexBuildingTable.values().length));
PreparedStatement prepStreetNode = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexStreetNodeTable.getTable(), IndexStreetNodeTable.values().length));
Map<PreparedStatement, Integer> count = new HashMap<PreparedStatement, Integer>();
count.put(prepStreet, 0);
count.put(prepCity, 0);
count.put(prepStreetNode, 0);
count.put(prepBuilding, 0);
conn.setAutoCommit(false);
for(CityType t : CityType.values()){
for(City city : region.getCitiesByType(t)) {
if(city.getId() == null || city.getLocation() == null){
continue;
}
writeCity(prepCity, count, city, BATCH_SIZE);
for(Street street : city.getStreets()){
if(street.getId() == null || street.getLocation() == null){
continue;
}
assert IndexStreetTable.values().length == 6;
prepStreet.setLong(IndexStreetTable.ID.ordinal() + 1, street.getId());
prepStreet.setString(IndexStreetTable.NAME_EN.ordinal() + 1, street.getEnName());
prepStreet.setDouble(IndexStreetTable.LATITUDE.ordinal() + 1, street.getLocation().getLatitude());
prepStreet.setDouble(IndexStreetTable.LONGITUDE.ordinal() + 1, street.getLocation().getLongitude());
prepStreet.setString(IndexStreetTable.NAME.ordinal() + 1, street.getName());
prepStreet.setLong(IndexStreetTable.CITY.ordinal() + 1, city.getId());
addBatch(count, prepStreet);
if (writeWayNodes) {
for (Way way : street.getWayNodes()) {
writeStreetWayNodes(prepStreetNode, count, street.getId(), way, BATCH_SIZE);
}
}
for(Building building : street.getBuildings()){
if(building.getId() == null || building.getLocation() == null){
continue;
}
writeBuilding(prepBuilding, count, street.getId(), building, BATCH_SIZE);
}
}
}
}
for(PreparedStatement p : count.keySet()){
if(count.get(p) > 0){
p.executeBatch();
}
p.close();
}
conn.setAutoCommit(true);
} finally {
conn.close();
log.info(String.format("Indexing address done in %s ms.", System.currentTimeMillis() - now)); //$NON-NLS-1$
}
if(date != null){
file.setLastModified(date);
}
return this;
}
public static void writeStreetWayNodes(PreparedStatement prepStreetNode, Map<PreparedStatement, Integer> count, Long streetId, Way way, int batchSize)
throws SQLException {
for (Node n : way.getNodes()) {
@ -283,60 +127,6 @@ public class DataIndexWriter {
}
public DataIndexWriter writeTransport() throws IOException, SQLException{
return writeTransport(IndexConstants.TRANSPORT_INDEX_DIR+region.getName()+IndexConstants.TRANSPORT_INDEX_EXT, null);
}
public DataIndexWriter writeTransport(String fileName, Long date) throws IOException, SQLException{
File file = checkFile(fileName);
long now = System.currentTimeMillis();
try {
Class.forName("org.sqlite.JDBC"); //$NON-NLS-1$
} catch (ClassNotFoundException e) {
log.error("Illegal configuration", e); //$NON-NLS-1$
throw new IllegalStateException(e);
}
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+file.getAbsolutePath()); //$NON-NLS-1$
try {
createTransportIndexStructure(conn);
PreparedStatement prepRoute = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexTransportRoute.getTable(), IndexTransportRoute.values().length));
PreparedStatement prepRouteStops = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexTransportRouteStop.getTable(), IndexTransportRouteStop.values().length));
PreparedStatement prepStops = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexTransportStop.getTable(), IndexTransportStop.values().length));
Map<PreparedStatement, Integer> count = new HashMap<PreparedStatement, Integer>();
count.put(prepRouteStops, 0);
count.put(prepRoute, 0);
count.put(prepStops, 0);
conn.setAutoCommit(false);
Set<Long> writtenStops = new LinkedHashSet<Long>();
for(String t : region.getTransportRoutes().keySet()){
for(TransportRoute r : region.getTransportRoutes().get(t)) {
insertTransportIntoIndex(prepRoute, prepRouteStops, prepStops, writtenStops, r, count, BATCH_SIZE);
}
}
for(PreparedStatement p : count.keySet()){
if(count.get(p) > 0){
p.executeBatch();
}
p.close();
}
conn.setAutoCommit(true);
} finally {
conn.close();
log.info(String.format("Indexing transport done in %s ms.", System.currentTimeMillis() - now)); //$NON-NLS-1$
}
if(date != null){
file.setLastModified(date);
}
return this;
}
private static void writeRouteStops(PreparedStatement prepRouteStops, PreparedStatement prepStops, Map<PreparedStatement, Integer> count,
Set<Long> writtenStops, TransportRoute r, List<TransportStop> stops, boolean direction) throws SQLException {
int i = 0;
@ -395,9 +185,9 @@ public class DataIndexWriter {
Statement stat = conn.createStatement();
stat.execute(IndexConstants.generateCreateSQL(IndexMapRenderObject.values()));
stat.execute(IndexConstants.generateCreateIndexSQL(IndexMapRenderObject.values()));
stat.execute("CREATE VIRTUAL TABLE "+IndexConstants.indexMapLocationsTable+" USING rtree (id, minLon, maxLon, minLat, maxLat);");
stat.execute("CREATE VIRTUAL TABLE "+IndexConstants.indexMapLocationsTable2+" USING rtree (id, minLon, maxLon, minLat, maxLat);");
stat.execute("CREATE VIRTUAL TABLE "+IndexConstants.indexMapLocationsTable3+" USING rtree (id, minLon, maxLon, minLat, maxLat);");
stat.execute("CREATE VIRTUAL TABLE "+IndexConstants.indexMapLocationsTable+" USING rtree (id, minLon, maxLon, minLat, maxLat);"); //$NON-NLS-1$ //$NON-NLS-2$
stat.execute("CREATE VIRTUAL TABLE "+IndexConstants.indexMapLocationsTable2+" USING rtree (id, minLon, maxLon, minLat, maxLat);"); //$NON-NLS-1$ //$NON-NLS-2$
stat.execute("CREATE VIRTUAL TABLE "+IndexConstants.indexMapLocationsTable3+" USING rtree (id, minLon, maxLon, minLat, maxLat);"); //$NON-NLS-1$ //$NON-NLS-2$
stat.execute("PRAGMA user_version = " + IndexConstants.MAP_TABLE_VERSION); //$NON-NLS-1$
stat.close();
}

View file

@ -18,8 +18,6 @@ import java.util.zip.ZipOutputStream;
import net.osmand.Algoritms;
import net.osmand.LogUtil;
import net.osmand.data.Region;
import net.osmand.data.preparation.DataExtraction;
import net.osmand.data.preparation.IndexCreator;
import net.osmand.impl.ConsoleProgressImplementation;
@ -375,7 +373,9 @@ public class IndexBatchCreator {
}
System.out.println("GENERATING INDEXES FINISHED ");
}
protected void generateIndexOld(File f, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles) {
/* protected void generateIndexOld(File f, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles) {
if (!generateIndexes) {
return;
}
@ -410,7 +410,7 @@ public class IndexBatchCreator {
}
System.gc();
}
}*/
protected void generateIndex(File f, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles) {
if (!generateIndexes) {

View file

@ -64,12 +64,16 @@ import org.xml.sax.SAXException;
/**
* http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing#Is_inside.2Foutside
* http://wiki.openstreetmap.org/wiki/Relations/Proposed/Postal_Addresses
* http://wiki.openstreetmap.org/wiki/Proposed_features/House_numbers/Karlsruhe_Schema#Tags (node, way)
* That data extraction has aim,
* save runtime memory and generate indexes on the fly.
* It will be longer than load in memory (needed part) and save into index.
*/
public class IndexCreator {
private static final Log log = LogFactory.getLog(DataExtraction.class);
private static final Log log = LogFactory.getLog(IndexCreator.class);
public static final int BATCH_SIZE = 5000;
@ -937,7 +941,7 @@ public class IndexCreator {
}
}
if(indexMap && (e instanceof Way) || (e instanceof Node)){
if(indexMap && (e instanceof Way || e instanceof Node)){
// manipulate what kind of way to load
loadEntityData(e, true);
boolean inverse = "-1".equals(e.getTag(OSMTagKey.ONEWAY));

View file

@ -5,8 +5,6 @@ import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
@ -16,70 +14,33 @@ import java.io.OutputStream;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
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.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreePath;
import javax.xml.stream.XMLStreamException;
import net.osmand.Algoritms;
import net.osmand.ExceptionHandler;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.Building;
import net.osmand.data.City;
import net.osmand.data.DataTileManager;
import net.osmand.data.MapObject;
import net.osmand.data.Region;
import net.osmand.data.Street;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.data.City.CityType;
import net.osmand.data.index.DataIndexWriter;
import net.osmand.data.preparation.DataExtraction;
import net.osmand.data.preparation.IndexCreator;
import net.osmand.map.IMapLocationListener;
import net.osmand.map.ITileSource;
import net.osmand.osm.Entity;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
import net.osmand.osm.Node;
import net.osmand.osm.Way;
import net.osmand.osm.io.IOsmStorageFilter;
import net.osmand.osm.io.OsmBaseStorage;
import net.osmand.osm.io.OsmBoundsFilter;
import net.osmand.osm.io.OsmStorageWriter;
import net.osmand.swing.MapPanel.MapSelectionArea;
@ -110,98 +71,39 @@ public class OsmExtractionUI implements IMapLocationListener {
}
});
MAIN_APP = new OsmExtractionUI(null);
MAIN_APP = new OsmExtractionUI();
MAIN_APP.frame.setBounds(DataExtractionSettings.getSettings().getWindowBounds());
MAIN_APP.frame.setVisible(true);
}
protected City selectedCity;
private MapPanel mapPanel;
private DataExtractionTreeNode amenitiesTree;
private JTree treePlaces;
private JList searchList;
private JTextField searchTextField;
// private DataExtractionTreeNode amenitiesTree;
// private TreeModelListener treeModelListener;
private MapPanel mapPanel;
private JFrame frame;
private JLabel statusBarLabel;
private Region region;
private JButton generateDataButton;
private JCheckBox buildPoiIndex;
private JCheckBox buildAddressIndex;
private JCheckBox buildMapIndex;
private JCheckBox buildTransportIndex;
private JCheckBox normalizingStreets;
private TreeModelListener treeModelListener;
private JCheckBox loadingAllData;
private String regionName;
public OsmExtractionUI(final Region r){
this.region = r;
public OsmExtractionUI(){
createUI();
setRegion(r, "Region");
}
public void setRegion(Region region, String name){
if (this.region == region) {
return;
}
this.region = region;
DefaultMutableTreeNode root = new DataExtractionTreeNode(name, region);
if (region != null) {
amenitiesTree = new DataExtractionTreeNode("Amenities", region);
amenitiesTree.add(new DataExtractionTreeNode("First 15", region));
for (AmenityType type : AmenityType.values()) {
amenitiesTree.add(new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()), type));
}
root.add(amenitiesTree);
DataExtractionTreeNode transport = new DataExtractionTreeNode("Transport", region);
root.add(transport);
for(String s : region.getTransportRoutes().keySet()){
DataExtractionTreeNode trRoute = new DataExtractionTreeNode(s, s);
transport.add(trRoute);
List<TransportRoute> list = region.getTransportRoutes().get(s);
for(TransportRoute r : list){
DataExtractionTreeNode route = new DataExtractionTreeNode(r.getRef(), r);
trRoute.add(route);
}
}
for (CityType t : CityType.values()) {
DefaultMutableTreeNode cityTree = new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(t.toString()), t);
root.add(cityTree);
for (City ct : region.getCitiesByType(t)) {
DefaultMutableTreeNode cityNodeTree = new DataExtractionTreeNode(ct.getName(), ct);
cityTree.add(cityNodeTree);
for (Street str : ct.getStreets()) {
DefaultMutableTreeNode strTree = new DataExtractionTreeNode(str.getName(), str);
cityNodeTree.add(strTree);
for (Building b : str.getBuildings()) {
DefaultMutableTreeNode building = new DataExtractionTreeNode(b.getName(), b);
strTree.add(building);
}
}
}
}
}
if (searchList != null) {
updateListCities(region, searchTextField.getText(), searchList);
}
mapPanel.repaint();
DefaultTreeModel newModel = new DefaultTreeModel(root, false);
newModel.addTreeModelListener(treeModelListener);
treePlaces.setModel(newModel);
updateButtonsBar();
locationChanged(mapPanel.getLatitude(), mapPanel.getLongitude(), this);
}
@ -228,164 +130,31 @@ public class OsmExtractionUI implements IMapLocationListener {
statusBarLabel.setText(workingDir == null ? "<working directory unspecified>" : "Working directory : " + workingDir.getAbsolutePath());
JSplitPane panelForTreeAndMap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(createTree(content)), mapPanel);
treePlaces = new JTree();
treePlaces.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Region"), false));
JSplitPane panelForTreeAndMap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePlaces), mapPanel);
panelForTreeAndMap.setResizeWeight(0.2);
content.add(panelForTreeAndMap, BorderLayout.CENTER);
createButtonsBar(content);
// createCitySearchPanel(content);
if(searchList != null){
JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(searchList), panelForTreeAndMap);
pane.setResizeWeight(0.2);
content.add(pane, BorderLayout.CENTER);
} else {
content.add(panelForTreeAndMap, BorderLayout.CENTER);
}
JMenuBar bar = new JMenuBar();
fillMenuWithActions(bar);
JPopupMenu popupMenu = new JPopupMenu();
fillPopupMenuWithActions(popupMenu);
treePlaces.add(popupMenu);
treePlaces.addMouseListener(new PopupTrigger(popupMenu));
frame.setJMenuBar(bar);
}
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
public void valueChanged(TreeSelectionEvent e) {
if (e.getPath() != null) {
if (e.getPath().getLastPathComponent() instanceof DataExtractionTreeNode) {
Object o = ((DataExtractionTreeNode) e.getPath().getLastPathComponent()).getModelObject();
if (o instanceof MapObject) {
MapObject c = (MapObject) o;
LatLon location = c.getLocation();
if(location != null){
if(o instanceof Street){
DataTileManager<Way> ways = new DataTileManager<Way>();
for(Way w : ((Street)o).getWayNodes()){
LatLon l = w.getLatLon();
ways.registerObject(l.getLatitude(), l.getLongitude(), w);
}
mapPanel.setPoints(ways);
mapPanel.requestFocus();
}
mapPanel.setLatLon(location.getLatitude(), location.getLongitude());
mapPanel.requestFocus();
}
if(o instanceof TransportRoute){
DataTileManager<Entity> ways = new DataTileManager<Entity>();
for(Way w : ((TransportRoute)o).getWays()){
LatLon l = w.getLatLon();
ways.registerObject(l.getLatitude(), l.getLongitude(), w);
}
for(TransportStop w : ((TransportRoute)o).getBackwardStops()){
LatLon l = w.getLocation();
ways.registerObject(l.getLatitude(), l.getLongitude(),
new Node(l.getLatitude(), l.getLongitude(), w.getId()));
}
for(TransportStop w : ((TransportRoute)o).getForwardStops()){
LatLon l = w.getLocation();
ways.registerObject(l.getLatitude(), l.getLongitude(),
new Node(l.getLatitude(), l.getLongitude(), w.getId()));
}
mapPanel.setPoints(ways);
mapPanel.requestFocus();
}
} else if (o instanceof Entity) {
Entity c = (Entity) o;
LatLon latLon = c.getLatLon();
if (latLon != null) {
mapPanel.setLatLon(latLon.getLatitude(), latLon.getLongitude());
mapPanel.requestFocus();
}
}
}
}
}
});
treeModelListener = new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
Object node = e.getTreePath().getLastPathComponent();
if(e.getChildren() != null && e.getChildren().length > 0){
node =e.getChildren()[0];
}
if (node instanceof DataExtractionTreeNode) {
DataExtractionTreeNode n = ((DataExtractionTreeNode) node);
if (n.getModelObject() instanceof MapObject) {
MapObject r = (MapObject) n.getModelObject();
String newName = n.getUserObject().toString();
if (!r.getName().equals(newName)) {
r.setName(n.getUserObject().toString());
}
if (r instanceof Street && !((Street) r).isRegisteredInCity()) {
DefaultMutableTreeNode parent = ((DefaultMutableTreeNode) n.getParent());
parent.remove(n);
((DefaultTreeModel) treePlaces.getModel()).nodeStructureChanged(parent);
}
}
}
}
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(region != null);
normalizingStreets.setVisible(region == null);
loadingAllData.setVisible(region == null);
if(region == null && !buildAddressIndex.isEnabled()){
buildAddressIndex.setEnabled(true);
}
if(region == null && !buildPoiIndex.isEnabled()){
buildPoiIndex.setEnabled(true);
}
if(region == null && !buildTransportIndex.isEnabled()){
buildTransportIndex.setEnabled(true);
}
}
public void createButtonsBar(Container content){
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
content.add(panel, BorderLayout.NORTH);
generateDataButton = new JButton();
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);
generateDataButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
generateData();
}
});
buildMapIndex = new JCheckBox();
buildMapIndex.setText("Build map index");
panel.add(buildMapIndex);
buildMapIndex.setSelected(true);
buildPoiIndex = new JCheckBox();
buildPoiIndex.setText("Build POI index");
@ -407,136 +176,17 @@ public class OsmExtractionUI implements IMapLocationListener {
panel.add(buildTransportIndex);
buildTransportIndex.setSelected(true);
loadingAllData = new JCheckBox();
loadingAllData.setText("Loading all osm data");
panel.add(loadingAllData);
loadingAllData.setSelected(false);
updateButtonsBar();
}
protected void generateData() {
try {
final ProgressDialog dlg = new ProgressDialog(frame, "Generating data");
dlg.setRunnable(new Runnable(){
@Override
public void run() {
dlg.startTask("Generating indices...", -1);
DataIndexWriter builder = new DataIndexWriter(DataExtractionSettings.getSettings().getDefaultWorkingDir(), region);
StringBuilder msg = new StringBuilder();
try {
msg.append("Indices for ").append(region.getName());
if(buildPoiIndex.isSelected()){
dlg.startTask("Generating POI index...", -1);
builder.writePOI();
msg.append(", POI index ").append("successfully created");
}
if(buildAddressIndex.isSelected()){
dlg.startTask("Generating address index...", -1);
builder.writeAddress();
msg.append(", address index ").append("successfully created");
}
if(buildTransportIndex.isSelected()){
dlg.startTask("Generating transport index...", -1);
builder.writeTransport();
msg.append(", transport index ").append("successfully created");
}
// new DataIndexReader().testIndex(new File(
// DataExtractionSettings.getSettings().getDefaultWorkingDir(),
// IndexConstants.ADDRESS_INDEX_DIR+region.getName()+IndexConstants.ADDRESS_INDEX_EXT));
msg.append(".");
JOptionPane pane = new JOptionPane(msg);
JDialog dialog = pane.createDialog(frame, "Generation data");
dialog.setVisible(true);
} catch (SQLException e1) {
throw new IllegalArgumentException(e1);
} catch (IOException e1) {
throw new IllegalArgumentException(e1);
}
}
});
dlg.run();
} catch (InterruptedException e1) {
log.error("Interrupted", e1);
} catch (InvocationTargetException e1) {
ExceptionHandler.handle((Exception) e1.getCause());
}
}
public void fillPopupMenuWithActions(JPopupMenu menu) {
Action delete = new AbstractAction("Delete") {
private static final long serialVersionUID = 7476603434847164396L;
public void actionPerformed(ActionEvent e) {
TreePath[] p = treePlaces.getSelectionPaths();
if(p != null &&
JOptionPane.OK_OPTION ==
JOptionPane.showConfirmDialog(frame, "Are you sure about deleting " +p.length + " resources ? ")){
for(TreePath path : treePlaces.getSelectionPaths()){
Object node = path.getLastPathComponent();
if (node instanceof DataExtractionTreeNode) {
DataExtractionTreeNode n = ((DataExtractionTreeNode) node);
if(n.getParent() instanceof DataExtractionTreeNode){
DataExtractionTreeNode parent = ((DataExtractionTreeNode) n.getParent());
boolean remove = false;
if (n.getModelObject() instanceof Street) {
((City)parent.getModelObject()).unregisterStreet(((Street)n.getModelObject()).getName());
remove = true;
} else if (n.getModelObject() instanceof Building) {
((Street)parent.getModelObject()).getBuildings().remove(n.getModelObject());
remove = true;
} else if (n.getModelObject() instanceof City) {
Region r = (Region) ((DataExtractionTreeNode)parent.getParent()).getModelObject();
r.unregisterCity((City) n.getModelObject());
remove = true;
} else if (n.getModelObject() instanceof Amenity) {
Region r = (Region) ((DataExtractionTreeNode)parent.getParent().getParent()).getModelObject();
Amenity am = (Amenity) n.getModelObject();
r.getAmenityManager().unregisterObject(am.getLocation().getLatitude(), am.getLocation().getLongitude(), am);
remove = true;
}
if(remove){
parent.remove(n);
((DefaultTreeModel) treePlaces.getModel()).nodeStructureChanged(parent);
}
}
}
}
}
}
};
menu.add(delete);
Action rename= new AbstractAction("Rename") {
private static final long serialVersionUID = -8257594433235073767L;
public void actionPerformed(ActionEvent e) {
TreePath path = treePlaces.getSelectionPath();
if(path != null){
treePlaces.startEditingAtPath(path);
}
}
};
menu.add(rename);
}
public void fillMenuWithActions(final JMenuBar bar){
JMenu menu = new JMenu("File");
bar.add(menu);
JMenuItem loadFile = new JMenuItem("Load osm file...");
JMenuItem loadFile = new JMenuItem("Select osm file...");
menu.add(loadFile);
JMenuItem loadSpecifiedAreaFile = new JMenuItem("Load osm file for specifed area...");
JMenuItem loadSpecifiedAreaFile = new JMenuItem("Select osm file for specifed area...");
menu.add(loadSpecifiedAreaFile);
JMenuItem closeCurrentFile = new JMenuItem("Close current file");
menu.add(closeCurrentFile);
menu.addSeparator();
JMenuItem saveOsmFile = new JMenuItem("Save data to osm file...");
menu.add(saveOsmFile);
JMenuItem specifyWorkingDir = new JMenuItem("Specify working directory...");
menu.add(specifyWorkingDir);
menu.addSeparator();
@ -582,7 +232,7 @@ public class OsmExtractionUI implements IMapLocationListener {
sqliteDB.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
final String regionName = region == null ? "Region" : region.getName();
final String regionName = OsmExtractionUI.this.regionName == null ? "Region" : OsmExtractionUI.this.regionName;
final ITileSource map = mapPanel.getMap();
if(map != null){
try {
@ -619,14 +269,6 @@ public class OsmExtractionUI implements IMapLocationListener {
frame.setVisible(false);
}
});
closeCurrentFile.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
setRegion(null, "Region");
frame.setTitle("OsmAnd Map Creator");
}
});
settings.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
@ -655,7 +297,6 @@ public class OsmExtractionUI implements IMapLocationListener {
tileSource.add(sqliteDB);
bar.remove(1);
bar.add(tileSource, 1);
updateButtonsBar();
}
}
@ -714,21 +355,7 @@ public class OsmExtractionUI implements IMapLocationListener {
}
});
saveOsmFile.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(region == null){
return;
}
JFileChooser fc = getOsmFileChooser();
int answer = fc.showSaveDialog(frame);
if (answer == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null){
saveCountry(fc.getSelectedFile());
}
}
});
}
public JFileChooser getOsmFileChooser(){
@ -763,22 +390,14 @@ public class OsmExtractionUI implements IMapLocationListener {
@Override
public void run() {
Region res;
IndexCreator creator = new IndexCreator(DataExtractionSettings.getSettings().getDefaultWorkingDir());
try {
DataExtraction dataExtraction = new DataExtraction(buildAddressIndex.isSelected(), buildPoiIndex.isSelected(),
buildTransportIndex.isSelected(), normalizingStreets.isSelected(), loadingAllData.isSelected(),
DataExtractionSettings.getSettings().getLoadEntityInfo(),
DataExtractionSettings.getSettings().getDefaultWorkingDir());
if(!buildAddressIndex.isSelected()){
buildAddressIndex.setEnabled(false);
}
if(!buildTransportIndex.isSelected()){
buildTransportIndex.setEnabled(false);
}
if(!buildPoiIndex.isSelected()){
buildPoiIndex.setEnabled(false);
}
res = dataExtraction.readCountry(f.getAbsolutePath(), dlg, filter);
creator.setIndexAddress(buildAddressIndex.isSelected());
creator.setIndexPOI(buildPoiIndex.isSelected());
creator.setNormalizeStreets(normalizingStreets.isSelected());
creator.setIndexTransport(buildTransportIndex.isSelected());
creator.setIndexMap(buildMapIndex.isSelected());
creator.generateIndexes(f, dlg, filter);
} catch (IOException e) {
throw new IllegalArgumentException(e);
} catch (SAXException e) {
@ -786,25 +405,47 @@ public class OsmExtractionUI implements IMapLocationListener {
} catch (SQLException e) {
throw new IllegalStateException(e);
}
dlg.setResult(res);
regionName = creator.getRegionName();
StringBuilder msg = new StringBuilder();
msg.append("Indexes for ").append(regionName).append(" : ");
boolean comma = false;
if (buildMapIndex.isSelected()) {
if(comma) msg.append(", ");
comma = true;
msg.append("map");
}
if (buildPoiIndex.isSelected()) {
if(comma) msg.append(", ");
comma = true;
msg.append("POI");
}
if (buildAddressIndex.isSelected()) {
if(comma) msg.append(", ");
comma = true;
msg.append("address");
}
if (buildTransportIndex.isSelected()) {
if(comma) msg.append(", ");
comma = true;
msg.append("transport");
}
msg.append(" - successfully created in working directory.");
JOptionPane pane = new JOptionPane(msg);
JDialog dialog = pane.createDialog(frame, "Generation data");
dialog.setVisible(true);
}
});
Region region = (Region) dlg.run();
if(region != null){
setRegion(region, region.getName());
frame.setTitle("OsmAnd Map Creator - " + f.getName());
} else {
//frame.setTitle("OsmAnd Map Creator");
}
dlg.run();
frame.setTitle("OsmAnd Map Creator - " + f.getName());
} catch (InterruptedException e1) {
log.error("Interrupted", e1);
updateButtonsBar();
} catch (InvocationTargetException e1) {
ExceptionHandler.handle("Exception during operation", e1.getCause());
}
}
public void saveCountry(final File f){
public void saveCountry(final File f, final OsmBaseStorage storage){
final OsmStorageWriter writer = new OsmStorageWriter();
try {
final ProgressDialog dlg = new ProgressDialog(frame, "Saving osm file");
@ -819,7 +460,7 @@ public class OsmExtractionUI implements IMapLocationListener {
output.write('Z');
output = new CBZip2OutputStream(output);
}
writer.saveStorage(output, region.getStorage(), null, false);
writer.saveStorage(output, storage, null, false);
} finally {
output.close();
}
@ -840,6 +481,258 @@ public class OsmExtractionUI implements IMapLocationListener {
@Override
public void locationChanged(final double newLatitude, final double newLongitude, Object source){
// recalculateAmenities(newLatitude, newLongitude);
}
public class ExitListener extends WindowAdapter {
public void windowClosing(WindowEvent event) {
// save preferences
DataExtractionSettings settings = DataExtractionSettings.getSettings();
settings.saveDefaultLocation(mapPanel.getLatitude(), mapPanel.getLongitude());
settings.saveDefaultZoom(mapPanel.getZoom());
settings.saveWindowBounds(frame.getBounds());
System.exit(0);
}
}
// OLD CODE
/*
public JTree createTree(Container content) {
treePlaces.setEditable(true);
treePlaces.setCellEditor(new RegionCellEditor(treePlaces, (DefaultTreeCellRenderer) treePlaces.getCellRenderer()));
treePlaces.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getPath() != null) {
if (e.getPath().getLastPathComponent() instanceof DataExtractionTreeNode) {
Object o = ((DataExtractionTreeNode) e.getPath().getLastPathComponent()).getModelObject();
if (o instanceof MapObject) {
MapObject c = (MapObject) o;
LatLon location = c.getLocation();
if (location != null) {
if (o instanceof Street) {
DataTileManager<Way> ways = new DataTileManager<Way>();
for (Way w : ((Street) o).getWayNodes()) {
LatLon l = w.getLatLon();
ways.registerObject(l.getLatitude(), l.getLongitude(), w);
}
mapPanel.setPoints(ways);
mapPanel.requestFocus();
}
mapPanel.setLatLon(location.getLatitude(), location.getLongitude());
mapPanel.requestFocus();
}
if (o instanceof TransportRoute) {
DataTileManager<Entity> ways = new DataTileManager<Entity>();
for (Way w : ((TransportRoute) o).getWays()) {
LatLon l = w.getLatLon();
ways.registerObject(l.getLatitude(), l.getLongitude(), w);
}
for (TransportStop w : ((TransportRoute) o).getBackwardStops()) {
LatLon l = w.getLocation();
ways.registerObject(l.getLatitude(), l.getLongitude(), new Node(l.getLatitude(), l.getLongitude(), w
.getId()));
}
for (TransportStop w : ((TransportRoute) o).getForwardStops()) {
LatLon l = w.getLocation();
ways.registerObject(l.getLatitude(), l.getLongitude(), new Node(l.getLatitude(), l.getLongitude(), w
.getId()));
}
mapPanel.setPoints(ways);
mapPanel.requestFocus();
}
} else if (o instanceof Entity) {
Entity c = (Entity) o;
LatLon latLon = c.getLatLon();
if (latLon != null) {
mapPanel.setLatLon(latLon.getLatitude(), latLon.getLongitude());
mapPanel.requestFocus();
}
}
}
}
}
});
treeModelListener = new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
Object node = e.getTreePath().getLastPathComponent();
if (e.getChildren() != null && e.getChildren().length > 0) {
node = e.getChildren()[0];
}
if (node instanceof DataExtractionTreeNode) {
DataExtractionTreeNode n = ((DataExtractionTreeNode) node);
if (n.getModelObject() instanceof MapObject) {
MapObject r = (MapObject) n.getModelObject();
String newName = n.getUserObject().toString();
if (!r.getName().equals(newName)) {
r.setName(n.getUserObject().toString());
}
if (r instanceof Street && !((Street) r).isRegisteredInCity()) {
DefaultMutableTreeNode parent = ((DefaultMutableTreeNode) n.getParent());
parent.remove(n);
((DefaultTreeModel) treePlaces.getModel()).nodeStructureChanged(parent);
}
}
}
}
public void treeNodesInserted(TreeModelEvent e) {
}
public void treeNodesRemoved(TreeModelEvent e) {
}
public void treeStructureChanged(TreeModelEvent e) {
}
};
treePlaces.getModel().addTreeModelListener(treeModelListener);
return treePlaces;
}
public void fillPopupMenuWithActions(JPopupMenu menu) {
Action delete = new AbstractAction("Delete") {
private static final long serialVersionUID = 7476603434847164396L;
public void actionPerformed(ActionEvent e) {
TreePath[] p = treePlaces.getSelectionPaths();
if(p != null &&
JOptionPane.OK_OPTION ==
JOptionPane.showConfirmDialog(frame, "Are you sure about deleting " +p.length + " resources ? ")){
for(TreePath path : treePlaces.getSelectionPaths()){
Object node = path.getLastPathComponent();
if (node instanceof DataExtractionTreeNode) {
DataExtractionTreeNode n = ((DataExtractionTreeNode) node);
if(n.getParent() instanceof DataExtractionTreeNode){
DataExtractionTreeNode parent = ((DataExtractionTreeNode) n.getParent());
boolean remove = false;
if (n.getModelObject() instanceof Street) {
((City)parent.getModelObject()).unregisterStreet(((Street)n.getModelObject()).getName());
remove = true;
} else if (n.getModelObject() instanceof Building) {
((Street)parent.getModelObject()).getBuildings().remove(n.getModelObject());
remove = true;
} else if (n.getModelObject() instanceof City) {
Region r = (Region) ((DataExtractionTreeNode)parent.getParent()).getModelObject();
r.unregisterCity((City) n.getModelObject());
remove = true;
} else if (n.getModelObject() instanceof Amenity) {
Region r = (Region) ((DataExtractionTreeNode)parent.getParent().getParent()).getModelObject();
Amenity am = (Amenity) n.getModelObject();
r.getAmenityManager().unregisterObject(am.getLocation().getLatitude(), am.getLocation().getLongitude(), am);
remove = true;
}
if(remove){
parent.remove(n);
((DefaultTreeModel) treePlaces.getModel()).nodeStructureChanged(parent);
}
}
}
}
}
}
};
menu.add(delete);
Action rename= new AbstractAction("Rename") {
private static final long serialVersionUID = -8257594433235073767L;
public void actionPerformed(ActionEvent e) {
TreePath path = treePlaces.getSelectionPath();
if(path != null){
treePlaces.startEditingAtPath(path);
}
}
};
menu.add(rename);
}
public void setRegion(Region region, String name){
if (this.region == region) {
return;
}
this.region = region;
DefaultMutableTreeNode root = new DataExtractionTreeNode(name, region);
if (region != null) {
amenitiesTree = new DataExtractionTreeNode("Amenities", region);
amenitiesTree.add(new DataExtractionTreeNode("First 15", region));
for (AmenityType type : AmenityType.values()) {
amenitiesTree.add(new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()), type));
}
root.add(amenitiesTree);
DataExtractionTreeNode transport = new DataExtractionTreeNode("Transport", region);
root.add(transport);
for(String s : region.getTransportRoutes().keySet()){
DataExtractionTreeNode trRoute = new DataExtractionTreeNode(s, s);
transport.add(trRoute);
List<TransportRoute> list = region.getTransportRoutes().get(s);
for(TransportRoute r : list){
DataExtractionTreeNode route = new DataExtractionTreeNode(r.getRef(), r);
trRoute.add(route);
}
}
for (CityType t : CityType.values()) {
DefaultMutableTreeNode cityTree = new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(t.toString()), t);
root.add(cityTree);
for (City ct : region.getCitiesByType(t)) {
DefaultMutableTreeNode cityNodeTree = new DataExtractionTreeNode(ct.getName(), ct);
cityTree.add(cityNodeTree);
for (Street str : ct.getStreets()) {
DefaultMutableTreeNode strTree = new DataExtractionTreeNode(str.getName(), str);
cityNodeTree.add(strTree);
for (Building b : str.getBuildings()) {
DefaultMutableTreeNode building = new DataExtractionTreeNode(b.getName(), b);
strTree.add(building);
}
}
}
}
}
if (searchList != null) {
updateListCities(region, searchTextField.getText(), searchList);
}
mapPanel.repaint();
DefaultTreeModel newModel = new DefaultTreeModel(root, false);
newModel.addTreeModelListener(treeModelListener);
treePlaces.setModel(newModel);
updateButtonsBar();
locationChanged(mapPanel.getLatitude(), mapPanel.getLongitude(), this);
}
public static class DataExtractionTreeNode extends DefaultMutableTreeNode {
private static final long serialVersionUID = 1L;
private final Object modelObject;
public DataExtractionTreeNode(String name, Object modelObject){
super(name);
this.modelObject = modelObject;
}
public Object getModelObject(){
return modelObject;
}
}
private void recalculateAmenities(final double newLatitude, final double newLongitude) {
if (amenitiesTree != null) {
Region reg = (Region) amenitiesTree.getModelObject();
List<Amenity> closestAmenities = reg.getAmenityManager().getClosestObjects(newLatitude, newLongitude, 0, 5);
@ -878,8 +771,6 @@ public class OsmExtractionUI implements IMapLocationListener {
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).add(new DataExtractionTreeNode(str, n));
((DefaultTreeModel)treePlaces.getModel()).nodeStructureChanged(amenitiesTree.getChildAt(0));
}
}
}
@ -897,23 +788,7 @@ public class OsmExtractionUI implements IMapLocationListener {
}
jList.setListData(names);
}
public static class DataExtractionTreeNode extends DefaultMutableTreeNode {
private static final long serialVersionUID = 1L;
private final Object modelObject;
public DataExtractionTreeNode(String name, Object modelObject){
super(name);
this.modelObject = modelObject;
}
public Object getModelObject(){
return modelObject;
}
}
public static class RegionCellEditor extends DefaultTreeCellEditor {
public RegionCellEditor(JTree tree, DefaultTreeCellRenderer renderer) {
@ -939,17 +814,6 @@ public class OsmExtractionUI implements IMapLocationListener {
}
}
public class ExitListener extends WindowAdapter {
public void windowClosing(WindowEvent event) {
// save preferences
DataExtractionSettings settings = DataExtractionSettings.getSettings();
settings.saveDefaultLocation(mapPanel.getLatitude(), mapPanel.getLongitude());
settings.saveDefaultZoom(mapPanel.getZoom());
settings.saveWindowBounds(frame.getBounds());
System.exit(0);
}
}
private class PopupTrigger extends MouseAdapter {
private final JPopupMenu popupMenu;
@ -973,6 +837,7 @@ public class OsmExtractionUI implements IMapLocationListener {
}
}
}
*/
}

View file

@ -17,9 +17,9 @@ import java.util.TreeSet;
import net.osmand.data.Building;
import net.osmand.data.City;
import net.osmand.data.CityComparator;
import net.osmand.data.MapObject;
import net.osmand.data.PostCode;
import net.osmand.data.Region;
import net.osmand.data.Street;
import net.osmand.data.City.CityType;
import net.osmand.data.index.IndexConstants;
@ -183,7 +183,7 @@ public class RegionAddressRepository {
}
// sort cities
ArrayList<City> list = new ArrayList<City>(cities.values());
Collections.sort(list, new Region.CityComparator(useEnglishNames));
Collections.sort(list, new CityComparator(useEnglishNames));
cities.clear();
cityTypes.clear();
for(City c : list){