Changeset 17880 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2021-05-10T21:44:33+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java
r17878 r17880 207 207 public File getFile() { 208 208 return file; 209 } 210 211 /** 212 * Returns a display name for this entry 213 * @return a display name for this entry 214 */ 215 public String getDisplayName() { 216 return file == null ? "" : file.getName(); 209 217 } 210 218 -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r17767 r17880 130 130 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 131 131 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 132 import org.openstreetmap.josm.gui.layer.geoimage.WikimediaCommonsLoader; 132 133 import org.openstreetmap.josm.gui.mappaint.MapPaintMenu; 133 134 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; … … 748 749 add(fileMenu, searchNotes); 749 750 add(fileMenu, downloadNotesInView); 751 add(fileMenu, new WikimediaCommonsLoader.Action()); 750 752 add(fileMenu, downloadReferrers); 751 753 add(fileMenu, update); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r17878 r17880 702 702 @Override 703 703 public String getElementAt(int i) { 704 return yLayer.getImageData().getImages().get(i).get File().getName();704 return yLayer.getImageData().getImages().get(i).getDisplayName(); 705 705 } 706 706 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r17872 r17880 703 703 } 704 704 if (errorLoading) { 705 String loadingStr = tr("Error on file {0}", entry.get File().getName());705 String loadingStr = tr("Error on file {0}", entry.getDisplayName()); 706 706 Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(loadingStr, g); 707 707 g.drawString(loadingStr, … … 749 749 // we are probably still loading the image. (oldEntry gets set to entry when the image finishes loading). 750 750 if (!errorLoading) { 751 errorMessage = tr("Loading {0}", entry.get File().getName());751 errorMessage = tr("Loading {0}", entry.getDisplayName()); 752 752 } else { 753 errorMessage = tr("Error on file {0}", entry.get File().getName());753 errorMessage = tr("Error on file {0}", entry.getDisplayName()); 754 754 } 755 755 } else { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
r17872 r17880 10 10 import java.io.IOException; 11 11 import java.io.UncheckedIOException; 12 import java.net.MalformedURLException; 13 import java.net.URL; 12 14 import java.util.Collections; 13 15 import java.util.Objects; … … 29 31 * @since 2662 30 32 */ 31 public finalclass ImageEntry extends GpxImageEntry {33 public class ImageEntry extends GpxImageEntry { 32 34 33 35 private Image thumbnail; … … 141 143 */ 142 144 public BufferedImage read(Dimension target) throws IOException { 143 Logging.info(tr("Loading {0}", getFile().getPath())); 144 BufferedImage image = ImageProvider.read(getFile(), false, false, 145 URL imageUrl = getImageUrl(); 146 Logging.info(tr("Loading {0}", imageUrl)); 147 BufferedImage image = ImageProvider.read(imageUrl, false, false, 145 148 r -> target == null ? r.getDefaultReadParam() : withSubsampling(r, target)); 146 149 Logging.debug("Loaded {0} with dimensions {1}x{2} memoryTaken={3}m exifOrientationSwitchedDimension={4}", 147 getFile().getPath(), image.getWidth(), image.getHeight(), image.getWidth() * image.getHeight() * 4 / 1024 / 1024,150 imageUrl, image.getWidth(), image.getHeight(), image.getWidth() * image.getHeight() * 4 / 1024 / 1024, 148 151 ExifReader.orientationSwitchesDimensions(getExifOrientation())); 149 152 return applyExifRotation(image); 153 } 154 155 protected URL getImageUrl() throws MalformedURLException { 156 return getFile().toURI().toURL(); 150 157 } 151 158 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r17740 r17880 372 372 public void actionPerformed(ActionEvent e) { 373 373 if (currentData != null) { 374 ClipboardUtils.copyString( currentData.getSelectedImage().getFile().toString());374 ClipboardUtils.copyString(String.valueOf(currentData.getSelectedImage().getFile())); 375 375 } 376 376 } … … 461 461 setPreviousEnabled(data.hasPreviousImage()); 462 462 btnDelete.setEnabled(true); 463 btnDeleteFromDisk.setEnabled( true);463 btnDeleteFromDisk.setEnabled(entry.getFile() != null); 464 464 btnCopyPath.setEnabled(true); 465 465 … … 469 469 imgDisplay.setImage(entry); 470 470 } 471 setTitle(tr("Geotagged Images") + ( entry.getFile() != null ? " - " + entry.getFile().getName() : ""));472 StringBuilder osd = new StringBuilder(entry.get File() != null ? entry.getFile().getName() : "");471 setTitle(tr("Geotagged Images") + (!entry.getDisplayName().isEmpty() ? " - " + entry.getDisplayName() : "")); 472 StringBuilder osd = new StringBuilder(entry.getDisplayName()); 473 473 if (entry.getElevation() != null) { 474 474 osd.append(tr("\nAltitude: {0} m", Math.round(entry.getElevation()))); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r17871 r17880 1549 1549 */ 1550 1550 public static BufferedImage read(File input, boolean readMetadata, boolean enforceTransparency) throws IOException { 1551 return read(input, readMetadata, enforceTransparency, ImageReader::getDefaultReadParam);1552 }1553 1554 /**1555 * Returns a <code>BufferedImage</code> as the result of decoding1556 * a supplied <code>File</code> with an <code>ImageReader</code>1557 * chosen automatically from among those currently registered.1558 * The <code>File</code> is wrapped in an1559 * <code>ImageInputStream</code>. If no registered1560 * <code>ImageReader</code> claims to be able to read the1561 * resulting stream, <code>null</code> is returned.1562 *1563 * <p> The current cache settings from <code>getUseCache</code>and1564 * <code>getCacheDirectory</code> will be used to control caching in the1565 * <code>ImageInputStream</code> that is created.1566 *1567 * <p> Note that there is no <code>read</code> method that takes a1568 * filename as a <code>String</code>; use this method instead after1569 * creating a <code>File</code> from the filename.1570 *1571 * <p> This method does not attempt to locate1572 * <code>ImageReader</code>s that can read directly from a1573 * <code>File</code>; that may be accomplished using1574 * <code>IIORegistry</code> and <code>ImageReaderSpi</code>.1575 *1576 * @param input a <code>File</code> to read from.1577 * @param readMetadata if {@code true}, makes sure to read image metadata to detect transparency color, if any.1578 * In that case the color can be retrieved later through {@link #PROP_TRANSPARENCY_COLOR}.1579 * Always considered {@code true} if {@code enforceTransparency} is also {@code true}1580 * @param enforceTransparency if {@code true}, makes sure to read image metadata and, if the image does not1581 * provide an alpha channel but defines a {@code TransparentColor} metadata node, that the resulting image1582 * has a transparency set to {@code TRANSLUCENT} and uses the correct transparent color.1583 * @param readParamFunction a function to compute the read parameters from the image reader1584 *1585 * @return a <code>BufferedImage</code> containing the decoded contents of the input, or <code>null</code>.1586 *1587 * @throws IllegalArgumentException if <code>input</code> is <code>null</code>.1588 * @throws IOException if an error occurs during reading.1589 * @see BufferedImage#getProperty1590 * @since xxx1591 */1592 public static BufferedImage read(File input, boolean readMetadata, boolean enforceTransparency,1593 Function<ImageReader, ImageReadParam> readParamFunction) throws IOException {1594 1551 CheckParameterUtil.ensureParameterNotNull(input, "input"); 1595 1552 if (!input.canRead()) { … … 1601 1558 throw new IIOException("Can't create an ImageInputStream!"); 1602 1559 } 1603 BufferedImage bi = read(stream, readMetadata, enforceTransparency , readParamFunction);1560 BufferedImage bi = read(stream, readMetadata, enforceTransparency); 1604 1561 if (bi == null) { 1605 1562 stream.close(); … … 1688 1645 */ 1689 1646 public static BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency) throws IOException { 1647 return read(input, readMetadata, enforceTransparency, ImageReader::getDefaultReadParam); 1648 } 1649 1650 /** 1651 * Returns a <code>BufferedImage</code> as the result of decoding 1652 * a supplied <code>URL</code> with an <code>ImageReader</code> 1653 * chosen automatically from among those currently registered. An 1654 * <code>InputStream</code> is obtained from the <code>URL</code>, 1655 * which is wrapped in an <code>ImageInputStream</code>. If no 1656 * registered <code>ImageReader</code> claims to be able to read 1657 * the resulting stream, <code>null</code> is returned. 1658 * 1659 * <p> The current cache settings from <code>getUseCache</code>and 1660 * <code>getCacheDirectory</code> will be used to control caching in the 1661 * <code>ImageInputStream</code> that is created. 1662 * 1663 * <p> This method does not attempt to locate 1664 * <code>ImageReader</code>s that can read directly from a 1665 * <code>URL</code>; that may be accomplished using 1666 * <code>IIORegistry</code> and <code>ImageReaderSpi</code>. 1667 * 1668 * @param input a <code>URL</code> to read from. 1669 * @param readMetadata if {@code true}, makes sure to read image metadata to detect transparency color for non translucent images, if any. 1670 * In that case the color can be retrieved later through {@link #PROP_TRANSPARENCY_COLOR}. 1671 * Always considered {@code true} if {@code enforceTransparency} is also {@code true} 1672 * @param enforceTransparency if {@code true}, makes sure to read image metadata and, if the image does not 1673 * provide an alpha channel but defines a {@code TransparentColor} metadata node, that the resulting image 1674 * has a transparency set to {@code TRANSLUCENT} and uses the correct transparent color. 1675 * @param readParamFunction a function to compute the read parameters from the image reader 1676 * 1677 * @return a <code>BufferedImage</code> containing the decoded contents of the input, or <code>null</code>. 1678 * 1679 * @throws IllegalArgumentException if <code>input</code> is <code>null</code>. 1680 * @throws IOException if an error occurs during reading. 1681 * @since 17880 1682 */ 1683 public static BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency, 1684 Function<ImageReader, ImageReadParam> readParamFunction) throws IOException { 1690 1685 CheckParameterUtil.ensureParameterNotNull(input, "input"); 1691 1686 1692 1687 try (InputStream istream = Utils.openStream(input)) { 1693 1688 ImageInputStream stream = createImageInputStream(istream); // NOPMD 1694 BufferedImage bi = read(stream, readMetadata, enforceTransparency );1689 BufferedImage bi = read(stream, readMetadata, enforceTransparency, readParamFunction); 1695 1690 if (bi == null) { 1696 1691 stream.close(); -
trunk/src/org/openstreetmap/josm/tools/Mediawiki.java
r16988 r17880 7 7 import java.util.List; 8 8 import java.util.Optional; 9 import java.util.function.BiConsumer; 9 10 import java.util.stream.Collectors; 10 11 … … 15 16 import javax.xml.xpath.XPathFactory; 16 17 18 import org.openstreetmap.josm.data.Bounds; 19 import org.openstreetmap.josm.data.coor.LatLon; 17 20 import org.w3c.dom.Document; 21 import org.w3c.dom.NamedNodeMap; 18 22 import org.w3c.dom.Node; 23 import org.w3c.dom.NodeList; 19 24 import org.xml.sax.SAXException; 20 25 … … 53 58 .collect(Collectors.joining(Utils.encodeUrl("|"))) 54 59 ); 55 final HttpClient.Response conn = HttpClient.create(url).connect(); 56 final Document document; 57 try (InputStream content = conn.getContent()) { 58 document = XmlUtils.parseSafeDOM(content); 59 } 60 conn.disconnect(); 60 final Document document = getDocument(url); 61 61 final XPath xPath = XPathFactory.newInstance().newXPath(); 62 62 for (String page : distinctPages) { … … 75 75 } 76 76 77 private Document getDocument(URL url) throws IOException, ParserConfigurationException, SAXException { 78 final HttpClient.Response conn = HttpClient.create(url).connect(); 79 try (InputStream content = conn.getContent()) { 80 return XmlUtils.parseSafeDOM(content); 81 } finally { 82 conn.disconnect(); 83 } 84 } 85 86 /** 87 * Searches geocoded images from <a href="https://commons.wikimedia.org/">Wikimedia Commons</a> for the given bounding box. 88 * @param bounds the bounds to load 89 * @param imageConsumer a consumer to receive the file title and the coordinates for every geocoded image 90 * @throws IOException if any I/O error occurs 91 * @throws ParserConfigurationException if a parser cannot be created 92 * @throws SAXException if any XML error occurs 93 * @throws XPathExpressionException if any error in an XPath expression occurs 94 */ 95 public void searchGeoImages(Bounds bounds, BiConsumer<String, LatLon> imageConsumer) 96 throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { 97 final URL url = new URL(baseUrl + 98 "?format=xml" + 99 "&action=query" + 100 "&list=geosearch" + 101 "&gsnamespace=6" + 102 "&gslimit=500" + 103 "&gsprop=type|name" + 104 "&gsbbox=" + bounds.getMaxLat() + "|" + bounds.getMinLon() + "|" + bounds.getMinLat() + "|" + bounds.getMaxLon()); 105 final Document document = getDocument(url); 106 final XPath xPath = XPathFactory.newInstance().newXPath(); 107 NodeList nodes = (NodeList) xPath.evaluate("/api/query/geosearch/gs", document, XPathConstants.NODESET); 108 for (int i = 0; i < nodes.getLength(); i++) { 109 NamedNodeMap attributes = nodes.item(i).getAttributes(); 110 String title = attributes.getNamedItem("title").getNodeValue(); 111 double lat = Double.parseDouble(attributes.getNamedItem("lat").getNodeValue()); 112 double lon = Double.parseDouble(attributes.getNamedItem("lon").getNodeValue()); 113 imageConsumer.accept(title, new LatLon(lat, lon)); 114 } 115 } 116 77 117 /** 78 118 * Computes the URL for the given filename on the MediaWiki server
Note:
See TracChangeset
for help on using the changeset viewer.