Clean code

This commit is contained in:
Victor Shcherb 2012-11-11 13:44:18 +01:00
parent c7f2d39371
commit 3858180df6
3 changed files with 1 additions and 372 deletions

View file

@ -286,7 +286,7 @@ public class RouteResultPreparation {
} }
result.get(prevSegment).setDescription(turn + String.format(" and go %.2f meters", dist)); result.get(prevSegment).setDescription(turn + String.format(" and go %.2f meters", dist));
if(result.get(prevSegment).getTurnType().isSkipToSpeak()) { if(result.get(prevSegment).getTurnType().isSkipToSpeak()) {
result.get(prevSegment).setDescription(result.get(prevSegment).getDescription() +" (*)"); result.get(prevSegment).setDescription("-*"+result.get(prevSegment).getDescription());
} }
} }
prevSegment = i; prevSegment = i;

View file

@ -526,35 +526,6 @@ public class MapRouterLayer implements MapPanelLayer {
if (!w.getNodes().isEmpty()) { if (!w.getNodes().isEmpty()) {
res.add(w); res.add(w);
} }
/*DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder dom = factory.newDocumentBuilder();
Document doc = dom.parse(new InputSource(new StringReader(content.toString())));
NodeList list = doc.getElementsByTagName("coordinates");
for(int i=0; i<list.getLength(); i++){
Node item = list.item(i);
String str = item.getTextContent();
int st = 0;
int next = 0;
Way w = new Way(-1);
while((next = str.indexOf('\n', st)) != -1){
String coordinate = str.substring(st, next + 1);
int s = coordinate.indexOf(',');
if (s != -1) {
try {
double lon = Double.parseDouble(coordinate.substring(0, s));
double lat = Double.parseDouble(coordinate.substring(s + 1));
w.addNode(new net.osmand.osm.Node(lat, lon, -1));
} catch (NumberFormatException e) {
}
}
st = next + 1;
}
if(!w.getNodes().isEmpty()){
res.add(w);
}
}*/
} catch (IOException e) { } catch (IOException e) {
ExceptionHandler.handle(e); ExceptionHandler.handle(e);
} catch (JSONException e) { } catch (JSONException e) {

View file

@ -619,346 +619,4 @@ public class OsmExtractionUI implements IMapLocationListener {
settings.saveWindowBounds(frame.getBounds()); settings.saveWindowBounds(frame.getBounds());
System.exit(0); System.exit(0);
} }
// OLD CODE
/*
public JTree createTree(Container content) {
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 DataExtractionTreeNode) {
Object o = ((DataExtractionTreeNode) e.getPath().getLastPathComponent()).getModelObject();
if (o instanceof MapObject) {
MapObject c = (MapObject) o;
LatLon location = c.getLocation();
if (location != null) {
if (o instanceof Street) {
DataTileManager<Way> ways = new DataTileManager<Way>();
for (Way w : ((Street) o).getWayNodes()) {
LatLon l = w.getLatLon();
ways.registerObject(l.getLatitude(), l.getLongitude(), w);
}
mapPanel.setPoints(ways);
mapPanel.requestFocus();
}
mapPanel.setLatLon(location.getLatitude(), location.getLongitude());
mapPanel.requestFocus();
}
if (o instanceof TransportRoute) {
DataTileManager<Entity> ways = new DataTileManager<Entity>();
for (Way w : ((TransportRoute) o).getWays()) {
LatLon l = w.getLatLon();
ways.registerObject(l.getLatitude(), l.getLongitude(), w);
}
for (TransportStop w : ((TransportRoute) o).getBackwardStops()) {
LatLon l = w.getLocation();
ways.registerObject(l.getLatitude(), l.getLongitude(), new Node(l.getLatitude(), l.getLongitude(), w
.getId()));
}
for (TransportStop w : ((TransportRoute) o).getForwardStops()) {
LatLon l = w.getLocation();
ways.registerObject(l.getLatitude(), l.getLongitude(), new Node(l.getLatitude(), l.getLongitude(), w
.getId()));
}
mapPanel.setPoints(ways);
mapPanel.requestFocus();
}
} else if (o instanceof Entity) {
Entity c = (Entity) o;
LatLon latLon = c.getLatLon();
if (latLon != null) {
mapPanel.setLatLon(latLon.getLatitude(), latLon.getLongitude());
mapPanel.requestFocus();
}
}
}
}
}
});
treeModelListener = new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
Object node = e.getTreePath().getLastPathComponent();
if (e.getChildren() != null && e.getChildren().length > 0) {
node = e.getChildren()[0];
}
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) {
}
public void treeNodesRemoved(TreeModelEvent e) {
}
public void treeStructureChanged(TreeModelEvent e) {
}
};
treePlaces.getModel().addTreeModelListener(treeModelListener);
return treePlaces;
}
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 setRegion(Region region, String name){
if (this.region == region) {
return;
}
this.region = region;
DefaultMutableTreeNode root = new DataExtractionTreeNode(name, region);
if (region != null) {
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));
}
root.add(amenitiesTree);
DataExtractionTreeNode transport = new DataExtractionTreeNode("Transport", region);
root.add(transport);
for(String s : region.getTransportRoutes().keySet()){
DataExtractionTreeNode trRoute = new DataExtractionTreeNode(s, s);
transport.add(trRoute);
List<TransportRoute> list = region.getTransportRoutes().get(s);
for(TransportRoute r : list){
DataExtractionTreeNode route = new DataExtractionTreeNode(r.getRef(), r);
trRoute.add(route);
}
}
for (CityType t : CityType.values()) {
DefaultMutableTreeNode cityTree = new DataExtractionTreeNode(Algoritms.capitalizeFirstLetterAndLowercase(t.toString()), t);
root.add(cityTree);
for (City ct : region.getCitiesByType(t)) {
DefaultMutableTreeNode cityNodeTree = new DataExtractionTreeNode(ct.getName(), ct);
cityTree.add(cityNodeTree);
for (Street str : ct.getStreets()) {
DefaultMutableTreeNode strTree = new DataExtractionTreeNode(str.getName(), str);
cityNodeTree.add(strTree);
for (Building b : str.getBuildings()) {
DefaultMutableTreeNode building = new DataExtractionTreeNode(b.getName(), b);
strTree.add(building);
}
}
}
}
}
if (searchList != null) {
updateListCities(region, searchTextField.getText(), searchList);
}
mapPanel.repaint();
DefaultTreeModel newModel = new DefaultTreeModel(root, false);
newModel.addTreeModelListener(treeModelListener);
treePlaces.setModel(newModel);
updateButtonsBar();
locationChanged(mapPanel.getLatitude(), mapPanel.getLongitude(), this);
}
public static class DataExtractionTreeNode extends DefaultMutableTreeNode {
private static final long serialVersionUID = 1L;
private final Object modelObject;
public DataExtractionTreeNode(String name, Object modelObject){
super(name);
this.modelObject = modelObject;
}
public Object getModelObject(){
return modelObject;
}
}
private void recalculateAmenities(final double newLatitude, final double newLongitude) {
if (amenitiesTree != null) {
Region reg = (Region) amenitiesTree.getModelObject();
List<Amenity> closestAmenities = reg.getAmenityManager().getClosestObjects(newLatitude, newLongitude, 0, 5);
MapUtils.sortListOfMapObject(closestAmenities, newLatitude, newLongitude);
Map<AmenityType, List<Amenity>> filter = new HashMap<AmenityType, List<Amenity>>();
for (Amenity n : closestAmenities) {
AmenityType type = n.getType();
if (!filter.containsKey(type)) {
filter.put(type, new ArrayList<Amenity>());
}
filter.get(type).add(n);
}
for (int i = 1; i < amenitiesTree.getChildCount(); i++) {
AmenityType type = (AmenityType) ((DataExtractionTreeNode) amenitiesTree.getChildAt(i)).getModelObject();
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).removeAllChildren();
if (filter.get(type) != null) {
for (Amenity n : filter.get(type)) {
int dist = (int) (MapUtils.getDistance(n.getLocation(), newLatitude, newLongitude));
String str = n.getStringWithoutType(false) + " [" + 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();
for (int i = 0; i < 15 && i < closestAmenities.size(); i++) {
Amenity n = closestAmenities.get(i);
int dist = (int) (MapUtils.getDistance(n.getLocation(), newLatitude, newLongitude));
String str = n.getSimpleFormat(false) + " [" + dist + " m ]";
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).add(new DataExtractionTreeNode(str, n));
((DefaultTreeModel)treePlaces.getModel()).nodeStructureChanged(amenitiesTree.getChildAt(0));
}
}
}
public void updateListCities(Region r, String text, JList jList) {
Collection<City> city;
if (r == null) {
city = Collections.emptyList();
} else {
city = r.getSuggestedCities(text, 100);
}
City[] names = new City[city.size()];
int i = 0;
for (City c : city) {
names[i++] = c;
}
jList.setListData(names);
}
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 || treeNode.getModelObject() instanceof MapObject) {
return true;
}
}
}
return returnValue;
}
}
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);
}
}
}
}
*/
} }