Changeset 30735 in osm
- Timestamp:
- 2014-10-18T20:09:04+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/imagery-xml-bounds
- Files:
-
- 2 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery-xml-bounds/.project
r26776 r30735 13 13 </buildSpec> 14 14 <natures> 15 <nature>org.sonar.ide.eclipse.core.sonarNature</nature> 15 16 <nature>org.eclipse.jdt.core.javanature</nature> 16 17 </natures> -
applications/editors/josm/plugins/imagery-xml-bounds/.settings/org.eclipse.jdt.core.prefs
r30416 r30735 1 1 eclipse.preferences.version=1 2 org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled 2 3 org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore 3 4 org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull … … 6 7 org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled 7 8 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 9 org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 8 10 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 9 11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve … … 12 14 org.eclipse.jdt.core.compiler.debug.localVariable=generate 13 15 org.eclipse.jdt.core.compiler.debug.sourceFile=generate 16 org.eclipse.jdt.core.compiler.doc.comment.support=enabled 14 17 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 15 18 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error … … 23 26 org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore 24 27 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 25 org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable= ignore28 org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning 26 29 org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore 27 30 org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled … … 35 38 org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning 36 39 org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore 40 org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning 41 org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled 42 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled 43 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled 44 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public 37 45 org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore 38 46 org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning … … 41 49 org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled 42 50 org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore 51 org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning 52 org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled 53 org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public 54 org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag 55 org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning 56 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled 57 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled 58 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public 43 59 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore 44 60 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled … … 48 64 org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning 49 65 org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore 66 org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning 50 67 org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error 51 68 org.eclipse.jdt.core.compiler.problem.nullReference=warning … … 60 77 org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning 61 78 org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore 62 org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments= ignore79 org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning 63 80 org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore 64 81 org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore … … 68 85 org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled 69 86 org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled 87 org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled 70 88 org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore 71 89 org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning … … 91 109 org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled 92 110 org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning 111 org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore 93 112 org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning 94 113 org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -
applications/editors/josm/plugins/imagery-xml-bounds/build.xml
r30495 r30735 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 6 <property name="plugin.main.version" value="7248"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). 9 9 See http://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlEditorKit.java
r26776 r30735 19 19 import javax.swing.text.ViewFactory; 20 20 21 22 21 /** 23 22 * @author kees 24 23 * @date 12-jan-2006 25 *26 24 */ 27 25 public class XmlEditorKit extends StyledEditorKit { … … 30 28 private ViewFactory xmlViewFactory; 31 29 30 /** 31 * Constructs a new {@code XmlEditorKit}. 32 */ 32 33 public XmlEditorKit() { 33 34 xmlViewFactory = new XmlViewFactory(); 34 35 } 35 36 36 37 @Override 37 38 public ViewFactory getViewFactory() { … … 43 44 return "text/xml"; 44 45 } 45 46 47 46 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlTextPane.java
r26776 r30735 24 24 import javax.swing.text.BadLocationException; 25 25 26 import net.boplicity.xmleditor.XmlEditorKit;27 28 26 29 27 /** 30 28 * JTextPane implementation that can handle xml text. The IndentKeyListener 31 29 * implements smart indenting. 32 * 30 * 33 31 * @author kees 34 32 * @date 27-jan-2006 … … 37 35 public class XmlTextPane extends JTextPane { 38 36 39 private static final long serialVersionUID = 6270183148379328084L;40 private Logger logger = Logger.getLogger(getClass().getName());37 private static final Logger LOGGER = Logger.getLogger(XmlTextPane.class.getName()); 38 private static final Character NEW_LINE = '\n'; 41 39 40 /** 41 * Constructs a new {@code XmlTextPane}. 42 */ 42 43 public XmlTextPane() { 43 44 44 45 // Set editor kit 45 46 this.setEditorKitForContentType("text/xml", new XmlEditorKit()); 46 47 this.setContentType("text/xml"); 47 48 48 49 addKeyListener(new IndentKeyListener()); 49 50 } 50 51 private class IndentKeyListener implements KeyListener {52 51 53 private boolean enterFlag; 54 private final Character NEW_LINE = '\n'; 52 private class IndentKeyListener implements KeyListener { 55 53 56 public void keyPressed(KeyEvent event) { 57 enterFlag = false; 58 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 59 && (event.getModifiers() == 0)) { 60 if (getSelectionStart() == getSelectionEnd()) { 61 enterFlag = true; 62 event.consume(); 63 } 64 } 65 } 54 private boolean enterFlag; 66 55 67 public void keyReleased(KeyEvent event) { 68 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 69 && (event.getModifiers() == 0)) { 70 if (enterFlag) { 71 event.consume(); 56 @Override 57 public void keyPressed(KeyEvent event) { 58 enterFlag = false; 59 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 60 && (event.getModifiers() == 0) 61 && getSelectionStart() == getSelectionEnd()) { 62 enterFlag = true; 63 event.consume(); 64 } 65 } 72 66 73 int start, end; 74 String text = getText(); 67 @Override 68 public void keyReleased(KeyEvent event) { 69 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 70 && (event.getModifiers() == 0) && enterFlag) { 71 event.consume(); 75 72 76 int caretPosition = getCaretPosition(); 77 try { 78 if (text.charAt(caretPosition) == NEW_LINE) { 79 caretPosition--; 80 } 81 } catch (IndexOutOfBoundsException e) { 82 } 73 int start, end; 74 String text = getText(); 83 75 84 start = text.lastIndexOf(NEW_LINE, caretPosition) + 1; 85 end = start; 86 try { 87 if (text.charAt(start) != NEW_LINE) { 88 while ((end < text.length()) 89 && (Character 90 .isWhitespace(text.charAt(end))) 91 && (text.charAt(end) != NEW_LINE)) { 92 end++; 93 } 94 if (end > start) { 95 getDocument() 96 .insertString( 97 getCaretPosition(), 98 NEW_LINE 99 + text.substring(start, 100 end), null); 101 } else { 102 getDocument().insertString(getCaretPosition(), 103 NEW_LINE.toString(), null); 104 } 105 } else { 106 getDocument().insertString(getCaretPosition(), 107 NEW_LINE.toString(), null); 108 } 109 } catch (IndexOutOfBoundsException e) { 110 try { 111 getDocument().insertString(getCaretPosition(), 112 NEW_LINE.toString(), null); 113 } catch (BadLocationException e1) { 114 logger.log(Level.WARNING, e1.toString()); 115 } 116 } catch (BadLocationException e) { 117 logger.log(Level.WARNING, e.toString()); 118 } 119 } 120 } 121 } 76 int caretPosition = getCaretPosition(); 77 try { 78 if (text.charAt(caretPosition) == NEW_LINE) { 79 caretPosition--; 80 } 81 } catch (IndexOutOfBoundsException e) { 82 LOGGER.log(Level.FINE, e.toString()); 83 } 122 84 123 public void keyTyped(KeyEvent e) { 124 } 125 } 126 85 start = text.lastIndexOf(NEW_LINE, caretPosition) + 1; 86 end = start; 87 try { 88 if (text.charAt(start) != NEW_LINE) { 89 while ((end < text.length()) 90 && (Character.isWhitespace(text.charAt(end))) 91 && (text.charAt(end) != NEW_LINE)) { 92 end++; 93 } 94 if (end > start) { 95 getDocument() 96 .insertString( 97 getCaretPosition(), 98 NEW_LINE 99 + text.substring(start, 100 end), null); 101 } else { 102 getDocument().insertString(getCaretPosition(), 103 NEW_LINE.toString(), null); 104 } 105 } else { 106 getDocument().insertString(getCaretPosition(), 107 NEW_LINE.toString(), null); 108 } 109 } catch (IndexOutOfBoundsException e) { 110 try { 111 getDocument().insertString(getCaretPosition(), 112 NEW_LINE.toString(), null); 113 } catch (BadLocationException e1) { 114 LOGGER.log(Level.WARNING, e1.toString()); 115 } 116 } catch (BadLocationException e) { 117 LOGGER.log(Level.WARNING, e.toString()); 118 } 119 } 120 } 121 122 @Override 123 public void keyTyped(KeyEvent e) { 124 // Do nothing 125 } 126 } 127 127 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlView.java
r26776 r30735 18 18 import java.awt.Color; 19 19 import java.awt.Graphics; 20 import java.util.HashMap;21 20 import java.util.LinkedHashMap; 22 21 import java.util.Map; … … 47 46 public class XmlView extends PlainView { 48 47 49 private static HashMap<Pattern, Color> patternColors;48 private static Map<Pattern, Color> patternColors; 50 49 private static String GENERIC_XML_NAME = "[A-Za-z]+[A-Za-z0-9\\-_]*(:[A-Za-z]+[A-Za-z0-9\\-_]+)?"; 51 50 private static String TAG_PATTERN = "(</?" + GENERIC_XML_NAME + ")"; … … 58 57 static { 59 58 // NOTE: the order is important! 60 patternColors = new LinkedHashMap< Pattern, Color>();59 patternColors = new LinkedHashMap<>(); 61 60 patternColors 62 61 .put(Pattern.compile(TAG_PATTERN), new Color(63, 127, 127)); … … 71 70 } 72 71 72 /** 73 * Constructs a new {@code XmlView}. 74 * @param element the element 75 */ 73 76 public XmlView(Element element) { 74 77 … … 80 83 81 84 @Override 82 protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, 83 int p1)throws BadLocationException {85 protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) 86 throws BadLocationException { 84 87 85 88 Document doc = getDocument(); … … 88 91 Segment segment = getLineBuffer(); 89 92 90 SortedMap<Integer, Integer> startMap = new TreeMap< Integer, Integer>();91 SortedMap<Integer, Color> colorMap = new TreeMap< Integer, Color>();93 SortedMap<Integer, Integer> startMap = new TreeMap<>(); 94 SortedMap<Integer, Color> colorMap = new TreeMap<>(); 92 95 93 96 // Match all regexes on this snippet, store positions -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlViewFactory.java
r26776 r30735 20 20 import javax.swing.text.ViewFactory; 21 21 22 23 22 /** 24 23 * @author kees … … 28 27 public class XmlViewFactory extends Object implements ViewFactory { 29 28 30 /** 31 * @see javax.swing.text.ViewFactory#create(javax.swing.text.Element) 32 */ 29 @Override 33 30 public View create(Element element) { 34 35 31 return new XmlView(element); 36 32 } 37 38 33 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java
r30342 r30735 30 30 * Action showing bounds of the selected closed ways in Selection dialog 31 31 */ 32 32 private final ShowBoundsAction selectionListAction = new ShowBoundsAction(); 33 33 34 34 /** … … 37 37 private final ShowBoundsAction propertiesListAction = new ShowBoundsAction(); 38 38 39 39 /** 40 40 * Action showing bounds of the selected multipolygons in Relations dialog 41 41 */ 42 42 private final ShowBoundsAction relationListAction = new ShowBoundsAction(); 43 43 44 44 /** 45 45 * Action showing bounds of the current selection 46 46 */ 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 47 private final ShowBoundsSelectionAction selectionAction = new ShowBoundsSelectionAction(); 48 49 /** 50 * Class modifying the Imagery preferences panel 51 */ 52 private final XmlBoundsPreferenceSetting preferenceSetting = new XmlBoundsPreferenceSetting(); 53 54 /** 55 * Initializes the plugin. 56 * @param info 57 */ 58 public ImageryXmlBoundsPlugin(PluginInformation info) { 59 super(info); 60 // Allow JOSM to import *.imagery.xml files 61 ExtensionFileFilter.importers.add(0, new XmlBoundsImporter()); 62 62 // Allow JOSM to export *.imagery.xml files 63 63 ExtensionFileFilter.exporters.add(0, new XmlBoundsExporter()); 64 64 // Initialize the selection action 65 66 67 68 69 70 65 DataSet.addSelectionListener(selectionAction); 66 Main.toolbar.register(selectionAction); 67 // Allow JOSM to download *.imagery.xml files 68 Main.main.menu.openLocation.addDownloadTaskClass(DownloadXmlBoundsTask.class); 69 } 70 71 71 @Override 72 72 public PreferenceSetting getPreferenceSetting() { … … 74 74 } 75 75 76 77 78 79 76 @Override 77 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 78 if (newFrame != null) { 79 // Initialize dialogs actions only after the main frame is created 80 80 newFrame.selectionListDialog.getPopupMenuHandler().addSeparator(); 81 81 newFrame.selectionListDialog.getPopupMenuHandler().addAction(selectionListAction); 82 82 newFrame.propertiesDialog.getMembershipPopupMenuHandler().addSeparator(); 83 83 newFrame.propertiesDialog.getMembershipPopupMenuHandler().addAction(propertiesListAction); 84 85 86 84 newFrame.relationListDialog.getPopupMenuHandler().addSeparator(); 85 newFrame.relationListDialog.getPopupMenuHandler().addAction(relationListAction); 86 } else if (oldFrame != null) { 87 87 // Remove listeners from previous frame to avoid memory leaks 88 89 90 91 92 93 94 95 96 97 98 88 if (oldFrame.relationListDialog != null) { 89 oldFrame.relationListDialog.getPopupMenuHandler().removeAction(relationListAction); 90 } 91 if (oldFrame.propertiesDialog != null) { 92 oldFrame.propertiesDialog.getMembershipPopupMenuHandler().removeAction(propertiesListAction); 93 } 94 if (oldFrame.selectionListDialog != null) { 95 oldFrame.selectionListDialog.getPopupMenuHandler().removeAction(selectionListAction); 96 } 97 } 98 } 99 99 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java
r30342 r30735 16 16 public interface XmlBoundsConstants { 17 17 18 19 20 21 22 23 24 25 26 18 /** 19 * Plugin version. 20 */ 21 public static final String PLUGIN_VERSION = "1.3"; 22 23 /** 24 * XML namespace for JOSM Imagery schema. 25 */ 26 public static final String XML_NAMESPACE = "http://josm.openstreetmap.de/maps-1.0"; 27 27 28 28 /** … … 31 31 public static final String XML_LOCATION = "https?://josm.openstreetmap.de/maps"; 32 32 33 /**34 * XML Schema35 */36 public static final String XML_SCHEMA = "resource://data/maps.xsd";37 38 33 /** 39 * XML tags34 * XML Schema 40 35 */ 36 public static final String XML_SCHEMA = "resource://data/maps.xsd"; 37 38 /** XML name tag */ 41 39 public static final String XML_NAME = "name"; 40 /** XML type tag */ 42 41 public static final String XML_TYPE = "type"; 42 /** XML url tag */ 43 43 public static final String XML_URL = "url"; 44 /** XML default tag */ 44 45 public static final String XML_DEFAULT = "default"; 46 /** XML eula tag */ 45 47 public static final String XML_EULA = "eula"; 48 /** XML attribution-text tag */ 46 49 public static final String XML_ATTR_TEXT = "attribution-text"; 50 /** XML attribution-url tag */ 47 51 public static final String XML_ATTR_URL = "attribution-url"; 52 /** XML terms-of-use-text tag */ 48 53 public static final String XML_TERMS_TEXT = "terms-of-use-text"; 54 /** XML terms-of-use-url tag */ 49 55 public static final String XML_TERMS_URL = "terms-of-use-url"; 56 /** XML projections tag */ 50 57 public static final String XML_PROJECTIONS = "projections"; 58 /** XML max-zoom tag */ 51 59 public static final String XML_MAX_ZOOM = "max-zoom"; 60 /** XML min-zoom tag */ 52 61 public static final String XML_MIN_ZOOM = "min-zoom"; 62 /** XML country-code tag */ 53 63 public static final String XML_COUNTRY_CODE = "country-code"; 54 public static final String XML_LOGO_IMAGE = "logo-image";// TODO 64 /** XML logo-image tag */ 65 public static final String XML_LOGO_IMAGE = "logo-image"; 66 /** XML logo-url tag */ 55 67 public static final String XML_LOGO_URL = "logo-url"; 56 68 … … 60 72 public static final String PREFIX = "imagery:"; 61 73 62 63 64 65 66 67 68 69 70 71 74 /** 75 * OSM keys, equivalent to those used in XML schema, but prefixed (except for name). 76 */ 77 public static final String KEY_NAME = XML_NAME; 78 public static final String KEY_TYPE = PREFIX + XML_TYPE; 79 public static final String KEY_URL = PREFIX + XML_URL; 80 public static final String KEY_DEFAULT = PREFIX + XML_DEFAULT; 81 public static final String KEY_EULA = PREFIX + XML_EULA; 82 public static final String KEY_ATTR_TEXT = PREFIX + XML_ATTR_TEXT; 83 public static final String KEY_ATTR_URL = PREFIX + XML_ATTR_URL; 72 84 public static final String KEY_TERMS_TEXT = PREFIX + XML_TERMS_TEXT; 73 74 75 76 77 85 public static final String KEY_TERMS_URL = PREFIX + XML_TERMS_URL; 86 public static final String KEY_PROJECTIONS = PREFIX + XML_PROJECTIONS; 87 public static final String KEY_MAX_ZOOM = PREFIX + XML_MAX_ZOOM; 88 public static final String KEY_MIN_ZOOM = PREFIX + XML_MIN_ZOOM; 89 public static final String KEY_COUNTRY_CODE = PREFIX + XML_COUNTRY_CODE; 78 90 public static final String KEY_LOGO_IMAGE = PREFIX + XML_LOGO_IMAGE;// TODO 79 91 public static final String KEY_LOGO_URL = PREFIX + XML_LOGO_URL; 80 81 /**82 * File extension.83 */84 public static final String EXTENSION = "imagery.xml";85 86 /**87 * File encoding.88 */89 public static final String ENCODING = "UTF-8";90 91 /**92 * File filter used in import/export dialogs.93 */94 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(EXTENSION, EXTENSION, tr("Imagery XML Files") + " (*."+EXTENSION+")");95 92 96 /** 97 * Plugin icons. 98 */ 99 public static ImageIcon XML_ICON_16 = ImageProvider.get("xml_16.png"); 100 public static ImageIcon XML_ICON_24 = ImageProvider.get("xml_24.png"); 93 /** 94 * File extension. 95 */ 96 public static final String EXTENSION = "imagery.xml"; 97 98 /** 99 * File encoding. 100 */ 101 public static final String ENCODING = "UTF-8"; 102 103 /** 104 * File filter used in import/export dialogs. 105 */ 106 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 107 EXTENSION, EXTENSION, tr("Imagery XML Files") + " (*."+EXTENSION+")"); 108 109 /** 110 * Plugin 16x16 icon. 111 */ 112 public static ImageIcon XML_ICON_16 = ImageProvider.get("xml_16.png"); 113 114 /** 115 * Plugin 24x24 icon. 116 */ 117 public static ImageIcon XML_ICON_24 = ImageProvider.get("xml_24.png"); 101 118 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsLayer.java
r30342 r30735 24 24 /** 25 25 * An "OSM data" layer that cannot be uploaded, merged, and in which real OSM data cannot be imported. 26 * Its sole purpose is to allow "classic" OSM edition tools to edit Imagery bounds (as XML files) without compromising OSM database integrity. 27 * 26 * Its sole purpose is to allow "classic" OSM edition tools to edit Imagery bounds (as XML files) 27 * without compromising OSM database integrity. 28 * 28 29 * @author Don-vip 29 30 */ 30 31 public class XmlBoundsLayer extends OsmDataLayer implements LayerChangeListener, XmlBoundsConstants { 31 32 32 33 34 List<Action> result = new ArrayList<Action>();35 36 37 33 @Override 34 public Action[] getMenuEntries() { 35 List<Action> result = new ArrayList<>(); 36 for (Action action : super.getMenuEntries()) { 37 if (action instanceof LayerSaveAction) { 38 result.add(new BoundsLayerSaveAction(this)); 38 39 39 } else if (action instanceof LayerSaveAsAction) { 40 result.add(new BoundsLayerSaveAsAction(this)); 41 42 } else if (!(action instanceof LayerGpxExportAction) && !(action instanceof ConvertToGpxLayerAction)) { 43 // Add everything else, expect GPX-related action 44 result.add(action); 45 } 46 } 47 result.add(new ShowBoundsAction(this)); 48 return result.toArray(new Action[0]); 49 } 40 } else if (action instanceof LayerSaveAsAction) { 41 result.add(new BoundsLayerSaveAsAction(this)); 50 42 51 private static final JosmAction[] actionsToDisable = new JosmAction[] { 52 Main.main.menu.download, 53 Main.main.menu.downloadPrimitive, 54 Main.main.menu.downloadReferrers, 55 Main.main.menu.upload, 56 Main.main.menu.uploadSelection, 57 Main.main.menu.update, 58 Main.main.menu.updateModified, 59 Main.main.menu.updateSelection, 60 Main.main.menu.openLocation 61 }; 62 63 private static final Map<JosmAction, Boolean> actionsStates = new HashMap<JosmAction, Boolean>(); 64 65 public XmlBoundsLayer(DataSet data) { 66 this(data, OsmDataLayer.createNewName(), null); 67 } 43 } else if (!(action instanceof LayerGpxExportAction) && !(action instanceof ConvertToGpxLayerAction)) { 44 // Add everything else, expect GPX-related action 45 result.add(action); 46 } 47 } 48 result.add(new ShowBoundsAction(this)); 49 return result.toArray(new Action[0]); 50 } 68 51 69 public XmlBoundsLayer(DataSet data, String name, File associatedFile) { 70 super(data, name, associatedFile); 71 MapView.addLayerChangeListener(this); 72 } 73 74 @Override 75 public boolean isMergable(Layer other) { 76 return other instanceof XmlBoundsLayer; 77 } 52 private static final JosmAction[] ACTIONS_TO_DISABLE = new JosmAction[] { 53 Main.main.menu.download, 54 Main.main.menu.downloadPrimitive, 55 Main.main.menu.downloadReferrers, 56 Main.main.menu.upload, 57 Main.main.menu.uploadSelection, 58 Main.main.menu.update, 59 Main.main.menu.updateModified, 60 Main.main.menu.updateSelection, 61 Main.main.menu.openLocation 62 }; 78 63 79 @Override 80 public Icon getIcon() { 81 return XML_ICON_16; 82 } 64 private static final Map<JosmAction, Boolean> ACTIONS_STATES = new HashMap<>(); 83 65 84 @Override 85 public boolean requiresUploadToServer() { 86 return false; // Never ! 87 } 66 /** 67 * Constructs a new {@code XmlBoundsLayer}. 68 * @param data data 69 */ 70 public XmlBoundsLayer(DataSet data) { 71 this(data, OsmDataLayer.createNewName(), null); 72 } 88 73 89 @Override 90 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 91 if (newLayer == this && !(oldLayer instanceof XmlBoundsLayer)) { 92 for (JosmAction action : actionsToDisable) { 93 actionsStates.put(action, action.isEnabled()); 94 action.setEnabled(false); 95 } 96 } else if (oldLayer == this && !(newLayer instanceof XmlBoundsLayer)) { 97 for (JosmAction action : actionsToDisable) { 98 action.setEnabled(actionsStates.get(action)); 99 } 100 } 101 } 74 /** 75 * Constructs a new {@code XmlBoundsLayer}. 76 * @param data data 77 * @param name Layer name 78 * @param associatedFile Associated file (can be null) 79 */ 80 public XmlBoundsLayer(DataSet data, String name, File associatedFile) { 81 super(data, name, associatedFile); 82 MapView.addLayerChangeListener(this); 83 } 102 84 103 @Override 104 public void layerAdded(Layer newLayer) { 105 } 85 @Override 86 public boolean isMergable(Layer other) { 87 return other instanceof XmlBoundsLayer; 88 } 106 89 107 @Override 108 public void layerRemoved(Layer oldLayer) { 109 if (Main.main.getEditLayer() instanceof XmlBoundsLayer) { 110 for (JosmAction action : actionsToDisable) { 90 @Override 91 public Icon getIcon() { 92 return XML_ICON_16; 93 } 94 95 @Override 96 public boolean requiresUploadToServer() { 97 return false; // Never ! 98 } 99 100 @Override 101 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 102 if (newLayer == this && !(oldLayer instanceof XmlBoundsLayer)) { 103 for (JosmAction action : ACTIONS_TO_DISABLE) { 104 ACTIONS_STATES.put(action, action.isEnabled()); 111 105 action.setEnabled(false); 112 106 } 113 } 114 } 107 } else if (oldLayer == this && !(newLayer instanceof XmlBoundsLayer)) { 108 for (JosmAction action : ACTIONS_TO_DISABLE) { 109 action.setEnabled(ACTIONS_STATES.get(action)); 110 } 111 } 112 } 113 114 @Override 115 public void layerAdded(Layer newLayer) { 116 // Do nothing 117 } 118 119 @Override 120 public void layerRemoved(Layer oldLayer) { 121 if (Main.main.getEditLayer() instanceof XmlBoundsLayer) { 122 for (JosmAction action : ACTIONS_TO_DISABLE) { 123 action.setEnabled(false); 124 } 125 } 126 } 115 127 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsPreferenceSetting.java
r30342 r30735 11 11 12 12 /** 13 * 13 * Plugin preferences. 14 14 * @author Don-vip 15 *16 15 */ 17 16 public class XmlBoundsPreferenceSetting implements SubPreferenceSetting { … … 34 33 } 35 34 35 @Override 36 36 public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) { 37 37 return gui.getImageryPreference(); 38 38 } 39 40 39 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/BoundsLayerSaveAction.java
r30342 r30735 14 14 15 15 /** 16 * 16 * Save the current data. 17 17 * @author Don-vip 18 *19 18 */ 20 @SuppressWarnings("serial")21 19 public class BoundsLayerSaveAction extends LayerSaveAction { 22 20 23 public static class SaveBoundsAction extends SaveActionBase { 21 /** 22 * Save the current data. 23 */ 24 public static class SaveBoundsAction extends SaveActionBase { 24 25 25 public SaveBoundsAction() { 26 super(tr("Save"), "save", tr("Save the current data."), null); 27 putValue("help", ht("/Action/Save")); 28 } 26 /** 27 * Constructs a new {@code SaveBoundsAction}. 28 */ 29 public SaveBoundsAction() { 30 super(tr("Save"), "save", tr("Save the current data."), null); 31 putValue("help", ht("/Action/Save")); 32 } 29 33 30 @Override public File getFile(Layer layer) { 31 File f = layer.getAssociatedFile(); 32 if (f != null && ! f.exists()) { 33 f = null; 34 } 35 return f == null ? BoundsLayerSaveAsAction.SaveBoundsAsAction.openFileDialog(layer) : f; 36 } 37 } 34 @Override 35 public File getFile(Layer layer) { 36 File f = layer.getAssociatedFile(); 37 if (f != null && ! f.exists()) { 38 f = null; 39 } 40 return f == null ? BoundsLayerSaveAsAction.SaveBoundsAsAction.openFileDialog(layer) : f; 41 } 42 } 38 43 39 protectedXmlBoundsLayer layer;44 protected final XmlBoundsLayer layer; 40 45 41 public BoundsLayerSaveAction(XmlBoundsLayer layer) { 42 super(layer); 43 } 46 /** 47 * Constructs a new {@code BoundsLayerSaveAction}. 48 * @param layer XML bounds layer 49 */ 50 public BoundsLayerSaveAction(XmlBoundsLayer layer) { 51 super(layer); 52 this.layer = layer; 53 } 44 54 45 55 @Override 46 56 public void actionPerformed(ActionEvent e) { 47 57 new SaveBoundsAction().doSave(layer); 48 58 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/BoundsLayerSaveAsAction.java
r30342 r30735 14 14 15 15 /** 16 * 16 * Save Imagery XML file. 17 17 * @author Don-vip 18 *19 18 */ 20 @SuppressWarnings("serial")21 19 public class BoundsLayerSaveAsAction extends LayerSaveAsAction { 22 20 23 public static class SaveBoundsAsAction extends SaveAsAction { 21 /** 22 * Save Imagery XML file 23 */ 24 public static class SaveBoundsAsAction extends SaveAsAction { 24 25 25 @Override public File getFile(Layer layer) { 26 return openFileDialog(layer); 27 } 28 29 public static File openFileDialog(Layer layer) { 30 if (layer instanceof XmlBoundsLayer) { 31 return createAndOpenSaveFileChooser(tr("Save Imagery XML file"), XmlBoundsConstants.EXTENSION); 32 } else { 33 return null; 34 } 35 } 36 } 37 38 protected XmlBoundsLayer layer; 39 40 public BoundsLayerSaveAsAction(XmlBoundsLayer layer) { 41 super(layer); 42 this.layer = layer; 43 } 26 @Override 27 public File getFile(Layer layer) { 28 return openFileDialog(layer); 29 } 44 30 45 @Override 46 public void actionPerformed(ActionEvent e) { 47 new SaveBoundsAsAction().doSave(layer); 48 } 31 /** 32 * Opens a "File/Save as" dialog if the given layer is an XML bounds layer 33 * @param layer layer 34 * @return chosen destination file, or {@code null} 35 */ 36 public static File openFileDialog(Layer layer) { 37 if (layer instanceof XmlBoundsLayer) { 38 return createAndOpenSaveFileChooser(tr("Save Imagery XML file"), XmlBoundsConstants.EXTENSION); 39 } else { 40 return null; 41 } 42 } 43 } 44 45 protected final XmlBoundsLayer layer; 46 47 /** 48 * Constructs a new {@code BoundsLayerSaveAsAction}. 49 * @param layer XML Bounds layer 50 */ 51 public BoundsLayerSaveAsAction(XmlBoundsLayer layer) { 52 super(layer); 53 this.layer = layer; 54 } 55 56 @Override 57 public void actionPerformed(ActionEvent e) { 58 new SaveBoundsAsAction().doSave(layer); 59 } 49 60 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ComputeBoundsAction.java
r30662 r30735 19 19 import javax.swing.AbstractAction; 20 20 21 import org.openstreetmap.josm.Main; 21 22 import org.openstreetmap.josm.data.coor.LatLon; 22 23 import org.openstreetmap.josm.data.osm.BBox; … … 29 30 30 31 /** 31 * 32 * 32 33 * @author Don-vip 33 34 * 34 35 */ 35 @SuppressWarnings("serial")36 36 public class ComputeBoundsAction extends AbstractAction implements XmlBoundsConstants { 37 37 38 protected static final DecimalFormat df = new DecimalFormat("#0.0000000", new DecimalFormatSymbols(Locale.UK)); 39 40 protected static final String ACTION_NAME = tr("XML Imagery Bounds"); 41 42 private final Set<Relation> multipolygons; 43 private final Set<Way> closedWays; 44 45 public ComputeBoundsAction() { 46 this(null); 47 } 48 49 public ComputeBoundsAction(OsmDataLayer layer) { 50 this.multipolygons = new HashSet<Relation>(); 51 this.closedWays = new HashSet<Way>(); 52 38 protected static final DecimalFormat DF = new DecimalFormat("#0.0000000", new DecimalFormatSymbols(Locale.UK)); 39 40 protected static final String ACTION_NAME = tr("XML Imagery Bounds"); 41 42 protected static final String EIGHT_SP = " "; 43 44 private final Set<Relation> multipolygons; 45 private final Set<Way> closedWays; 46 47 /** 48 * Constructs a new {@code ComputeBoundsAction}. 49 */ 50 public ComputeBoundsAction() { 51 this(null); 52 } 53 54 /** 55 * Constructs a new {@code ComputeBoundsAction}. 56 * @param layer data layer 57 */ 58 public ComputeBoundsAction(OsmDataLayer layer) { 59 this.multipolygons = new HashSet<>(); 60 this.closedWays = new HashSet<>(); 61 53 62 putValue(SHORT_DESCRIPTION, tr("Generate Imagery XML bounds for the selection")); 54 63 putValue(NAME, ACTION_NAME); 55 64 try { 56 65 putValue(SMALL_ICON, XML_ICON_24); 57 66 } catch (Exception e) { 58 e.printStackTrace();59 } 60 61 62 63 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 67 Main.error(e); 68 } 69 setEnabled(false); 70 71 if (layer != null) { 72 List<OsmPrimitive> primitives = new ArrayList<>(); 73 primitives.addAll(layer.data.getRelations()); 74 primitives.addAll(layer.data.getWays()); 75 updateOsmPrimitives(primitives); 76 } 77 } 78 79 protected void updateOsmPrimitives(Collection<? extends OsmPrimitive> primitives) { 80 multipolygons.clear(); 81 closedWays.clear(); 82 // Store selected multipolygons and closed ways 83 for (OsmPrimitive value : primitives) { 84 if (value instanceof Relation) { 85 Relation r = (Relation) value; 86 if (r.isMultipolygon()) { 87 multipolygons.add(r); 88 } 89 } else if (value instanceof Way) { 90 Way w = (Way) value; 91 if (w.isClosed()) { 92 closedWays.add(w); 93 } 94 } 95 } 96 // Remove closed ways already inside a selected multipolygon 97 for (Iterator<Way> it = closedWays.iterator(); it.hasNext(); ) { 98 processIterator(it); 99 } 100 // Enable the action if at least one area is found 101 setEnabled(!multipolygons.isEmpty() || !closedWays.isEmpty()); 102 } 94 103 95 104 private void processIterator(Iterator<Way> it) { 96 105 Way way = it.next(); 97 106 for (Relation mp : multipolygons) { 98 for (RelationMember mb : mp.getMembers()) { 99 if (mb.getMember().equals(way)) { 100 it.remove(); 101 return; 102 } 103 } 104 } 105 } 106 107 public final String getXml() { 108 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 109 primitives.addAll(multipolygons); 110 primitives.addAll(closedWays); 111 return getXml(primitives.toArray(new OsmPrimitive[0])); 112 } 113 107 for (RelationMember mb : mp.getMembers()) { 108 if (mb.getMember().equals(way)) { 109 it.remove(); 110 return; 111 } 112 } 113 } 114 } 115 116 /** 117 * Replies XML code. 118 * @return XML code 119 */ 120 public final String getXml() { 121 List<OsmPrimitive> primitives = new ArrayList<>(); 122 primitives.addAll(multipolygons); 123 primitives.addAll(closedWays); 124 return getXml(primitives.toArray(new OsmPrimitive[0])); 125 } 126 114 127 protected static final String startTag(String tag) { 115 128 return "<" + tag + ">"; … … 137 150 138 151 protected static final String simpleTag(String tag, String content, String def, boolean escape) { 139 return startTag(tag) + (content != null 140 ? (escape ? escapeReservedCharacters(content) : content) 152 return startTag(tag) + (content != null 153 ? (escape ? escapeReservedCharacters(content) : content) 141 154 : def 142 155 ) + endTag(tag); … … 151 164 } 152 165 166 /** 167 * Escapes HTML entities. 168 * @param s The string to update 169 * @return String with escaped entities 170 */ 153 171 public static String escapeReservedCharacters(String s) { 154 172 return s == null ? "" : s.replace("&", "&").replace("<", "<").replace(">", ">"); 155 173 } 156 157 protected static final String getXml(OsmPrimitive ... primitives) { 158 List<String> entries = new ArrayList<String>(); 159 for (OsmPrimitive p : primitives) { 160 if (p instanceof Relation) { 161 entries.add(getEntry(p, getMultiPolygonBounds((Relation) p))); 162 } else if (p instanceof Way) { 163 entries.add(getEntry(p, getClosedWayBounds((Way) p))); 164 } 165 } 166 return getImagery(entries.toArray(new String[0])); 167 } 168 169 protected static final String getImagery(String ... entries) { 170 String result = "<?xml version=\"1.0\" encoding=\""+ENCODING+"\" ?>\n"; 171 result += "<!-- Generated with JOSM Imagery XML Plugin version "+PLUGIN_VERSION+" -->\n"; 172 result += "<imagery xmlns=\""+XML_NAMESPACE+"\">\n"; 173 for (String entry : entries) { 174 result += entry+"\n"; 175 } 176 result += "</imagery>"; 177 return result; 178 } 179 180 protected static final String getEntry(OsmPrimitive p, String bounds) { 181 return getEntry(p.get(KEY_NAME), p.get(KEY_TYPE), p.get(KEY_DEFAULT), p.get(KEY_URL), bounds, p.get(KEY_PROJECTIONS), p.get(KEY_LOGO_URL), 182 p.get(KEY_EULA), p.get(KEY_ATTR_TEXT), p.get(KEY_ATTR_URL), p.get(KEY_TERMS_TEXT), p.get(KEY_TERMS_URL), p.get(KEY_COUNTRY_CODE), p.get(KEY_MAX_ZOOM), p.get(KEY_MIN_ZOOM)); 183 } 184 185 protected static final boolean isSet(String tag) { 186 return tag != null && !tag.isEmpty(); 187 } 188 189 protected static final String getEntry(String name, String type, String def, String url, String bounds, String projections, String logoURL, 190 String eula, String attributionText, String attributionUrl, String termsText, String termsUrl, String countryCode, String maxZoom, String minZoom) { 191 String result = 192 " <entry>\n"+ 193 " " + simpleTag(XML_NAME, name) + "\n"+ 194 " " + simpleTag(XML_TYPE, type, "wms") + "\n"+ 195 " " + simpleTag(XML_URL, url != null ? encodeUrl(url) : "", false) + "\n"+ 196 bounds+"\n"; 197 if (projections != null && !projections.isEmpty()) { 198 result += " "+startTag(XML_PROJECTIONS)+"\n"; 199 int i = 0; 200 String[] codes = projections.split(";"); 201 for (String code : codes) { 202 if (i%6 == 0) { 203 result += " "; 204 } 205 result += simpleTag("code", code.trim()); 206 if (i%6 == 5 || i == codes.length-1 ) { 207 result += "\n"; 208 } 209 i++; 210 } 211 result += " "+endTag(XML_PROJECTIONS)+"\n"; 212 } 213 if (isSet(def) && def.equals("true")) { 214 result += " " + simpleTag(XML_DEFAULT, def) + "\n"; 215 } 216 if (isSet(eula)) { 217 result += " " + mandatoryTag(XML_EULA, encodeUrl(eula), false) + "\n"; 218 } 219 if (isSet(attributionText)) { 220 result += " " + mandatoryTag(XML_ATTR_TEXT, attributionText) + "\n"; 221 } 222 if (isSet(attributionUrl)) { 223 result += " " + simpleTag(XML_ATTR_URL, encodeUrl(attributionUrl), false) + "\n"; 224 } 174 175 protected static final String getXml(OsmPrimitive ... primitives) { 176 List<String> entries = new ArrayList<>(); 177 for (OsmPrimitive p : primitives) { 178 if (p instanceof Relation) { 179 entries.add(getEntry(p, getMultiPolygonBounds((Relation) p))); 180 } else if (p instanceof Way) { 181 entries.add(getEntry(p, getClosedWayBounds((Way) p))); 182 } 183 } 184 return getImagery(entries.toArray(new String[0])); 185 } 186 187 protected static final String getImagery(String ... entries) { 188 StringBuilder result = new StringBuilder(); 189 result.append("<?xml version=\"1.0\" encoding=\"").append(ENCODING).append("\" ?>\n"); 190 result.append("<!-- Generated with JOSM Imagery XML Plugin version ").append(PLUGIN_VERSION).append(" -->\n"); 191 result.append("<imagery xmlns=\"").append(XML_NAMESPACE).append("\">\n"); 192 for (String entry : entries) { 193 result.append(entry).append("\n"); 194 } 195 result.append("</imagery>"); 196 return result.toString(); 197 } 198 199 protected static final String getEntry(OsmPrimitive p, String bounds) { 200 return getEntry(p.get(KEY_NAME), p.get(KEY_TYPE), p.get(KEY_DEFAULT), p.get(KEY_URL), bounds, p.get(KEY_PROJECTIONS), 201 p.get(KEY_LOGO_URL), p.get(KEY_EULA), p.get(KEY_ATTR_TEXT), p.get(KEY_ATTR_URL), p.get(KEY_TERMS_TEXT), 202 p.get(KEY_TERMS_URL), p.get(KEY_COUNTRY_CODE), p.get(KEY_MAX_ZOOM), p.get(KEY_MIN_ZOOM)); 203 } 204 205 protected static final boolean isSet(String tag) { 206 return tag != null && !tag.isEmpty(); 207 } 208 209 protected static final String getEntry(String name, String type, String def, String url, String bounds, String projections, 210 String logoURL, String eula, String attributionText, String attributionUrl, String termsText, String termsUrl, 211 String countryCode, String maxZoom, String minZoom) { 212 StringBuilder result = new StringBuilder(); 213 result.append(" <entry>\n"+ 214 EIGHT_SP + simpleTag(XML_NAME, name) + "\n"+ 215 EIGHT_SP + simpleTag(XML_TYPE, type, "wms") + "\n"+ 216 EIGHT_SP + simpleTag(XML_URL, url != null ? encodeUrl(url) : "", false) + "\n"+ 217 bounds+"\n"); 218 if (projections != null && !projections.isEmpty()) { 219 result.append(EIGHT_SP+startTag(XML_PROJECTIONS)+"\n"); 220 int i = 0; 221 String[] codes = projections.split(";"); 222 for (String code : codes) { 223 if (i%6 == 0) { 224 result.append(" "); 225 } 226 result.append(simpleTag("code", code.trim())); 227 if (i%6 == 5 || i == codes.length-1 ) { 228 result.append("\n"); 229 } 230 i++; 231 } 232 result.append(EIGHT_SP+endTag(XML_PROJECTIONS)+"\n"); 233 } 234 if (isSet(def) && "true".equals(def)) { 235 result.append(EIGHT_SP + simpleTag(XML_DEFAULT, def) + "\n"); 236 } 237 if (isSet(eula)) { 238 result.append(EIGHT_SP + mandatoryTag(XML_EULA, encodeUrl(eula), false) + "\n"); 239 } 240 if (isSet(attributionText)) { 241 result.append(EIGHT_SP + mandatoryTag(XML_ATTR_TEXT, attributionText) + "\n"); 242 } 243 if (isSet(attributionUrl)) { 244 result.append(EIGHT_SP + simpleTag(XML_ATTR_URL, encodeUrl(attributionUrl), false) + "\n"); 245 } 225 246 if (isSet(termsText)) { 226 result += " " + simpleTag(XML_TERMS_TEXT, termsText) + "\n";247 result.append(EIGHT_SP + simpleTag(XML_TERMS_TEXT, termsText) + "\n"); 227 248 } 228 249 if (isSet(termsUrl)) { 229 result += " " + simpleTag(XML_TERMS_URL, encodeUrl(termsUrl), false) + "\n";250 result.append(EIGHT_SP + simpleTag(XML_TERMS_URL, encodeUrl(termsUrl), false) + "\n"); 230 251 } 231 252 if (isSet(logoURL)) { 232 result += " " + simpleTag(XML_LOGO_URL, encodeUrl(logoURL), false) + "\n";233 } 234 235 result += " " + simpleTag(XML_COUNTRY_CODE, countryCode) + "\n";236 237 238 239 result += " " + simpleTag(XML_MAX_ZOOM, maxZoom) + "\n";240 253 result.append(EIGHT_SP + simpleTag(XML_LOGO_URL, encodeUrl(logoURL), false) + "\n"); 254 } 255 if (isSet(countryCode)) { 256 result.append(EIGHT_SP + simpleTag(XML_COUNTRY_CODE, countryCode) + "\n"); 257 } 258 if ("tms".equals(type)) { 259 if (isSet(maxZoom)) { 260 result.append(EIGHT_SP + simpleTag(XML_MAX_ZOOM, maxZoom) + "\n"); 261 } 241 262 if (isSet(minZoom)) { 242 result += " " + simpleTag(XML_MIN_ZOOM, minZoom) + "\n"; 243 } 244 } 245 result += " </entry>"; 246 return result; 247 } 248 249 protected static final String encodeUrl(String url) { 250 return "<![CDATA["+url+"]]>"; 251 } 252 253 protected static final String getBounds(OsmPrimitive p, boolean closeTag) { 254 BBox bbox = p.getBBox(); 255 String result = " <bounds "; 256 result += "min-lat='"+df.format(bbox.getBottomRight().lat())+"' "; 257 result += "min-lon='"+df.format(bbox.getTopLeft().lon())+"' "; 258 result += "max-lat='"+df.format(bbox.getTopLeft().lat())+"' "; 259 result += "max-lon='"+df.format(bbox.getBottomRight().lon())+"'"; 260 result += closeTag ? " />" : ">\n"; 261 return result; 262 } 263 264 protected static final boolean isValidOuterMember(RelationMember mb) { 265 return (mb.getRole() == null || mb.getRole().isEmpty() || mb.getRole().equals("outer")) 266 && mb.getMember() instanceof Way && ((Way) mb.getMember()).isClosed(); 267 } 268 269 protected static final String getMultiPolygonBounds(Relation mp) { 270 List<Way> outerClosedWays = new ArrayList<Way>(); 271 for (RelationMember mb : mp.getMembers()) { 272 if (isValidOuterMember(mb)) { 273 outerClosedWays.add((Way) mb.getMember()); 274 } 275 } 276 277 if (outerClosedWays.isEmpty() || (outerClosedWays.size() == 1 && areClosedWayAndBboxEqual(outerClosedWays.get(0), mp.getBBox()))) { 278 return getBounds(mp, true); 279 } else { 280 String result = getBounds(mp, false); 281 for (Way way : outerClosedWays) { 282 result += getClosedWayShape(way); 283 } 284 result += " </bounds>"; 285 return result; 286 } 287 } 288 289 protected static final boolean areClosedWayAndBboxEqual(Way way, BBox bBox) { 290 if (way.getNodesCount() == 5) { 291 Map<Double, List<Integer>> latMap = new HashMap<Double, List<Integer>>(); 292 Map<Double, List<Integer>> lonMap = new HashMap<Double, List<Integer>>(); 293 294 for (int i=0; i<4; i++) { 295 LatLon c = way.getNode(i).getCoor(); 296 if (i > 1) { 297 LatLon b = way.getNode(i-1).getCoor(); 298 if (b.lat() != c.lat() && b.lon() != c.lon()) { 299 return false; 300 } 301 } 302 List<Integer> latList = latMap.get(c.lat()); 303 if (latList == null) { 304 latList = new ArrayList<Integer>(); 305 latMap.put(c.lat(), latList); 306 } 307 latList.add(i); 308 List<Integer> lonList = lonMap.get(c.lon()); 309 if (lonList == null) { 310 lonList = new ArrayList<Integer>(); 311 lonMap.put(c.lon(), lonList); 312 } 313 lonList.add(i); 314 } 315 316 return latMap.size() == 2 && lonMap.size() == 2 317 && latMap.containsKey(bBox.getBottomRight().lat()) && latMap.containsKey(bBox.getTopLeft().lat()) 318 && lonMap.containsKey(bBox.getBottomRight().lon()) && lonMap.containsKey(bBox.getTopLeft().lon()); 319 } 320 return false; 321 } 322 323 protected static final String getClosedWayBounds(Way cw) { 324 if (areClosedWayAndBboxEqual(cw, cw.getBBox())) { 325 return getBounds(cw, true); 326 } else { 327 return getBounds(cw, false) + getClosedWayShape(cw) + " </bounds>"; 328 } 329 } 330 331 protected static final String getClosedWayShape(Way cw) { 332 String result = " <shape>\n"; 333 for (int i=0; i<cw.getNodesCount(); i++) { 334 if (i%3 == 0) { 335 result += " "; 336 } 337 int j = i; 338 if(j == cw.getNodesCount()) 339 j = 0; 340 result += "<point "; 341 result += "lat='" + df.format(cw.getNode(i).getCoor().lat()) + "' "; 342 result += "lon='" + df.format(cw.getNode(i).getCoor().lon()) + "'/>"; 343 if (i%3 == 2 || i == cw.getNodesCount()-1 ) { 344 result += "\n"; 345 } 346 } 347 result += " </shape>\n"; 348 return result; 349 } 350 351 @Override 352 public void actionPerformed(ActionEvent e) { 353 System.out.println(getXml()); 354 } 263 result.append(EIGHT_SP + simpleTag(XML_MIN_ZOOM, minZoom) + "\n"); 264 } 265 } 266 result.append(" </entry>"); 267 return result.toString(); 268 } 269 270 protected static final String encodeUrl(String url) { 271 return "<![CDATA["+url+"]]>"; 272 } 273 274 protected static final String getBounds(OsmPrimitive p, boolean closeTag) { 275 BBox bbox = p.getBBox(); 276 String result = " <bounds "; 277 result += "min-lat='"+DF.format(bbox.getBottomRight().lat())+"' "; 278 result += "min-lon='"+DF.format(bbox.getTopLeft().lon())+"' "; 279 result += "max-lat='"+DF.format(bbox.getTopLeft().lat())+"' "; 280 result += "max-lon='"+DF.format(bbox.getBottomRight().lon())+"'"; 281 result += closeTag ? " />" : ">\n"; 282 return result; 283 } 284 285 protected static final boolean isValidOuterMember(RelationMember mb) { 286 return (mb.getRole() == null || mb.getRole().isEmpty() || "outer".equals(mb.getRole())) 287 && mb.getMember() instanceof Way && ((Way) mb.getMember()).isClosed(); 288 } 289 290 protected static final String getMultiPolygonBounds(Relation mp) { 291 List<Way> outerClosedWays = new ArrayList<>(); 292 for (RelationMember mb : mp.getMembers()) { 293 if (isValidOuterMember(mb)) { 294 outerClosedWays.add((Way) mb.getMember()); 295 } 296 } 297 298 if (outerClosedWays.isEmpty() || (outerClosedWays.size() == 1 && areClosedWayAndBboxEqual(outerClosedWays.get(0), mp.getBBox()))) { 299 return getBounds(mp, true); 300 } else { 301 StringBuilder result = new StringBuilder(getBounds(mp, false)); 302 for (Way way : outerClosedWays) { 303 result.append(getClosedWayShape(way)); 304 } 305 result.append(" </bounds>"); 306 return result.toString(); 307 } 308 } 309 310 protected static final boolean areClosedWayAndBboxEqual(Way way, BBox bBox) { 311 if (way.getNodesCount() == 5) { 312 Map<Double, List<Integer>> latMap = new HashMap<>(); 313 Map<Double, List<Integer>> lonMap = new HashMap<>(); 314 315 for (int i=0; i<4; i++) { 316 LatLon c = way.getNode(i).getCoor(); 317 if (i > 1) { 318 LatLon b = way.getNode(i-1).getCoor(); 319 if (b.lat() != c.lat() && b.lon() != c.lon()) { 320 return false; 321 } 322 } 323 List<Integer> latList = latMap.get(c.lat()); 324 if (latList == null) { 325 latList = new ArrayList<>(); 326 latMap.put(c.lat(), latList); 327 } 328 latList.add(i); 329 List<Integer> lonList = lonMap.get(c.lon()); 330 if (lonList == null) { 331 lonList = new ArrayList<>(); 332 lonMap.put(c.lon(), lonList); 333 } 334 lonList.add(i); 335 } 336 337 return latMap.size() == 2 && lonMap.size() == 2 338 && latMap.containsKey(bBox.getBottomRight().lat()) && latMap.containsKey(bBox.getTopLeft().lat()) 339 && lonMap.containsKey(bBox.getBottomRight().lon()) && lonMap.containsKey(bBox.getTopLeft().lon()); 340 } 341 return false; 342 } 343 344 protected static final String getClosedWayBounds(Way cw) { 345 if (areClosedWayAndBboxEqual(cw, cw.getBBox())) { 346 return getBounds(cw, true); 347 } else { 348 return getBounds(cw, false) + getClosedWayShape(cw) + " </bounds>"; 349 } 350 } 351 352 protected static final String getClosedWayShape(Way cw) { 353 StringBuilder result = new StringBuilder(" <shape>\n"); 354 for (int i=0; i<cw.getNodesCount(); i++) { 355 if (i%3 == 0) { 356 result.append(" "); 357 } 358 int j = i; 359 if(j == cw.getNodesCount()) 360 j = 0; 361 result.append("<point "); 362 result.append("lat='").append(DF.format(cw.getNode(i).getCoor().lat())).append("' "); 363 result.append("lon='").append(DF.format(cw.getNode(i).getCoor().lon())).append("'/>"); 364 if (i%3 == 2 || i == cw.getNodesCount()-1 ) { 365 result.append("\n"); 366 } 367 } 368 result.append(" </shape>\n"); 369 return result.toString(); 370 } 371 372 @Override 373 public void actionPerformed(ActionEvent e) { 374 if (Main.isDebugEnabled()) { 375 Main.debug(getXml()); 376 } 377 } 355 378 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/EditEntriesAction.java
r30342 r30735 9 9 10 10 import javax.swing.JTable; 11 import javax.swing.SwingUtilities;12 11 import javax.swing.event.ListSelectionEvent; 13 12 import javax.swing.event.ListSelectionListener; … … 17 16 import org.openstreetmap.josm.data.imagery.ImageryInfo; 18 17 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference.ImageryProvidersPanel.ImageryDefaultLayerTableModel; 18 import org.openstreetmap.josm.gui.util.GuiHelper; 19 19 import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants; 20 20 import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsLayer; 21 21 import org.openstreetmap.josm.plugins.imageryxmlbounds.data.XmlBoundsConverter; 22 22 23 @SuppressWarnings("serial") 23 /** 24 * Edit bounds for selected defaults. 25 */ 24 26 public class EditEntriesAction extends JosmAction implements XmlBoundsConstants, ListSelectionListener { 25 27 26 28 protected static final String ACTION_NAME = tr("Edit"); 27 29 28 29 30 private final JTable defaultTable; 31 private final ImageryDefaultLayerTableModel defaultModel; 30 32 31 33 private final List<ImageryInfo> entries; 32 34 33 public EditEntriesAction(JTable defaultTable, ImageryDefaultLayerTableModel defaultModel) { 35 /** 36 * Constructs a new {@code EditEntriesAction}. 37 * @param defaultTable table 38 * @param defaultModel table model 39 */ 40 public EditEntriesAction(JTable defaultTable, ImageryDefaultLayerTableModel defaultModel) { 34 41 putValue(SHORT_DESCRIPTION, tr("edit bounds for selected defaults")); 35 42 putValue(NAME, ACTION_NAME); 36 43 try { 37 44 putValue(SMALL_ICON, XML_ICON_24); 38 45 } catch (Exception ex) { 39 ex.printStackTrace();46 Main.error(ex); 40 47 } 41 48 this.defaultModel = defaultModel; 42 49 this.defaultTable = defaultTable; 43 50 this.defaultTable.getSelectionModel().addListSelectionListener(this); 44 this.entries = new ArrayList< ImageryInfo>();45 46 51 this.entries = new ArrayList<>(); 52 setEnabled(false); 53 } 47 54 48 49 50 51 55 @Override 56 public void actionPerformed(ActionEvent e) { 57 final XmlBoundsLayer layer = new XmlBoundsLayer( 58 XmlBoundsConverter.convertImageryEntries(entries)); 52 59 final Runnable uiStuff = new Runnable() { 53 60 @Override … … 57 64 } 58 65 }; 59 if (SwingUtilities.isEventDispatchThread()) { 60 uiStuff.run(); 61 } else { 62 SwingUtilities.invokeLater(uiStuff); 66 GuiHelper.runInEDT(uiStuff); 67 } 68 69 @Override 70 public void valueChanged(ListSelectionEvent e) { 71 if (!e.getValueIsAdjusting()) { 72 entries.clear(); 73 for (int row : defaultTable.getSelectedRows()) { 74 ImageryInfo info = defaultModel.getRow(row); 75 if (info != null && info.getBounds() != null) { 76 entries.add(info); 77 } 78 } 79 setEnabled(!entries.isEmpty()); 63 80 } 64 } 65 66 @Override 67 public void valueChanged(ListSelectionEvent e) { 68 if (!e.getValueIsAdjusting()) { 69 entries.clear(); 70 for (int row : defaultTable.getSelectedRows()) { 71 ImageryInfo info = defaultModel.getRow(row); 72 if (info != null && info.getBounds() != null) { 73 entries.add(info); 74 } 75 } 76 setEnabled(!entries.isEmpty()); 77 } 78 } 81 } 79 82 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ShowBoundsAction.java
r30342 r30735 19 19 20 20 /** 21 * Show XML bounds. 21 22 * @author Don-vip 22 *23 23 */ 24 @SuppressWarnings("serial")25 24 public class ShowBoundsAction extends ComputeBoundsAction implements OsmPrimitiveAction { 26 25 27 public ShowBoundsAction() { 28 } 29 30 public ShowBoundsAction(XmlBoundsLayer xmlBoundsLayer) { 31 super(xmlBoundsLayer); 32 } 26 /** 27 * Constructs a new {@code ShowBoundsAction}. 28 */ 29 public ShowBoundsAction() { 30 } 33 31 34 @Override 35 public void actionPerformed(ActionEvent e) { 36 XmlTextPane pane = new XmlTextPane(); 37 Font courierNew = Font.getFont("Courier New"); 38 if (courierNew != null) { 39 pane.setFont(courierNew); 40 } 41 pane.setText(getXml()); 42 pane.setEditable(false); 43 Box box = Box.createVerticalBox(); 44 JScrollPane scrollPane = new JScrollPane(pane); 32 /** 33 * Constructs a new {@code ShowBoundsAction}. 34 * @param xmlBoundsLayer XML bounds layer 35 */ 36 public ShowBoundsAction(XmlBoundsLayer xmlBoundsLayer) { 37 super(xmlBoundsLayer); 38 } 39 40 @Override 41 public void actionPerformed(ActionEvent e) { 42 XmlTextPane pane = new XmlTextPane(); 43 Font courierNew = Font.getFont("Courier New"); 44 if (courierNew != null) { 45 pane.setFont(courierNew); 46 } 47 pane.setText(getXml()); 48 pane.setEditable(false); 49 Box box = Box.createVerticalBox(); 50 JScrollPane scrollPane = new JScrollPane(pane); 45 51 scrollPane.setPreferredSize(new Dimension(1024, 600)); 46 52 box.add(scrollPane); 47 53 JOptionPane.showMessageDialog(Main.parent, box, ACTION_NAME, JOptionPane.PLAIN_MESSAGE); 48 54 } 49 55 50 56 @Override -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ShowBoundsSelectionAction.java
r30342 r30735 8 8 9 9 /** 10 * 10 * 11 11 * @author Don-vip 12 12 * 13 13 */ 14 @SuppressWarnings("serial")15 14 public class ShowBoundsSelectionAction extends ShowBoundsAction implements SelectionChangedListener { 16 15 17 public ShowBoundsSelectionAction() { 18 putValue("toolbar", "xml-imagery-bounds"); 19 } 16 /** 17 * Constructs a new {@code ShowBoundsSelectionAction}. 18 */ 19 public ShowBoundsSelectionAction() { 20 putValue("toolbar", "xml-imagery-bounds"); 21 } 20 22 21 22 23 24 23 @Override 24 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 25 updateOsmPrimitives(newSelection); 26 } 25 27 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/downloadtask/DownloadXmlBoundsTask.java
r30342 r30735 17 17 import org.openstreetmap.josm.plugins.imageryxmlbounds.io.JosmServerLocationReader; 18 18 19 /** 20 * Download imagery XML bounds from JOSM server. 21 */ 19 22 public class DownloadXmlBoundsTask extends DownloadOsmTask implements XmlBoundsConstants { 20 23 … … 49 52 50 53 protected class DownloadTask extends DownloadOsmTask.DownloadTask { 54 55 /** 56 * Constructs a new {@code DownloadTask}. 57 * @param newLayer if {@code true}, download to a new layer 58 * @param reader server reader 59 * @param progressMonitor progress monitor 60 */ 51 61 public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) { 52 62 super(newLayer, reader, progressMonitor); 53 63 } 54 64 55 65 @Override 56 66 protected OsmDataLayer getEditLayer() { -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/data/XmlBoundsConverter.java
r30393 r30735 8 8 import org.openstreetmap.josm.data.coor.LatLon; 9 9 import org.openstreetmap.josm.data.imagery.ImageryInfo; 10 import org.openstreetmap.josm.data.imagery.Shape;11 10 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; 12 11 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 12 import org.openstreetmap.josm.data.imagery.Shape; 13 13 import org.openstreetmap.josm.data.osm.BBox; 14 14 import org.openstreetmap.josm.data.osm.DataSet; … … 21 21 22 22 /** 23 * 23 * Converts imagery entries to bounds data. 24 24 * @author Don-vip 25 *26 25 */ 27 26 public class XmlBoundsConverter implements XmlBoundsConstants { 28 29 public static DataSet convertImageryEntries(List<ImageryInfo> entries) { 30 DataSet dataSet = new DataSet(); 31 32 for (ImageryInfo imagery : entries) { 33 if (!imagery.isBlacklisted()) { 34 ImageryBounds bounds = imagery.getBounds(); 35 if (bounds != null) { 36 dataSet.addPrimitive(convertImagery(imagery, bounds, dataSet)); 37 } 38 } 39 } 40 return dataSet; 41 } 42 43 private static void safePut(OsmPrimitive p, String key, Object value) { 44 if (value != null) { 45 if (value instanceof Collection) { 46 String s = ""; 47 for (Object elt : (Collection<?>)value) { 48 if (elt != null && elt.toString() != null && !elt.toString().isEmpty()) { 49 if (!s.isEmpty()) { 50 s += ";"; 51 } 52 s += elt.toString(); 53 } 54 } 55 if (!s.isEmpty()) { 56 p.put(key, s); 57 } 58 } else if (!value.equals(0) && value.toString() != null && !value.toString().isEmpty()) { 59 p.put(key, value.toString()); 60 } 61 } 62 } 63 27 28 /** 29 * Convert a list of imagery entries to a dataset containing associated bounds. 30 * @param entries imagery entries 31 * @return dataset containing associated bounds 32 */ 33 public static DataSet convertImageryEntries(List<ImageryInfo> entries) { 34 DataSet dataSet = new DataSet(); 35 36 for (ImageryInfo imagery : entries) { 37 if (!imagery.isBlacklisted()) { 38 ImageryBounds bounds = imagery.getBounds(); 39 if (bounds != null) { 40 dataSet.addPrimitive(convertImagery(imagery, bounds, dataSet)); 41 } 42 } 43 } 44 return dataSet; 45 } 46 47 private static void safePut(OsmPrimitive p, String key, Object value) { 48 if (value != null) { 49 if (value instanceof Collection) { 50 StringBuilder s = new StringBuilder(""); 51 for (Object elt : (Collection<?>)value) { 52 if (elt != null && elt.toString() != null && !elt.toString().isEmpty()) { 53 if (s.length() > 0) { 54 s.append(";"); 55 } 56 s.append(elt.toString()); 57 } 58 } 59 if (s.length() > 0) { 60 p.put(key, s.toString()); 61 } 62 } else if (!value.equals(0) && value.toString() != null && !value.toString().isEmpty()) { 63 p.put(key, value.toString()); 64 } 65 } 66 } 67 64 68 private static Node getNode(LatLon latlon, DataSet dataSet) { 65 69 List<Node> nodes = dataSet.searchNodes(new BBox(latlon, latlon)); … … 73 77 } 74 78 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 79 private static Node getNode(double lat, double lon, DataSet dataSet) { 80 return getNode(new LatLon(lat, lon), dataSet); 81 } 82 83 private static void ensureWayIsClosed(Way way) { 84 if (!way.getNode(0).equals(way.getNode(way.getNodesCount()-1))) { 85 way.addNode(way.getNode(0)); 86 } 87 } 88 89 private static OsmPrimitive convertImagery(ImageryInfo imagery, ImageryBounds bounds, DataSet dataSet) { 90 OsmPrimitive osmImagery = null; 91 if (bounds.getShapes().isEmpty()) { 92 LatLon bottomLeft = bounds.getMin(); 93 LatLon topRight = bounds.getMax(); 94 LatLon topLeft = new LatLon(topRight.lat(), bottomLeft.lon()); 95 LatLon bottomRight = new LatLon(bottomLeft.lat(), topRight.lon()); 96 97 Way way = new Way(); 98 for (LatLon ll : new LatLon[]{bottomLeft, topLeft, topRight, bottomRight}) { 99 way.addNode(getNode(ll, dataSet)); 100 } 101 ensureWayIsClosed(way); 102 osmImagery = way; 103 104 } else { 105 Relation relation = new Relation(); 106 relation.put("type", "multipolygon"); 107 for (Shape shape : bounds.getShapes()) { 108 Way way = new Way(); 109 for (Coordinate coor : shape.getPoints()) { 110 way.addNode(getNode(coor.getLat(), coor.getLon(), dataSet)); 111 } 112 ensureWayIsClosed(way); 113 dataSet.addPrimitive(way); 114 relation.addMember(new RelationMember("outer", way)); 115 } 116 osmImagery = relation; 117 } 118 119 safePut(osmImagery, KEY_NAME, imagery.getOriginalName()); 120 safePut(osmImagery, KEY_TYPE, imagery.getImageryType().getTypeString()); 121 safePut(osmImagery, KEY_DEFAULT, imagery.isDefaultEntry()); 122 safePut(osmImagery, KEY_URL, imagery.getUrl()); 123 safePut(osmImagery, KEY_PROJECTIONS, imagery.getServerProjections()); 124 safePut(osmImagery, KEY_EULA, imagery.getEulaAcceptanceRequired()); 125 safePut(osmImagery, KEY_ATTR_TEXT, imagery.getAttributionText(0, null, null)); 126 safePut(osmImagery, KEY_ATTR_URL, imagery.getAttributionLinkURL()); 123 127 safePut(osmImagery, KEY_TERMS_TEXT, imagery.getTermsOfUseText()); 124 125 126 128 safePut(osmImagery, KEY_TERMS_URL, imagery.getTermsOfUseURL()); 129 safePut(osmImagery, KEY_COUNTRY_CODE, imagery.getCountryCode()); 130 safePut(osmImagery, KEY_LOGO_URL, imagery.getAttributionImageURL()); 127 131 128 129 130 131 132 133 134 132 if (imagery.getImageryType().equals(ImageryType.TMS)) { 133 safePut(osmImagery, KEY_MAX_ZOOM, imagery.getMaxZoom()); 134 safePut(osmImagery, KEY_MIN_ZOOM, imagery.getMinZoom()); 135 } 136 137 return osmImagery; 138 } 135 139 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/JosmServerLocationReader.java
r30342 r30735 9 9 import org.openstreetmap.josm.io.OsmTransferException; 10 10 11 /** 12 * Read XML bounds from JOSM server. 13 */ 11 14 public class JosmServerLocationReader extends OsmServerReader { 12 15 13 16 private String url; 14 17 18 /** 19 * Constructs a new {@code JosmServerLocationReader}. 20 * @param url URL to read 21 */ 15 22 public JosmServerLocationReader(String url) { 16 23 this.url = url; -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/ValidatingImageryReader.java
r30495 r30735 21 21 public class ValidatingImageryReader extends ImageryReader implements XmlBoundsConstants { 22 22 23 public ValidatingImageryReader(String source) throws SAXException, IOException { 24 this(source, true); 25 } 23 /** 24 * Constructs a new {@code ValidatingImageryReader}. 25 * @param source input source URL 26 * @throws SAXException if a SAX error occurs during parsing 27 * @throws IOException if any I/O error occurs 28 */ 29 public ValidatingImageryReader(String source) throws SAXException, IOException { 30 this(source, true); 31 } 26 32 27 public ValidatingImageryReader(String source, boolean validateFirst) throws SAXException, IOException { 28 super(source); 29 if (validateFirst) { 30 validate(source); 31 } 32 } 33 /** 34 * Constructs a new {@code ValidatingImageryReader}. 35 * @param source input source URL 36 * @param validateFirst if {@code true}, the source if validated first 37 * @throws SAXException if a SAX error occurs during parsing 38 * @throws IOException if any I/O error occurs 39 */ 40 public ValidatingImageryReader(String source, boolean validateFirst) throws SAXException, IOException { 41 super(source); 42 if (validateFirst) { 43 validate(source); 44 } 45 } 33 46 34 public static void validate(String source) throws SAXException, IOException { 47 /** 48 * Validates input against the JOSM Maps XSD. 49 * @param source input source URL 50 * @throws SAXException if a SAX error occurs during parsing 51 * @throws IOException if any I/O error occurs 52 */ 53 public static void validate(String source) throws SAXException, IOException { 35 54 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 36 55 Schema schema = factory.newSchema(new StreamSource(new CachedFile(XML_SCHEMA).getInputStream())); 37 56 schema.newValidator().validate(new StreamSource(source)); 38 57 } 39 58 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/XmlBoundsExporter.java
r30342 r30735 21 21 public class XmlBoundsExporter extends FileExporter implements XmlBoundsConstants { 22 22 23 public XmlBoundsExporter() { 24 super(FILE_FILTER); 25 } 23 /** 24 * Constructs a new {@code XmlBoundsExporter}. 25 */ 26 public XmlBoundsExporter() { 27 super(FILE_FILTER); 28 } 26 29 27 @Override 28 public void exportData(File file, Layer layer) throws IOException { 29 if (layer instanceof OsmDataLayer) { 30 Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), ENCODING)); 31 try { 32 writer.write(new ComputeBoundsAction((OsmDataLayer) layer).getXml()); 33 } finally { 34 writer.close(); 35 } 36 } 37 } 30 @Override 31 public void exportData(File file, Layer layer) throws IOException { 32 if (layer instanceof OsmDataLayer) { 33 try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), ENCODING))) { 34 writer.write(new ComputeBoundsAction((OsmDataLayer) layer).getXml()); 35 } 36 } 37 } 38 38 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/XmlBoundsImporter.java
r30342 r30735 9 9 10 10 import javax.swing.JOptionPane; 11 import javax.swing.SwingUtilities;12 11 13 12 import org.openstreetmap.josm.Main; 14 13 import org.openstreetmap.josm.data.osm.DataSet; 15 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 import org.openstreetmap.josm.gui.util.GuiHelper; 16 16 import org.openstreetmap.josm.io.FileImporter; 17 17 import org.openstreetmap.josm.io.IllegalDataException; … … 28 28 public class XmlBoundsImporter extends FileImporter implements XmlBoundsConstants { 29 29 30 public XmlBoundsImporter() { 31 super(FILE_FILTER); 32 } 33 34 public DataSet parseDataSet(final String source) throws IOException, SAXException { 35 return parseDataSet(source, null); 36 } 30 public XmlBoundsImporter() { 31 super(FILE_FILTER); 32 } 37 33 38 public DataSet parseDataSet(final File file) throws IOException, SAXException { 34 public DataSet parseDataSet(final String source) throws IOException, SAXException { 35 return parseDataSet(source, null); 36 } 37 38 public DataSet parseDataSet(final File file) throws IOException, SAXException { 39 39 return parseDataSet(null, file); 40 40 } 41 42 41 42 protected DataSet parseDataSet(final String source, final File file) throws IOException, SAXException { 43 43 ImageryReader reader = null; 44 44 45 45 try { 46 46 reader = new ValidatingImageryReader(source != null ? source : file.getAbsolutePath()); … … 48 48 if (JOptionPane.showConfirmDialog( 49 49 Main.parent, 50 tr("Validating error in file {0}:\n{1}\nDo you want to continue without validating the file ?", 50 tr("Validating error in file {0}:\n{1}\nDo you want to continue without validating the file ?", 51 51 source != null ? source : file.getPath(), e.getLocalizedMessage()), 52 52 tr("Open Imagery XML file"), … … 57 57 reader = new ImageryReader(source != null ? source : file.getAbsolutePath()); 58 58 } 59 59 60 60 return XmlBoundsConverter.convertImageryEntries(reader.parse()); 61 62 61 } 62 63 63 protected void importData(final String source, final String layerName, final File file, ProgressMonitor progressMonitor) 64 64 throws IOException, IllegalDataException { … … 78 78 } 79 79 }; 80 if (SwingUtilities.isEventDispatchThread()) { 81 uiStuff.run(); 82 } else { 83 SwingUtilities.invokeLater(uiStuff); 84 } 80 GuiHelper.runInEDT(uiStuff); 85 81 } catch (SAXException e) { 86 82 e.printStackTrace(); 87 83 } 88 84 } 89 90 @Override 91 public void importData(final File file, ProgressMonitor progressMonitor) 92 throws IOException, IllegalDataException { 93 importData(null, null, file, progressMonitor); 94 } 95 96 public void importData(final String source, final String layerName, ProgressMonitor progressMonitor) 97 throws IOException, IllegalDataException { 98 importData(source, layerName, null, progressMonitor); 85 86 @Override 87 public void importData(final File file, ProgressMonitor progressMonitor) 88 throws IOException, IllegalDataException { 89 importData(null, null, file, progressMonitor); 99 90 } 100 91 101 @Override 102 public void importData(List<File> files, ProgressMonitor progressMonitor) 103 throws IOException, IllegalDataException { 104 for (File file : files) { 105 importData(file, progressMonitor); 106 } 107 } 92 public void importData(final String source, final String layerName, ProgressMonitor progressMonitor) 93 throws IOException, IllegalDataException { 94 importData(source, layerName, null, progressMonitor); 95 } 96 97 @Override 98 public void importData(List<File> files, ProgressMonitor progressMonitor) 99 throws IOException, IllegalDataException { 100 for (File file : files) { 101 importData(file, progressMonitor); 102 } 103 } 108 104 }
Note:
See TracChangeset
for help on using the changeset viewer.