Changeset 12594 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-08-12T11:24:39+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r12593 r12594 18 18 import java.util.LinkedList; 19 19 import java.util.Optional; 20 import java.util.Set;21 20 22 21 import javax.swing.JOptionPane; -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/ColorfulImageProcessor.java
r11914 r12594 3 3 4 4 import java.awt.image.BufferedImage; 5 import java.util.Collections; 6 import java.util.Map; 5 7 6 8 import org.openstreetmap.josm.gui.layer.ImageProcessor; 9 import org.openstreetmap.josm.io.session.SessionAwareReadApply; 10 import org.openstreetmap.josm.tools.Utils; 7 11 8 12 /** … … 12 16 * @since 10547 13 17 */ 14 public class ColorfulImageProcessor implements ImageProcessor {18 public class ColorfulImageProcessor implements ImageProcessor, SessionAwareReadApply { 15 19 private ColorfulFilter op; 16 private double colorfulness = 1 ;20 private double colorfulness = 1.0; 17 21 18 22 /** … … 52 56 53 57 @Override 58 public void applyFromPropertiesMap(Map<String, String> properties) { 59 String cStr = properties.get("colorfulness"); 60 if (cStr != null) { 61 try { 62 setColorfulness(Double.parseDouble(cStr)); 63 } catch (NumberFormatException e) { 64 // nothing 65 } 66 } 67 } 68 69 @Override 70 public Map<String, String> toPropertiesMap() { 71 if (Utils.equalsEpsilon(colorfulness, 1.0)) 72 return Collections.emptyMap(); 73 else 74 return Collections.singletonMap("colorfulness", Double.toString(colorfulness)); 75 } 76 77 @Override 54 78 public String toString() { 55 79 return "ColorfulImageProcessor [colorfulness=" + colorfulness + ']'; -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/GammaImageProcessor.java
r10547 r12594 6 6 import java.awt.image.LookupOp; 7 7 import java.awt.image.ShortLookupTable; 8 import java.util.Collections; 9 import java.util.Map; 8 10 9 11 import org.openstreetmap.josm.Main; 10 12 import org.openstreetmap.josm.gui.layer.ImageProcessor; 13 import org.openstreetmap.josm.io.session.SessionAwareReadApply; 14 import org.openstreetmap.josm.tools.Utils; 11 15 12 16 /** … … 14 18 * @since 10547 15 19 */ 16 public class GammaImageProcessor implements ImageProcessor {17 private double gamma = 1 ;20 public class GammaImageProcessor implements ImageProcessor, SessionAwareReadApply { 21 private double gamma = 1.0; 18 22 final short[] gammaChange = new short[256]; 19 23 private final LookupOp op3 = new LookupOp( … … 43 47 @Override 44 48 public BufferedImage process(BufferedImage image) { 45 if (gamma == 1 ) {49 if (gamma == 1.0) { 46 50 return image; 47 51 } … … 63 67 64 68 @Override 69 public void applyFromPropertiesMap(Map<String, String> properties) { 70 String cStr = properties.get("gamma"); 71 if (cStr != null) { 72 try { 73 setGamma(Double.parseDouble(cStr)); 74 } catch (NumberFormatException e) { 75 // nothing 76 } 77 } 78 } 79 80 @Override 81 public Map<String, String> toPropertiesMap() { 82 if (Utils.equalsEpsilon(gamma, 1.0)) 83 return Collections.emptyMap(); 84 else 85 return Collections.singletonMap("gamma", Double.toString(gamma)); 86 } 87 88 @Override 65 89 public String toString() { 66 90 return "GammaImageProcessor [gamma=" + gamma + ']'; -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/SharpenImageProcessor.java
r12537 r12594 5 5 import java.awt.image.ConvolveOp; 6 6 import java.awt.image.Kernel; 7 import java.util.Collections; 8 import java.util.Map; 7 9 8 10 import org.openstreetmap.josm.gui.layer.ImageProcessor; 11 import org.openstreetmap.josm.io.session.SessionAwareReadApply; 12 import org.openstreetmap.josm.tools.Utils; 9 13 10 14 /** … … 18 22 * @since 10547 19 23 */ 20 public class SharpenImageProcessor implements ImageProcessor {21 private float sharpenLevel = 1 ;24 public class SharpenImageProcessor implements ImageProcessor, SessionAwareReadApply { 25 private float sharpenLevel = 1.0f; 22 26 private ConvolveOp op; 23 27 … … 89 93 90 94 @Override 95 public void applyFromPropertiesMap(Map<String, String> properties) { 96 String vStr = properties.get("sharpenlevel"); 97 if (vStr != null) { 98 try { 99 setSharpenLevel(Float.parseFloat(vStr)); 100 } catch (NumberFormatException e) { 101 // nothing 102 } 103 } 104 } 105 106 @Override 107 public Map<String, String> toPropertiesMap() { 108 if (Utils.equalsEpsilon(sharpenLevel, 1.0)) 109 return Collections.emptyMap(); 110 else 111 return Collections.singletonMap("sharpenlevel", Float.toString(sharpenLevel)); 112 } 113 114 @Override 91 115 public String toString() { 92 116 return "SharpenImageProcessor [sharpenLevel=" + sharpenLevel + ']'; -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java
r12267 r12594 5 5 import java.awt.GridBagLayout; 6 6 import java.io.IOException; 7 import java.util.HashMap; 7 8 import java.util.LinkedHashMap; 8 9 import java.util.Map; … … 20 21 import org.openstreetmap.josm.gui.layer.WMSLayer; 21 22 import org.openstreetmap.josm.gui.layer.WMTSLayer; 23 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings; 22 24 import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport; 23 25 import org.openstreetmap.josm.tools.GBC; 26 import org.openstreetmap.josm.tools.Utils; 24 27 import org.w3c.dom.Element; 25 28 … … 95 98 } 96 99 } 100 ImageryFilterSettings filters = layer.getFilterSettings(); 101 if (filters != null) { 102 Map<String, String> filterProps = new HashMap<>(); 103 filters.getProcessors().stream() 104 .flatMap(Utils.castToStream(SessionAwareReadApply.class)) 105 .forEach(proc -> filterProps.putAll(proc.toPropertiesMap())); 106 if (!filterProps.isEmpty()) { 107 Element filterEl = support.createElement("filters"); 108 layerElem.appendChild(filterEl); 109 addAttributes(filterEl, filterProps, support); 110 } 111 } 97 112 return layerElem; 98 113 } -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java
r12267 r12594 18 18 import org.openstreetmap.josm.gui.layer.WMSLayer; 19 19 import org.openstreetmap.josm.gui.layer.WMTSLayer; 20 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings; 20 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 22 import org.openstreetmap.josm.io.IllegalDataException; 22 23 import org.openstreetmap.josm.io.session.SessionReader.ImportSupport; 24 import org.openstreetmap.josm.tools.Utils; 23 25 import org.w3c.dom.Element; 24 26 import org.w3c.dom.Node; … … 45 47 AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer; 46 48 tsLayer.getDisplaySettings().loadFrom(attributes); 47 NodeList nodes = elem.getChildNodes(); 48 for (int i = 0; i < nodes.getLength(); ++i) { 49 Node node = nodes.item(i); 50 if (node.getNodeType() == Node.ELEMENT_NODE && "offset".equals(node.getLocalName())) { 51 Map<String, String> offsetAttributes = readProperties((Element) node); 52 OffsetBookmark offset = OffsetBookmark.fromPropertiesMap(offsetAttributes); 53 tsLayer.getDisplaySettings().setOffsetBookmark(offset); 54 break; 55 } 49 Element offsetEl = getFirstElementByTagName(elem, "offset"); 50 if (offsetEl != null) { 51 Map<String, String> offsetAttributes = readProperties(offsetEl); 52 OffsetBookmark offset = OffsetBookmark.fromPropertiesMap(offsetAttributes); 53 tsLayer.getDisplaySettings().setOffsetBookmark(offset); 54 } 55 } 56 Element filtersEl = getFirstElementByTagName(elem, "filters"); 57 if (filtersEl != null) { 58 ImageryFilterSettings filterSettings = layer.getFilterSettings(); 59 if (filterSettings != null) { 60 Map<String, String> filtersProps = readProperties(filtersEl); 61 filterSettings.getProcessors().stream() 62 .flatMap(Utils.castToStream(SessionAwareReadApply.class)) 63 .forEach(proc -> proc.applyFromPropertiesMap(filtersProps)); 56 64 } 57 65 } 58 66 return layer; 67 } 68 69 private static Element getFirstElementByTagName(Element el, String name) { 70 NodeList nl = el.getElementsByTagName(name); 71 if (nl.getLength() == 0) 72 return null; 73 return (Element) nl.item(0); 59 74 } 60 75 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12238 r12594 55 55 import java.util.regex.Matcher; 56 56 import java.util.regex.Pattern; 57 import java.util.stream.Stream; 57 58 import java.util.zip.GZIPInputStream; 58 59 import java.util.zip.ZipEntry; … … 1690 1691 return null; 1691 1692 } 1693 1694 /** 1695 * Get a function that converts an object to a singleton stream of a certain 1696 * class (or null if the object cannot be cast to that class). 1697 * 1698 * Can be useful in relation with streams, but be aware of the performance 1699 * implications of creating a stream for each element. 1700 * @param <T> type of the objects to convert 1701 * @param <U> type of the elements in the resulting stream 1702 * @param klass the class U 1703 * @return function converting an object to a singleton stream or null 1704 */ 1705 public static <T, U> Function<T, Stream<U>> castToStream(Class<U> klass) { 1706 return x -> klass.isInstance(x) ? Stream.of(klass.cast(x)) : null; 1707 } 1692 1708 }
Note:
See TracChangeset
for help on using the changeset viewer.