From 5322550b13000b7c6f6b1e008e89431c78f14dfa Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 14 May 2010 11:44:35 +0000 Subject: [PATCH] refactor swing version git-svn-id: https://osmand.googlecode.com/svn/trunk@56 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ExceptionHandler.java | 18 ++ .../src/com/osmand/data/City.java | 12 +- .../src/com/osmand/data/DataTileManager.java | 4 + .../src/com/osmand/data/Region.java | 43 +++- .../src/com/osmand/data/Street.java | 10 +- .../preparation}/DataExtraction.java | 26 +- .../data/preparation/DataIndexBuilder.java | 75 ++++++ .../preparation}/MapTileDownloader.java | 6 +- .../src/com/osmand/map/TileSourceManager.java | 29 +++ .../src/com/osmand/swing/MapPanel.java | 34 ++- .../src/com/osmand/swing/OsmExtractionUI.java | 223 +++++++++++++----- OsmAnd/.classpath | 2 +- OsmAnd/src/com/osmand/ResourceManager.java | 3 +- .../com/osmand/views/OsmandMapTileView.java | 6 +- 14 files changed, 406 insertions(+), 85 deletions(-) create mode 100644 DataExtractionOSM/src/com/osmand/ExceptionHandler.java rename DataExtractionOSM/src/com/osmand/{ => data/preparation}/DataExtraction.java (89%) create mode 100644 DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java rename DataExtractionOSM/src/com/osmand/{ => data/preparation}/MapTileDownloader.java (94%) diff --git a/DataExtractionOSM/src/com/osmand/ExceptionHandler.java b/DataExtractionOSM/src/com/osmand/ExceptionHandler.java new file mode 100644 index 0000000000..fea87f65a6 --- /dev/null +++ b/DataExtractionOSM/src/com/osmand/ExceptionHandler.java @@ -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); + } + +} diff --git a/DataExtractionOSM/src/com/osmand/data/City.java b/DataExtractionOSM/src/com/osmand/data/City.java index 44ff34f657..87bfbaf6de 100644 --- a/DataExtractionOSM/src/com/osmand/data/City.java +++ b/DataExtractionOSM/src/com/osmand/data/City.java @@ -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){ String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER); String street = e.getTag(OSMTagKey.ADDR_STREET); if( street != null && number != null){ - if(!streets.containsKey(street)){ - streets.put(street, new Street(street)); - } - streets.get(street).registerBuilding(point, e); + registerStreet(street).registerBuilding(point, e); return streets.get(street); } return null; diff --git a/DataExtractionOSM/src/com/osmand/data/DataTileManager.java b/DataExtractionOSM/src/com/osmand/data/DataTileManager.java index b0c6c1d1f3..718c60c464 100644 --- a/DataExtractionOSM/src/com/osmand/data/DataTileManager.java +++ b/DataExtractionOSM/src/com/osmand/data/DataTileManager.java @@ -119,6 +119,10 @@ public class DataTileManager { return tile; } + public boolean isEmpty(){ + return objects.isEmpty(); + } + } diff --git a/DataExtractionOSM/src/com/osmand/data/Region.java b/DataExtractionOSM/src/com/osmand/data/Region.java index 627aadca3b..6709b90ef8 100644 --- a/DataExtractionOSM/src/com/osmand/data/Region.java +++ b/DataExtractionOSM/src/com/osmand/data/Region.java @@ -2,6 +2,8 @@ package com.osmand.data; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,9 +22,18 @@ public class Region { private DataTileManager amenities = new DataTileManager(); + private String name; + private OsmBaseStorage storage; - private Map> cities = new HashMap>(); + private static class CityComparator implements Comparator{ + @Override + public int compare(City o1, City o2) { + return o1.getName().compareTo(o2.getName()); + } + } + + private Map> cities = new HashMap>(); { for(CityType type : CityType.values()){ cities.put(type, new ArrayList()); @@ -48,13 +59,35 @@ public class Region { } public String getName(){ + if(name != null){ + return name; + } return entity == null ? "" : entity.getTag(OSMTagKey.NAME); } + public void setName(String name) { + this.name = name; + } + public Collection 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 getCitiesByName(String name){ 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); + } + + } } diff --git a/DataExtractionOSM/src/com/osmand/data/Street.java b/DataExtractionOSM/src/com/osmand/data/Street.java index 637c6bc264..49dd13606a 100644 --- a/DataExtractionOSM/src/com/osmand/data/Street.java +++ b/DataExtractionOSM/src/com/osmand/data/Street.java @@ -1,16 +1,20 @@ package com.osmand.data; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import com.osmand.osm.Entity; import com.osmand.osm.LatLon; +import com.osmand.osm.Node; public class Street { private final String name; - private Map buildings = new HashMap(); + private Map buildings = new HashMap(); + private List wayNodes = new ArrayList(); public Street(String name){ this.name = name; @@ -31,5 +35,9 @@ public class Street { public String getName() { return name; } + + public List getWayNodes() { + return wayNodes; + } } diff --git a/DataExtractionOSM/src/com/osmand/DataExtraction.java b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java similarity index 89% rename from DataExtractionOSM/src/com/osmand/DataExtraction.java rename to DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java index 5430ac3af6..e5681b70cd 100644 --- a/DataExtractionOSM/src/com/osmand/DataExtraction.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java @@ -1,4 +1,4 @@ -package com.osmand; +package com.osmand.data.preparation; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -17,10 +17,13 @@ import org.apache.tools.bzip2.CBZip2InputStream; import org.apache.tools.bzip2.CBZip2OutputStream; import org.xml.sax.SAXException; +import com.osmand.DefaultLauncherConstants; +import com.osmand.IProgress; import com.osmand.data.Amenity; import com.osmand.data.City; import com.osmand.data.DataTileManager; import com.osmand.data.Region; +import com.osmand.data.Street; import com.osmand.impl.ConsoleProgressImplementation; import com.osmand.osm.Entity; import com.osmand.osm.LatLon; @@ -79,7 +82,7 @@ public class DataExtraction { private static boolean parseSmallFile = true; private static boolean parseOSM = true; - private ArrayList mapWays; + private ArrayList ways; private ArrayList amenities; private ArrayList buildings; private ArrayList places; @@ -153,7 +156,7 @@ public class DataExtraction { buildings = new ArrayList(); amenities = new ArrayList(); // highways count - mapWays = new ArrayList(); + ways = new ArrayList(); OsmBaseStorage storage = new OsmBaseStorage(){ @Override @@ -187,7 +190,7 @@ public class DataExtraction { @Override public boolean acceptWayToLoad(Way w) { if (OSMSettings.wayForCar(w.getTag(OSMTagKey.HIGHWAY))) { - mapWays.add(w); + ways.add(w); return true; } return false; @@ -239,14 +242,23 @@ public class DataExtraction { waysManager = new DataTileManager(); - for (Way w : mapWays) { + for (Way w : ways) { if (w.getTag(OSMTagKey.NAME) != null) { - LatLon latLon = MapUtils.getWeightCenterForNodes(w.getNodes()); - waysManager.registerObject(latLon.getLatitude(), latLon.getLongitude(), w); + String street = w.getTag(OSMTagKey.NAME); + 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 : МЗОР, ул. ..., + country.doDataPreparation(); return country; } diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java b/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java new file mode 100644 index 0000000000..80e1e0a29d --- /dev/null +++ b/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java @@ -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 list = region.getAmenityManager().getAllObjects(); + List interestedObjects = new ArrayList(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; + } +} diff --git a/DataExtractionOSM/src/com/osmand/MapTileDownloader.java b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java similarity index 94% rename from DataExtractionOSM/src/com/osmand/MapTileDownloader.java rename to DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java index d056073338..eaa05864c3 100644 --- a/DataExtractionOSM/src/com/osmand/MapTileDownloader.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java @@ -1,4 +1,4 @@ -package com.osmand; +package com.osmand.data.preparation; import java.io.BufferedInputStream; import java.io.File; @@ -16,6 +16,10 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; +import com.osmand.Algoritms; +import com.osmand.DefaultLauncherConstants; +import com.osmand.LogUtil; + public class MapTileDownloader { private static MapTileDownloader downloader = null; diff --git a/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java b/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java index 5aea748f7c..c767a9f92e 100644 --- a/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java +++ b/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java @@ -58,6 +58,35 @@ public class TileSourceManager { public String getUrlToLoad(int x, int y, int zoom) { 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; + } + + } diff --git a/DataExtractionOSM/src/com/osmand/swing/MapPanel.java b/DataExtractionOSM/src/com/osmand/swing/MapPanel.java index b9dbab174c..31ce552acc 100644 --- a/DataExtractionOSM/src/com/osmand/swing/MapPanel.java +++ b/DataExtractionOSM/src/com/osmand/swing/MapPanel.java @@ -5,9 +5,6 @@ import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.Image; -import java.awt.Menu; -import java.awt.MenuBar; -import java.awt.MenuItem; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -30,7 +27,10 @@ import java.util.Map; import javax.imageio.IIOException; import javax.imageio.ImageIO; import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.UIManager; @@ -39,10 +39,10 @@ import org.apache.commons.logging.Log; import com.osmand.DefaultLauncherConstants; import com.osmand.IMapLocationListener; 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.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.TileSourceManager; 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); - public static Menu getMenuToChooseSource(final MapPanel panel){ - Menu tiles = new Menu("Source tile"); - List list = TileSourceManager.getKnownSourceTemplates(); + public static JMenu getMenuToChooseSource(final MapPanel panel){ + final JMenu tiles = new JMenu("Source tile"); + final List list = TileSourceManager.getKnownSourceTemplates(); for(final TileSourceTemplate l : list){ - MenuItem menuItem = new MenuItem(l.getName()); + JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(l.getName()); menuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { + for(int i=0; i" : "Working directory : " + workingDir.getAbsolutePath()); + + - 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); mapPanel.setFocusable(true); mapPanel.addMapLocationListener(this); @@ -180,36 +200,50 @@ public class OsmExtractionUI implements IMapLocationListener { } else { content.add(panelForTreeAndMap, BorderLayout.CENTER); } + + JMenuBar bar = new JMenuBar(); + fillMenuWithActions(bar); - - treePlaces.addTreeSelectionListener(new TreeSelectionListener(){ + 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 DefaultMutableTreeNode) { - Object o = ((DefaultMutableTreeNode) e.getPath().getLastPathComponent()).getUserObject(); + if (e.getPath().getLastPathComponent() instanceof DataExtractionTreeNode) { + Object o = ((DataExtractionTreeNode) e.getPath().getLastPathComponent()).getModelObject(); if (o instanceof City) { City c = (City) o; mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude()); mapPanel.requestFocus(); - } - if (o instanceof Amenity) { + } else if (o instanceof Street) { + 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; mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude()); mapPanel.requestFocus(); - } - - if (o instanceof Entity) { + } else if (o instanceof Entity) { Entity c = (Entity) o; if (c instanceof Node) { mapPanel.setLatLon(((Node) c).getLatitude(), ((Node) c).getLongitude()); mapPanel.requestFocus(); } else { - DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.getPath().getPathComponent( + DataExtractionTreeNode n = (DataExtractionTreeNode) e.getPath().getPathComponent( e.getPath().getPathCount() - 2); - if (n.getUserObject() instanceof Street) { - Street str = (Street) n.getUserObject(); + if (n.getModelObject() instanceof Street) { + Street str = (Street) n.getModelObject(); LatLon l = str.getLocationBuilding(c); mapPanel.setLatLon(l.getLatitude(), l.getLongitude()); 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){ - JPanel panel = new JPanel(new BorderLayout()); + 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.setEnabled(workingDir != null); - workingDirLabel = new JLabel(); - workingDirLabel.setText(workingDir == null ? "" : workingDir.getAbsolutePath()); - panel.add(workingDirLabel); + generateDataButton.addActionListener(new ActionListener(){ + + @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){ @@ -292,14 +387,12 @@ public class OsmExtractionUI implements IMapLocationListener { if(selectedCity != null){ text += " distance " + MapUtils.getDistance(selectedCity.getNode(), node); } - statusBarLabel.setText(text); mapPanel.setLatLon(node.getLatitude(), node.getLongitude()); - } else { - String text = selectedCity == null ? "" : selectedCity.getName(); - statusBarLabel.setText(text); } } }); + + } public void runUI(){ @@ -307,15 +400,15 @@ public class OsmExtractionUI implements IMapLocationListener { frame.setVisible(true); } - public void fillMenuWithActions(MenuBar bar){ - Menu menu = new Menu("File"); + public void fillMenuWithActions(JMenuBar bar){ + JMenu menu = new JMenu("File"); bar.add(menu); - MenuItem loadFile = new MenuItem("Load osm file..."); + JMenuItem loadFile = new JMenuItem("Load osm file..."); menu.add(loadFile); - MenuItem specifyWorkingDir = new MenuItem("Specify working directory..."); + JMenuItem specifyWorkingDir = new JMenuItem("Specify working directory..."); menu.add(specifyWorkingDir); menu.addSeparator(); - MenuItem exitMenu= new MenuItem("Exit"); + JMenuItem exitMenu= new JMenuItem("Exit"); menu.add(exitMenu); bar.add(MapPanel.getMenuToChooseSource(mapPanel)); @@ -326,7 +419,6 @@ public class OsmExtractionUI implements IMapLocationListener { frame.setVisible(false); } }); - specifyWorkingDir.addActionListener(new ActionListener(){ @Override @@ -340,8 +432,8 @@ public class OsmExtractionUI implements IMapLocationListener { if(fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null && fc.getSelectedFile().isDirectory()){ workingDir = fc.getSelectedFile(); - workingDirLabel.setText(fc.getSelectedFile().getAbsolutePath()); - generateDataButton.setEnabled(true); + statusBarLabel.setText("Working directory : " + fc.getSelectedFile().getAbsolutePath()); + updateButtonsBar(); } } @@ -400,7 +492,10 @@ public class OsmExtractionUI implements IMapLocationListener { Region region = (Region) dlg.run(); if(region != null){ 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()); } else { //frame.setTitle("OsmAnd Map Creator"); @@ -415,7 +510,7 @@ public class OsmExtractionUI implements IMapLocationListener { @Override public void locationChanged(final double newLatitude, final double newLongitude, Object source){ if (amenitiesTree != null) { - Region reg = (Region) amenitiesTree.getUserObject(); + Region reg = (Region) amenitiesTree.getModelObject(); List closestAmenities = reg.getClosestAmenities(newLatitude, newLongitude); Collections.sort(closestAmenities, new Comparator() { @Override @@ -436,7 +531,7 @@ public class OsmExtractionUI implements IMapLocationListener { 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(); if (filter.get(type) != null) { for (Amenity n : filter.get(type)) { @@ -480,19 +575,41 @@ public class OsmExtractionUI implements IMapLocationListener { public static class DataExtractionTreeNode extends DefaultMutableTreeNode { private static final long serialVersionUID = 1L; - private String name; + private final Object modelObject; - public DataExtractionTreeNode(String name, Object userObject){ - super(userObject); - this.name = name; + public DataExtractionTreeNode(String name, Object modelObject){ + super(name); + this.modelObject = modelObject; } - public void setName(String name) { - this.name = name; + public Object getModelObject(){ + 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; } } diff --git a/OsmAnd/.classpath b/OsmAnd/.classpath index 82f47e085f..88a4835117 100644 --- a/OsmAnd/.classpath +++ b/OsmAnd/.classpath @@ -1,7 +1,7 @@ - + diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 69712c31f8..7b4d0adcf2 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -18,9 +18,10 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Environment; -import com.osmand.MapTileDownloader.DownloadRequest; import com.osmand.data.Amenity; 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.osm.Entity; import com.osmand.osm.Node; diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index 5b5b79eccd..53e4f2de5f 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -23,11 +23,11 @@ import android.view.SurfaceHolder.Callback; import com.osmand.DefaultLauncherConstants; import com.osmand.IMapLocationListener; import com.osmand.LogUtil; -import com.osmand.MapTileDownloader; import com.osmand.OsmandSettings; import com.osmand.ResourceManager; -import com.osmand.MapTileDownloader.DownloadRequest; -import com.osmand.MapTileDownloader.IMapDownloaderCallback; +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.osm.MapUtils; import com.osmand.views.AnimateDraggingMapThread.AnimateDraggingCallback;