Changeset 32788 in osm for applications
- Timestamp:
- 2016-08-09T01:40:50+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/tracer2
- Files:
-
- 2 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tracer2/.project
r32286 r32788 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/ConnectWays.java
r32474 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 35 18 import org.openstreetmap.josm.command.SequenceCommand; 36 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.data.osm.BBox; 37 21 import org.openstreetmap.josm.data.osm.Node; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 23 import org.openstreetmap.josm.data.osm.Way; 39 import org.openstreetmap.josm.data.osm.BBox;40 import org.openstreetmap.josm.data.osm.OsmPrimitive;41 24 import org.openstreetmap.josm.plugins.tracer2.preferences.ServerParam; 42 25 import org.openstreetmap.josm.tools.Pair; 43 26 44 public class ConnectWays { 45 static double s_dMinDistance = 0.000006; // Minimal distance, for objects 46 static double s_dMinDistanceN2N = 0.0000005; // Minimal distance, when nodes are merged 47 static double s_dMinDistanceN2oW = 0.000001; // Minimal distance, when node is connected to other way 48 static double s_dMinDistanceN2tW = 0.000001; // Minimal distance, when other node is connected this way 49 final static double MAX_ANGLE = 30; // Minimal angle, when other node is connected this way 50 27 public final class ConnectWays { 28 29 private ConnectWays() { 30 // Hide default constructor for utilities classes 31 } 32 33 // CHECKSTYLE.OFF: SingleSpaceSeparator 34 static double s_dMinDistance = 0.000006; // Minimal distance, for objects 35 static double s_dMinDistanceN2N = 0.0000005; // Minimal distance, when nodes are merged 36 static double s_dMinDistanceN2oW = 0.000001; // Minimal distance, when node is connected to other way 37 static double s_dMinDistanceN2tW = 0.000001; // Minimal distance, when other node is connected this way 38 static final double MAX_ANGLE = 30; // Minimal angle, when other node is connected this way 39 // CHECKSTYLE.ON: SingleSpaceSeparator 40 51 41 static Way s_oWay; 52 42 static Way s_oWayOld; 53 43 static List<Way> s_oWays; 54 44 static List<Node> s_oNodes; 55 45 56 46 static ServerParam s_oParam; 57 47 static boolean s_bCtrl; 58 48 static boolean s_bAlt; 59 49 60 50 static boolean s_bAddNewWay; 61 62 private static void calcDistance() 63 { 64 double dTileSize = Double.parseDouble(s_oParam.getTileSize()); 65 double dResolution = Double.parseDouble(s_oParam.getResolution()); 66 double dMin = dTileSize / dResolution; 67 68 s_dMinDistance = dMin * 30; 69 s_dMinDistanceN2N = dMin * 2.5; 70 s_dMinDistanceN2oW = dMin * 5; 71 s_dMinDistanceN2tW = dMin * 5; 72 } 73 51 52 private static void calcDistance() { 53 double dTileSize = Double.parseDouble(s_oParam.getTileSize()); 54 double dResolution = Double.parseDouble(s_oParam.getResolution()); 55 double dMin = dTileSize / dResolution; 56 57 s_dMinDistance = dMin * 30; 58 s_dMinDistanceN2N = dMin * 2.5; 59 s_dMinDistanceN2oW = dMin * 5; 60 s_dMinDistanceN2tW = dMin * 5; 61 } 62 74 63 private static void getWays(Way way) { 75 76 bbox.addPrimitive(way,s_dMinDistance);64 BBox bbox = new BBox(way); 65 bbox.addPrimitive(way, s_dMinDistance); 77 66 s_oWays = Main.getLayerManager().getEditDataSet().searchWays(bbox); 78 67 } 79 68 80 69 private static List<Way> getWaysOfNode(Node node) { 81 82 83 84 } 85 70 List<Way> ways; 71 ways = OsmPrimitive.getFilteredList(node.getReferrers(), Way.class); 72 return ways; 73 } 74 86 75 private static void getNodes(Way way) { 87 88 bbox.addPrimitive(way,s_dMinDistance);89 90 } 91 76 BBox bbox = new BBox(way); 77 bbox.addPrimitive(way, s_dMinDistance); 78 s_oNodes = Main.getLayerManager().getEditDataSet().searchNodes(bbox); 79 } 80 92 81 private static double calcAlpha(LatLon oP1, Node n) { 93 94 95 96 97 } 98 82 LatLon oP2 = n.getCoor(); 83 84 double dAlpha = Math.atan((oP2.getY() - oP1.getY()) / (oP2.getX() - oP1.getX())) * 180 / Math.PI + (oP1.getX() > oP2.getX() ? 180 : 0); 85 return checkAlpha(dAlpha); 86 } 87 99 88 private static Double checkAlpha(Double dAlpha) { 100 89 if (dAlpha > 180) { … … 106 95 return dAlpha; 107 96 } 108 97 109 98 private static boolean isNodeInsideWay(LatLon pos, Way way) { 110 111 112 113 114 115 116 117 118 dSumAlpha += checkAlpha( dAlpha - dAlphaOld);119 120 121 122 123 124 } 125 99 List<Node> listNode = way.getNodes(); 100 101 double dAlpha; 102 double dAlphaOld = calcAlpha(pos, listNode.get(listNode.size()-1)); 103 double dSumAlpha = 0; 104 105 for (Node n : listNode) { 106 dAlpha = calcAlpha(pos, n); 107 dSumAlpha += checkAlpha(dAlpha - dAlphaOld); 108 dAlphaOld = dAlpha; 109 } 110 dSumAlpha = Math.abs(dSumAlpha); 111 112 return dSumAlpha > 359 && dSumAlpha < 361; 113 } 114 126 115 private static Way getOldWay(LatLon pos) { 127 128 129 130 131 132 133 134 135 136 137 138 139 140 } 141 116 int i; 117 118 for (i = 0; i < s_oWays.size(); i++) { 119 Way way = s_oWays.get(i); 120 if (!isSameTag(way)) { 121 continue; 122 } 123 if (isNodeInsideWay(pos, way)) { 124 s_oWays.remove(way); 125 return way; 126 } 127 } 128 return null; 129 } 130 142 131 /** 143 132 * Try connect way to other buildings. … … 148 137 LinkedList<Command> cmds = new LinkedList<>(); 149 138 LinkedList<Command> cmds2 = new LinkedList<>(); 150 139 151 140 s_oParam = param; 152 141 s_bCtrl = ctrl; 153 142 s_bAlt = alt; 154 143 155 144 boolean bAddWay = false; 156 145 157 146 calcDistance(); 158 147 getNodes(newWay); 159 148 getWays(newWay); 160 149 161 150 s_oWayOld = getOldWay(pos); 162 151 163 152 if (s_oWayOld == null) { 164 165 166 167 168 s_oWay = new Way( newWay);153 s_bAddNewWay = true; 154 //cmds.add(new AddCommand(newWay)); 155 bAddWay = true; 156 s_oWayOld = newWay; 157 s_oWay = new Way(newWay); 169 158 } else { 170 159 int i; 171 160 Way tempWay; 172 161 s_bAddNewWay = false; 173 162 174 163 //Main.main.getCurrentDataSet().setSelected(m_wayOld); 175 164 176 165 tempWay = new Way(s_oWayOld); 177 166 178 167 for (i = 0; i < newWay.getNodesCount(); i++) { 179 168 tempWay.addNode(tempWay.getNodesCount(), newWay.getNode(i)); 180 169 } 181 170 i++; 182 171 for (i = 0; i < s_oWayOld.getNodesCount() - 1; i++) { 183 tempWay.removeNode( s_oWayOld.getNode(i));172 tempWay.removeNode(s_oWayOld.getNode(i)); 184 173 } 185 174 //cmds.add(new ChangeCommand(m_wayOld, tempWay)); 186 175 for (i = 0; i < s_oWayOld.getNodesCount() - 1; i++) { 187 188 189 if (ways.size()<=1) {190 cmds2.add(new DeleteCommand( s_oWayOld.getNode(i)));191 192 176 Node n = s_oWayOld.getNode(i); 177 List<Way> ways = getWaysOfNode(n); 178 if (ways.size() <= 1) { 179 cmds2.add(new DeleteCommand(s_oWayOld.getNode(i))); 180 } 181 s_oNodes.remove(s_oWayOld.getNode(i)); 193 182 } 194 183 s_oWay = tempWay; 195 184 } 196 197 { 198 cmds2.addAll(connectTo()); 199 200 // add new Node 201 Node firstNode = null; 202 Way way = new Way(s_oWay); 203 for (Node node : s_oWay.getNodes()) { 204 if ( node.getDataSet() != null ) 205 { 206 way.removeNode(node); 207 } 208 } 209 if ( way.getNodes().size() > 0 ) 210 { 211 if (way.firstNode() != way.lastNode() ) 212 { 213 way.addNode(way.firstNode()); 214 } 215 for (Node node : way.getNodes()) 216 { 217 if (firstNode == null || firstNode != node) { 218 cmds.add(new AddCommand(node)); 219 } 220 if (firstNode == null) { 221 firstNode = node; 222 } 223 } 224 } 225 226 // add new way 227 if ( bAddWay == true ) 228 { 229 cmds.add(new AddCommand(s_oWay)); 230 } 231 232 cmds.add(new ChangeCommand(s_oWayOld, trySplitWayByAnyNodes(s_oWay))); 233 } 185 186 cmds2.addAll(connectTo()); 187 188 // add new Node 189 Node firstNode = null; 190 Way way = new Way(s_oWay); 191 for (Node node : s_oWay.getNodes()) { 192 if (node.getDataSet() != null) { 193 way.removeNode(node); 194 } 195 } 196 if (way.getNodes().size() > 0) { 197 if (way.firstNode() != way.lastNode()) { 198 way.addNode(way.firstNode()); 199 } 200 for (Node node : way.getNodes()) { 201 if (firstNode == null || firstNode != node) { 202 cmds.add(new AddCommand(node)); 203 } 204 if (firstNode == null) { 205 firstNode = node; 206 } 207 } 208 } 209 210 // add new way 211 if (bAddWay == true) { 212 cmds.add(new AddCommand(s_oWay)); 213 } 214 215 cmds.add(new ChangeCommand(s_oWayOld, trySplitWayByAnyNodes(s_oWay))); 234 216 cmds.addAll(cmds2); 235 217 236 218 TracerDebug oTracerDebug = new TracerDebug(); 237 219 oTracerDebug.OutputCommands(cmds); 238 220 239 221 Command cmd = new SequenceCommand(tr("Merge objects nodes"), cmds); 240 222 241 223 return cmd; 242 224 } 243 244 225 226 245 227 /** 246 228 * Try connect way to other buildings. … … 268 250 Node nearestNode = null; 269 251 for (Node nn : s_oNodes) { 270 252 System.out.println("Node: " + nn); 271 253 if (!nn.isUsable() || way.containsNode(nn) || s_oWay.containsNode(nn) || !isInSameTag(nn)) { 272 254 continue; … … 278 260 } 279 261 } 280 262 281 263 System.out.println("Nearest: " + nearestNode + " distance: " + minDistanceSq); 282 264 if (nearestNode == null) { … … 287 269 } 288 270 } 289 271 290 272 for (Map.Entry<Way, Way> e : modifiedWays.entrySet()) { 291 273 cmds.add(new ChangeCommand(e.getKey(), e.getValue())); 292 274 } 293 275 294 276 //cmds.addFirst(new ChangeCommand(way, trySplitWayByAnyNodes(newWay))); 295 277 296 278 List<Command> cmd = cmds; 297 279 return cmd; … … 305 287 * @return List of Commands. 306 288 */ 307 private static List<Command> mergeNodes(Node n1, Node n2) {289 private static List<Command> mergeNodes(Node n1, Node n2) { 308 290 List<Command> cmds = new LinkedList<>(); 309 291 cmds.add(new MoveCommand(n2, 310 311 312 313 292 (n1.getEastNorth().getX() - n2.getEastNorth().getX())/2, 293 (n1.getEastNorth().getY() - n2.getEastNorth().getY())/2 294 )); 295 314 296 Way newWay = new Way(s_oWay); 315 297 316 298 int j = s_oWay.getNodes().indexOf(n1); 317 299 newWay.addNode(j, n2); 318 300 if (j == 0) { 319 301 // first + last point 320 321 } 322 302 newWay.addNode(newWay.getNodesCount(), n2); 303 } 304 323 305 newWay.removeNode(n1); 324 // cmds.add(new ChangeCommand(m_way, newWay)); 325 326 if (newWay.firstNode() != newWay.lastNode() ) 327 { 328 newWay.addNode(newWay.firstNode()); 306 // cmds.add(new ChangeCommand(m_way, newWay)); 307 308 if (newWay.firstNode() != newWay.lastNode()) { 309 newWay.addNode(newWay.firstNode()); 329 310 } 330 311 s_oWay = new Way(newWay); 331 312 332 313 //cmds.add(new DeleteCommand(n1)); 333 314 return cmds; … … 341 322 * 342 323 * @param node Node to connect. 343 * @throws IllegalStateException344 * @throws IndexOutOfBoundsException345 324 * @return List of Commands. 346 325 */ 347 326 private static void tryConnectNodeToAnyWay(Node node, Map<Way, Way> m) 348 327 throws IllegalStateException, IndexOutOfBoundsException { 349 328 … … 364 343 int nearestNodeIndex = 0; 365 344 for (Way ww : s_oWays) { 366 345 System.out.println("Way: " + ww); 367 346 if (!ww.isUsable() || ww.containsNode(node) || !isSameTag(ww)) { 368 347 continue; … … 377 356 double dist = distanceFromSegment2(ll, np.a.getCoor(), np.b.getCoor()); 378 357 //System.out.println(" distance: " + dist1 + " " + dist); 379 358 380 359 if (dist < minDist) { 381 360 minDist = dist; … … 399 378 400 379 private static double distanceFromSegment2(LatLon c, LatLon a, LatLon b) { 401 402 403 380 double x; 381 double y; 382 404 383 StraightLine oStraightLine1 = new StraightLine( 405 new Point2D.Double(a.getX(),a.getY()),406 new Point2D.Double(b.getX(),b.getY()));384 new Point2D.Double(a.getX(), a.getY()), 385 new Point2D.Double(b.getX(), b.getY())); 407 386 StraightLine oStraightLine2 = new StraightLine( 408 new Point2D.Double(c.getX(),c.getY()),409 new Point2D.Double(c.getX() + (a.getY()-b.getY()),c.getY() - (a.getX()-b.getX())));387 new Point2D.Double(c.getX(), c.getY()), 388 new Point2D.Double(c.getX() + (a.getY()-b.getY()), c.getY() - (a.getX()-b.getX()))); 410 389 Point2D.Double oPoint = oStraightLine1.GetIntersectionPoint(oStraightLine2); 411 412 if ((oPoint.x > a.getX() && oPoint.x > b.getX()) || (oPoint.x < a.getX() && oPoint.x < b.getX()) || 413 414 415 } 416 417 x =c.getX()-oPoint.getX();418 y =c.getY()-oPoint.getY();419 390 391 if ((oPoint.x > a.getX() && oPoint.x > b.getX()) || (oPoint.x < a.getX() && oPoint.x < b.getX()) || 392 (oPoint.y > a.getY() && oPoint.y > b.getY()) || (oPoint.y < a.getY() && oPoint.y < b.getY())) { 393 return 100000; 394 } 395 396 x = c.getX()-oPoint.getX(); 397 y = c.getY()-oPoint.getY(); 398 420 399 return Math.sqrt((x*x)+(y*y)); 421 400 } 422 401 423 402 /** 424 403 * Try split way by any existing building nodes. … … 429 408 * 430 409 * @param way Way to split. 431 * @throws IndexOutOfBoundsException432 * @throws IllegalStateException433 410 * @return Modified way 434 411 */ … … 444 421 System.out.println(way.getNodes().get(i) + "-----" + way.getNodes().get((i + 1) % way.getNodesCount())); 445 422 double minDistanceSq = Double.MAX_VALUE; 446 // double maxAngle = MAX_ANGLE;423 // double maxAngle = MAX_ANGLE; 447 424 //List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox( 448 425 // Math.min(n1.getX(), n2.getX()) - minDistanceSq, … … 460 437 //double dist = TracerGeometry.distanceFromSegment(nn, n1, n2); 461 438 double dist = distanceFromSegment2(nn, n1, n2); 462 // double angle = TracerGeometry.angleOfLines(n1, nn, nn, n2);439 // double angle = TracerGeometry.angleOfLines(n1, nn, nn, n2); 463 440 //System.out.println("Angle: " + angle + " distance: " + dist + " Node: " + nod); 464 if (!n1.equalsEpsilon(nn) && !n2.equalsEpsilon(nn) && dist < minDistanceSq) { // && Math.abs(angle) < maxAngle) {465 466 //maxAngle = angle;441 if (!n1.equalsEpsilon(nn) && !n2.equalsEpsilon(nn) && dist < minDistanceSq) { // && Math.abs(angle) < maxAngle) { 442 minDistanceSq = dist; 443 // maxAngle = angle; 467 444 nearestNode = nod; 468 445 } … … 490 467 for (OsmPrimitive op : n.getReferrers()) { 491 468 if (op instanceof Way) { 492 if (isSameTag( (Way)op)) {469 if (isSameTag(op)) { 493 470 return true; 494 471 } … … 497 474 return false; 498 475 } 499 476 500 477 /** 501 478 * Determines if the specified primitive denotes a building. … … 503 480 * @return True if building key is set and different from no,entrance 504 481 */ 505 protected static finalboolean isSameTag(OsmPrimitive p) {482 protected static boolean isSameTag(OsmPrimitive p) { 506 483 String v = p.get(s_oParam.getTag()); 507 484 if (s_bCtrl || s_oParam.getTag().equals("")) { 508 returnv == null || v.equals("no");485 return v == null || v.equals("no"); 509 486 } 510 487 if (s_oParam.getTag().equals("building")) { 511 488 return v != null && !v.equals("no") && !v.equals("entrance"); 512 489 } 513 490 return v != null && !v.equals("no"); -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/StraightLine.java
r30047 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 29 12 30 13 public StraightLine(Double dm, Double dc, boolean bRevert) { 31 32 33 14 this.m_dm = dm; 15 this.m_dc = dc; 16 this.m_dx = Double.NaN; 34 17 if (this.m_dm.isNaN()) { 35 18 this.m_dAlpha = Double.NaN; … … 37 20 this.m_dAlpha = CheckAlpha((Double.NEGATIVE_INFINITY == this.m_dm) ? -90.0 : 90.0); 38 21 } else { 39 this.m_dAlpha = CheckAlpha(Math.atan(dm) * 180 / Math.PI + (bRevert ? 180 : 0) 22 this.m_dAlpha = CheckAlpha(Math.atan(dm) * 180 / Math.PI + (bRevert ? 180 : 0)); 40 23 } 41 24 } 42 25 43 26 public StraightLine(Point2D.Double oP1, Point2D.Double oP2) { 44 27 this.m_dm = (oP2.getY() - oP1.getY()) / (oP2.getX() - oP1.getX()); … … 50 33 } else { 51 34 this.m_dx = Double.NaN; 52 this.m_dAlpha = CheckAlpha(Math.atan((oP2.getY() - oP1.getY()) / (oP2.getX() - oP1.getX())) * 180 / Math.PI + (oP1.getX() > oP2.getX() ? 180 : 0)); 35 this.m_dAlpha = CheckAlpha( 36 Math.atan((oP2.getY() - oP1.getY()) / (oP2.getX() - oP1.getX())) * 180 / Math.PI + (oP1.getX() > oP2.getX() ? 180 : 0)); 53 37 } 54 38 } 55 56 static privateDouble CheckAlpha(Double dAlpha) {39 40 private static Double CheckAlpha(Double dAlpha) { 57 41 if (dAlpha > 180) { 58 42 return dAlpha - 360; … … 63 47 return dAlpha; 64 48 } 65 49 66 50 public Double getM() { 67 51 return m_dm; 68 52 } 53 69 54 public Double getC() { 70 55 return m_dc; 71 56 } 57 72 58 public Double getX() { 73 59 return m_dx; 74 60 } 61 75 62 public Double getAlpha() { 76 63 return m_dAlpha; 77 64 } 65 78 66 public boolean IsLine() { 79 67 return !(m_dx.isNaN() || m_dx.isInfinite() || m_dAlpha.isNaN() || m_dAlpha.isInfinite()) … … 84 72 Double dx; 85 73 Double dy; 86 74 87 75 if (!this.IsLine() || !oLine.IsLine()) { 88 76 // data missing … … 105 93 dy = this.m_dm * dx + this.m_dc; 106 94 } 107 95 108 96 return new Point2D.Double(dx, dy); 109 97 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/TagValues.java
r32474 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 29 12 private String m_strTag = ""; 30 13 private String m_strPreferredValues = ""; 31 14 32 15 private int m_nPos = 0; 33 16 private boolean m_bPreferred = false; 34 17 private String[] m_astrTagValues = null; 35 18 private String[] m_astrTagValuesPreferred = null; 36 19 37 20 public TagValues() { 38 21 clearAll(); 39 22 } 40 23 41 24 public void readBuildingTags(ServerParam param) { 42 if (param ==null || param.getTag() == null || param.getTag().equals("")) {43 44 25 if (param == null || param.getTag() == null || param.getTag().equals("")) { 26 clearAll(); 27 return; 45 28 } 46 29 if (param.getTag().equals(m_strTag) && param.getPreferredValues().equals(m_strPreferredValues)) { 47 30 return; 48 31 } 49 32 clearAll(); 50 33 51 34 m_strTag = param.getTag(); 52 35 m_strPreferredValues = param.getPreferredValues(); 53 54 36 37 // get values 55 38 List<String> tagValues = new ArrayList<>(); 56 39 List<AutoCompletionListItem> values = Main.getLayerManager().getEditDataSet().getAutoCompletionManager().getValues(m_strTag); 57 for ( AutoCompletionListItem i : values) {58 40 for (AutoCompletionListItem i : values) { 41 tagValues.add(i.getValue()); 59 42 } 60 m_astrTagValues = (String[])tagValues.toArray(new String[tagValues.size()]);61 62 63 if ( m_strPreferredValues.equals("")) {64 65 66 67 68 69 70 71 if (getPos(temp, m_astrTagValues) >= 0) {72 73 74 75 m_astrTagValuesPreferred = (String[])tagValues.toArray(new String[tagValues.size()]);76 77 78 79 80 43 m_astrTagValues = tagValues.toArray(new String[tagValues.size()]); 44 45 // get preferred values 46 if (m_strPreferredValues.equals("")) { 47 m_astrTagValuesPreferred = new String[0]; 48 } else { 49 String[] prefered = m_strPreferredValues.split(";"); 50 tagValues = new ArrayList<>(); 51 52 for (String str: prefered) { 53 String temp = str.trim(); 54 if (getPos(temp, m_astrTagValues) >= 0) { 55 tagValues.add(temp); 56 } 57 } 58 m_astrTagValuesPreferred = tagValues.toArray(new String[tagValues.size()]); 59 60 // set to the first preferred 61 m_bPreferred = true; 62 m_nPos = 0; 63 } 81 64 } 82 65 83 66 private void clearAll() { 84 67 m_strTag = ""; 85 68 m_strPreferredValues = ""; 86 69 87 70 m_nPos = 0; 88 71 m_bPreferred = false; … … 90 73 m_astrTagValuesPreferred = null; 91 74 } 92 75 93 76 public String getTag() { 94 95 96 97 77 if (m_strTag == null || m_strTag.equals("")) { 78 return null; 79 } 80 return m_strTag; 98 81 } 99 82 100 83 public String getTagValue() { 101 if ( m_bPreferred == false) {102 103 104 105 106 107 108 109 110 84 if (m_bPreferred == false) { 85 if (m_astrTagValues != null && m_astrTagValues.length > m_nPos) { 86 return m_astrTagValues[m_nPos]; 87 } 88 } else { 89 if (m_astrTagValuesPreferred != null && m_astrTagValuesPreferred.length > m_nPos) { 90 return m_astrTagValuesPreferred[m_nPos]; 91 } 92 } 93 return null; 111 94 } 112 113 private int getPos( 114 if (value != null && values != null) {115 for ( int i = 0; i<values.length ; i++) {116 if ( value.equals(values[i])) {117 118 119 120 121 95 96 private int getPos(String value, String[] values) { 97 if (value != null && values != null) { 98 for (int i = 0; i < values.length; i++) { 99 if (value.equals(values[i])) { 100 return i; 101 } 102 } 103 } 104 return -1; 122 105 } 123 106 124 107 public void left() { 125 126 127 128 129 130 131 132 133 m_nPos = getPos(m_astrTagValues[m_nPos], m_astrTagValuesPreferred);134 if ( m_nPos < 0) {135 136 137 138 139 140 108 if (m_astrTagValues == null || m_astrTagValues.length == 0) { 109 return; 110 } 111 if (m_bPreferred == false) { 112 if (m_astrTagValuesPreferred == null || m_astrTagValuesPreferred.length == 0) { 113 return; 114 } 115 m_bPreferred = true; 116 m_nPos = getPos(m_astrTagValues[m_nPos], m_astrTagValuesPreferred); 117 if (m_nPos < 0) { 118 m_nPos = 0; 119 return; 120 } 121 } 122 m_nPos--; 123 if (m_nPos < 0) m_nPos = m_astrTagValuesPreferred.length-1; 141 124 } 142 125 143 126 public void right() { 144 145 146 147 148 149 150 151 152 m_nPos = getPos(m_astrTagValues[m_nPos], m_astrTagValuesPreferred);153 if ( m_nPos < 0) {154 155 156 157 158 159 127 if (m_astrTagValues == null || m_astrTagValues.length == 0) { 128 return; 129 } 130 if (m_bPreferred == false) { 131 if (m_astrTagValuesPreferred == null || m_astrTagValuesPreferred.length == 0) { 132 return; 133 } 134 m_bPreferred = true; 135 m_nPos = getPos(m_astrTagValues[m_nPos], m_astrTagValuesPreferred); 136 if (m_nPos < 0) { 137 m_nPos = 0; 138 return; 139 } 140 } 141 m_nPos++; 142 if (m_nPos >= m_astrTagValuesPreferred.length) m_nPos = 0; 160 143 } 161 144 162 145 public void up() { 163 164 165 166 167 168 m_nPos = getPos(m_astrTagValuesPreferred[m_nPos], m_astrTagValues);169 if ( m_nPos < 0) {170 171 172 173 174 175 146 if (m_astrTagValues == null || m_astrTagValues.length == 0) { 147 return; 148 } 149 if (m_bPreferred == true) { 150 m_bPreferred = false; 151 m_nPos = getPos(m_astrTagValuesPreferred[m_nPos], m_astrTagValues); 152 if (m_nPos < 0) { 153 m_nPos = 0; 154 return; 155 } 156 } 157 m_nPos--; 158 if (m_nPos < 0) m_nPos = m_astrTagValues.length-1; 176 159 } 177 160 178 161 public void down() { 179 180 181 182 183 184 m_nPos = getPos(m_astrTagValuesPreferred[m_nPos], m_astrTagValues);185 if ( m_nPos < 0) {186 187 188 189 190 191 162 if (m_astrTagValues == null || m_astrTagValues.length == 0) { 163 return; 164 } 165 if (m_bPreferred == true) { 166 m_bPreferred = false; 167 m_nPos = getPos(m_astrTagValuesPreferred[m_nPos], m_astrTagValues); 168 if (m_nPos < 0) { 169 m_nPos = 0; 170 return; 171 } 172 } 173 m_nPos++; 174 if (m_nPos >= m_astrTagValues.length) m_nPos = 0; 192 175 } 193 176 194 177 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/TracerAction.java
r32474 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 62 45 private static final long serialVersionUID = 1L; 63 46 private static boolean s_bServerVersionOK = false; 64 47 65 48 protected boolean m_bCancel; 66 private boolean m_bCtrl; 67 private boolean m_bAlt; //68 private boolean m_bShift; 49 private boolean m_bCtrl; // if pressed no tag is added + changes and connection are made to ways without tag 50 private boolean m_bAlt; // 51 private boolean m_bShift; // if pressed the new way will be add to the current selected 69 52 private boolean m_bEnter = false; 70 53 71 54 private TagValues m_oTagValues = new TagValues(); 72 55 73 56 TracerPlugin m_oPlugin; 74 75 public TracerAction(MapFrame mapFrame) { 76 super(tr("Tracer2"), "tracer2-sml", tr("Tracer2."), Shortcut.registerShortcut("tools:tracer2", tr("Tool: {0}", tr("Tracer2")), KeyEvent.VK_T, Shortcut.DIRECT), mapFrame, getCursor()); 77 } 78 57 58 TracerAction(MapFrame mapFrame) { 59 super(tr("Tracer2"), "tracer2-sml", tr("Tracer2."), 60 Shortcut.registerShortcut("tools:tracer2", tr("Tool: {0}", tr("Tracer2")), KeyEvent.VK_T, Shortcut.DIRECT), 61 mapFrame, getCursor()); 62 } 63 79 64 @Override 80 65 public void keyPressed(KeyEvent e) { 81 //System.out.println("keyPressed: key:" + e.getKeyChar() + " code" + e.getKeyCode() + " Loc" + e.getKeyLocation()+ " ID" + KeyEvent.getKeyText(e.getKeyCode())); 82 83 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 84 List<Command> commands = new ArrayList<>(); 85 86 if ( checkActiveServerParam() == false ) return; 87 88 switch (e.getKeyCode()) { 89 case 37: // left 90 m_oTagValues.left(); 91 break; 92 case 38: // up 93 m_oTagValues.up(); 94 break; 95 case 39: // right 96 m_oTagValues.right(); 97 break; 98 case 40: // down 99 m_oTagValues.down(); 100 break; 101 default: 102 return; 103 } 104 105 if (selection.isEmpty()) 106 { 66 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 67 List<Command> commands = new ArrayList<>(); 68 69 if (checkActiveServerParam() == false) return; 70 71 switch (e.getKeyCode()) { 72 case 37: // left 73 m_oTagValues.left(); 74 break; 75 case 38: // up 76 m_oTagValues.up(); 77 break; 78 case 39: // right 79 m_oTagValues.right(); 80 break; 81 case 40: // down 82 m_oTagValues.down(); 83 break; 84 default: 107 85 return; 108 86 } 109 87 88 if (selection.isEmpty()) { 89 return; 90 } 91 110 92 String strTag = m_oTagValues.getTag(); 111 93 String strTagValue = m_oTagValues.getTagValue(); 112 113 if ( strTag != null && strTagValue != null ) { 114 commands.add(new ChangePropertyCommand(selection, strTag, strTagValue)); 115 116 if (!commands.isEmpty()) { 117 Main.main.undoRedo.add( new SequenceCommand( tr("Change tag {0} to {1}", strTag, strTagValue), commands )); 118 } 119 } 120 } 121 122 @Override 123 public void keyReleased ( KeyEvent e ) { 124 //System.out.println("keyReleased: key:" + e.getKeyChar() + " code" + e.getKeyCode() + " Loc" + e.getKeyLocation()+ " chra" + KeyEvent.getKeyText(e.getKeyCode())); 125 } 126 127 @Override 128 public void keyTyped ( KeyEvent e ) { 129 //System.out.println("keyTyped: key:" + e.getKeyChar() + " code" + e.getKeyCode() + " Loc" + e.getKeyLocation()+ " ID" + KeyEvent.getKeyText(e.getKeyCode())); 130 } 131 94 95 if (strTag != null && strTagValue != null) { 96 commands.add(new ChangePropertyCommand(selection, strTag, strTagValue)); 97 98 if (!commands.isEmpty()) { 99 Main.main.undoRedo.add(new SequenceCommand(tr("Change tag {0} to {1}", strTag, strTagValue), commands)); 100 } 101 } 102 } 103 104 @Override 105 public void keyReleased(KeyEvent e) { 106 } 107 108 @Override 109 public void keyTyped(KeyEvent e) { 110 } 111 132 112 @Override 133 113 public void enterMode() { 134 135 136 137 138 139 140 114 m_bEnter = true; 115 116 // is not working hear 117 // because if JOSM exit it is called too 118 //checkActiveServerParam(); 119 120 if (!isEnabled()) { 141 121 return; 142 122 } … … 146 126 Main.map.mapView.addKeyListener(this); 147 127 } 148 128 149 129 @Override 150 130 public void exitMode() { 151 152 131 m_bEnter = false; 132 153 133 super.exitMode(); 154 134 Main.map.mapView.removeMouseListener(this); 155 135 Main.map.mapView.removeKeyListener(this); 156 136 } 157 137 158 138 private static Cursor getCursor() { 159 139 return ImageProvider.getCursor("crosshair", "tracer2-sml"); 160 140 } 161 141 162 142 protected void traceAsync(Point clickPoint) { 163 143 m_bCancel = false; … … 166 146 */ 167 147 final LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y); 168 148 169 149 try { 170 150 PleaseWaitRunnable tracerTask = new PleaseWaitRunnable(tr("Tracing")) { … … 173 153 traceSync(pos, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 174 154 } 175 155 176 156 @Override 177 157 protected void finish() { 178 158 } 179 159 180 160 @Override 181 161 protected void cancel() { … … 189 169 } 190 170 } 191 171 192 172 private void tagBuilding(Way way) { 193 173 String strTag = m_oTagValues.getTag(); 194 174 String strTagValue = m_oTagValues.getTagValue(); 195 196 if ( 197 198 } 199 } 200 175 176 if (strTag != null && strTagValue != null && !m_bCtrl) { 177 way.put(strTag, strTagValue); 178 } 179 } 180 201 181 private boolean checkServerVersion() { 202 203 204 205 206 GetVersion 182 int nMajor = 1; 183 int nMinor = 1; 184 185 if (s_bServerVersionOK == false) { 186 GetVersion oGetVersion = new GetVersion(); 207 187 oGetVersion.start(); 208 188 209 189 int nRetray = 500; // 5 seconds 210 211 while (oGetVersion.isAlive() && nRetray > 0) {212 213 214 215 216 217 218 219 190 191 while (oGetVersion.isAlive() && nRetray > 0) { 192 try { 193 Thread.sleep(10); 194 } catch (Exception e) { 195 break; 196 } 197 nRetray--; 198 } 199 220 200 if (oGetVersion.m_nVersionMajor < 0 || oGetVersion.m_nVersionMinor < 0) { 221 201 return false; 222 202 } 223 203 if (oGetVersion.m_nVersionMajor != nMajor) { 224 JOptionPane.showMessageDialog(Main.parent, tr("The Tracer2Server version isn''t compatible with this plugin. Please download version {0} from\n{1}.", nMajor + ".x", 225 "http://sourceforge.net/projects/tracer2server/"), tr("Error"), JOptionPane.ERROR_MESSAGE); 204 JOptionPane.showMessageDialog(Main.parent, 205 tr("The Tracer2Server version isn''t compatible with this plugin. Please download version {0} from\n{1}.", nMajor + ".x", 206 "http://sourceforge.net/projects/tracer2server/"), tr("Error"), JOptionPane.ERROR_MESSAGE); 226 207 return false; 227 208 } 228 209 if (oGetVersion.m_nVersionMinor < nMinor) { 229 JOptionPane.showMessageDialog(Main.parent, tr("New version of Tracer2Server is available. For best results please upgrade to version {0}.",nMajor + "." + nMinor ), tr("Information"), JOptionPane.INFORMATION_MESSAGE); 210 JOptionPane.showMessageDialog(Main.parent, 211 tr("New version of Tracer2Server is available. For best results please upgrade to version {0}.", nMajor + "." + nMinor), 212 tr("Information"), JOptionPane.INFORMATION_MESSAGE); 230 213 } 231 214 s_bServerVersionOK = true; 232 233 234 } 235 215 } 216 return true; 217 } 218 236 219 private boolean checkActiveServerParam() { 237 238 239 240 if ( m_bEnter == true || TracerPlugin.s_oPlugin.m_oParamList.getActivParam() == null) {241 242 243 244 220 if (checkServerVersion() == false) { 221 return false; 222 } 223 if (m_bEnter == true || TracerPlugin.s_oPlugin.m_oParamList.getActivParam() == null) { 224 225 ServerParamList listParam = TracerPlugin.s_oPlugin.m_oParamList; 226 List<ServerParam> listEnableParam = listParam.getEnableParamList(); 227 245 228 if (listEnableParam == null || listEnableParam.size() == 0) { 246 247 JOptionPane.showMessageDialog(Main.parent, tr("No set of parameter is active!"), tr("Error"), 248 249 } 250 if ( listEnableParam.size() == 1) {251 252 253 254 255 } 256 229 listParam.setActivParam(null); 230 JOptionPane.showMessageDialog(Main.parent, tr("No set of parameter is active!"), tr("Error"), JOptionPane.ERROR_MESSAGE); 231 return false; 232 } 233 if (listEnableParam.size() == 1) { 234 ServerParam param = listEnableParam.get(0); 235 listParam.setActivParam(param); 236 m_oTagValues.readBuildingTags(param); 237 return true; 238 } 239 257 240 ServerParamSelectDialog dialog = new ServerParamSelectDialog(listEnableParam, listParam.getActivParam()); 258 241 259 242 if (dialog.getShow()) { 260 243 JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 261 244 JDialog dlg = pane.createDialog(Main.parent, tr("Tracer2") + " - " + tr("Select parameter")); 262 263 245 dlg.setVisible(true); 246 Object obj = pane.getValue(); 264 247 dlg.dispose(); 265 if(obj != null && ((Integer)obj) == JOptionPane.OK_OPTION) {266 267 268 269 270 } 271 272 273 if ( param == null) {274 275 276 277 278 279 } 280 248 if (obj != null && ((Integer) obj) == JOptionPane.OK_OPTION) { 249 TracerPlugin.s_oPlugin.m_oParamList.setActivParam(dialog.getSelectedParam()); 250 } else { 251 return false; 252 } 253 } 254 } 255 ServerParam param = TracerPlugin.s_oPlugin.m_oParamList.getActivParam(); 256 if (param == null) { 257 return false; 258 } 259 m_bEnter = false; 260 m_oTagValues.readBuildingTags(param); 261 return true; 262 } 263 281 264 private void traceSync(LatLon pos, ProgressMonitor progressMonitor) { 282 265 Collection<Command> commands = new LinkedList<>(); 283 266 284 267 progressMonitor.beginTask(null, 3); 285 268 try { 286 269 ArrayList<LatLon> coordList; 287 288 if ( checkActiveServerParam() == false) return;289 270 271 if (checkActiveServerParam() == false) return; 272 290 273 ServerParam param = TracerPlugin.s_oPlugin.m_oParamList.getActivParam(); 291 GetTrace 274 GetTrace oTraceSimple = new GetTrace(pos, param); 292 275 oTraceSimple.start(); 293 try 294 { 295 while(oTraceSimple.isAlive()) 296 { 297 Thread.sleep(50); 298 if (m_bCancel == true) 299 { 300 oTraceSimple.interrupt(); 301 break; 302 } 303 } 304 coordList = oTraceSimple.m_listLatLon; 305 } catch (Exception e) { 306 coordList = new ArrayList<>(); 307 } 308 276 try { 277 while (oTraceSimple.isAlive()) { 278 Thread.sleep(50); 279 if (m_bCancel == true) { 280 oTraceSimple.interrupt(); 281 break; 282 } 283 } 284 coordList = oTraceSimple.m_listLatLon; 285 } catch (Exception e) { 286 coordList = new ArrayList<>(); 287 } 288 309 289 if (m_bCancel == true || coordList.size() == 0) { 310 290 return; 311 291 } 312 292 313 293 // make nodes a way 314 294 Way way = new Way(); … … 323 303 } 324 304 way.addNode(firstNode); 325 305 326 306 tagBuilding(way); 327 307 328 308 // connect to other buildings 329 309 commands.add(ConnectWays.connect(way, pos, param, m_bCtrl, m_bAlt)); 330 310 331 311 if (!commands.isEmpty()) { 332 333 334 335 336 337 338 339 312 String strCommand; 313 if (ConnectWays.s_bAddNewWay == true) { 314 strCommand = tr("Tracer2: add a way with {0} points", coordList.size()); 315 } else { 316 strCommand = tr("Tracer2: modify way to {0} points", coordList.size()); 317 } 318 Main.main.undoRedo.add(new SequenceCommand(strCommand, commands)); 319 340 320 if (m_bShift) { 341 321 getLayerManager().getEditDataSet().addSelected(ConnectWays.s_oWay); … … 346 326 System.out.println("Failed"); 347 327 } 348 328 349 329 } finally { 350 330 progressMonitor.finishTask(); 351 331 } 352 332 } 353 333 354 334 public void cancel() { 355 335 m_bCancel = true; 356 336 } 357 337 358 338 @Override 359 339 public void mouseClicked(MouseEvent e) { 360 340 } 361 341 362 342 @Override 363 343 public void mouseEntered(MouseEvent e) { 364 344 } 365 345 366 346 @Override 367 347 public void mouseExited(MouseEvent e) { 368 348 } 369 349 370 350 @Override 371 351 public void mousePressed(MouseEvent e) { … … 379 359 } 380 360 } 381 361 382 362 @Override 383 363 protected void updateKeyModifiers(MouseEvent e) { … … 386 366 m_bShift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 387 367 } 388 368 389 369 @Override 390 370 public void mouseReleased(MouseEvent e) { 391 371 } 392 372 393 373 } 394 374 -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/TracerDebug.java
r30737 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 34 17 35 18 private static String FormatPrimitive(String strIn) { 36 37 38 39 return strIn.replaceAll("xxxxx", "\r\n{");19 while (strIn.contains("{")) { 20 strIn = strIn.replace("{", "xxxxx"); 21 } 22 return strIn.replaceAll("xxxxx", "\r\n {"); 40 23 } 41 24 42 public void OutputOsmPrimitive(Collection<OsmPrimitive> cOsmPrimitive) { 43 if (cOsmPrimitive != null) { 44 for (OsmPrimitive p : cOsmPrimitive) { 45 System.out.println(" OsmPrimitive: " + FormatPrimitive(p.toString())); 46 } 47 } 48 } 49 50 public void OutputOsmExtendsPrimitive(Collection<? extends OsmPrimitive> cOsmPrimitive) { 51 if (cOsmPrimitive != null) { 52 for (OsmPrimitive p : cOsmPrimitive) { 53 System.out.println(" OsmPrimitive x: " + FormatPrimitive(p.toString())); 54 } 55 } 56 } 57 58 public void OutputCommands(LinkedList<Command> cmds) { 59 60 for (Command c : cmds) { 61 System.out.println(""); 25 public void OutputOsmPrimitive(Collection<OsmPrimitive> cOsmPrimitive) { 26 if (cOsmPrimitive != null) { 27 for (OsmPrimitive p : cOsmPrimitive) { 28 System.out.println(" OsmPrimitive: " + FormatPrimitive(p.toString())); 29 } 30 } 31 } 62 32 63 Collection<OsmPrimitive> cp1 = null; 64 Collection<OsmPrimitive> cp2 = null; 65 Collection<OsmPrimitive> cp3 = null; 66 Collection<? extends OsmPrimitive> cpx = null; 67 68 List<OsmPrimitive> lp1 = new LinkedList<>(); 69 List<OsmPrimitive> lp2 = new LinkedList<>(); 70 List<OsmPrimitive> lp3 = new LinkedList<>(); 71 List<OsmPrimitive> lp = new LinkedList<>(); 72 73 cp1 = lp1; 74 cp2 = lp2; 75 cp3 = lp3; 76 cpx = lp; 77 78 //OsmPrimitive op = new OsmPrimitive(); 79 OsmPrimitive op1 = new Way(); 80 81 System.out.println("Command: " + c.toString()); 82 83 if (c instanceof AddCommand) { 84 AddCommand x = (AddCommand) c; 85 x.fillModifiedData(cp1, cp2, cp3); 86 OutputOsmPrimitive(cp1); 87 OutputOsmPrimitive(cp2); 88 OutputOsmPrimitive(cp3); 89 cpx = x.getParticipatingPrimitives(); 90 OutputOsmExtendsPrimitive(cpx); 91 } else if (c instanceof ChangeCommand) { // order is important! 92 ChangeCommand x = (ChangeCommand) c; 93 x.fillModifiedData(cp1, cp2, cp3); 94 x.getOrig(op1); 95 OutputOsmPrimitive(cp1); 96 OutputOsmPrimitive(cp2); 97 OutputOsmPrimitive(cp3); 98 cpx = x.getParticipatingPrimitives(); 99 OutputOsmExtendsPrimitive(cpx); 100 } else if (c instanceof DeleteCommand) { 101 DeleteCommand x = (DeleteCommand) c; 102 x.fillModifiedData(cp1, cp2, cp3); 103 OutputOsmPrimitive(cp1); 104 OutputOsmPrimitive(cp2); 105 OutputOsmPrimitive(cp3); 106 cpx = x.getParticipatingPrimitives(); 107 OutputOsmExtendsPrimitive(cpx); 108 } else if (c instanceof MoveCommand) { // order is important! 109 MoveCommand x = (MoveCommand) c; 110 x.fillModifiedData(cp1, cp2, cp3); 111 OutputOsmPrimitive(cp1); 112 OutputOsmPrimitive(cp2); 113 OutputOsmPrimitive(cp3); 114 cpx = x.getParticipatingPrimitives(); 115 OutputOsmExtendsPrimitive(cpx); 116 } else { 117 c.fillModifiedData(cp1, cp2, cp3); 118 OutputOsmPrimitive(cp1); 119 OutputOsmPrimitive(cp2); 120 OutputOsmPrimitive(cp3); 121 cpx = c.getParticipatingPrimitives(); 122 OutputOsmExtendsPrimitive(cpx); 123 } 33 public void OutputOsmExtendsPrimitive(Collection<? extends OsmPrimitive> cOsmPrimitive) { 34 if (cOsmPrimitive != null) { 35 for (OsmPrimitive p : cOsmPrimitive) { 36 System.out.println(" OsmPrimitive x: " + FormatPrimitive(p.toString())); 37 } 124 38 } 125 } 126 39 } 40 41 public void OutputCommands(LinkedList<Command> cmds) { 42 43 for (Command c : cmds) { 44 System.out.println(""); 45 46 Collection<OsmPrimitive> cp1 = null; 47 Collection<OsmPrimitive> cp2 = null; 48 Collection<OsmPrimitive> cp3 = null; 49 Collection<? extends OsmPrimitive> cpx = null; 50 51 List<OsmPrimitive> lp1 = new LinkedList<>(); 52 List<OsmPrimitive> lp2 = new LinkedList<>(); 53 List<OsmPrimitive> lp3 = new LinkedList<>(); 54 List<OsmPrimitive> lp = new LinkedList<>(); 55 56 cp1 = lp1; 57 cp2 = lp2; 58 cp3 = lp3; 59 cpx = lp; 60 61 //OsmPrimitive op = new OsmPrimitive(); 62 OsmPrimitive op1 = new Way(); 63 64 System.out.println("Command: " + c.toString()); 65 66 if (c instanceof AddCommand) { 67 AddCommand x = (AddCommand) c; 68 x.fillModifiedData(cp1, cp2, cp3); 69 OutputOsmPrimitive(cp1); 70 OutputOsmPrimitive(cp2); 71 OutputOsmPrimitive(cp3); 72 cpx = x.getParticipatingPrimitives(); 73 OutputOsmExtendsPrimitive(cpx); 74 } else if (c instanceof ChangeCommand) { // order is important! 75 ChangeCommand x = (ChangeCommand) c; 76 x.fillModifiedData(cp1, cp2, cp3); 77 x.getOrig(op1); 78 OutputOsmPrimitive(cp1); 79 OutputOsmPrimitive(cp2); 80 OutputOsmPrimitive(cp3); 81 cpx = x.getParticipatingPrimitives(); 82 OutputOsmExtendsPrimitive(cpx); 83 } else if (c instanceof DeleteCommand) { 84 DeleteCommand x = (DeleteCommand) c; 85 x.fillModifiedData(cp1, cp2, cp3); 86 OutputOsmPrimitive(cp1); 87 OutputOsmPrimitive(cp2); 88 OutputOsmPrimitive(cp3); 89 cpx = x.getParticipatingPrimitives(); 90 OutputOsmExtendsPrimitive(cpx); 91 } else if (c instanceof MoveCommand) { // order is important! 92 MoveCommand x = (MoveCommand) c; 93 x.fillModifiedData(cp1, cp2, cp3); 94 OutputOsmPrimitive(cp1); 95 OutputOsmPrimitive(cp2); 96 OutputOsmPrimitive(cp3); 97 cpx = x.getParticipatingPrimitives(); 98 OutputOsmExtendsPrimitive(cpx); 99 } else { 100 c.fillModifiedData(cp1, cp2, cp3); 101 OutputOsmPrimitive(cp1); 102 OutputOsmPrimitive(cp2); 103 OutputOsmPrimitive(cp3); 104 cpx = c.getParticipatingPrimitives(); 105 OutputOsmExtendsPrimitive(cpx); 106 } 107 } 108 } 109 127 110 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/TracerException.java
r30047 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 24 7 25 8 /** 26 * 27 28 9 * 10 */ 11 private static final long serialVersionUID = 4404064875119981715L; 29 12 30 publicTracerException() {13 TracerException() { 31 14 super(tr("An unknown error has occurred")); 32 15 } 33 16 34 publicTracerException(String err) {17 TracerException(String err) { 35 18 super(err); 36 19 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/TracerGeometry.java
r30047 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 21 4 import org.openstreetmap.josm.data.coor.LatLon; 22 5 23 public class TracerGeometry { 6 public final class TracerGeometry { 7 8 private TracerGeometry() { 9 // Hide default constructor for utilities classes 10 } 24 11 25 12 /** … … 31 18 * @return Angle in degrees. 32 19 */ 33 static public double angleOfLines(LatLon a, LatLon b, LatLon c, LatLon d) {20 public static double angleOfLines(LatLon a, LatLon b, LatLon c, LatLon d) { 34 21 return (Math.abs( 35 36 22 Math.atan2(a.lat() - b.lat(), a.lon() - b.lon()) - 23 Math.atan2(c.lat() - d.lat(), c.lon() - d.lon()) 37 24 ) / Math.PI * 180) % 360; 38 25 } … … 45 32 * @return Distance. 46 33 */ 47 static public double distanceFromSegment(LatLon c, LatLon a, LatLon b) {34 public static double distanceFromSegment(LatLon c, LatLon a, LatLon b) { 48 35 return distanceFromSegment( 49 36 c.getX(), c.getY(), 50 37 a.getX(), a.getY(), 51 38 b.getX(), b.getY() 52 );39 ); 53 40 } 54 41 55 static privatedouble distanceFromSegment(double cx, double cy, double ax, double ay, double bx, double by) {42 private static double distanceFromSegment(double cx, double cy, double ax, double ay, double bx, double by) { 56 43 double r_numerator = (cx - ax) * (bx - ax) + (cy - ay) * (by - ay); 57 44 double r_denomenator = (bx - ax) * (bx - ax) + (by - ay) * (by - ay); 58 if (r_denomenator == 0)System.out.println("r_denomenator == 0 ------------");45 if (r_denomenator == 0)System.out.println("r_denomenator == 0 ------------"); 59 46 double r = r_numerator / r_denomenator; 60 47 double s = ((ay - cy) * (bx - ax) - (ax - cx) * (by - ay)) / r_denomenator; -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/TracerPlugin.java
r30047 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2; 20 3 … … 30 13 31 14 public class TracerPlugin extends Plugin { 32 15 33 16 public static TracerPlugin s_oPlugin; 34 17 35 18 public final ServerParamList m_oParamList; 36 19 37 20 public TracerPlugin(PluginInformation info) { 38 21 super(info); 39 22 MainMenu.add(Main.main.menu.moreToolsMenu, new TracerAction(Main.map)); 40 23 41 24 s_oPlugin = this; 42 25 43 26 File plugindir = new File(this.getPluginDir()); 44 27 if (!plugindir.exists()) { 45 28 plugindir.mkdirs(); 46 29 } 47 30 48 31 m_oParamList = new ServerParamList(new File(plugindir, "serverParam.cfg").getAbsolutePath()); 49 32 } 50 33 51 34 @Override 52 35 public PreferenceSetting getPreferenceSetting() { 53 36 return new ServerParamPreference(this); 54 37 } 55 56 38 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParam.java
r30049 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.preferences; 20 3 … … 35 18 36 19 public class ServerParam { 37 20 38 21 protected boolean m_bEnabled; 39 22 private String m_strName = "Name"; … … 48 31 private String m_strTag = "building"; 49 32 private String m_strPreferredValues = "yes;house;garage"; 50 33 51 34 protected JMenuItem m_oMenuItem; 52 35 53 36 public boolean isEnabled() { 54 37 return m_bEnabled; 55 38 } 39 56 40 public void setEnabled(boolean enabled) { 57 41 if (!m_bEnabled ^ enabled) 58 42 return; 59 43 m_bEnabled = enabled; 60 44 } 61 45 62 46 public String getName() { 63 47 return m_strName; 64 48 } 49 65 50 public void setName(String name) { 66 51 m_strName = name; 67 52 } 68 53 69 54 public String getDescription() { 70 55 return m_strDescription; 71 56 } 57 72 58 public void setDescription(String description) { 73 59 m_strDescription = description; 74 60 } 75 61 76 62 public String getUrl() { 77 63 return m_strUrl; 78 64 } 65 79 66 public void setUrl(String url) { 80 67 m_strUrl = url; 81 68 } 82 69 83 70 public String getTileSize() { 84 71 return m_strTileSize; 85 72 } 73 86 74 public void setTileSize(String tileSize) { 87 75 m_strTileSize = tileSize; 88 76 } 89 77 90 78 public String getResolution() { 91 79 return m_strResolution; 92 80 } 81 93 82 public void setResolution(String resolution) { 94 83 m_strResolution = resolution; 95 84 } 96 85 97 86 public String getSkipBottom() { 98 87 return m_strSkipBottom; 99 88 } 89 100 90 public void setSkipBottom(String skipBottom) { 101 91 m_strSkipBottom = skipBottom; 102 92 } 103 93 104 94 public String getMode() { 105 95 return m_strMode; 106 96 } 97 107 98 public void setMode(String mode) { 108 99 m_strMode = mode; 109 100 } 110 101 111 102 public String getThreshold() { 112 103 return m_strThreshold; 113 104 } 105 114 106 public void setThreshold(String threshold) { 115 107 m_strThreshold = threshold; 116 108 } 117 109 118 110 public String getPointsPerCircle() { 119 111 return m_strPointsPerCircle; 120 112 } 113 121 114 public void setPointsPerCircle(String pointsPerCircle) { 122 115 m_strPointsPerCircle = pointsPerCircle; 123 116 } 124 117 125 118 public String getTag() { 126 119 return m_strTag; 127 120 } 121 128 122 public void setTag(String tag) { 129 123 m_strTag = tag; 130 124 } 131 125 132 126 public String getPreferredValues() { 133 127 return m_strPreferredValues; 134 128 } 129 135 130 public void setPreferredValues(String preferredValues) { 136 131 m_strPreferredValues = preferredValues; 137 132 } 138 133 139 134 public ServerParam() { 140 135 m_bEnabled = false; 141 136 } 142 137 143 138 public ServerParam(String name) { 144 139 this(); 145 140 m_strName = name; 146 141 } 147 142 148 143 public String serialize() { 149 144 StringBuilder oBuilder = new StringBuilder(); … … 163 158 return oBuilder.toString(); 164 159 } 165 160 166 161 public static ServerParam unserialize(String str) { 167 162 ServerParam oParam = new ServerParam(); 168 163 String[] lines = str.split("\n"); 169 164 for (String line : lines) { … … 196 191 return oParam; 197 192 } 198 193 199 194 protected void showErrorMessage(String message, String details) { 200 195 final JPanel p = new JPanel(new GridBagLayout()); 201 p.add(new JMultilineLabel(message), GBC.eol());196 p.add(new JMultilineLabel(message), GBC.eol()); 202 197 if (details != null) { 203 198 JTextArea info = new JTextArea(details, 20, 60); … … 207 202 } 208 203 SwingUtilities.invokeLater(new Runnable() { 204 @Override 209 205 public void run() { 210 206 JOptionPane.showMessageDialog(Main.parent, p, tr("Tracer2 error"), JOptionPane.ERROR_MESSAGE); … … 212 208 }); 213 209 } 214 210 215 211 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamDialog.java
r30532 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.preferences; 20 3 … … 41 24 public class ServerParamDialog extends ExtendedDialog { 42 25 /** 43 * 44 45 46 47 48 49 50 51 52 53 26 * 27 */ 28 private static final long serialVersionUID = -3229680217088662218L; 29 30 private String[] m_astrTileSize = new String[] {"0.0001", "0.0002", "0.0004", "0.0008", "0.001", "0.002", "0.004", "0.008", "0.01"}; 31 private String[] m_astrResolution = new String[] {"512", "1024", "2048", "4096"}; 32 private String[] m_astrMode = new String[] {"boundary", "match color"}; 33 private String[] m_astrPointsPerCircle = new String[] {"0", "8", "12", "16", "20", "24", "32"}; 34 35 private ServerParam m_oParam; 36 54 37 private JPanel m_oPanel = new JPanel(new GridBagLayout()); 55 38 private JTextField m_oName = new JTextField(); 56 39 private JTextField m_oDescription = new JTextField(); 57 private JTextArea m_oUrl = new JTextArea(5, 5);40 private JTextArea m_oUrl = new JTextArea(5, 5); 58 41 private JComboBox<String> m_oTileSize; 59 42 private JComboBox<String> m_oResolution; … … 64 47 private JTextField m_oTag = new JTextField(); 65 48 private JTextField m_oPreferredValues = new JTextField(); 66 49 67 50 private JScrollPane m_oScrollpaneUrl; 68 51 69 52 public ServerParam getServerParam() { 70 53 return m_oParam; 71 54 } 72 55 73 56 private void addLabelled(String str, Component c) { 74 57 JLabel label = new JLabel(str); … … 77 60 m_oPanel.add(c, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 78 61 } 79 62 80 63 private void addGap() { 81 64 JPanel p = new JPanel(); 82 p.setMinimumSize(new Dimension(10, 0));65 p.setMinimumSize(new Dimension(10, 0)); 83 66 m_oPanel.add(p, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 84 67 } 85 68 86 69 private void load() { 87 70 m_oName.setText(m_oParam.getName()); 88 71 m_oDescription.setText(m_oParam.getDescription()); 89 72 m_oUrl.setText(m_oParam.getUrl()); 90 loadComboBox( 91 loadComboBox( 73 loadComboBox(m_oTileSize, m_oParam.getTileSize(), m_astrTileSize); 74 loadComboBox(m_oResolution, m_oParam.getResolution(), m_astrResolution); 92 75 //m_oSkipBottom.setText(param.getSkipBottom()); 93 loadComboBox( 76 loadComboBox(m_oMode, m_oParam.getMode(), m_astrMode); 94 77 m_oThreshold.setText(m_oParam.getThreshold()); 95 loadComboBox( 78 loadComboBox(m_oPointsPerCircle, m_oParam.getPointsPerCircle(), m_astrPointsPerCircle); 96 79 m_oTag.setText(m_oParam.getTag()); 97 80 m_oPreferredValues.setText(m_oParam.getPreferredValues()); 98 81 } 99 82 100 83 private void save() { 101 102 103 104 105 106 107 108 109 110 111 84 m_oParam.setName(m_oName.getText()); 85 m_oParam.setDescription(m_oDescription.getText()); 86 m_oParam.setUrl(m_oUrl.getText()); 87 m_oParam.setTileSize(saveComboBox(m_oTileSize, m_astrTileSize)); 88 m_oParam.setResolution(saveComboBox(m_oResolution, m_astrResolution)); 89 //m_oParam.setSkipBottom(m_oSkipBottom.getText()); 90 m_oParam.setMode(saveComboBox(m_oMode, m_astrMode)); 91 m_oParam.setThreshold(m_oThreshold.getText()); 92 m_oParam.setPointsPerCircle(saveComboBox(m_oPointsPerCircle, m_astrPointsPerCircle)); 93 m_oParam.setTag(m_oTag.getText()); 94 m_oParam.setPreferredValues(m_oPreferredValues.getText()); 112 95 } 113 114 private void loadComboBox( JComboBox<?> c, String strValue, String[] astrValues) {96 97 private void loadComboBox(JComboBox<?> c, String strValue, String[] astrValues) { 115 98 int pos = 0; 116 for ( String str: astrValues) {117 118 119 120 121 99 for (String str: astrValues) { 100 if (strValue.equals(str)) { 101 c.setSelectedIndex(pos); 102 return; 103 } 104 pos++; 122 105 } 123 106 } 124 125 private String saveComboBox( JComboBox<?> c, String[] astrValues) {107 108 private String saveComboBox(JComboBox<?> c, String[] astrValues) { 126 109 return astrValues[c.getSelectedIndex()]; 127 110 } 128 111 129 112 public ServerParamDialog(ServerParam param) { 130 113 super(Main.parent, tr("Tracer2") + " - " + tr("Parameter for server request"), 131 new String[] { tr("OK"), tr("Cancel")},114 new String[] {tr("OK"), tr("Cancel")}, 132 115 true); 133 116 if (param == null) { 134 117 m_oParam = new ServerParam(); 135 118 } else { 136 119 m_oParam = param; 137 120 } 138 121 139 122 contentInsets = new Insets(15, 15, 5, 15); 140 setButtonIcons(new String[] { "ok.png", "cancel.png"});141 123 setButtonIcons(new String[] {"ok.png", "cancel.png"}); 124 142 125 m_oTileSize = new JComboBox<>(m_astrTileSize); 143 126 m_oResolution = new JComboBox<>(m_astrResolution); 144 127 m_oMode = new JComboBox<>(m_astrMode); 145 128 m_oPointsPerCircle = new JComboBox<>(m_astrPointsPerCircle); 146 129 147 130 load(); 148 131 149 132 addLabelled(tr("Name:"), m_oName); 150 133 addLabelled(tr("Description:"), m_oDescription); … … 165 148 addLabelled(tr("Tag:"), m_oTag); 166 149 addLabelled(tr("Preferred values:"), m_oPreferredValues); 167 150 168 151 setMinimumSize(new Dimension(500, 0)); 169 152 170 153 setContent(m_oPanel); 171 154 setupDialog(); 172 155 } 173 156 174 157 @Override 175 158 protected void buttonAction(int buttonIndex, ActionEvent evt) { … … 177 160 save(); 178 161 } else { 179 162 m_oParam = null; 180 163 } 181 164 super.buttonAction(buttonIndex, evt); -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamList.java
r30738 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.preferences; 20 3 … … 38 21 this.m_strFilename = filename; 39 22 if (filename == null) { 40 23 loadDefault(); 41 24 } else { 42 25 load(); 43 26 } 44 27 } … … 49 32 String strLine; 50 33 while ((strLine = oReader.readLine()) != null) { 51 34 oBuilder.append(strLine).append('\n'); 52 35 if (strLine.equals("")) { 53 54 36 m_listServerParam.add(ServerParam.unserialize(oBuilder.toString())); 37 oBuilder = new StringBuilder(); 55 38 } 56 39 } 57 40 } catch (Exception e) { 58 41 loadDefault(); 59 42 } 60 43 } … … 62 45 public void loadDefault() { 63 46 try ( 64 65 BufferedReader oReader = new BufferedReader(new InputStreamReader(oIP));66 ) {47 InputStream oIP = getClass().getResourceAsStream("/resources/serverParam.cfg"); 48 BufferedReader oReader = new BufferedReader(new InputStreamReader(oIP)); 49 ) { 67 50 StringBuilder oBuilder = new StringBuilder(); 68 51 String strLine; 69 52 while ((strLine = oReader.readLine()) != null) { 70 53 oBuilder.append(strLine).append('\n'); 71 54 if (strLine.equals("")) { 72 73 55 m_listServerParam.add(ServerParam.unserialize(oBuilder.toString())); 56 oBuilder = new StringBuilder(); 74 57 } 75 58 } 76 59 } catch (Exception e) { 77 60 Main.warn("Tracer2 warning: can't load file " + m_strFilename); 78 61 } 79 62 } … … 82 65 try (OutputStreamWriter oWriter = new OutputStreamWriter(new FileOutputStream(m_strFilename), "UTF-8")) { 83 66 for (ServerParam param : m_listServerParam) { 84 67 oWriter.write(param.serialize()); 85 68 } 86 69 } catch (Exception e) { 87 70 Main.warn("Tracer2 warning: can't save file " + m_strFilename); 88 71 } 89 72 } … … 96 79 return m_oActivParam; 97 80 } 81 98 82 public void setActivParam(ServerParam param) { 99 if (m_listServerParam.contains(param)) {100 101 83 if (m_listServerParam.contains(param)) { 84 m_oActivParam = param; 85 } 102 86 } 103 87 104 88 public List<ServerParam> getEnableParamList() { 105 106 for (ServerParam param: m_listServerParam) {107 108 109 89 List<ServerParam> listParam = new ArrayList<>(); 90 for (ServerParam param: m_listServerParam) { 91 if (param.isEnabled()) { 92 listParam.add(param); 93 } 110 94 } 111 95 return listParam; 112 96 } 113 97 114 98 public void addParam(ServerParam param) { 115 99 m_listServerParam.add(param); 116 100 } 117 101 118 102 public void removeParam(ServerParam param) { 119 120 103 param.setEnabled(false); 104 m_listServerParam.remove(param); 121 105 } 122 106 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamPanel.java
r30047 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.preferences; 20 3 … … 36 19 37 20 public class ServerParamPanel extends JPanel { 38 39 * 40 41 42 43 44 21 /** 22 * 23 */ 24 private static final long serialVersionUID = -6174275926314685531L; 25 26 ServerParamList m_listParam; 27 45 28 public ServerParamPanel(ServerParamList listParam) { 46 29 super(new GridBagLayout()); 47 30 m_listParam = listParam; 48 31 } 49 32 50 33 public void refresh() { 51 34 removeAll(); … … 54 37 gbc.fill = GridBagConstraints.HORIZONTAL; 55 38 gbc.insets = new Insets(2, 5, 2, 5); 56 39 57 40 for (final ServerParam param : m_listParam.getParamList()) { 58 41 gbc.gridx = 0; 59 42 gbc.weightx = 1.0; 60 43 gbc.anchor = GridBagConstraints.WEST; 61 44 62 45 final JCheckBox cbParam = new JCheckBox(param.getName()); 63 46 cbParam.setSelected(param.isEnabled()); 64 47 cbParam.addActionListener(new ActionListener() { 48 @Override 65 49 public void actionPerformed(ActionEvent e) { 66 50 param.setEnabled(cbParam.isSelected()); … … 68 52 }); 69 53 add(cbParam, gbc); 70 54 71 55 gbc.gridx = 1; 72 56 gbc.weightx = 0; 73 57 gbc.anchor = GridBagConstraints.EAST; 74 58 75 59 final JButton bEdit = new JButton(tr("Edit")); 76 60 bEdit.addActionListener(new ActionListener() { … … 84 68 }); 85 69 add(bEdit, gbc); 86 70 87 71 gbc.gridx = 2; 88 72 final JButton bDel = new JButton(tr("Delete")); … … 94 78 tr("Are you sure?"), 95 79 JOptionPane.YES_NO_OPTION, 96 JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 97 { 98 m_listParam.removeParam(param); 80 JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { 81 m_listParam.removeParam(param); 99 82 refresh(); 100 83 } … … 102 85 }); 103 86 add(bDel, gbc); 104 87 105 88 gbc.gridy++; 106 89 } … … 108 91 gbc.fill = GridBagConstraints.NONE; 109 92 gbc.anchor = GridBagConstraints.WEST; 110 93 111 94 JPanel p = new JPanel(new GridBagLayout()); 112 95 113 96 final JButton bNew = new JButton(tr("Add new")); 114 97 bNew.addActionListener(new ActionListener() { … … 118 101 dlg.setVisible(true); 119 102 dlg.dispose(); 120 ServerParam param = ((ServerParamDialog) dlg).getServerParam();103 ServerParam param = ((ServerParamDialog) dlg).getServerParam(); 121 104 if (param != null && param.getName() != null && (!"".equals(param.getName()))) { 122 105 m_listParam.addParam(param); … … 127 110 }); 128 111 p.add(bNew); 129 112 130 113 final JButton bPredefined = new JButton(tr("Add predefined")); 131 114 bPredefined.addActionListener(new ActionListener() { 132 115 @Override 133 116 public void actionPerformed(ActionEvent arg0) { 134 117 ServerParamList myParamList; 135 118 136 137 138 139 119 myParamList = new ServerParamList(null); 120 121 ServerParamSelectDialog dialog = new ServerParamSelectDialog(myParamList.getParamList(), null); 122 140 123 if (dialog.getShow()) { 141 124 JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 142 125 JDialog dlg = pane.createDialog(Main.parent, tr("Tracer2") + " - " + tr("Select predefined parameter")); 143 144 126 dlg.setVisible(true); 127 Object obj = pane.getValue(); 145 128 dlg.dispose(); 146 if(obj != null && ((Integer)obj) == JOptionPane.OK_OPTION) {147 129 if (obj != null && ((Integer) obj) == JOptionPane.OK_OPTION) { 130 ServerParam param = dialog.getSelectedParam(); 148 131 149 150 151 152 param = ((ServerParamDialog) dlg).getServerParam();132 dlg = new ServerParamDialog(param); 133 dlg.setVisible(true); 134 dlg.dispose(); 135 param = ((ServerParamDialog) dlg).getServerParam(); 153 136 if (param != null && param.getName() != null && (!"".equals(param.getName()))) { 154 137 m_listParam.addParam(param); 155 138 param.setEnabled(true); 156 139 } 157 140 } 158 141 } 159 142 refresh(); … … 161 144 }); 162 145 p.add(bPredefined); 163 146 164 147 add(p, gbc); 165 148 gbc.gridy++; 166 149 167 150 gbc.weightx = 1.0; 168 151 gbc.weighty = 1.0; -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamPreference.java
r30047 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.preferences; 20 3 … … 32 15 33 16 public class ServerParamPreference extends DefaultTabPreferenceSetting { 34 35 36 17 18 TracerPlugin m_oPlugin; 19 37 20 public ServerParamPreference(TracerPlugin plugin) { 38 21 super("tracer2", tr("Tracer2") + " - " + tr("Preferences"), tr("Modify list of parameter for server request.")); 39 22 40 23 m_oPlugin = plugin; 41 24 } 42 25 43 26 @Override 44 27 public void addGui(PreferenceTabbedPane gui) { … … 49 32 p.add(sp, GBC.eol().fill(GridBagConstraints.BOTH)); 50 33 } 51 34 52 35 @Override 53 36 public boolean ok() { -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamSelectDialog.java
r30532 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.preferences; 20 3 … … 33 16 34 17 public class ServerParamSelectDialog extends JPanel { 35 36 18 19 private JComboBox<String> m_oComboBox; 37 20 List<ServerParam> m_listServerParam; 38 21 private boolean m_bShow = true; 39 22 40 23 public boolean getShow() { 41 24 return m_bShow; 42 25 } 43 44 45 46 47 48 49 50 51 52 26 27 public ServerParamSelectDialog(List<ServerParam> listParam) { 28 Init(m_listServerParam, null); 29 } 30 31 public ServerParamSelectDialog(List<ServerParam> listServerParam, ServerParam activParam) { 32 Init(listServerParam, activParam); 33 } 34 35 private void Init(List<ServerParam> listParam, ServerParam activParam) { 53 36 GridBagConstraints c = new GridBagConstraints(); 54 37 55 38 String[] astr = new String[listParam.size()]; 56 39 57 40 m_listServerParam = listParam; 58 59 if ( activParam == null) {60 41 42 if (activParam == null) { 43 activParam = m_listServerParam.get(0); 61 44 } 62 45 int i = 0; 63 46 int pos = 0; 64 for ( ServerParam param: m_listServerParam) {65 66 67 68 69 47 for (ServerParam param: m_listServerParam) { 48 astr[i] = param.getName(); 49 if (param.equals(activParam)) { 50 pos = i; 51 } 52 i++; 70 53 } 71 54 m_oComboBox = new JComboBox<>(astr); 72 55 m_oComboBox.setSelectedIndex(pos); 73 56 74 57 setLayout(new GridBagLayout()); 75 76 c.insets = new Insets(4, 4,4,4);58 59 c.insets = new Insets(4, 4, 4, 4); 77 60 c.gridwidth = 1; 78 61 c.weightx = 0.8; … … 81 64 c.gridy = 0; 82 65 add(new JLabel(tr("Parameter:")), c); 83 66 84 67 c.gridwidth = 1; 85 68 c.gridx = 1; … … 87 70 c.weightx = 1.5; 88 71 add(m_oComboBox, c); 89 90 91 92 72 } 73 74 public ServerParam getSelectedParam() { 75 int nSel = m_oComboBox.getSelectedIndex(); 93 76 return m_listServerParam.get(nSel); 94 77 } 95 public void checkComboBox() { 96 int nSel = m_oComboBox.getSelectedIndex(); 78 79 public void checkComboBox() { 80 int nSel = m_oComboBox.getSelectedIndex(); 97 81 TracerPlugin.s_oPlugin.m_oParamList.setActivParam(m_listServerParam.get(nSel)); 98 82 } 99 83 100 84 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/server/GetTrace.java
r31369 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.server; 20 3 21 4 import java.util.ArrayList; 22 5 6 import org.openstreetmap.josm.Main; 23 7 import org.openstreetmap.josm.data.coor.LatLon; 24 8 import org.openstreetmap.josm.plugins.tracer2.preferences.ServerParam; 25 9 26 10 public class GetTrace extends Request { 27 28 29 11 12 private LatLon m_oLatLon; 13 private ServerParam m_oServerParam; 30 14 public ArrayList<LatLon> m_listLatLon = new ArrayList<>(); 31 15 32 16 /** 33 17 * Trace s simple shape on position. … … 35 19 * @param oParam parameter for tracing. 36 20 */ 37 public GetTrace(LatLon oLatLon, ServerParam oParam) {38 39 21 public GetTrace(LatLon oLatLon, ServerParam oParam) { 22 m_oLatLon = oLatLon; 23 m_oServerParam = oParam; 40 24 } 41 42 /** 43 * Thread that get a shape from the Server. 44 */ 25 26 /** 27 * Thread that get a shape from the Server. 28 */ 29 @Override 45 30 public void run() { 46 47 31 m_listLatLon = new ArrayList<>(); 32 48 33 try { 49 34 String strResponse = callServer("traceOrder=GetTrace" 50 51 52 53 54 55 56 57 58 59 60 );61 35 + "&traceLat=" + m_oLatLon.lat() 36 + "&traceLon=" + m_oLatLon.lon() 37 + "&traceName=" + m_oServerParam.getName() 38 + "&traceUrl=" + m_oServerParam.getUrl() 39 + "&traceTileSize=" + m_oServerParam.getTileSize() 40 + "&traceResolution=" + m_oServerParam.getResolution() 41 //+ "&traceSkipBottom=" + param.getSkipBottom() 42 + "&traceMode=" + m_oServerParam.getMode() 43 + "&traceThreshold=" + m_oServerParam.getThreshold() 44 + "&tracePointsPerCircle=" + m_oServerParam.getPointsPerCircle() 45 ); 46 62 47 if (strResponse == null || strResponse.equals("")) { 63 48 return; 64 49 } 65 50 66 51 if (checkError(strResponse) == true) { 67 52 return; 68 53 } 69 54 70 55 if (strResponse.startsWith("(")) { 71 72 56 GetPoints(strResponse); 57 return; 73 58 } 74 59 String[] astrParts = strResponse.split("&"); 75 60 76 61 for (String strPart : astrParts) { 77 if (strPart.contains("tracePoints=")) 78 { 79 String strPoints = strPart.replace("tracePoints=", ""); 80 GetPoints(strPoints); 81 return; 82 } 62 if (strPart.contains("tracePoints=")) { 63 String strPoints = strPart.replace("tracePoints=", ""); 64 GetPoints(strPoints); 65 return; 66 } 83 67 } 84 68 } catch (Exception e) { 85 //m_listLatLon = new ArrayList<>(); 69 //m_listLatLon = new ArrayList<>(); 70 Main.warn(e); 86 71 } 87 72 } 88 89 73 90 74 /** 91 75 * Get points from string 92 76 */ 93 public void GetPoints(String strResponse) { 94 try { 95 if (!strResponse.startsWith("(") || !strResponse.endsWith(")")){ 96 return; 97 } 98 strResponse = strResponse.substring(1, strResponse.length()-1); 99 100 ArrayList<LatLon> nodelist = new ArrayList<>(); 101 102 String[] astrPoints = strResponse.split("\\)\\("); 103 for (String strPoint : astrPoints) { 104 String[] astrParts = strPoint.split(":"); 105 double x = Double.parseDouble(astrParts[0]); 106 double y = Double.parseDouble(astrParts[1]); 107 nodelist.add(new LatLon(x, y)); 108 } 109 m_listLatLon = nodelist; 110 } catch (Exception e) { 111 //m_listLatLon = new ArrayList<>(); 112 } 113 } 114 77 public void GetPoints(String strResponse) { 78 try { 79 if (!strResponse.startsWith("(") || !strResponse.endsWith(")")) { 80 return; 81 } 82 strResponse = strResponse.substring(1, strResponse.length()-1); 83 84 ArrayList<LatLon> nodelist = new ArrayList<>(); 85 86 String[] astrPoints = strResponse.split("\\)\\("); 87 for (String strPoint : astrPoints) { 88 String[] astrParts = strPoint.split(":"); 89 double x = Double.parseDouble(astrParts[0]); 90 double y = Double.parseDouble(astrParts[1]); 91 nodelist.add(new LatLon(x, y)); 92 } 93 m_listLatLon = nodelist; 94 } catch (Exception e) { 95 //m_listLatLon = new ArrayList<>(); 96 Main.warn(e); 97 } 98 } 99 115 100 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/server/GetVersion.java
r30077 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.server; 20 3 4 import org.openstreetmap.josm.Main; 5 21 6 public class GetVersion extends Request { 22 7 23 8 public int m_nVersionMajor = -1; 24 9 public int m_nVersionMinor = -1; 25 10 public int m_nVersionBuild = -1; 26 11 public int m_nVersionRevision = -1; 27 12 28 13 /** 29 14 * Get version from server. 30 15 */ 31 16 public GetVersion() { 32 17 } 33 34 /** 35 * Thread that get the version of the Server. 36 */ 18 19 /** 20 * Thread that get the version of the Server. 21 */ 22 @Override 37 23 public void run() { 38 24 try { 39 String strResponse = callServer("traceOrder=GetVersion" 40 25 String strResponse = callServer("traceOrder=GetVersion"); 26 41 27 if (strResponse == null || strResponse.equals("")) { 42 28 return; 43 29 } 44 30 45 31 if (checkError(strResponse) == true) { 46 32 return; 47 33 } 48 34 49 35 String[] astrParts = strResponse.split(":"); 50 36 if (astrParts.length < 2) { 51 37 return; 52 38 } 53 39 if (astrParts.length > 0) m_nVersionMajor = Integer.parseInt(astrParts[0]); … … 56 42 if (astrParts.length > 3) m_nVersionRevision = Integer.parseInt(astrParts[3]); 57 43 } catch (Exception e) { 44 Main.warn(e); 58 45 } 59 46 } 60 47 61 48 } -
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/server/Request.java
r30062 r32788 1 /** 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.tracer2.server; 20 3 … … 31 14 32 15 public class Request extends Thread { 33 16 34 17 static final String URL = "http://localhost:49243/"; 35 18 36 19 public Request() { 37 20 } 38 21 39 22 /** 40 23 * Send request to the server. … … 53 36 return oBuilder.toString(); 54 37 } catch (ConnectException e) { 55 JOptionPane.showMessageDialog(Main.parent, tr("Tracer2Server isn''t running. Please start the Server.\nIf you don''t have the server, please download it from\n{0}.", 56 "http://sourceforge.net/projects/tracer2server/") , tr("Error"), JOptionPane.ERROR_MESSAGE); 38 JOptionPane.showMessageDialog(Main.parent, 39 tr("Tracer2Server isn''t running. Please start the Server.\nIf you don''t have the server, please download it from\n{0}.", 40 "http://sourceforge.net/projects/tracer2server/"), tr("Error"), JOptionPane.ERROR_MESSAGE); 57 41 return ""; 58 42 } catch (Exception e) { 59 JOptionPane.showMessageDialog(Main.parent, tr("Tracer2Server hasn''t found anything.") + "\n", tr("Error"), JOptionPane.ERROR_MESSAGE); 60 return ""; 61 } 43 JOptionPane.showMessageDialog(Main.parent, tr("Tracer2Server hasn''t found anything.") + "\n", 44 tr("Error"), JOptionPane.ERROR_MESSAGE); 45 return ""; 46 } 62 47 } 63 48 64 49 /** 65 50 * Checks errors in response from the server. … … 70 55 String strIdentifier = "&traceError="; 71 56 if (strResponse.contains(strIdentifier)) { 72 String strError = strResponse.replaceFirst(strIdentifier, "").trim(); 73 JOptionPane.showMessageDialog(Main.parent, tr("Tracer2Server has detected an error.") + "\n" + strError, tr("Error"), JOptionPane.ERROR_MESSAGE); 74 return true; 57 String strError = strResponse.replaceFirst(strIdentifier, "").trim(); 58 JOptionPane.showMessageDialog(Main.parent, tr("Tracer2Server has detected an error.") + "\n" + strError, 59 tr("Error"), JOptionPane.ERROR_MESSAGE); 60 return true; 75 61 } 76 62 return false; 77 63 } 78 64 65 @Override 79 66 public void run() { 80 67 } 81 82 68 }
Note:
See TracChangeset
for help on using the changeset viewer.