Skip to content

Commit

Permalink
Merge pull request #3 from aarthykc/changesetSource
Browse files Browse the repository at this point in the history
Added filters
  • Loading branch information
aarthykc committed Nov 13, 2015
2 parents 9b7647a + 349a461 commit 8009eec
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 153 deletions.
307 changes: 176 additions & 131 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified build/org/openstreetmap/josm/plugins/MyPlugin.class
Binary file not shown.
Binary file not shown.
Binary file modified build/org/openstreetmap/josm/plugins/MyPluginAddLayerAction$1.class
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/org/openstreetmap/josm/plugins/MyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public MyPlugin(PluginInformation info) {
super(info);
MainMenu menu = Main.main.menu;
JMenu loadTaskComponents = menu.addMenu(marktr("Task Components"), KeyEvent.VK_K, menu.getDefaultMenuPos(), HelpUtil.ht("/Plugin/task"));
loadTaskComponents.add(new JMenuItem(new MyPluginAddLayerAction()));
loadTaskComponents.add(new JMenuItem(new MyPluginAddLayerAction("Load task from Gist")));

}
}
86 changes: 65 additions & 21 deletions src/org/openstreetmap/josm/plugins/MyPluginAddLayerAction.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package org.openstreetmap.josm.plugins;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.actions.search.SearchCompiler;
import org.openstreetmap.josm.data.imagery.ImageryInfo;
import org.openstreetmap.josm.data.osm.Filter;
import org.openstreetmap.josm.data.osm.FilterMatcher;
import org.openstreetmap.josm.data.osm.FilterWorker;
import org.openstreetmap.josm.data.osm.event.*;
import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
import org.openstreetmap.josm.gui.MapFrame;
import org.openstreetmap.josm.gui.MapFrameListener;
import org.openstreetmap.josm.gui.MapView;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.dialogs.FilterDialog;
import org.openstreetmap.josm.gui.dialogs.FilterTableModel;
import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
import org.openstreetmap.josm.gui.mappaint.StyleSource;
import org.openstreetmap.josm.gui.preferences.SourceEntry;
import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonString;
import javax.net.ssl.HttpsURLConnection;
import javax.swing.*;
import java.awt.event.ActionEvent;
Expand All @@ -20,32 +33,30 @@
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
* Created by aarthychandrasekhar on 09/10/15.
*/
public class MyPluginAddLayerAction extends JosmAction implements DataSetListenerAdapter.Listener, MapView.LayerChangeListener {
ArrayList<TaskLayer> taskLayers = new ArrayList<TaskLayer>();
ArrayList<SourceEntry> mapPaintStyleSourceEntries = new ArrayList<SourceEntry>();
List<Filter> filterList = new ArrayList<Filter>();
DataSetListenerAdapter dataSetListenerAdapter = new DataSetListenerAdapter(this);

public MyPluginAddLayerAction() {

String changesetSource,changesetComment,filters;
MapFrameListener mapFrameListener;
public MyPluginAddLayerAction(String name) {
super(name, null, name, null , true);
}

@Override
public void actionPerformed(ActionEvent e) {
for (int j = 0; j < taskLayers.size(); j++) {
Main.main.removeLayer(taskLayers.get(j));
}

String url = JOptionPane.showInputDialog(Main.parent, "Enter gist URL");
String taskString, layerName, layerUrl, mapPaint, mapPaintName, mapPaintTitle;
mapPaint = "https://raw.githubusercontent.com/Andygol/josm-styles/master/created_in_2015.mapcss";
mapPaintName = "recent edits";
mapPaintTitle = "recent edits";

String taskString, layerName, layerUrl;

//MapPaintStyles.addStyle(new SourceEntry("https://raw.githubusercontent.com/Andygol/josm-styles/master/created_in_2015.mapcss","Name","description",true));

try {
URL obj = new URL(url);
Expand All @@ -59,12 +70,21 @@ public void actionPerformed(ActionEvent e) {
JsonObject taskObject = Json.createReader(new StringReader(taskString)).readObject();
JsonObject task = taskObject.getJsonObject("task");
JsonArray layerArray = task.getJsonArray("layers");
JsonArray mapPaintStyles = task.getJsonArray("mappaints");
changesetSource = task.getString("source");
changesetComment = task.getString("comment");
filters = task.getString("filters");
new Notification("Filter:"+filters).show();
Filter f1 = new Filter();
f1.text = filters;
f1.hiding = true;
filterList.add(f1);


for (int i = 0; i < layerArray.size(); i++) {
JsonObject layer = layerArray.getJsonObject(i);
layerUrl = layer.getString("url");
layerName = layer.getString("name");
new Notification("Name:" + layerName + " URL:" + layerUrl).show();

ImageryInfo imageryInfo = new ImageryInfo();
imageryInfo.setUrl(layerUrl);
Expand All @@ -74,21 +94,37 @@ public void actionPerformed(ActionEvent e) {
Main.main.addLayer(taskLayer);
taskLayers.add(taskLayer);
}
for (int j = 0; j < mapPaintStyles.size(); j++) {
JsonObject mapPaint = mapPaintStyles.getJsonObject(j);
String mapPaintName = mapPaint.getString("name");
String mapPaintDescription = mapPaint.getString("description");
String mapPaintUrl = mapPaint.getString("url");

//Editing the changeset comment and source tags
Main.addMapFrameListener(new MapFrameListener() {
mapPaintStyleSourceEntries.add(new SourceEntry(mapPaintUrl,mapPaintName,mapPaintDescription,true));
}
if(mapFrameListener==null) Main.removeMapFrameListener(mapFrameListener);

mapFrameListener = new MapFrameListener(){
@Override
public void mapFrameInitialized(final MapFrame mapFrame, MapFrame mapFrame1) {
Main.map.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Main.main.getEditLayer().data.addChangeSetTag("source", "aarthy");
for (SourceEntry sc : mapPaintStyleSourceEntries) {
boolean flag = false;
List<StyleSource> styleSources = MapPaintStyles.getStyles().getStyleSources();
for(StyleSource ss: styleSources) {
if(ss.url.equals(sc.url)) {
flag = true;
}
}
});
if(!flag)
MapPaintStyles.addStyle(sc);
}
}
});


};
Main.addMapFrameListener(mapFrameListener);
MapView.addLayerChangeListener(this);
} catch (IOException e1) {
} catch (Exception e1) {
e1.printStackTrace();
new Notification(e1.toString()).show();
}
Expand All @@ -97,7 +133,9 @@ public void propertyChange(PropertyChangeEvent evt) {
@Override
public void processDatasetEvent(AbstractDatasetChangedEvent abstractDatasetChangedEvent) {
if (Main.main.hasEditLayer()) {
Main.main.getCurrentDataSet().addChangeSetTag("source", "hello");
//set changeset source and comment
Main.main.getCurrentDataSet().addChangeSetTag("source", changesetSource);
Main.main.getCurrentDataSet().addChangeSetTag("comment", changesetComment);
}
}

Expand All @@ -113,6 +151,7 @@ public void layerAdded(Layer layer) {
}
}


@Override
public void layerRemoved(Layer layer) {
if (layer instanceof OsmDataLayer) {
Expand All @@ -121,6 +160,11 @@ public void layerRemoved(Layer layer) {
}
private void registerNewLayer(OsmDataLayer layer) {
layer.data.addDataSetListener(dataSetListenerAdapter);
FilterTableModel filterTableModel = Main.map.filterDialog.getFilterModel();
for(Filter f: filterList){
filterTableModel.addFilter(f);
filterTableModel.executeFilters();
}
}

private void unRegisterNewLayer(OsmDataLayer layer) {
Expand Down

0 comments on commit 8009eec

Please sign in to comment.