Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKarlas committed Oct 9, 2021
0 parents commit 78c11b8
Show file tree
Hide file tree
Showing 14 changed files with 1,147 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
build
bin
.gradle
gradlew
gradlew.bat
gradle
.settings
.project
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
// First run "./gradlew debugJosm" in terminal
// Then start debugging in VSCode to attach to that session
"type": "java",
"name": "Debug",
"request": "attach",
"hostName": "localhost",
"port": 2019
}
]
}
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# JOSM plugin for reviewing changes before upload

Main montivation for this plugin was semi-automatic import of [addresses/buildings in Slovenia](https://wiki.openstreetmap.org/wiki/Slovenia_Address_Import). We created [tool](https://github.com/DavidKarlas/GursAddressesForOSM/tree/master/OsmGursBuildingImport) that generated changeset for mapper to use for import, but mapper needs to review all buildings before uploading, because source can have demolished buildings or misaligned/wrong size...

Reviewing changes was hard, hence this plugin was created which allows quick navigation between changes on ways/relations ignoring untagged nodes.

## How to install



## How to develop

We use [Gradle plugin for developing JOSM plugins](https://github.com/floscher/gradle-josm-plugin) which simplifies things...
* Install Gradle https://gradle.org/install/
* Run `gradle w` to create wrapper in repo
* Run `./gradlew runJosm` to compile and run JOSM which loads plugin

### Debugging

* Run `./gradlew debugJosm`
* In VSCode start debugging

What this will do is start JOSM with listening for debugger to connect on port 2019, and VSCode will connect to that port and start debugging.

## License
Since [JOSM](https://github.com/JOSM/josm) itself is GPL 3.0 it makes sense for this plugin to be too.
30 changes: 30 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id("org.openstreetmap.josm").version("0.7.1")
id("java")
}

sourceSets {
main {
java {
srcDir("src").include("org/openstreetmap/**")
}
resources {
srcDir(".").include("images/**/*.svg")
}
}
}

josm {
pluginName = "Review Changes"
debugPort = 2019
josmCompileVersion = "18193"
manifest {
version = "1.0.0"
description = "JOSM plugin for reviewing changes."
mainClass = "org.openstreetmap.josm.plugins.davidkarlas.JosmReviewPlugin.JosmReviewPlugin"
minJosmVersion = "18193"
author = "David Karlaš"
canLoadAtRuntime = true
iconPath = "dialogs/reviewPlugin/icon"
}
}
9 changes: 9 additions & 0 deletions images/dialogs/reviewPlugin/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/reviewplugin/ReviewedItem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/reviewplugin/UnReviewedItem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.openstreetmap.josm.plugins.davidkarlas.JosmReviewPlugin;

import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.MainMenu;
import org.openstreetmap.josm.plugins.Plugin;
import org.openstreetmap.josm.plugins.PluginInformation;

public class JosmReviewPlugin extends Plugin {
StartReviewAction startReviewAction;
public JosmReviewPlugin(PluginInformation info) {
super(info);

startReviewAction = new StartReviewAction();
MainMenu.add(MainApplication.getMenu().toolsMenu, startReviewAction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.openstreetmap.josm.plugins.davidkarlas.JosmReviewPlugin;

import org.openstreetmap.josm.data.osm.OsmPrimitive;

public class ReviewItem {
private OsmPrimitive item;
private boolean reviewed;
private boolean onlyChildChanged;

public ReviewItem(OsmPrimitive item, boolean reviewed, boolean onlyChildChanged) {
this.item = item;
this.reviewed = reviewed;
this.onlyChildChanged = onlyChildChanged;
}

public boolean isOnlyChildChanged() {
return onlyChildChanged;
}

public OsmPrimitive getItem() {
return item;
}

public boolean getReviewed() {
return reviewed;
}

public void ToggleReviewed() {
reviewed = !reviewed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.openstreetmap.josm.plugins.davidkarlas.JosmReviewPlugin;

import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;

public class ReviewItemRenderer implements ListCellRenderer<ReviewItem> {

private final DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer();
private final DefaultNameFormatter formatter = DefaultNameFormatter.getInstance();
private ImageIcon okImageIcon = new ImageProvider("reviewplugin/ReviewedItem").setSize(ImageSizes.SMALLICON).get();
private ImageIcon cancelImageIcon = new ImageProvider("reviewplugin/UnReviewedItem").setSize(ImageSizes.SMALLICON).get();

@Override
public Component getListCellRendererComponent(JList<? extends ReviewItem> list, ReviewItem item, int index,
boolean isSelected, boolean cellHasFocus) {
Component comp = defaultListCellRenderer.getListCellRendererComponent(list, item, index, isSelected,
cellHasFocus);
if (item != null && comp instanceof JLabel) {
OsmPrimitive osm = item.getItem();
JLabel jlabel = (JLabel) comp;
jlabel.setText((item.isOnlyChildChanged() ? "moved" : "modifed") + ": " + formatter.format(osm));
jlabel.setToolTipText(formatter.buildDefaultToolTip(osm));
jlabel.setIcon(item.getReviewed() ? okImageIcon : cancelImageIcon);
}
return comp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.openstreetmap.josm.plugins.davidkarlas.JosmReviewPlugin;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.LinkedList;
import java.util.List;
import java.awt.event.MouseEvent;

import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;

import java.awt.event.MouseAdapter;

import org.openstreetmap.josm.data.APIDataSet;
import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.SideButton;
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
import org.openstreetmap.josm.gui.util.HighlightHelper;
import org.openstreetmap.josm.tools.Shortcut;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class ReviewListDialog extends ToggleDialog {

private JList<ReviewItem> displayList;
private ReviewListModel model = new ReviewListModel();
private final HighlightHelper highlightHelper = new HighlightHelper();

public ReviewListDialog() {
super(tr("Review List"), "reviewPlugin/icon", tr("Open the review list window."),
Shortcut.registerShortcut("subwindow:reviewchanges", tr("Windows: {0}", tr("Review List")),
KeyEvent.VK_E, Shortcut.ALT_SHIFT),
350, false);

List<SideButton> buttons = new LinkedList<>();

displayList = new JList<>(model);
displayList.setCellRenderer(new ReviewItemRenderer());
displayList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
displayList.addListSelectionListener(e -> {
ZoomToSelectedItem();
});
displayList.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
ZoomToSelectedItem();
}

@Override
public void focusLost(FocusEvent e) {
highlightHelper.clear();
}
});

displayList.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getExtendedKeyCode() == KeyEvent.VK_SPACE) {
ReviewItem sel = displayList.getSelectedValue();
if (sel == null)
return;
model.ToggleReviewed(sel);
}
}

@Override
public void keyPressed(KeyEvent e) {

}

@Override
public void keyReleased(KeyEvent e) {

}
});

displayList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
ReviewItem sel = displayList.getSelectedValue();
if (sel == null)
return;
model.ToggleReviewed(sel);
}
}
});
createLayout(displayList, true, buttons);
}

protected void ZoomToSelectedItem() {
BoundingXYVisitor v = new BoundingXYVisitor();
ReviewItem sel = displayList.getSelectedValue();
if (sel == null)
return;
sel.getItem().accept((OsmPrimitiveVisitor) v);
if (v.getBounds() == null)
return;
MainApplication.getMap().mapView.zoomTo(v);
highlightHelper.highlightOnly(sel.getItem());
}

public void setData(APIDataSet apiData) {
model.UpdateData(apiData);
}
}
Loading

0 comments on commit 78c11b8

Please sign in to comment.