kopia lustrzana https://github.com/JOSM/MapWithAI
Add setting for maximum additions
* Also fix a bug w.r.t. closed ways Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head v0.0.6
rodzic
409ee03dfe
commit
8b7a51f121
|
@ -2,6 +2,7 @@ package org.openstreetmap.josm.plugins.rapid;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
|
@ -10,6 +11,9 @@ import javax.swing.JCheckBox;
|
|||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
|
||||
import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
||||
import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
||||
|
@ -23,18 +27,27 @@ public class RapiDPreferences implements SubPreferenceSetting {
|
|||
private final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
|
||||
private final JCheckBox switchLayerCheckBox = new JCheckBox();
|
||||
|
||||
private final JLabel maximumAddition = new JLabel(
|
||||
tr("Maximum features (add)"));
|
||||
private final JSpinner maximumAdditionSpinner = new JSpinner(
|
||||
new SpinnerNumberModel(RapiDDataUtils.getMaximumAddition(), 0, 100, 1));
|
||||
|
||||
@Override
|
||||
public void addGui(PreferenceTabbedPane gui) {
|
||||
final JPanel container = new JPanel(new GridBagLayout());
|
||||
container.setAlignmentY(JPanel.TOP_ALIGNMENT);
|
||||
final GridBagConstraints constraints = new GridBagConstraints();
|
||||
|
||||
for (String url : RapiDDataUtils.getRapiDURLs()) {
|
||||
possibleRapidApiUrl.addItem(url);
|
||||
}
|
||||
|
||||
possibleRapidApiUrl.setEditable(true);
|
||||
possibleRapidApiUrl.setPrototypeDisplayValue("https://example.url/some/end/point");
|
||||
Component textField = possibleRapidApiUrl.getEditor().getEditorComponent();
|
||||
if (textField instanceof JTextField) {
|
||||
((JTextField) textField).setColumns(36);
|
||||
}
|
||||
for (String url : RapiDDataUtils.getRapiDURLs()) {
|
||||
possibleRapidApiUrl.addItem(url);
|
||||
}
|
||||
possibleRapidApiUrl.setSelectedItem(RapiDDataUtils.getRapiDURL());
|
||||
|
||||
switchLayerCheckBox.setSelected(RapiDDataUtils.getSwitchLayers());
|
||||
|
@ -49,7 +62,6 @@ public class RapiDPreferences implements SubPreferenceSetting {
|
|||
container.add(rapidApiUrl, constraints);
|
||||
|
||||
constraints.gridx++;
|
||||
constraints.weightx = 1;
|
||||
container.add(possibleRapidApiUrl, constraints);
|
||||
|
||||
constraints.gridx--;
|
||||
|
@ -59,6 +71,12 @@ public class RapiDPreferences implements SubPreferenceSetting {
|
|||
constraints.gridx++;
|
||||
container.add(switchLayerCheckBox, constraints);
|
||||
|
||||
constraints.gridx--;
|
||||
constraints.gridy++;
|
||||
container.add(maximumAddition, constraints);
|
||||
constraints.gridx++;
|
||||
container.add(maximumAdditionSpinner, constraints);
|
||||
|
||||
getTabPreferenceSetting(gui).addSubTab(this, "RapiD", container);
|
||||
}
|
||||
|
||||
|
@ -66,6 +84,10 @@ public class RapiDPreferences implements SubPreferenceSetting {
|
|||
public boolean ok() {
|
||||
RapiDDataUtils.setRapiDUrl((String) possibleRapidApiUrl.getSelectedItem());
|
||||
RapiDDataUtils.setSwitchLayers(switchLayerCheckBox.isSelected());
|
||||
Object value = maximumAdditionSpinner.getValue();
|
||||
if (value instanceof Integer) {
|
||||
RapiDDataUtils.setMaximumAddition((Integer) value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public class AddPrimitivesCommand extends Command {
|
|||
|
||||
private static Collection<OsmPrimitive> addNodes(DataSet ds, Collection<Node> nodes) {
|
||||
Collection<OsmPrimitive> toAdd = nodes.stream().filter(node -> node.getDataSet() == null)
|
||||
.collect(Collectors.toList());
|
||||
.distinct().collect(Collectors.toList());
|
||||
toAdd.stream().forEach(ds::addPrimitive);
|
||||
return toAdd;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class AddPrimitivesCommand extends Command {
|
|||
private static Collection<OsmPrimitive> addWays(DataSet ds, Collection<Way> ways) {
|
||||
Collection<OsmPrimitive> toAdd = new ArrayList<>();
|
||||
ways.stream().map(Way::getNodes).forEach(list -> toAdd.addAll(addNodes(ds, list)));
|
||||
ways.stream()
|
||||
ways.stream().distinct()
|
||||
.filter(way -> way.getDataSet() == null
|
||||
&& way.getNodes().stream().filter(node -> node.getDataSet() != ds).count() == 0)
|
||||
.forEach(way -> {
|
||||
|
@ -91,7 +91,7 @@ public class AddPrimitivesCommand extends Command {
|
|||
|
||||
// This might break with relations. TODO (not needed right now)
|
||||
private static Collection<OsmPrimitive> addRelations(DataSet ds, Collection<Relation> relations) {
|
||||
Collection<OsmPrimitive> toAdd = relations.stream().filter(relation -> relation.getDataSet() != null)
|
||||
Collection<OsmPrimitive> toAdd = relations.stream().distinct().filter(relation -> relation.getDataSet() != null)
|
||||
.collect(Collectors.toList());
|
||||
toAdd.forEach(ds::addPrimitive);
|
||||
return toAdd;
|
||||
|
|
|
@ -218,4 +218,23 @@ public final class RapiDDataUtils {
|
|||
public static boolean getSwitchLayers() {
|
||||
return Config.getPref().getBoolean(RapiDPlugin.NAME.concat(".autoswitchlayers"), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of objects that can be added at one time
|
||||
*
|
||||
* @return The maximum selection. If 0, allow any number.
|
||||
*/
|
||||
public static int getMaximumAddition() {
|
||||
return Config.getPref().getInt(RapiDPlugin.NAME.concat(".maximumselection"), 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of objects that can be added at one time.
|
||||
*
|
||||
* @param max The maximum number of objects to select (0 allows any number to be
|
||||
* selected).
|
||||
*/
|
||||
public static void setMaximumAddition(int max) {
|
||||
Config.getPref().putInt(RapiDPlugin.NAME.concat(".maximumselection"), max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,13 @@ public class RapiDMoveAction extends JosmAction {
|
|||
for (RapiDLayer rapid : MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class)) {
|
||||
List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
||||
OsmDataLayer editLayer = null;
|
||||
Collection<OsmPrimitive> selected = rapid.getDataSet().getSelected();
|
||||
int maxAddition = RapiDDataUtils.getMaximumAddition();
|
||||
Collection<OsmPrimitive> selected;
|
||||
if (maxAddition > 0) {
|
||||
selected = rapid.getDataSet().getSelected().stream().limit(maxAddition).collect(Collectors.toList());
|
||||
} else {
|
||||
selected = rapid.getDataSet().getSelected();
|
||||
}
|
||||
for (OsmDataLayer osmLayer : osmLayers) {
|
||||
if (!osmLayer.isLocked() && osmLayer.isVisible() && osmLayer.isUploadable()
|
||||
&& osmLayer.getClass().equals(OsmDataLayer.class)) {
|
||||
|
|
Ładowanie…
Reference in New Issue