Changeset 25704 in osm for applications/editors/josm
- Timestamp:
- 2011-03-25T09:47:31+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/TODO
r25702 r25704 12 12 - Solve width problem for narrows buttons when "fix" and "download" appear simultaneously 13 13 - Sort relation members button (now it's just role fixer) 14 - Show role panel only when relation members are selected 15 - Rethink role panel. Maybe, replace chosen relation title with role combobox? 14 16 15 17 == RELEASE == -
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25698 r25704 66 66 private MultipolygonSettingsPopup multiPopupMenu; 67 67 private JLabel crRoleIndicator; 68 private AutoCompletingComboBox roleBox;68 private RoleComboBoxModel roleBoxModel; 69 69 private String lastSelectedRole; 70 70 … … 111 111 crRoleIndicator = new JLabel(); 112 112 rolePanel.add(crRoleIndicator, GBC.std().insets(5, 0, 5, 0)); 113 roleBox = new AutoCompletingComboBox();114 roleBox.setEditable(false);113 roleBoxModel = new RoleComboBoxModel(); 114 JComboBox roleBox = new JComboBox(roleBoxModel); 115 115 rolePanel.add(roleBox, GBC.std().fill(GBC.HORIZONTAL)); 116 116 rolePanel.add(sizeButton(new JButton(new ApplyNewRoleAction()), 40, 20), GBC.std()); … … 278 278 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 279 279 updateRoleIndicator(); 280 updateRoleAutoCompletionList();280 roleBoxModel.update(); 281 281 // ? 282 282 } … … 306 306 return; 307 307 updateRoleIndicator(); 308 roleBoxModel.update(); 308 309 // repopulate relations table 309 310 relationsData.setRowCount(0); … … 383 384 } 384 385 385 private void updateRoleAutoCompletionList() {386 String currentRole = roleBox.getSelectedItem() == null ? null : ((AutoCompletionListItem)roleBox.getSelectedItem()).getValue();387 List<String> items = new ArrayList<String>();388 items.add(" ");389 if( chosenRelation != null && chosenRelation.get() != null ) {390 if( chosenRelation.isMultipolygon() ) {391 items.add("outer");392 items.add("inner");393 }394 if( chosenRelation.get().get("type") != null ) {395 List<String> values = possibleRoles.get(chosenRelation.get().get("type"));396 if( values != null )397 items.addAll(values);398 }399 for( RelationMember m : chosenRelation.get().getMembers() )400 if( !items.contains(m.getRole()) )401 items.add(m.getRole());402 }403 if( currentRole != null && currentRole.length() > 1 ) {404 lastSelectedRole = currentRole;405 Main.pref.put(PREF_ROLEBOX + ".lastrole", lastSelectedRole);406 }407 roleBox.setPossibleItems(items);408 if( lastSelectedRole != null && items.contains(lastSelectedRole) )409 roleBox.setSelectedItem(lastSelectedRole);410 // todo: do we really want empty role as default one? Maybe, store last selected role in preferences411 }412 413 386 private String askForRoleName() { 414 387 JPanel panel = new JPanel(new GridBagLayout()); 415 388 389 List<String> items = new ArrayList<String>(); 390 for( String role : roleBoxModel.getRoles() ) { 391 if( role.length() > 1 ) 392 items.add(role); 393 } 416 394 final AutoCompletingComboBox role = new AutoCompletingComboBox(); 417 List<AutoCompletionListItem> items = new ArrayList<AutoCompletionListItem>(); 418 for( int i = 0; i < roleBox.getModel().getSize(); i++ ) { 419 final AutoCompletionListItem item = (AutoCompletionListItem)roleBox.getModel().getElementAt(i); 420 if( item.getValue().length() > 1 ) 421 items.add(item); 422 } 423 role.setPossibleACItems(items); 395 role.setPossibleItems(items); 424 396 role.setEditable(true); 425 397 … … 514 486 if( chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) { 515 487 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 516 Relation r = new Relation(chosenRelation.get());488 Relation r = chosenRelation.get(); 517 489 List<Command> commands = new ArrayList<Command>(); 518 490 for( int i = 0; i < r.getMembersCount(); i++ ) { … … 520 492 if( selected.contains(m.getMember()) ) { 521 493 if( !role.equals(m.getRole()) ) { 522 r.setMember(i, new RelationMember(role, m.getMember()));494 // r.setMember(i, new RelationMember(role, m.getMember())); 523 495 commands.add(new ChangeRelationMemberRoleCommand(r, i, role)); 524 496 } … … 526 498 } 527 499 if( !commands.isEmpty() ) { 528 Main.main.undoRedo.add(new ChangeCommand(chosenRelation.get(), r));529 //Main.main.undoRedo.add(new SequenceCommand(tr("Change relation member roles to {0}", role), commands));500 // Main.main.undoRedo.add(new ChangeCommand(chosenRelation.get(), r)); 501 Main.main.undoRedo.add(new SequenceCommand(tr("Change relation member roles to {0}", role), commands)); 530 502 } 531 503 } … … 539 511 540 512 public void actionPerformed( ActionEvent e ) { 541 Object selectedItem = roleBox == null ? null : roleBox.getSelectedItem(); 542 if( selectedItem != null ) { 543 if( selectedItem instanceof AutoCompletionListItem ) 544 selectedItem = ((AutoCompletionListItem)selectedItem).getValue(); 545 applyRoleToSelection(selectedItem.toString().trim()); 546 } 513 String selectedRole = roleBoxModel.getSelectedRole(); 514 if( selectedRole != null ) 515 applyRoleToSelection(selectedRole.toString().trim()); 547 516 } 548 517 } … … 617 586 } 618 587 } 588 589 private class RoleComboBoxModel extends AbstractListModel implements ComboBoxModel { 590 private List<String> roles = new ArrayList<String>(); 591 private int selectedIndex = -1; 592 593 public RoleComboBoxModel() { 594 super(); 595 update(); 596 } 597 598 public void update() { 599 String currentRole = getSelectedRole(); 600 List<String> items = new ArrayList<String>(); 601 items.add(" "); 602 if( chosenRelation != null && chosenRelation.get() != null ) { 603 if( chosenRelation.isMultipolygon() ) { 604 items.add("outer"); 605 items.add("inner"); 606 } 607 if( chosenRelation.get().get("type") != null ) { 608 List<String> values = possibleRoles.get(chosenRelation.get().get("type")); 609 if( values != null ) 610 items.addAll(values); 611 } 612 for( RelationMember m : chosenRelation.get().getMembers() ) 613 if( !items.contains(m.getRole()) ) 614 items.add(m.getRole()); 615 } 616 if( currentRole != null && currentRole.length() > 1 ) { 617 lastSelectedRole = currentRole; 618 Main.pref.put(PREF_ROLEBOX + ".lastrole", lastSelectedRole); 619 } 620 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 625 } 626 627 public List<String> getRoles() { 628 return roles; 629 } 630 631 public int getSize() { 632 return roles.size(); 633 } 634 635 public Object getElementAt( int index ) { 636 return getRole(index); 637 } 638 639 public String getRole( int index ) { 640 return roles.get(index); 641 } 642 643 public void setSelectedItem( Object anItem ) { 644 selectedIndex = anItem == null ? -1 : roles.indexOf(anItem); 645 } 646 647 public Object getSelectedItem() { 648 return getSelectedRole(); 649 } 650 651 public String getSelectedRole() { 652 return selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex); 653 } 654 } 619 655 }
Note:
See TracChangeset
for help on using the changeset viewer.