Changeset 25709 in osm for applications/editors/josm/plugins/relcontext
- Timestamp:
- 2011-03-25T13:58:59+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/TODO
r25704 r25709 9 9 - Break touching rings of multipolygons 10 10 - Option to create separate multipolygon for every outer ring 11 - Solve multipolygon settings button width problem12 11 - Solve width problem for narrows buttons when "fix" and "download" appear simultaneously 13 12 - Sort relation members button (now it's just role fixer) 14 - Show role panel only when relation members are selected15 - Rethink role panel. Maybe, replace chosen relation title with role combobox?16 13 17 14 == RELEASE == -
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25704 r25709 30 30 31 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.command.ChangeCommand;33 32 import org.openstreetmap.josm.data.SelectionChangedListener; 34 33 import org.openstreetmap.josm.data.osm.Relation; … … 47 46 import org.openstreetmap.josm.command.ChangeRelationMemberRoleCommand; 48 47 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 49 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;50 48 import static org.openstreetmap.josm.tools.I18n.tr; 51 49 … … 58 56 59 57 public final static String PREF_PREFIX = "reltoolbox"; 60 private static final String PREF_ROLEBOX = PREF_PREFIX + ".rolebox";61 58 62 59 private final DefaultTableModel relationsData; … … 65 62 private ChosenRelationPopupMenu popupMenu; 66 63 private MultipolygonSettingsPopup multiPopupMenu; 67 private JLabel crRoleIndicator;68 64 private RoleComboBoxModel roleBoxModel; 69 private String lastSelectedRole;70 65 71 66 public RelContextDialog() { … … 90 85 rcPanel.add(new JScrollPane(relationsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); 91 86 92 chosenRelationPanel = new JPanel(new BorderLayout()); 93 94 // [^] roles [new role][V][Apply] 95 final JPanel rolePanel = new JPanel(new GridBagLayout()); 96 final JButton toggleRolePanelButtonTop = new JButton(new TogglePanelAction(rolePanel) { 97 @Override 98 protected void init() { 99 putValue(Action.SMALL_ICON, ImageProvider.get("svpDown")); 100 putValue(Action.SHORT_DESCRIPTION, tr("Show role panel")); 101 } 102 }); 103 final JButton toggleRolePanelButtonIn = new JButton(new TogglePanelAction(rolePanel) { 104 @Override 105 protected void init() { 106 putValue(Action.SMALL_ICON, ImageProvider.get("svpUp")); 107 putValue(Action.SHORT_DESCRIPTION, tr("Hide role panel")); 108 } 109 }); 110 rolePanel.add(sizeButton(toggleRolePanelButtonIn, 16, 20), GBC.std()); 111 crRoleIndicator = new JLabel(); 112 rolePanel.add(crRoleIndicator, GBC.std().insets(5, 0, 5, 0)); 113 roleBoxModel = new RoleComboBoxModel(); 114 JComboBox roleBox = new JComboBox(roleBoxModel); 115 rolePanel.add(roleBox, GBC.std().fill(GBC.HORIZONTAL)); 116 rolePanel.add(sizeButton(new JButton(new ApplyNewRoleAction()), 40, 20), GBC.std()); 117 rolePanel.add(sizeButton(new JButton(new EnterNewRoleAction()), 40, 20), GBC.eol()); 118 // rolePanel.setVisible(false); // todo: take from preferences 87 final MouseListener relationMouseAdapter = new ChosenRelationMouseAdapter(); 88 final JComboBox roleBox = new JComboBox(); 89 roleBoxModel = new RoleComboBoxModel(roleBox); 90 roleBox.setModel(roleBoxModel); 91 roleBox.addMouseListener(relationMouseAdapter); 92 roleBox.addItemListener(new ItemListener() { 93 public void itemStateChanged( ItemEvent e ) { 94 if( e.getStateChange() == ItemEvent.DESELECTED ) return; 95 String memberRole = roleBoxModel.getSelectedMembersRole(); 96 String selectedRole = roleBoxModel.isAnotherRoleSelected() ? askForRoleName() : roleBoxModel.getSelectedRole(); 97 if( memberRole != null && selectedRole != null && !memberRole.equals(selectedRole) ) { 98 applyRoleToSelection(selectedRole.trim()); 99 } 100 } 101 }); 102 roleBox.setVisible(false); 119 103 120 104 // [±][X] relation U [AZ][Down][Edit] 121 JPanel topLine = new JPanel(new GridBagLayout()); 122 topLine.add(new JButton(new AddRemoveMemberAction(chosenRelation)), GBC.std()); 123 topLine.add(sizeButton(toggleRolePanelButtonTop, 16, 24), GBC.std()); 124 topLine.add(sizeButton(new JButton(new ClearChosenRelationAction(chosenRelation)), 32, 0), GBC.std()); 105 chosenRelationPanel = new JPanel(new GridBagLayout()); 106 chosenRelationPanel.add(new JButton(new AddRemoveMemberAction(chosenRelation)), GBC.std()); 107 chosenRelationPanel.add(sizeButton(new JButton(new ClearChosenRelationAction(chosenRelation)), 32, 0), GBC.std()); 125 108 final ChosenRelationComponent chosenRelationComponent = new ChosenRelationComponent(chosenRelation); 126 chosenRelationComponent.addMouseListener(new ChosenRelationMouseAdapter()); 127 topLine.add(chosenRelationComponent, GBC.std().fill().insets(5, 0, 5, 0)); 109 chosenRelationComponent.addMouseListener(relationMouseAdapter); 110 chosenRelationPanel.add(chosenRelationComponent, GBC.std().fill().insets(5, 0, 5, 0)); 111 chosenRelationPanel.add(roleBox, GBC.std().fill().insets(5, 0, 5, 0)); 128 112 final Action sortAndFixAction = new SortAndFixAction(chosenRelation); 129 113 final JButton sortAndFixButton = (JButton) sizeButton(new JButton(sortAndFixAction), 32, 24); 130 topLine.add(sortAndFixButton, GBC.std());114 chosenRelationPanel.add(sortAndFixButton, GBC.std()); 131 115 final Action downloadChosenRelationAction = new DownloadChosenRelationAction(chosenRelation); 132 116 final JButton downloadButton = (JButton) sizeButton(new JButton(downloadChosenRelationAction), 32, 24); 133 topLine.add(downloadButton, GBC.std()); 134 topLine.add(new JButton(new EditChosenRelationAction(chosenRelation)), GBC.eol().fill(GBC.VERTICAL)); 135 136 chosenRelationPanel.add(topLine, BorderLayout.CENTER); 137 chosenRelationPanel.add(rolePanel, BorderLayout.SOUTH); 117 chosenRelationPanel.add(downloadButton, GBC.std()); 118 chosenRelationPanel.add(new JButton(new EditChosenRelationAction(chosenRelation)), GBC.eol().fill(GBC.VERTICAL)); 119 138 120 rcPanel.add(chosenRelationPanel, BorderLayout.NORTH); 139 121 140 rolePanel.addComponentListener(new ComponentAdapter() { 141 @Override 142 public void componentHidden( ComponentEvent e ) { 143 Main.pref.put(PREF_ROLEBOX + ".visible", false); 144 toggleRolePanelButtonTop.setVisible(true); 145 } 146 147 @Override 148 public void componentShown( ComponentEvent e ) { 149 Main.pref.put(PREF_ROLEBOX + ".visible", true); 150 toggleRolePanelButtonTop.setVisible(false); 151 } 152 }); 153 rolePanel.setVisible(Main.pref.getBoolean(PREF_ROLEBOX + ".visible", true)); 154 toggleRolePanelButtonTop.setVisible(!rolePanel.isVisible()); 155 lastSelectedRole = Main.pref.get(PREF_ROLEBOX + ".lastrole"); 122 roleBox.addPropertyChangeListener("enabled", new PropertyChangeListener() { 123 public void propertyChange( PropertyChangeEvent evt ) { 124 boolean showRoleBox = roleBox.isEnabled(); 125 roleBox.setVisible(showRoleBox); 126 chosenRelationComponent.setVisible(!showRoleBox); 127 } 128 }); 156 129 157 130 sortAndFixAction.addPropertyChangeListener(new PropertyChangeListener() { … … 277 250 if( Main.main.getCurrentDataSet() != null ) 278 251 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 279 updateRoleIndicator();280 252 roleBoxModel.update(); 281 253 // ? 282 }283 284 private void updateRoleIndicator() {285 if( crRoleIndicator == null )286 return;287 String role = "";288 if( chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) {289 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();290 for( RelationMember m : chosenRelation.get().getMembers() ) {291 if( selected.contains(m.getMember()) ) {292 if( role.length() == 0 && m.getRole() != null )293 role = m.getRole();294 else if( !role.equals(m.getRole()) ) {295 role = tr("<different>");296 break;297 }298 }299 }300 }301 crRoleIndicator.setText(role);302 254 } 303 255 … … 305 257 if( !isVisible() || relationsData == null ) 306 258 return; 307 updateRoleIndicator();308 259 roleBoxModel.update(); 309 260 // repopulate relations table … … 431 382 @Override 432 383 public void mouseClicked( MouseEvent e ) { 384 if( e.isControlDown() || !(e.getComponent() instanceof JComboBox ) ) // do not use left click handler on combo box 433 385 if( SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main.map.mapView.getEditLayer() != null ) { 434 386 Main.map.mapView.getEditLayer().data.setSelected(chosenRelation.get()); … … 456 408 public ChosenRelationPopupMenu() { 457 409 add(new SelectMembersAction(chosenRelation)); 410 add(new SelectRelationAction(chosenRelation)); 458 411 add(new DeleteChosenRelationAction(chosenRelation)); 459 412 add(new DownloadParentsAction(chosenRelation)); … … 461 414 add(new SelectInRelationPanelAction(chosenRelation)); 462 415 add(new RelationHelpAction(chosenRelation)); 463 }464 }465 466 private class TogglePanelAction extends AbstractAction {467 private JComponent component;468 469 public TogglePanelAction( JPanel panel ) {470 super();471 this.component = panel;472 init();473 if( getValue(Action.SMALL_ICON) == null )474 putValue(Action.NAME, "R");475 }476 477 protected void init() {}478 479 public void actionPerformed( ActionEvent e ) {480 Main.pref.put(PREF_ROLEBOX + ".visible", !component.isVisible());481 component.setVisible(!component.isVisible());482 416 } 483 417 } … … 504 438 } 505 439 506 private class ApplyNewRoleAction extends AbstractAction {507 public ApplyNewRoleAction() {508 super(null, ImageProvider.get("apply"));509 putValue(Action.SHORT_DESCRIPTION, tr("Apply chosen role to selected relation members"));510 }511 512 public void actionPerformed( ActionEvent e ) {513 String selectedRole = roleBoxModel.getSelectedRole();514 if( selectedRole != null )515 applyRoleToSelection(selectedRole.toString().trim());516 }517 }518 519 private class EnterNewRoleAction extends AbstractAction {520 public EnterNewRoleAction() {521 super();522 putValue(Action.NAME, "…");523 // putValue(SMALL_ICON, ImageProvider.get("dialogs/mappaint", "pencil"));524 putValue(SHORT_DESCRIPTION, tr("Enter new role for selected relation members"));525 }526 527 public void actionPerformed( ActionEvent e ) {528 String role = askForRoleName();529 if( role != null )530 applyRoleToSelection(role);531 }532 }533 534 440 private static class RelationTableModel extends DefaultTableModel { 535 441 @Override … … 590 496 private List<String> roles = new ArrayList<String>(); 591 497 private int selectedIndex = -1; 592 593 public RoleComboBoxModel() { 498 private JComboBox combobox; 499 private String membersRole; 500 private final String EMPTY_ROLE = tr("<empty>"); 501 private final String ANOTHER_ROLE = tr("another..."); 502 503 public RoleComboBoxModel( JComboBox combobox ) { 594 504 super(); 505 this.combobox = combobox; 595 506 update(); 596 507 } 597 508 598 509 public void update() { 599 String currentRole = getSelectedRole(); 510 membersRole = getSelectedMembersRoleIntl(); 511 if( membersRole == null ) { 512 if( combobox.isEnabled() ) 513 combobox.setEnabled(false); 514 return; 515 } 516 if( !combobox.isEnabled() ) 517 combobox.setEnabled(true); 518 600 519 List<String> items = new ArrayList<String>(); 601 items.add(" ");602 520 if( chosenRelation != null && chosenRelation.get() != null ) { 603 521 if( chosenRelation.isMultipolygon() ) { … … 611 529 } 612 530 for( RelationMember m : chosenRelation.get().getMembers() ) 613 if( !items.contains(m.getRole()) )531 if( m.getRole().length() > 0 && !items.contains(m.getRole()) ) 614 532 items.add(m.getRole()); 615 533 } 616 i f( currentRole != null && currentRole.length() > 1 ) {617 lastSelectedRole = currentRole;618 Main.pref.put(PREF_ROLEBOX + ".lastrole", lastSelectedRole);619 }534 items.add(EMPTY_ROLE); 535 if( !items.contains(membersRole) ) 536 items.add(0, membersRole); 537 items.add(ANOTHER_ROLE); 620 538 roles = Collections.unmodifiableList(items); 621 fireContentsChanged(this, 0, getSize()); 622 if( lastSelectedRole != null && items.contains(lastSelectedRole) ) 623 setSelectedItem(lastSelectedRole); 624 // todo: do we really want empty role as default one? Maybe, store last selected role in preferences 539 540 if( membersRole != null ) 541 setSelectedItem(membersRole); 542 else 543 fireContentsChanged(this, -1, -1); 544 combobox.repaint(); 545 } 546 547 public String getSelectedMembersRole() { 548 return membersRole == EMPTY_ROLE ? "" : membersRole; 549 } 550 551 public boolean isAnotherRoleSelected() { 552 return getSelectedRole() != null && getSelectedRole().equals(ANOTHER_ROLE); 553 } 554 555 private String getSelectedMembersRoleIntl() { 556 String role = null; 557 if( chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) { 558 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 559 for( RelationMember m : chosenRelation.get().getMembers() ) { 560 if( selected.contains(m.getMember()) ) { 561 if( role == null ) 562 role = m.getRole(); 563 else if( m.getRole() != null && !role.equals(m.getRole()) ) { 564 role = tr("<different>"); 565 break; 566 } 567 } 568 } 569 } 570 return role == null ? null : role.length() == 0 ? EMPTY_ROLE : role; 625 571 } 626 572 … … 642 588 643 589 public void setSelectedItem( Object anItem ) { 644 selectedIndex = anItem == null ? -1 : roles.indexOf(anItem); 590 int newIndex = anItem == null ? -1 : roles.indexOf(anItem); 591 if( newIndex != selectedIndex ) { 592 selectedIndex = newIndex; 593 fireContentsChanged(this, -1, -1); 594 } 645 595 } 646 596 647 597 public Object getSelectedItem() { 648 return getSelectedRole();598 return selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex); 649 599 } 650 600 651 601 public String getSelectedRole() { 652 return selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex); 602 String role = selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex); 603 return role != null && role.equals(EMPTY_ROLE) ? "" : role; 653 604 } 654 605 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java
r25705 r25709 69 69 for( Way w : poly.ways ) 70 70 rel.addMember(new RelationMember("inner", w)); 71 if( isBoundary )72 addBoundaryMembers(rel);73 71 List<Command> list = removeTagsFromInnerWays(rel); 74 if( isBoundary ) 72 if( isBoundary ) { 75 73 if( !askForAdminLevelAndName(rel) ) 76 74 return; 77 if( isBoundary && getPref("boundaryways") ) 78 list.addAll(fixWayTagsForBoundary(rel)); 75 addBoundaryMembers(rel); 76 if( getPref("boundaryways") ) 77 list.addAll(fixWayTagsForBoundary(rel)); 78 } 79 79 list.add(new AddCommand(rel)); 80 80 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), list));
Note:
See TracChangeset
for help on using the changeset viewer.