From 3833f018f2a609256b84fcb00bba72b67bc8f903 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 2 Jun 2010 15:19:37 +0000 Subject: [PATCH] fix some swing improvements git-svn-id: https://osmand.googlecode.com/svn/trunk@119 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- DataExtractionOSM/logging.properties | 2 +- .../src/com/osmand/ToDoConstants.java | 30 +--- .../src/com/osmand/data/DataTileManager.java | 8 + .../src/com/osmand/data/Region.java | 8 + .../src/com/osmand/data/Street.java | 14 +- .../src/com/osmand/swing/OsmExtractionUI.java | 142 +++++++++++++++--- .../swing/TileBundleDownloadDialog.java | 23 +++ 7 files changed, 180 insertions(+), 47 deletions(-) diff --git a/DataExtractionOSM/logging.properties b/DataExtractionOSM/logging.properties index 3453681c1e..3a224a64e4 100644 --- a/DataExtractionOSM/logging.properties +++ b/DataExtractionOSM/logging.properties @@ -6,7 +6,7 @@ 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.append = true java.util.logging.FileHandler.limit = 100000 java.util.logging.ConsoleHandler.level=ALL diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index f2239433a6..8fc6a1b373 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -13,14 +13,11 @@ public class ToDoConstants { // TODO ANDROID in release 0.1 -// 25. POI search near to map location (show categories & type). Second cut. (implement incremental search) // 29. Show opened/closed amenities (in search poi). // 13. Save point as favorite & introduce favorite points dialog - // 3. Revise osmand UI. Preparing new icons (revise UI 18, 2, ). Main application icon, back to location icon. // 14. Show zoom level on map - // NOT in release 0.1 // 8. Enable change POI directly on map (requires OSM login) // 16. Support open street bugs api. @@ -32,40 +29,17 @@ public class ToDoConstants { // FIXME Bugs Android : // 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 : // 2. Introducing cache of file names that are on disk (creating new File() consumes a lot of memory) (+) - // TODO SWING : in release 0.1 - // 6. Implement renaming/deleting street/building/city (+) - // 7. Implement saving bundle of tiles in different folder (+) - - // NOT in release 0.1 + // TODO swing NOT in release 0.1 // 1. Download tiles without using dir tiles // DONE ANDROID : -// 27. Search intersection of streets -// 24. Implement ResourceManager, load cities/streets/buildings on Low memory (clear previous all addresses cities). -// 28. Implement transliteration search for android version -// 5. Search for city/streets/buildings -// 15. Investigate interruption of any long running operation & implement where it is needed. - // ProgressDialogImplementation should support setOnCancelListener or obtain CANCEL message & - // throw InterruptedException in all methods (remaining, progress, startTask, ...) when call it. - // Otherwise thread could be stopped however it is not good method. -// 21. Implement zooming tile (if tile doesn't exist local, we can zoom in previous tile). -// 11. Print out additional info speed, altitude, number of satellites -// 19. Show how map is rotated where north/south on map (do not consider compass) -// 23. Implement moving point from center to bottom (for rotating map) -// 17. Enable go to location by specifying coordinates -// 9. Configure file log & see log from file (when exception happened to see from device) -// 2. Showing compass on the map : use device compass if exists(?) -// 18. Implement go to point // 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/DataTileManager.java b/DataExtractionOSM/src/com/osmand/data/DataTileManager.java index d6a0da770b..ea3440219e 100644 --- a/DataExtractionOSM/src/com/osmand/data/DataTileManager.java +++ b/DataExtractionOSM/src/com/osmand/data/DataTileManager.java @@ -148,6 +148,14 @@ public class DataTileManager { return evTile(tileX, tileY); } + public void unregisterObject(double latitude, double longitude, T object){ + String tile = evaluateTile(latitude, longitude); + if(objects.containsKey(tile)){ + objects.get(tile).remove(object); + } + + } + public String registerObject(double latitude, double longitude, T object){ String tile = evaluateTile(latitude, longitude); if(!objects.containsKey(tile)){ diff --git a/DataExtractionOSM/src/com/osmand/data/Region.java b/DataExtractionOSM/src/com/osmand/data/Region.java index a03afd368e..eefb699d98 100644 --- a/DataExtractionOSM/src/com/osmand/data/Region.java +++ b/DataExtractionOSM/src/com/osmand/data/Region.java @@ -137,6 +137,14 @@ public class Region extends MapObject { } } + 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())){ diff --git a/DataExtractionOSM/src/com/osmand/data/Street.java b/DataExtractionOSM/src/com/osmand/data/Street.java index dbab879afd..b4d97b7682 100644 --- a/DataExtractionOSM/src/com/osmand/data/Street.java +++ b/DataExtractionOSM/src/com/osmand/data/Street.java @@ -61,6 +61,10 @@ public class Street extends MapObject { } } + public boolean isRegisteredInCity(){ + return city.getStreet(getName()) == this; + } + @Override public void setName(String name) { if (name.equals(getName())) { @@ -69,7 +73,11 @@ public class Street extends MapObject { if (city.getStreet(getName()) == this) { city.unregisterStreet(getName()); super.setName(name); - city.registerStreet(this); + Street s = city.registerStreet(this); + if(s != this){ + // that case means that street unregistered +// city = null; + } } else { super.setName(name); } @@ -79,6 +87,10 @@ public class Street extends MapObject { public List getWayNodes() { return wayNodes; } + + public City getCity() { + return city; + } public void doDataPreparation() { Collections.sort(buildings, new Comparator(){ diff --git a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java index 3247be58f9..39784d1f02 100644 --- a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java +++ b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java @@ -6,6 +6,8 @@ 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; @@ -24,6 +26,7 @@ import java.util.List; import java.util.Map; import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -37,6 +40,7 @@ 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; @@ -56,6 +60,7 @@ 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 org.apache.commons.logging.Log; @@ -127,6 +132,7 @@ public class OsmExtractionUI implements IMapLocationListener { private JCheckBox normalizingStreets; private TreeModelListener treeModelListener; private JCheckBox loadingAllData; + @@ -144,7 +150,7 @@ public class OsmExtractionUI implements IMapLocationListener { this.region = region; DefaultMutableTreeNode root = new DataExtractionTreeNode(name, region); if (region != null) { - amenitiesTree = new DataExtractionTreeNode("Closest amenities", region); + 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)); @@ -235,7 +241,15 @@ public class OsmExtractionUI implements IMapLocationListener { 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) { @@ -283,18 +297,23 @@ public class OsmExtractionUI implements IMapLocationListener { treeModelListener = new TreeModelListener() { public void treeNodesChanged(TreeModelEvent e) { - DefaultMutableTreeNode node; - node = (DefaultMutableTreeNode) - (e.getTreePath().getLastPathComponent()); - if(node instanceof DataExtractionTreeNode){ - if(((DataExtractionTreeNode) node).getModelObject() instanceof Region){ - Region r = (Region) ((DataExtractionTreeNode) node).getModelObject(); - r.setName(node.getUserObject().toString()); - } else if(((DataExtractionTreeNode) node).getModelObject() instanceof MapObject){ - MapObject r = (MapObject) ((DataExtractionTreeNode) node).getModelObject(); - r.setName(node.getUserObject().toString()); - } - } + for (Object node : e.getChildren()) { + 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) { } @@ -307,6 +326,8 @@ public class OsmExtractionUI implements IMapLocationListener { return treePlaces; } + + protected void updateButtonsBar() { generateDataButton.setEnabled(region != null); normalizingStreets.setVisible(region == null); @@ -380,6 +401,7 @@ public class OsmExtractionUI implements IMapLocationListener { builder.writeAddress(); msg.append(", Address index ").append("successfully created"); } + // new DataIndexReader().testIndex(new File( // DataExtractionSettings.getSettings().getDefaultWorkingDir(), // IndexConstants.ADDRESS_INDEX_DIR+region.getName()+IndexConstants.ADDRESS_INDEX_EXT)); @@ -467,6 +489,64 @@ public class OsmExtractionUI implements IMapLocationListener { } + 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(JMenuBar bar){ JMenu menu = new JMenu("File"); bar.add(menu); @@ -501,10 +581,14 @@ public class OsmExtractionUI implements IMapLocationListener { 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); + if (System.getProperty("os.name").startsWith("Windows")) { + 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 { + JOptionPane.showMessageDialog(frame, "Open log file manually " + LOG_PATH); } } else { @@ -841,6 +925,30 @@ public class OsmExtractionUI implements IMapLocationListener { System.exit(0); } } + + private class PopupTrigger extends MouseAdapter { + + private final JPopupMenu popupMenu; + + public PopupTrigger(JPopupMenu popupMenu) { + this.popupMenu = popupMenu; + } + public void mouseReleased(MouseEvent e) + { + if (e.isPopupTrigger()) + { + int x = e.getX(); + int y = e.getY(); + TreePath path = treePlaces.getPathForLocation(x, y); + if (path != null) { + if(!treePlaces.getSelectionModel().isPathSelected(path)){ + treePlaces.setSelectionPath(path); + } + popupMenu.show(treePlaces, x, y); + } + } + } + } } diff --git a/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java b/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java index 2fa9d9ca50..aef78cf6be 100644 --- a/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java +++ b/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java @@ -15,6 +15,7 @@ import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -43,8 +44,10 @@ public class TileBundleDownloadDialog extends JDialog { private JSpinner endSpinner; private JButton downloadButton; private JButton cancelButton; + private JButton specifyFolder; private File tilesLocation; + public TileBundleDownloadDialog(Component parent, MapPanel panel){ super(JOptionPane.getFrameForComponent(parent), true); map = panel.getMap(); @@ -104,6 +107,9 @@ public class TileBundleDownloadDialog extends JDialog { JPanel buttonControls = new JPanel(); buttonControls.setLayout(new BoxLayout(buttonControls, BoxLayout.X_AXIS)); buttonControls.add(Box.createHorizontalGlue()); + specifyFolder = new JButton("Specify different folder"); + buttonControls.add(specifyFolder); + buttonControls.add(Box.createHorizontalStrut(3)); downloadButton = new JButton("Download tiles"); buttonControls.add(downloadButton); buttonControls.add(Box.createHorizontalStrut(3)); @@ -144,6 +150,23 @@ public class TileBundleDownloadDialog extends JDialog { } }); + specifyFolder.addActionListener(new ActionListener(){ + + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser fc = new JFileChooser(); + fc.setDialogTitle("Choose working directory"); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + if(tilesLocation != null){ + fc.setCurrentDirectory(tilesLocation); + } + if(fc.showOpenDialog(TileBundleDownloadDialog.this) == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null && + fc.getSelectedFile().isDirectory()){ + tilesLocation = fc.getSelectedFile(); + } + } + + }); }