diff --git a/README.md b/README.md
index 9b18cc9..7f2ae01 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
Make [To-Fix](http://osmlab.github.io/to-fix) OpenStreetMap microtasking challenges available in [JOSM](http://josm.openstreetmap.de/) editor.
-
+
+
## Installation
@@ -15,7 +16,27 @@ Make [To-Fix](http://osmlab.github.io/to-fix) OpenStreetMap microtasking challen
- Ubuntu: `cp tofix.jar ~/.josm/plugins/`
- Mac OSX: `cp tofix.jar ~/Library/JOSM/plugins`
+- Windows : Copy in `C:\Users\(Windows user)\AppData\Roaming\JOSM\plugins`
*Activate plugin*
-
+
+
+
+
+## Configuration
+
+#### Shortcuts
+
+Default shortcuts:
+
+- **Skip button:** ALT + SHIFT + S
+- **Not a error button :** ALT + SHIFT + N
+- **Fixed button :** ALT + SHIFT + S
+
+Example to configure your own shortcuts:
+
+
+
+
+
diff --git a/build.xml b/build.xml
index 7f2d216..b308a28 100644
--- a/build.xml
+++ b/build.xml
@@ -3,10 +3,11 @@
+
-
+
-
+
diff --git a/dist/tofix.jar b/dist/tofix.jar
index 0a93efb..9bd0591 100644
Binary files a/dist/tofix.jar and b/dist/tofix.jar differ
diff --git a/images/dialogs/icontofix.png b/images/dialogs/icontofix.png
index f00ff55..ce8bdb0 100644
Binary files a/images/dialogs/icontofix.png and b/images/dialogs/icontofix.png differ
diff --git a/images/icontofix.png b/images/icontofix.png
index 41fc7da..ce8bdb0 100644
Binary files a/images/icontofix.png and b/images/icontofix.png differ
diff --git a/images/mapmode/icontofix.png b/images/mapmode/icontofix.png
index 41fc7da..ce8bdb0 100644
Binary files a/images/mapmode/icontofix.png and b/images/mapmode/icontofix.png differ
diff --git a/images/mapmode/noterror.png b/images/mapmode/noterror.png
new file mode 100644
index 0000000..672e7df
Binary files /dev/null and b/images/mapmode/noterror.png differ
diff --git a/src/org/openstreetmap/josm/plugins/tofix/TofixDialog.java b/src/org/openstreetmap/josm/plugins/tofix/TofixDialog.java
index ab664ec..1cc4611 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/TofixDialog.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/TofixDialog.java
@@ -1,49 +1,44 @@
package org.openstreetmap.josm.plugins.tofix;
-import java.awt.FlowLayout;
+import java.awt.Cursor;
import java.awt.GridLayout;
-import java.awt.Polygon;
+import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.Hashtable;
import javax.swing.AbstractAction;
import static javax.swing.Action.NAME;
import static javax.swing.Action.SHORT_DESCRIPTION;
import static javax.swing.Action.SMALL_ICON;
import javax.swing.JComboBox;
+import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JTabbedPane;
import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
-import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.gui.JosmUserIdentityManager;
import org.openstreetmap.josm.gui.MapView;
import org.openstreetmap.josm.gui.SideButton;
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
-import org.openstreetmap.josm.plugins.tofix.bean.AccessTaskBean;
-import org.openstreetmap.josm.plugins.tofix.bean.AttributesBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemFixedBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemKeeprightBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemNycbuildingsBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemTigerdeltaBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemUnconnectedBean;
+import org.openstreetmap.josm.plugins.tofix.bean.AccessToTask;
+import org.openstreetmap.josm.plugins.tofix.bean.FixedBean;
import org.openstreetmap.josm.plugins.tofix.bean.ListTaskBean;
import org.openstreetmap.josm.plugins.tofix.bean.TrackBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.Item;
import org.openstreetmap.josm.plugins.tofix.controller.ItemController;
-import org.openstreetmap.josm.plugins.tofix.controller.ItemEditController;
-import org.openstreetmap.josm.plugins.tofix.controller.ItemFixedController;
-import org.openstreetmap.josm.plugins.tofix.controller.ItemSkipController;
+import org.openstreetmap.josm.plugins.tofix.controller.ItemTrackController;
import org.openstreetmap.josm.plugins.tofix.controller.ListTaskController;
-import org.openstreetmap.josm.plugins.tofix.layer.TofixLayer;
import org.openstreetmap.josm.plugins.tofix.util.*;
-import org.openstreetmap.josm.tools.Geometry;
+import org.openstreetmap.josm.plugins.tofix.util.Config;
import static org.openstreetmap.josm.tools.I18n.tr;
import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.OpenBrowser;
import org.openstreetmap.josm.tools.Shortcut;
/**
@@ -55,36 +50,49 @@ public class TofixDialog extends ToggleDialog implements ActionListener {
// private final SideButton editButton;
private final SideButton skipButton;
private final SideButton fixedButton;
+ private final SideButton noterrorButton;
+ private Shortcut skipShortcut = null;
+ private Shortcut fixedShortcut = null;
+ private Shortcut noterrorButtonShortcut = null;
+ JSlider slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 1);
- // To-Fix host
- AccessTaskBean accessTaskBean = null;
+ //size to download
+ double zise = 0.001; //per default
+
+ AccessToTask mainAccessToTask = null;
// Task list
ListTaskBean listTaskBean = null;
ListTaskController listTaskController = new ListTaskController();
+ //Item
+ Item item = new Item();
ItemController itemController = new ItemController();
- Bounds bounds = null;
- DownloadOsmTask downloadOsmTask = new DownloadOsmTask();
-
// To-Fix layer
MapView mv = Main.map.mapView;
- TofixLayer tofixLayer = new TofixLayer("Tofix-layer");
- JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- JPanel jcontenpanel = new JPanel(new GridLayout(1, 0));
+ ItemTrackController itemTrackController = new ItemTrackController();
+
+ JTabbedPane TabbedPanel = new javax.swing.JTabbedPane();
+
+ JPanel jcontenTasks = new JPanel(new GridLayout(2, 1));
+ JPanel valuePanel = new JPanel(new GridLayout(1, 1));
+
+ JPanel jcontenConfig = new JPanel(new GridLayout(2, 1));
+ JPanel panelslide = new JPanel(new GridLayout(1, 1));
JosmUserIdentityManager josmUserIdentityManager = JosmUserIdentityManager.getInstance();
+ TofixTask tofixTask = new TofixTask();
+ UploadAction upload = new UploadAction();
+
public TofixDialog() {
super(tr("To-fix"), "icontofix", tr("Open to-fix window."),
- Shortcut.registerShortcut("tool:to-fix", tr("Toggle: {0}", tr("To-fix")),
- KeyEvent.VK_F, Shortcut.CTRL_SHIFT), 75);
-
- // Request data
- accessTaskBean = new AccessTaskBean("mixedlayer", "keepright", false);
+ Shortcut.registerShortcut("Tool:To-fix", tr("Toggle: {0}", tr("Tool:To-fix")),
+ KeyEvent.VK_T, Shortcut.ALT_CTRL_SHIFT), 170);
+ // "Skip" button
skipButton = new SideButton(new AbstractAction() {
{
putValue(NAME, tr("Skip"));
@@ -95,10 +103,10 @@ public TofixDialog() {
@Override
public void actionPerformed(ActionEvent e) {
skip();
- get_new_item();
}
});
skipButton.setEnabled(false);
+
// "Fixed" button
fixedButton = new SideButton(new AbstractAction() {
{
@@ -109,37 +117,136 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
+ upload.setCustomized_comment("#to-fix:"+mainAccessToTask.getTask_id());
+ upload.actionPerformed(e);
fixed();
}
});
+
fixedButton.setEnabled(false);
- // Panels
- valuePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jcontenpanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+
+ // "Not a error" button
+ noterrorButton = new SideButton(new AbstractAction() {
+ {
+ putValue(NAME, tr("Not an error"));
+ putValue(SMALL_ICON, ImageProvider.get("mapmode", "noterror.png"));
+ putValue(SHORT_DESCRIPTION, tr("Not an error"));
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ noterror();
+ }
+ });
+
+ noterrorButton.setEnabled(false);
+
+ //add tittle for To-fix task
+ JLabel title_tasks = new javax.swing.JLabel();
+ title_tasks.setText("List of To-fix tasks:");
+ title_tasks.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ title_tasks.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ OpenBrowser.displayUrl(Config.url_tofix);
+ }
+ });
+ jcontenTasks.add(title_tasks);
+
// JComboBox for each task
ArrayList tasksList = new ArrayList();
tasksList.add("Select a task ...");
+
if (Status.isInternetReachable()) { //checkout internet connection
listTaskBean = listTaskController.getListTasksBean();
for (int i = 0; i < listTaskBean.getTasks().size(); i++) {
tasksList.add(listTaskBean.getTasks().get(i).getTitle());
}
+ JComboBox jcomboBox = new JComboBox(tasksList.toArray());
+ valuePanel.add(jcomboBox);
+ jcomboBox.addActionListener(this);
+
+ jcontenTasks.add(valuePanel);
+
+ //add title to download
+ jcontenConfig.add(new Label(tr("Size to download in Sq.m")));
+
+ //Add Slider to download
+ slider.setMinorTickSpacing(2);
+ slider.setMajorTickSpacing(5);
+ slider.setPaintTicks(true);
+ slider.setPaintLabels(true);
+ //slider.setLabelTable((slider.createStandardLabels(1)));
+ Hashtable table = new Hashtable();
+ table.put(1, new JLabel(tr("~.02")));
+ table.put(3, new JLabel("~.20"));
+ table.put(5, new JLabel("~.40"));
+ slider.setLabelTable(table);
+
+ slider.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ zise = (slider.getValue() * 0.001);
+ }
+ });
+ panelslide.add(slider);
+ jcontenConfig.add(panelslide);
+
+ //PANEL TASKS
+ valuePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+ //jcontenTasks.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+ panelslide.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+
+ TabbedPanel.addTab("Tasks", jcontenTasks);
+ TabbedPanel.addTab("Config", jcontenConfig);
+
+ //add panels in JOSM
+ createLayout(TabbedPanel, false, Arrays.asList(new SideButton[]{
+ skipButton, noterrorButton, fixedButton
+ }));
+
+ if (!Status.server()) {
+ jcomboBox.setEnabled(false);
+ skipButton.setEnabled(false);
+ fixedButton.setEnabled(false);
+ noterrorButton.setEnabled(false);
+ } else {
+ // Request data
+ mainAccessToTask = new AccessToTask("mixedlayer", "keepright", false);//start mixedlayer task by default
+ //Shortcuts
+ skipShortcut = Shortcut.registerShortcut("tofix:skip", tr("tofix:Skip item"), KeyEvent.VK_S, Shortcut.ALT_SHIFT);
+ Main.registerActionShortcut(new Skip_key_Action(), skipShortcut);
+
+ fixedShortcut = Shortcut.registerShortcut("tofix:fixed", tr("tofix:Fixed item"), KeyEvent.VK_F, Shortcut.ALT_SHIFT);
+ Main.registerActionShortcut(new Fixed_key_Action(), fixedShortcut);
+ noterrorButtonShortcut = Shortcut.registerShortcut("tofix:noterror", tr("tofix:Not a Error item"), KeyEvent.VK_N, Shortcut.ALT_SHIFT);
+ Main.registerActionShortcut(new NotError_key_Action(), noterrorButtonShortcut);
+ }
}
+ }
- JComboBox jcomboBox = new JComboBox(tasksList.toArray());
+ public class Skip_key_Action extends AbstractAction {
- valuePanel.add(jcomboBox);
- jcomboBox.addActionListener(this);
- createLayout(jcontenpanel, false, Arrays.asList(new SideButton[]{
- skipButton, fixedButton
- }));
- jcontenpanel.add(valuePanel);
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ skip();
+ }
+ }
- if (!Status.server()) {
- jcomboBox.setEnabled(false);
- skipButton.setEnabled(false);
- fixedButton.setEnabled(false);
+ public class Fixed_key_Action extends AbstractAction {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ upload.actionPerformed(e);
+ fixed();
+ }
+ }
+
+ public class NotError_key_Action extends AbstractAction {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ noterror();
}
}
@@ -147,161 +254,88 @@ public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
if (cb.getSelectedIndex() != 0) {
- accessTaskBean.setTask(listTaskBean.getTasks().get(cb.getSelectedIndex() - 1).getId());
- accessTaskBean.setTask_source(listTaskBean.getTasks().get(cb.getSelectedIndex() - 1).getSource());
+ mainAccessToTask.setTask_name(listTaskBean.getTasks().get(cb.getSelectedIndex() - 1).getTitle());
+ mainAccessToTask.setTask_id(listTaskBean.getTasks().get(cb.getSelectedIndex() - 1).getId());
+ mainAccessToTask.setTask_source(listTaskBean.getTasks().get(cb.getSelectedIndex() - 1).getSource());
get_new_item();
skipButton.setEnabled(true);
fixedButton.setEnabled(true);
+ noterrorButton.setEnabled(true);
} else {
skipButton.setEnabled(false);
fixedButton.setEnabled(false);
+ noterrorButton.setEnabled(false);
}
}
public void edit() {
- if (accessTaskBean.isAccess()) {
- Download.Download(downloadOsmTask, bounds, accessTaskBean.getOsm_obj_id());
+ if (mainAccessToTask.isAccess()) {
TrackBean trackBean = new TrackBean();
- AttributesBean attributesBean = new AttributesBean();
- attributesBean.setAction("edit");
- attributesBean.setEditor("josm");
- attributesBean.setUser(josmUserIdentityManager.getUserName());
- attributesBean.setKey(accessTaskBean.getKey());
- trackBean.setAttributes(attributesBean);
- ItemEditController itemEditController = new ItemEditController(accessTaskBean.getTrack_url(), trackBean);
- itemEditController.sendTrackBean();
+ trackBean.getAttributes().setAction("edit");
+ trackBean.getAttributes().setEditor("josm");
+ trackBean.getAttributes().setUser(josmUserIdentityManager.getUserName());
+ trackBean.getAttributes().setKey(mainAccessToTask.getKey());
+ itemTrackController.send_track_edit(mainAccessToTask.getTrack_url(), trackBean);
}
}
public void skip() {
- if (accessTaskBean.isAccess()) {
+ if (mainAccessToTask.isAccess()) {
TrackBean trackBean = new TrackBean();
- AttributesBean attributesBean = new AttributesBean();
- attributesBean.setAction("skip");
- attributesBean.setEditor("josm");
- attributesBean.setUser(josmUserIdentityManager.getUserName());
- attributesBean.setKey(accessTaskBean.getKey());
- trackBean.setAttributes(attributesBean);
- ItemSkipController skipController = new ItemSkipController(accessTaskBean.getTrack_url(), trackBean);
- skipController.sendTrackBean();
+ trackBean.getAttributes().setAction("skip");
+ trackBean.getAttributes().setEditor("josm");
+ trackBean.getAttributes().setUser(josmUserIdentityManager.getUserName());
+ trackBean.getAttributes().setKey(mainAccessToTask.getKey());
+ itemTrackController.send_track_skip(mainAccessToTask.getTrack_url(), trackBean);
}
get_new_item();
-
}
public void fixed() {
- if (accessTaskBean.isAccess()) {
- ItemFixedBean itemFixedBean = new ItemFixedBean();
- itemFixedBean.setUser(josmUserIdentityManager.getUserName());
- itemFixedBean.setKey(accessTaskBean.getKey());
- //itemFixedBean.setEditor("josm");
- ItemFixedController itemFixedController = new ItemFixedController(accessTaskBean.getFixed_url(), itemFixedBean);
- itemFixedController.sendTrackBean();
+ if (mainAccessToTask.isAccess()) {
+ FixedBean fixedBean = new FixedBean();
+ fixedBean.setUser(josmUserIdentityManager.getUserName());
+ fixedBean.setKey(mainAccessToTask.getKey());
+ itemTrackController.send_track_fix(mainAccessToTask.getFixed_url(), fixedBean);
}
get_new_item();
}
- private void get_new_item() {
- if (accessTaskBean.getTask_source().equals("keepright")) {
- get_item_keepright();
- edit();
- }
+ public void noterror() {
+ if (mainAccessToTask.isAccess()) {
- if (accessTaskBean.getTask_source().equals("unconnected")) {
- if (accessTaskBean.getTask().equals("unconnected_minor1")) {
- JOptionPane.showConfirmDialog(Main.panel, "Not implemented yet");
- } else {
- get_item_unconnected();
- edit();
- }
- }
- if (accessTaskBean.getTask_source().equals("tigerdelta")) {
- get_item_tigerdelta();
- edit();
- }
+ FixedBean NoterrorBean = new FixedBean();
+ NoterrorBean.setUser(josmUserIdentityManager.getUserName());
+ NoterrorBean.setKey(mainAccessToTask.getKey());
+ itemTrackController.send_track_noterror(mainAccessToTask.getNoterror_url(), NoterrorBean);
- if (accessTaskBean.getTask_source().equals("nycbuildings")) {
- get_item_nycbuildings();
- edit();
- }
- }
-
- private void get_item_keepright() {
- ItemKeeprightBean itemKeeprightBean = null;
- itemController.setUrl(accessTaskBean.getTask_url());
- itemKeeprightBean = itemController.getItemKeeprightBean();
- Util.print(itemKeeprightBean.getKey());
- if (itemKeeprightBean != null) {
- accessTaskBean.setAccess(true);
- accessTaskBean.setOsm_obj_id(itemKeeprightBean.getValue().getObject_id());
- accessTaskBean.setKey(itemKeeprightBean.getKey());
- LatLon latLon = Util.format_St_astext_Keepright(itemKeeprightBean.getValue().getSt_astext());
- bounds = new Bounds(latLon.toBBox(0.0007).toRectangle());
-
- TofixDraw.draw_Node(tofixLayer, latLon);
- } else {
- accessTaskBean.setAccess(false);
- JOptionPane.showMessageDialog(Main.parent, "Something went wrong on Server!, Please change the Task or try to again");
- }
- }
-
- private void get_item_unconnected() {
- ItemUnconnectedBean itemUnconnectedBean = null;
- itemController.setUrl(accessTaskBean.getTask_url());
- itemUnconnectedBean = itemController.getItemBean();
- if (itemUnconnectedBean != null) {
- accessTaskBean.setAccess(true);
- accessTaskBean.setOsm_obj_id(itemUnconnectedBean.getValue().getNode_id());
- accessTaskBean.setKey(itemUnconnectedBean.getKey());
- // itemUnconnectedBean.
- //Util.print(itemUnconnectedBean.getValue().getY()+" o "+itemUnconnectedBean.getValue().getX());
- LatLon latLon = new LatLon(itemUnconnectedBean.getValue().getY(), itemUnconnectedBean.getValue().getX());
- bounds = new Bounds(latLon.toBBox(0.0007).toRectangle());
- TofixDraw.draw_Node(tofixLayer, latLon);
- } else {
- accessTaskBean.setAccess(false);
- JOptionPane.showMessageDialog(Main.parent, "Something went wrong on Server!, Please change the Task or try to again");
}
+ get_new_item();
}
- private void get_item_nycbuildings() {
- ItemNycbuildingsBean itemNycbuildingsBean = null;
- itemController.setUrl(accessTaskBean.getTask_url());
- itemNycbuildingsBean = itemController.getItemNycbuildingsBean();
- Util.print(accessTaskBean.getTask_url());
- if (itemNycbuildingsBean != null) {
- accessTaskBean.setAccess(true);
- accessTaskBean.setOsm_obj_id(Util.format_Elems_Nycbuildings(itemNycbuildingsBean.getValue().getElems()));
- accessTaskBean.setKey(itemNycbuildingsBean.getKey());
- LatLon latLon = new LatLon(itemNycbuildingsBean.getValue().getLat(), itemNycbuildingsBean.getValue().getLon());
- Util.print(latLon);
- bounds = new Bounds(latLon.toBBox(0.0007).toRectangle());
- TofixDraw.draw_Node(tofixLayer, latLon);
- } else {
- accessTaskBean.setAccess(false);
- JOptionPane.showMessageDialog(Main.parent, "Something went wrong on Server!, Please change the Task or try to again");
+ private void get_new_item() {
+ item.setStatus(0);
+ itemController.setAccessToTask(mainAccessToTask);
+ item = itemController.getItem();
+ switch (item.getStatus()) {
+ case 200:
+ mainAccessToTask.setAccess(true);
+ mainAccessToTask = tofixTask.work(item, mainAccessToTask, zise);
+ edit();
+ break;
+ case 410:
+ mainAccessToTask.setAccess(false);
+ tofixTask.task_complete(item, mainAccessToTask);
+ break;
+ case 503:
+ mainAccessToTask.setAccess(false);
+ JOptionPane.showMessageDialog(Main.panel, tr("Maintenance server"));
+ break;
+
+ default:
+ mainAccessToTask.setAccess(false);
+ JOptionPane.showMessageDialog(Main.panel, tr("Somethig went wrong, try to again"));
}
-
}
- private void get_item_tigerdelta() {
- ItemTigerdeltaBean itemTigerdeltaBean = null;
- itemController.setUrl(accessTaskBean.getTask_url());
- itemTigerdeltaBean = itemController.getItemTigerdeltaBean();
- Util.print(accessTaskBean.getTask_url());
- if (itemTigerdeltaBean != null) {
- accessTaskBean.setAccess(true);
- accessTaskBean.setOsm_obj_id(itemTigerdeltaBean.getValue().getWay());
- accessTaskBean.setKey(itemTigerdeltaBean.getKey());
- List> list = Util.format_st_astext_Tigerdelta(itemTigerdeltaBean.getValue().getSt_astext());
- LatLon latLon = new LatLon(list.get(0).get(0).getCoor().lat(), list.get(0).get(0).getCoor().lon());// Util.print(latLon);
- bounds = new Bounds(latLon.toBBox(0.001).toRectangle());
- TofixDraw.draw_line(tofixLayer, latLon, list);
-
- } else {
- accessTaskBean.setAccess(false);
- JOptionPane.showMessageDialog(Main.parent, "Something went wrong on Server!, Please change the Task or try to again");
- }
-
- }
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/TofixDraw.java b/src/org/openstreetmap/josm/plugins/tofix/TofixDraw.java
index 26710b5..6010394 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/TofixDraw.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/TofixDraw.java
@@ -8,7 +8,7 @@
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemUnconnectedBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemUnconnectedBean;
import org.openstreetmap.josm.plugins.tofix.layer.TofixLayer;
import static org.openstreetmap.josm.tools.I18n.tr;
@@ -16,6 +16,7 @@
*
* @author ruben
*/
+
public class TofixDraw {
ItemUnconnectedBean itemBean = null;
@@ -28,8 +29,7 @@ public static void draw_Node(final TofixLayer tofixLayer, LatLon latLon) {
return;
}
BoundingXYVisitor v = new BoundingXYVisitor();
- //double ex = 0.0001; = 2.34 m
- //double ex = 0.0007;// 16.7 m
+
v.visit(new Bounds(latLon.toBBox(0.0007).toRectangle()));
Main.map.mapView.zoomTo(v);
if (!Main.map.mapView.hasLayer(tofixLayer)) {
@@ -48,8 +48,6 @@ public static void draw_line(final TofixLayer tofixLayer, LatLon latLon, List list_nodes) {
+ MapView mv = Main.map.mapView;
+ Bounds bounds = null;
+ if (latLon.isOutSideWorld()) {
+ JOptionPane.showMessageDialog(Main.parent, tr("Can not find outside of the world."));
+ return;
+ }
+ BoundingXYVisitor v = new BoundingXYVisitor();
+ v.visit(new Bounds(latLon.toBBox(0.0007).toRectangle()));
+ Main.map.mapView.zoomTo(v);
+ if (!Main.map.mapView.hasLayer(tofixLayer)) {
+ mv.addLayer(tofixLayer);
+ tofixLayer.add_Nodes(list_nodes);
+ } else {
+ tofixLayer.add_Nodes(list_nodes);
+ }
+ }
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/TofixMode.java b/src/org/openstreetmap/josm/plugins/tofix/TofixMode.java
deleted file mode 100644
index b1977cb..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/TofixMode.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix;
-
-import java.awt.Cursor;
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.gui.MapFrame;
-
-/**
- *
- * @author ruben
- */
-public class TofixMode extends MapMode {
-
- public TofixMode(MapFrame mapFrame, String name, String desc) {
- super(name, "icontofix.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- }
-
- @Override
- public void enterMode() {
- super.enterMode();
- Main.map.mapView.addMouseListener(this);
- }
-
- @Override
- public void exitMode() {
- super.exitMode();
- Main.map.mapView.removeMouseListener(this);
- }
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/TofixPlugin.java b/src/org/openstreetmap/josm/plugins/tofix/TofixPlugin.java
index 6ff228e..21f9cd0 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/TofixPlugin.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/TofixPlugin.java
@@ -9,8 +9,7 @@ public class TofixPlugin extends Plugin {
private IconToggleButton btn;
protected static TofixDialog tofixDialog;
- private TofixMode mode;
-
+
public TofixPlugin(PluginInformation info) {
super(info);
}
@@ -19,18 +18,6 @@ public TofixPlugin(PluginInformation info) {
public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
if (newFrame != null) {
newFrame.addToggleDialog(tofixDialog = new TofixDialog());
- //mode = new TofixMode(newFrame, "To-Fix", tr("To-fix mode"));
-// btn = new IconToggleButton(mode);
-// btn.setVisible(true);
-// newFrame.addMapMode(btn);
-
}
-// else {
-// btn = null;
-// mode = null;
-// tofixDialog = null;
-// //Rub21
-// }
-
}
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/TofixTask.java b/src/org/openstreetmap/josm/plugins/tofix/TofixTask.java
new file mode 100644
index 0000000..3762bdb
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/TofixTask.java
@@ -0,0 +1,138 @@
+package org.openstreetmap.josm.plugins.tofix;
+
+import java.util.List;
+import javax.swing.JOptionPane;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
+import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.gui.io.UploadDialog;
+import org.openstreetmap.josm.plugins.tofix.bean.AccessToTask;
+import org.openstreetmap.josm.plugins.tofix.bean.items.Item;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemKeeprightBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemKrakatoaBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemNycbuildingsBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemSmallcomponents;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemStrava;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemTigerdeltaBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemUnconnectedBean;
+import org.openstreetmap.josm.plugins.tofix.controller.ItemController;
+import org.openstreetmap.josm.plugins.tofix.layer.TofixLayer;
+import org.openstreetmap.josm.plugins.tofix.util.Download;
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+/**
+ *
+ * @author ruben
+ */
+public class TofixTask {
+
+ ItemController itemController = new ItemController();
+ Bounds bounds = null;
+ DownloadOsmTask downloadOsmTask = new DownloadOsmTask();
+ Node node = null;
+ TofixLayer tofixLayer = new TofixLayer("Tofix-layer");
+
+ public AccessToTask work(Item item, AccessToTask accessToTask, double size) { //size to download
+
+ if (accessToTask.getTask_source().equals("unconnected")) {
+ accessToTask = work_unconnected(item.getItemUnconnectedBean(), accessToTask, size);
+ }
+ if (accessToTask.getTask_source().equals("keepright")) {
+ accessToTask = work_keepright(item.getItemKeeprightBean(), accessToTask, size);
+ }
+ if (accessToTask.getTask_source().equals("tigerdelta")) {
+ accessToTask = work_tigerdelta(item.getItemTigerdeltaBean(), accessToTask, size);
+ }
+ if (accessToTask.getTask_source().equals("nycbuildings")) {
+ accessToTask = work_nycbuildings(item.getItemNycbuildingsBean(), accessToTask, size);
+ }
+ if (accessToTask.getTask_source().equals("krakatoa")) {
+ accessToTask = work_krakatoa(item.getItemKrakatoaBean(), accessToTask, size);
+ }
+ if (accessToTask.getTask_source().equals("strava")) {
+ accessToTask = work_strava(item.getItemStrava(), accessToTask, size);
+ }
+ if (accessToTask.getTask_source().equals("components")) {
+ accessToTask = work_smallcomponents(item.getItemSmallcomponents(), accessToTask, size);
+ }
+
+ UploadDialog.getUploadDialog().getChangeset().getCommentsCount();
+ return accessToTask;
+ }
+
+ private AccessToTask work_unconnected(ItemUnconnectedBean itemUnconnectedBean, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemUnconnectedBean.getKey());
+ node = itemUnconnectedBean.getValue().get_node();
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_Node(tofixLayer, node.getCoor());
+ Download.Download(downloadOsmTask, bounds, itemUnconnectedBean.getValue().getNode_id());
+ return accessToTask;
+ }
+
+ private AccessToTask work_keepright(ItemKeeprightBean itemKeeprightBean, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemKeeprightBean.getKey());
+ node = itemKeeprightBean.getValue().get_node();
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_Node(tofixLayer, node.getCoor());
+ Download.Download(downloadOsmTask, bounds, itemKeeprightBean.getValue().getObject_id());
+ return accessToTask;
+
+ }
+
+ private AccessToTask work_nycbuildings(ItemNycbuildingsBean itemNycbuildingsBean, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemNycbuildingsBean.getKey());
+ node = itemNycbuildingsBean.getValue().get_node();
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_Node(tofixLayer, node.getCoor());
+ Download.Download(downloadOsmTask, bounds, itemNycbuildingsBean.getValue().osm_obj_id());
+ return accessToTask;
+ }
+
+ private AccessToTask work_tigerdelta(ItemTigerdeltaBean itemTigerdeltaBean, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemTigerdeltaBean.getKey());
+ List> list = itemTigerdeltaBean.getValue().get_nodes();
+ node = new Node(new LatLon(list.get(0).get(0).getCoor().lat(), list.get(0).get(0).getCoor().lon()));
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_line(tofixLayer, node.getCoor(), list);
+ Download.Download(downloadOsmTask, bounds, 0x0L);//0x0L = null porque no exixte el id del objeto
+ return accessToTask;
+ }
+
+ private AccessToTask work_krakatoa(ItemKrakatoaBean itemkrakatoaBean, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemkrakatoaBean.getKey());
+ List list = itemkrakatoaBean.getValue().get_nodes();
+ node = new Node(new LatLon(list.get(0).getCoor().lat(), list.get(0).getCoor().lon()));
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_nodes(tofixLayer, node.getCoor(), list);
+ Download.Download(downloadOsmTask, bounds, 0x0L);//0x0L = null porque no exixte el id del objeto
+ return accessToTask;
+ }
+
+ private AccessToTask work_strava(ItemStrava itemStrava, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemStrava.getKey());
+ node = itemStrava.getValue().get_node();
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_Node(tofixLayer, node.getCoor());
+ Download.Download(downloadOsmTask, bounds, 0x0L);
+ return accessToTask;
+ }
+
+ private AccessToTask work_smallcomponents(ItemSmallcomponents itemSmallcomponents, AccessToTask accessToTask, double size) {
+ accessToTask.setKey(itemSmallcomponents.getKey());
+ List> list = itemSmallcomponents.getValue().get_nodes();
+ node = new Node(new LatLon(list.get(0).get(0).getCoor().lat(), list.get(0).get(0).getCoor().lon()));
+ bounds = new Bounds(node.getCoor().toBBox(size).toRectangle());
+ TofixDraw.draw_line(tofixLayer, node.getCoor(), list);
+ Download.Download(downloadOsmTask, bounds, 0x0L);//0x0L = null porque no exixte el id del objeto
+ return accessToTask;
+ }
+
+ public void task_complete(Item item, AccessToTask accessToTask) {
+ String message = "Task : " + accessToTask.getTask_name() + " was completed\n"
+ + "Total items : " + item.getTaskCompleteBean().getMessage().getValue().getTotal();
+ JOptionPane.showMessageDialog(Main.panel, tr(message));
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/AccessTaskBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/AccessToTask.java
similarity index 57%
rename from src/org/openstreetmap/josm/plugins/tofix/bean/AccessTaskBean.java
rename to src/org/openstreetmap/josm/plugins/tofix/bean/AccessToTask.java
index bddef6c..5652766 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/AccessTaskBean.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/AccessToTask.java
@@ -1,20 +1,23 @@
package org.openstreetmap.josm.plugins.tofix.bean;
+import org.openstreetmap.josm.plugins.tofix.util.Config;
+
/**
*
* @author ruben
*/
-public class AccessTaskBean {
+public class AccessToTask {
- private String host = "http://54.147.184.23:8000";
- private String task;
+ private String host = Config.host;
+ private String task_id;
private String task_source;
+ private String task_name;
private boolean access;
private Long osm_obj_id;
private String key;
- public AccessTaskBean(String task, String task_source, boolean access) {
- this.task = task;
+ public AccessToTask(String task_id, String task_source, boolean access) {
+ this.task_id = task_id;
this.task_source = task_source;
this.access = access;
}
@@ -28,16 +31,16 @@ public void setHost(String host) {
}
public String getTask_url() {
- String url = this.getHost() + "/task/" + this.getTask();
+ String url = this.getHost() + "task/" + this.getTask_id();
return url;
}
- public String getTask() {
- return task;
+ public String getTask_id() {
+ return task_id;
}
- public void setTask(String task) {
- this.task = task;
+ public void setTask_id(String task) {
+ this.task_id = task;
}
public String getTask_source() {
@@ -57,11 +60,15 @@ public void setAccess(boolean access) {
}
public String getTrack_url() {
- return getHost() + "/track/" + getTask();
+ return getHost() + "track/" + getTask_id();
}
public String getFixed_url() {
- return getHost() + "/fixed/" + getTask();
+ return getHost() + "fixed/" + getTask_id();
+ }
+
+ public String getNoterror_url() {
+ return getHost() + "noterror/" + getTask_id();
}
public Long getOsm_obj_id() {
@@ -79,7 +86,13 @@ public String getKey() {
public void setKey(String key) {
this.key = key;
}
-
-
+
+ public String getTask_name() {
+ return task_name;
+ }
+
+ public void setTask_name(String task_name) {
+ this.task_name = task_name;
+ }
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/AttributesBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/AttributesBean.java
deleted file mode 100644
index dd677ac..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/AttributesBean.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class AttributesBean {
-
- String user;
- String action;
- String key;
- String editor;
-
- public String getUser() {
- return user;
- }
-
- public void setUser(String user) {
- this.user = user;
- }
-
- public String getAction() {
- return action;
- }
-
- public void setAction(String action) {
- this.action = action;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getEditor() {
- return editor;
- }
-
- public void setEditor(String editor) {
- this.editor = editor;
- }
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemFixedBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/FixedBean.java
similarity index 93%
rename from src/org/openstreetmap/josm/plugins/tofix/bean/ItemFixedBean.java
rename to src/org/openstreetmap/josm/plugins/tofix/bean/FixedBean.java
index f40a931..741c908 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemFixedBean.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/FixedBean.java
@@ -4,7 +4,7 @@
*
* @author ruben
*/
-public class ItemFixedBean {
+public class FixedBean {
private String user;
private String key;
//private String editor;
@@ -24,6 +24,5 @@ public String getKey() {
public void setKey(String key) {
this.key = key;
}
-
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemKeeprightBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemKeeprightBean.java
deleted file mode 100644
index 67bcc75..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemKeeprightBean.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemKeeprightBean {
-
- private String key;
- private ItemKeeprightValueBean value;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public ItemKeeprightValueBean getValue() {
- return value;
- }
-
- public void setValue(ItemKeeprightValueBean value) {
- this.value = value;
- }
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemKeeprightValueBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemKeeprightValueBean.java
deleted file mode 100644
index b48822a..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemKeeprightValueBean.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemKeeprightValueBean {
- String object_type;
- Long object_id;
- String st_astext;
-
- public String getObject_type() {
- return object_type;
- }
-
- public void setObject_type(String object_type) {
- this.object_type = object_type;
- }
-
- public Long getObject_id() {
- return object_id;
- }
-
- public void setObject_id(Long object_id) {
- this.object_id = object_id;
- }
-
-
- public String getSt_astext() {
- return st_astext;
- }
-
- public void setSt_astext(String st_astext) {
- this.st_astext = st_astext;
- }
-
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemNycbuildingsBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemNycbuildingsBean.java
deleted file mode 100644
index 62fc295..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemNycbuildingsBean.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemNycbuildingsBean {
- private String key;
- private ItemNycbuildingsValueBean value;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public ItemNycbuildingsValueBean getValue() {
- return value;
- }
-
- public void setValue(ItemNycbuildingsValueBean value) {
- this.value = value;
- }
-
-}
-
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemNycbuildingsValueBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemNycbuildingsValueBean.java
deleted file mode 100644
index 256c742..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemNycbuildingsValueBean.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemNycbuildingsValueBean {
-
- private Double lat;
- private Double lon;
- private String elems;
-
- public Double getLat() {
- return lat;
- }
-
- public void setLat(Double lat) {
- this.lat = lat;
- }
-
- public Double getLon() {
- return lon;
- }
-
- public void setLon(Double lon) {
- this.lon = lon;
- }
-
- public String getElems() {
- return elems;
- }
-
- public void setElems(String elems) {
- this.elems = elems;
- }
-
-
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemTigerdeltaBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemTigerdeltaBean.java
deleted file mode 100644
index 7f72d6e..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemTigerdeltaBean.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemTigerdeltaBean {
-
- private String key;
- private ItemTigerdeltaValueBean value;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public ItemTigerdeltaValueBean getValue() {
- return value;
- }
-
- public void setValue(ItemTigerdeltaValueBean value) {
- this.value = value;
- }
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemTigerdeltaValueBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemTigerdeltaValueBean.java
deleted file mode 100644
index 5793c22..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemTigerdeltaValueBean.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemTigerdeltaValueBean {
-
- private String name;
- private Long way;
- private String st_astext;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Long getWay() {
- return way;
- }
-
- public void setWay(Long way) {
- this.way = way;
- }
-
- public String getSt_astext() {
- return st_astext;
- }
-
- public void setSt_astext(String st_astext) {
- this.st_astext = st_astext;
- }
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemUnconnectedBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemUnconnectedBean.java
deleted file mode 100644
index 8fac5d0..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemUnconnectedBean.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemUnconnectedBean {
- private String key;
- private ItemUnconnectedValueBean value;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public ItemUnconnectedValueBean getValue() {
- return value;
- }
-
- public void setValue(ItemUnconnectedValueBean value) {
- this.value = value;
- }
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemUnconnectedValueBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ItemUnconnectedValueBean.java
deleted file mode 100644
index 3c21f4d..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/ItemUnconnectedValueBean.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.bean;
-
-/**
- *
- * @author ruben
- */
-public class ItemUnconnectedValueBean {
-
- Double X;
- Double Y;
- Float weight;
- Integer problem_id;
- Long way_id;
- Long node_id;
- String highwaykey;
- Double distance;
- String iso_a2;
-
- public Double getX() {
- return X;
- }
-
- public void setX(Double X) {
- this.X = X;
- }
-
- public Double getY() {
- return Y;
- }
-
- public void setY(Double Y) {
- this.Y = Y;
- }
-
- public Float getWeight() {
- return weight;
- }
-
- public void setWeight(Float weight) {
- this.weight = weight;
- }
-
- public Integer getProblem_id() {
- return problem_id;
- }
-
- public void setProblem_id(Integer problem_id) {
- this.problem_id = problem_id;
- }
-
- public Long getWay_id() {
- return way_id;
- }
-
- public void setWay_id(Long way_id) {
- this.way_id = way_id;
- }
-
- public Long getNode_id() {
- return node_id;
- }
-
- public void setNode_id(Long node_id) {
- this.node_id = node_id;
- }
-
- public String getHighwaykey() {
- return highwaykey;
- }
-
- public void setHighwaykey(String highwaykey) {
- this.highwaykey = highwaykey;
- }
-
- public Double getDistance() {
- return distance;
- }
-
- public void setDistance(Double distance) {
- this.distance = distance;
- }
-
- public String getIso_a2() {
- return iso_a2;
- }
-
- public void setIso_a2(String iso_a2) {
- this.iso_a2 = iso_a2;
- }
-
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/ResponseBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/ResponseBean.java
new file mode 100644
index 0000000..6075686
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/ResponseBean.java
@@ -0,0 +1,30 @@
+package org.openstreetmap.josm.plugins.tofix.bean;
+
+/**
+ *
+ *
+ * @author ruben
+ */
+public class ResponseBean {
+
+ private int status;
+ private String value;//String from server response
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/TaskCompleteBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/TaskCompleteBean.java
new file mode 100644
index 0000000..e9bd73f
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/TaskCompleteBean.java
@@ -0,0 +1,102 @@
+package org.openstreetmap.josm.plugins.tofix.bean;
+
+/**
+ *
+ * @author ruben
+ */
+public class TaskCompleteBean {
+
+ int statusCode;
+ String error;
+ Message message;
+
+ public class Message {
+
+ String key;
+ Value value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ }
+
+ public class Value {
+
+ int skip;
+ int noterror;
+ int fix;
+ int total;
+
+ public int getSkip() {
+ return skip;
+ }
+
+ public void setSkip(int skip) {
+ this.skip = skip;
+ }
+
+ public int getNoterror() {
+ return noterror;
+ }
+
+ public void setNoterror(int noterror) {
+ this.noterror = noterror;
+ }
+
+ public int getFix() {
+ return fix;
+ }
+
+ public void setFix(int fix) {
+ this.fix = fix;
+ }
+
+ public int getTotal() {
+ return total;
+ }
+
+ public void setTotal(int total) {
+ this.total = total;
+ }
+
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/TrackBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/TrackBean.java
index 73a29a2..5c8e1d5 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/bean/TrackBean.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/TrackBean.java
@@ -5,8 +5,8 @@
* @author ruben
*/
public class TrackBean {
-
- AttributesBean attributes;
+
+ AttributesBean attributes = new AttributesBean();
public AttributesBean getAttributes() {
return attributes;
@@ -15,5 +15,47 @@ public AttributesBean getAttributes() {
public void setAttributes(AttributesBean attributes) {
this.attributes = attributes;
}
-
+
+ //Atributos
+ public class AttributesBean {
+
+ String user;
+ String action;
+ String key;
+ String editor;
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getEditor() {
+ return editor;
+ }
+
+ public void setEditor(String editor) {
+ this.editor = editor;
+ }
+
+ }
+
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/Item.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/Item.java
new file mode 100644
index 0000000..b85989d
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/Item.java
@@ -0,0 +1,93 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import org.openstreetmap.josm.plugins.tofix.bean.TaskCompleteBean;
+
+/**
+ *
+ * @author ruben
+ */
+public class Item {
+
+ private int status;
+ private ItemKeeprightBean itemKeeprightBean;
+ private ItemKrakatoaBean itemKrakatoaBean;
+ private ItemNycbuildingsBean itemNycbuildingsBean;
+ private ItemTigerdeltaBean itemTigerdeltaBean;
+ private ItemUnconnectedBean itemUnconnectedBean;
+ private TaskCompleteBean taskCompleteBean;
+ private ItemStrava itemStrava;
+ private ItemSmallcomponents itemSmallcomponents;
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public ItemKeeprightBean getItemKeeprightBean() {
+ return itemKeeprightBean;
+ }
+
+ public void setItemKeeprightBean(ItemKeeprightBean itemKeeprightBean) {
+ this.itemKeeprightBean = itemKeeprightBean;
+ }
+
+ public ItemKrakatoaBean getItemKrakatoaBean() {
+ return itemKrakatoaBean;
+ }
+
+ public void setItemKrakatoaBean(ItemKrakatoaBean itemKrakatoaBean) {
+ this.itemKrakatoaBean = itemKrakatoaBean;
+ }
+
+ public ItemNycbuildingsBean getItemNycbuildingsBean() {
+ return itemNycbuildingsBean;
+ }
+
+ public void setItemNycbuildingsBean(ItemNycbuildingsBean itemNycbuildingsBean) {
+ this.itemNycbuildingsBean = itemNycbuildingsBean;
+ }
+
+ public ItemTigerdeltaBean getItemTigerdeltaBean() {
+ return itemTigerdeltaBean;
+ }
+
+ public void setItemTigerdeltaBean(ItemTigerdeltaBean itemTigerdeltaBean) {
+ this.itemTigerdeltaBean = itemTigerdeltaBean;
+ }
+
+ public ItemUnconnectedBean getItemUnconnectedBean() {
+ return itemUnconnectedBean;
+ }
+
+ public void setItemUnconnectedBean(ItemUnconnectedBean itemUnconnectedBean) {
+ this.itemUnconnectedBean = itemUnconnectedBean;
+ }
+
+ public TaskCompleteBean getTaskCompleteBean() {
+ return taskCompleteBean;
+ }
+
+ public void setTaskCompleteBean(TaskCompleteBean taskCompleteBean) {
+ this.taskCompleteBean = taskCompleteBean;
+ }
+
+ public ItemStrava getItemStrava() {
+ return itemStrava;
+ }
+
+ public void setItemStrava(ItemStrava itemStrava) {
+ this.itemStrava = itemStrava;
+ }
+
+ public ItemSmallcomponents getItemSmallcomponents() {
+ return itemSmallcomponents;
+ }
+
+ public void setItemSmallcomponents(ItemSmallcomponents itemSmallcomponents) {
+ this.itemSmallcomponents = itemSmallcomponents;
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemKeeprightBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemKeeprightBean.java
new file mode 100644
index 0000000..0c98d60
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemKeeprightBean.java
@@ -0,0 +1,73 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import java.util.Arrays;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+
+/**
+ *
+ * @author ruben
+ */
+public class ItemKeeprightBean {
+
+ private String key;
+ private Value value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ public class Value {
+
+ String object_type;
+ Long object_id;
+ String st_astext;
+
+ public String getObject_type() {
+ return object_type;
+ }
+
+ public void setObject_type(String object_type) {
+ this.object_type = object_type;
+ }
+
+ public Long getObject_id() {
+ return object_id;
+ }
+
+ public void setObject_id(Long object_id) {
+ this.object_id = object_id;
+ }
+
+ public String getSt_astext() {
+ return st_astext;
+ }
+
+ public void setSt_astext(String st_astext) {
+ this.st_astext = st_astext;
+ }
+
+ public Node get_node() {
+ String str = getSt_astext().replaceAll("[^-?0-9.]+", " ");
+ Double lat = Double.parseDouble(Arrays.asList(str.trim().split(" ")).get(1));
+ Double lon = Double.parseDouble(Arrays.asList(str.trim().split(" ")).get(0));
+ LatLon coor = new LatLon(lat, lon);
+ Node node = new Node(coor);
+ return node;
+ }
+
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemKrakatoaBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemKrakatoaBean.java
new file mode 100644
index 0000000..042644c
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemKrakatoaBean.java
@@ -0,0 +1,74 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+
+/**
+ *
+ * @author ruben
+ */
+public class ItemKrakatoaBean {
+
+ private String key;
+ private Value value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ public class Value {
+
+ private String geom;
+
+ public String getGeom() {
+ return geom;
+ }
+
+ public void setGeom(String geom) {
+ this.geom = geom;
+ }
+
+ public List get_nodes() {
+ String geoString = getGeom();
+ List list = new LinkedList();
+ String multipoint = geoString.substring(0, 10);
+ if (multipoint.equalsIgnoreCase("MULTIPOINT")) {
+ geoString = geoString.replace("MULTIPOINT(", "").replace(")", "");
+ String[] arr = geoString.split(",");
+ for (int i = 0; i < arr.length; i++) {
+ String[] latlon = arr[i].split(" ");
+ LatLon latLon = new LatLon(Double.parseDouble(arr[i].split(" ")[1]), Double.parseDouble(arr[i].split(" ")[0]));
+ Node node = new Node(latLon);
+ list.add(node);
+ }
+ }
+ multipoint = geoString.substring(0, 5);
+ if (multipoint.equalsIgnoreCase("POINT")) {
+ geoString = geoString.replace("POINT(", "").replace(")", "");
+ String[] arr = geoString.split(",");
+ for (int i = 0; i < arr.length; i++) {
+ String[] latlon = arr[i].split(" ");
+ LatLon latLon = new LatLon(Double.parseDouble(arr[i].split(" ")[1]), Double.parseDouble(arr[i].split(" ")[0]));
+ Node node = new Node(latLon);
+ list.add(node);
+ }
+ }
+ return list;
+ }
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemNycbuildingsBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemNycbuildingsBean.java
new file mode 100644
index 0000000..8520822
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemNycbuildingsBean.java
@@ -0,0 +1,72 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+
+/**
+ *
+ * @author ruben
+ */
+public class ItemNycbuildingsBean {
+
+ private String key;
+ private Value value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ public class Value {
+
+ private Double lat;
+ private Double lon;
+ private String elems;
+
+ public Double getLat() {
+ return lat;
+ }
+
+ public void setLat(Double lat) {
+ this.lat = lat;
+ }
+
+ public Double getLon() {
+ return lon;
+ }
+
+ public void setLon(Double lon) {
+ this.lon = lon;
+ }
+
+ public String getElems() {
+ return elems;
+ }
+
+ public void setElems(String elems) {
+ this.elems = elems;
+ }
+
+ public Long osm_obj_id() {
+ String[] arr = getElems().replace("way", "").split("_");
+ return Long.valueOf(arr[0]);
+ }
+ public Node get_node(){
+ Node node = new Node(new LatLon(getLat(),getLon()));
+ return node;
+ }
+
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemSmallcomponents.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemSmallcomponents.java
new file mode 100644
index 0000000..1724517
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemSmallcomponents.java
@@ -0,0 +1,90 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+
+/**
+ *
+ * @author ruben
+ */
+public class ItemSmallcomponents {
+
+ private String key;
+ private Value value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ public class Value {
+
+ private String nothing;
+ private String geom;
+
+ public String getNothing() {
+ return nothing;
+ }
+
+ public void setNothing(String nothing) {
+ this.nothing = nothing;
+ }
+
+ public String getGeom() {
+ return geom;
+ }
+
+ public void setGeom(String geom) {
+ this.geom = geom;
+ }
+
+ public List> get_nodes() {
+ String geostring = getGeom();
+ geostring = geostring.replace("MULTILINESTRING (", "").replace("))", ")").replace(", ", ",");
+ geostring = geostring.replace("LINESTRING (", "(");
+ Double[][] cordinates;
+
+ List> list = new LinkedList>();
+ String[] array;
+ if (geostring.contains("), (")) {
+ geostring = geostring.replace(")", "").replace("(", "");
+ array = geostring.split(",\\(");
+ for (int i = 0; i < array.length; i++) {
+ List l = new LinkedList();
+ String[] a = array[i].split(",");
+ for (int j = 0; j < a.length; j++) {
+ LatLon latLon = new LatLon(Double.parseDouble(a[j].split(" ")[1]), Double.parseDouble(a[j].split(" ")[0]));
+ Node node = new Node(latLon);
+ l.add(node);
+ }
+ list.add(l);
+ }
+ } else {
+ geostring = geostring.replace(")", "").replace("(", "");
+ array = geostring.split(",");
+ List l = new LinkedList();
+ for (int i = 0; i < array.length; i++) {
+ LatLon latLon = new LatLon(Double.parseDouble(array[i].split(" ")[1]), Double.parseDouble(array[i].split(" ")[0]));
+ Node node = new Node(latLon);
+ l.add(node);
+ }
+ list.add(l);
+ }
+ return list;
+ }
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemStrava.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemStrava.java
new file mode 100644
index 0000000..8fbfa12
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemStrava.java
@@ -0,0 +1,48 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+
+public class ItemStrava {
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+ private Value value;
+
+ public class Value {
+
+ private String geom;
+
+ public String getGeom() {
+ return geom;
+ }
+
+ public void setGeom(String geom) {
+ this.geom = geom;
+ }
+
+ public Node get_node() {
+ String geoString = getGeom();
+ geoString = geoString.replace("POINT(", "").replace(")", "");
+ String[] array = geoString.split(" ");
+ LatLon latLon = new LatLon(Double.parseDouble(array[1]), Double.parseDouble(array[0]));
+ Node node = new Node(latLon);
+ return node;
+ }
+
+ }
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemTigerdeltaBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemTigerdeltaBean.java
new file mode 100644
index 0000000..df3e78d
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemTigerdeltaBean.java
@@ -0,0 +1,100 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+/**
+ *
+ * @author ruben
+ */
+public class ItemTigerdeltaBean {
+
+ private String key;
+ private Value value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ public class Value {
+
+ private String name;
+ private Long way;
+ private String geom;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Long getWay() {
+ return way;
+ }
+
+ public void setWay(Long way) {
+ this.way = way;
+ }
+
+ public String getSt_astext() {
+ return geom;
+ }
+
+ public void setSt_astext(String st_astext) {
+ this.geom = st_astext;
+ }
+
+ public List> get_nodes() {
+ String geostring = getSt_astext();
+ geostring = geostring.replace("MULTILINESTRING (", "").replace("))", ")").replace(", ", ",");
+ geostring = geostring.replace("LINESTRING (", "(");
+ Double[][] cordinates;
+
+ List> list = new LinkedList>();
+ String[] array;
+ if (geostring.contains("), (")) {
+ geostring = geostring.replace(")", "").replace("(", "");
+ array = geostring.split(",\\(");
+ for (int i = 0; i < array.length; i++) {
+ List l = new LinkedList();
+ String[] a = array[i].split(",");
+ for (int j = 0; j < a.length; j++) {
+ LatLon latLon = new LatLon(Double.parseDouble(a[j].split(" ")[1]), Double.parseDouble(a[j].split(" ")[0]));
+ Node node = new Node(latLon);
+ l.add(node);
+ }
+ list.add(l);
+ }
+ } else {
+ geostring = geostring.replace(")", "").replace("(", "");
+ array = geostring.split(",");
+ List l = new LinkedList();
+ for (int i = 0; i < array.length; i++) {
+ LatLon latLon = new LatLon(Double.parseDouble(array[i].split(" ")[1]), Double.parseDouble(array[i].split(" ")[0]));
+ Node node = new Node(latLon);
+ l.add(node);
+ }
+ list.add(l);
+
+ }
+ return list;
+ }
+
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemUnconnectedBean.java b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemUnconnectedBean.java
new file mode 100644
index 0000000..11bb82c
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/bean/items/ItemUnconnectedBean.java
@@ -0,0 +1,71 @@
+package org.openstreetmap.josm.plugins.tofix.bean.items;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+
+/**
+ *
+ * @author ruben
+ */
+public class ItemUnconnectedBean {
+
+ private String key;
+ private ItemUnconnectedValueBean value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public ItemUnconnectedValueBean getValue() {
+ return value;
+ }
+
+ public void setValue(ItemUnconnectedValueBean value) {
+ this.value = value;
+ }
+
+ public class ItemUnconnectedValueBean {
+
+ Long way_id;
+ Long node_id;
+ String st_astext;
+
+ public Long getWay_id() {
+ return way_id;
+ }
+
+ public void setWay_id(Long way_id) {
+ this.way_id = way_id;
+ }
+
+ public Long getNode_id() {
+ return node_id;
+ }
+
+ public void setNode_id(Long node_id) {
+ this.node_id = node_id;
+ }
+
+ public String getSt_astext() {
+ return st_astext;
+ }
+
+ public void setSt_astext(String st_astext) {
+ this.st_astext = st_astext;
+ }
+
+ public Node get_node() {
+ String geoString = getSt_astext();
+ geoString = geoString.replace("POINT(", "").replace(")", "");
+ String[] array = geoString.split(" ");
+ LatLon latLon = new LatLon(Double.parseDouble(array[1]), Double.parseDouble(array[0]));
+ Node node = new Node(latLon);
+ return node;
+ }
+
+ }
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemController.java
index 15cb7d5..d7dab6d 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemController.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemController.java
@@ -3,11 +3,17 @@
import com.google.gson.Gson;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.JOptionPane;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemUnconnectedBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemKeeprightBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemNycbuildingsBean;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemTigerdeltaBean;
+import org.openstreetmap.josm.plugins.tofix.bean.AccessToTask;
+import org.openstreetmap.josm.plugins.tofix.bean.ResponseBean;
+import org.openstreetmap.josm.plugins.tofix.bean.TaskCompleteBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.Item;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemKeeprightBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemKrakatoaBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemNycbuildingsBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemSmallcomponents;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemStrava;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemTigerdeltaBean;
+import org.openstreetmap.josm.plugins.tofix.bean.items.ItemUnconnectedBean;
import org.openstreetmap.josm.plugins.tofix.util.Request;
/**
@@ -16,73 +22,61 @@
*/
public class ItemController {
- private String url;
-
Gson gson = new Gson();
+ Item item = new Item();
+ ResponseBean responseBean = new ResponseBean();
- public String getUrl() {
- return url;
- }
+ AccessToTask accessToTask;
- public void setUrl(String url) {
- this.url = url;
+ public AccessToTask getAccessToTask() {
+ return accessToTask;
}
- public ItemUnconnectedBean getItemBean() {
- ItemUnconnectedBean itemUnconnectedBean = new ItemUnconnectedBean();
- String stringItem = null;
- try {
- stringItem = Request.sendPOST(getUrl());
- itemUnconnectedBean = gson.fromJson(stringItem, ItemUnconnectedBean.class);
- return itemUnconnectedBean;
- } catch (Exception ex) {
- JOptionPane.showConfirmDialog(null, "null");
- Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
- }
- return null;
+ public void setAccessToTask(AccessToTask accessToTask) {
+ this.accessToTask = accessToTask;
}
- public ItemKeeprightBean getItemKeeprightBean() {
- ItemKeeprightBean itemKeeprightBean = new ItemKeeprightBean();
- String stringItem = null;
- try {
- stringItem = Request.sendPOST(getUrl());
- itemKeeprightBean = gson.fromJson(stringItem, ItemKeeprightBean.class);
- return itemKeeprightBean;
- } catch (Exception ex) {
- JOptionPane.showConfirmDialog(null, "null");
- Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
- }
- return null;
- }
+ public Item getItem() {
- public ItemNycbuildingsBean getItemNycbuildingsBean() {
- ItemNycbuildingsBean itemNycbuildingsBean = new ItemNycbuildingsBean();
- String stringItem = null;
try {
- stringItem = Request.sendPOST(getUrl());
- itemNycbuildingsBean = gson.fromJson(stringItem, ItemNycbuildingsBean.class);
-
- return itemNycbuildingsBean;
- } catch (Exception ex) {
- JOptionPane.showConfirmDialog(null, "null");
- Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
- }
- return null;
- }
+ responseBean = Request.sendPOST(accessToTask.getTask_url());
+ item.setStatus(responseBean.getStatus());
- public ItemTigerdeltaBean getItemTigerdeltaBean() {
- ItemTigerdeltaBean itemTigerdeltaBean = new ItemTigerdeltaBean();
- String stringItem = null;
- try {
- stringItem = Request.sendPOST(getUrl());
- itemTigerdeltaBean = gson.fromJson(stringItem, ItemTigerdeltaBean.class);
+ switch (responseBean.getStatus()) {
+ case 200:
+ if (accessToTask.getTask_source().equals("unconnected")) {
+ item.setItemUnconnectedBean(gson.fromJson(responseBean.getValue(), ItemUnconnectedBean.class));
+ }
+ if (accessToTask.getTask_source().equals("keepright")) {
+ item.setItemKeeprightBean(gson.fromJson(responseBean.getValue(), ItemKeeprightBean.class));
+ }
+ if (accessToTask.getTask_source().equals("tigerdelta")) {
+ item.setItemTigerdeltaBean(gson.fromJson(responseBean.getValue(), ItemTigerdeltaBean.class));
+ }
+ if (accessToTask.getTask_source().equals("nycbuildings")) {
+ item.setItemNycbuildingsBean(gson.fromJson(responseBean.getValue(), ItemNycbuildingsBean.class));
+ }
+ if (accessToTask.getTask_source().equals("krakatoa")) {
+ item.setItemKrakatoaBean(gson.fromJson(responseBean.getValue(), ItemKrakatoaBean.class));
+ }
+ if (accessToTask.getTask_source().equals("strava")) {
+ item.setItemStrava(gson.fromJson(responseBean.getValue(), ItemStrava.class));
+ }
+ if (accessToTask.getTask_source().equals("components")) {
+ item.setItemSmallcomponents(gson.fromJson(responseBean.getValue(), ItemSmallcomponents.class));
+ }
+ break;
+ case 410:
+ item.setTaskCompleteBean(gson.fromJson(responseBean.getValue().replace("\\", "").replace("\"{", "{").replace("}\"", "}"), TaskCompleteBean.class));
+ break;
+ case 503:
+ //Servidor en mantenimiento
+ break;
+ }
- return itemTigerdeltaBean;
} catch (Exception ex) {
- JOptionPane.showConfirmDialog(null, "null");
Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
}
- return null;
+ return item;
}
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemEditController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemEditController.java
deleted file mode 100644
index d0c4dd2..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemEditController.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.controller;
-
-import com.google.gson.Gson;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.openstreetmap.josm.plugins.tofix.bean.TrackBean;
-import org.openstreetmap.josm.plugins.tofix.util.Request;
-import org.openstreetmap.josm.plugins.tofix.util.Util;
-
-/**
- *
- * @author ruben
- */
-public class ItemEditController {
-
- private String url;
- private TrackBean trackBean;
-
- public ItemEditController(String url, TrackBean trackBean) {
- this.url = url;
- this.trackBean = trackBean;
- }
-
- public void sendTrackBean() {
- Gson gson = new Gson();
- String string_obj = gson.toJson(trackBean).toString();
- Util.print(string_obj);
- try {
- Request.sendPOST_Json(url, string_obj);
-
- } catch (IOException ex) {
- Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
- }
-
- }
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemFixedController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemFixedController.java
deleted file mode 100644
index e2ff2a4..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemFixedController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.controller;
-
-import com.google.gson.Gson;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.openstreetmap.josm.plugins.tofix.bean.ItemFixedBean;
-import org.openstreetmap.josm.plugins.tofix.bean.TrackBean;
-import org.openstreetmap.josm.plugins.tofix.util.Request;
-import org.openstreetmap.josm.plugins.tofix.util.Util;
-
-/**
- *
- * @author ruben
- */
-public class ItemFixedController {
-
- private String url;
- private ItemFixedBean itemFixedBean;
- public ItemFixedController(String url, ItemFixedBean itemFixedBean) {
- this.url = url;
- this.itemFixedBean = itemFixedBean;
- }
-
- public void sendTrackBean() {
- Gson gson = new Gson();
- String string_obj = gson.toJson(itemFixedBean).toString();
- Util.print(string_obj);
- try {
- Request.sendPOST_Json(url, string_obj);
-
- } catch (IOException ex) {
- Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemSkipController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemSkipController.java
deleted file mode 100644
index 1aacb05..0000000
--- a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemSkipController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.openstreetmap.josm.plugins.tofix.controller;
-
-import com.google.gson.Gson;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.openstreetmap.josm.plugins.tofix.bean.TrackBean;
-import org.openstreetmap.josm.plugins.tofix.util.Request;
-import org.openstreetmap.josm.plugins.tofix.util.Util;
-
-/**
- *
- * @author ruben
- */
-public class ItemSkipController {
-
- private String url;
- private TrackBean trackBean;
-
- public ItemSkipController(String url, TrackBean trackBean) {
- this.url = url;
- this.trackBean = trackBean;
- }
-
- public void sendTrackBean() {
- Gson gson = new Gson();
- String string_obj = gson.toJson(trackBean).toString();
- Util.print(string_obj);
- try {
- Request.sendPOST_Json(url, string_obj);
-
- } catch (IOException ex) {
- Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/ItemTrackController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemTrackController.java
new file mode 100644
index 0000000..63fc222
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/controller/ItemTrackController.java
@@ -0,0 +1,52 @@
+package org.openstreetmap.josm.plugins.tofix.controller;
+
+import com.google.gson.Gson;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.openstreetmap.josm.plugins.tofix.bean.FixedBean;
+import org.openstreetmap.josm.plugins.tofix.bean.TrackBean;
+import org.openstreetmap.josm.plugins.tofix.util.Request;
+
+public class ItemTrackController {
+ public void send_track_edit(String url, TrackBean trackBean) {
+ Gson gson = new Gson();
+ String string_obj = gson.toJson(trackBean);
+ try {
+ Request.sendPOST_Json(url, string_obj);
+ } catch (IOException ex) {
+ Logger.getLogger(ItemTrackController.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public void send_track_skip(String url, TrackBean trackBean) {
+ Gson gson = new Gson();
+ String string_obj = gson.toJson(trackBean);
+ try {
+ Request.sendPOST_Json(url, string_obj);
+ } catch (IOException ex) {
+ Logger.getLogger(ItemTrackController.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public void send_track_fix(String url, FixedBean fixedBean) {
+ Gson gson = new Gson();
+ String string_obj = gson.toJson(fixedBean);
+ try {
+ Request.sendPOST_Json(url, string_obj);
+ } catch (IOException ex) {
+ Logger.getLogger(ItemTrackController.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public void send_track_noterror(String url, FixedBean NoterrorBean) {
+ Gson gson = new Gson();
+ String string_obj = gson.toJson(NoterrorBean);
+ try {
+ Request.sendPOST_Json(url, string_obj);
+ } catch (IOException ex) {
+ Logger.getLogger(ItemTrackController.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ }
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/ListTaskController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/ListTaskController.java
index d16e180..aca188c 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/controller/ListTaskController.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/controller/ListTaskController.java
@@ -4,6 +4,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openstreetmap.josm.plugins.tofix.bean.ListTaskBean;
+import org.openstreetmap.josm.plugins.tofix.bean.TrackBean;
+import org.openstreetmap.josm.plugins.tofix.util.Config;
import org.openstreetmap.josm.plugins.tofix.util.Request;
/**
@@ -16,7 +18,7 @@ public class ListTaskController {
private String url;
public ListTaskController() {
- this.url = "http://osmlab.github.io/to-fix/src/data/tasks.json";
+ this.url = Config.host + "tasks";
}
public ListTaskBean getListTasksBean() {
@@ -24,11 +26,11 @@ public ListTaskBean getListTasksBean() {
String stringListTaskBean = null;
try {
stringListTaskBean = Request.sendGET(url);
+
} catch (Exception ex) {
Logger.getLogger(StatusController.class.getName()).log(Level.SEVERE, null, ex);
}
listTasksBean = gson.fromJson(stringListTaskBean, ListTaskBean.class);
-
return listTasksBean;
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/controller/StatusController.java b/src/org/openstreetmap/josm/plugins/tofix/controller/StatusController.java
index 958b384..895598a 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/controller/StatusController.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/controller/StatusController.java
@@ -27,10 +27,7 @@ public StatusBean getStatusBean() {
} catch (Exception ex) {
Logger.getLogger(StatusController.class.getName()).log(Level.SEVERE, null, ex);
}
-
statusBean = gson.fromJson(stringStatusBean, StatusBean.class);
- //statusBean.sumary();
-
return statusBean;
}
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/layer/TofixLayer.java b/src/org/openstreetmap/josm/plugins/tofix/layer/TofixLayer.java
index 58466ec..511387b 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/layer/TofixLayer.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/layer/TofixLayer.java
@@ -27,10 +27,10 @@
public class TofixLayer extends Layer implements ActionListener {
LatLon latLon;
- List> list_nodes;
- boolean isnode = true;
+ List> list_list_nodes;
+ List list_nodes;
+ String type = "";
- //List listcoordinates = new LinkedList();
public TofixLayer(String name) {
super(name);
}
@@ -39,7 +39,6 @@ public TofixLayer(String name) {
@Override
public Icon getIcon() {
- //return icon;
return ImageProvider.get("layer", "marker_small");
}
@@ -54,38 +53,46 @@ public boolean isMergable(Layer other) {
}
public void add_Node(LatLon latLon) {
- //listcoordinates.add(coordinate);
- isnode = true;
+ type = "draw_node";
this.latLon = latLon;
Main.map.mapView.repaint();
-
}
public void add_Line(List> list_nodes) {
- //listcoordinates.add(coordinate);
- isnode = false;
- this.list_nodes = list_nodes;
+ type = "draw_line";
+ this.list_list_nodes = list_nodes;
Main.map.mapView.repaint();
+ }
+ public void add_Nodes(List list_nodes) {
+ type = "draw_nodes";
+ this.list_nodes = list_nodes;
+ Main.map.mapView.repaint();
}
@Override
public void paint(Graphics2D g, final MapView mv, Bounds bounds) {
g.setColor(new Color(254, 30, 123));
g.setStroke(new BasicStroke((float) 5));
- if (isnode) {
+ if (type.equals("draw_node")) {
Point pnt = mv.getPoint(latLon);
g.drawOval(pnt.x - 25, pnt.y - 25, 50, 50);
- } else {
- for (List l_nodes : list_nodes) {
+ } else if (type.equals("draw_line")) {
+ for (List l_nodes : list_list_nodes) {
for (int i = 0; i < l_nodes.size() - 1; i++) {
Point pnt1 = mv.getPoint(l_nodes.get(i).getCoor());
Point pnt2 = mv.getPoint(l_nodes.get(i + 1).getCoor());
g.drawLine(pnt1.x, pnt1.y, pnt2.x, pnt2.y);
}
}
+ } else if (type.equals("draw_nodes")) {
+ for (Node node : list_nodes) {
+ Point pnt = mv.getPoint(node.getCoor());
+ g.drawOval(pnt.x - 5, pnt.y - 5, 10, 10);
+ }
}
+//add for others ways
}
@Override
diff --git a/src/org/openstreetmap/josm/plugins/tofix/util/Config.java b/src/org/openstreetmap/josm/plugins/tofix/util/Config.java
new file mode 100644
index 0000000..4232ed7
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/util/Config.java
@@ -0,0 +1,7 @@
+package org.openstreetmap.josm.plugins.tofix.util;
+
+public class Config {
+ public static final String host = "http://54.173.75.173:8000/";
+ public static final String url_tofix = "http://osmlab.github.io/to-fix/";
+ public static final String url_osm = "http://www.openstreetmap.org";
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/util/Download.java b/src/org/openstreetmap/josm/plugins/tofix/util/Download.java
index 8c1df0e..5df8d86 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/util/Download.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/util/Download.java
@@ -32,15 +32,20 @@ public static void Download(final DownloadOsmTask task, Bounds bounds, final Lon
@Override
public void run() {
try {
- future.get();
- Node node = new Node(osm_obj_id);
- Relation relation = new Relation(osm_obj_id);
- Way way = new Way(osm_obj_id);
- List selection = new ArrayList<>();
- selection.add(way);
- selection.add(node);
- selection.add(relation);
- Main.main.getCurrentDataSet().setSelected(selection);
+ if (osm_obj_id != 0) {
+ future.get();
+ //create object
+ Node node = new Node(osm_obj_id);
+ Relation relation = new Relation(osm_obj_id);
+ Way way = new Way(osm_obj_id);
+ //create list of objects
+ List selection = new ArrayList<>();
+ selection.add(way);
+ selection.add(node);
+ selection.add(relation);
+ //make selection ob objects
+ Main.main.getCurrentDataSet().setSelected(selection);
+ }
} catch (InterruptedException ex) {
Logger.getLogger(TofixDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionException ex) {
diff --git a/src/org/openstreetmap/josm/plugins/tofix/util/Request.java b/src/org/openstreetmap/josm/plugins/tofix/util/Request.java
index 43713bb..66ae9fb 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/util/Request.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/util/Request.java
@@ -6,6 +6,7 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
+import org.openstreetmap.josm.plugins.tofix.bean.ResponseBean;
/**
*
@@ -13,8 +14,7 @@
*/
public class Request {
- public static String sendPOST(String url) throws Exception {
- Util.print(url);
+ public static ResponseBean sendPOST(String url) throws Exception {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
@@ -25,9 +25,15 @@ public static String sendPOST(String url) throws Exception {
os.close();
//POST - END
int responseCode = con.getResponseCode();
+
+ //Crear un ResponseBean para que regrese el String y el status de la peticion.
+ ResponseBean responseBean = new ResponseBean();
+
+ responseBean.setStatus(responseCode);//agregar el estatus
+
if (responseCode == HttpURLConnection.HTTP_OK) {
- BufferedReader in = new BufferedReader(new InputStreamReader(
- con.getInputStream()));
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
@@ -35,12 +41,27 @@ public static String sendPOST(String url) throws Exception {
}
in.close();
Util.print(response.toString());
- return response.toString();
+ responseBean.setValue(response.toString());//agrega el valor de la respuesta
+
+ } else if (responseCode == HttpURLConnection.HTTP_GONE) {
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
+ String inputLine;
+ StringBuffer response_error = new StringBuffer();
+ while ((inputLine = in.readLine()) != null) {
+ response_error.append(inputLine);
+ }
+ in.close();
+
+ responseBean.setValue(response_error.toString());// agregar respuesta de complete task
} else {
- return null;
+
+ responseBean.setValue("error");
}
+ con.disconnect();
+ return responseBean;
}
public static void sendPOST_Json(String url, String object) throws IOException {
@@ -55,7 +76,7 @@ public static void sendPOST_Json(String url, String object) throws IOException {
os.write(outputBytes);
os.close();
int responseCode = con.getResponseCode();
- Util.print(responseCode);
+
}
public static String sendGET(String url) throws IOException {
@@ -73,8 +94,6 @@ public static String sendGET(String url) throws IOException {
response.append(inputLine);
}
in.close();
-
- System.out.println(response.toString());
return response.toString();
} else {
diff --git a/src/org/openstreetmap/josm/plugins/tofix/util/Status.java b/src/org/openstreetmap/josm/plugins/tofix/util/Status.java
index 7641072..7989007 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/util/Status.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/util/Status.java
@@ -3,9 +3,6 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.net.UnknownHostException;
-import javax.swing.JOptionPane;
-import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.plugins.tofix.controller.StatusController;
/**
@@ -14,34 +11,28 @@
*/
public class Status {
- final static String host = "http://54.147.184.23:8000/status";
+ final static String host = Config.host + "status";
public static boolean server() {
- StatusController statusController = new StatusController(host);
+ StatusController statusController = new StatusController(host);
if (statusController.getStatusBean().getStatus().equals("a ok")) {
return true;
} else {
- JOptionPane.showConfirmDialog(Main.parent, "The server is on maintenance!");
return false;
}
-
}
public static boolean isInternetReachable() {
+ HttpURLConnection activeConnection = null;
try {
- URL url = new URL("http://www.openstreetmap.org");
- HttpURLConnection urlConnect = (HttpURLConnection) url.openConnection();
- //is no connection, this line will fail
- Object objData = urlConnect.getContent();
-
- } catch (UnknownHostException e) {
- e.printStackTrace();
- return false;
+ URL url = new URL(Config.url_osm);
+ activeConnection = (HttpURLConnection) url.openConnection();
+ activeConnection.connect();
+ return true;
} catch (IOException e) {
- e.printStackTrace();
+ System.err.println("Couldn't connect to the osm server. Please check your internet connection.");
return false;
}
- return true;
}
}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/util/UploadAction.java b/src/org/openstreetmap/josm/plugins/tofix/util/UploadAction.java
new file mode 100644
index 0000000..0550beb
--- /dev/null
+++ b/src/org/openstreetmap/josm/plugins/tofix/util/UploadAction.java
@@ -0,0 +1,317 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.tofix.util;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.actions.upload.ApiPreconditionCheckerHook;
+import org.openstreetmap.josm.actions.upload.DiscardTagsHook;
+import org.openstreetmap.josm.actions.upload.FixDataHook;
+import org.openstreetmap.josm.actions.upload.RelationUploadOrderHook;
+import org.openstreetmap.josm.actions.upload.UploadHook;
+import org.openstreetmap.josm.actions.upload.ValidateUploadHook;
+import org.openstreetmap.josm.data.APIDataSet;
+import org.openstreetmap.josm.data.conflict.ConflictCollection;
+import org.openstreetmap.josm.gui.HelpAwareOptionPane;
+import org.openstreetmap.josm.gui.help.HelpUtil;
+import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
+import org.openstreetmap.josm.gui.io.UploadDialog;
+import org.openstreetmap.josm.gui.io.UploadPrimitivesTask;
+import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.util.GuiHelper;
+import static org.openstreetmap.josm.tools.I18n.tr;
+import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Shortcut;
+
+/**
+ * Action that opens a connection to the osm server and uploads all changes.
+ *
+ * An dialog is displayed asking the user to specify a rectangle to grab. The
+ * url and account settings from the preferences are used.
+ *
+ * If the upload fails this action offers various options to resolve conflicts.
+ *
+ * @author imi
+ */
+public class UploadAction extends JosmAction {
+
+ /**
+ * The list of upload hooks. These hooks will be called one after the other
+ * when the user wants to upload data. Plugins can insert their own hooks
+ * here if they want to be able to veto an upload.
+ *
+ * Be default, the standard upload dialog is the only element in the list.
+ * Plugins should normally insert their code before that, so that the upload
+ * dialog is the last thing shown before upload really starts; on occasion
+ * however, a plugin might also want to insert something after that.
+ */
+ private static final List uploadHooks = new LinkedList<>();
+ private static final List lateUploadHooks = new LinkedList<>();
+
+ static {
+ /**
+ * Calls validator before upload.
+ */
+ uploadHooks.add(new ValidateUploadHook());
+
+ /**
+ * Fixes database errors
+ */
+ uploadHooks.add(new FixDataHook());
+
+ /**
+ * Checks server capabilities before upload.
+ */
+ uploadHooks.add(new ApiPreconditionCheckerHook());
+
+ /**
+ * Adjusts the upload order of new relations
+ */
+ uploadHooks.add(new RelationUploadOrderHook());
+
+ /**
+ * Removes discardable tags like created_by on modified objects
+ */
+ lateUploadHooks.add(new DiscardTagsHook());
+ }
+
+ /**
+ * Registers an upload hook. Adds the hook at the first position of the
+ * upload hooks.
+ *
+ * @param hook the upload hook. Ignored if null.
+ */
+ public static void registerUploadHook(UploadHook hook) {
+ registerUploadHook(hook, false);
+ }
+
+ /**
+ * Registers an upload hook. Adds the hook at the first position of the
+ * upload hooks.
+ *
+ * @param hook the upload hook. Ignored if null.
+ * @param late true, if the hook should be executed after the upload dialog
+ * has been confirmed. Late upload hooks should in general succeed and not
+ * abort the upload.
+ */
+ public static void registerUploadHook(UploadHook hook, boolean late) {
+ if (hook == null) {
+ return;
+ }
+ if (late) {
+ if (!lateUploadHooks.contains(hook)) {
+ lateUploadHooks.add(0, hook);
+ }
+ } else {
+ if (!uploadHooks.contains(hook)) {
+ uploadHooks.add(0, hook);
+ }
+ }
+ }
+
+ /**
+ * Unregisters an upload hook. Removes the hook from the list of upload
+ * hooks.
+ *
+ * @param hook the upload hook. Ignored if null.
+ */
+ public static void unregisterUploadHook(UploadHook hook) {
+ if (hook == null) {
+ return;
+ }
+ if (uploadHooks.contains(hook)) {
+ uploadHooks.remove(hook);
+ }
+ if (lateUploadHooks.contains(hook)) {
+ lateUploadHooks.remove(hook);
+ }
+ }
+
+ private String customized_comment;
+
+ public UploadAction() {
+ super(tr("Upload data"), "upload", tr("Upload all changes in the active data layer to the OSM server"),
+ Shortcut.registerShortcut("file:upload", tr("File: {0}", tr("Upload data")), KeyEvent.VK_UP, Shortcut.CTRL_SHIFT), true);
+ putValue("help", ht("/Action/Upload"));
+ }
+
+ /**
+ * Refreshes the enabled state
+ *
+ */
+ @Override
+ protected void updateEnabledState() {
+ setEnabled(getEditLayer() != null);
+ }
+
+ public static boolean checkPreUploadConditions(AbstractModifiableLayer layer) {
+ return checkPreUploadConditions(layer,
+ layer instanceof OsmDataLayer ? new APIDataSet(((OsmDataLayer) layer).data) : null);
+ }
+
+ protected static void alertUnresolvedConflicts(OsmDataLayer layer) {
+ HelpAwareOptionPane.showOptionDialog(
+ Main.parent,
+ tr("The data to be uploaded participates in unresolved conflicts of layer ''{0}''.
"
+ + "You have to resolve them first.", layer.getName()
+ ),
+ tr("Warning"),
+ JOptionPane.WARNING_MESSAGE,
+ HelpUtil.ht("/Action/Upload#PrimitivesParticipateInConflicts")
+ );
+ }
+
+ /**
+ * returns true if the user wants to cancel, false if they want to continue
+ */
+ public static boolean warnUploadDiscouraged(AbstractModifiableLayer layer) {
+ return GuiHelper.warnUser(tr("Upload discouraged"),
+ ""
+ + tr("You are about to upload data from the layer ''{0}''.
"
+ + "Sending data from this layer is strongly discouraged. If you continue,
"
+ + "it may require you subsequently have to revert your changes, or force other contributors to.
"
+ + "Are you sure you want to continue?", layer.getName())
+ + "",
+ ImageProvider.get("upload"), tr("Ignore this hint and upload anyway"));
+ }
+
+ /**
+ * Check whether the preconditions are met to upload data in
+ * apiData
. Makes sure upload is allowed, primitives in
+ * apiData
don't participate in conflicts and runs the
+ * installed {@link UploadHook}s.
+ *
+ * @param layer the source layer of the data to be uploaded
+ * @param apiData the data to be uploaded
+ * @return true, if the preconditions are met; false, otherwise
+ */
+ public static boolean checkPreUploadConditions(AbstractModifiableLayer layer, APIDataSet apiData) {
+ if (layer.isUploadDiscouraged()) {
+ if (warnUploadDiscouraged(layer)) {
+ return false;
+ }
+ }
+ if (layer instanceof OsmDataLayer) {
+ OsmDataLayer osmLayer = (OsmDataLayer) layer;
+ ConflictCollection conflicts = osmLayer.getConflicts();
+ if (apiData.participatesInConflict(conflicts)) {
+ alertUnresolvedConflicts(osmLayer);
+ return false;
+ }
+ }
+ // Call all upload hooks in sequence.
+ // FIXME: this should become an asynchronous task
+ //
+ if (apiData != null) {
+ for (UploadHook hook : uploadHooks) {
+ if (!hook.checkUpload(apiData)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Uploads data to the OSM API.
+ *
+ * @param layer the source layer for the data to upload
+ * @param apiData the primitives to be added, updated, or deleted
+ */
+ public void uploadData(final OsmDataLayer layer, APIDataSet apiData) {
+ if (apiData.isEmpty()) {
+ JOptionPane.showMessageDialog(
+ Main.parent,
+ tr("No changes to upload."),
+ tr("Warning"),
+ JOptionPane.INFORMATION_MESSAGE
+ );
+ return;
+ }
+ if (!checkPreUploadConditions(layer, apiData)) {
+ return;
+ }
+
+ final UploadDialog dialog = UploadDialog.getUploadDialog();
+ // If we simply set the changeset comment here, it would be
+ // overridden by subsequent events in EDT that are caused by
+ // dialog creation. The current solution is to queue this operation
+ // after these events.
+ // TODO: find better way to initialize the comment field
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ final Map tags = new HashMap<>(layer.data.getChangeSetTags());
+ if (!tags.containsKey("source")) {
+ tags.put("source", dialog.getLastChangesetSourceFromHistory());
+ }
+ if (!tags.containsKey("comment")) {
+ String comment = dialog.getLastChangesetCommentFromHistory();
+ if (!comment.contains(getCustomized_comment())) {
+ comment = getCustomized_comment();
+ }
+ tags.put("comment", comment);
+ }
+
+ dialog.setDefaultChangesetTags(tags);
+ }
+ });
+ dialog.setUploadedPrimitives(apiData);
+ dialog.setVisible(true);
+ if (dialog.isCanceled()) {
+ return;
+ }
+ dialog.rememberUserInput();
+
+ for (UploadHook hook : lateUploadHooks) {
+ if (!hook.checkUpload(apiData)) {
+ return;
+ }
+ }
+
+ Main.worker.execute(
+ new UploadPrimitivesTask(
+ UploadDialog.getUploadDialog().getUploadStrategySpecification(),
+ layer,
+ apiData,
+ UploadDialog.getUploadDialog().getChangeset()
+ )
+ );
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (!isEnabled()) {
+ return;
+ }
+ if (Main.map == null) {
+ JOptionPane.showMessageDialog(
+ Main.parent,
+ tr("Nothing to upload. Get some data first."),
+ tr("Warning"),
+ JOptionPane.WARNING_MESSAGE
+ );
+ return;
+ }
+ APIDataSet apiData = new APIDataSet(Main.main.getCurrentDataSet());
+ uploadData(Main.main.getEditLayer(), apiData);
+ }
+
+ public String getCustomized_comment() {
+ return customized_comment;
+ }
+
+ public void setCustomized_comment(String customized_comment) {
+ this.customized_comment = customized_comment;
+ }
+
+}
diff --git a/src/org/openstreetmap/josm/plugins/tofix/util/Util.java b/src/org/openstreetmap/josm/plugins/tofix/util/Util.java
index c0ca712..98629b7 100644
--- a/src/org/openstreetmap/josm/plugins/tofix/util/Util.java
+++ b/src/org/openstreetmap/josm/plugins/tofix/util/Util.java
@@ -1,87 +1,18 @@
package org.openstreetmap.josm.plugins.tofix.util;
-import java.util.AbstractList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import org.openstreetmap.josm.data.coor.CachedLatLon;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.tools.Geometry;
+import javax.swing.JOptionPane;
+
/**
*
* @author ruben
*/
public class Util {
+ public static void alert(Object object) {
+ JOptionPane.showMessageDialog(null, object);
+ }
public static void print(Object object) {
System.err.println(object);
}
-
- public static LatLon format_St_astext_Keepright(String st_astext) {
- String str = st_astext.replaceAll("[^-?0-9.]+", " ");
- Double lat = Double.parseDouble(Arrays.asList(str.trim().split(" ")).get(1));
- Double lon = Double.parseDouble(Arrays.asList(str.trim().split(" ")).get(0));
- LatLon coor = new LatLon(lat, lon);
- Util.print(coor);
- return coor;
- }
-
- public static Long format_Elems_Nycbuildings(String elems) {
- String[] arr = elems.replace("way", "").split("_");
-
- Util.print(arr);
- return Long.valueOf(arr[0]);
- }
-
- public static List format_st_astext_Tigerdelta(String st_astext) {
- // String[] list = st_astext.replaceAll("[^-?0-9.]+", " ").split(" ");
- st_astext = st_astext.replace("MULTILINESTRING(", "").replace("))", ")");
- Double[][] cordinates;
-
- List> list = new LinkedList>();
- String[] array;
- if (st_astext.contains("),(")) {
- st_astext = st_astext.replace(")", "").replace("(", "");
- array = st_astext.split(",\\(");
- for (int i = 0; i < array.length; i++) {
- List l = new LinkedList();
- String[] a = array[i].split(",");
- for (int j = 0; j < a.length; j++) {
- LatLon latLon = new LatLon(Double.parseDouble(a[j].split(" ")[1]), Double.parseDouble(a[j].split(" ")[0]));
- Node node = new Node(latLon);
- l.add(node);
- }
- list.add(l);
- }
- } else {
- st_astext = st_astext.replace(")", "").replace("(", "");
- array = st_astext.split(",");
- List l = new LinkedList();
- for (int i = 0; i < array.length; i++) {
- LatLon latLon = new LatLon(Double.parseDouble(array[i].split(" ")[1]), Double.parseDouble(array[i].split(" ")[0]));
- Node node = new Node(latLon);
- l.add(node);
- }
- list.add(l);
-
- }
-
-// for (List l : list) {
-// for (Double[] s : l) {
-// Util.print(s[0] + " , " + s[1]);
-// }
-// }
-
-//:"MULTILINESTRING((-95.434784 30.066343,-95.434784 30.066349),(-95.434814 30.066545,-95.434845 30.066711),(-95.43486 30.06678,-95.434906 30.067045,-95.434952 30.067226))"}}
-//"MULTILINESTRING((-83.312073 35.471603,-83.3125 35.471741,-83.312843 35.471855))"}}
-// Double lat = Double.parseDouble(list[2]);
-// Double lon = Double.parseDouble(list[1]);
- // LatLon coor = new LatLon(4, 6);
- // Util.print(coor);
- return list;
-
- }
}