Changeset 12892 in osm for applications
- Timestamp:
- 2009-01-04T00:25:32+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r12778 r12892 258 258 } 259 259 260 way.put(" created_by", "Dshpak_landsat_lakes");260 way.put("source", Main.pref.get(LakewalkerPreferences.PREF_SOURCE, "water")); 261 261 commands.add(new AddCommand(way)); 262 262 … … 277 277 } 278 278 279 way.put(" created_by", "Dshpak_landsat_lakes");279 way.put("source", Main.pref.get(LakewalkerPreferences.PREF_SOURCE, "water")); 280 280 281 281 way.nodes.add(fn); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java
r12588 r12892 1 1 package org.openstreetmap.josm.plugins.lakewalker; 2 2 3 import static org.openstreetmap.josm.tools.I18n.marktr; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 … … 12 13 import org.openstreetmap.josm.tools.GBC; 13 14 import org.openstreetmap.josm.tools.I18n; 15 14 16 public class LakewalkerPreferences implements PreferenceSetting { 17 public static final String[] DIRECTIONS = new String[] 18 {marktr("east"), marktr("northeast"), marktr("north"), marktr("northwest"), 19 marktr("west"), marktr("southwest"), marktr("south"), marktr("southeast")}; 20 public static final String[] WAYTYPES = new String[] 21 {marktr("water"), marktr("coastline"), marktr("land"), marktr("none")}; 22 public static final String[] WMSLAYERS = new String[] {"IR1", "IR2", "IR3"}; 15 23 16 // TODO: Make these translatable 17 public static final String[] DIRECTIONS = new String[] {"east", "northeast", "north", "northwest", "west", "southwest", "south", "southeast"}; 18 public static final String[] WAYTYPES = new String[] {"water", "coastline", "land", "none"}; 19 public static final String[] WMSLAYERS = new String[] {"IR1", "IR2", "IR3"}; 24 public static final String PREF_MAX_SEG = "lakewalker.max_segs_in_way"; 25 public static final String PREF_MAX_NODES = "lakewalker.max_nodes"; 26 public static final String PREF_THRESHOLD_VALUE = "lakewalker.thresholdvalue"; 27 public static final String PREF_EPSILON = "lakewalker.epsilon"; 28 public static final String PREF_LANDSAT_RES = "lakewalker.landsat_res"; 29 public static final String PREF_LANDSAT_SIZE = "lakewalker.landsat_size"; 30 public static final String PREF_EAST_OFFSET = "lakewalker.east_offset"; 31 public static final String PREF_NORTH_OFFSET = "lakewalker.north_offset"; 32 public static final String PREF_START_DIR = "lakewalker.startdir"; 33 public static final String PREF_WAYTYPE = "lakewalker.waytype"; 34 public static final String PREF_WMS = "lakewalker.wms"; 35 public static final String PREF_SOURCE = "lakewalker.source"; 36 public static final String PREF_MAXCACHESIZE = "lakewalker.maxcachesize"; 37 public static final String PREF_MAXCACHEAGE = "lakewalker.maxcacheage"; 20 38 21 public static final String PREF_MAX_SEG = "lakewalker.max_segs_in_way"; 22 public static final String PREF_MAX_NODES = "lakewalker.max_nodes"; 23 public static final String PREF_THRESHOLD_VALUE = "lakewalker.thresholdvalue"; 24 public static final String PREF_EPSILON = "lakewalker.epsilon"; 25 public static final String PREF_LANDSAT_RES = "lakewalker.landsat_res"; 26 public static final String PREF_LANDSAT_SIZE = "lakewalker.landsat_size"; 27 public static final String PREF_EAST_OFFSET = "lakewalker.east_offset"; 28 public static final String PREF_NORTH_OFFSET = "lakewalker.north_offset"; 29 public static final String PREF_START_DIR = "lakewalker.startdir"; 30 public static final String PREF_WAYTYPE = "lakewalker.waytype"; 31 public static final String PREF_WMS = "lakewalker.wms"; 32 public static final String PREF_MAXCACHESIZE = "lakewalker.maxcachesize"; 33 public static final String PREF_MAXCACHEAGE = "lakewalker.maxcacheage"; 34 35 protected IntConfigurer maxSegsConfig = new IntConfigurer(); 36 protected JLabel maxSegsLabel = new JLabel(tr("Maximum number of segments per way")); 37 protected IntConfigurer maxNodesConfig = new IntConfigurer(); 38 protected JLabel maxNodesLabel = new JLabel(tr("Maximum number of nodes in initial trace")); 39 protected IntConfigurer thresholdConfig = new IntConfigurer(); 40 protected JLabel thresholdLabel = new JLabel(tr("Maximum gray value to count as water (0-255)")); 41 protected DoubleConfigurer epsilonConfig = new DoubleConfigurer(); 42 protected JLabel epsilonLabel = new JLabel(tr("Line simplification accuracy (degrees)")); 43 protected IntConfigurer landsatResConfig = new IntConfigurer(); 44 protected JLabel landsatResLabel = new JLabel(tr("Resolution of Landsat tiles (pixels per degree)")); 45 protected IntConfigurer landsatSizeConfig = new IntConfigurer(); 46 protected JLabel landsatSizeLabel = new JLabel(tr("Size of Landsat tiles (pixels)")); 47 protected DoubleConfigurer eastOffsetConfig = new DoubleConfigurer(); 48 protected JLabel eastOffsetLabel = new JLabel(tr("Shift all traces to east (degrees)")); 49 protected DoubleConfigurer northOffsetConfig = new DoubleConfigurer(); 50 protected JLabel northOffsetLabel = new JLabel(tr("Shift all traces to north (degrees)")); 51 protected StringEnumConfigurer startDirConfig = new StringEnumConfigurer(DIRECTIONS); 52 protected JLabel startDirLabel = new JLabel(tr("Direction to search for land")); 53 protected StringEnumConfigurer lakeTypeConfig = new StringEnumConfigurer(WAYTYPES); 54 protected JLabel lakeTypeLabel = new JLabel(tr("Tag ways as")); 55 protected StringEnumConfigurer wmsConfig = new StringEnumConfigurer(WMSLAYERS); 56 protected JLabel wmsLabel = new JLabel(tr("WMS Layer")); 57 protected IntConfigurer maxCacheSizeConfig = new IntConfigurer(); 58 protected JLabel maxCacheSizeLabel = new JLabel(tr("Maximum cache size (MB)")); 59 protected IntConfigurer maxCacheAgeConfig = new IntConfigurer(); 60 protected JLabel maxCacheAgeLabel = new JLabel(tr("Maximum cache age (days)")); 61 62 public void addGui(PreferenceDialog gui) { 63 maxSegsConfig.setToolTipText(tr("Maximum number of segments allowed in each generated way. Default 250.")); 64 maxNodesConfig.setToolTipText(tr("Maximum number of nodes to generate before bailing out (before simplifying lines). Default 50000.")); 65 thresholdConfig.setToolTipText(tr("Maximum gray value to accept as water (based on Landsat IR-1 data). Can be in the range 0-255. Default 90.")); 66 epsilonConfig.setToolTipText(tr("Accuracy of Douglas-Peucker line simplification, measured in degrees.<br>Lower values give more nodes, and more accurate lines. Default 0.0003.")); 67 landsatResConfig.setToolTipText(tr("Resolution of Landsat tiles, measured in pixels per degree. Default 4000.")); 68 landsatSizeConfig.setToolTipText(tr("Size of one landsat tile, measured in pixels. Default 2000.")); 69 eastOffsetConfig.setToolTipText(tr("Offset all points in East direction (degrees). Default 0.")); 70 northOffsetConfig.setToolTipText(tr("Offset all points in North direction (degrees). Default 0.")); 71 startDirConfig.setToolTipText(tr("Direction to search for land. Default east.")); 72 lakeTypeConfig.setToolTipText(tr("Tag ways as water, coastline, land or nothing. Default is water.")); 73 wmsConfig.setToolTipText(tr("Which WMS layer to use for tracing against. Default is IR1.")); 74 maxCacheSizeConfig.setToolTipText(tr("Maximum size of each cache directory in bytes. Default is 300MB")); 75 maxCacheAgeConfig.setToolTipText(tr("Maximum age of each cached file in days. Default is 100")); 76 77 String description = tr("An plugin to trace water bodies on Landsat imagery."); 78 JPanel prefPanel = gui.createPreferenceTab("lakewalker.png", I18n.tr("Lakewalker Plugin Preferences"), description); 79 buildPreferences(prefPanel); 80 81 maxSegsConfig.setValue(Main.pref.getInteger(PREF_MAX_SEG, 500)); 82 maxNodesConfig.setValue(Main.pref.getInteger(PREF_MAX_NODES, 50000)); 83 thresholdConfig.setValue(Main.pref.getInteger(PREF_THRESHOLD_VALUE, 90)); 84 epsilonConfig.setValue(Main.pref.getDouble(PREF_EPSILON, 0.0003)); 85 landsatResConfig.setValue(Main.pref.getInteger(PREF_LANDSAT_RES, 4000)); 86 landsatSizeConfig.setValue(Main.pref.getInteger(PREF_LANDSAT_SIZE, 2000)); 87 eastOffsetConfig.setValue(Main.pref.getDouble(PREF_EAST_OFFSET, 0.0)); 88 northOffsetConfig.setValue(Main.pref.getDouble(PREF_NORTH_OFFSET, 0.0)); 89 startDirConfig.setValue(Main.pref.get(PREF_START_DIR, "east")); 90 lakeTypeConfig.setValue(Main.pref.get(PREF_WAYTYPE, "water")); 91 wmsConfig.setValue(Main.pref.get(PREF_WMS, "IR1")); 92 maxCacheSizeConfig.setValue(Main.pref.getInteger(PREF_MAXCACHESIZE, 300)); 93 maxCacheAgeConfig.setValue(Main.pref.getInteger(PREF_MAXCACHEAGE, 100)); 94 } 95 96 public void buildPreferences(JPanel prefPanel) { 97 GBC labelConstraints = GBC.std().insets(10,5,5,0); 98 GBC dataConstraints = GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL); 99 100 prefPanel.add(maxSegsLabel, labelConstraints); 101 prefPanel.add(maxSegsConfig.getControls(), dataConstraints); 102 prefPanel.add(maxNodesLabel, labelConstraints); 103 prefPanel.add(maxNodesConfig.getControls(), dataConstraints); 104 prefPanel.add(thresholdLabel, labelConstraints); 105 prefPanel.add(thresholdConfig.getControls(), dataConstraints); 106 prefPanel.add(epsilonLabel, labelConstraints); 107 prefPanel.add(epsilonConfig.getControls(), dataConstraints); 108 prefPanel.add(landsatResLabel, labelConstraints); 109 prefPanel.add(landsatResConfig.getControls(), dataConstraints); 110 prefPanel.add(landsatSizeLabel, labelConstraints); 111 prefPanel.add(landsatSizeConfig.getControls(), dataConstraints); 112 prefPanel.add(eastOffsetLabel, labelConstraints); 113 prefPanel.add(eastOffsetConfig.getControls(), dataConstraints); 114 prefPanel.add(northOffsetLabel, labelConstraints); 115 prefPanel.add(northOffsetConfig.getControls(), dataConstraints); 116 prefPanel.add(startDirLabel, labelConstraints); 117 prefPanel.add(startDirConfig.getControls(), dataConstraints); 118 prefPanel.add(lakeTypeLabel, labelConstraints); 119 prefPanel.add(lakeTypeConfig.getControls(), dataConstraints); 120 prefPanel.add(wmsLabel, labelConstraints); 121 prefPanel.add(wmsConfig.getControls(), dataConstraints); 122 prefPanel.add(maxCacheSizeLabel, labelConstraints); 123 prefPanel.add(maxCacheSizeConfig.getControls(), dataConstraints); 124 prefPanel.add(maxCacheAgeLabel, labelConstraints); 125 prefPanel.add(maxCacheAgeConfig.getControls(), dataConstraints); 39 protected IntConfigurer maxSegsConfig = new IntConfigurer(); 40 protected JLabel maxSegsLabel = new JLabel(tr("Maximum number of segments per way")); 41 protected IntConfigurer maxNodesConfig = new IntConfigurer(); 42 protected JLabel maxNodesLabel = new JLabel(tr("Maximum number of nodes in initial trace")); 43 protected IntConfigurer thresholdConfig = new IntConfigurer(); 44 protected JLabel thresholdLabel = new JLabel(tr("Maximum gray value to count as water (0-255)")); 45 protected DoubleConfigurer epsilonConfig = new DoubleConfigurer(); 46 protected JLabel epsilonLabel = new JLabel(tr("Line simplification accuracy (degrees)")); 47 protected IntConfigurer landsatResConfig = new IntConfigurer(); 48 protected JLabel landsatResLabel = new JLabel(tr("Resolution of Landsat tiles (pixels per degree)")); 49 protected IntConfigurer landsatSizeConfig = new IntConfigurer(); 50 protected JLabel landsatSizeLabel = new JLabel(tr("Size of Landsat tiles (pixels)")); 51 protected DoubleConfigurer eastOffsetConfig = new DoubleConfigurer(); 52 protected JLabel eastOffsetLabel = new JLabel(tr("Shift all traces to east (degrees)")); 53 protected DoubleConfigurer northOffsetConfig = new DoubleConfigurer(); 54 protected JLabel northOffsetLabel = new JLabel(tr("Shift all traces to north (degrees)")); 55 protected StringEnumConfigurer startDirConfig = new StringEnumConfigurer(DIRECTIONS); 56 protected JLabel startDirLabel = new JLabel(tr("Direction to search for land")); 57 protected StringEnumConfigurer lakeTypeConfig = new StringEnumConfigurer(WAYTYPES); 58 protected JLabel lakeTypeLabel = new JLabel(tr("Tag ways as")); 59 protected StringEnumConfigurer wmsConfig = new StringEnumConfigurer(WMSLAYERS); 60 protected JLabel wmsLabel = new JLabel(tr("WMS Layer")); 61 protected IntConfigurer maxCacheSizeConfig = new IntConfigurer(); 62 protected JLabel maxCacheSizeLabel = new JLabel(tr("Maximum cache size (MB)")); 63 protected IntConfigurer maxCacheAgeConfig = new IntConfigurer(); 64 protected JLabel maxCacheAgeLabel = new JLabel(tr("Maximum cache age (days)")); 65 protected StringConfigurer sourceConfig = new StringConfigurer(); 66 protected JLabel sourceLabel = new JLabel(tr("Source text")); 126 67 127 prefPanel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 68 public void addGui(PreferenceDialog gui) { 69 maxSegsConfig.setToolTipText(tr("Maximum number of segments allowed in each generated way. Default 250.")); 70 maxNodesConfig.setToolTipText(tr("Maximum number of nodes to generate before bailing out (before simplifying lines). Default 50000.")); 71 thresholdConfig.setToolTipText(tr("Maximum gray value to accept as water (based on Landsat IR-1 data). Can be in the range 0-255. Default 90.")); 72 epsilonConfig.setToolTipText(tr("Accuracy of Douglas-Peucker line simplification, measured in degrees.<br>Lower values give more nodes, and more accurate lines. Default 0.0003.")); 73 landsatResConfig.setToolTipText(tr("Resolution of Landsat tiles, measured in pixels per degree. Default 4000.")); 74 landsatSizeConfig.setToolTipText(tr("Size of one landsat tile, measured in pixels. Default 2000.")); 75 eastOffsetConfig.setToolTipText(tr("Offset all points in East direction (degrees). Default 0.")); 76 northOffsetConfig.setToolTipText(tr("Offset all points in North direction (degrees). Default 0.")); 77 startDirConfig.setToolTipText(tr("Direction to search for land. Default east.")); 78 lakeTypeConfig.setToolTipText(tr("Tag ways as water, coastline, land or nothing. Default is water.")); 79 wmsConfig.setToolTipText(tr("Which WMS layer to use for tracing against. Default is IR1.")); 80 maxCacheSizeConfig.setToolTipText(tr("Maximum size of each cache directory in bytes. Default is 300MB")); 81 maxCacheAgeConfig.setToolTipText(tr("Maximum age of each cached file in days. Default is 100")); 82 sourceConfig.setToolTipText(tr("Data source text. Default is Landsat.")); 128 83 129 } 84 String description = tr("An plugin to trace water bodies on Landsat imagery."); 85 JPanel prefPanel = gui.createPreferenceTab("lakewalker.png", I18n.tr("Lakewalker Plugin Preferences"), description); 86 buildPreferences(prefPanel); 130 87 131 /* 132 * Save entered preference values on OK button 133 */ 134 public boolean ok() { 135 Main.pref.put(PREF_MAX_SEG, maxSegsConfig.getValueString()); 136 Main.pref.put(PREF_MAX_NODES, maxNodesConfig.getValueString()); 137 Main.pref.put(PREF_THRESHOLD_VALUE, thresholdConfig.getValueString()); 138 Main.pref.put(PREF_EPSILON, epsilonConfig.getValueString()); 139 Main.pref.put(PREF_LANDSAT_RES, landsatResConfig.getValueString()); 140 Main.pref.put(PREF_LANDSAT_SIZE, landsatSizeConfig.getValueString()); 141 Main.pref.put(PREF_EAST_OFFSET, eastOffsetConfig.getValueString()); 142 Main.pref.put(PREF_NORTH_OFFSET, northOffsetConfig.getValueString()); 143 Main.pref.put(PREF_START_DIR, startDirConfig.getValueString()); 144 Main.pref.put(PREF_WAYTYPE, lakeTypeConfig.getValueString()); 145 Main.pref.put(PREF_WMS, wmsConfig.getValueString()); 146 Main.pref.put(PREF_MAXCACHESIZE, maxCacheSizeConfig.getValueString()); 147 Main.pref.put(PREF_MAXCACHEAGE, maxCacheAgeConfig.getValueString()); 148 return false; 149 } 88 maxSegsConfig.setValue(Main.pref.getInteger(PREF_MAX_SEG, 500)); 89 maxNodesConfig.setValue(Main.pref.getInteger(PREF_MAX_NODES, 50000)); 90 thresholdConfig.setValue(Main.pref.getInteger(PREF_THRESHOLD_VALUE, 90)); 91 epsilonConfig.setValue(Main.pref.getDouble(PREF_EPSILON, 0.0003)); 92 landsatResConfig.setValue(Main.pref.getInteger(PREF_LANDSAT_RES, 4000)); 93 landsatSizeConfig.setValue(Main.pref.getInteger(PREF_LANDSAT_SIZE, 2000)); 94 eastOffsetConfig.setValue(Main.pref.getDouble(PREF_EAST_OFFSET, 0.0)); 95 northOffsetConfig.setValue(Main.pref.getDouble(PREF_NORTH_OFFSET, 0.0)); 96 startDirConfig.setValue(Main.pref.get(PREF_START_DIR, "east")); 97 lakeTypeConfig.setValue(Main.pref.get(PREF_WAYTYPE, "water")); 98 wmsConfig.setValue(Main.pref.get(PREF_WMS, "IR1")); 99 sourceConfig.setValue(Main.pref.get(PREF_SOURCE, "Landsat")); 100 maxCacheSizeConfig.setValue(Main.pref.getInteger(PREF_MAXCACHESIZE, 300)); 101 maxCacheAgeConfig.setValue(Main.pref.getInteger(PREF_MAXCACHEAGE, 100)); 102 } 103 104 public void buildPreferences(JPanel prefPanel) { 105 GBC labelConstraints = GBC.std().insets(10,5,5,0); 106 GBC dataConstraints = GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL); 107 108 prefPanel.add(maxSegsLabel, labelConstraints); 109 prefPanel.add(maxSegsConfig.getControls(), dataConstraints); 110 prefPanel.add(maxNodesLabel, labelConstraints); 111 prefPanel.add(maxNodesConfig.getControls(), dataConstraints); 112 prefPanel.add(thresholdLabel, labelConstraints); 113 prefPanel.add(thresholdConfig.getControls(), dataConstraints); 114 prefPanel.add(epsilonLabel, labelConstraints); 115 prefPanel.add(epsilonConfig.getControls(), dataConstraints); 116 prefPanel.add(landsatResLabel, labelConstraints); 117 prefPanel.add(landsatResConfig.getControls(), dataConstraints); 118 prefPanel.add(landsatSizeLabel, labelConstraints); 119 prefPanel.add(landsatSizeConfig.getControls(), dataConstraints); 120 prefPanel.add(eastOffsetLabel, labelConstraints); 121 prefPanel.add(eastOffsetConfig.getControls(), dataConstraints); 122 prefPanel.add(northOffsetLabel, labelConstraints); 123 prefPanel.add(northOffsetConfig.getControls(), dataConstraints); 124 prefPanel.add(startDirLabel, labelConstraints); 125 prefPanel.add(startDirConfig.getControls(), dataConstraints); 126 prefPanel.add(lakeTypeLabel, labelConstraints); 127 prefPanel.add(lakeTypeConfig.getControls(), dataConstraints); 128 prefPanel.add(wmsLabel, labelConstraints); 129 prefPanel.add(wmsConfig.getControls(), dataConstraints); 130 prefPanel.add(maxCacheSizeLabel, labelConstraints); 131 prefPanel.add(maxCacheSizeConfig.getControls(), dataConstraints); 132 prefPanel.add(maxCacheAgeLabel, labelConstraints); 133 prefPanel.add(maxCacheAgeConfig.getControls(), dataConstraints); 134 prefPanel.add(sourceLabel, labelConstraints); 135 prefPanel.add(sourceConfig.getControls(), dataConstraints); 136 137 prefPanel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 138 } 139 140 /* 141 * Save entered preference values on OK button 142 */ 143 public boolean ok() { 144 Main.pref.put(PREF_MAX_SEG, maxSegsConfig.getValueString()); 145 Main.pref.put(PREF_MAX_NODES, maxNodesConfig.getValueString()); 146 Main.pref.put(PREF_THRESHOLD_VALUE, thresholdConfig.getValueString()); 147 Main.pref.put(PREF_EPSILON, epsilonConfig.getValueString()); 148 Main.pref.put(PREF_LANDSAT_RES, landsatResConfig.getValueString()); 149 Main.pref.put(PREF_LANDSAT_SIZE, landsatSizeConfig.getValueString()); 150 Main.pref.put(PREF_EAST_OFFSET, eastOffsetConfig.getValueString()); 151 Main.pref.put(PREF_NORTH_OFFSET, northOffsetConfig.getValueString()); 152 Main.pref.put(PREF_START_DIR, startDirConfig.getValueString()); 153 Main.pref.put(PREF_WAYTYPE, lakeTypeConfig.getValueString()); 154 Main.pref.put(PREF_WMS, wmsConfig.getValueString()); 155 Main.pref.put(PREF_MAXCACHESIZE, maxCacheSizeConfig.getValueString()); 156 Main.pref.put(PREF_MAXCACHEAGE, maxCacheAgeConfig.getValueString()); 157 Main.pref.put(PREF_SOURCE, sourceConfig.getValueString()); 158 return false; 159 } 150 160 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerReader.java
r12778 r12892 1 1 /* LakewalkerReader.java 2 * 2 * 3 3 * Read and process data from a Lakwalker python module 4 * 4 * 5 5 */ 6 6 package org.openstreetmap.josm.plugins.lakewalker; … … 22 22 23 23 public class LakewalkerReader { 24 25 protected Collection<Command> commands = new LinkedList<Command>(); 26 protected Collection<Way> ways = new ArrayList<Way>(); 27 protected boolean cancel; 28 29 /* 30 * Read the data 31 */ 32 public void read(BufferedReader input) { 24 protected Collection<Command> commands = new LinkedList<Command>(); 25 protected Collection<Way> ways = new ArrayList<Way>(); 26 protected boolean cancel; 27 33 28 /* 34 * Lakewalker will output data it stdout. Each line has a code in 35 * character 1 indicating the type of data on the line: 36 * 37 * m text - Status message l name [size] - Access landsat image name. size 38 * is returned if it needs to be downloaded. e text - Error message s nnn - 39 * Start node data stream, nnn seperate tracings to follow t nnn - Start 40 * tracing, nnn nodes to follow x [o] - End of Tracing. o indicates do not 41 * connect last node to first n lat lon [o] - Node. o indicates it is an 42 * open node (not connected to the previous node) z - End of data stream 43 */ 29 * Read the data 30 */ 31 public void read(BufferedReader input) { 32 /* 33 * Lakewalker will output data it stdout. Each line has a code in 34 * character 1 indicating the type of data on the line: 35 * 36 * m text - Status message l name [size] - Access landsat image name. size 37 * is returned if it needs to be downloaded. e text - Error message s nnn - 38 * Start node data stream, nnn seperate tracings to follow t nnn - Start 39 * tracing, nnn nodes to follow x [o] - End of Tracing. o indicates do not 40 * connect last node to first n lat lon [o] - Node. o indicates it is an 41 * open node (not connected to the previous node) z - End of data stream 42 */ 44 43 45 Way way = new Way(); 46 String line; 47 setStatus("Initializing"); 48 double eastOffset = Main.pref.getDouble(LakewalkerPreferences.PREF_EAST_OFFSET, 0.0); 49 double northOffset = Main.pref.getDouble(LakewalkerPreferences.PREF_NORTH_OFFSET, 0.0); 50 char option = ' '; 51 52 try { 53 54 Node n = null; // The current node being created 55 Node tn = null; // The last node of the previous way 56 Node fn = null; // Node to hold the first node in the trace 57 58 while ((line = input.readLine()) != null) { 59 if (cancel) { 60 return; 44 Way way = new Way(); 45 String line; 46 setStatus("Initializing"); 47 double eastOffset = Main.pref.getDouble(LakewalkerPreferences.PREF_EAST_OFFSET, 0.0); 48 double northOffset = Main.pref.getDouble(LakewalkerPreferences.PREF_NORTH_OFFSET, 0.0); 49 char option = ' '; 50 51 try { 52 Node n = null; // The current node being created 53 Node tn = null; // The last node of the previous way 54 Node fn = null; // Node to hold the first node in the trace 55 56 while ((line = input.readLine()) != null) { 57 if (cancel) 58 return; 59 System.out.println(line); 60 option = line.charAt(0); 61 switch (option) { 62 case 'n': 63 String[] tokens = line.split(" "); 64 65 if(tn==null){ 66 try { 67 LatLon ll = new LatLon(Double.parseDouble(tokens[1])+northOffset, 68 Double.parseDouble(tokens[2])+eastOffset); 69 n = new Node(ll); 70 if(fn==null) 71 fn = n; 72 commands.add(new AddCommand(n)); 73 } 74 catch (Exception ex) {} 75 } else { 76 // If there is a last node, and this node has the same coordinates 77 // then we substitute for the previous node 78 n = tn; 79 tn = null; 80 } 81 way.nodes.add(n); 82 break; 83 case 's': 84 setStatus(line.substring(2)); 85 break; 86 case 'x': 87 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 88 89 if(!waytype.equals("none")) 90 way.put("natural",waytype); 91 way.put("source", Main.pref.get(LakewalkerPreferences.PREF_SOURCE, "water")); 92 commands.add(new AddCommand(way)); 93 break; 94 case 't': 95 way = new Way(); 96 tn = n; 97 break; 98 case 'e': 99 String error = line.substring(2); 100 cancel = true; 101 break; 102 } 103 } 104 input.close(); 105 106 // Add the start node to the end of the trace to form a closed shape 107 way.nodes.add(fn); 61 108 } 62 System.out.println(line); 63 option = line.charAt(0); 64 switch (option) { 65 case 'n': 66 String[] tokens = line.split(" "); 67 68 if(tn==null){ 69 try { 70 LatLon ll = new LatLon(Double.parseDouble(tokens[1])+northOffset, Double.parseDouble(tokens[2])+eastOffset); 71 n = new Node(ll); 72 if(fn==null){ 73 fn = n; 74 } 75 commands.add(new AddCommand(n)); 76 } 77 catch (Exception ex) { 78 79 } 80 81 } else { 82 // If there is a last node, and this node has the same coordinates 83 // then we substitute for the previous node 84 n = tn; 85 tn = null; 86 } 87 88 way.nodes.add(n); 89 90 break; 109 catch (Exception ex) { } 91 110 92 case 's': 93 setStatus(line.substring(2)); 94 break; 95 96 case 'x': 97 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 98 99 if(!waytype.equals("none")){ 100 way.put("natural",waytype); 101 } 102 103 way.put("created_by", "Dshpak_landsat_lakes"); 104 commands.add(new AddCommand(way)); 105 106 break; 107 108 case 't': 109 way = new Way(); 110 tn = n; 111 break; 112 113 case 'e': 114 String error = line.substring(2); 115 cancel = true; 116 break; 111 if (!commands.isEmpty()) { 112 Main.main.undoRedo.add(new SequenceCommand(tr("Lakewalker trace"), commands)); 113 Main.ds.setSelected(ways); 117 114 } 118 }119 input.close();120 121 // Add the start node to the end of the trace to form a closed shape122 way.nodes.add(fn);123 115 } 124 116 125 catch (Exception ex) { 117 /* 118 * User has hit the cancel button 119 */ 120 public void cancel() { 121 cancel = true; 126 122 } 127 128 if (!commands.isEmpty()) { 129 Main.main.undoRedo.add(new SequenceCommand(tr("Lakewalker trace"), commands)); 130 Main.ds.setSelected(ways); 123 protected void setStatus(String s) { 124 Main.pleaseWaitDlg.currentAction.setText(s); 125 Main.pleaseWaitDlg.repaint(); 131 126 } 132 }133 134 /*135 * User has hit the cancel button136 */137 public void cancel() {138 cancel = true;139 }140 141 protected void setStatus(String s) {142 Main.pleaseWaitDlg.currentAction.setText(s);143 Main.pleaseWaitDlg.repaint();144 }145 146 127 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringEnumConfigurer.java
r12778 r12892 27 27 package org.openstreetmap.josm.plugins.lakewalker; 28 28 29 import static org.openstreetmap.josm.tools.I18n.tr; 30 29 31 import java.awt.Component; 30 32 import java.awt.Dimension; … … 40 42 */ 41 43 public class StringEnumConfigurer extends Configurer { 42 protected String[] validValues; 43 protected JComboBox box; 44 protected Box panel; 45 protected String tooltipText = ""; 46 47 public StringEnumConfigurer(String key, String name, String[] validValues) { 48 super(key, name); 49 this.validValues = validValues; 50 } 44 protected String[] validValues; 45 protected String[] transValues; 46 protected JComboBox box; 47 protected Box panel; 48 protected String tooltipText = ""; 51 49 52 public StringEnumConfigurer(String[] validValues) { 53 this(null, "", validValues); 54 } 55 56 public void setToolTipText(String s) { 57 tooltipText = s; 58 } 59 public Component getControls() { 60 if (panel == null) { 61 panel = Box.createHorizontalBox(); 62 panel.add(new JLabel(name)); 63 box = new JComboBox(validValues); 64 box.setToolTipText(tooltipText); 65 box.setMaximumSize(new Dimension(box.getMaximumSize().width,box.getPreferredSize().height)); 66 if (isValidValue(getValue())) { 67 box.setSelectedItem(getValue()); 68 } 69 else if (validValues.length > 0) { 70 box.setSelectedIndex(0); 71 } 72 box.addActionListener(new ActionListener() { 73 public void actionPerformed(ActionEvent e) { 74 noUpdate = true; 75 setValue(box.getSelectedItem()); 76 noUpdate = false; 50 public StringEnumConfigurer(String key, String name, String[] validValues) { 51 super(key, name); 52 this.validValues = validValues; 53 transValues = new String[validValues.length]; 54 for(int i = 0; i < validValues.length; ++i) 55 transValues[i] = tr(validValues[i]); 56 } 57 58 public StringEnumConfigurer(String[] validValues) { 59 this(null, "", validValues); 60 } 61 62 public void setToolTipText(String s) { 63 tooltipText = s; 64 } 65 public Component getControls() { 66 if (panel == null) { 67 panel = Box.createHorizontalBox(); 68 panel.add(new JLabel(name)); 69 box = new JComboBox(transValues); 70 box.setToolTipText(tooltipText); 71 box.setMaximumSize(new Dimension(box.getMaximumSize().width,box.getPreferredSize().height)); 72 setValue(value); 73 box.addActionListener(new ActionListener() { 74 public void actionPerformed(ActionEvent e) { 75 noUpdate = true; 76 setValue(box.getSelectedIndex()); 77 noUpdate = false; 78 } 79 }); 80 panel.add(box); 77 81 } 78 }); 79 panel.add(box); 82 return panel; 80 83 } 81 return panel; 82 } 84 public void setValue(Object o) { 85 if(o == null) 86 o = new Integer(0); 87 super.setValue(o); 88 if(!noUpdate && box != null) 89 box.setSelectedIndex((Integer)o); 90 } 83 91 84 public boolean isValidValue(Object o) { 85 for (int i = 0; i < validValues.length; ++i) { 86 if (validValues[i].equals(o)) { 87 return true; 88 } 92 public void setValue(String s) { 93 Integer n = 0; 94 for (int i = 0; i < transValues.length; ++i) 95 { 96 if (transValues[i].equals(s) || validValues[i].equals(s)){ 97 n = i; 98 break; 99 } 100 } 101 setValue(n); 89 102 } 90 return false;91 }92 103 93 public String[] getValidValues() { 94 return validValues; 95 } 96 97 public void setValidValues(String[] s) { 98 validValues = s; 99 if (box == null) { 100 getControls(); 104 public String getValueString() { 105 return validValues[(Integer)value]; 101 106 } 102 box.setModel(new DefaultComboBoxModel(validValues));103 }104 105 public void setValue(Object o) {106 if (validValues == null107 || isValidValue(o)) {108 super.setValue(o);109 if (!noUpdate && box != null) {110 box.setSelectedItem(o);111 }112 }113 }114 115 public String getValueString() {116 return box != null ? (String) box.getSelectedItem() : validValues[0];117 }118 119 public void setValue(String s) {120 setValue((Object) s);121 }122 123 107 }
Note:
See TracChangeset
for help on using the changeset viewer.