fix small bugs for swing version
git-svn-id: https://osmand.googlecode.com/svn/trunk@50 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
acd99e37e6
commit
0a146f6088
5 changed files with 231 additions and 120 deletions
|
@ -130,6 +130,11 @@ public class Amenity {
|
||||||
return getType().toString() +" : " + getSubType() + " " +(name == null ? node.getId() : name);
|
return getType().toString() +" : " + getSubType() + " " +(name == null ? node.getId() : name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStringWithoutType(){
|
||||||
|
String name = node.getTag(OSMTagKey.NAME);
|
||||||
|
return getSubType() + " " +(name == null ? node.getId() : name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getSimpleFormat();
|
return getSimpleFormat();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.awt.Menu;
|
||||||
import java.awt.MenuBar;
|
import java.awt.MenuBar;
|
||||||
import java.awt.MenuItem;
|
import java.awt.MenuItem;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
|
@ -16,6 +17,7 @@ import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,6 +29,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
@ -116,6 +119,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
|
|
||||||
private List<IMapLocationListener> listeners = new ArrayList<IMapLocationListener>();
|
private List<IMapLocationListener> listeners = new ArrayList<IMapLocationListener>();
|
||||||
|
|
||||||
|
private MapSelectionArea selectionArea = new MapSelectionArea();
|
||||||
|
|
||||||
|
|
||||||
// cached data to draw image
|
// cached data to draw image
|
||||||
private Image[][] images;
|
private Image[][] images;
|
||||||
private int xStartingImage = 0;
|
private int xStartingImage = 0;
|
||||||
|
@ -136,9 +142,13 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
prepareImage();
|
prepareImage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setOpaque(false);
|
||||||
MapMouseAdapter mouse = new MapMouseAdapter();
|
MapMouseAdapter mouse = new MapMouseAdapter();
|
||||||
addMouseListener(mouse);
|
addMouseListener(mouse);
|
||||||
addMouseMotionListener(mouse);
|
addMouseMotionListener(mouse);
|
||||||
|
addMouseWheelListener(mouse);
|
||||||
|
|
||||||
|
addZoomButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,12 +198,21 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
g.fillOval(p.x, p.y, 3, 3);
|
g.fillOval(p.x, p.y, 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(selectionArea.isVisible()){
|
||||||
|
g.setColor(new Color(0, 0, 230, 50));
|
||||||
|
Rectangle r = selectionArea.getSelectedArea();
|
||||||
|
g.fillRect(r.x, r.y, r.width, r.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(Color.black);
|
||||||
String s = MessageFormat.format("Lat : {0}, lon : {1}, zoom : {2}", latitude, longitude, zoom);
|
String s = MessageFormat.format("Lat : {0}, lon : {1}, zoom : {2}", latitude, longitude, zoom);
|
||||||
g.drawString(s, 5, 20);
|
g.drawString(s, 5, 20);
|
||||||
|
|
||||||
g.fillOval(getWidth() / 2 - 2, getHeight() / 2 - 2, 4, 4);
|
g.fillOval(getWidth() / 2 - 2, getHeight() / 2 - 2, 4, 4);
|
||||||
g.drawOval(getWidth() / 2 - 2, getHeight() / 2 - 2, 4, 4);
|
g.drawOval(getWidth() / 2 - 2, getHeight() / 2 - 2, 4, 4);
|
||||||
g.drawOval(getWidth() / 2 - 5, getHeight() / 2 - 5, 10, 10);
|
g.drawOval(getWidth() / 2 - 5, getHeight() / 2 - 5, 10, 10);
|
||||||
|
|
||||||
|
super.paintComponent(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -331,6 +350,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
|
|
||||||
|
|
||||||
public void setZoom(int zoom){
|
public void setZoom(int zoom){
|
||||||
|
if(map != null && (zoom > map.getMaximumZoomSupported() || zoom < map.getMinimumZoomSupported())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.zoom = zoom;
|
this.zoom = zoom;
|
||||||
prepareImage();
|
prepareImage();
|
||||||
}
|
}
|
||||||
|
@ -354,6 +376,10 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
return zoom;
|
return zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MapSelectionArea getSelectionArea() {
|
||||||
|
return selectionArea;
|
||||||
|
}
|
||||||
|
|
||||||
public ITileSource getMap(){
|
public ITileSource getMap(){
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -434,10 +460,97 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
|
|
||||||
public void setPoints(DataTileManager<LatLon> points) {
|
public void setPoints(DataTileManager<LatLon> points) {
|
||||||
this.points = points;
|
this.points = points;
|
||||||
|
prepareImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addZoomButtons(){
|
||||||
|
JButton zoomIn = new JButton("+");
|
||||||
|
JButton zoomOut = new JButton("-");
|
||||||
|
zoomIn.addActionListener(new ActionListener(){
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setZoom(getZoom() + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
zoomOut.addActionListener(new ActionListener(){
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setZoom(getZoom() - 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(zoomIn);
|
||||||
|
add(zoomOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MapSelectionArea {
|
||||||
|
|
||||||
|
private double lat1;
|
||||||
|
private double lon1;
|
||||||
|
private double lat2;
|
||||||
|
private double lon2;
|
||||||
|
|
||||||
|
|
||||||
|
public double getLat1() {
|
||||||
|
return lat1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLat2() {
|
||||||
|
return lat2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLon1() {
|
||||||
|
return lon1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLon2() {
|
||||||
|
return lon2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle getSelectedArea(){
|
||||||
|
Rectangle r = new Rectangle();
|
||||||
|
r.x = getWidth() / 2 + MapUtils.getPixelShiftX(zoom, lon1, getLongitude(), getTileSize());
|
||||||
|
r.y = getHeight() / 2 + MapUtils.getPixelShiftY(zoom, lat1, getLatitude(), getTileSize());
|
||||||
|
r.width = getWidth() / 2 + MapUtils.getPixelShiftX(zoom, lon2, getLongitude(), getTileSize()) - r.x;
|
||||||
|
r.height = getHeight() / 2 + MapUtils.getPixelShiftY(zoom, lat2, getLatitude(), getTileSize()) - r.y;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVisible(){
|
||||||
|
if(lat1 == lat2 || lon1 == lon2){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Rectangle area = getSelectedArea();
|
||||||
|
return area.width > 4 && area.height > 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setSelectedArea(int x1, int y1, int x2, int y2){
|
||||||
|
int rx1 = Math.min(x1, x2);
|
||||||
|
int rx2 = Math.max(x1, x2);
|
||||||
|
int ry1 = Math.min(y1, y2);
|
||||||
|
int ry2 = Math.max(y1, y2);
|
||||||
|
int zoom = getZoom();
|
||||||
|
double xTile = getXTile();
|
||||||
|
double yTile = getYTile();
|
||||||
|
int wid = getWidth();
|
||||||
|
int h = getHeight();
|
||||||
|
int tileSize = getTileSize();
|
||||||
|
|
||||||
|
double xTile1 = xTile - (wid / 2 - rx1) / ((double)tileSize);
|
||||||
|
double yTile1 = yTile - (h / 2 - ry1) / ((double)tileSize);
|
||||||
|
double xTile2 = xTile - (wid / 2 - rx2) / ((double)tileSize);
|
||||||
|
double yTile2 = yTile - (h / 2 - ry2) / ((double)tileSize);
|
||||||
|
lat1 = MapUtils.getLatitudeFromTile(zoom, yTile1);
|
||||||
|
lat2 = MapUtils.getLatitudeFromTile(zoom, yTile2);
|
||||||
|
lon1 = MapUtils.getLongitudeFromTile(zoom, xTile1);
|
||||||
|
lon2 = MapUtils.getLongitudeFromTile(zoom, xTile2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MapMouseAdapter extends MouseAdapter {
|
public class MapMouseAdapter extends MouseAdapter {
|
||||||
private Point startDragging = null;
|
private Point startDragging = null;
|
||||||
|
private Point startSelecting = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
@ -462,14 +575,29 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
startDragging = e.getPoint();
|
startDragging = e.getPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(startSelecting != null){
|
||||||
|
selectionArea.setSelectedArea(startSelecting.x, startSelecting.y, e.getPoint().x, e.getPoint().y);
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
|
if(e.getWheelRotation() < 0){
|
||||||
|
setZoom(getZoom() + 1);
|
||||||
|
} else if(e.getWheelRotation() > 0) {
|
||||||
|
setZoom(getZoom() - 1);
|
||||||
|
}
|
||||||
|
super.mouseWheelMoved(e);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if(e.getButton() == MouseEvent.BUTTON3){
|
if(e.getButton() == MouseEvent.BUTTON3){
|
||||||
if(startDragging == null){
|
if(startDragging == null){
|
||||||
startDragging = e.getPoint();
|
startDragging = e.getPoint();
|
||||||
}
|
}
|
||||||
|
} else if(e.getButton() == MouseEvent.BUTTON1){
|
||||||
|
startSelecting = e.getPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -481,6 +609,14 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
startDragging = null;
|
startDragging = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(e.getButton() == MouseEvent.BUTTON1){
|
||||||
|
if(startSelecting != null){
|
||||||
|
selectionArea.setSelectedArea(startSelecting.x, startSelecting.y, e.getPoint().x, e.getPoint().y);
|
||||||
|
startSelecting = null;
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
super.mouseReleased(e);
|
super.mouseReleased(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ import javax.swing.filechooser.FileFilter;
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.osmand.DataExtraction;
|
import com.osmand.DataExtraction;
|
||||||
|
@ -53,6 +55,7 @@ import com.osmand.data.City;
|
||||||
import com.osmand.data.DataTileManager;
|
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.City.CityType;
|
import com.osmand.data.City.CityType;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
|
@ -61,8 +64,15 @@ import com.osmand.osm.Node;
|
||||||
import com.osmand.osm.OSMSettings.OSMTagKey;
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||||
|
|
||||||
public class OsmExtractionUI implements IMapLocationListener {
|
public class OsmExtractionUI implements IMapLocationListener {
|
||||||
protected City selectedCity;
|
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(OsmExtractionUI.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
OsmExtractionUI ui = new OsmExtractionUI(null);
|
||||||
|
ui.runUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected City selectedCity;
|
||||||
private MapPanel mapPanel = new MapPanel(new File(DefaultLauncherConstants.pathToDirWithTiles));
|
private MapPanel mapPanel = new MapPanel(new File(DefaultLauncherConstants.pathToDirWithTiles));
|
||||||
|
|
||||||
private DefaultMutableTreeNode amenitiesTree;
|
private DefaultMutableTreeNode amenitiesTree;
|
||||||
|
@ -81,10 +91,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
workingDir = new File(DefaultLauncherConstants.pathToWorkingDir);
|
workingDir = new File(DefaultLauncherConstants.pathToWorkingDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
OsmExtractionUI ui = new OsmExtractionUI(null);
|
|
||||||
ui.runUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegion(Region region){
|
public void setRegion(Region region){
|
||||||
if (this.region == region) {
|
if (this.region == region) {
|
||||||
|
@ -94,6 +100,9 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||||
amenitiesTree = new DataExtractionTreeNode("Amenities", region);
|
amenitiesTree = new DataExtractionTreeNode("Amenities", region);
|
||||||
amenitiesTree.add(new DataExtractionTreeNode("closest", region));
|
amenitiesTree.add(new DataExtractionTreeNode("closest", region));
|
||||||
|
for(AmenityType type : AmenityType.values()){
|
||||||
|
amenitiesTree.add(new DataExtractionTreeNode(type.toString().toLowerCase(), type));
|
||||||
|
}
|
||||||
root.add(amenitiesTree);
|
root.add(amenitiesTree);
|
||||||
|
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
|
@ -131,7 +140,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
|
|
||||||
|
|
||||||
public void createUI(){
|
public void createUI(){
|
||||||
frame = new JFrame("Tree of choose");
|
frame = new JFrame("OsmAnd Map Creator");
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -222,7 +231,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
treePlaces.addTreeSelectionListener(new TreeSelectionListener(){
|
treePlaces.addTreeSelectionListener(new TreeSelectionListener(){
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(TreeSelectionEvent e) {
|
public void valueChanged(TreeSelectionEvent e) {
|
||||||
|
@ -235,6 +243,11 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
||||||
mapPanel.requestFocus();
|
mapPanel.requestFocus();
|
||||||
}
|
}
|
||||||
|
if (o instanceof Amenity) {
|
||||||
|
Amenity c = (Amenity) o;
|
||||||
|
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
|
||||||
|
mapPanel.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
if (o instanceof Entity) {
|
if (o instanceof Entity) {
|
||||||
Entity c = (Entity) o;
|
Entity c = (Entity) o;
|
||||||
|
@ -348,13 +361,16 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Region region = (Region) dlg.run();
|
Region region = (Region) dlg.run();
|
||||||
|
if(region != null){
|
||||||
setRegion(region);
|
setRegion(region);
|
||||||
|
frame.setTitle("OsmAnd Map Creator - " + f.getName());
|
||||||
|
} else {
|
||||||
|
//frame.setTitle("OsmAnd Map Creator");
|
||||||
|
}
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
// TODO
|
log.error("Interrupted", e1);
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e1) {
|
} catch (InvocationTargetException e1) {
|
||||||
// TODO
|
log.error("Exception during operation", e1.getCause());
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,21 +387,29 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, List<Amenity>> filter = new TreeMap<String, List<Amenity>>();
|
Map<AmenityType, List<Amenity>> filter = new TreeMap<AmenityType, List<Amenity>>();
|
||||||
for (Amenity n : closestAmenities) {
|
for (Amenity n : closestAmenities) {
|
||||||
String type = n.getType().toString();
|
AmenityType type = n.getType();
|
||||||
if (!filter.containsKey(type)) {
|
if (!filter.containsKey(type)) {
|
||||||
filter.put(type, new ArrayList<Amenity>());
|
filter.put(type, new ArrayList<Amenity>());
|
||||||
}
|
}
|
||||||
filter.get(type).add(n);
|
filter.get(type).add(n);
|
||||||
}
|
}
|
||||||
for (int i = 1; i < amenitiesTree.getChildCount();) {
|
|
||||||
if (!filter.containsKey(((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).getUserObject())) {
|
|
||||||
amenitiesTree.remove(i);
|
for (int i = 1; i < amenitiesTree.getChildCount(); i++) {
|
||||||
} else {
|
AmenityType type = (AmenityType) ((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).getUserObject();
|
||||||
i++;
|
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).removeAllChildren();
|
||||||
|
if (filter.get(type) != null) {
|
||||||
|
for (Amenity n : filter.get(type)) {
|
||||||
|
int dist = (int) (MapUtils.getDistance(n.getNode(), newLatitude, newLongitude));
|
||||||
|
String str = n.getStringWithoutType() + " [" + dist + " m ]";
|
||||||
|
DataExtractionTreeNode node = new DataExtractionTreeNode(str, n);
|
||||||
|
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).add(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
((DefaultTreeModel)treePlaces.getModel()).nodeStructureChanged(amenitiesTree.getChildAt(i));
|
||||||
|
}
|
||||||
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).removeAllChildren();
|
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).removeAllChildren();
|
||||||
|
|
||||||
for (int i = 0; i < 15 && i < closestAmenities.size(); i++) {
|
for (int i = 0; i < 15 && i < closestAmenities.size(); i++) {
|
||||||
|
@ -393,30 +417,10 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
int dist = (int) (MapUtils.getDistance(n.getNode(), newLatitude, newLongitude));
|
int dist = (int) (MapUtils.getDistance(n.getNode(), newLatitude, newLongitude));
|
||||||
String str = n.getSimpleFormat() + " [" + dist + " m ]";
|
String str = n.getSimpleFormat() + " [" + dist + " m ]";
|
||||||
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).add(new DataExtractionTreeNode(str, n));
|
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).add(new DataExtractionTreeNode(str, n));
|
||||||
|
((DefaultTreeModel)treePlaces.getModel()).nodeStructureChanged(amenitiesTree.getChildAt(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : filter.keySet()) {
|
|
||||||
DefaultMutableTreeNode p = null;
|
|
||||||
for (int i = 0; i < amenitiesTree.getChildCount(); i++) {
|
|
||||||
if (s.equals(((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).getUserObject())) {
|
|
||||||
p = ((DefaultMutableTreeNode) amenitiesTree.getChildAt(i));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p == null) {
|
|
||||||
p = new DefaultMutableTreeNode(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
p.removeAllChildren();
|
|
||||||
for (Amenity n : filter.get(s)) {
|
|
||||||
int dist = (int) (MapUtils.getDistance(n.getNode(), newLatitude, newLongitude));
|
|
||||||
String str = n.getSimpleFormat() + " [" + dist + " m ]";
|
|
||||||
DataExtractionTreeNode node = new DataExtractionTreeNode(str, n);
|
|
||||||
p.add(node);
|
|
||||||
}
|
|
||||||
amenitiesTree.add(p);
|
|
||||||
}
|
|
||||||
treePlaces.updateUI();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import com.osmand.IProgress;
|
import com.osmand.IProgress;
|
||||||
|
|
||||||
|
@ -49,10 +50,9 @@ public class ProgressDialog extends JDialog implements IProgress {
|
||||||
finished = false;
|
finished = false;
|
||||||
result = null;
|
result = null;
|
||||||
new WorkerThread().start();
|
new WorkerThread().start();
|
||||||
synchronized (this) {
|
|
||||||
if(!finished){
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
if (!finished) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
throw exception;
|
throw exception;
|
||||||
|
@ -64,7 +64,6 @@ public class ProgressDialog extends JDialog implements IProgress {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (run != null) {
|
if (run != null) {
|
||||||
run.run();
|
run.run();
|
||||||
|
@ -72,11 +71,12 @@ public class ProgressDialog extends JDialog implements IProgress {
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
exception = new InvocationTargetException(e);
|
exception = new InvocationTargetException(e);
|
||||||
} finally {
|
} finally {
|
||||||
synchronized (this) {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
finished = true;
|
@Override
|
||||||
|
public void run() {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,14 +170,23 @@ public class ProgressDialog extends JDialog implements IProgress {
|
||||||
if(work == 0){
|
if(work == 0){
|
||||||
work = 1;
|
work = 1;
|
||||||
}
|
}
|
||||||
if(work != -1){
|
final int w = work;
|
||||||
|
SwingUtilities.invokeLater(new Runnable(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(w != -1){
|
||||||
progressBar.setMinimum(0);
|
progressBar.setMinimum(0);
|
||||||
progressBar.setMaximum(work);
|
progressBar.setMaximum(w);
|
||||||
progressBar.setValue(0);
|
progressBar.setValue(0);
|
||||||
progressBar.setIndeterminate(false);
|
progressBar.setIndeterminate(false);
|
||||||
} else {
|
} else {
|
||||||
progressBar.setIndeterminate(true);
|
progressBar.setIndeterminate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
deltaWork = 0;
|
deltaWork = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
package com.osmand.swing;
|
|
||||||
|
|
||||||
import com.osmand.IProgress;
|
|
||||||
|
|
||||||
public class SwingProgressImplementation implements IProgress {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finishTask() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIndeterminate() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void progress(int deltaWork) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remaining(int remainingWork) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startTask(String taskName, int work) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startWork(int work) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue