| 84 | | public CommandLine(PluginInformation info) { |
| 85 | | super(info); |
| 86 | | commandSymbol = ": "; |
| 87 | | history = new History(100); |
| 88 | | historyField = new JTextField(); |
| 89 | | textField = new JTextField() { |
| 90 | | @Override |
| 91 | | protected void processKeyEvent(KeyEvent e) { |
| 92 | | if (e.getID() == KeyEvent.KEY_PRESSED) { |
| 93 | | String text = textField.getText(); |
| 94 | | int code = e.getKeyCode(); |
| 95 | | if (code == KeyEvent.VK_ENTER) { |
| 96 | | String commandText = textField.getText().substring(prefix.length()); |
| 97 | | switch (mode) { |
| 98 | | case IDLE: |
| 99 | | if (commandText.isEmpty()) { |
| 100 | | commandText = history.getLastItem(); |
| 101 | | } |
| 102 | | else { |
| 103 | | history.addItem(commandText); |
| 104 | | } |
| 105 | | Command command = findCommand(commandText, true); |
| 106 | | if (command != null) { |
| 107 | | startCommand(command); |
| 108 | | } |
| 109 | | else |
| 110 | | setMode(Mode.IDLE); |
| 111 | | break; |
| 112 | | case SELECTION: |
| 113 | | if (currentMapFrame.mapMode instanceof WayAction || currentMapFrame.mapMode instanceof NodeAction || currentMapFrame.mapMode instanceof RelationAction || currentMapFrame.mapMode instanceof AnyAction) { |
| 114 | | Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); |
| 115 | | if (selected.size() > 0) |
| 116 | | loadParameter(selected, true); |
| 117 | | } |
| 118 | | else { |
| 119 | | loadParameter(commandText, currentCommand.parameters.get(currentCommand.currentParameterNum).maxInstances == 1); |
| 120 | | } |
| 121 | | break; |
| 122 | | case ADJUSTMENT: |
| 123 | | break; |
| 124 | | } |
| 125 | | e.consume(); |
| 126 | | } |
| 127 | | else if (code == KeyEvent.VK_UP) { |
| 128 | | textField.setText(prefix + history.getPrevItem()); |
| 129 | | e.consume(); |
| 130 | | } |
| 131 | | else if (code == KeyEvent.VK_DOWN) { |
| 132 | | textField.setText(prefix + history.getNextItem()); |
| 133 | | e.consume(); |
| 134 | | } |
| 135 | | else if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) { |
| 136 | | if (textField.getCaretPosition() <= prefix.length()) |
| 137 | | e.consume(); |
| 138 | | } |
| 139 | | else if (code == KeyEvent.VK_HOME) { |
| 140 | | setCaretPosition(prefix.length()); |
| 141 | | e.consume(); |
| 142 | | } |
| 143 | | else if (code == KeyEvent.VK_ESCAPE) { |
| 144 | | if (textField.getText().length() == prefix.length() && mode == Mode.IDLE) |
| 145 | | deactivate(); |
| 146 | | else |
| 147 | | endInput(); |
| 148 | | e.consume(); |
| 149 | | } |
| 150 | | else if (code == KeyEvent.VK_DELETE || code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_END) { |
| 151 | | } |
| 152 | | else { |
| 153 | | e.consume(); |
| 154 | | } |
| 155 | | if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) |
| 156 | | e.consume(); |
| 157 | | } |
| 158 | | if (e.getID() == KeyEvent.KEY_TYPED) |
| 159 | | if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) |
| 160 | | e.consume(); |
| 161 | | super.processKeyEvent(e); |
| 162 | | if (textField.getText().length() < prefix.length()) { // Safe |
| 163 | | setMode(mode); |
| 164 | | } |
| 165 | | if (e.getID() == KeyEvent.KEY_TYPED) { |
| 166 | | if (e.getKeyChar() > 'A' && e.getKeyChar() < 'z') { |
| 167 | | Command command = findCommand(textField.getText().substring(prefix.length()), false); |
| 168 | | if (command != null) { |
| 169 | | int currentPos = textField.getSelectionStart() == 0 ? textField.getCaretPosition() : textField.getSelectionStart(); |
| 170 | | textField.setText(prefix + command.name); |
| 171 | | textField.setCaretPosition(currentPos); |
| 172 | | textField.select(currentPos, prefix.length() + command.name.length()); |
| 173 | | } |
| 174 | | } |
| 175 | | } |
| 176 | | } |
| 177 | | @Override |
| 178 | | protected void processMouseEvent(MouseEvent e) { |
| 179 | | super.processMouseEvent(e); |
| 180 | | if (e.getButton() == MouseEvent.BUTTON1 && e.getID() == MouseEvent.MOUSE_RELEASED) { |
| 181 | | if (textField.getSelectionStart() > 0 && textField.getSelectionStart() < prefix.length()) |
| 182 | | textField.setSelectionStart(prefix.length()); |
| 183 | | else if (textField.getCaretPosition() < prefix.length()) |
| 184 | | textField.setCaretPosition(prefix.length()); |
| 185 | | } |
| 186 | | } |
| 187 | | }; |
| | 80 | @SuppressWarnings("serial") |
| | 81 | public CommandLine(PluginInformation info) { |
| | 82 | super(info); |
| | 83 | commandSymbol = ": "; |
| | 84 | history = new History(100); |
| | 85 | historyField = new JTextField(); |
| | 86 | textField = new JTextField() { |
| | 87 | @Override |
| | 88 | protected void processKeyEvent(KeyEvent e) { |
| | 89 | if (e.getID() == KeyEvent.KEY_PRESSED) { |
| | 90 | //String text = textField.getText(); |
| | 91 | int code = e.getKeyCode(); |
| | 92 | if (code == KeyEvent.VK_ENTER) { |
| | 93 | String commandText = textField.getText().substring(prefix.length()); |
| | 94 | switch (mode) { |
| | 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; |
| | 121 | } |
| | 122 | e.consume(); |
| | 123 | } |
| | 124 | else if (code == KeyEvent.VK_UP) { |
| | 125 | textField.setText(prefix + history.getPrevItem()); |
| | 126 | e.consume(); |
| | 127 | } |
| | 128 | else if (code == KeyEvent.VK_DOWN) { |
| | 129 | textField.setText(prefix + history.getNextItem()); |
| | 130 | e.consume(); |
| | 131 | } |
| | 132 | else if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) { |
| | 133 | if (textField.getCaretPosition() <= prefix.length()) |
| | 134 | e.consume(); |
| | 135 | } |
| | 136 | else if (code == KeyEvent.VK_HOME) { |
| | 137 | setCaretPosition(prefix.length()); |
| | 138 | e.consume(); |
| | 139 | } |
| | 140 | else if (code == KeyEvent.VK_ESCAPE) { |
| | 141 | if (textField.getText().length() == prefix.length() && mode == Mode.IDLE) |
| | 142 | deactivate(); |
| | 143 | else |
| | 144 | endInput(); |
| | 145 | e.consume(); |
| | 146 | } |
| | 147 | else if (code == KeyEvent.VK_DELETE || code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_END) { |
| | 148 | } |
| | 149 | else { |
| | 150 | e.consume(); |
| | 151 | } |
| | 152 | if (textField.getCaretPosition() < prefix.length() || (textField.getSelectionStart() < prefix.length() && textField.getSelectionStart() > 0) ) |
| | 153 | e.consume(); |
| | 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); |
| | 161 | } |
| | 162 | if (e.getID() == KeyEvent.KEY_TYPED) { |
| | 163 | if (e.getKeyChar() > 'A' && e.getKeyChar() < 'z') { |
| | 164 | Command command = findCommand(textField.getText().substring(prefix.length()), false); |
| | 165 | if (command != null) { |
| | 166 | int currentPos = textField.getSelectionStart() == 0 ? textField.getCaretPosition() : textField.getSelectionStart(); |
| | 167 | textField.setText(prefix + command.name); |
| | 168 | textField.setCaretPosition(currentPos); |
| | 169 | textField.select(currentPos, prefix.length() + command.name.length()); |
| | 170 | } |
| | 171 | } |
| | 172 | } |
| | 173 | } |
| | 174 | @Override |
| | 175 | protected void processMouseEvent(MouseEvent e) { |
| | 176 | super.processMouseEvent(e); |
| | 177 | if (e.getButton() == MouseEvent.BUTTON1 && e.getID() == MouseEvent.MOUSE_RELEASED) { |
| | 178 | if (textField.getSelectionStart() > 0 && textField.getSelectionStart() < prefix.length()) |
| | 179 | textField.setSelectionStart(prefix.length()); |
| | 180 | else if (textField.getCaretPosition() < prefix.length()) |
| | 181 | textField.setCaretPosition(prefix.length()); |
| | 182 | } |
| | 183 | } |
| | 184 | }; |
| 222 | | @Override |
| 223 | | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) |
| 224 | | { |
| 225 | | currentMapFrame = newFrame; |
| 226 | | if (oldFrame == null && newFrame != null) { |
| 227 | | JToolBar tb = new JToolBar(); |
| 228 | | tb.setLayout(new BorderLayout()); |
| 229 | | tb.setFloatable(false); |
| 230 | | tb.setOrientation(JToolBar.HORIZONTAL); |
| 231 | | tb.add(historyField, BorderLayout.NORTH); |
| 232 | | tb.add(textField, BorderLayout.SOUTH); |
| 233 | | currentMapFrame.add(tb, BorderLayout.NORTH); |
| 234 | | printHistory("Loaded CommandLine, version " + getPluginInformation().version); |
| 235 | | } |
| 236 | | } |
| | 219 | @Override |
| | 220 | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) |
| | 221 | { |
| | 222 | currentMapFrame = newFrame; |
| | 223 | if (oldFrame == null && newFrame != null) { |
| | 224 | JToolBar tb = new JToolBar(); |
| | 225 | tb.setLayout(new BorderLayout()); |
| | 226 | tb.setFloatable(false); |
| | 227 | tb.setOrientation(JToolBar.HORIZONTAL); |
| | 228 | tb.add(historyField, BorderLayout.NORTH); |
| | 229 | tb.add(textField, BorderLayout.SOUTH); |
| | 230 | currentMapFrame.add(tb, BorderLayout.NORTH); |
| | 231 | printHistory("Loaded CommandLine, version " + getPluginInformation().version); |
| | 232 | } |
| | 233 | } |
| 265 | | protected void setMode(Mode targetMode) { |
| 266 | | DataSet currentDataSet = Main.main.getCurrentDataSet(); |
| 267 | | if (currentDataSet != null) { |
| 268 | | currentDataSet.clearSelection(); |
| 269 | | Main.map.mapView.repaint(); |
| 270 | | } |
| 271 | | if (targetMode == Mode.IDLE) { |
| 272 | | mode = Mode.IDLE; |
| 273 | | currentCommand = null; |
| 274 | | prefix = tr("Command") + commandSymbol; |
| 275 | | textField.setText(prefix); |
| 276 | | } |
| 277 | | else if (targetMode == Mode.SELECTION) { |
| 278 | | mode = Mode.SELECTION; |
| 279 | | Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum); |
| 280 | | prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description); |
| 281 | | if (currentParameter.getRawValue() instanceof Relay) |
| 282 | | prefix = prefix + " (" + ((Relay)(currentParameter.getRawValue())).getOptionsString() + ")"; |
| 283 | | prefix += commandSymbol; |
| 284 | | String value = currentParameter.getValue(); |
| 285 | | textField.setText(prefix + value); |
| 286 | | Type currentType = currentParameter.type; |
| 287 | | MapMode action = null; |
| 288 | | switch (currentType) { |
| 289 | | case POINT: |
| 290 | | action = new PointAction(currentMapFrame, this); |
| 291 | | break; |
| 292 | | case WAY: |
| 293 | | action = new WayAction(currentMapFrame, this); |
| 294 | | break; |
| 295 | | case NODE: |
| 296 | | action = new NodeAction(currentMapFrame, this); |
| 297 | | break; |
| 298 | | case RELATION: |
| 299 | | action = new RelationAction(currentMapFrame, this); |
| 300 | | break; |
| 301 | | case ANY: |
| 302 | | action = new AnyAction(currentMapFrame, this); |
| 303 | | break; |
| 304 | | case LENGTH: |
| 305 | | action = new LengthAction(currentMapFrame, this); |
| 306 | | break; |
| 307 | | case USERNAME: |
| 308 | | loadParameter(Main.pref.get("osm-server.username", null), true); |
| 309 | | action = new DummyAction(currentMapFrame, this); |
| 310 | | break; |
| 311 | | case IMAGERYURL: |
| 312 | | Layer layer = Main.map.mapView.getActiveLayer(); |
| 313 | | if (layer != null) { |
| 314 | | if (layer instanceof ImageryLayer) { |
| 315 | | } |
| 316 | | else { |
| 317 | | List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); |
| 318 | | if (imageryLayers.size() == 1) { |
| 319 | | layer = imageryLayers.get(0); |
| 320 | | } |
| 321 | | else { |
| 322 | | endInput(); |
| 323 | | return; |
| 324 | | } |
| 325 | | } |
| 326 | | } |
| 327 | | ImageryInfo info = ((ImageryLayer)layer).getInfo(); |
| 328 | | String url = info.getUrl(); |
| 329 | | String itype = info.getImageryType().getUrlString(); |
| 330 | | loadParameter((url.equals("") ? itype : url), true); |
| 331 | | action = new DummyAction(currentMapFrame, this); |
| 332 | | break; |
| 333 | | case IMAGERYOFFSET: |
| 334 | | Layer olayer = Main.map.mapView.getActiveLayer(); |
| 335 | | if (olayer != null) { |
| 336 | | if (olayer instanceof ImageryLayer) { |
| 337 | | } |
| 338 | | else { |
| 339 | | List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); |
| 340 | | if (imageryLayers.size() == 1) { |
| 341 | | olayer = imageryLayers.get(0); |
| 342 | | } |
| 343 | | else { |
| 344 | | endInput(); |
| 345 | | return; |
| 346 | | } |
| 347 | | } |
| 348 | | } |
| 349 | | loadParameter((String.valueOf(((ImageryLayer)olayer).getDx()) + "," + String.valueOf(((ImageryLayer)olayer).getDy())), true); |
| 350 | | action = new DummyAction(currentMapFrame, this); |
| 351 | | break; |
| 352 | | default: |
| 353 | | action = new DummyAction(currentMapFrame, this); |
| 354 | | break; |
| 355 | | } |
| 356 | | currentMapFrame.selectMapMode(action); |
| 357 | | activate(); |
| 358 | | textField.select(prefix.length(), textField.getText().length()); |
| 359 | | } |
| 360 | | else if (targetMode == Mode.PROCESSING) { |
| 361 | | mode = Mode.PROCESSING; |
| 362 | | prefix = tr("Processing..."); |
| 363 | | textField.setText(prefix); |
| 364 | | Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
| 365 | | } |
| 366 | | } |
| | 262 | protected void setMode(Mode targetMode) { |
| | 263 | DataSet currentDataSet = Main.main.getCurrentDataSet(); |
| | 264 | if (currentDataSet != null) { |
| | 265 | currentDataSet.clearSelection(); |
| | 266 | Main.map.mapView.repaint(); |
| | 267 | } |
| | 268 | if (targetMode == Mode.IDLE) { |
| | 269 | mode = Mode.IDLE; |
| | 270 | currentCommand = null; |
| | 271 | prefix = tr("Command") + commandSymbol; |
| | 272 | textField.setText(prefix); |
| | 273 | } |
| | 274 | else if (targetMode == Mode.SELECTION) { |
| | 275 | mode = Mode.SELECTION; |
| | 276 | Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum); |
| | 277 | prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description); |
| | 278 | if (currentParameter.getRawValue() instanceof Relay) |
| | 279 | prefix = prefix + " (" + ((Relay)(currentParameter.getRawValue())).getOptionsString() + ")"; |
| | 280 | prefix += commandSymbol; |
| | 281 | String value = currentParameter.getValue(); |
| | 282 | textField.setText(prefix + value); |
| | 283 | Type currentType = currentParameter.type; |
| | 284 | MapMode action = null; |
| | 285 | switch (currentType) { |
| | 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); |
| | 317 | } |
| | 318 | else { |
| | 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); |
| | 339 | } |
| | 340 | else { |
| | 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; |
| | 352 | } |
| | 353 | currentMapFrame.selectMapMode(action); |
| | 354 | activate(); |
| | 355 | textField.select(prefix.length(), textField.getText().length()); |
| | 356 | } |
| | 357 | else if (targetMode == Mode.PROCESSING) { |
| | 358 | mode = Mode.PROCESSING; |
| | 359 | prefix = tr("Processing..."); |
| | 360 | textField.setText(prefix); |
| | 361 | Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
| | 362 | } |
| | 363 | } |
| 495 | | // Write stdin stream |
| 496 | | Thread osmWriteThread = new Thread(new Runnable() { |
| 497 | | @Override |
| 498 | | public void run() { |
| 499 | | BBox bbox = null; |
| 500 | | final OutputStream outputStream = tp.process.getOutputStream(); |
| 501 | | PrintWriter printWriter = null; |
| 502 | | try { printWriter = new PrintWriter(new OutputStreamWriter(outputStream, "utf-8")); } |
| 503 | | catch (Exception e) {e.printStackTrace();} |
| 504 | | final OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(printWriter, true, null); |
| 505 | | Collection<OsmPrimitive> refObjects = currentCommand.getDepsObjects(); |
| 506 | | Collection<OsmPrimitive> pObjects; |
| 507 | | osmWriter.header(); |
| 508 | | for (OsmPrimitive primitive : refObjects) { |
| 509 | | if (primitive instanceof Node) |
| 510 | | osmWriter.visit((Node)primitive); |
| 511 | | else if (primitive instanceof Way) |
| 512 | | osmWriter.visit((Way)primitive); |
| 513 | | else if (primitive instanceof Relation) |
| 514 | | osmWriter.visit((Relation)primitive); |
| 515 | | if (bbox == null) |
| 516 | | bbox = new BBox(primitive.getBBox()); |
| 517 | | else |
| 518 | | bbox.addPrimitive(primitive, 0.0); |
| 519 | | } |
| 520 | | osmWriter.footer(); |
| 521 | | osmWriter.flush(); |
| 522 | | for (Parameter parameter : parameters) { |
| 523 | | if (!parameter.isOsm()) |
| 524 | | continue; |
| 525 | | osmWriter.header(); |
| 526 | | pObjects = parameter.getParameterObjects(); |
| 527 | | for (OsmPrimitive primitive : pObjects) { |
| 528 | | if (primitive instanceof Node) |
| 529 | | osmWriter.visit((Node)primitive); |
| 530 | | else if (primitive instanceof Way) |
| 531 | | osmWriter.visit((Way)primitive); |
| 532 | | else if (primitive instanceof Relation) |
| 533 | | osmWriter.visit((Relation)primitive); |
| 534 | | if (bbox == null) |
| 535 | | bbox = new BBox(primitive.getBBox()); |
| 536 | | else |
| 537 | | bbox.addPrimitive(primitive, 0.0); |
| 538 | | } |
| 539 | | osmWriter.footer(); |
| 540 | | osmWriter.flush(); |
| 541 | | } |
| 542 | | if (tracks) { |
| 543 | | final GpxWriter gpxWriter = new GpxWriter(printWriter); |
| 544 | | GpxFilter gpxFilter = new GpxFilter(); |
| 545 | | gpxFilter.initBboxFilter(bbox); |
| 546 | | List<GpxLayer> gpxLayers = Main.map.mapView.getLayersOfType(GpxLayer.class); |
| 547 | | for (GpxLayer gpxLayer : gpxLayers) { |
| 548 | | gpxFilter.addGpxData(gpxLayer.data); |
| 549 | | } |
| 550 | | gpxWriter.write(gpxFilter.getGpxData()); |
| 551 | | } |
| 552 | | osmWriter.close(); |
| 553 | | synchronized (syncObj) { |
| 554 | | tp.running = false; |
| 555 | | syncObj.notifyAll(); |
| 556 | | } |
| 557 | | } |
| | 492 | // Write stdin stream |
| | 493 | Thread osmWriteThread = new Thread(new Runnable() { |
| | 494 | @Override |
| | 495 | public void run() { |
| | 496 | BBox bbox = null; |
| | 497 | final OutputStream outputStream = tp.process.getOutputStream(); |
| | 498 | PrintWriter printWriter = null; |
| | 499 | try { printWriter = new PrintWriter(new OutputStreamWriter(outputStream, "utf-8")); } |
| | 500 | catch (Exception e) {e.printStackTrace();} |
| | 501 | final OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(printWriter, true, null); |
| | 502 | Collection<OsmPrimitive> refObjects = currentCommand.getDepsObjects(); |
| | 503 | Collection<OsmPrimitive> pObjects; |
| | 504 | osmWriter.header(); |
| | 505 | DataSet ds = new DataSet(); |
| | 506 | for (OsmPrimitive primitive : refObjects) { |
| | 507 | ds.addPrimitive(primitive); |
| | 508 | if (bbox == null) |
| | 509 | bbox = new BBox(primitive.getBBox()); |
| | 510 | else |
| | 511 | bbox.addPrimitive(primitive, 0.0); |
| | 512 | } |
| | 513 | for (Parameter parameter : parameters) { |
| | 514 | if (!parameter.isOsm()) |
| | 515 | continue; |
| | 516 | pObjects = parameter.getParameterObjects(); |
| | 517 | for (OsmPrimitive primitive : pObjects) { |
| | 518 | ds.addPrimitive(primitive); |
| | 519 | if (bbox == null) |
| | 520 | bbox = new BBox(primitive.getBBox()); |
| | 521 | else |
| | 522 | bbox.addPrimitive(primitive, 0.0); |
| | 523 | } |
| | 524 | } |
| | 525 | osmWriter.writeContent(ds); |
| | 526 | osmWriter.footer(); |
| | 527 | osmWriter.flush(); |
| | 528 | if (tracks) { |
| | 529 | final GpxWriter gpxWriter = new GpxWriter(printWriter); |
| | 530 | GpxFilter gpxFilter = new GpxFilter(); |
| | 531 | gpxFilter.initBboxFilter(bbox); |
| | 532 | List<GpxLayer> gpxLayers = Main.map.mapView.getLayersOfType(GpxLayer.class); |
| | 533 | for (GpxLayer gpxLayer : gpxLayers) { |
| | 534 | gpxFilter.addGpxData(gpxLayer.data); |
| | 535 | } |
| | 536 | gpxWriter.write(gpxFilter.getGpxData()); |
| | 537 | } |
| | 538 | osmWriter.close(); |
| | 539 | synchronized (syncObj) { |
| | 540 | tp.running = false; |
| | 541 | syncObj.notifyAll(); |
| | 542 | } |
| | 543 | } |
| 561 | | // Read stdout stream |
| 562 | | final OsmToCmd osmToCmd = new OsmToCmd(this, Main.main.getCurrentDataSet()); |
| 563 | | Thread osmParseThread = new Thread(new Runnable() { |
| 564 | | @Override |
| 565 | | public void run() { |
| 566 | | try { |
| 567 | | String commandName = currentCommand.name; |
| 568 | | HashMap<Long, Long> inexiDMap = new HashMap<Long, Long>(); |
| 569 | | final InputStream inputStream = tp.process.getInputStream(); |
| 570 | | osmToCmd.parseStream(inputStream); |
| 571 | | final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList(); |
| 572 | | if (!cmdlist.isEmpty()) { |
| 573 | | SequenceCommand cmd = new SequenceCommand(commandName, cmdlist); |
| 574 | | Main.main.undoRedo.add(cmd); |
| 575 | | } |
| 576 | | } |
| 577 | | catch (Exception e) {} |
| 578 | | finally { |
| 579 | | synchronized (syncObj) { |
| 580 | | tp.running = false; |
| 581 | | syncObj.notifyAll(); |
| 582 | | } |
| 583 | | } |
| 584 | | } |
| | 547 | // Read stdout stream |
| | 548 | final OsmToCmd osmToCmd = new OsmToCmd(this, Main.main.getCurrentDataSet()); |
| | 549 | Thread osmParseThread = new Thread(new Runnable() { |
| | 550 | @Override |
| | 551 | public void run() { |
| | 552 | try { |
| | 553 | String commandName = currentCommand.name; |
| | 554 | //HashMap<Long, Long> inexiDMap = new HashMap<Long, Long>(); |
| | 555 | final InputStream inputStream = tp.process.getInputStream(); |
| | 556 | osmToCmd.parseStream(inputStream); |
| | 557 | final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList(); |
| | 558 | if (!cmdlist.isEmpty()) { |
| | 559 | SequenceCommand cmd = new SequenceCommand(commandName, cmdlist); |
| | 560 | Main.main.undoRedo.add(cmd); |
| | 561 | } |
| | 562 | } |
| | 563 | catch (Exception e) {} |
| | 564 | finally { |
| | 565 | synchronized (syncObj) { |
| | 566 | tp.running = false; |
| | 567 | syncObj.notifyAll(); |
| | 568 | } |
| | 569 | } |
| | 570 | } |