Skip to content

Commit

Permalink
Replace calls to deprecated JOSM API with the recommended replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed Sep 20, 2018
1 parent 9715681 commit 3cb556d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ josm {
tasks.withType(Javadoc) {
failOnError false
}

tasks.withType(JavaCompile) {
options.compilerArgs += [
"-Xlint:all",
"-Xlint:-serial",
]
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugin.icon=images/preferences/fieldpapers.png
plugin.link=http://wiki.openstreetmap.org/index.php/JOSM/Plugins/FieldPapers
# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
# You can check if the plugin compiles against this version by executing `./gradlew minJosmVersionClasses`.
plugin.main.version=12643
plugin.main.version=14140
# Version of JOSM against which the plugin is compiled
# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
# If not, choose the next higher number that is available, or the gradle build will break.
plugin.compile.version=13265
plugin.compile.version=14178
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.coor.LatLon;
Expand All @@ -42,11 +41,11 @@ public void actionPerformed(ActionEvent e) {

// snapshot URL selection
panel.add(new JLabel(tr("Enter a fieldpapers.org snapshot URL to download from")), GBC.eol());
JosmTextField snapshotAddress = new JosmTextField(Main.pref.get("fieldpapers.last-used-id"));
JosmTextField snapshotAddress = new JosmTextField(FieldPapersPlugin.LAST_USED_ID.get());
snapshotAddress.setToolTipText(tr("Enter an URL from where scanned map should be downloaded"));
panel.add(snapshotAddress, GBC.eop().fill(GBC.BOTH));

ExtendedDialog dialog = new ExtendedDialog(Main.parent,
ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(),
tr("Download Snapshot"),
tr("Download"), tr("Cancel"))
.setContent(panel, false)
Expand All @@ -64,7 +63,7 @@ public void openUrl(String url) {
if (url == null || url.equals("")) return;

if (!url.startsWith("http")) {
url = Main.pref.get("fieldpapers-base-url", "http://fieldpapers.org/") + "snapshots/" + url;
url = FieldPapersPlugin.BASE_URL.get() + "snapshots/" + url;
}

try {
Expand All @@ -88,7 +87,7 @@ public void openUrl(String url) {
double north = bounds.getJsonNumber(3).doubleValue();

// save this atlas as the
Main.pref.put("fieldpapers.last-used-id", id);
FieldPapersPlugin.LAST_USED_ID.put(id);

Bounds b = new Bounds(new LatLon(south, west), new LatLon(north, east));

Expand All @@ -97,7 +96,7 @@ public void openUrl(String url) {

} catch (IOException ex) {
Logging.error(ex);
JOptionPane.showMessageDialog(Main.parent,tr("Could not read information for the id \"{0}\" from fieldpapers.org", url));
JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Could not read information for the id \"{0}\" from fieldpapers.org", url));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import javax.swing.JMenuItem;

import org.openstreetmap.josm.data.Preferences;
import org.openstreetmap.josm.data.preferences.StringProperty;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.plugins.Plugin;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.tools.Logging;

/**
* Main class for the field papers plugin.
Expand All @@ -14,8 +17,21 @@
*
*/
public class FieldPapersPlugin extends Plugin {
public static final StringProperty LAST_USED_ID = new StringProperty("fieldpapers.last-used-id", "");

public static final StringProperty BASE_URL = new StringProperty("fieldpapers.base-url", "http://fieldpapers.org/");

public FieldPapersPlugin(PluginInformation info) {
super(info);

// Migrate old setting, remove this in one of the next versions.
final String oldValue = Preferences.main().get("fieldpapers-base-url");
if (!"".equals(oldValue) && !BASE_URL.isSet()) {
BASE_URL.put(oldValue);
Preferences.main().put("fieldpapers-base-url", null);
Logging.info("Preference `fieldpapers-base-url`={0} was renamed to `fieldpapers.base-url`!", oldValue);
}

MainApplication.getMenu().imageryMenu.add(new JMenuItem(new FieldPapersAddLayerAction()));
}
}

0 comments on commit 3cb556d

Please sign in to comment.