Changeset 32398 in osm for applications/editors/josm/plugins/reltoolbox
- Timestamp:
- 2016-06-25T11:56:57+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/reltoolbox/src/relcontext
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/ChosenRelation.java
r32395 r32398 69 69 70 70 public boolean isSame(Object r) { 71 if (r == null 71 if (r == null) 72 72 return chosenRelation == null; 73 else if (!(r instanceof Relation) 73 else if (!(r instanceof Relation)) 74 74 return false; 75 75 else … … 89 89 90 90 public static boolean isMultipolygon(Relation r) { 91 if (r == null 91 if (r == null) 92 92 return false; 93 93 String type = r.get("type"); 94 if (type == null 94 if (type == null) 95 95 return false; 96 for (String t : MULTIPOLYGON_TYPES )97 if (t.equals(type) 96 for (String t : MULTIPOLYGON_TYPES) { 97 if (t.equals(type)) 98 98 return true; 99 } 99 100 return false; 100 101 } … … 138 139 return; 139 140 140 OsmDataLayer dataLayer = mv.get EditLayer();141 float opacity = dataLayer == null ? 0.0f : !dataLayer.isVisible() ? 0.0f : (float) dataLayer.getOpacity();142 if (opacity < 0.01 141 OsmDataLayer dataLayer = mv.getLayerManager().getEditLayer(); 142 float opacity = dataLayer == null ? 0.0f : !dataLayer.isVisible() ? 0.0f : (float) dataLayer.getOpacity(); 143 if (opacity < 0.01) 143 144 return; 144 145 … … 153 154 g.setComposite(oldComposite); 154 155 g.setStroke(oldStroke); 155 156 156 } 157 157 … … 159 159 for (OsmPrimitive element : rel.getMemberPrimitives()) { 160 160 if (element.getType() == OsmPrimitiveType.NODE) { 161 Node node = (Node) element;161 Node node = (Node) element; 162 162 Point center = mv.getPoint(node); 163 163 g.drawOval(center.x - 4, center.y - 4, 9, 9); 164 164 } else if (element.getType() == OsmPrimitiveType.WAY) { 165 Way way = (Way) element;165 Way way = (Way) element; 166 166 if (way.getNodesCount() >= 2) { 167 167 GeneralPath b = new GeneralPath(); … … 177 177 Color oldColor = g.getColor(); 178 178 g.setColor(Color.magenta); 179 drawRelations(g, mv, bbox, (Relation) element);179 drawRelations(g, mv, bbox, (Relation) element); 180 180 g.setColor(oldColor); 181 181 } … … 186 186 @Override 187 187 public void relationMembersChanged(RelationMembersChangedEvent event) { 188 if (chosenRelation != null && event.getRelation().equals(chosenRelation) 188 if (chosenRelation != null && event.getRelation().equals(chosenRelation)) { 189 189 fireRelationChanged(chosenRelation); 190 190 } … … 193 193 @Override 194 194 public void tagsChanged(TagsChangedEvent event) { 195 if (chosenRelation != null && event.getPrimitive().equals(chosenRelation) 195 if (chosenRelation != null && event.getPrimitive().equals(chosenRelation)) { 196 196 fireRelationChanged(chosenRelation); 197 197 } … … 200 200 @Override 201 201 public void dataChanged(DataChangedEvent event) { 202 if (chosenRelation != null 202 if (chosenRelation != null) { 203 203 fireRelationChanged(chosenRelation); 204 204 } … … 207 207 @Override 208 208 public void primitivesRemoved(PrimitivesRemovedEvent event) { 209 if (chosenRelation != null && event.getPrimitives().contains(chosenRelation) 209 if (chosenRelation != null && event.getPrimitives().contains(chosenRelation)) { 210 210 clear(); 211 211 } … … 214 214 @Override 215 215 public void wayNodesChanged(WayNodesChangedEvent event) { 216 if (chosenRelation != null ) 217 { 216 if (chosenRelation != null) { 218 217 fireRelationChanged(chosenRelation); // download incomplete primitives doesn't cause dataChanged event 219 218 } … … 222 221 @Override 223 222 public void primitivesAdded(PrimitivesAddedEvent event) {} 223 224 224 @Override 225 225 public void nodeMoved(NodeMovedEvent event) {} 226 226 227 @Override 227 228 public void otherDatasetChange(AbstractDatasetChangedEvent event) {} -
applications/editors/josm/plugins/reltoolbox/src/relcontext/ChosenRelationComponent.java
r32395 r32398 15 15 public class ChosenRelationComponent extends JLabel implements ChosenRelationListener { 16 16 17 //private ChosenRelation chRel;18 19 17 public ChosenRelationComponent(ChosenRelation rel) { 20 18 super(""); 21 /* setBackground(Color.white);22 setOpaque(true);23 setBorder(new LineBorder(Color.black, 1, true));*/24 //this.chRel = rel;25 19 rel.addChosenRelationListener(this); 26 20 } … … 32 26 } 33 27 34 private final staticString[] TYPE_KEYS = new String[] {28 private static final String[] TYPE_KEYS = new String[] { 35 29 "natural", "landuse", "place", "waterway", "leisure", "amenity", "restriction", "public_transport", "route", "enforcement" 36 30 }; 37 31 38 private final staticString[] NAMING_TAGS = new String[] {32 private static final String[] NAMING_TAGS = new String[] { 39 33 "name", "place_name", "ref", "destination", "note" 40 34 }; 41 35 42 36 protected String prepareText(Relation rel) { 43 if (rel == null 37 if (rel == null) 44 38 return ""; 45 39 46 40 String type = rel.get("type"); 47 if (type == null || type.length() == 0 41 if (type == null || type.length() == 0) { 48 42 type = "-"; 49 43 } 50 44 51 45 String tag = null; 52 for (int i = 0; i < TYPE_KEYS.length && tag == null; i++ )46 for (int i = 0; i < TYPE_KEYS.length && tag == null; i++) { 53 47 if (rel.hasKey(TYPE_KEYS[i])) { 54 48 tag = TYPE_KEYS[i]; 55 49 } 56 if (tag != null ) { 50 } 51 if (tag != null) { 57 52 tag = tag.substring(0, 2) + "=" + rel.get(tag); 58 53 } 59 54 60 55 String name = null; 61 for (int i = 0; i < NAMING_TAGS.length && name == null; i++ )62 if (rel.hasKey(NAMING_TAGS[i]) 56 for (int i = 0; i < NAMING_TAGS.length && name == null; i++) { 57 if (rel.hasKey(NAMING_TAGS[i])) { 63 58 name = rel.get(NAMING_TAGS[i]); 64 59 } 60 } 65 61 66 62 StringBuilder sb = new StringBuilder(); 67 63 sb.append(type.substring(0, 1)); 68 if (type.equals("boundary") && rel.hasKey("admin_level") 64 if (type.equals("boundary") && rel.hasKey("admin_level")) { 69 65 sb.append(rel.get("admin_level")); 70 66 } 71 if (name != null 67 if (name != null) { 72 68 sb.append(" \"").append(name).append('"'); 73 69 } 74 if (tag != null 70 if (tag != null) { 75 71 sb.append("; ").append(tag); 76 72 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/ExtraNameFormatHook.java
r32395 r32398 26 26 @Override 27 27 public String checkFormat(IWay way, String defaultName) { 28 if (way.get("place") != null && way.get("name") == null && way.get("place_name") != null 28 if (way.get("place") != null && way.get("name") == null && way.get("place_name") != null) 29 29 return way.get("place_name") + " " + defaultName; 30 30 return null; … … 37 37 String name = relation.get("destination"); 38 38 if (type.equals("destination_sign") && name != null) { 39 if (relation.get("distance") != null 39 if (relation.get("distance") != null) { 40 40 name += " " + relation.get("distance"); 41 41 } 42 if (defaultName.indexOf('"') < 0 42 if (defaultName.indexOf('"') < 0) 43 43 return '"' + name + "\" " + defaultName; 44 44 else -
applications/editors/josm/plugins/reltoolbox/src/relcontext/RelContextDialog.java
r32395 r32398 70 70 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 71 71 import org.openstreetmap.josm.gui.DefaultNameFormatter; 72 import org.openstreetmap.josm.gui.MapView;73 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;74 72 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 75 73 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 76 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 74 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 75 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 77 76 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 78 77 import org.openstreetmap.josm.tools.GBC; … … 102 101 * @author Zverik 103 102 */ 104 public class RelContextDialog extends ToggleDialog implements EditLayerChangeListener, ChosenRelationListener, SelectionChangedListener {103 public class RelContextDialog extends ToggleDialog implements ActiveLayerChangeListener, ChosenRelationListener, SelectionChangedListener { 105 104 106 105 public static final String PREF_PREFIX = "reltoolbox"; … … 136 135 final JTable relationsTable = new JTable(relationsData); 137 136 configureRelationsTable(relationsTable); 138 rcPanel.add(new JScrollPane(relationsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); 137 rcPanel.add(new JScrollPane(relationsTable, 138 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); 139 139 140 140 final MouseListener relationMouseAdapter = new ChosenRelationMouseAdapter(); … … 146 146 @Override 147 147 public void itemStateChanged(ItemEvent e) { 148 if (e.getStateChange() == ItemEvent.DESELECTED 148 if (e.getStateChange() == ItemEvent.DESELECTED) return; 149 149 String memberRole = roleBoxModel.getSelectedMembersRole(); 150 150 String selectedRole = roleBoxModel.isAnotherRoleSelected() ? askForRoleName() : roleBoxModel.getSelectedRole(); … … 200 200 }); 201 201 downloadButton.setVisible(false); 202 if (Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false) 202 if (Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false)) { 203 203 chosenRelationPanel.setVisible(false); 204 204 } … … 229 229 230 230 private void checkPopup(MouseEvent e) { 231 if (e.isPopupTrigger() 231 if (e.isPopupTrigger()) { 232 232 multiPopupMenu.show(e.getComponent(), e.getX(), e.getY()); 233 233 } … … 249 249 int row = relationsTable.rowAtPoint(p); 250 250 if (SwingUtilities.isLeftMouseButton(e) && row >= 0) { 251 Relation relation = (Relation) relationsData.getValueAt(row, 0);251 Relation relation = (Relation) relationsData.getValueAt(row, 0); 252 252 if (e.getClickCount() > 1) { 253 Main. main.getEditLayer().data.setSelected(relation);253 Main.getLayerManager().getEditLayer().data.setSelected(relation); 254 254 } 255 255 } … … 271 271 int row = relationsTable.rowAtPoint(p); 272 272 if (row > -1) { 273 Relation relation = (Relation) relationsData.getValueAt(row, 0);273 Relation relation = (Relation) relationsData.getValueAt(row, 0); 274 274 JPopupMenu menu = chosenRelation.isSame(relation) ? popupMenu 275 275 : new ChosenRelationPopupMenu(new StaticChosenRelation(relation)); … … 288 288 289 289 @Override 290 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 290 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 291 int row, int column) { 291 292 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 292 if (!isSelected && value instanceof Relation && chosenRelation.isSame(value) 293 if (!isSelected && value instanceof Relation && chosenRelation.isSame(value)) { 293 294 c.setBackground(CHOSEN_RELATION_COLOR); 294 295 } else { … … 301 302 columns.getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 302 303 @Override 303 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 304 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 305 int row, int column) { 304 306 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 305 if (!isSelected && chosenRelation.isSame(table.getValueAt(row, 0)) 307 if (!isSelected && chosenRelation.isSame(table.getValueAt(row, 0))) { 306 308 c.setBackground(CHOSEN_RELATION_COLOR); 307 309 } else { … … 318 320 int selectedRow = relationsTable.getSelectedRow(); 319 321 if (selectedRow >= 0) { 320 chosenRelation.set((Relation) relationsData.getValueAt(selectedRow, 0));322 chosenRelation.set((Relation) relationsData.getValueAt(selectedRow, 0)); 321 323 relationsTable.clearSelection(); 322 324 } … … 334 336 public void hideNotify() { 335 337 SelectionEventManager.getInstance().removeSelectionListener(this); 336 Ma pView.removeEditLayerChangeListener(this);338 Main.getLayerManager().removeActiveLayerChangeListener(this); 337 339 DatasetEventManager.getInstance().removeDatasetListener(chosenRelation); 338 340 chosenRelation.clear(); … … 342 344 public void showNotify() { 343 345 SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED); 344 Ma pView.addEditLayerChangeListener(this);346 Main.getLayerManager().addActiveLayerChangeListener(this); 345 347 DatasetEventManager.getInstance().addDatasetListener(chosenRelation, FireMode.IN_EDT); 346 348 } … … 352 354 @Override 353 355 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) { 354 if (chosenRelationPanel != null && Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false) 356 if (chosenRelationPanel != null && Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false)) { 355 357 chosenRelationPanel.setVisible(newRelation != null); 356 358 } 357 if (Main. main.getCurrentDataSet() != null) {358 selectionChanged(Main. main.getCurrentDataSet().getSelected());359 if (Main.getLayerManager().getEditDataSet() != null) { 360 selectionChanged(Main.getLayerManager().getEditDataSet().getSelected()); 359 361 } 360 362 roleBoxModel.update(); 361 // ?362 363 } 363 364 364 365 @Override 365 366 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 366 if (!isVisible() || relationsData == null 367 if (!isVisible() || relationsData == null) 367 368 return; 368 369 roleBoxModel.update(); … … 370 371 relationsData.setRowCount(0); 371 372 sortAndFixAction.chosenRelationChanged(chosenRelation.get(), chosenRelation.get()); 372 if (newSelection == null 373 if (newSelection == null) 373 374 return; 374 375 … … 388 389 for (OsmPrimitive element : newSelection) { 389 390 if (m.getMember().equals(element)) { 390 if (role == null 391 if (role == null) { 391 392 role = m.getRole(); 392 393 } else if (!role.equals(m.getRole())) { … … 399 400 relationsData.addRow(new Object[] {rel, role == null ? "" : role}); 400 401 } 401 for (OsmPrimitive element : newSelection )402 if (element instanceof Relation && !chosenRelation.isSame(element) 402 for (OsmPrimitive element : newSelection) { 403 if (element instanceof Relation && !chosenRelation.isSame(element)) { 403 404 relationsData.addRow(new Object[] {element, ""}); 404 405 } 406 } 405 407 } 406 408 407 409 private void updateSelection() { 408 if (Main. main.getCurrentDataSet() == null) {410 if (Main.getLayerManager().getEditDataSet() == null) { 409 411 selectionChanged(Collections.<OsmPrimitive>emptyList()); 410 412 } else { 411 selectionChanged(Main. main.getCurrentDataSet().getSelected());413 selectionChanged(Main.getLayerManager().getEditDataSet().getSelected()); 412 414 } 413 415 } 414 416 415 417 @Override 416 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {418 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 417 419 updateSelection(); 418 420 } … … 435 437 436 438 ClassLoader classLoader = RelContextDialog.class.getClassLoader(); 437 try ( 438 InputStream possibleRolesStream = classLoader.getResourceAsStream(POSSIBLE_ROLES_FILE); 439 try (InputStream possibleRolesStream = classLoader.getResourceAsStream(POSSIBLE_ROLES_FILE); 439 440 BufferedReader r = new BufferedReader(new InputStreamReader(possibleRolesStream)); 440 441 ) { 441 while (r.ready()) {442 while (r.ready()) { 442 443 String line = r.readLine(); 443 444 StringTokenizer t = new StringTokenizer(line, " ,;:\""); … … 445 446 String type = t.nextToken(); 446 447 List<String> roles = new ArrayList<>(); 447 while (t.hasMoreTokens()) {448 while (t.hasMoreTokens()) { 448 449 roles.add(t.nextToken()); 449 450 } … … 451 452 } 452 453 } 453 } catch (Exception e) {454 } catch (Exception e) { 454 455 Main.error("[RelToolbox] Error reading possible roles file."); 455 456 Main.error(e); … … 463 464 List<String> items = new ArrayList<>(); 464 465 for (String role : roleBoxModel.getRoles()) { 465 if (role.length() > 1 466 if (role.length() > 1) { 466 467 items.add(role); 467 468 } … … 497 498 Object answer = optionPane.getValue(); 498 499 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE 499 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))500 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION)) 500 501 return null; 501 502 … … 506 507 @Override 507 508 public void mouseClicked(MouseEvent e) { 508 if (e.isControlDown() || !(e.getComponent() instanceof JComboBox )) // do not use left click handler on combo box509 if (SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main. main.getEditLayer() != null) {510 Main. main.getEditLayer().data.setSelected(chosenRelation.get());509 if (e.isControlDown() || !(e.getComponent() instanceof JComboBox)) // do not use left click handler on combo box 510 if (SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main.getLayerManager().getEditLayer() != null) { 511 Main.getLayerManager().getEditLayer().data.setSelected(chosenRelation.get()); 511 512 } 512 513 } … … 530 531 531 532 private class ChosenRelationPopupMenu extends JPopupMenu { 532 publicChosenRelationPopupMenu(ChosenRelation chosenRelation) {533 ChosenRelationPopupMenu(ChosenRelation chosenRelation) { 533 534 add(new SelectMembersAction(chosenRelation)); 534 535 add(new SelectRelationAction(chosenRelation)); … … 545 546 546 547 protected void applyRoleToSelection(String role) { 547 if (chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty()) { 548 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 548 if (chosenRelation != null && chosenRelation.get() != null 549 && Main.getLayerManager().getEditDataSet() != null && !Main.getLayerManager().getEditDataSet().selectionEmpty()) { 550 Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected(); 549 551 Relation r = chosenRelation.get(); 550 552 List<Command> commands = new ArrayList<>(); … … 553 555 if (selected.contains(m.getMember())) { 554 556 if (!role.equals(m.getRole())) { 555 // r.setMember(i, new RelationMember(role, m.getMember()));556 557 commands.add(new ChangeRelationMemberRoleCommand(r, i, role)); 557 558 } … … 576 577 } 577 578 } 578 /*579 private class MultipolygonSettingsAction extends AbstractAction {580 public MultipolygonSettingsAction() {581 super();582 putValue(SMALL_ICON, ImageProvider.get("svpRight"));583 putValue(SHORT_DESCRIPTION, tr("Change multipolygon creation settings"));584 }585 586 public void actionPerformed(ActionEvent e) {587 Component c = e.getSource() instanceof Component ? (Component)e.getSource() : Main.parent;588 multiPopupMenu.show(c, 0, 0);589 }590 }*/591 579 592 580 private class MultipolygonSettingsPopup extends JPopupMenu implements ActionListener { 593 public MultipolygonSettingsPopup() { 594 super(); 581 MultipolygonSettingsPopup() { 595 582 addMenuItem("boundary", tr("Create administrative boundary relations")); 596 583 addMenuItem("boundaryways", tr("Add tags boundary and admin_level to boundary relation ways")); … … 614 601 String property = e.getActionCommand(); 615 602 if (property != null && property.length() > 0 && e.getSource() instanceof JCheckBoxMenuItem) { 616 boolean value = ((JCheckBoxMenuItem) e.getSource()).isSelected();603 boolean value = ((JCheckBoxMenuItem) e.getSource()).isSelected(); 617 604 Main.pref.put(property, value); 618 605 show(getInvoker(), getX(), getY()); … … 623 610 private class EnterRoleAction extends JosmAction implements ChosenRelationListener { 624 611 625 publicEnterRoleAction() {626 super(tr("Change role"), (String) null, tr("Enter role for selected members"),612 EnterRoleAction() { 613 super(tr("Change role"), (String) null, tr("Enter role for selected members"), 627 614 Shortcut.registerShortcut("reltoolbox:changerole", tr("Relation Toolbox: {0}", tr("Enter role for selected members")), 628 615 KeyEvent.VK_R, Shortcut.ALT_CTRL), false, "relcontext/enterrole", true); … … 635 622 if (roleBoxModel.membersRole != null) { 636 623 String role = askForRoleName(); 637 if (role != null 624 if (role != null) { 638 625 applyRoleToSelection(role); 639 626 } … … 655 642 private final String ANOTHER_ROLE = tr("another..."); 656 643 657 publicRoleComboBoxModel(JComboBox<String> combobox) {644 RoleComboBoxModel(JComboBox<String> combobox) { 658 645 super(); 659 646 this.combobox = combobox; … … 664 651 membersRole = getSelectedMembersRoleIntl(); 665 652 if (membersRole == null) { 666 if (combobox.isEnabled() 653 if (combobox.isEnabled()) { 667 654 combobox.setEnabled(false); 668 655 } 669 656 return; 670 657 } 671 if (!combobox.isEnabled() 658 if (!combobox.isEnabled()) { 672 659 combobox.setEnabled(true); 673 660 } … … 681 668 if (chosenRelation.get().get("type") != null) { 682 669 List<String> values = possibleRoles.get(chosenRelation.get().get("type")); 683 if (values != null 670 if (values != null) { 684 671 items.addAll(values); 685 672 } 686 673 } 687 for (RelationMember m : chosenRelation.get().getMembers() )688 if (m.getRole().length() > 0 && !items.contains(m.getRole()) 674 for (RelationMember m : chosenRelation.get().getMembers()) { 675 if (m.getRole().length() > 0 && !items.contains(m.getRole())) { 689 676 items.add(m.getRole()); 690 677 } 678 } 691 679 } 692 680 items.add(EMPTY_ROLE); 693 if (!items.contains(membersRole) 681 if (!items.contains(membersRole)) { 694 682 items.add(0, membersRole); 695 683 } … … 697 685 roles = Collections.unmodifiableList(items); 698 686 699 if (membersRole != null 687 if (membersRole != null) { 700 688 setSelectedItem(membersRole); 701 689 } else { … … 715 703 private String getSelectedMembersRoleIntl() { 716 704 String role = null; 717 if (chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty()) { 718 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 705 if (chosenRelation != null && chosenRelation.get() != null 706 && Main.getLayerManager().getEditDataSet() != null && !Main.getLayerManager().getEditDataSet().selectionEmpty()) { 707 Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected(); 719 708 for (RelationMember m : chosenRelation.get().getMembers()) { 720 709 if (selected.contains(m.getMember())) { 721 if (role == null 710 if (role == null) { 722 711 role = m.getRole(); 723 712 } else if (m.getRole() != null && !role.equals(m.getRole())) { -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/AddRemoveMemberAction.java
r32395 r32398 13 13 import org.openstreetmap.josm.command.ChangeCommand; 14 14 import org.openstreetmap.josm.command.Command; 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.Node; 16 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 49 50 @Override 50 51 public void actionPerformed(ActionEvent e) { 51 if (rel.get() == null 52 if (rel.get() == null) 52 53 return; 53 54 54 55 Relation r = new Relation(rel.get()); 55 56 56 Collection<OsmPrimitive> toAdd = new ArrayList<>(get CurrentDataSet().getSelected());57 Collection<OsmPrimitive> toAdd = new ArrayList<>(getLayerManager().getEditDataSet().getSelected()); 57 58 toAdd.remove(rel.get()); 58 59 toAdd.removeAll(r.getMemberPrimitives()); … … 62 63 63 64 // 1. remove all present members 64 r.removeMembersFor(get CurrentDataSet().getSelected());65 r.removeMembersFor(getLayerManager().getEditDataSet().getSelected()); 65 66 66 67 // 2. add all new members 67 68 for (OsmPrimitive p : toAdd) { 68 69 int pos = -1; //p instanceof Way ? findAdjacentMember(p, r) : -1; 69 if (pos < 0 70 if (pos < 0) { 70 71 r.addMember(new RelationMember("", p)); 71 72 } else { … … 76 77 // 3. check for roles again (temporary) 77 78 Command roleFix = !isBroken && sortAndFix.needsFixing(r) ? sortAndFix.fixRelation(r) : null; 78 if (roleFix != null 79 if (roleFix != null) { 79 80 roleFix.executeCommand(); 80 81 } 81 82 82 if (!r.getMemberPrimitives().equals(rel.get().getMemberPrimitives()) 83 if (!r.getMemberPrimitives().equals(rel.get().getMemberPrimitives())) { 83 84 Main.main.undoRedo.add(new ChangeCommand(rel.get(), r)); 84 85 } … … 96 97 for (int i = 0; i < r.getMembersCount(); i++) { 97 98 if (r.getMember(i).getType().equals(OsmPrimitiveType.WAY)) { 98 Way rw = (Way) r.getMember(i).getMember();99 Way rw = (Way) r.getMember(i).getMember(); 99 100 Node firstNodeR = rw.firstNode(); 100 101 Node lastNodeR = rw.lastNode(); 101 if (firstNode.equals(firstNodeR) || firstNode.equals(lastNodeR) || lastNode.equals(firstNodeR) || lastNode.equals(lastNodeR) 102 if (firstNode.equals(firstNodeR) || firstNode.equals(lastNodeR) || lastNode.equals(firstNodeR) || lastNode.equals(lastNodeR)) 102 103 return i + 1; 103 104 } … … 114 115 @Override 115 116 protected void updateEnabledState() { 116 updateEnabledState(get CurrentDataSet() == null ? null : getCurrentDataSet().getSelected());117 updateEnabledState(getLayerManager().getEditDataSet() == null ? null : getLayerManager().getEditDataSet().getSelected()); 117 118 } 118 119 … … 134 135 // todo: change icon based on selection 135 136 final int state; // 0=unknown, 1=add, 2=remove, 3=both 136 if (getCurrentDataSet() == null || getCurrentDataSet().getSelected() == null 137 || getCurrentDataSet().getSelected().isEmpty() || rel == null || rel.get() == null ) { 137 DataSet ds = getLayerManager().getEditDataSet(); 138 if (ds == null || ds.getSelected() == null 139 || ds.getSelected().isEmpty() || rel == null || rel.get() == null) { 138 140 state = 0; 139 141 } else { 140 Collection<OsmPrimitive> toAdd = new ArrayList<>( getCurrentDataSet().getSelected());142 Collection<OsmPrimitive> toAdd = new ArrayList<>(ds.getSelected()); 141 143 toAdd.remove(rel.get()); 142 144 int selectedSize = toAdd.size(); 143 if (selectedSize == 0 145 if (selectedSize == 0) { 144 146 state = 0; 145 147 } else { 146 148 toAdd.removeAll(rel.get().getMemberPrimitives()); 147 if (toAdd.isEmpty() 149 if (toAdd.isEmpty()) { 148 150 state = 2; 149 } else if (toAdd.size() < selectedSize 151 } else if (toAdd.size() < selectedSize) { 150 152 state = 3; 151 153 } else { … … 157 159 @Override 158 160 public void run() { 159 // String name = state == 0 ? "?" : state == 1 ? "+" : state == 2 ? "-" : "±";160 // putValue(Action.NAME, name);161 161 if (state == 0) { 162 // putValue(NAME, "?");163 162 putValue(LARGE_ICON_KEY, ImageProvider.get("relcontext", "addremove")); 164 163 } else { -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/CreateMultipolygonAction.java
r32395 r32398 33 33 import org.openstreetmap.josm.command.Command; 34 34 import org.openstreetmap.josm.command.SequenceCommand; 35 import org.openstreetmap.josm.data.osm.DataSet; 35 36 import org.openstreetmap.josm.data.osm.MultipolygonBuilder; 36 37 import org.openstreetmap.josm.data.osm.Node; … … 68 69 69 70 public static boolean getDefaultPropertyValue(String property) { 70 if (property.equals("boundary") 71 if (property.equals("boundary")) 71 72 return false; 72 else if (property.equals("boundaryways") 73 else if (property.equals("boundaryways")) 73 74 return true; 74 else if (property.equals("tags") 75 else if (property.equals("tags")) 75 76 return true; 76 else if (property.equals("alltags") 77 else if (property.equals("alltags")) 77 78 return false; 78 else if (property.equals("single") 79 else if (property.equals("single")) 79 80 return true; 80 else if (property.equals("allowsplit") 81 else if (property.equals("allowsplit")) 81 82 return false; 82 83 throw new IllegalArgumentException(property); … … 90 91 public void actionPerformed(ActionEvent e) { 91 92 boolean isBoundary = getPref("boundary"); 92 Collection<Way> selectedWays = getCurrentDataSet().getSelectedWays(); 93 DataSet ds = getLayerManager().getEditDataSet(); 94 Collection<Way> selectedWays = ds.getSelectedWays(); 93 95 if (!isBoundary && getPref("tags")) { 94 96 List<Relation> rels = null; 95 97 if (getPref("allowsplit") || selectedWays.size() == 1) { 96 if (SplittingMultipolygons.canProcess(selectedWays) 97 rels = SplittingMultipolygons.process( getCurrentDataSet().getSelectedWays());98 if (SplittingMultipolygons.canProcess(selectedWays)) { 99 rels = SplittingMultipolygons.process(ds.getSelectedWays()); 98 100 } 99 101 } else { 100 102 if (TheRing.areAllOfThoseRings(selectedWays)) { 101 103 List<Command> commands = new ArrayList<>(); 102 rels = TheRing.makeManySimpleMultipolygons( getCurrentDataSet().getSelectedWays(), commands);103 if (!commands.isEmpty() 104 rels = TheRing.makeManySimpleMultipolygons(ds.getSelectedWays(), commands); 105 if (!commands.isEmpty()) { 104 106 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygons from rings"), commands)); 105 107 } … … 107 109 } 108 110 if (rels != null && !rels.isEmpty()) { 109 if (chRel != null 111 if (chRel != null) { 110 112 chRel.set(rels.size() == 1 ? rels.get(0) : null); 111 113 } 112 if (rels.size() == 1 113 getCurrentDataSet().setSelected(rels);114 if (rels.size() == 1) { 115 ds.setSelected(rels); 114 116 } else { 115 getCurrentDataSet().clearSelection();117 ds.clearSelection(); 116 118 } 117 119 return; … … 121 123 // for now, just copying standard action 122 124 MultipolygonBuilder mpc = new MultipolygonBuilder(); 123 String error = mpc.makeFromWays(get CurrentDataSet().getSelectedWays());125 String error = mpc.makeFromWays(getLayerManager().getEditDataSet().getSelectedWays()); 124 126 if (error != null) { 125 127 JOptionPane.showMessageDialog(Main.parent, error); … … 133 135 rel.put("type", "multipolygon"); 134 136 } 135 for (MultipolygonBuilder.JoinedPolygon poly : mpc.outerWays 136 for (Way w : poly.ways 137 for (MultipolygonBuilder.JoinedPolygon poly : mpc.outerWays) { 138 for (Way w : poly.ways) { 137 139 rel.addMember(new RelationMember("outer", w)); 138 140 } 139 141 } 140 for (MultipolygonBuilder.JoinedPolygon poly : mpc.innerWays 141 for (Way w : poly.ways 142 for (MultipolygonBuilder.JoinedPolygon poly : mpc.innerWays) { 143 for (Way w : poly.ways) { 142 144 rel.addMember(new RelationMember("inner", w)); 143 145 } … … 149 151 } 150 152 if (isBoundary) { 151 if (!askForAdminLevelAndName(rel) 153 if (!askForAdminLevelAndName(rel)) 152 154 return; 153 155 addBoundaryMembers(rel); 154 if (getPref("boundaryways") 156 if (getPref("boundaryways")) { 155 157 list.addAll(fixWayTagsForBoundary(rel)); 156 158 } … … 159 161 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), list)); 160 162 161 if (chRel != null 163 if (chRel != null) { 162 164 chRel.set(rel); 163 165 } 164 166 165 get CurrentDataSet().setSelected(rel);167 getLayerManager().getEditDataSet().setSelected(rel); 166 168 } 167 169 168 170 @Override 169 171 protected void updateEnabledState() { 170 if (get CurrentDataSet() == null) {172 if (getLayerManager().getEditDataSet() == null) { 171 173 setEnabled(false); 172 174 } else { 173 updateEnabledState(get CurrentDataSet().getSelected());175 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); 174 176 } 175 177 } … … 178 180 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 179 181 boolean isEnabled = true; 180 if (selection == null || selection.isEmpty() 182 if (selection == null || selection.isEmpty()) { 181 183 isEnabled = false; 182 184 } else { … … 197 199 */ 198 200 private void addBoundaryMembers(Relation rel) { 199 for (OsmPrimitive p : get CurrentDataSet().getSelected()) {201 for (OsmPrimitive p : getLayerManager().getEditDataSet().getSelected()) { 200 202 String role = null; 201 203 if (p.getType().equals(OsmPrimitiveType.RELATION)) { 202 204 role = "subarea"; 203 205 } else if (p.getType().equals(OsmPrimitiveType.NODE)) { 204 Node n = (Node) p;206 Node n = (Node) p; 205 207 if (!n.isIncomplete()) { 206 if (n.hasKey("place") 208 if (n.hasKey("place")) { 207 209 role = "admin_centre"; 208 210 } else { … … 211 213 } 212 214 } 213 if (role != null 215 if (role != null) { 214 216 rel.addMember(new RelationMember(role, p)); 215 217 } … … 222 224 private List<Command> fixWayTagsForBoundary(Relation rel) { 223 225 List<Command> commands = new ArrayList<>(); 224 if (!rel.hasKey("boundary") || !rel.hasKey("admin_level") 226 if (!rel.hasKey("boundary") || !rel.hasKey("admin_level")) 225 227 return commands; 226 228 String adminLevelStr = rel.get("admin_level"); … … 228 230 try { 229 231 adminLevel = Integer.parseInt(adminLevelStr); 230 } catch (NumberFormatException e) {232 } catch (NumberFormatException e) { 231 233 return commands; 232 234 } … … 236 238 if (p instanceof Way) { 237 239 int count = 0; 238 if (p.hasKey("boundary") && p.get("boundary").equals("administrative") 240 if (p.hasKey("boundary") && p.get("boundary").equals("administrative")) { 239 241 count++; 240 242 } 241 if (p.hasKey("admin_level") 243 if (p.hasKey("admin_level")) { 242 244 count++; 243 245 } 244 246 if (p.keySet().size() - count == 0) { 245 if (!p.hasKey("boundary") 247 if (!p.hasKey("boundary")) { 246 248 waysBoundary.add(p); 247 249 } … … 251 253 try { 252 254 int oldAdminLevel = Integer.parseInt(p.get("admin_level")); 253 if (oldAdminLevel > adminLevel 255 if (oldAdminLevel > adminLevel) { 254 256 waysAdminLevel.add(p); 255 257 } 256 } catch (NumberFormatException e) {258 } catch (NumberFormatException e) { 257 259 waysAdminLevel.add(p); // some garbage, replace it 258 260 } … … 261 263 } 262 264 } 263 if (!waysBoundary.isEmpty() 265 if (!waysBoundary.isEmpty()) { 264 266 commands.add(new ChangePropertyCommand(waysBoundary, "boundary", "administrative")); 265 267 } 266 if (!waysAdminLevel.isEmpty() 268 if (!waysAdminLevel.isEmpty()) { 267 269 commands.add(new ChangePropertyCommand(waysAdminLevel, "admin_level", adminLevelStr)); 268 270 } 269 271 return commands; 270 272 } 271 static public final List<String> DEFAULT_LINEAR_TAGS = Arrays.asList(new String[] {"barrier", "source"}); 273 274 public static final List<String> DEFAULT_LINEAR_TAGS = Arrays.asList(new String[] {"barrier", "source"}); 275 272 276 private static final Set<String> REMOVE_FROM_BOUNDARY_TAGS = new TreeSet<>(Arrays.asList(new String[] { 273 277 "boundary", "boundary_type", "type", "admin_level" … … 314 318 // filter out empty key conflicts - we need second iteration 315 319 boolean isBoundary = getPref("boundary"); 316 if (isBoundary || !getPref("alltags") 317 for (RelationMember m : relation.getMembers() )318 if (m.hasRole() && m.getRole().equals("outer") && m.isWay() 319 for (String key : values.keySet() )320 if (!m.getWay().hasKey(key) && !relation.hasKey(key) 320 if (isBoundary || !getPref("alltags")) { 321 for (RelationMember m : relation.getMembers()) { 322 if (m.hasRole() && m.getRole().equals("outer") && m.isWay()) { 323 for (String key : values.keySet()) { 324 if (!m.getWay().hasKey(key) && !relation.hasKey(key)) { 321 325 conflictingKeys.add(key); 322 326 } 323 } 324 } 325 326 for (String key : conflictingKeys ) { 327 } 328 } 329 } 330 } 331 332 for (String key : conflictingKeys) { 327 333 values.remove(key); 328 334 } 329 335 330 for (String linearTag : Main.pref.getCollection(PREF_MULTIPOLY + "lineartags", DEFAULT_LINEAR_TAGS) 336 for (String linearTag : Main.pref.getCollection(PREF_MULTIPOLY + "lineartags", DEFAULT_LINEAR_TAGS)) { 331 337 values.remove(linearTag); 332 338 } 333 339 334 if (values.containsKey("natural") && values.get("natural").equals("coastline") 340 if (values.containsKey("natural") && values.get("natural").equals("coastline")) { 335 341 values.remove("natural"); 336 342 } … … 339 345 if (isBoundary) { 340 346 Set<String> keySet = new TreeSet<>(values.keySet()); 341 for (String key : keySet )342 if (!REMOVE_FROM_BOUNDARY_TAGS.contains(key) 347 for (String key : keySet) { 348 if (!REMOVE_FROM_BOUNDARY_TAGS.contains(key)) { 343 349 values.remove(key); 344 350 } 351 } 345 352 } 346 353 … … 376 383 if (moveTags) { 377 384 // add those tag values to the relation 378 if (isBoundary 385 if (isBoundary) { 379 386 values.put("name", name); 380 387 } … … 384 391 if (!r2.hasKey(key) && !key.equals("area") 385 392 && (!isBoundary || key.equals("admin_level") || key.equals("name"))) { 386 if (relation.isNew() 393 if (relation.isNew()) { 387 394 relation.put(key, values.get(key)); 388 395 } else { … … 392 399 } 393 400 } 394 if (fixed && !relation.isNew() 401 if (fixed && !relation.isNew()) { 395 402 commands.add(new ChangeCommand(relation, r2)); 396 403 } … … 402 409 /** 403 410 * 404 * @param rel 411 * @param rel relation 405 412 * @return false if user pressed "cancel". 406 413 */ … … 408 415 String relAL = rel.get("admin_level"); 409 416 String relName = rel.get("name"); 410 if (relAL != null && relName != null 417 if (relAL != null && relName != null) 411 418 return true; 412 419 … … 421 428 422 429 final JTextField name = new JTextField(); 423 if (relName != null 430 if (relName != null) { 424 431 name.setText(relName); 425 432 } … … 450 457 Object answer = optionPane.getValue(); 451 458 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE 452 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))459 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION)) 453 460 return false; 454 461 … … 459 466 Main.pref.put(PREF_MULTIPOLY + "lastadmin", admin_level); 460 467 } 461 if (new_name.length() > 0 468 if (new_name.length() > 0) { 462 469 rel.put("name", new_name); 463 470 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/CreateRelationAction.java
r32395 r32398 56 56 public void actionPerformed(ActionEvent e) { 57 57 String type = askForType(); 58 if (type == null 58 if (type == null) 59 59 return; 60 60 61 61 Relation rel = new Relation(); 62 if (type.length() > 0 62 if (type.length() > 0) { 63 63 rel.put("type", type); 64 64 } 65 for (OsmPrimitive selected : get CurrentDataSet().getSelected()) {65 for (OsmPrimitive selected : getLayerManager().getEditDataSet().getSelected()) { 66 66 rel.addMember(new RelationMember("", selected)); 67 67 } … … 76 76 @Override 77 77 protected void updateEnabledState() { 78 if (get CurrentDataSet() == null) {78 if (getLayerManager().getEditDataSet() == null) { 79 79 setEnabled(false); 80 80 } else { 81 updateEnabledState(get CurrentDataSet().getSelected());81 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); 82 82 } 83 83 } … … 130 130 Object answer = optionPane.getValue(); 131 131 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE 132 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))132 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION)) 133 133 return null; 134 134 -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DeleteChosenRelationAction.java
r32395 r32398 33 33 Relation r = rel.get(); 34 34 rel.clear(); 35 Command c = DeleteCommand.delete(Main. main.getEditLayer(), Collections.singleton(r), true, true);36 if (c != null 35 Command c = DeleteCommand.delete(Main.getLayerManager().getEditLayer(), Collections.singleton(r), true, true); 36 if (c != null) { 37 37 Main.main.undoRedo.add(c); 38 38 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DownloadChosenRelationAction.java
r32395 r32398 31 31 32 32 public DownloadChosenRelationAction(ChosenRelation rel) { 33 super();34 // putValue(NAME, "D");35 33 putValue(SMALL_ICON, ImageProvider.get("relcontext", "download")); 36 34 putValue(SHORT_DESCRIPTION, tr("Download incomplete members for the chosen relation")); … … 43 41 public void actionPerformed(ActionEvent e) { 44 42 Relation relation = rel.get(); 45 if (relation == null || relation.isNew() 43 if (relation == null || relation.isNew()) return; 46 44 int total = relation.getMembersCount(); 47 45 int incomplete = relation.getIncompleteMembers().size(); 48 // if (incomplete <= 5 || (incomplete <= 10 && incomplete * 3 < total) ) 49 if (incomplete <= 10 && incomplete * 3 < total ) { 46 if (incomplete <= 10 && incomplete * 3 < total) { 50 47 downloadIncomplete(relation); 51 48 } else { … … 70 67 protected void downloadMembers(Relation rel) { 71 68 if (!rel.isNew()) { 72 Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main. main.getEditLayer()));69 Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.getLayerManager().getEditLayer())); 73 70 } 74 71 } 75 72 76 73 protected void downloadIncomplete(Relation rel) { 77 if (rel.isNew() 74 if (rel.isNew()) return; 78 75 Set<OsmPrimitive> ret = new HashSet<>(); 79 76 ret.addAll(rel.getIncompleteMembers()); 80 if (ret.isEmpty() 81 Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main. main.getEditLayer()));77 if (ret.isEmpty()) return; 78 Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.getLayerManager().getEditLayer())); 82 79 } 83 80 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DownloadParentsAction.java
r32395 r32398 38 38 this.rel = rel; 39 39 rel.addChosenRelationListener(this); 40 setEnabled(rel.get() != null && Main. main.getEditLayer() != null);40 setEnabled(rel.get() != null && Main.getLayerManager().getEditLayer() != null); 41 41 } 42 42 … … 44 44 public void actionPerformed(ActionEvent e) { 45 45 Relation relation = rel.get(); 46 if (relation == null 46 if (relation == null) return; 47 47 List<OsmPrimitive> objects = new ArrayList<>(); 48 48 objects.add(relation); 49 49 objects.addAll(relation.getMemberPrimitives()); 50 Main.worker.submit(new DownloadReferrersTask(Main. main.getEditLayer(), objects));50 Main.worker.submit(new DownloadReferrersTask(Main.getLayerManager().getEditLayer(), objects)); 51 51 } 52 52 53 53 @Override 54 54 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) { 55 setEnabled(newRelation != null && Main. main.getEditLayer() != null);55 setEnabled(newRelation != null && Main.getLayerManager().getEditLayer() != null); 56 56 } 57 57 58 58 protected void downloadMembers(Relation rel) { 59 59 if (!rel.isNew()) { 60 Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main. main.getEditLayer()));60 Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.getLayerManager().getEditLayer())); 61 61 } 62 62 } 63 63 64 64 protected void downloadIncomplete(Relation rel) { 65 if (rel.isNew() 65 if (rel.isNew()) return; 66 66 Set<OsmPrimitive> ret = new HashSet<>(); 67 67 ret.addAll(rel.getIncompleteMembers()); 68 if (ret.isEmpty() 69 Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main. main.getEditLayer()));68 if (ret.isEmpty()) return; 69 Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.getLayerManager().getEditLayer())); 70 70 } 71 71 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DuplicateChosenRelationAction.java
r32395 r32398 34 34 Main.main.undoRedo.add(new AddCommand(copy)); 35 35 rel.set(copy); 36 if (Main. main.getCurrentDataSet() != null) {37 Main. main.getCurrentDataSet().setSelected(copy);36 if (Main.getLayerManager().getEditDataSet() != null) { 37 Main.getLayerManager().getEditDataSet().setSelected(copy); 38 38 } 39 39 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/EditChosenRelationAction.java
r32395 r32398 25 25 26 26 public EditChosenRelationAction(ChosenRelation rel) { 27 super();28 // putValue(NAME, "E");29 27 putValue(SMALL_ICON, ImageProvider.get("dialogs/mappaint", "pencil")); 30 28 putValue(SHORT_DESCRIPTION, tr("Open relation editor for the chosen relation")); … … 37 35 public void actionPerformed(ActionEvent e) { 38 36 Relation relation = rel.get(); 39 if (relation == null 40 RelationEditor.getEditor(Main. main.getEditLayer(), relation, null).setVisible(true);37 if (relation == null) return; 38 RelationEditor.getEditor(Main.getLayerManager().getEditLayer(), relation, null).setVisible(true); 41 39 } 42 40 -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/FindRelationAction.java
r32395 r32398 63 63 relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 64 64 relationsList.setCellRenderer(new OsmPrimitivRenderer()); 65 panel.add(new JScrollPane(relationsList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); 65 panel.add(new JScrollPane(relationsList, 66 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); 66 67 panel.setPreferredSize(new Dimension(400, 400)); 67 68 … … 108 109 @Override 109 110 public void keyPressed(KeyEvent e) { 110 if (shouldForward(e) 111 if (shouldForward(e)) { 111 112 relationsList.dispatchEvent(e); 112 113 } … … 115 116 @Override 116 117 public void keyReleased(KeyEvent e) { 117 if (shouldForward(e) 118 if (shouldForward(e)) { 118 119 relationsList.dispatchEvent(e); 119 120 } … … 132 133 Object answer = optionPane.getValue(); 133 134 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE 134 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))135 || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION)) 135 136 return; 136 137 137 138 Relation r = relationsList.getSelectedValue(); 138 if (r != null 139 if (r != null) { 139 140 chRel.set(r); 140 141 } … … 143 144 @Override 144 145 protected void updateEnabledState() { 145 setEnabled(get CurrentDataSet() != null);146 setEnabled(getLayerManager().getEditDataSet() != null); 146 147 } 147 148 … … 150 151 if (keywords.length > 0) { 151 152 List<String> filteredKeywords = new ArrayList<>(keywords.length); 152 for (String s : keywords )153 if (s.length() > 0 153 for (String s : keywords) { 154 if (s.length() > 0) { 154 155 filteredKeywords.add(s.trim().toLowerCase()); 155 156 } 157 } 156 158 keywords = filteredKeywords.toArray(new String[0]); 157 159 } 158 160 159 System.out.println("keywords.length = " + keywords.length); 160 for (int i = 0; i < keywords.length; i++ ) { 161 System.out.println("keyword["+i+"] = " + keywords[i]); 161 if (Main.isDebugEnabled()) { 162 Main.debug("keywords.length = " + keywords.length); 163 for (int i = 0; i < keywords.length; i++) { 164 Main.debug("keyword["+i+"] = " + keywords[i]); 165 } 162 166 } 163 167 164 168 List<Relation> relations = new ArrayList<>(); 165 if (get EditLayer() != null) {166 for (Relation r : get EditLayer().data.getRelations()) {169 if (getLayerManager().getEditLayer() != null) { 170 for (Relation r : getLayerManager().getEditLayer().data.getRelations()) { 167 171 if (!r.isDeleted() && r.isVisible() && !r.isIncomplete()) { 168 172 boolean add = true; 169 173 for (int i = 0; i < keywords.length && add; i++) { 170 174 boolean ok = false; 171 if (String.valueOf(r.getPrimitiveId().getUniqueId()).contains(keywords[i]) 175 if (String.valueOf(r.getPrimitiveId().getUniqueId()).contains(keywords[i])) { 172 176 ok = true; 173 177 } else { … … 180 184 } 181 185 } 182 if (!ok 186 if (!ok) { 183 187 add = false; 184 188 } 185 189 } 186 if (add 190 if (add) { 187 191 relations.add(r); 188 192 } … … 227 231 public void setRelations(Collection<Relation> relations) { 228 232 int selectedIndex = selectionModel.getMinSelectionIndex(); 229 Relation sel = 233 Relation sel = selectedIndex < 0 ? null : getElementAt(selectedIndex); 230 234 231 235 this.relations.clear(); 232 236 selectionModel.clearSelection(); 233 if (relations != null 237 if (relations != null) { 234 238 this.relations.addAll(relations); 235 239 } … … 238 242 if (sel != null) { 239 243 selectedIndex = this.relations.indexOf(sel); 240 if (selectedIndex >= 0 244 if (selectedIndex >= 0) { 241 245 selectionModel.addSelectionInterval(selectedIndex, selectedIndex); 242 246 } 243 247 } 244 if (selectionModel.isSelectionEmpty() && !this.relations.isEmpty() 248 if (selectionModel.isSelectionEmpty() && !this.relations.isEmpty()) { 245 249 selectionModel.addSelectionInterval(0, 0); 246 250 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/PublicTransportHelper.java
r32395 r32398 7 7 8 8 /** 9 * @author freeExec 9 10 * @see http://wiki.openstreetmap.org/wiki/Key:public_transport 10 */11 12 /**13 *14 * @author freeExec15 11 */ 16 12 public final class PublicTransportHelper { 17 13 18 public final staticString PUBLIC_TRANSPORT = "public_transport";19 public final staticString STOP_POSITION = "stop_position";20 public final staticString STOP = "stop";21 public final staticString STOP_AREA = "stop_area";22 public final staticString PLATFORM = "platform";23 public final staticString HIGHWAY = "highway";24 public final staticString RAILWAY = "railway";25 public final staticString BUS_STOP = "bus_stop";26 public final staticString RAILWAY_HALT = "halt";27 public final staticString RAILWAY_STATION = "station";14 public static final String PUBLIC_TRANSPORT = "public_transport"; 15 public static final String STOP_POSITION = "stop_position"; 16 public static final String STOP = "stop"; 17 public static final String STOP_AREA = "stop_area"; 18 public static final String PLATFORM = "platform"; 19 public static final String HIGHWAY = "highway"; 20 public static final String RAILWAY = "railway"; 21 public static final String BUS_STOP = "bus_stop"; 22 public static final String RAILWAY_HALT = "halt"; 23 public static final String RAILWAY_STATION = "station"; 28 24 29 25 private PublicTransportHelper() { … … 54 50 String pt = p.get(PUBLIC_TRANSPORT); 55 51 if (STOP_POSITION.equals(pt)) return true; 56 } 57 else if (p.hasKey(RAILWAY)) { 52 } else if (p.hasKey(RAILWAY)) { 58 53 String rw = p.get(RAILWAY); 59 54 if (RAILWAY_HALT.equals(rw) || RAILWAY_STATION.equals(rw)) return true; … … 83 78 return false; 84 79 } 80 85 81 public static boolean isWayPlatform(RelationMember m) { 86 82 return isWayPlatform(m.getMember()); … … 121 117 if (result != null) return result; 122 118 // try to get name by stop_area 123 for (OsmPrimitive refOp : prim.getReferrers()) 119 for (OsmPrimitive refOp : prim.getReferrers()) { 124 120 if (refOp.getType() == OsmPrimitiveType.RELATION 125 && refOp.hasTag(PUBLIC_TRANSPORT, STOP_AREA)) {121 && refOp.hasTag(PUBLIC_TRANSPORT, STOP_AREA)) { 126 122 result = refOp.getName(); 127 123 if (result != null) return result; 128 124 } 125 } 129 126 return result; 130 127 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java
r32395 r32398 60 60 boolean wont = false; 61 61 for (RelationMember m : r.getMembers()) { 62 if (m.isWay() 62 if (m.isWay()) { 63 63 ways.add(m.getWay()); 64 64 } else { … … 67 67 } 68 68 if (wont) { 69 JOptionPane.showMessageDialog(Main.parent, tr("Multipolygon must consist only of ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE); 69 JOptionPane.showMessageDialog(Main.parent, 70 tr("Multipolygon must consist only of ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE); 70 71 return; 71 72 } … … 79 80 80 81 if (!mpc.innerWays.isEmpty()) { 81 JOptionPane.showMessageDialog(Main.parent, tr("Reconstruction of polygons can be done only from outer ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE); 82 JOptionPane.showMessageDialog(Main.parent, 83 tr("Reconstruction of polygons can be done only from outer ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE); 82 84 return; 83 85 } … … 86 88 List<Way> newSelection = new ArrayList<>(); 87 89 List<Command> commands = new ArrayList<>(); 88 Command c = DeleteCommand.delete(Main. main.getEditLayer(), Collections.singleton(r), true, true);89 if (c == null 90 Command c = DeleteCommand.delete(Main.getLayerManager().getEditLayer(), Collections.singleton(r), true, true); 91 if (c == null) 90 92 return; 91 93 commands.add(c); … … 106 108 } 107 109 List<OsmPrimitive> referrers = w.getReferrers(); 108 for (Iterator<OsmPrimitive> ref1 = relations.iterator(); ref1.hasNext(); )109 if (!referrers.contains(ref1.next()) 110 for (Iterator<OsmPrimitive> ref1 = relations.iterator(); ref1.hasNext();) { 111 if (!referrers.contains(ref1.next())) { 110 112 ref1.remove(); 111 113 } 114 } 112 115 } 113 116 tags.putAll(r.getKeys()); … … 123 126 keys.removeAll(IRRELEVANT_KEYS); 124 127 if (keys.isEmpty()) { 125 if (candidateWay == null 128 if (candidateWay == null) { 126 129 candidateWay = w; 127 130 } else { … … 149 152 Main.main.undoRedo.add(new SequenceCommand(tr("Reconstruct polygons from relation {0}", 150 153 r.getDisplayName(DefaultNameFormatter.getInstance())), commands)); 151 Main. main.getCurrentDataSet().setSelected(newSelection);154 Main.getLayerManager().getEditDataSet().setSelected(newSelection); 152 155 } 153 156 … … 158 161 159 162 private boolean isSuitableRelation(Relation newRelation) { 160 if (newRelation == null || !"multipolygon".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0 163 if (newRelation == null || !"multipolygon".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0) 161 164 return false; 162 165 else { 163 for (RelationMember m : newRelation.getMembers() )164 if ("inner".equals(m.getRole()) 166 for (RelationMember m : newRelation.getMembers()) { 167 if ("inner".equals(m.getRole())) 165 168 return false; 169 } 166 170 return true; 167 171 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructRouteAction.java
r32395 r32398 33 33 * @author freeExec 34 34 */ 35 public class ReconstructRouteAction 35 public class ReconstructRouteAction extends AbstractAction implements ChosenRelationListener { 36 36 private final ChosenRelation rel; 37 37 38 public ReconstructRouteAction 38 public ReconstructRouteAction(ChosenRelation rel) { 39 39 super(tr("Reconstruct route")); 40 40 putValue(SMALL_ICON, ImageProvider.get("dialogs", "filter")); … … 65 65 m.getMember()); 66 66 stopMembers.put(rm.getMember(), rm); 67 } 68 else if (PublicTransportHelper.isMemberPlatform(m)) { 67 } else if (PublicTransportHelper.isMemberPlatform(m)) { 69 68 RelationMember rm = new RelationMember( 70 69 m.hasRole() ? m.getRole() : PublicTransportHelper.PLATFORM, … … 81 80 platformMembers.put(platformName, nList); 82 81 } 83 } 84 else if (PublicTransportHelper.isMemberRouteway(m)) { 82 } else if (PublicTransportHelper.isMemberRouteway(m)) { 85 83 routeMembers.add(new RelationMember(m)); 86 84 } else { … … 93 91 Node lastNode = null; 94 92 for (int rIndex = 0; rIndex < routeMembers.size(); rIndex++) { 95 Way w = (Way) routeMembers.get(rIndex).getMember();93 Way w = (Way) routeMembers.get(rIndex).getMember(); 96 94 boolean dirForward = false; 97 95 if (lastNode == null) { // first segment 98 96 if (routeMembers.size() > 2) { 99 Way nextWay = (Way) routeMembers.get(rIndex + 1).getMember();97 Way nextWay = (Way) routeMembers.get(rIndex + 1).getMember(); 100 98 if (w.lastNode().equals(nextWay.lastNode()) || w.lastNode().equals(nextWay.firstNode())) { 101 99 dirForward = true; … … 106 104 } // else one segment - direction unknown 107 105 } else { 108 if (lastNode.equals(w.firstNode())) { dirForward = true; lastNode = w.lastNode(); } else { 106 if (lastNode.equals(w.firstNode())) { 107 dirForward = true; lastNode = w.lastNode(); 108 } else { 109 109 lastNode = w.firstNode(); 110 110 } … … 126 126 } 127 127 boolean existsPlatform = platformMembers.containsKey(stopName); 128 if (!existsPlatform) { stopName = ""; } // find of the nameless 128 if (!existsPlatform) { 129 stopName = ""; // find of the nameless 130 } 129 131 if (existsPlatform || platformMembers.containsKey(stopName)) { 130 132 List<RelationMember> lMember = platformMembers.get(stopName); … … 153 155 String stopName = PublicTransportHelper.getNameViaStoparea(stop); 154 156 boolean existsPlatform = platformMembers.containsKey(stopName); 155 if (!existsPlatform) { stopName = ""; } // find of the nameless 157 if (!existsPlatform) { 158 stopName = ""; // find of the nameless 159 } 156 160 if (existsPlatform || platformMembers.containsKey(stopName)) { 157 161 List<RelationMember> lMember = platformMembers.get(stopName); … … 224 228 } 225 229 226 private boolean isSuitableRelation 230 private boolean isSuitableRelation(Relation newRelation) { 227 231 return !(newRelation == null || !"route".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0); 228 232 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/RelationHelpAction.java
r32395 r32398 45 45 @Override 46 46 public void actionPerformed(ActionEvent e) { 47 if (rel.get() == null 47 if (rel.get() == null) 48 48 return; 49 49 try { … … 61 61 uris.add(new URI(String.format("%sRelations", base))); 62 62 63 Main.worker.execute(new Runnable() {63 Main.worker.execute(new Runnable() { 64 64 @Override 65 65 public void run() { -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SelectMembersAction.java
r32395 r32398 28 28 @Override 29 29 public void actionPerformed(ActionEvent e) { 30 Main. main.getEditLayer().data.setSelected(rel.get() == null ? null : rel.get().getMemberPrimitives());30 Main.getLayerManager().getEditLayer().data.setSelected(rel.get() == null ? null : rel.get().getMemberPrimitives()); 31 31 } 32 32 -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SelectRelationAction.java
r32395 r32398 29 29 @Override 30 30 public void actionPerformed(ActionEvent e) { 31 Main. main.getEditLayer().data.setSelected(rel.get() == null ? null : rel.get());31 Main.getLayerManager().getEditLayer().data.setSelected(rel.get() == null ? null : rel.get()); 32 32 } 33 33 -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SortAndFixAction.java
r32395 r32398 56 56 public void actionPerformed(ActionEvent e) { 57 57 Command c = fixRelation(rel.get()); 58 if (c != null 58 if (c != null) { 59 59 Main.main.undoRedo.add(c); 60 60 } … … 71 71 72 72 private RelationFixer getFixer(Relation rel) { 73 for (RelationFixer fixer : fixers) 73 for (RelationFixer fixer : fixers) { 74 74 if (fixer.isFixerApplicable(rel)) 75 75 return fixer; 76 } 76 77 return new NothingFixer(); 77 78 } … … 82 83 83 84 protected static boolean isIncomplete(Relation r) { 84 if (r == null || r.isIncomplete() || r.isDeleted() 85 if (r == null || r.isIncomplete() || r.isDeleted()) 85 86 return true; 86 for (RelationMember m : r.getMembers()) 87 if (m.getMember().isIncomplete() 87 for (RelationMember m : r.getMembers()) { 88 if (m.getMember().isIncomplete()) 88 89 return true; 90 } 89 91 return false; 90 92 } 91 92 93 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SplittingMultipolygons.java
r32395 r32398 33 33 * @author Zverik 34 34 */ 35 public class SplittingMultipolygons {35 public final class SplittingMultipolygons { 36 36 private static final String PREF_MULTIPOLY = "reltoolbox.multipolygon."; 37 38 private SplittingMultipolygons() { 39 // Hide default constructor for utilities classes 40 } 37 41 38 42 public static boolean canProcess(Collection<Way> ways) { 39 43 List<Way> rings = new ArrayList<>(); 40 44 List<Way> arcs = new ArrayList<>(); 41 Area a = Main. main.getCurrentDataSet().getDataSourceArea();45 Area a = Main.getLayerManager().getEditDataSet().getDataSourceArea(); 42 46 for (Way way : ways) { 43 if (way.isDeleted() 47 if (way.isDeleted()) 44 48 return false; 45 49 for (Node n : way.getNodes()) { 46 50 LatLon ll = n.getCoor(); 47 if (n.isIncomplete() || (a != null && !a.contains(ll.getX(), ll.getY())) 51 if (n.isIncomplete() || (a != null && !a.contains(ll.getX(), ll.getY()))) 48 52 return false; 49 53 } 50 if (way.isClosed() 54 if (way.isClosed()) { 51 55 rings.add(way); 52 56 } else { … … 59 63 for (Way segment : arcs) { 60 64 boolean found = false; 61 for (Way ring : rings )62 if (ring.containsNode(segment.firstNode()) && ring.containsNode(segment.lastNode()) 65 for (Way ring : rings) { 66 if (ring.containsNode(segment.firstNode()) && ring.containsNode(segment.lastNode())) { 63 67 found = true; 64 68 } 65 if (!found ) 69 } 70 if (!found) 66 71 return false; 67 72 } 68 73 } 69 74 70 if (rings.isEmpty() && arcs.isEmpty() 75 if (rings.isEmpty() && arcs.isEmpty()) 71 76 return false; 72 77 … … 75 80 for (int j = i + 1; j < rings.size(); j++) { 76 81 PolygonIntersection intersection = Geometry.polygonIntersection(rings.get(i).getNodes(), rings.get(j).getNodes()); 77 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST 82 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST) 78 83 return false; 79 84 } … … 84 89 85 90 public static List<Relation> process(Collection<Way> selectedWays) { 86 // System.out.println("---------------------------------------");87 91 List<Relation> result = new ArrayList<>(); 88 92 List<Way> rings = new ArrayList<>(); 89 93 List<Way> arcs = new ArrayList<>(); 90 94 for (Way way : selectedWays) { 91 if (way.isClosed() 95 if (way.isClosed()) { 92 96 rings.add(way); 93 97 } else { … … 148 152 public static List<Way> splitWay(Way w, Node n1, Node n2, List<Command> commands) { 149 153 List<Node> nodes = new ArrayList<>(w.getNodes()); 150 if (w.isClosed() 154 if (w.isClosed()) { 151 155 nodes.remove(nodes.size() - 1); 152 156 } … … 159 163 } 160 164 // right now index2 >= index1 161 if (index2 < 1 || index1 >= w.getNodesCount() - 1 || index2 >= w.getNodesCount() 165 if (index2 < 1 || index1 >= w.getNodesCount() - 1 || index2 >= w.getNodesCount()) 162 166 return Collections.emptyList(); 163 if (w.isClosed() && (index1 < 0 || index1 == index2 || index1 + w.getNodesCount() == index2) 167 if (w.isClosed() && (index1 < 0 || index1 == index2 || index1 + w.getNodesCount() == index2)) 164 168 return Collections.emptyList(); 165 169 … … 183 187 chunks.get(chunks.size() - 1).addAll(chunks.get(0)); 184 188 chunks.remove(0); 185 } else if (chunks.get(chunks.size() - 1).size() < 2 189 } else if (chunks.get(chunks.size() - 1).size() < 2) { 186 190 chunks.remove(chunks.size() - 1); 187 191 } 188 189 // todo remove debug: show chunks array contents190 /*for (List<Node> c1 : chunks) {191 for (Node cn1 : c1 )192 System.out.print(cn1.getId() + ",");193 System.out.println();194 }*/195 192 196 193 // build a map of referencing relations … … 199 196 for (OsmPrimitive p : w.getReferrers()) { 200 197 if (p instanceof Relation) { 201 Relation rel = commands == null ? (Relation) p : new Relation((Relation)p);202 if (commands != null 198 Relation rel = commands == null ? (Relation) p : new Relation((Relation) p); 199 if (commands != null) { 203 200 relationCommands.add(new ChangeCommand(p, rel)); 204 201 } 205 for (int i = 0; i < rel.getMembersCount(); i++ )206 if (rel.getMember(i).getMember().equals(w) 202 for (int i = 0; i < rel.getMembersCount(); i++) { 203 if (rel.getMember(i).getMember().equals(w)) { 207 204 references.put(rel, Integer.valueOf(i)); 208 205 } 206 } 209 207 } 210 208 } … … 229 227 } 230 228 newWay.setNodes(achunk); 231 if (commands != null 229 if (commands != null) { 232 230 commands.add(new AddCommand(newWay)); 233 231 } 234 232 } 235 if (commands != null 233 if (commands != null) { 236 234 commands.addAll(relationCommands); 237 235 } … … 247 245 */ 248 246 public static Relation tryToCloseOneWay(Way segment, List<Command> resultingCommands) { 249 if (segment.isClosed() || segment.isIncomplete() 247 if (segment.isClosed() || segment.isIncomplete()) 250 248 return null; 251 249 … … 256 254 for (Iterator<Way> iter = ways.iterator(); iter.hasNext();) { 257 255 boolean save = false; 258 for (OsmPrimitive ref : iter.next().getReferrers() )259 if (ref instanceof Relation && ((Relation) ref).isMultipolygon() && !ref.isDeleted()) {256 for (OsmPrimitive ref : iter.next().getReferrers()) { 257 if (ref instanceof Relation && ((Relation) ref).isMultipolygon() && !ref.isDeleted()) { 260 258 save = true; 261 259 } 262 if (!save ) { 260 } 261 if (!save) { 263 262 iter.remove(); 264 263 } 265 264 } 266 if (ways.isEmpty() 265 if (ways.isEmpty()) 267 266 return null; // well... 268 267 Way target = ways.get(0); … … 283 282 } 284 283 } 285 if (changed 284 if (changed) { 286 285 commands.add(new ChangeCommand(segment, segmentCopy)); 287 286 } … … 318 317 private static <T> List<T> intersection(Collection<T> list1, Collection<T> list2) { 319 318 List<T> result = new ArrayList<>(); 320 for (T item : list1 )321 if (list2.contains(item) 319 for (T item : list1) { 320 if (list2.contains(item)) { 322 321 result.add(item); 323 322 } 323 } 324 324 return result; 325 325 } … … 329 329 */ 330 330 public static Relation attachRingToNeighbours(Way ring, List<Command> resultingCommands) { 331 if (!ring.isClosed() || ring.isIncomplete() 331 if (!ring.isClosed() || ring.isIncomplete()) 332 332 return null; 333 333 Map<Way, Boolean> touchingWays = new HashMap<>(); … … 336 336 if (p instanceof Way && !p.equals(ring)) { 337 337 for (OsmPrimitive r : p.getReferrers()) { 338 if (r instanceof Relation && ((Relation) r).hasKey("type") && ((Relation)r).get("type").equals("multipolygon")) {339 if (touchingWays.containsKey(p) 340 touchingWays.put((Way) p, Boolean.TRUE);338 if (r instanceof Relation && ((Relation) r).hasKey("type") && ((Relation) r).get("type").equals("multipolygon")) { 339 if (touchingWays.containsKey(p)) { 340 touchingWays.put((Way) p, Boolean.TRUE); 341 341 } else { 342 touchingWays.put((Way) p, Boolean.FALSE);342 touchingWays.put((Way) p, Boolean.FALSE); 343 343 } 344 344 break; … … 350 350 351 351 List<TheRing> otherWays = new ArrayList<>(); 352 for (Way w : touchingWays.keySet() )352 for (Way w : touchingWays.keySet()) { 353 353 if (touchingWays.get(w)) { 354 354 otherWays.add(new TheRing(w)); 355 // System.out.println("Touching ring: " + otherWays.get(otherWays.size()-1)); 356 } 357 358 // for (Iterator<Way> keys = touchingWays.keySet().iterator(); keys.hasNext();) { 359 // if (!touchingWays.get(keys.next()) ) 360 // keys.remove(); 361 // } 355 } 356 } 362 357 363 358 // now touchingWays has only ways that touch the ring twice … … 365 360 TheRing theRing = new TheRing(ring); // this is actually useful 366 361 367 for (TheRing otherRing : otherWays 362 for (TheRing otherRing : otherWays) { 368 363 theRing.collide(otherRing); 369 364 } 370 365 371 366 theRing.putSourceWayFirst(); 372 for (TheRing otherRing : otherWays 367 for (TheRing otherRing : otherWays) { 373 368 otherRing.putSourceWayFirst(); 374 369 } 375 370 376 371 Map<Relation, Relation> relationCache = new HashMap<>(); 377 for (TheRing otherRing : otherWays 372 for (TheRing otherRing : otherWays) { 378 373 commands.addAll(otherRing.getCommands(false, relationCache)); 379 374 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java
r32395 r32398 1 1 // License: GPL. For details, see LICENSE file. 2 2 package relcontext.actions; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.util.ArrayList; … … 45 47 List<Way> rings = new ArrayList<>(); 46 48 for (Way way : ways) { 47 if (way.isClosed() 49 if (way.isClosed()) { 48 50 rings.add(way); 49 51 } else 50 52 return false; 51 53 } 52 if (rings.isEmpty() || ways.size() == 1 54 if (rings.isEmpty() || ways.size() == 1) 53 55 return false; 54 56 … … 57 59 for (int j = i + 1; j < rings.size(); j++) { 58 60 PolygonIntersection intersection = Geometry.polygonIntersection(rings.get(i).getNodes(), rings.get(j).getNodes()); 59 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST 61 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST) 60 62 return false; 61 63 } … … 72 74 log("---------------------------------------"); 73 75 List<TheRing> rings = new ArrayList<>(selection.size()); 74 for (Way w : selection 76 for (Way w : selection) { 75 77 rings.add(new TheRing(w)); 76 78 } 77 for (int i = 0; i < rings.size() - 1; i++ 78 for (int j = i + 1; j < rings.size(); j++ 79 for (int i = 0; i < rings.size() - 1; i++) { 80 for (int j = i + 1; j < rings.size(); j++) { 79 81 rings.get(i).collide(rings.get(j)); 80 82 } … … 108 110 RingSegment segment = splitRingAt(i, split[0], split[1]); 109 111 RingSegment otherSegment = other.splitRingAt(j, split[2], split[3]); 110 if (!areSegmentsEqual(segment, otherSegment) ) 111 throw new IllegalArgumentException("Error: algorithm gave incorrect segments: " + segment + " and " + otherSegment); 112 if (!areSegmentsEqual(segment, otherSegment)) 113 throw new IllegalArgumentException( 114 "Error: algorithm gave incorrect segments: " + segment + " and " + otherSegment); 112 115 segment.makeReference(otherSegment); 113 116 } 114 117 } 115 if (segment1.isReference() 118 if (segment1.isReference()) { 116 119 break; 117 120 } … … 126 129 public static Node[] getSplitNodes(List<Node> nodes1, List<Node> nodes2, boolean isRing1, boolean isRing2) { 127 130 int pos = 0; 128 while (pos < nodes1.size() && !nodes2.contains(nodes1.get(pos))) {131 while (pos < nodes1.size() && !nodes2.contains(nodes1.get(pos))) { 129 132 pos++; 130 133 } … … 133 136 // rewind a bit 134 137 pos = nodes1.size() - 1; 135 while (pos > 0 && nodes2.contains(nodes1.get(pos))) {138 while (pos > 0 && nodes2.contains(nodes1.get(pos))) { 136 139 pos--; 137 140 } 138 141 if (pos == 0 && nodes1.size() == nodes2.size()) { 139 JOptionPane.showMessageDialog(Main.parent, "Two rings are equal, and this must not be.", "Multipolygon from rings", JOptionPane.ERROR_MESSAGE); 142 JOptionPane.showMessageDialog(Main.parent, 143 tr("Two rings are equal, and this must not be."), tr("Multipolygon from rings"), JOptionPane.ERROR_MESSAGE); 140 144 return null; 141 145 } … … 143 147 } 144 148 int firstPos = isRing1 ? pos : nodes1.size(); 145 while (!collideFound) {149 while (!collideFound) { 146 150 log("pos=" + pos); 147 151 int start1 = pos; … … 152 156 if (last1 >= 0) { 153 157 last2 = incrementBy(start2, -1, nodes2.size(), isRing2); 154 if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2)) 158 if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2))) { 155 159 increment2 = -1; 156 160 } else { 157 161 last2 = incrementBy(start2, 1, nodes2.size(), isRing2); 158 if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2)) 162 if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2))) { 159 163 increment2 = 1; 160 164 } … … 165 169 // find the first nodes 166 170 boolean reachedEnd = false; 167 while (!reachedEnd) {171 while (!reachedEnd) { 168 172 int newLast1 = incrementBy(last1, 1, nodes1.size(), isRing1); 169 173 int newLast2 = incrementBy(last2, increment2, nodes2.size(), isRing2); 170 if (newLast1 < 0 || newLast2 < 0 || !nodes1.get(newLast1).equals(nodes2.get(newLast2)) 174 if (newLast1 < 0 || newLast2 < 0 || !nodes1.get(newLast1).equals(nodes2.get(newLast2))) { 171 175 reachedEnd = true; 172 176 } else { … … 184 188 } else { 185 189 pos = last1; 186 while (pos != firstPos && pos >= 0 && !nodes2.contains(nodes1.get(pos))) {190 while (pos != firstPos && pos >= 0 && !nodes2.contains(nodes1.get(pos))) { 187 191 pos = incrementBy(pos, 1, nodes1.size(), isRing1); 188 192 } 189 if (pos < 0 || pos == firstPos || !nodes2.contains(nodes1.get(pos)) 193 if (pos < 0 || pos == firstPos || !nodes2.contains(nodes1.get(pos))) { 190 194 collideFound = true; 191 195 } … … 197 201 private static int incrementBy(int value, int increment, int limit1, boolean isRing) { 198 202 int result = value + increment; 199 if (result < 0 203 if (result < 0) 200 204 return isRing ? result + limit1 : -1; 201 else if (result >= limit1 205 else if (result >= limit1) 202 206 return isRing ? result - limit1 : -1; 203 207 else … … 209 213 List<Node> nodes2 = seg2.getNodes(); 210 214 int size = nodes1.size(); 211 if (size != nodes2.size() 215 if (size != nodes2.size()) 212 216 return false; 213 217 boolean reverse = size > 1 && !nodes1.get(0).equals(nodes2.get(0)); 214 for (int i = 0; i < size; i++ )215 if (!nodes1.get(i).equals(nodes2.get(reverse ? size-1-i : i)) 218 for (int i = 0; i < size; i++) { 219 if (!nodes1.get(i).equals(nodes2.get(reverse ? size-1-i : i))) 216 220 return false; 221 } 217 222 return true; 218 223 } … … 223 228 */ 224 229 private RingSegment splitRingAt(int segmentIndex, Node n1, Node n2) { 225 if (n1.equals(n2) 230 if (n1.equals(n2)) 226 231 throw new IllegalArgumentException("Both nodes are equal, id=" + n1.getUniqueId()); 227 232 RingSegment segment = segments.get(segmentIndex); … … 242 247 // if thirdPart == null, then n2 == lastNode 243 248 int pos = segmentIndex + 1; 244 if (secondPart != null 249 if (secondPart != null) { 245 250 segments.add(pos++, secondPart); 246 251 } 247 if (thirdPart != null 252 if (thirdPart != null) { 248 253 segments.add(pos++, thirdPart); 249 254 } … … 260 265 // build segments map 261 266 Map<RingSegment, TheRing> segmentMap = new HashMap<>(); 262 for (TheRing ring : rings 263 for (RingSegment seg : ring.segments )264 if (!seg.isReference() 267 for (TheRing ring : rings) { 268 for (RingSegment seg : ring.segments) { 269 if (!seg.isReference()) { 265 270 segmentMap.put(seg, ring); 266 271 } 272 } 267 273 } 268 274 … … 283 289 284 290 // initializing source way for each ring 285 for (TheRing ring : rings 291 for (TheRing ring : rings) { 286 292 ring.putSourceWayFirst(); 287 293 } … … 290 296 private int countNonReferenceSegments() { 291 297 int count = 0; 292 for (RingSegment seg : segments )293 if (!seg.isReference() 298 for (RingSegment seg : segments) { 299 if (!seg.isReference()) { 294 300 count++; 295 301 } 302 } 296 303 return count; 297 304 } … … 325 332 relation.put("type", "multipolygon"); 326 333 for (String key : sourceCopy.keySet()) { 327 if (linearTags.contains(key) 334 if (linearTags.contains(key)) { 328 335 continue; 329 336 } 330 if (key.equals("natural") && sourceCopy.get("natural").equals("coastline") 337 if (key.equals("natural") && sourceCopy.get("natural").equals("coastline")) { 331 338 continue; 332 339 } … … 343 350 Relation rel = null; 344 351 if (relationChangeMap != null) { 345 if (relationChangeMap.containsKey(p) 352 if (relationChangeMap.containsKey(p)) { 346 353 rel = relationChangeMap.get(p); 347 354 } else { 348 rel = new Relation((Relation) p);349 relationChangeMap.put((Relation) p, rel);355 rel = new Relation((Relation) p); 356 relationChangeMap.put((Relation) p, rel); 350 357 } 351 358 } else { 352 rel = new Relation((Relation) p);359 rel = new Relation((Relation) p); 353 360 relationCommands.add(new ChangeCommand(p, rel)); 354 361 } 355 for (int i = 0; i < rel.getMembersCount(); i++ )356 if (rel.getMember(i).getMember().equals(source) 362 for (int i = 0; i < rel.getMembersCount(); i++) { 363 if (rel.getMember(i).getMember().equals(source)) { 357 364 referencingRelations.put(rel, Integer.valueOf(i)); 358 365 } 359 } 360 } 361 // todo: когда два кольца менÑ�ÑŽÑ‚ одно и то же отношение, в Ñ�пиÑ�ок команд добавлÑ�етÑ�Ñ� 362 // изменение базового отношениÑ� на новое, а не предыдущего 363 // поÑ�тому Ñ�охранÑ�етÑ�Ñ� только первое изменение 366 } 367 } 368 } 364 369 365 370 List<Command> commands = new ArrayList<>(); … … 368 373 boolean needAdding = !seg.isWayConstructed(); 369 374 Way w = seg.constructWay(seg.isReference() ? null : sourceCopy); 370 if (needAdding 375 if (needAdding) { 371 376 commands.add(new AddCommand(w)); 372 377 } … … 383 388 } 384 389 } 385 if (createMultipolygon 390 if (createMultipolygon) { 386 391 relation.addMember(new RelationMember("outer", w)); 387 392 } 388 393 } 389 if (!foundOwnWay 394 if (!foundOwnWay) { 390 395 commands.add(new DeleteCommand(source)); 391 396 } 392 397 commands.addAll(relationCommands); 393 if (createMultipolygon 398 if (createMultipolygon) { 394 399 commands.add(new AddCommand(relation)); 395 400 } … … 398 403 399 404 public static void updateCommandsWithRelations(List<Command> commands, Map<Relation, Relation> relationCache) { 400 for (Relation src : relationCache.keySet() 405 for (Relation src : relationCache.keySet()) { 401 406 commands.add(new ChangeCommand(src, relationCache.get(src))); 402 407 } … … 414 419 StringBuilder sb = new StringBuilder("TheRing@"); 415 420 sb.append(this.hashCode()).append('[').append("wayId: ").append(source == null ? "null" : source.getUniqueId()).append("; segments: "); 416 if (segments.isEmpty() 421 if (segments.isEmpty()) { 417 422 sb.append("empty"); 418 423 } else { 419 424 sb.append(segments.get(0)); 420 for (int i = 1; i < segments.size(); i++ 425 for (int i = 1; i < segments.size(); i++) { 421 426 sb.append(", ").append(segments.get(i)); 422 427 } … … 425 430 } 426 431 427 /**428 * Appends "append" to "base" so the closed polygon forms.429 */430 /*private static void closePolygon(List<Node> base, List<Node> append) {431 if (append.get(0).equals(base.get(0)) && append.get(append.size() - 1).equals(base.get(base.size() - 1))) {432 List<Node> ap2 = new ArrayList<Node>(append);433 Collections.reverse(ap2);434 append = ap2;435 }436 base.remove(base.size() - 1);437 base.addAll(append);438 }*/439 440 /**441 * Checks if a middle point between two nodes is inside a polygon. Useful to check if the way is inside.442 */443 /*private static boolean segmentInsidePolygon(Node n1, Node n2, List<Node> polygon) {444 EastNorth en1 = n1.getEastNorth();445 EastNorth en2 = n2.getEastNorth();446 Node testNode = new Node(new EastNorth((en1.east() + en2.east()) / 2.0, (en1.north() + en2.north()) / 2.0));447 return Geometry.nodeInsidePolygon(testNode, polygon);448 }*/449 450 432 private static void log(String s) { 451 // System.out.println(s);433 Main.debug(s); 452 434 } 453 435 … … 459 441 private boolean isRing; 460 442 461 /*private RingSegment() { 462 }*/ 463 464 public RingSegment(Way w) { 443 RingSegment(Way w) { 465 444 this(w.getNodes()); 466 445 } 467 446 468 publicRingSegment(List<Node> nodes) {447 RingSegment(List<Node> nodes) { 469 448 this.nodes = nodes; 470 449 isRing = nodes.size() > 1 && nodes.get(0).equals(nodes.get(nodes.size() - 1)); 471 if (isRing 450 if (isRing) { 472 451 nodes.remove(nodes.size() - 1); 473 452 } 474 453 references = null; 475 454 } 476 477 /*public RingSegment(RingSegment ref) {478 this.nodes = null;479 this.references = ref;480 }*/481 455 482 456 /** … … 487 461 */ 488 462 public RingSegment split(Node n) { 489 if (nodes == null 463 if (nodes == null) 490 464 throw new IllegalArgumentException("Cannot split segment: it is a reference"); 491 465 int pos = nodes.indexOf(n); 492 if (pos <= 0 || pos >= nodes.size() - 1 466 if (pos <= 0 || pos >= nodes.size() - 1) 493 467 return null; 494 468 List<Node> newNodes = new ArrayList<>(nodes.subList(pos, nodes.size())); … … 503 477 */ 504 478 public RingSegment split(Node n1, Node n2) { 505 if (nodes == null 479 if (nodes == null) 506 480 throw new IllegalArgumentException("Cannot split segment: it is a reference"); 507 481 if (!isRing) { 508 if (n1 == null || nodes.get(0).equals(n1) || nodes.get(nodes.size() - 1).equals(n1) 482 if (n1 == null || nodes.get(0).equals(n1) || nodes.get(nodes.size() - 1).equals(n1)) 509 483 return split(n2); 510 if (n2 == null || nodes.get(0).equals(n2) || nodes.get(nodes.size() - 1).equals(n2) 484 if (n2 == null || nodes.get(0).equals(n2) || nodes.get(nodes.size() - 1).equals(n2)) 511 485 return split(n1); 512 486 throw new IllegalArgumentException("Split for two nodes is called for not-ring: " + this); … … 514 488 int pos1 = nodes.indexOf(n1); 515 489 int pos2 = nodes.indexOf(n2); 516 if (pos1 == pos2 490 if (pos1 == pos2) 517 491 return null; 518 492 … … 521 495 newNodes.addAll(nodes.subList(pos2, nodes.size())); 522 496 newNodes.addAll(nodes.subList(0, pos1 + 1)); 523 if (pos2 + 1 < nodes.size() 497 if (pos2 + 1 < nodes.size()) { 524 498 nodes.subList(pos2 + 1, nodes.size()).clear(); 525 499 } 526 if (pos1 > 0 500 if (pos1 > 0) { 527 501 nodes.subList(0, pos1).clear(); 528 502 } … … 541 515 542 516 public List<Node> getWayNodes() { 543 if (nodes == null 517 if (nodes == null) 544 518 throw new IllegalArgumentException("Won't give you wayNodes: it is a reference"); 545 519 List<Node> wayNodes = new ArrayList<>(nodes); 546 if (isRing 520 if (isRing) { 547 521 wayNodes.add(wayNodes.get(0)); 548 522 } … … 576 550 577 551 public Way constructWay(Way template) { 578 if (isReference() 552 if (isReference()) 579 553 return references.constructWay(template); 580 554 if (resultingWay == null) { … … 590 564 591 565 public void overrideWay(Way source) { 592 if (isReference() 566 if (isReference()) { 593 567 references.overrideWay(source); 594 568 } else { … … 598 572 } 599 573 600 /**601 * Compares two segments with respect to referencing.602 * @return true if ways are equals, or one references another.603 */604 /*public boolean isReferencingEqual(RingSegment other) {605 return this.equals(other) || (other.isReference() && other.references == this) || (isReference() && references == other);606 }*/607 608 574 @Override 609 575 public String toString() { 610 576 StringBuilder sb = new StringBuilder("RingSegment@"); 611 577 sb.append(this.hashCode()).append('['); 612 if (isReference() 578 if (isReference()) { 613 579 sb.append("references ").append(references.hashCode()); 614 } else if (nodes.isEmpty() 580 } else if (nodes.isEmpty()) { 615 581 sb.append("empty"); 616 582 } else { 617 if (isRing 583 if (isRing) { 618 584 sb.append("ring:"); 619 585 } 620 586 sb.append(nodes.get(0).getUniqueId()); 621 for (int i = 1; i < nodes.size(); i++ 587 for (int i = 1; i < nodes.size(); i++) { 622 588 sb.append(',').append(nodes.get(i).getUniqueId()); 623 589 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/AssociatedStreetFixer.java
r32395 r32398 90 90 (way.hasKey("building") || way.hasKey("addr:housenumber"))) { 91 91 fixed = true; 92 rel.setMember(i, 92 rel.setMember(i, new RelationMember("house", way)); 93 93 } 94 94 } else if (m.isRelation()) {
Note:
See TracChangeset
for help on using the changeset viewer.