Changeset 31646 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-10-19T13:28:54+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r30678 r31646 22 22 23 23 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 24 import static org.openstreetmap.josm.tools.I18n.marktr;25 24 import static org.openstreetmap.josm.tools.I18n.tr; 26 25 … … 76 75 77 76 public class CommandLine extends Plugin { 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 commandMenu = Main.main.menu.addMenu(marktr("Commands"), KeyEvent.VK_O, Main.main.menu.getDefaultMenuPos(), ht("/Plugin/CommandLine"));198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 77 protected JTextField textField; 78 protected JTextField historyField; 79 private String prefix; 80 private Mode mode; 81 private ArrayList<Command> commands; 82 private JMenu commandMenu; 83 protected Command currentCommand; 84 protected String commandSymbol; 85 protected History history; 86 protected MapFrame currentMapFrame; 87 protected MapMode previousMode; 88 89 static final String pluginDir = Main.pref.getPluginsDirectory().getAbsolutePath() + "/CommandLine/"; 90 91 @SuppressWarnings("serial") 92 public CommandLine(PluginInformation info) { 93 super(info); 94 commandSymbol = ": "; 95 history = new History(100); 96 historyField = new DisableShortcutsOnFocusGainedTextField(); 97 textField = new DisableShortcutsOnFocusGainedTextField() { 98 @Override 99 protected void processKeyEvent(KeyEvent e) { 100 if (e.getID() == KeyEvent.KEY_PRESSED) { 101 int code = e.getKeyCode(); 102 if (code == KeyEvent.VK_ENTER) { 103 String commandText = textField.getText().substring(prefix.length()); 104 switch (mode) { 105 case IDLE: 106 if (commandText.isEmpty()) { 107 commandText = history.getLastItem(); 108 } else { 109 history.addItem(commandText); 110 } 111 Command command = findCommand(commandText, true); 112 if (command != null) { 113 startCommand(command); 114 } else { 115 setMode(Mode.IDLE); 116 } 117 break; 118 case SELECTION: 119 if (currentMapFrame.mapMode instanceof WayAction || currentMapFrame.mapMode instanceof NodeAction || currentMapFrame.mapMode instanceof RelationAction || currentMapFrame.mapMode instanceof AnyAction) { 120 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 121 if (selected.size() > 0) 122 loadParameter(selected, true); 123 } 124 else { 125 loadParameter(commandText, currentCommand.parameters.get(currentCommand.currentParameterNum).maxInstances == 1); 126 } 127 break; 128 case ADJUSTMENT: 129 break; 130 } 131 e.consume(); 132 } 133 else if (code == KeyEvent.VK_UP) { 134 textField.setText(prefix + history.getPrevItem()); 135 e.consume(); 136 } 137 else if (code == KeyEvent.VK_DOWN) { 138 textField.setText(prefix + history.getNextItem()); 139 e.consume(); 140 } 141 else if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) { 142 if (textField.getCaretPosition() <= prefix.length()) 143 e.consume(); 144 } 145 else if (code == KeyEvent.VK_HOME) { 146 setCaretPosition(prefix.length()); 147 e.consume(); 148 } 149 else if (code == KeyEvent.VK_ESCAPE) { 150 if (textField.getText().length() == prefix.length() && mode == Mode.IDLE) 151 deactivate(); 152 else 153 endInput(); 154 e.consume(); 155 } 156 else if (code == KeyEvent.VK_DELETE || code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_END) { 157 } 158 else { 159 e.consume(); 160 } 161 if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) 162 e.consume(); 163 } 164 if (e.getID() == KeyEvent.KEY_TYPED) 165 if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) 166 e.consume(); 167 super.processKeyEvent(e); 168 if (textField.getText().length() < prefix.length()) { // Safe 169 setMode(mode); 170 } 171 if (e.getID() == KeyEvent.KEY_TYPED) { 172 if (e.getKeyChar() > 'A' && e.getKeyChar() < 'z') { 173 Command command = findCommand(textField.getText().substring(prefix.length()), false); 174 if (command != null) { 175 int currentPos = textField.getSelectionStart() == 0 ? textField.getCaretPosition() : textField.getSelectionStart(); 176 textField.setText(prefix + command.name); 177 textField.setCaretPosition(currentPos); 178 textField.select(currentPos, prefix.length() + command.name.length()); 179 } 180 } 181 } 182 } 183 @Override 184 protected void processMouseEvent(MouseEvent e) { 185 super.processMouseEvent(e); 186 if (e.getButton() == MouseEvent.BUTTON1 && e.getID() == MouseEvent.MOUSE_RELEASED) { 187 if (textField.getSelectionStart() > 0 && textField.getSelectionStart() < prefix.length()) 188 textField.setSelectionStart(prefix.length()); 189 else if (textField.getCaretPosition() < prefix.length()) 190 textField.setCaretPosition(prefix.length()); 191 } 192 } 193 }; 194 195 if (Main.main.menu != null) { 196 commandMenu = Main.main.menu.addMenu("Commands", tr("Commands"), KeyEvent.VK_O, Main.main.menu.getDefaultMenuPos(), ht("/Plugin/CommandLine")); 197 MainMenu.add(commandMenu, new CommandLineAction(this)); 198 } 199 loadCommands(); 200 setMode(Mode.IDLE); 201 } 202 203 public void startCommand(String commandName) { 204 Command command = findCommand(commandName, true); 205 if (command != null) { 206 startCommand(command); 207 } 208 } 209 210 protected void startCommand(Command command) { 211 if (Main.map == null) 212 return; 213 DataSet ds = Main.main.getCurrentDataSet(); 214 if (ds == null) 215 return; 216 currentCommand = command; 217 currentCommand.resetLoading(); 218 parseSelection(ds.getSelected()); 219 if (!(Main.map.mapMode instanceof AnyAction || Main.map.mapMode instanceof DummyAction || Main.map.mapMode instanceof LengthAction || Main.map.mapMode instanceof NodeAction || Main.map.mapMode instanceof PointAction || Main.map.mapMode instanceof RelationAction || Main.map.mapMode instanceof WayAction)) { 220 previousMode = Main.map.mapMode; 221 } 222 if (currentCommand.currentParameterNum < currentCommand.parameters.size()) 223 setMode(Mode.SELECTION); 224 else 225 runTool(); 226 } 227 228 @Override 229 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 230 currentMapFrame = newFrame; 231 if (oldFrame == null && newFrame != null) { 232 JToolBar tb = new JToolBar(); 233 tb.setLayout(new BorderLayout()); 234 tb.setFloatable(false); 235 tb.setOrientation(JToolBar.HORIZONTAL); 236 tb.add(historyField, BorderLayout.NORTH); 237 tb.add(textField, BorderLayout.SOUTH); 238 currentMapFrame.add(tb, BorderLayout.NORTH); 239 printHistory("Loaded CommandLine, version " + getPluginInformation().version); 240 } 241 } 242 243 protected void printHistory(final String text) { 244 SwingUtilities.invokeLater(new Runnable() { 245 @Override 246 public void run() { 247 historyField.setText(text); 248 } 249 }); 250 } 251 252 private void loadCommands() { 253 commands = (new Loader(getPluginDir())).load(); 254 if (commands.isEmpty()) { 255 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Main.parent, 256 tr("No command has been found. Would you like to download and install default commands now?"), 257 tr("No command found"), JOptionPane.YES_NO_CANCEL_OPTION)) { 258 try { 259 downloadAndInstallDefaultCommands(); 260 commands = (new Loader(getPluginDir())).load(); 261 JOptionPane.showMessageDialog(Main.parent, tr("Default commands have been successfully installed"), 262 tr("Success"), JOptionPane.INFORMATION_MESSAGE); 263 } catch (IOException e) { 264 Main.warn(e); 265 JOptionPane.showMessageDialog(Main.parent, 266 tr("Failed to download and install default commands.\n\nError: {0}", e.getMessage()), 267 tr("Warning"), JOptionPane.WARNING_MESSAGE); 268 } 269 } 270 } 271 for (Command command : commands) { 272 commandMenu.add(new CommandAction(command, this)); 273 } 274 } 275 276 private void downloadAndInstallDefaultCommands() throws IOException { 277 String url = Main.pref.get("commandline.default.commands.url", 278 "https://github.com/Foxhind/JOSM-CommandLine-commands/archive/master.zip"); 279 try (ZipInputStream zis = new ZipInputStream(Utils.openURL(new URL(url)), StandardCharsets.UTF_8)) { 280 File dir = new File(getPluginDir()); 281 if (!dir.exists()) { 282 dir.mkdirs(); 283 } 284 ZipEntry entry = null; 285 while ( (entry = zis.getNextEntry()) != null ) { 286 if (!entry.isDirectory()) { 287 String name = entry.getName(); 288 if (name.contains("/")) { 289 name = name.substring(name.lastIndexOf("/")); 290 } 291 File file = new File(dir + File.separator + name); 292 Main.info("Installing command file: "+file); 293 if (!file.createNewFile()) { 294 throw new IOException("Could not create file: " + file.getAbsolutePath()); 295 } 296 // Write file 297 try (FileOutputStream fos = new FileOutputStream(file)) { 298 Utils.copyStream(zis, fos); 299 } 300 // Set last modification date 301 long time = entry.getTime(); 302 if (time > -1) { 303 file.setLastModified(time); 304 } 305 } 306 } 307 } 308 } 309 310 private Command findCommand(String text, boolean strict) { 311 for (int i = 0; i < commands.size(); i++) { 312 if (strict) { 313 if ( commands.get(i).name.equalsIgnoreCase(text) ) { 314 return commands.get(i); 315 } 316 } else if ( commands.get(i).name.toLowerCase().startsWith( text.toLowerCase() ) && text.length() > 1 ) { 317 return commands.get(i); 318 } 319 } 320 return null; 321 } 322 323 protected void setMode(Mode targetMode) { 324 DataSet currentDataSet = Main.main.getCurrentDataSet(); 325 if (currentDataSet != null) { 326 currentDataSet.clearSelection(); 327 Main.map.mapView.repaint(); 328 } 329 if (targetMode == Mode.IDLE) { 330 mode = Mode.IDLE; 331 currentCommand = null; 332 prefix = tr("Command") + commandSymbol; 333 textField.setText(prefix); 334 } 335 else if (targetMode == Mode.SELECTION) { 336 mode = Mode.SELECTION; 337 Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum); 338 prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description); 339 if (currentParameter.getRawValue() instanceof Relay) 340 prefix = prefix + " (" + ((Relay)(currentParameter.getRawValue())).getOptionsString() + ")"; 341 prefix += commandSymbol; 342 String value = currentParameter.getValue(); 343 textField.setText(prefix + value); 344 Type currentType = currentParameter.type; 345 MapMode action = null; 346 switch (currentType) { 347 case POINT: 348 action = new PointAction(currentMapFrame, this); 349 break; 350 case WAY: 351 action = new WayAction(currentMapFrame, this); 352 break; 353 case NODE: 354 action = new NodeAction(currentMapFrame, this); 355 break; 356 case RELATION: 357 action = new RelationAction(currentMapFrame, this); 358 break; 359 case ANY: 360 action = new AnyAction(currentMapFrame, this); 361 break; 362 case LENGTH: 363 action = new LengthAction(currentMapFrame, this); 364 break; 365 case USERNAME: 366 loadParameter(Main.pref.get("osm-server.username", null), true); 367 action = new DummyAction(currentMapFrame, this); 368 break; 369 case IMAGERYURL: 370 Layer layer = Main.map.mapView.getActiveLayer(); 371 if (layer != null) { 372 if (!(layer instanceof ImageryLayer)) { 373 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 374 if (imageryLayers.size() == 1) { 375 layer = imageryLayers.get(0); 376 } 377 else { 378 endInput(); 379 return; 380 } 381 } 382 } 383 ImageryInfo info = ((ImageryLayer)layer).getInfo(); 384 String url = info.getUrl(); 385 String itype = info.getImageryType().getTypeString(); 386 loadParameter((url.equals("") ? itype : url), true); 387 action = new DummyAction(currentMapFrame, this); 388 break; 389 case IMAGERYOFFSET: 390 Layer olayer = Main.map.mapView.getActiveLayer(); 391 if (olayer != null) { 392 if (!(olayer instanceof ImageryLayer)) { 393 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 394 if (imageryLayers.size() == 1) { 395 olayer = imageryLayers.get(0); 396 } 397 else { 398 endInput(); 399 return; 400 } 401 } 402 } 403 loadParameter((String.valueOf(((ImageryLayer)olayer).getDx()) + "," + String.valueOf(((ImageryLayer)olayer).getDy())), true); 404 action = new DummyAction(currentMapFrame, this); 405 break; 406 default: 407 action = new DummyAction(currentMapFrame, this); 408 break; 409 } 410 currentMapFrame.selectMapMode(action); 411 activate(); 412 textField.select(prefix.length(), textField.getText().length()); 413 } 414 else if (targetMode == Mode.PROCESSING) { 415 mode = Mode.PROCESSING; 416 prefix = tr("Processing..."); 417 textField.setText(prefix); 418 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 419 } 420 } 421 422 public void activate() { 423 textField.requestFocus(); 424 textField.setCaretPosition(textField.getText().length()); 425 } 426 427 public void deactivate() { 428 Main.map.mapView.requestFocus(); 429 } 430 431 public void abortInput() { 432 printHistory(tr("Aborted") + "."); 433 endInput(); 434 } 435 436 public void endInput() { 437 setMode(Mode.IDLE); 438 Main.map.selectMapMode(previousMode); 439 Main.map.mapView.repaint(); 440 } 441 442 public void loadParameter(Object obj, boolean next) { 443 if (currentCommand.loadObject(obj)) { 444 if (currentCommand.hasNextParameter()) { 445 if (next) { 446 Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum); 447 String prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description); 448 prefix += commandSymbol; 449 String value = currentParameter.getValue(); 450 printHistory(prefix + value); 451 currentCommand.nextParameter(); 452 setMode(Mode.SELECTION); 453 } 454 } else { 455 runTool(); 456 } 457 } else { 458 Main.info("Invalid argument"); 459 endInput(); 460 } 461 } 462 463 private void parseSelection(Collection<OsmPrimitive> selection) { 464 boolean ok = false; 465 for (OsmPrimitive obj : selection) { 466 ok = currentCommand.loadObject(obj); 467 if (!ok) 468 break; 469 } 470 if (ok) { 471 currentCommand.nextParameter(); 472 } else { 473 currentCommand.resetLoading(); 474 } 475 } 476 477 private class ToolProcess { 478 public Process process; 479 public volatile boolean running; 480 } 481 482 // Thanks to Upliner 483 public void runTool() { 484 setMode(Mode.PROCESSING); 485 String commandToRun = currentCommand.run; 486 final boolean tracks = currentCommand.tracks; 487 final ArrayList<Parameter> parameters = currentCommand.parameters; 488 489 for (Parameter parameter : currentCommand.parameters) { 490 commandToRun = commandToRun.replace("{" + parameter.name + "}", parameter.getValue()); 491 } 492 for (Parameter parameter : currentCommand.optParameters) { 493 commandToRun = commandToRun.replace("{" + parameter.name + "}", parameter.getValue()); 494 } 495 String[] listToRun = commandToRun.split(" "); 496 497 // create the process 498 final Object syncObj = new Object(); 499 500 ProcessBuilder builder; 501 builder = new ProcessBuilder(listToRun); 502 builder.directory(new File(getPluginDir())); 503 504 final StringBuilder debugstr = new StringBuilder(); 505 506 // debug: print resulting cmdline 507 for (String s : builder.command()) 508 debugstr.append(s + " "); 509 debugstr.append("\n"); 510 Main.info(debugstr.toString()); 511 512 final ToolProcess tp = new ToolProcess(); 513 try { 514 tp.process = builder.start(); 515 } catch (final IOException e) { 516 synchronized (debugstr) { 517 Main.error( 518 tr("Error executing the script: ") + 519 debugstr.toString() + e.getMessage() + "\n" + e.getStackTrace()); 520 } 521 return; 522 } 523 tp.running = true; 524 525 // redirect child process's stderr to JOSM stderr 526 new Thread(new Runnable() { 527 @Override 528 public void run() { 529 try { 530 byte[] buffer = new byte[1024]; 531 InputStream errStream = tp.process.getErrorStream(); 532 int len; 533 while ((len = errStream.read(buffer)) > 0) { 534 synchronized (debugstr) { 535 debugstr.append(new String(buffer, 0, len)); 536 } 537 System.err.write(buffer, 0, len); 538 } 539 } catch (IOException e) { 540 } 541 } 542 }).start(); 543 544 // Write stdin stream 545 Thread osmWriteThread = new Thread(new Runnable() { 546 @Override 547 public void run() { 548 BBox bbox = null; 549 final OutputStream outputStream = tp.process.getOutputStream(); 550 PrintWriter printWriter = null; 551 try { 552 printWriter = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); 553 } catch (Exception e) { 554 Main.error(e); 555 } 556 final OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(printWriter, true, null); 557 Collection<OsmPrimitive> refObjects = currentCommand.getDepsObjects(); 558 Collection<OsmPrimitive> pObjects; 559 osmWriter.header(); 560 Collection<OsmPrimitive> contents = new ArrayList<>(); 561 for (OsmPrimitive primitive : refObjects) { 562 contents.add(primitive); 563 if (bbox == null) 564 bbox = new BBox(primitive.getBBox()); 565 else 566 bbox.addPrimitive(primitive, 0.0); 567 } 568 osmWriter.writeNodes(new SubclassFilteredCollection<OsmPrimitive, Node>(contents, OsmPrimitive.nodePredicate)); 569 osmWriter.writeWays(new SubclassFilteredCollection<OsmPrimitive, Way>(contents, OsmPrimitive.wayPredicate)); 570 osmWriter.writeRelations(new SubclassFilteredCollection<OsmPrimitive, Relation>(contents, OsmPrimitive.relationPredicate)); 571 osmWriter.footer(); 572 osmWriter.flush(); 573 574 for (Parameter parameter : parameters) { 575 if (!parameter.isOsm()) 576 continue; 577 contents = new ArrayList<>(); 578 osmWriter.header(); 579 pObjects = parameter.getParameterObjects(); 580 for (OsmPrimitive primitive : pObjects) { 581 contents.add(primitive); 582 if (bbox == null) 583 bbox = new BBox(primitive.getBBox()); 584 else 585 bbox.addPrimitive(primitive, 0.0); 586 } 587 osmWriter.writeNodes(new SubclassFilteredCollection<OsmPrimitive, Node>(contents, OsmPrimitive.nodePredicate)); 588 osmWriter.writeWays(new SubclassFilteredCollection<OsmPrimitive, Way>(contents, OsmPrimitive.wayPredicate)); 589 osmWriter.writeRelations(new SubclassFilteredCollection<OsmPrimitive, Relation>(contents, OsmPrimitive.relationPredicate)); 590 osmWriter.footer(); 591 osmWriter.flush(); 592 } 593 594 if (tracks) { 595 try (GpxWriter gpxWriter = new GpxWriter(printWriter)) { 596 GpxFilter gpxFilter = new GpxFilter(); 597 gpxFilter.initBboxFilter(bbox); 598 List<GpxLayer> gpxLayers = Main.map.mapView.getLayersOfType(GpxLayer.class); 599 for (GpxLayer gpxLayer : gpxLayers) { 600 gpxFilter.addGpxData(gpxLayer.data); 601 } 602 gpxWriter.write(gpxFilter.getGpxData()); 603 } catch (IOException e) { 604 Main.warn(e); 605 } 606 } 607 Utils.close(osmWriter); 608 synchronized (syncObj) { 609 if (currentCommand.asynchronous) { 610 tp.running = false; 611 syncObj.notifyAll(); 612 } 613 } 614 } 615 }); 616 617 // Read stdout stream 618 final DataSet currentDataSet = Main.main.getCurrentDataSet(); 619 final CommandLine that = this; 620 Thread osmParseThread = new Thread(new Runnable() { 621 @Override 622 public void run() { 623 try { 624 final OsmToCmd osmToCmd = new OsmToCmd(that, currentDataSet); 625 String commandName = currentCommand.name; 626 final InputStream inputStream = tp.process.getInputStream(); 627 osmToCmd.parseStream(inputStream); 628 final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList(); 629 if (!cmdlist.isEmpty()) { 630 final SequenceCommand cmd = new SequenceCommand(commandName, cmdlist); 631 SwingUtilities.invokeLater(new Runnable() { 632 @Override 633 public void run() { 634 Main.main.undoRedo.add(cmd); 635 } 636 }); 637 } 638 } catch (Exception e) { 639 } 640 finally { 641 synchronized (syncObj) { 642 tp.running = false; 643 syncObj.notifyAll(); 644 } 645 } 646 } 647 648 }); 649 650 osmParseThread.start(); 651 osmWriteThread.start(); 652 653 synchronized (syncObj) { 654 try { 655 syncObj.wait(Main.pref.getInteger("commandline.timeout", 20000)); 656 } catch (InterruptedException e) { 657 } 658 } 659 if (tp.running) { 660 new Thread(new PleaseWaitRunnable(currentCommand.name) { 661 @Override 662 protected void realRun() { 663 try { 664 progressMonitor.indeterminateSubTask(null); 665 synchronized (syncObj) { 666 if (tp.running) 667 syncObj.wait(); 668 } 669 } catch (InterruptedException e) { 670 } 671 } 672 673 @Override 674 protected void cancel() { 675 synchronized (syncObj) { 676 tp.running = false; 677 tp.process.destroy(); 678 syncObj.notifyAll(); 679 endInput(); 680 } 681 } 682 683 @Override 684 protected void finish() { 685 } 686 }).start(); 687 } 688 endInput(); 689 } 691 690 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r30859 r31646 220 220 221 221 if (cadastreJMenu == null) { 222 cadastreJMenu = menu.addMenu( marktr("Cadastre"), KeyEvent.VK_C, menu.getDefaultMenuPos(), ht("/Plugin/CadastreFr"));222 cadastreJMenu = menu.addMenu("Cadastre", tr("Cadastre"), KeyEvent.VK_C, menu.getDefaultMenuPos(), ht("/Plugin/CadastreFr")); 223 223 JosmAction grab = new MenuActionGrab(); 224 224 JMenuItem menuGrab = new JMenuItem(grab); -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/CzechAddressPlugin.java
r30737 r31646 2 2 3 3 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 import static org.openstreetmap.josm.tools.I18n. marktr;4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.event.KeyEvent; … … 186 186 GuiHelper.runInEDTAndWait(new Runnable() { 187 187 @Override public void run() { 188 czechMenu = Main.main.menu.addMenu( marktr("Address"), KeyEvent.VK_Z, Main.main.menu.getDefaultMenuPos(), ht("/Plugin/CzechAddress"));188 czechMenu = Main.main.menu.addMenu("Address", tr("Address"), KeyEvent.VK_Z, Main.main.menu.getDefaultMenuPos(), ht("/Plugin/CzechAddress")); 189 189 menuItems.add(MainMenu.add(czechMenu, new PointManipulatorAction())); 190 190 menuItems.add(MainMenu.add(czechMenu, new GroupManipulatorAction())); -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetPlugin.java
r30738 r31646 1 1 package iodb; 2 2 3 import static org.openstreetmap.josm.tools.I18n. marktr;3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 5 import java.awt.event.KeyEvent; … … 41 41 int version = Version.getInstance().getVersion(); 42 42 JMenu offsetMenu = version < 5803 43 ? Main.main.menu.addMenu( marktr("Offset"), KeyEvent.VK_O, 6, "help")43 ? Main.main.menu.addMenu("Offset", tr("Offset"), KeyEvent.VK_O, 6, "help") 44 44 : Main.main.menu.imageryMenu; 45 45 offsetMenu.add(getAction); -
applications/editors/josm/plugins/public_transport/src/public_transport/PublicTransportPlugin.java
r29854 r31646 1 1 package public_transport; 2 2 3 import static org.openstreetmap.josm.tools.I18n. marktr;3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 5 import java.awt.event.KeyEvent; … … 28 28 29 29 if (jMenu == null) 30 jMenu = menu.addMenu( marktr("Public Transport"), KeyEvent.VK_COMMA, menu.getDefaultMenuPos(), "help");30 jMenu = menu.addMenu("Public Transport", tr("Public Transport"), KeyEvent.VK_COMMA, menu.getDefaultMenuPos(), "help"); 31 31 else 32 32 jMenu.removeAll(); -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java
r30361 r31646 29 29 30 30 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 31 import static org.openstreetmap.josm.tools.I18n.marktr;32 31 import static org.openstreetmap.josm.tools.I18n.tr; 33 32 … … 75 74 public RoutingMenu() { 76 75 MainMenu mm = Main.main.menu; 77 menu = mm.addMenu( marktr("Routing"), KeyEvent.VK_O, mm.getDefaultMenuPos(), ht("/Plugin/Routing"));76 menu = mm.addMenu("Routing", tr("Routing"), KeyEvent.VK_O, mm.getDefaultMenuPos(), ht("/Plugin/Routing")); 78 77 79 78 startMI = new JMenuItem(tr("Add routing layer")); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsMenu.java
r30738 r31646 3 3 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.marktr;6 5 import static org.openstreetmap.josm.tools.I18n.tr; 7 6 … … 39 38 public SdsMenu(final SeparateDataStorePlugin thePlugin) { 40 39 MainMenu mm = Main.main.menu; 41 menu = mm.addMenu( marktr("SDS"), KeyEvent.VK_S, mm.getDefaultMenuPos(), null);40 menu = mm.addMenu("SDS", tr("SDS"), KeyEvent.VK_S, mm.getDefaultMenuPos(), null); 42 41 saveItem = new JMenuItem(new SdsSaveAction()); 43 42 menu.add(saveItem); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/TrustOSMplugin.java
r30745 r31646 2 2 3 3 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 import static org.openstreetmap.josm.tools.I18n. marktr;4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.event.KeyEvent; … … 257 257 258 258 if (gpgJMenu == null) { 259 gpgJMenu = menu.addMenu( marktr("GPG"), KeyEvent.VK_B, menu.getDefaultMenuPos(), ht("/Plugin/TrustOSM"));259 gpgJMenu = menu.addMenu("GPG", tr("GPG"), KeyEvent.VK_B, menu.getDefaultMenuPos(), ht("/Plugin/TrustOSM")); 260 260 gpgJMenu.add(new JMenuItem(new ExportSigsAction())); 261 261 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPlugin.java
r30639 r31646 2 2 3 3 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 import static org.openstreetmap.josm.tools.I18n.marktr;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 … … 78 77 79 78 private void createMenusAndShortCuts() { 80 VMenu = Main.main.menu.addMenu( marktr("Video"), KeyEvent.VK_Q, Main.main.menu.getDefaultMenuPos(),ht("/Plugin/Videomapping"));79 VMenu = Main.main.menu.addMenu("Video", tr("Video"), KeyEvent.VK_Q, Main.main.menu.getDefaultMenuPos(),ht("/Plugin/Videomapping")); 81 80 VMenu.setEnabled(false); 82 81 VAdd= new JosmAction(tr("Import Video"),"videomapping",tr("Sync a video against this GPS track"),null,false) {
Note:
See TracChangeset
for help on using the changeset viewer.