Changeset 25179 in osm
- Timestamp:
- 2011-01-29T19:59:10+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/CommandLine
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/build.xml
r25060 r25179 5 5 <property name="commit.message" value="Moar bugfixes" /> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="3 751" />7 <property name="plugin.main.version" value="3826" /> 8 8 9 9 -
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r25052 r25179 1 1 /* 2 2 * CommandLine.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License as published by 8 8 * the Free Software Foundation; either version 2 of the License, or 9 9 * (at your option) any later version. 10 * 10 * 11 11 * This program is distributed in the hope that it will be useful, 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 * 15 * 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software … … 23 23 24 24 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 25 import static org.openstreetmap.josm.tools.I18n.marktr; 25 26 import static org.openstreetmap.josm.tools.I18n.tr; 26 import static org.openstreetmap.josm.tools.I18n.marktr;27 27 28 28 import java.awt.BorderLayout; … … 35 35 import java.io.OutputStream; 36 36 import java.io.OutputStreamWriter; 37 import java.io.FileOutputStream;38 37 import java.io.PrintWriter; 39 import java.nio.charset.Charset;40 38 import java.util.ArrayList; 41 import java.util.List;42 39 import java.util.Collection; 43 40 import java.util.HashMap; 44 import java.util.Iterator; 45 import java.util.regex.*; 41 import java.util.List; 42 43 import javax.swing.JMenu; 46 44 import javax.swing.JTextField; 47 import javax.swing.JMenu;48 import javax.swing.JMenuItem;49 45 import javax.swing.JToolBar; 50 46 51 47 import org.openstreetmap.josm.Main; 52 48 import org.openstreetmap.josm.actions.mapmode.MapMode; 53 import org.openstreetmap.josm.command.MoveCommand;54 49 import org.openstreetmap.josm.command.SequenceCommand; 55 import org.openstreetmap.josm.data.gpx.GpxData;56 import org.openstreetmap.josm.data.gpx.GpxTrack;57 import org.openstreetmap.josm.data.gpx.GpxTrackSegment;58 import org.openstreetmap.josm.data.gpx.WayPoint;59 50 import org.openstreetmap.josm.data.imagery.ImageryInfo; 60 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;61 51 import org.openstreetmap.josm.data.osm.BBox; 52 import org.openstreetmap.josm.data.osm.DataSet; 62 53 import org.openstreetmap.josm.data.osm.Node; 63 54 import org.openstreetmap.josm.data.osm.OsmPrimitive; 64 55 import org.openstreetmap.josm.data.osm.Relation; 65 56 import org.openstreetmap.josm.data.osm.Way; 66 import org.openstreetmap.josm.data.osm.DataSet; 67 import org.openstreetmap.josm.data.osm.DataSetMerger; 57 import org.openstreetmap.josm.gui.MainMenu; 58 import org.openstreetmap.josm.gui.MapFrame; 59 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 68 60 import org.openstreetmap.josm.gui.layer.GpxLayer; 69 61 import org.openstreetmap.josm.gui.layer.ImageryLayer; 70 62 import org.openstreetmap.josm.gui.layer.Layer; 71 import org.openstreetmap.josm.gui.MainMenu; 72 import org.openstreetmap.josm.gui.MapFrame; 73 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 74 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 75 import org.openstreetmap.josm.io.IllegalDataException; 63 import org.openstreetmap.josm.io.GpxWriter; 76 64 import org.openstreetmap.josm.io.OsmWriter; 77 import org.openstreetmap.josm.io.GpxWriter;78 65 import org.openstreetmap.josm.plugins.Plugin; 79 66 import org.openstreetmap.josm.plugins.PluginInformation; … … 106 93 String commandText = textField.getText().substring(prefix.length()); 107 94 switch (mode) { 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 95 case IDLE: 96 if (commandText.isEmpty()) { 97 commandText = history.getLastItem(); 98 } 99 else { 100 history.addItem(commandText); 101 } 102 Command command = findCommand(commandText, true); 103 if (command != null) { 104 startCommand(command); 105 } 106 else 107 setMode(Mode.IDLE); 108 break; 109 case SELECTION: 110 if (currentMapFrame.mapMode instanceof WayAction || currentMapFrame.mapMode instanceof NodeAction || currentMapFrame.mapMode instanceof RelationAction || currentMapFrame.mapMode instanceof AnyAction) { 111 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 112 if (selected.size() > 0) 113 loadParameter(selected, true); 114 } 115 else { 116 loadParameter(commandText, currentCommand.parameters.get(currentCommand.currentParameterNum).maxInstances == 1); 117 } 118 break; 119 case ADJUSTMENT: 120 break; 134 121 } 135 122 e.consume(); … … 165 152 if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) 166 153 e.consume(); 167 168 169 170 171 172 173 154 } 155 if (e.getID() == KeyEvent.KEY_TYPED) 156 if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) 157 e.consume(); 158 super.processKeyEvent(e); 159 if (textField.getText().length() < prefix.length()) { // Safe 160 setMode(mode); 174 161 } 175 162 if (e.getID() == KeyEvent.KEY_TYPED) { … … 230 217 } 231 218 219 @Override 232 220 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 233 221 { … … 271 259 return null; 272 260 } 273 261 274 262 protected void setMode(Mode targetMode) { 275 263 DataSet currentDataSet = Main.main.getCurrentDataSet(); … … 296 284 MapMode action = null; 297 285 switch (currentType) { 298 case POINT: 299 action = new PointAction(currentMapFrame, this); 300 break; 301 case WAY: 302 action = new WayAction(currentMapFrame, this); 303 break; 304 case NODE: 305 action = new NodeAction(currentMapFrame, this); 306 break; 307 case RELATION: 308 action = new RelationAction(currentMapFrame, this); 309 break; 310 case ANY: 311 action = new AnyAction(currentMapFrame, this); 312 break; 313 case LENGTH: 314 action = new LengthAction(currentMapFrame, this); 315 break; 316 case USERNAME: 317 loadParameter((Object)Main.pref.get("osm-server.username", null), true); 318 action = new DummyAction(currentMapFrame, this); 319 break; 320 case IMAGERYURL: 321 Layer layer = Main.map.mapView.getActiveLayer(); 322 if (layer != null) { 323 if (layer instanceof ImageryLayer) { 286 case POINT: 287 action = new PointAction(currentMapFrame, this); 288 break; 289 case WAY: 290 action = new WayAction(currentMapFrame, this); 291 break; 292 case NODE: 293 action = new NodeAction(currentMapFrame, this); 294 break; 295 case RELATION: 296 action = new RelationAction(currentMapFrame, this); 297 break; 298 case ANY: 299 action = new AnyAction(currentMapFrame, this); 300 break; 301 case LENGTH: 302 action = new LengthAction(currentMapFrame, this); 303 break; 304 case USERNAME: 305 loadParameter(Main.pref.get("osm-server.username", null), true); 306 action = new DummyAction(currentMapFrame, this); 307 break; 308 case IMAGERYURL: 309 Layer layer = Main.map.mapView.getActiveLayer(); 310 if (layer != null) { 311 if (layer instanceof ImageryLayer) { 312 } 313 else { 314 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 315 if (imageryLayers.size() == 1) { 316 layer = imageryLayers.get(0); 324 317 } 325 318 else { 326 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class);327 if (imageryLayers.size() == 1) {328 layer = imageryLayers.get(0);329 330 else {331 endInput();332 return;333 }334 }335 }336 ImageryInfo info = ((ImageryLayer)layer).getInfo();337 String url = info.getURL();338 String itype = info.getImageryType().getUrlString();339 loadParameter((Object)(url.equals("") ? itype : url), true);340 action = new DummyAction(currentMapFrame, this);341 break;342 case IMAGERYOFFSET:343 Layer olayer = Main.map.mapView.getActiveLayer();344 if (olayer != null) {345 if (olayer instanceof ImageryLayer) {319 endInput(); 320 return; 321 } 322 } 323 } 324 ImageryInfo info = ((ImageryLayer)layer).getInfo(); 325 String url = info.getUrl(); 326 String itype = info.getImageryType().getUrlString(); 327 loadParameter((url.equals("") ? itype : url), true); 328 action = new DummyAction(currentMapFrame, this); 329 break; 330 case IMAGERYOFFSET: 331 Layer olayer = Main.map.mapView.getActiveLayer(); 332 if (olayer != null) { 333 if (olayer instanceof ImageryLayer) { 334 } 335 else { 336 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 337 if (imageryLayers.size() == 1) { 338 olayer = imageryLayers.get(0); 346 339 } 347 340 else { 348 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 349 if (imageryLayers.size() == 1) { 350 olayer = imageryLayers.get(0); 351 } 352 else { 353 endInput(); 354 return; 355 } 356 } 357 } 358 loadParameter((Object)(String.valueOf(((ImageryLayer)olayer).getDx()) + "," + String.valueOf(((ImageryLayer)olayer).getDy())), true); 359 action = new DummyAction(currentMapFrame, this); 360 break; 361 default: 362 action = new DummyAction(currentMapFrame, this); 363 break; 341 endInput(); 342 return; 343 } 344 } 345 } 346 loadParameter((String.valueOf(((ImageryLayer)olayer).getDx()) + "," + String.valueOf(((ImageryLayer)olayer).getDy())), true); 347 action = new DummyAction(currentMapFrame, this); 348 break; 349 default: 350 action = new DummyAction(currentMapFrame, this); 351 break; 364 352 } 365 353 currentMapFrame.selectMapMode(action); … … 483 471 // redirect child process's stderr to JOSM stderr 484 472 new Thread(new Runnable() { 473 @Override 485 474 public void run() { 486 475 try { … … 501 490 // Write stdin stream 502 491 Thread osmWriteThread = new Thread(new Runnable() { 492 @Override 503 493 public void run() { 504 494 BBox bbox = null; … … 512 502 osmWriter.header(); 513 503 for (OsmPrimitive primitive : refObjects) { 514 if (primitive instanceof Node) 504 if (primitive instanceof Node) 515 505 osmWriter.visit((Node)primitive); 516 else if (primitive instanceof Way) 517 osmWriter.visit((Way)primitive); 518 else if (primitive instanceof Relation) 506 else if (primitive instanceof Way) 507 osmWriter.visit((Way)primitive); 508 else if (primitive instanceof Relation) 519 509 osmWriter.visit((Relation)primitive); 520 510 if (bbox == null) … … 531 521 pObjects = parameter.getParameterObjects(); 532 522 for (OsmPrimitive primitive : pObjects) { 533 if (primitive instanceof Node) 523 if (primitive instanceof Node) 534 524 osmWriter.visit((Node)primitive); 535 else if (primitive instanceof Way) 536 osmWriter.visit((Way)primitive); 537 else if (primitive instanceof Relation) 525 else if (primitive instanceof Way) 526 osmWriter.visit((Way)primitive); 527 else if (primitive instanceof Relation) 538 528 osmWriter.visit((Relation)primitive); 539 529 if (bbox == null) … … 567 557 final OsmToCmd osmToCmd = new OsmToCmd(this, Main.main.getCurrentDataSet()); 568 558 Thread osmParseThread = new Thread(new Runnable() { 559 @Override 569 560 public void run() { 570 561 try {
Note:
See TracChangeset
for help on using the changeset viewer.