kopia lustrzana https://github.com/JOSM/MapWithAI
Add icons to everything that can have an icon
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head v0.2.0
rodzic
744490d0ed
commit
b72da6c6c3
|
@ -63,23 +63,22 @@ public class MapWithAIPreferences implements SubPreferenceSetting {
|
|||
private static void fillReplacementTagDisplayData(List<PrefEntry> list) {
|
||||
final Map<String, String> current = new TreeMap<>(MapWithAIPreferenceHelper.getReplacementTags());
|
||||
for (final Entry<String, String> entry : current.entrySet()) {
|
||||
list.add(new PrefEntry(entry.getKey(), new StringSetting(entry.getValue()), new StringSetting(null), false));
|
||||
list.add(
|
||||
new PrefEntry(entry.getKey(), new StringSetting(entry.getValue()), new StringSetting(null), false));
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillMapWithAIURLTableDisplayData(List<DataUrl> list) {
|
||||
MapWithAIPreferenceHelper.getMapWithAIURLs()
|
||||
.forEach(
|
||||
entry -> list
|
||||
.add(new DataUrl(entry.get(SOURCE), entry.get("url"),
|
||||
.forEach(entry -> list.add(new DataUrl(entry.get(SOURCE), entry.get("url"),
|
||||
Boolean.valueOf(entry.getOrDefault("enabled", "false")),
|
||||
entry.getOrDefault("parameters", "[]"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGui(PreferenceTabbedPane gui) {
|
||||
int width = 200;
|
||||
int height = 200;
|
||||
final int width = 200;
|
||||
final int height = 200;
|
||||
final JLabel mapWithAIApiUrl = new JLabel(tr("{0} API URLs", MapWithAIPlugin.NAME));
|
||||
final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
|
||||
final JLabel maximumAddition = new JLabel(tr("Maximum features (add)"));
|
||||
|
@ -104,9 +103,9 @@ public class MapWithAIPreferences implements SubPreferenceSetting {
|
|||
pane.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||
pane.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
|
||||
GBC first = GBC.std().weight(0, 1).anchor(GridBagConstraints.WEST);
|
||||
GBC second = GBC.eol().fill(GridBagConstraints.HORIZONTAL);
|
||||
GBC buttonInsets = GBC.std().insets(5, 5, 0, 0);
|
||||
final GBC first = GBC.std().weight(0, 1).anchor(GridBagConstraints.WEST);
|
||||
final GBC second = GBC.eol().fill(GridBagConstraints.HORIZONTAL);
|
||||
final GBC buttonInsets = GBC.std().insets(5, 5, 0, 0);
|
||||
|
||||
pane.add(mapWithAIApiUrl, first);
|
||||
|
||||
|
@ -116,7 +115,7 @@ public class MapWithAIPreferences implements SubPreferenceSetting {
|
|||
scroll1.setPreferredSize(new Dimension(width, height));
|
||||
|
||||
pane.add(new JLabel(), first);
|
||||
JPanel replaceAddEditDeleteScroll1 = new JPanel(new GridBagLayout());
|
||||
final JPanel replaceAddEditDeleteScroll1 = new JPanel(new GridBagLayout());
|
||||
pane.add(replaceAddEditDeleteScroll1, second);
|
||||
final JButton addScroll1 = new JButton(tr("Add"));
|
||||
replaceAddEditDeleteScroll1.add(addScroll1, buttonInsets);
|
||||
|
@ -135,7 +134,7 @@ public class MapWithAIPreferences implements SubPreferenceSetting {
|
|||
final JButton deleteScroll1 = new JButton(tr("Delete"));
|
||||
replaceAddEditDeleteScroll1.add(deleteScroll1, buttonInsets);
|
||||
deleteScroll1.addActionListener(e -> {
|
||||
List<DataUrl> toRemove = mapwithaiUrlPreferenceTable.getSelectedItems();
|
||||
final List<DataUrl> toRemove = mapwithaiUrlPreferenceTable.getSelectedItems();
|
||||
if (!toRemove.isEmpty()) {
|
||||
mapwithaiurlTableDisplayData.removeAll(toRemove);
|
||||
}
|
||||
|
@ -163,13 +162,13 @@ public class MapWithAIPreferences implements SubPreferenceSetting {
|
|||
scroll2.setPreferredSize(new Dimension(width, height));
|
||||
|
||||
pane.add(new JLabel(), first);
|
||||
JPanel replaceAddEditDeleteScroll2 = new JPanel(new GridBagLayout());
|
||||
final JPanel replaceAddEditDeleteScroll2 = new JPanel(new GridBagLayout());
|
||||
pane.add(replaceAddEditDeleteScroll2, second);
|
||||
final JButton addScroll2 = new JButton(tr("Add"));
|
||||
replaceAddEditDeleteScroll2.add(addScroll2, buttonInsets);
|
||||
addScroll2.addActionListener(e -> {
|
||||
final PrefEntry pe = replacementPreferenceTable.addPreference(gui);
|
||||
if (pe != null && pe.getValue() instanceof StringSetting) {
|
||||
if ((pe != null) && (pe.getValue() instanceof StringSetting)) {
|
||||
replacementTableDisplayData.add(pe);
|
||||
Collections.sort(replacementTableDisplayData);
|
||||
replacementPreferenceTable.fireDataChanged();
|
||||
|
@ -196,18 +195,19 @@ public class MapWithAIPreferences implements SubPreferenceSetting {
|
|||
});
|
||||
|
||||
Arrays.asList(replaceAddEditDeleteScroll2, scroll2, expertHorizontalGlue, replacementTags)
|
||||
.forEach(ExpertToggleAction::addVisibilitySwitcher);
|
||||
.forEach(ExpertToggleAction::addVisibilitySwitcher);
|
||||
|
||||
getTabPreferenceSetting(gui).addSubTab(this, MapWithAIPlugin.NAME, pane);
|
||||
getTabPreferenceSetting(gui).addSubTab(this, MapWithAIPlugin.NAME, pane,
|
||||
tr("{0} preferences", MapWithAIPlugin.NAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ok() {
|
||||
ArrayList<DataUrl> tData = new ArrayList<>(
|
||||
final ArrayList<DataUrl> tData = new ArrayList<>(
|
||||
mapwithaiurlTableDisplayData.stream().distinct()
|
||||
.filter(data -> !data.getMap().getOrDefault("url", "http://example.com")
|
||||
.equalsIgnoreCase(DataUrl.emptyData().getMap().get("url")))
|
||||
.collect(Collectors.toList()));
|
||||
.filter(data -> !data.getMap().getOrDefault("url", "http://example.com")
|
||||
.equalsIgnoreCase(DataUrl.emptyData().getMap().get("url")))
|
||||
.collect(Collectors.toList()));
|
||||
mapwithaiurlTableDisplayData.clear();
|
||||
mapwithaiurlTableDisplayData.addAll(tData);
|
||||
MapWithAIPreferenceHelper.setMapWithAIURLs(convertUrlPrefToMap(mapwithaiurlTableDisplayData));
|
||||
|
|
|
@ -27,15 +27,14 @@ import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
||||
import org.openstreetmap.josm.tools.Shortcut;
|
||||
|
||||
|
||||
public class MapWithAIAction extends JosmAction {
|
||||
/** UID */
|
||||
private static final long serialVersionUID = 8886705479253246588L;
|
||||
|
||||
public MapWithAIAction() {
|
||||
super(tr("{0}: Download data", MapWithAIPlugin.NAME), null, tr("Get data from {0}", MapWithAIPlugin.NAME),
|
||||
Shortcut.registerShortcut("data:mapWithAI", tr("Data: {0}", MapWithAIPlugin.NAME), KeyEvent.VK_R,
|
||||
Shortcut.CTRL),
|
||||
super(tr("{0}: Download data", MapWithAIPlugin.NAME), "mapwithai",
|
||||
tr("Get data from {0}", MapWithAIPlugin.NAME), Shortcut.registerShortcut("data:mapWithAI",
|
||||
tr("Data: {0}", MapWithAIPlugin.NAME), KeyEvent.VK_R, Shortcut.CTRL),
|
||||
true);
|
||||
setHelpId(ht("Plugin/MapWithAI#BasicUsage"));
|
||||
}
|
||||
|
@ -48,12 +47,12 @@ public class MapWithAIAction extends JosmAction {
|
|||
.stream().filter(layer -> !(layer instanceof MapWithAILayer)).filter(Layer::isVisible)
|
||||
.collect(Collectors.toList());
|
||||
final OsmDataLayer layer = getOsmLayer(osmLayers);
|
||||
if (layer != null && MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true), layer)) {
|
||||
Notification notification = createMessageDialog();
|
||||
if ((layer != null) && MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true), layer)) {
|
||||
final Notification notification = createMessageDialog();
|
||||
if (notification != null) {
|
||||
notification.show();
|
||||
}
|
||||
} else if (layer != null && hasLayer) {
|
||||
} else if ((layer != null) && hasLayer) {
|
||||
toggleLayer(layer);
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +87,9 @@ public class MapWithAIAction extends JosmAction {
|
|||
final OsmDataLayer mapwithai = MapWithAIDataUtils.getLayer(false);
|
||||
final Layer currentLayer = MainApplication.getLayerManager().getActiveLayer();
|
||||
if (currentLayer != null) {
|
||||
if (currentLayer.equals(mapwithai) && toLayer != null) {
|
||||
if (currentLayer.equals(mapwithai) && (toLayer != null)) {
|
||||
MainApplication.getLayerManager().setActiveLayer(toLayer);
|
||||
} else if (currentLayer.equals(toLayer) && mapwithai != null) {
|
||||
} else if (currentLayer.equals(toLayer) && (mapwithai != null)) {
|
||||
MainApplication.getLayerManager().setActiveLayer(mapwithai);
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +113,8 @@ public class MapWithAIAction extends JosmAction {
|
|||
final List<Bounds> bounds = new ArrayList<>(layer.getDataSet().getDataSourceBounds());
|
||||
if (bounds.isEmpty()) {
|
||||
MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
|
||||
.map(OsmDataLayer::getDataSet).filter(Objects::nonNull).map(DataSet::getDataSourceBounds)
|
||||
.forEach(bounds::addAll);
|
||||
.map(OsmDataLayer::getDataSet).filter(Objects::nonNull).map(DataSet::getDataSourceBounds)
|
||||
.forEach(bounds::addAll);
|
||||
}
|
||||
final StringBuilder message = new StringBuilder();
|
||||
message.append(MapWithAIPlugin.NAME).append(": ");
|
||||
|
@ -123,7 +122,7 @@ public class MapWithAIAction extends JosmAction {
|
|||
final Map<String, Boolean> availableTypes = new TreeMap<>();
|
||||
for (final Bounds bound : bounds) {
|
||||
availability.getDataTypes(bound.getCenter())
|
||||
.forEach((type, available) -> availableTypes.merge(type, available, Boolean::logicalOr));
|
||||
.forEach((type, available) -> availableTypes.merge(type, available, Boolean::logicalOr));
|
||||
}
|
||||
final List<String> types = availableTypes.entrySet().stream().filter(Entry::getValue)
|
||||
.map(entry -> MapWithAIAvailability.getPossibleDataTypesAndMessages().get(entry.getKey()))
|
||||
|
|
|
@ -48,10 +48,11 @@ public class MapWithAIArbitraryAction extends JosmAction {
|
|||
private static final String ARBITRARY_DATA_STRING = tr("Get arbitrary data from {0}", MapWithAIPlugin.NAME);
|
||||
|
||||
public MapWithAIArbitraryAction() {
|
||||
super(tr("{0}: Download arbitrary data", MapWithAIPlugin.NAME), null, tr(ARBITRARY_DATA_STRING),
|
||||
super(tr("{0}: Download arbitrary data", MapWithAIPlugin.NAME), "mapwithai", tr(ARBITRARY_DATA_STRING),
|
||||
Shortcut.registerShortcut("data:arbitrarymapwithai",
|
||||
tr("Data: Arbitrary {0} Data", tr(ARBITRARY_DATA_STRING)), KeyEvent.VK_R,
|
||||
Shortcut.ALT_CTRL_SHIFT), true);
|
||||
Shortcut.ALT_CTRL_SHIFT),
|
||||
true);
|
||||
setHelpId(ht("Plugin/MapWithAI#BasicUsage"));
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,7 @@ public class MapWithAIArbitraryAction extends JosmAction {
|
|||
bbox = new BBox();
|
||||
bbox.add(new LatLon(Double.parseDouble(lowerLat.getText()), Double.parseDouble(leftLon.getText())));
|
||||
bbox.add(new LatLon(Double.parseDouble(upperLat.getText()), Double.parseDouble(rightLon.getText())));
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (final NumberFormatException e) {
|
||||
JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
|
||||
tr("Could not parse Latitude or Longitude. Please check."), tr("Unable to parse Lon/Lat"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
@ -126,8 +127,9 @@ public class MapWithAIArbitraryAction extends JosmAction {
|
|||
}
|
||||
|
||||
if (checkbox.isSelected()) {
|
||||
MainApplication.getLayerManager().addLayer(new GpxLayer(
|
||||
DetectTaskingManagerUtils.createTaskingManagerGpxData(bbox), DetectTaskingManagerUtils.MAPWITHAI_CROP_AREA));
|
||||
MainApplication.getLayerManager()
|
||||
.addLayer(new GpxLayer(DetectTaskingManagerUtils.createTaskingManagerGpxData(bbox),
|
||||
DetectTaskingManagerUtils.MAPWITHAI_CROP_AREA));
|
||||
}
|
||||
|
||||
MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true), bbox);
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
@ -27,6 +28,7 @@ import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
||||
import org.openstreetmap.josm.spi.preferences.Config;
|
||||
import org.openstreetmap.josm.tools.GBC;
|
||||
import org.openstreetmap.josm.tools.ImageProvider;
|
||||
|
||||
/**
|
||||
* @author Taylor Smock
|
||||
|
@ -145,7 +147,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
|
|||
@Override
|
||||
public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
|
||||
if (checkIfToggleLayer()) {
|
||||
StyleSource style = MapWithAIDataUtils.getMapWithAIPaintStyle();
|
||||
final StyleSource style = MapWithAIDataUtils.getMapWithAIPaintStyle();
|
||||
if (style.active != this.equals(MainApplication.getLayerManager().getActiveLayer())) {
|
||||
MapPaintStyles.toggleStyleActive(MapPaintStyles.getStyles().getStyleSources().indexOf(style));
|
||||
}
|
||||
|
@ -153,7 +155,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
|
|||
}
|
||||
|
||||
private static boolean checkIfToggleLayer() {
|
||||
List<String> keys = Config.getPref().getKeySet().parallelStream()
|
||||
final List<String> keys = Config.getPref().getKeySet().parallelStream()
|
||||
.filter(string -> string.contains(MapWithAIPlugin.NAME) && string.contains("boolean:toggle_with_layer"))
|
||||
.collect(Collectors.toList());
|
||||
boolean toggle = false;
|
||||
|
@ -168,4 +170,9 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
|
|||
super.destroy();
|
||||
MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageIcon getIcon() {
|
||||
return ImageProvider.get("mapwithai", ImageProvider.ImageSizes.LAYER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
private transient Notification lastNotification;
|
||||
|
||||
public MapWithAIMoveAction() {
|
||||
super(tr("{0}: Add selected data", MapWithAIPlugin.NAME), null, tr("Add data from {0}", MapWithAIPlugin.NAME),
|
||||
obtainShortcut(), true);
|
||||
super(tr("{0}: Add selected data", MapWithAIPlugin.NAME), "mapwithai",
|
||||
tr("Add data from {0}", MapWithAIPlugin.NAME), obtainShortcut(), true);
|
||||
setHelpId(ht("Plugin/MapWithAI#BasicUsage"));
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,10 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
private static Shortcut obtainShortcut() {
|
||||
int key = KeyEvent.VK_A;
|
||||
int modifier = Shortcut.SHIFT;
|
||||
String shortText = "data:mapwithaiadd";
|
||||
Optional<Shortcut> shortCut = Shortcut.findShortcut(key, InputEvent.SHIFT_DOWN_MASK); // Shortcut.SHIFT maps to
|
||||
// KeyEvent.SHIFT_DOWN_MASK
|
||||
final String shortText = "data:mapwithaiadd";
|
||||
final Optional<Shortcut> shortCut = Shortcut.findShortcut(key, InputEvent.SHIFT_DOWN_MASK); // Shortcut.SHIFT
|
||||
// maps to
|
||||
// KeyEvent.SHIFT_DOWN_MASK
|
||||
if (shortCut.isPresent() && !shortText.equals(shortCut.get().getShortText())) {
|
||||
key = KeyEvent.VK_C;
|
||||
modifier = Shortcut.ALT;
|
||||
|
@ -94,7 +95,7 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
final Notification notification = new Notification();
|
||||
final StringBuilder message = new StringBuilder();
|
||||
message.append(MapWithAIPlugin.NAME).append(": ").append(tr("maximum additions per action are "))
|
||||
.append(maxAddition).append(", ").append(tr("tried to add ")).append(triedToAdd).append('.');
|
||||
.append(maxAddition).append(", ").append(tr("tried to add ")).append(triedToAdd).append('.');
|
||||
notification.setContent(message.toString());
|
||||
notification.setDuration(Notification.TIME_DEFAULT);
|
||||
notification.setIcon(JOptionPane.INFORMATION_MESSAGE);
|
||||
|
@ -112,7 +113,7 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
|
||||
@Override
|
||||
protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
||||
if (selection == null || selection.isEmpty()) {
|
||||
if ((selection == null) || selection.isEmpty()) {
|
||||
setEnabled(false);
|
||||
} else {
|
||||
setEnabled(checkIfActionEnabled());
|
||||
|
@ -125,7 +126,7 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
if (active instanceof MapWithAILayer) {
|
||||
final MapWithAILayer mapWithAILayer = (MapWithAILayer) active;
|
||||
final Collection<OsmPrimitive> selection = mapWithAILayer.getDataSet().getAllSelected();
|
||||
returnValue = selection != null && !selection.isEmpty();
|
||||
returnValue = (selection != null) && !selection.isEmpty();
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
|
|
@ -26,9 +26,8 @@ public class MergeDuplicateWaysAction extends JosmAction {
|
|||
private static final String DESCRIPTION = "Attempt to merge potential duplicate ways";
|
||||
|
||||
public MergeDuplicateWaysAction() {
|
||||
super(tr("{0}: ".concat(DESCRIPTION), MapWithAIPlugin.NAME), null, tr(DESCRIPTION),
|
||||
Shortcut.registerShortcut("data:attemptmergeway",
|
||||
tr(DESCRIPTION), KeyEvent.VK_EXCLAMATION_MARK,
|
||||
super(tr("{0}: ".concat(DESCRIPTION), MapWithAIPlugin.NAME), "mapwithai", tr(DESCRIPTION),
|
||||
Shortcut.registerShortcut("data:attemptmergeway", tr(DESCRIPTION), KeyEvent.VK_EXCLAMATION_MARK,
|
||||
Shortcut.ALT_CTRL_SHIFT),
|
||||
true);
|
||||
setHelpId(ht("Plugin/MapWithAI"));
|
||||
|
@ -37,7 +36,8 @@ public class MergeDuplicateWaysAction extends JosmAction {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (MainApplication.getLayerManager().getActiveDataSet() != null) {
|
||||
final List<Way> ways = new ArrayList<>(MainApplication.getLayerManager().getActiveDataSet().getSelectedWays());
|
||||
final List<Way> ways = new ArrayList<>(
|
||||
MainApplication.getLayerManager().getActiveDataSet().getSelectedWays());
|
||||
Command command = null;
|
||||
int i = 0;
|
||||
do {
|
||||
|
@ -52,7 +52,7 @@ public class MergeDuplicateWaysAction extends JosmAction {
|
|||
UndoRedoHandler.getInstance().add(command);
|
||||
i++;
|
||||
}
|
||||
} while (command != null && i < 1);
|
||||
} while ((command != null) && (i < 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue