diff --git a/DataExtractionOSM/.classpath b/DataExtractionOSM/.classpath index 9f58e99059..cddf9595c1 100644 --- a/DataExtractionOSM/.classpath +++ b/DataExtractionOSM/.classpath @@ -5,6 +5,6 @@ - + diff --git a/DataExtractionOSM/lib/icu4j-4_4_1.jar b/DataExtractionOSM/lib/icu4j-4_4_1.jar deleted file mode 100644 index dbb8b7884d..0000000000 Binary files a/DataExtractionOSM/lib/icu4j-4_4_1.jar and /dev/null differ diff --git a/DataExtractionOSM/lib/junidecode-0.1.jar b/DataExtractionOSM/lib/junidecode-0.1.jar new file mode 100644 index 0000000000..7c79c879e5 Binary files /dev/null and b/DataExtractionOSM/lib/junidecode-0.1.jar differ diff --git a/DataExtractionOSM/logging.properties b/DataExtractionOSM/logging.properties index 755f53b25f..3453681c1e 100644 --- a/DataExtractionOSM/logging.properties +++ b/DataExtractionOSM/logging.properties @@ -1,8 +1,13 @@ .level = SEVERE -handlers=java.util.logging.ConsoleHandler +handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler # Set the default logging level for the logger named com.mycompany com.osmand.level = ALL +java.util.logging.FileHandler.pattern=%h/Application Data/Osmand/osmand.log +java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.FileHandler.append = false +java.util.logging.FileHandler.limit = 100000 + java.util.logging.ConsoleHandler.level=ALL java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter \ No newline at end of file diff --git a/DataExtractionOSM/src/com/osmand/ExceptionHandler.java b/DataExtractionOSM/src/com/osmand/ExceptionHandler.java index fea87f65a6..adf0918dc9 100644 --- a/DataExtractionOSM/src/com/osmand/ExceptionHandler.java +++ b/DataExtractionOSM/src/com/osmand/ExceptionHandler.java @@ -1,18 +1,43 @@ package com.osmand; +import javax.swing.JOptionPane; + import org.apache.commons.logging.Log; +import com.osmand.swing.OsmExtractionUI; + 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(Throwable e){ + handle("Error occurred", e); } - public static void handle(String msg, Exception e){ - e.printStackTrace(); - log.error(msg, e); + public static void handle(String msg, Throwable e){ + if(e != null){ + log.error(msg, e); + } else { + log.error(msg); + } + if(e != null){ + e.printStackTrace(); + } + if (OsmExtractionUI.MAIN_APP != null && OsmExtractionUI.MAIN_APP.getFrame() != null) { + String text; + String title; + if (e != null) { + text = e.getMessage(); + title = msg; + } else { + title = "Error occured"; + text = msg; + } + JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), text, title, JOptionPane.ERROR_MESSAGE); + } + } + + public static void handle(String msg){ + handle(msg, null); } } diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index a23e573658..f2239433a6 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -30,10 +30,9 @@ public class ToDoConstants { // FIXME Bugs Android : - // Investigate good transliterate // 6. Understand concept of application where to save/restore global setting. // (for example reset navigate to point, reset link map with location). It should be reset after user call exit. - // Call ResourceManager.close when it is needed. + // Call ResourceManager.close when it is needed (+). // 10. Notification is gone after clear all notifications // Performance improvements Android : @@ -41,8 +40,6 @@ public class ToDoConstants { // TODO SWING : in release 0.1 - // 5. Implement suppress warning for duplicate id (+) - // 2. Configure file log & see log from file (add uncaught exception handling) (+) // 6. Implement renaming/deleting street/building/city (+) // 7. Implement saving bundle of tiles in different folder (+) @@ -70,4 +67,5 @@ public class ToDoConstants { // DONE SWING // 8. Implement basic transliteration version + // 2. Configure file log & see log from file (add uncaught exception handling) } diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java index 1ff8d45e5d..cb0a37c564 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java @@ -14,12 +14,13 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; +import net.sf.junidecode.Junidecode; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tools.bzip2.CBZip2InputStream; import org.xml.sax.SAXException; -import com.ibm.icu.text.Transliterator; import com.osmand.Algoritms; import com.osmand.IProgress; import com.osmand.data.Amenity; @@ -249,6 +250,7 @@ public class DataExtraction { progress.startTask("Loading file " + path, -1); } OsmBaseStorage storage = new OsmBaseStorage(); + storage.setSupressWarnings(DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId()); if (addFilter != null) { storage.getFilters().add(addFilter); } @@ -306,31 +308,32 @@ public class DataExtraction { // 7. Call data preparation to sort cities, calculate center location, assign id to objects country.doDataPreparation(); // 8. Transliterate names to english - Transliterator latin = Transliterator.getInstance("Any-Latin;NFD;[:Nonspacing Mark:] Remove;NFC"); - if(latin != null){ - convertEnglishName(country, latin); - for(CityType c : CityType.values() ){ - for(City city : country.getCitiesByType(c)){ - convertEnglishName(city, latin); - for(Street s : city.getStreets()){ - convertEnglishName(s, latin); - for(Building b : s.getBuildings()){ - convertEnglishName(b, latin); - } - } - } - } - for(Amenity a : country.getAmenityManager().getAllObjects()){ - convertEnglishName(a, latin); - } - } + + convertEnglishName(country); + for (CityType c : CityType.values()) { + for (City city : country.getCitiesByType(c)) { + convertEnglishName(city); + for (Street s : city.getStreets()) { + convertEnglishName(s); + for (Building b : s.getBuildings()) { + convertEnglishName(b); + } + } + } + } + for (Amenity a : country.getAmenityManager().getAllObjects()) { + convertEnglishName(a); + } return country; } + // icu4j example - icu is not good in transliteration russian names +// Transliterator latin = Transliterator.getInstance("Any-Latin;NFD;[:Nonspacing Mark:] Remove;NFC"); - private void convertEnglishName(MapObject o, Transliterator transliterator){ + private void convertEnglishName(MapObject o){ String name = o.getName(); if(name != null && o.getEnName() == null){ - o.setEnName(transliterator.transliterate(name)); + o.setEnName(Junidecode.unidecode(name)); +// o.setEnName(transliterator.transliterate(name)); } } diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java index ed81958003..41456aab29 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java @@ -56,6 +56,7 @@ public class OsmBaseStorage extends DefaultHandler { protected InputStream inputStream; protected InputStream streamForProgress; protected List filters = new ArrayList(); + protected boolean supressWarnings = true; public synchronized void parseOSM(InputStream stream, IProgress progress, InputStream streamForProgress) throws IOException, SAXException { @@ -89,6 +90,13 @@ public class OsmBaseStorage extends DefaultHandler { } + public boolean isSupressWarnings() { + return supressWarnings; + } + public void setSupressWarnings(boolean supressWarnings) { + this.supressWarnings = supressWarnings; + } + protected SAXParser saxParser; public SAXParser initSaxParser(){ if(saxParser != null){ @@ -192,8 +200,8 @@ public class OsmBaseStorage extends DefaultHandler { if(currentParsedEntity != null){ if(acceptEntityToLoad(currentParsedEntity)){ Entity oldEntity = entities.put(currentParsedEntity.getId(), currentParsedEntity); - if(oldEntity!= null){ - // throw new UnsupportedOperationException("Entity with id=" + oldEntity.getId() +" is duplicated in osm map"); + if(!supressWarnings && oldEntity!= null){ + throw new UnsupportedOperationException("Entity with id=" + oldEntity.getId() +" is duplicated in osm map"); } } else { // System.gc(); diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java index a129242f2f..4c3d3bab77 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; -import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.Stack; @@ -30,7 +29,6 @@ import java.util.Map.Entry; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import com.ibm.icu.text.Transliterator; import com.osmand.Algoritms; import com.osmand.data.MapObject; import com.osmand.osm.Entity; @@ -172,13 +170,17 @@ public class OsmStorageWriter { } } - public static void main(String[] args) { + /*public static void main(String[] args) { - Transliterator inst = Transliterator.getInstance("Any-Latin;NFD;[:Nonspacing Mark:] Remove;NFC"); +// Transliterator inst = Transliterator.getInstance("Any-Latin;NFD;[:Nonspacing Mark:] Remove;NFKC"); + Transliterator inst = Transliterator.getInstance("Any-Latin;"); Enumeration e = Transliterator.getAvailableIDs(); while(e.hasMoreElements()){ System.out.println(e.nextElement()); } - System.out.println(inst.transliterate("Привет всемь жаваыфайу ы х й к ще цуккак у ваа")); - } + String str = "Привет Гомель жаль прощаться до скорой встречи когда ы "; + System.out.println(Junidecode.unidecode(str)); + System.out.println(inst.transliterate(str)); + }*/ } + diff --git a/DataExtractionOSM/src/com/osmand/swing/DataExtractionSettings.java b/DataExtractionOSM/src/com/osmand/swing/DataExtractionSettings.java index ebcd04296e..25e5cf4111 100644 --- a/DataExtractionOSM/src/com/osmand/swing/DataExtractionSettings.java +++ b/DataExtractionOSM/src/com/osmand/swing/DataExtractionSettings.java @@ -84,6 +84,14 @@ public class DataExtractionSettings { preferences.putBoolean("use_internet", b); } + public boolean isSupressWarningsForDuplicatedId(){ + return preferences.getBoolean("supress_duplicated_id", true); + } + + public void setSupressWarningsForDuplicatedId(boolean b){ + preferences.putBoolean("supress_duplicated_id", b); + } + String[] SUFFIXES = new String[] {"av.", "avenue", "просп.", "пер.", "пр.","заул.", "проспект", "переул.", "бул.", "бульвар", "тракт"}; String[] DEFAUTL_SUFFIXES = new String[] {"str.", "street", "улица", "ул."}; diff --git a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionPreferencesDialog.java b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionPreferencesDialog.java index ae1252c0d2..f58f36f16c 100644 --- a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionPreferencesDialog.java +++ b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionPreferencesDialog.java @@ -32,6 +32,7 @@ public class OsmExtractionPreferencesDialog extends JDialog { private JTextField streetDefaultSuffixes; private JCheckBox useInternet; + private JCheckBox supressWarning; public OsmExtractionPreferencesDialog(Component parent){ super(JOptionPane.getFrameForComponent(parent), true); @@ -41,7 +42,7 @@ public class OsmExtractionPreferencesDialog extends JDialog { } public void showDialog(){ - setSize(600, 220); + setSize(600, 250); double x = getParent().getBounds().getCenterX(); double y = getParent().getBounds().getCenterY(); setLocation((int) x - getWidth() / 2, (int) y - getHeight() / 2); @@ -74,7 +75,7 @@ public class OsmExtractionPreferencesDialog extends JDialog { private void createGeneralSection(JPanel root) { JPanel panel = new JPanel(); - panel.setLayout(new GridLayout(1, 1, 5, 5)); + panel.setLayout(new GridLayout(2, 1, 5, 5)); panel.setBorder(BorderFactory.createTitledBorder("General")); root.add(panel); @@ -82,6 +83,11 @@ public class OsmExtractionPreferencesDialog extends JDialog { useInternet.setText("Use internet to download tiles"); useInternet.setSelected(DataExtractionSettings.getSettings().useInternetToLoadImages()); panel.add(useInternet); + + supressWarning = new JCheckBox(); + supressWarning.setText("Supress warnings for duplicated id in osm file"); + supressWarning.setSelected(DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId()); + panel.add(supressWarning); panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height)); } @@ -164,6 +170,9 @@ public class OsmExtractionPreferencesDialog extends JDialog { if(settings.useInternetToLoadImages() != useInternet.isSelected()){ settings.setUseInterentToLoadImages(useInternet.isSelected()); } + if(settings.isSupressWarningsForDuplicatedId() != supressWarning.isSelected()){ + settings.setSupressWarningsForDuplicatedId (supressWarning.isSelected()); + } } diff --git a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java index fefc357f67..3247be58f9 100644 --- a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java +++ b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java @@ -12,6 +12,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.Thread.UncaughtExceptionHandler; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.util.ArrayList; @@ -87,12 +88,25 @@ import com.osmand.swing.MapPanel.MapSelectionArea; public class OsmExtractionUI implements IMapLocationListener { - private static final Log log = LogFactory.getLog(OsmExtractionUI.class); + private static final Log log = LogFactory.getLog(OsmExtractionUI.class); + public static final String LOG_PATH = System.getProperty("user.home")+"/Application Data/Osmand/osmand.log"; + public static OsmExtractionUI MAIN_APP; public static void main(String[] args) { - OsmExtractionUI ui = new OsmExtractionUI(null); - ui.frame.setBounds(DataExtractionSettings.getSettings().getWindowBounds()); - ui.frame.setVisible(true); + // first of all config log + new File(LOG_PATH).getParentFile().mkdirs(); + final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){ + @Override + public void uncaughtException(Thread t, Throwable e) { + log.error("Error in thread " + t.getName(), e); + defaultHandler.uncaughtException(t, e); + } + }); + + MAIN_APP = new OsmExtractionUI(null); + MAIN_APP.frame.setBounds(DataExtractionSettings.getSettings().getWindowBounds()); + MAIN_APP.frame.setVisible(true); } protected City selectedCity; @@ -113,8 +127,7 @@ public class OsmExtractionUI implements IMapLocationListener { private JCheckBox normalizingStreets; private TreeModelListener treeModelListener; private JCheckBox loadingAllData; - - + public OsmExtractionUI(final Region r){ @@ -478,8 +491,28 @@ public class OsmExtractionUI implements IMapLocationListener { bar.add(menu); JMenuItem settings = new JMenuItem("Settings..."); menu.add(settings); + menu.addSeparator(); + JMenuItem openLogFile = new JMenuItem("Open log file..."); + menu.add(openLogFile); - + + openLogFile.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + File file = new File(OsmExtractionUI.LOG_PATH); + if (file != null && file.exists()) { + try { + Runtime.getRuntime().exec(new String[] { "notepad.exe", file.getAbsolutePath() }); //$NON-NLS-1$ + } catch (IOException es) { + ExceptionHandler.handle("Failed to open log file ", es); + } + + } else { + ExceptionHandler.handle("Log file is not found"); + } + } + }); + exitMenu.addActionListener(new ActionListener(){ @Override @@ -616,6 +649,10 @@ public class OsmExtractionUI implements IMapLocationListener { return fc; } + public JFrame getFrame() { + return frame; + } + public void loadCountry(final File f, final IOsmStorageFilter filter){ try { final ProgressDialog dlg = new ProgressDialog(frame, "Loading osm file"); @@ -655,7 +692,7 @@ public class OsmExtractionUI implements IMapLocationListener { } catch (InterruptedException e1) { log.error("Interrupted", e1); } catch (InvocationTargetException e1) { - log.error("Exception during operation", e1.getCause()); + ExceptionHandler.handle("Exception during operation", e1.getCause()); } } @@ -689,7 +726,7 @@ public class OsmExtractionUI implements IMapLocationListener { } catch (InterruptedException e1) { log.error("Interrupted", e1); } catch (InvocationTargetException e1) { - log.error("Exception during operation", e1.getCause()); + ExceptionHandler.handle("Log file is not found", e1.getCause()); } } diff --git a/OsmAnd/.classpath b/OsmAnd/.classpath index 605aecf7de..96027e6205 100644 --- a/OsmAnd/.classpath +++ b/OsmAnd/.classpath @@ -1,7 +1,7 @@ - +