public void actionPerformed(ActionEvent e) {
LinkedList<Way> ways = new LinkedList<>(Main.main.getCurrentDataSet().getSelectedWays());
addedRelations.clear();
if (ways.isEmpty()) {
new Notification(
tr("Please select at least one closed way that should be joined."))
.setIcon(JOptionPane.INFORMATION_MESSAGE)
.show();
return;
}
List<Node> allNodes = new ArrayList<>();
for (Way way : ways) {
if (!way.isClosed()) {
new Notification(
tr("One of the selected ways is not closed and therefore cannot be joined."))
.setIcon(JOptionPane.INFORMATION_MESSAGE)
.show();
return;
}
allNodes.addAll(way.getNodes());
}
// TODO: Only display this warning when nodes outside dataSourceArea are deleted
boolean ok = Command.checkAndConfirmOutlyingOperation("joinarea", tr("Join area confirmation"),
trn("The selected way has nodes outside of the downloaded data region.",
"The selected ways have nodes outside of the downloaded data region.",
ways.size()) + "<br/>"
+ tr("This can lead to nodes being deleted accidentally.") + "<br/>"
+ tr("Are you really sure to continue?")
+ tr("Please abort if you are not sure"),
tr("The selected area is incomplete. Continue?"),
allNodes, null);
if(!ok) return;
//analyze multipolygon relations and collect all areas
List<Multipolygon> areas = collectMultipolygons(ways);
if (areas == null)
//too complex multipolygon relations found
return;
if (!testJoin(areas)) {
new Notification(
tr("No intersection found. Nothing was changed."))
.setIcon(JOptionPane.INFORMATION_MESSAGE)
.show();
return;
}
if (!resolveTagConflicts(areas))
return;
//user canceled, do nothing.
try {
JoinAreasResult result = joinAreas(areas);
if (result.hasChanges) {
// move tags from ways to newly created relations
// TODO: do we need to also move tags for the modified relations?
for (Relation r: addedRelations) {
cmds.addAll(CreateMultipolygonAction.removeTagsFromWaysIfNeeded(r));
}
commitCommands(tr("Move tags from ways to relations"));
List<Way> allWays = new ArrayList<>();
for (Multipolygon pol : result.polygons) {
allWays.add(pol.outerWay);
allWays.addAll(pol.innerWays);
}
DataSet ds = Main.main.getCurrentDataSet();
ds.setSelected(allWays);
Main.map.mapView.repaint();
} else {
new Notification(
tr("No intersection found. Nothing was changed."))
.setIcon(JOptionPane.INFORMATION_MESSAGE)
.show();
}
}