From fc98ca97474757620b55a6815af03c47a066c97a Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Fri, 10 Jan 2020 08:10:35 -0700 Subject: [PATCH] Add TOS and Privacy policy for default servers Signed-off-by: Taylor Smock --- .../mapwithai/MapWithAIPreferences.java | 54 ++++++++++++++++++- .../mapwithai/backend/DataAvailability.java | 54 +++++++++++++++++++ .../backend/MapWithAIAvailability.java | 10 ++++ 3 files changed, 117 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java index 66aeb24..ba66f17 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java @@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai; import static org.openstreetmap.josm.tools.I18n.tr; +import java.awt.Color; import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; @@ -25,6 +26,7 @@ import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JSeparator; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; @@ -33,6 +35,8 @@ import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; import org.openstreetmap.josm.gui.preferences.advanced.PrefEntry; +import org.openstreetmap.josm.gui.widgets.JosmTextField; +import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIPreferenceHelper; import org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation.DataUrl; import org.openstreetmap.josm.spi.preferences.StringSetting; @@ -201,6 +205,8 @@ public class MapWithAIPreferences implements SubPreferenceSetting { pane.add(Box.createHorizontalGlue(), second); + legalInformation(pane); + JButton kaartLogo = new JButton(ImageProvider.getIfAvailable("kaart") == null ? null : new ImageProvider("kaart").setHeight(ImageProvider.ImageSizes.SETTINGS_TAB.getAdjustedHeight()) .get()); @@ -229,7 +235,7 @@ public class MapWithAIPreferences implements SubPreferenceSetting { Arrays.asList(replaceAddEditDeleteScroll2, scroll2, expertHorizontalGlue, replacementTags) .forEach(ExpertToggleAction::addVisibilitySwitcher); - getTabPreferenceSetting(gui).addSubTab(this, MapWithAIPlugin.NAME, pane, + getTabPreferenceSetting(gui).addSubTab(this, MapWithAIPlugin.NAME, new JScrollPane(pane), tr("{0} preferences", MapWithAIPlugin.NAME)); } @@ -292,4 +298,50 @@ public class MapWithAIPreferences implements SubPreferenceSetting { public JSpinner getMaximumAdditionSpinner() { return maximumAdditionSpinner; } + + /** + * Get legal information for sources with special handling + * + * @param pane A pane to directly add the terms of use/privacy panels to + * @return A scroll pane with sources + */ + public JScrollPane legalInformation(JPanel pane) { + GBC line = GBC.eol().fill(GBC.HORIZONTAL); + JPanel termsOfUse = new JPanel(new GridBagLayout()); + termsOfUse.add(new JLabel(tr("Server Terms Of Use")), line); + DataAvailability.getTermsOfUse().stream().map(MapWithAIPreferences::convertUrlToTextWithAction) + .forEach(urlObj -> termsOfUse.add(urlObj, line)); + JPanel privacy = new JPanel(new GridBagLayout()); + privacy.add(new JLabel(tr("Server Privacy Policy")), line); + DataAvailability.getPrivacyPolicy().stream().map(MapWithAIPreferences::convertUrlToTextWithAction) + .forEach(urlObj -> privacy.add(urlObj, line)); + + JScrollPane scroll = new JScrollPane(); + scroll.add(termsOfUse, line); + scroll.add(privacy, line); + scroll.setMinimumSize(new Dimension(0, 60)); + if (pane != null) { + pane.add(new JSeparator(), line); + pane.add(new JLabel(tr("Default Provider Legal Information")), line); + pane.add(termsOfUse, line); + pane.add(privacy, line); + pane.add(new JSeparator(), line); + } + return scroll; + } + + private static JosmTextField convertUrlToTextWithAction(String url) { + JosmTextField field = new JosmTextField(); + field.setEditable(false); + field.setText(url); + field.setForeground(Color.BLUE); + field.setCursor(new Cursor(Cursor.HAND_CURSOR)); + field.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + OpenBrowser.displayUrl(url); + } + }); + return field; + } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java index b1bb322..33f7bd0 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.TreeMap; import java.util.stream.Collectors; @@ -25,6 +26,7 @@ import org.openstreetmap.josm.io.CachedFile; import org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation.DataUrl; import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Territories; +import org.openstreetmap.josm.tools.Utils; public class DataAvailability { /** This points to a list of default sources that can be used with MapWithAI */ @@ -244,4 +246,56 @@ public class DataAvailability { public String getUrl() { return null; } + + /** + * Get the Terms Of Use Url + * + * @return The url or "" + */ + public String getTermsOfUseUrl() { + return ""; + } + + /** + * Get the Terms Of Use Url + * + * @return The url or "" + */ + public String getPrivacyPolicyUrl() { + return ""; + } + + /** + * Get the terms of use for all specially handled URL's + * + * @return List of terms of use urls + */ + public static final List getTermsOfUse() { + return DATA_SOURCES.stream().map(clazz -> { + try { + return clazz.getConstructor().newInstance().getTermsOfUseUrl(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + Logging.debug(e); + } + return ""; + }).filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).collect(Collectors.toList()); + } + + /** + * Get the privacy policy for all specially handled URL's + * + * @return List of privacy policy urls + */ + public static final List getPrivacyPolicy() { + return DATA_SOURCES.stream().map(clazz -> { + try { + return clazz.getConstructor().newInstance().getPrivacyPolicyUrl(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + Logging.debug(e); + } + return ""; + }).filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).collect(Collectors.toList()); + } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java index 95c5cb6..cf0c8d0 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java @@ -141,4 +141,14 @@ public final class MapWithAIAvailability extends DataAvailability { public String getUrl() { return MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API; } + + @Override + public String getTermsOfUseUrl() { + return "https://mapwith.ai/doc/license/MapWithAILicense.pdf"; + } + + @Override + public String getPrivacyPolicyUrl() { + return "https://mapwith.ai/doc/license/MapWithAIPrivacyPolicy.pdf#page=3"; + } }