use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.
the class AddNodeAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (!isEnabled())
return;
// #17682 - Run the action later in EDT to make sure the KeyEvent triggering it is consumed before the dialog is shown
SwingUtilities.invokeLater(() -> {
LatLonDialog dialog = new LatLonDialog(MainApplication.getMainFrame(), tr("Add Node..."), ht("/Action/AddNode"));
if (textLatLon != null) {
dialog.setLatLonText(textLatLon);
}
if (textEastNorth != null) {
dialog.setEastNorthText(textEastNorth);
}
dialog.showDialog();
if (dialog.getValue() != 1)
return;
LatLon coordinates = dialog.getCoordinates();
if (coordinates == null)
return;
textLatLon = dialog.getLatLonText();
textEastNorth = dialog.getEastNorthText();
Node nnew = new Node(coordinates);
// add the node
DataSet ds = getLayerManager().getEditDataSet();
UndoRedoHandler.getInstance().add(new AddCommand(ds, nnew));
ds.setSelected(nnew);
MapView mapView = MainApplication.getMap().mapView;
if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
}
});
}
use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.
the class CombineWayAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
final DataSet ds = getLayerManager().getEditDataSet();
if (ds == null)
return;
Collection<Way> selectedWays = new LinkedHashSet<>(ds.getSelectedWays());
selectedWays.removeIf(Way::isEmpty);
if (selectedWays.size() < 2) {
new Notification(tr("Please select at least two ways to combine.")).setIcon(JOptionPane.INFORMATION_MESSAGE).setDuration(Notification.TIME_SHORT).show();
return;
}
// see #18083: check if we will combine ways at nodes outside of the download area
Set<Node> endNodesOutside = new HashSet<>();
for (Way w : selectedWays) {
final Node[] endnodes = { w.firstNode(), w.lastNode() };
for (Node n : endnodes) {
if (!n.isNew() && n.isOutsideDownloadArea() && !endNodesOutside.add(n)) {
new Notification(tr("Combine ways refused<br>" + "(A shared node is outside of the download area)")).setIcon(JOptionPane.INFORMATION_MESSAGE).show();
return;
}
}
}
// combine and update gui
Pair<Way, Command> combineResult;
try {
combineResult = combineWaysWorker(selectedWays);
} catch (UserCancelException ex) {
Logging.trace(ex);
return;
}
if (combineResult == null)
return;
final Way selectedWay = combineResult.a;
UndoRedoHandler.getInstance().add(combineResult.b);
Test test = new OverlappingWays();
test.startTest(null);
test.visit(combineResult.a);
test.endTest();
if (test.getErrors().isEmpty()) {
test = new SelfIntersectingWay();
test.startTest(null);
test.visit(combineResult.a);
test.endTest();
}
if (!test.getErrors().isEmpty()) {
new Notification(test.getErrors().get(0).getMessage()).setIcon(JOptionPane.WARNING_MESSAGE).setDuration(Notification.TIME_SHORT).show();
}
if (selectedWay != null) {
GuiHelper.runInEDT(() -> ds.setSelected(selectedWay));
}
}
use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.
the class CopyAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
DataSet set = getLayerManager().getActiveDataSet();
Collection<OsmPrimitive> selection = set == null ? Collections.<OsmPrimitive>emptySet() : set.getSelected();
if (selection.isEmpty()) {
showEmptySelectionWarning();
return;
}
copy(getLayerManager().getActiveDataLayer(), selection);
}
use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.
the class ConflictResolveCommand method undoCommand.
@Override
public void undoCommand() {
super.undoCommand();
DataSet ds = getAffectedDataSet();
if (!OsmDataManager.getInstance().containsDataSet(ds)) {
Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", this.toString(), ds.getName()));
return;
}
OsmDataManager.getInstance().setActiveDataSet(ds);
reconstituteConflicts();
}
use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.
the class UndoRedoHandler method undo.
/**
* Undoes multiple commands.
* @param num The number of commands to undo
*/
public synchronized void undo(int num) {
if (commands.isEmpty())
return;
GuiHelper.runInEDTAndWait(() -> {
DataSet ds = OsmDataManager.getInstance().getEditDataSet();
if (ds != null) {
ds.beginUpdate();
}
try {
for (int i = 1; i <= num; ++i) {
final Command c = commands.removeLast();
try {
c.undoCommand();
} catch (Exception e) {
// NOPMD
// fix #20098: restore command stack as we will not fire an event
commands.add(c);
throw e;
}
redoCommands.addFirst(c);
fireEvent(new CommandUndoneEvent(this, c));
if (commands.isEmpty()) {
break;
}
}
} finally {
if (ds != null) {
ds.endUpdate();
}
}
fireCommandsChanged();
});
}
Aggregations