implement swing version

git-svn-id: https://osmand.googlecode.com/svn/trunk@51 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-13 18:02:30 +00:00
parent 0a146f6088
commit 690d60a782
8 changed files with 161 additions and 115 deletions

View file

@ -20,6 +20,16 @@ public class Algoritms {
} }
public static String capitalizeFirstLetterAndLowercase(String s) {
if (s != null && s.length() > 1) {
// not very efficient algorithm
return Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase();
} else {
return s;
}
}
public static boolean objectEquals(Object a, Object b){ public static boolean objectEquals(Object a, Object b){
if(a == null){ if(a == null){
return b == null; return b == null;

View file

@ -161,7 +161,7 @@ public class MapTileDownloader {
} }
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
currentErrors++; currentErrors++;
log.error("UnknownHostException, cannot download tile " + request.url, e); log.error("UnknownHostException, cannot download tile " + request.url + " " + e.getMessage());
} catch (IOException e) { } catch (IOException e) {
currentErrors++; currentErrors++;
log.warn("Cannot download tile : " + request.url, e); log.warn("Cannot download tile : " + request.url, e);

View file

@ -27,12 +27,14 @@ public class ToDoConstants {
//// TODO for releasing version //// TODO for releasing version
// 1. POI SEARCH NEAR TO YOU // 1. POI SEARCH NEAR TO YOU
// 2. FIX BACK TO your location & gps & point of view (may be compass) // 2. FIX BACK TO your location & gps & point of view (may be compass)
// 3. Save settings between session // 3. Revise UI icons/layout
// 4. Revise UI icons/layout // 4. Fix Java Spring to prepare your data!!! (add progress, import/export data)
// 5. Fix Java Spring to prepare your data!!! (add progress, import/export data) // 5. Enable city/streets/buildings index
// 6. Enable city/streets/buildings index
// 7. Search for city/streets/buildings! // 7. Search for city/streets/buildings!
// 8. Enable change POI directly on map // 8. Enable change POI directly on map
// 9. Log to see when exception occured(android)
// 10. Specify auto-rotating map (compass).
// 11. Print out additional info speed, altitude, number of satellites
// ------------------- // -------------------
@ -40,7 +42,7 @@ public class ToDoConstants {
// TODO : // TODO :
// 1. save preferences ? where? // 1. save preferences ? where?
// 2. specify area to download tiles () // 2. specify area to download tiles ()
// 3. implement mouse wheel to zoom (add zoom buttons) // 3. download tiles without using dir tiles
// 4. download tiles without using dir tiles // 4. Config file log & see log from file
} }

View file

@ -3,6 +3,7 @@ package com.osmand.data;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import com.osmand.Algoritms;
import com.osmand.osm.Node; import com.osmand.osm.Node;
import com.osmand.osm.OSMSettings.OSMTagKey; import com.osmand.osm.OSMSettings.OSMTagKey;
@ -127,7 +128,8 @@ public class Amenity {
public String getSimpleFormat(){ public String getSimpleFormat(){
String name = node.getTag(OSMTagKey.NAME); String name = node.getTag(OSMTagKey.NAME);
return getType().toString() +" : " + getSubType() + " " +(name == null ? node.getId() : name); return Algoritms.capitalizeFirstLetterAndLowercase(getType().toString()) +
" : " + getSubType() + " " +(name == null ? node.getId() : name);
} }
public String getStringWithoutType(){ public String getStringWithoutType(){

View file

@ -251,7 +251,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
try { try {
cache.put(file, ImageIO.read(en)); cache.put(file, ImageIO.read(en));
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Loaded file : " + file + " " + -(time - System.currentTimeMillis()) + " ms"); log.debug("Loaded file : " + file + " " + (System.currentTimeMillis() - time) + " ms");
} }
} catch (IIOException e) { } catch (IIOException e) {
log.error("Eror reading png " + x + " " + y + " zoom : " + zoom, e); log.error("Eror reading png " + x + " " + y + " zoom : " + zoom, e);

View file

@ -47,12 +47,12 @@ 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.DataExtraction; import com.osmand.DataExtraction;
import com.osmand.DefaultLauncherConstants; import com.osmand.DefaultLauncherConstants;
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;
import com.osmand.data.DataTileManager;
import com.osmand.data.Region; 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;
@ -78,36 +78,41 @@ public class OsmExtractionUI implements IMapLocationListener {
private DefaultMutableTreeNode amenitiesTree; private DefaultMutableTreeNode amenitiesTree;
private JTree treePlaces; private JTree treePlaces;
private JList searchList; private JList searchList;
private JFrame frame;
private JTextField searchTextField; private JTextField searchTextField;
private JFrame frame;
private JLabel statusBarLabel;
private Region region; private Region region;
private File workingDir; private File workingDir;
private JLabel workingDirLabel;
private JButton generateDataButton;
public OsmExtractionUI(final Region r){ public OsmExtractionUI(final Region r){
this.region = r; this.region = r;
createUI();
setRegion(r);
workingDir = new File(DefaultLauncherConstants.pathToWorkingDir); workingDir = new File(DefaultLauncherConstants.pathToWorkingDir);
createUI();
setRegion(r, "Region");
} }
public void setRegion(Region region){ public void setRegion(Region region, String name){
if (this.region == region) { if (this.region == region) {
return; return;
} }
this.region = region; this.region = region;
DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode root = new DataExtractionTreeNode(name, region);
amenitiesTree = new DataExtractionTreeNode("Amenities", region); amenitiesTree = new DataExtractionTreeNode("Closest amenities", region);
amenitiesTree.add(new DataExtractionTreeNode("closest", region)); amenitiesTree.add(new DataExtractionTreeNode("First 15", region));
for(AmenityType type : AmenityType.values()){ for(AmenityType type : AmenityType.values()){
amenitiesTree.add(new DataExtractionTreeNode(type.toString().toLowerCase(), type)); amenitiesTree.add(new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()), type));
} }
root.add(amenitiesTree); root.add(amenitiesTree);
if (region != null) { if (region != null) {
for (CityType t : CityType.values()) { for (CityType t : CityType.values()) {
DefaultMutableTreeNode cityTree = new DataExtractionTreeNode(t.toString(), t); DefaultMutableTreeNode cityTree = new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(t.toString()), t);
root.add(cityTree); root.add(cityTree);
for (City ct : region.getCitiesByType(t)) { for (City ct : region.getCitiesByType(t)) {
DefaultMutableTreeNode cityNodeTree = new DataExtractionTreeNode(ct.getName(), ct); DefaultMutableTreeNode cityNodeTree = new DataExtractionTreeNode(ct.getName(), ct);
@ -125,15 +130,19 @@ public class OsmExtractionUI implements IMapLocationListener {
} }
} }
} }
DataTileManager<LatLon> amenitiesManager = new DataTileManager<LatLon>();
if (region != null) { // amenities could be displayed as dots
for (Amenity a : region.getAmenityManager().getAllObjects()) { // DataTileManager<LatLon> amenitiesManager = new DataTileManager<LatLon>();
amenitiesManager.registerObject(a.getNode().getLatitude(), a.getNode().getLongitude(), a.getNode().getLatLon()); // if (region != null) {
} // for (Amenity a : region.getAmenityManager().getAllObjects()) {
} // amenitiesManager.registerObject(a.getNode().getLatitude(), a.getNode().getLongitude(), a.getNode().getLatLon());
mapPanel.setPoints(amenitiesManager); // }
// }
// mapPanel.setPoints(amenitiesManager);
if (searchList != null) {
updateListCities(region, searchTextField.getText(), searchList); updateListCities(region, searchTextField.getText(), searchList);
mapPanel.updateUI(); }
mapPanel.repaint();
treePlaces.setModel(new DefaultTreeModel(root, false)); treePlaces.setModel(new DefaultTreeModel(root, false));
} }
@ -144,16 +153,103 @@ public class OsmExtractionUI implements IMapLocationListener {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("Can't set look and feel", e);
} }
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();
content.add(statusBarLabel, BorderLayout.SOUTH);
treePlaces = new JTree(); treePlaces = new JTree();
treePlaces.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Region"), false)); treePlaces.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Region"), false));
JSplitPane panelForTreeAndMap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePlaces), mapPanel);
panelForTreeAndMap.setResizeWeight(0.2);
mapPanel.setFocusable(true);
mapPanel.addMapLocationListener(this);
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);
}
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 (o instanceof City) {
City c = (City) o;
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
mapPanel.requestFocus();
}
if (o instanceof Amenity) {
Amenity c = (Amenity) o;
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
mapPanel.requestFocus();
}
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(
e.getPath().getPathCount() - 2);
if (n.getUserObject() instanceof Street) {
Street str = (Street) n.getUserObject();
LatLon l = str.getLocationBuilding(c);
mapPanel.setLatLon(l.getLatitude(), l.getLongitude());
mapPanel.requestFocus();
}
}
}
}
}
}
});
}
public void createButtonsBar(Container content){
JPanel panel = new JPanel(new BorderLayout());
content.add(panel, BorderLayout.NORTH);
generateDataButton = new JButton();
generateDataButton.setText("Generate data ");
panel.add(generateDataButton);
generateDataButton.setEnabled(workingDir != null);
workingDirLabel = new JLabel();
workingDirLabel.setText(workingDir == null ? "<working dir unspecified>" : workingDir.getAbsolutePath());
panel.add(workingDirLabel);
}
public void createCitySearchPanel(Container content){
JPanel panel = new JPanel(new BorderLayout());
searchTextField = new JTextField();
final JButton button = new JButton();
button.setText("Set town");
panel.add(searchTextField, BorderLayout.CENTER);
panel.add(button, BorderLayout.WEST);
content.add(panel, BorderLayout.NORTH);
searchList = new JList(); searchList = new JList();
searchList.setCellRenderer(new DefaultListCellRenderer(){ searchList.setCellRenderer(new DefaultListCellRenderer(){
private static final long serialVersionUID = 4661949460526837891L; private static final long serialVersionUID = 4661949460526837891L;
@ -171,31 +267,6 @@ public class OsmExtractionUI implements IMapLocationListener {
} }
}); });
JSplitPane panelForTreeAndImage = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePlaces), mapPanel);
panelForTreeAndImage.setResizeWeight(0.2);
mapPanel.setFocusable(true);
mapPanel.addMapLocationListener(this);
JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(searchList), panelForTreeAndImage);
pane.setResizeWeight(0.2);
content.add(pane, BorderLayout.CENTER);
final JLabel label = new JLabel();
content.add(label, BorderLayout.SOUTH);
JPanel panel = new JPanel(new BorderLayout());
searchTextField = new JTextField();
final JButton button = new JButton();
button.setText("Set town");
panel.add(searchTextField, BorderLayout.CENTER);
panel.add(button, BorderLayout.WEST);
content.add(panel, BorderLayout.NORTH);
updateListCities(region, searchTextField.getText(), searchList); updateListCities(region, searchTextField.getText(), searchList);
searchTextField.getDocument().addUndoableEditListener(new UndoableEditListener(){ searchTextField.getDocument().addUndoableEditListener(new UndoableEditListener(){
@ -221,60 +292,14 @@ 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);
} }
label.setText(text); statusBarLabel.setText(text);
mapPanel.setLatLon(node.getLatitude(), node.getLongitude()); mapPanel.setLatLon(node.getLatitude(), node.getLongitude());
} else { } else {
String text = selectedCity == null ? "" : selectedCity.getName(); String text = selectedCity == null ? "" : selectedCity.getName();
label.setText(text); statusBarLabel.setText(text);
} }
}
});
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 (o instanceof City) {
City c = (City) o;
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
mapPanel.requestFocus();
}
if (o instanceof Amenity) {
Amenity c = (Amenity) o;
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
mapPanel.requestFocus();
}
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(
e.getPath().getPathCount() - 2);
if (n.getUserObject() instanceof Street) {
Street str = (Street) n.getUserObject();
LatLon l = str.getLocationBuilding(c);
mapPanel.setLatLon(l.getLatitude(), l.getLongitude());
mapPanel.requestFocus();
}
}
}
}
}
} }
}); });
MenuBar bar = new MenuBar();
fillMenuWithActions(bar);
frame.setMenuBar(bar);
} }
public void runUI(){ public void runUI(){
@ -285,13 +310,23 @@ public class OsmExtractionUI implements IMapLocationListener {
public void fillMenuWithActions(MenuBar bar){ public void fillMenuWithActions(MenuBar bar){
Menu menu = new Menu("File"); Menu menu = new Menu("File");
bar.add(menu); bar.add(menu);
MenuItem loadFile = new MenuItem("Load file..."); MenuItem loadFile = new MenuItem("Load osm file...");
menu.add(loadFile); menu.add(loadFile);
MenuItem specifyWorkingDir = new MenuItem("Specify working directory..."); MenuItem specifyWorkingDir = new MenuItem("Specify working directory...");
menu.add(specifyWorkingDir); menu.add(specifyWorkingDir);
menu.addSeparator();
MenuItem exitMenu= new MenuItem("Exit");
menu.add(exitMenu);
bar.add(MapPanel.getMenuToChooseSource(mapPanel)); bar.add(MapPanel.getMenuToChooseSource(mapPanel));
exitMenu.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
}
});
specifyWorkingDir.addActionListener(new ActionListener(){ specifyWorkingDir.addActionListener(new ActionListener(){
@Override @Override
@ -305,6 +340,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());
generateDataButton.setEnabled(true);
} }
} }
@ -344,7 +381,7 @@ public class OsmExtractionUI implements IMapLocationListener {
public void loadCountry(final File f){ public void loadCountry(final File f){
try { try {
final ProgressDialog dlg = new ProgressDialog(frame); final ProgressDialog dlg = new ProgressDialog(frame, "Loading osm file");
dlg.setRunnable(new Runnable(){ dlg.setRunnable(new Runnable(){
@Override @Override
@ -362,7 +399,8 @@ public class OsmExtractionUI implements IMapLocationListener {
}); });
Region region = (Region) dlg.run(); Region region = (Region) dlg.run();
if(region != null){ if(region != null){
setRegion(region); int i = f.getName().indexOf('.');
setRegion(region, Algoritms.capitalizeFirstLetterAndLowercase(f.getName().substring(0, i)));
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");

View file

@ -34,15 +34,9 @@ public class ProgressDialog extends JDialog implements IProgress {
private int deltaWork; private int deltaWork;
public ProgressDialog(Component parent, String name){
public ProgressDialog(Component parent, Runnable run){
this(parent);
this.run = run;
}
public ProgressDialog(Component parent){
super(JOptionPane.getFrameForComponent(parent), true); super(JOptionPane.getFrameForComponent(parent), true);
setTitle(name);
initDialog(); initDialog();
} }

View file

@ -69,7 +69,7 @@ public class MainMenuActivity extends Activity {
MainMenuActivity.this.finish(); MainMenuActivity.this.finish();
} }
}); });
// TODO exception!!! has leaked window !
final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices..."); final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices...");
final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg); final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg);
new Thread() { new Thread() {