Skip to content

Commit 64b262a

Browse files
author
niplecrumple
committed
Publishing RasterFilters plugin ver 1.0.1
git-svn-id: https://josm.openstreetmap.de/osmsvn/applications/editors/josm/plugins@31470 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
1 parent 7555eda commit 64b262a

27 files changed

+2307
-2
lines changed

build-common.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
-->
1313
<project name="plugin_common" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
1414

15-
<property name="josm" location="../../core/dist/josm-custom.jar"/>
16-
<property name="josm.test.build.dir" location="../../core/test/build"/>
15+
<property name="josm" location="../../dist/josm-custom.jar"/>
16+
<property name="josm.test.build.dir" location="../../test/build"/>
1717
<property name="groovy.jar" location="../00_core_tools/groovy-all-2.4.3.jar"/>
1818
<property name="plugin.build.dir" location="build"/>
1919
<property name="plugin.test.dir" location="test"/>

rasterfilters/.classpath

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
6+
<classpathentry kind="lib" path="lib/jsoup-1.8.2.jar"/>
7+
<classpathentry kind="lib" path="lib/picker.jar"/>
8+
<classpathentry kind="output" path="bin"/>
9+
</classpath>

rasterfilters/.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>rasterfilters</name>
4+
<comment>JavaCC Nature</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>sf.eclipse.javacc.javaccbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>sf.eclipse.javacc.javaccnature</nature>
22+
</natures>
23+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CLEAR_CONSOLE=true
2+
JAVACC_OPTIONS=
3+
JJDOC_OPTIONS=
4+
JJTREE_OPTIONS=
5+
JJ_NATURE=true
6+
JTB_OPTIONS=-ia -jd -tk
7+
KEEP_DEL_FILES_IN_HISTORY=false
8+
MARK_GEN_FILES_AS_DERIVED=true
9+
RUNTIME_JJJAR=
10+
RUNTIME_JTBJAR=
11+
RUNTIME_JVMOPTIONS=
12+
SUPPRESS_WARNINGS=false
13+
eclipse.preferences.version=1

rasterfilters/LICENSE

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2+
Version 2, December 2004
3+
4+
Copyright (C) 2004 Sam Hocevar <[email protected]>
5+
6+
Everyone is permitted to copy and distribute verbatim or modified
7+
copies of this license document, and changing it is allowed as long
8+
as the name is changed.
9+
10+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12+
13+
0. You just DO WHAT THE FUCK YOU WANT TO.
14+
15+
Icon made by http://www.freepik.com" from "http://www.flaticon.com" is licensed under "http://creativecommons.org/licenses/by/3.0/"

rasterfilters/build.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<project name="rasterfilters" default="dist" basedir=".">
4+
5+
<!-- ** include targets that all plugins have in common ** -->
6+
<import file="../build-common.xml" />
7+
8+
<!-- enter the SVN commit message -->
9+
<property name="commit.message" value="The first commit of rasterfilters JOSM's plugin" />
10+
11+
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
12+
<property name="plugin.main.version" value="8625" />
13+
<property name="plugin.version" value="1.0"/>
14+
15+
<property name="plugin.icon" value="images/josm_filters_48.png"/>
16+
<property name="plugin.author" value="Vadim Varnavsky" />
17+
<property name="plugin.class" value="org.openstreetmap.josm.plugins.rasterfilters.RasterFiltersPlugin" />
18+
<property name="plugin.description" value="The RasterFiltersPlugin allows to choose and apply some images' filters to some layers" />
19+
20+
</project>
1.88 KB
Loading

rasterfilters/lib/jsoup-1.8.2.jar

308 KB
Binary file not shown.

rasterfilters/lib/picker.jar

106 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package org.openstreetmap.josm.plugins.rasterfilters;
2+
3+
import java.awt.Container;
4+
import java.io.File;
5+
import java.io.IOException;
6+
7+
import javax.swing.JPanel;
8+
9+
import org.openstreetmap.josm.Main;
10+
import org.openstreetmap.josm.gui.MapFrame;
11+
import org.openstreetmap.josm.gui.MapView;
12+
import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
13+
import org.openstreetmap.josm.gui.SideButton;
14+
import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
15+
import org.openstreetmap.josm.gui.layer.ImageryLayer;
16+
import org.openstreetmap.josm.gui.layer.Layer;
17+
import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
18+
import org.openstreetmap.josm.plugins.Plugin;
19+
import org.openstreetmap.josm.plugins.PluginInformation;
20+
import org.openstreetmap.josm.plugins.rasterfilters.actions.ShowLayerFiltersDialog;
21+
import org.openstreetmap.josm.plugins.rasterfilters.gui.FiltersDialog;
22+
import org.openstreetmap.josm.plugins.rasterfilters.preferences.FiltersDownloader;
23+
import org.openstreetmap.josm.plugins.rasterfilters.preferences.RasterFiltersPreferences;
24+
25+
public class RasterFiltersPlugin extends Plugin implements LayerChangeListener {
26+
27+
private SideButton filterButton;
28+
private ShowLayerFiltersDialog action;
29+
private PreferenceSetting setting;
30+
31+
public RasterFiltersPlugin(PluginInformation info) {
32+
super(info);
33+
Main.debug("Loading RasterFiltersPlugin");
34+
35+
File file = new File(getPluginDir());
36+
if (file.mkdir()) {
37+
file = new File(file.getAbsoluteFile() + "\\urls.map");
38+
if (!file.exists()) {
39+
try {
40+
file.createNewFile();
41+
} catch (IOException e) {
42+
Main.debug("Cannot create file" + file.getAbsolutePath() + "\n" + e.getMessage());
43+
}
44+
}
45+
}
46+
47+
FiltersDownloader.setPluginDir(getPluginDir());
48+
}
49+
50+
@Override
51+
public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
52+
if (Main.isDisplayingMapView()) {
53+
MapView.addLayerChangeListener(this);
54+
}
55+
}
56+
57+
@Override
58+
public void activeLayerChange(Layer oldLayer, Layer newLayer) {
59+
if (!(newLayer instanceof ImageryLayer)) {
60+
filterButton.setEnabled(false);
61+
} else {
62+
filterButton.setEnabled(true);
63+
}
64+
65+
}
66+
67+
@Override
68+
public void layerAdded(Layer newLayer) {
69+
70+
if (filterButton == null) {
71+
72+
// filter reading and adding to the collections of
73+
// FilterDownloader
74+
FiltersDownloader.downloadFiltersInfoList();
75+
FiltersDownloader.initFilters();
76+
77+
LayerListDialog dialog = Main.map
78+
.getToggleDialog(LayerListDialog.class);
79+
80+
if (action == null) {
81+
action = new ShowLayerFiltersDialog();
82+
}
83+
84+
if (newLayer instanceof ImageryLayer) {
85+
filterButton = new SideButton(action, false);
86+
filterButton.setEnabled(true);
87+
} else {
88+
filterButton = new SideButton(action, false);
89+
filterButton.setEnabled(false);
90+
}
91+
92+
JPanel buttonRowPanel = (JPanel) ((JPanel) dialog.getComponent(2))
93+
.getComponent(0);
94+
buttonRowPanel.add(filterButton);
95+
96+
Main.debug("Layer " + newLayer.getName() + "was added");
97+
}
98+
99+
if (newLayer instanceof ImageryLayer) {
100+
FiltersDialog dialog = new FiltersDialog((ImageryLayer) newLayer);
101+
action.addFiltersDialog(dialog);
102+
}
103+
104+
}
105+
106+
@Override
107+
public void layerRemoved(Layer oldLayer) {
108+
Main.debug("Layer " + oldLayer.getName() + "was removed");
109+
110+
if (oldLayer instanceof ImageryLayer) {
111+
FiltersDialog dialog = action.getDialogByLayer(oldLayer);
112+
((ImageryLayer) oldLayer).removeImageProcessor(dialog.getFiltersManager());
113+
dialog.closeFrame();
114+
action.removeFiltersDialog(dialog);
115+
}
116+
117+
if (Main.map.mapView.getAllLayersAsList().size() == 0) {
118+
119+
Container container = filterButton.getParent();
120+
container.remove(filterButton);
121+
FiltersDownloader.destroyFilters();
122+
filterButton = null;
123+
124+
}
125+
}
126+
127+
@Override
128+
public PreferenceSetting getPreferenceSetting() {
129+
if (setting == null) {
130+
setting = new RasterFiltersPreferences();
131+
}
132+
133+
return setting;
134+
}
135+
136+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.openstreetmap.josm.plugins.rasterfilters.actions;
2+
3+
import static org.openstreetmap.josm.tools.I18n.tr;
4+
5+
import java.awt.Component;
6+
import java.awt.event.ActionEvent;
7+
import java.net.MalformedURLException;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
import javax.swing.AbstractAction;
12+
import javax.swing.JMenuItem;
13+
14+
import org.openstreetmap.josm.Main;
15+
import org.openstreetmap.josm.gui.dialogs.LayerListDialog.ShowHideLayerAction;
16+
import org.openstreetmap.josm.gui.layer.ImageryLayer;
17+
import org.openstreetmap.josm.gui.layer.Layer;
18+
import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
19+
import org.openstreetmap.josm.plugins.rasterfilters.gui.FiltersDialog;
20+
import org.openstreetmap.josm.tools.ImageProvider;
21+
22+
public final class ShowLayerFiltersDialog extends AbstractAction implements LayerAction {
23+
24+
private List<FiltersDialog> dialogs = new ArrayList<FiltersDialog>();
25+
26+
/**
27+
* Creates a {@link ShowHideLayerAction} which will toggle the visibility of
28+
* the currently selected layers
29+
*
30+
*/
31+
public ShowLayerFiltersDialog() {
32+
putValue(NAME, tr("Filters"));
33+
putValue(SHORT_DESCRIPTION, tr("Choose Filter"));
34+
putValue(SMALL_ICON, ImageProvider.get("josm_filters_48.png"));
35+
}
36+
37+
public void addFiltersDialog(FiltersDialog dialog) {
38+
dialogs.add(dialog);
39+
}
40+
41+
public void removeFiltersDialog(FiltersDialog dialog) {
42+
dialogs.remove(dialog);
43+
}
44+
45+
@Override
46+
public void actionPerformed(ActionEvent e) {
47+
48+
Layer layer = Main.map.mapView.getActiveLayer();
49+
50+
if (layer instanceof ImageryLayer) {
51+
for (FiltersDialog temp : dialogs) {
52+
53+
if (temp.getLayer().equals(layer)) {
54+
try {
55+
56+
temp.createAndShowGUI();
57+
58+
} catch (MalformedURLException e1) {
59+
e1.printStackTrace();
60+
}
61+
62+
break;
63+
}
64+
65+
}
66+
}
67+
}
68+
69+
public FiltersDialog getDialogByLayer(Layer layer) {
70+
for (FiltersDialog dialog : dialogs) {
71+
72+
if (dialog.getLayer().equals(layer)) {
73+
return dialog;
74+
}
75+
76+
}
77+
78+
return null;
79+
}
80+
81+
@Override
82+
public boolean supportLayers(List<Layer> layers) {
83+
return true;
84+
}
85+
86+
@Override
87+
public Component createMenuComponent() {
88+
return new JMenuItem(this);
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.openstreetmap.josm.plugins.rasterfilters.filters;
2+
3+
import java.awt.image.BufferedImage;
4+
import java.rmi.server.UID;
5+
6+
import javax.json.JsonObject;
7+
8+
public interface Filter {
9+
10+
public JsonObject changeFilterState(JsonObject filterState);
11+
12+
public BufferedImage applyFilter(BufferedImage img);
13+
14+
public void setId(UID id);
15+
16+
public UID getId();
17+
}

0 commit comments

Comments
 (0)