Changeset 25052 in osm for applications/editors/josm/plugins
- Timestamp:
- 2011-01-14T18:15:45+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/CommandLine
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/build.xml
r25044 r25052 3 3 4 4 <!-- enter the SVN commit message --> 5 <property name="commit.message" value=" Icons with menu and panel support" />5 <property name="commit.message" value="New types imageryurl, imageryoffset and username" /> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 7 <property name="plugin.main.version" value="3751" /> -
applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java
r25038 r25052 169 169 Main.map.mapView.repaint(); 170 170 updateStatusLine(); 171 parentPlugin. endInput();171 parentPlugin.abortInput(); 172 172 } 173 173 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java
r25044 r25052 164 164 } 165 165 break; 166 case USERNAME: 167 if (obj instanceof String) return true; 168 break; 169 case IMAGERYURL: 170 if (obj instanceof String) return true; 171 break; 172 case IMAGERYOFFSET: 173 if (obj instanceof String) return true; 174 break; 166 175 } 167 176 return false; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r25044 r25052 47 47 import javax.swing.JMenu; 48 48 import javax.swing.JMenuItem; 49 import javax.swing.JToolBar; 49 50 50 51 import org.openstreetmap.josm.Main; … … 52 53 import org.openstreetmap.josm.command.MoveCommand; 53 54 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 import org.openstreetmap.josm.data.imagery.ImageryInfo; 60 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 54 61 import org.openstreetmap.josm.data.osm.BBox; 55 62 import org.openstreetmap.josm.data.osm.Node; … … 59 66 import org.openstreetmap.josm.data.osm.DataSet; 60 67 import org.openstreetmap.josm.data.osm.DataSetMerger; 61 import org.openstreetmap.josm.data.gpx.GpxData;62 import org.openstreetmap.josm.data.gpx.GpxTrack;63 import org.openstreetmap.josm.data.gpx.GpxTrackSegment;64 import org.openstreetmap.josm.data.gpx.WayPoint;65 68 import org.openstreetmap.josm.gui.layer.GpxLayer; 69 import org.openstreetmap.josm.gui.layer.ImageryLayer; 66 70 import org.openstreetmap.josm.gui.layer.Layer; 67 71 import org.openstreetmap.josm.gui.MainMenu; … … 77 81 public class CommandLine extends Plugin { 78 82 protected JTextField textField; 83 protected JTextField historyField; 79 84 private String prefix; 80 85 private Mode mode; … … 91 96 commandSymbol = ": "; 92 97 history = new History(100); 98 historyField = new JTextField(); 93 99 textField = new JTextField() { 94 100 @Override … … 226 232 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 227 233 { 228 if (oldFrame ==null && newFrame!=null) {234 if (oldFrame == null && newFrame != null) { 229 235 currentMapFrame = newFrame; 230 currentMapFrame.add(textField,BorderLayout.NORTH); 231 } 236 JToolBar tb = new JToolBar(); 237 tb.setLayout(new BorderLayout()); 238 tb.setFloatable(false); 239 tb.setOrientation(JToolBar.HORIZONTAL); 240 tb.add(historyField, BorderLayout.NORTH); 241 tb.add(textField, BorderLayout.SOUTH); 242 currentMapFrame.add(tb, BorderLayout.NORTH); 243 printHistory("Loaded CommandLine, version " + getPluginInformation().version); 244 } 245 } 246 247 protected void printHistory(String text) { 248 historyField.setText(text); 232 249 } 233 250 234 251 private void loadCommands() { 235 Loader loader = new Loader(getPluginDir()); 236 commands = loader.load(); // lol 237 252 commands = (new Loader(getPluginDir())).load(); 238 253 for (Command command : commands) { 239 254 commandMenu.add(new CommandAction(command, this)); … … 272 287 mode = Mode.SELECTION; 273 288 Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum); 274 prefix = tr(currentParameter.description );289 prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description); 275 290 if (currentParameter.getRawValue() instanceof Relay) 276 291 prefix = prefix + " (" + ((Relay)(currentParameter.getRawValue())).getOptionsString() + ")"; … … 299 314 action = new LengthAction(currentMapFrame, this); 300 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) { 324 } 325 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) { 346 } 347 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; 301 361 default: 302 362 action = new DummyAction(currentMapFrame, this); … … 311 371 prefix = tr("Processing..."); 312 372 textField.setText(prefix); 373 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 313 374 } 314 375 } … … 321 382 public void deactivate() { 322 383 Main.map.mapView.requestFocus(); 384 } 385 386 public void abortInput() { 387 printHistory(tr("Aborted") + "."); 388 endInput(); 323 389 } 324 390 … … 333 399 if (currentCommand.hasNextParameter()) { 334 400 if (next) { 401 Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum); 402 String prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description); 403 prefix += commandSymbol; 404 String value = currentParameter.getValue(); 405 printHistory(prefix + value); 335 406 currentCommand.nextParameter(); 336 407 setMode(Mode.SELECTION); … … 360 431 currentCommand.resetLoading(); 361 432 } 362 System.out.println("Selected before " + String.valueOf(currentCommand.currentParameterNum) + "\n");433 //System.out.println("Selected before " + String.valueOf(currentCommand.currentParameterNum) + "\n"); 363 434 } 364 435 … … 371 442 public void runTool() { 372 443 setMode(Mode.PROCESSING); 373 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));374 444 String commandToRun = currentCommand.run; 375 445 … … 495 565 496 566 // Read stdout stream 567 final OsmToCmd osmToCmd = new OsmToCmd(this, Main.main.getCurrentDataSet()); 497 568 Thread osmParseThread = new Thread(new Runnable() { 498 569 public void run() { … … 501 572 HashMap<Long, Long> inexiDMap = new HashMap<Long, Long>(); 502 573 final InputStream inputStream = tp.process.getInputStream(); 503 final List<org.openstreetmap.josm.command.Command> cmdlist = new OsmToCmd(Main.main.getCurrentDataSet(), inputStream).getCommandList();504 //OsmReaderMod.deleteInexiDMap();574 osmToCmd.parseStream(inputStream); 575 final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList(); 505 576 if (!cmdlist.isEmpty()) { 506 577 SequenceCommand cmd = new SequenceCommand(commandName, cmdlist); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java
r25038 r25052 56 56 Main.map.mapView.repaint(); 57 57 updateStatusLine(); 58 parentPlugin. endInput();58 parentPlugin.abortInput(); 59 59 } 60 60 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java
r25038 r25052 101 101 Main.map.statusLine.setAngle(-1); 102 102 updateStatusLine(); 103 parentPlugin. endInput();103 parentPlugin.abortInput(); 104 104 } 105 105 -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java
r25044 r25052 106 106 else if (Value.equals("string")) currentParameter.type = Type.STRING; 107 107 else if (Value.equals("relay")) currentParameter.type = Type.RELAY; 108 else if (Value.equals("username")) currentParameter.type = Type.USERNAME; 109 else if (Value.equals("imageryurl")) currentParameter.type = Type.IMAGERYURL; 110 else if (Value.equals("imageryoffset")) currentParameter.type = Type.IMAGERYOFFSET; 108 111 } 109 112 else if (Name.equals("maxinstances")) { -
applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java
r25038 r25052 2 2 * NodeAction.java 3 3 * 4 * Copyright 201 0Hind <foxhind@gmail.com>4 * Copyright 2011 Hind <foxhind@gmail.com> 5 5 * 6 6 */ … … 109 109 } 110 110 else 111 System.out.println("Maximum instances!");111 parentPlugin.printHistory("Maximum instances is " + String.valueOf(maxInstances)); 112 112 } 113 113 } … … 170 170 Main.map.mapView.repaint(); 171 171 updateStatusLine(); 172 parentPlugin. endInput();172 parentPlugin.abortInput(); 173 173 } 174 174 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java
r25038 r25052 1 /* 2 * OsmToCmd.java 3 * 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 6 */ 7 1 8 package CommandLine; 2 9 … … 12 19 import javax.xml.parsers.ParserConfigurationException; 13 20 import javax.xml.parsers.SAXParserFactory; 21 import javax.xml.parsers.SAXParser; 14 22 15 23 import org.openstreetmap.josm.Main; … … 32 40 import org.xml.sax.SAXParseException; 33 41 import org.xml.sax.helpers.DefaultHandler; 42 import org.xml.sax.ext.LexicalHandler; 34 43 35 44 final class OsmToCmd { 45 private CommandLine parentPlugin; 36 46 private final DataSet targetDataSet; 37 47 private final LinkedList<Command> cmds = new LinkedList<Command>(); 38 48 private HashMap<PrimitiveId, OsmPrimitive> externalIdMap; // Maps external ids to internal primitives 39 40 public OsmToCmd(DataSet targetDataSet, InputStream stream) throws IllegalDataException { 49 50 public OsmToCmd(CommandLine parentPlugin, DataSet targetDataSet) { 51 this.parentPlugin = parentPlugin; 41 52 this.targetDataSet = targetDataSet; 42 53 externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>(); 43 parseStream(stream);44 54 } 45 55 46 p rivatevoid parseStream(InputStream stream) throws IllegalDataException {56 public void parseStream(InputStream stream) throws IllegalDataException { 47 57 try { 48 58 InputSource inputSource = new InputSource(UTFInputStreamReader.create(stream, "UTF-8")); 49 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser()); 59 SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); 60 Parser handler = new Parser(); 61 parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); 62 parser.parse(inputSource, handler); 50 63 } catch(ParserConfigurationException e) { 51 64 throw new IllegalDataException(e.getMessage(), e); … … 63 76 } 64 77 65 private class Parser extends DefaultHandler {78 private class Parser extends DefaultHandler implements LexicalHandler { 66 79 private Locator locator; 67 80 … … 259 272 } 260 273 274 @Override 275 public void comment(char[] ch, int start, int length) { 276 parentPlugin.printHistory(String.valueOf(ch)); 277 } 278 279 public void startCDATA() { 280 } 281 282 public void endCDATA() { 283 } 284 285 public void startEntity(String name) { 286 } 287 288 public void endEntity(String name) { 289 } 290 291 public void startDTD(String name, String publicId, String systemId) { 292 } 293 294 public void endDTD() { 295 } 296 261 297 private double getDouble(Attributes atts, String value) { 262 298 return Double.parseDouble(atts.getValue(value)); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Parameter.java
r25038 r25052 2 2 * Parameter.java 3 3 * 4 * Copyright 201 0Hind <foxhind@gmail.com>4 * Copyright 2011 Hind <foxhind@gmail.com> 5 5 * 6 6 */ 7 7 8 8 package CommandLine; 9 10 import static org.openstreetmap.josm.tools.I18n.tr; 9 11 10 12 import java.util.ArrayList; … … 15 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.data.osm.Relation; 17 20 18 21 public class Parameter { … … 41 44 break; 42 45 case STRING: 43 out = "\"" + String.valueOf(value) + "\"";46 out = String.valueOf(value); 44 47 break; 45 48 case RELAY: 46 49 out = String.valueOf(((Relay)value).getValue()); 50 break; 51 case NODE: 52 out = String.valueOf(valueList.size()) + " " + tr("nodes"); 53 break; 54 case WAY: 55 out = String.valueOf(valueList.size()) + " " + tr("ways"); 56 break; 57 case RELATION: 58 out = String.valueOf(valueList.size()) + " " + tr("relations"); 59 break; 60 case ANY: 61 out = String.valueOf(valueList.size()) + " " + tr("OSM objects"); 62 break; 63 case USERNAME: 64 out = String.valueOf(value); 65 break; 66 case IMAGERYURL: 67 out = String.valueOf(value); 68 break; 69 case IMAGERYOFFSET: 70 out = String.valueOf(value); 47 71 break; 48 72 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java
r25038 r25052 2 2 * PointAction.java 3 3 * 4 * Copyright 201 0Hind <foxhind@gmail.com>4 * Copyright 2011 Hind <foxhind@gmail.com> 5 5 * 6 6 */ … … 178 178 Main.map.mapView.repaint(); 179 179 updateStatusLine(); 180 parentPlugin. endInput();180 parentPlugin.abortInput(); 181 181 } 182 182 -
applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java
r25038 r25052 2 2 * RelationAction.java 3 3 * 4 * Copyright 201 0Hind <foxhind@gmail.com>4 * Copyright 2011 Hind <foxhind@gmail.com> 5 5 * 6 6 */ … … 56 56 Main.map.mapView.repaint(); 57 57 updateStatusLine(); 58 parentPlugin. endInput();58 parentPlugin.abortInput(); 59 59 } 60 60 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Type.java
r25038 r25052 19 19 package CommandLine; 20 20 21 public enum Type { NODE, WAY, RELATION, ANY, POINT, LENGTH, NATURAL, STRING, TRIGGER, RELAY }21 public enum Type { NODE, WAY, RELATION, ANY, POINT, LENGTH, NATURAL, STRING, TRIGGER, RELAY, USERNAME, IMAGERYURL, IMAGERYOFFSET } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java
r25038 r25052 2 2 * WayAction.java 3 3 * 4 * Copyright 201 0Hind <foxhind@gmail.com>4 * Copyright 2011 Hind <foxhind@gmail.com> 5 5 * 6 6 */ … … 191 191 Main.map.mapView.repaint(); 192 192 updateStatusLine(); 193 parentPlugin. endInput();193 parentPlugin.abortInput(); 194 194 } 195 195 }
Note:
See TracChangeset
for help on using the changeset viewer.