Changeset 1830 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-25T11:51:15+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/relation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1828 r1830 586 586 } 587 587 588 /** 589 * This function saves the user's changes. Must be invoked manually. 590 */ 591 protected void applyChanges() { 592 if (getRelation() == null) { 588 @Override 589 protected Dimension findMaxDialogSize() { 590 // FIXME: Make it remember dialog size 591 return new Dimension(700, 500); 592 } 593 594 /** 595 * Asynchronously download the members of the currently edited relation 596 * 597 */ 598 private void downloadRelationMembers() { 599 if (!memberTableModel.hasIncompleteMembers()) 600 return; 601 Main.worker.submit(new DownloadTask(this)); 602 } 603 604 @Override 605 public void dispose() { 606 selectionTableModel.unregister(); 607 super.dispose(); 608 } 609 610 @Override 611 public void setVisible(boolean b) { 612 super.setVisible(b); 613 if (!b) { 614 dispose(); 615 } 616 } 617 618 class AddSelectedAtStartAction extends AbstractAction implements TableModelListener { 619 public AddSelectedAtStartAction() { 620 putValue(SHORT_DESCRIPTION, 621 tr("Add all primitives selected in the current dataset before the first member")); 622 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copystartright")); 623 // putValue(NAME, tr("Add Selected")); 624 refreshEnabled(); 625 } 626 627 protected void refreshEnabled() { 628 setEnabled(selectionTableModel.getRowCount() > 0); 629 } 630 631 public void actionPerformed(ActionEvent e) { 632 memberTableModel.addMembersAtBeginning(selectionTableModel.getSelection()); 633 } 634 635 public void tableChanged(TableModelEvent e) { 636 refreshEnabled(); 637 } 638 } 639 640 class AddSelectedAtEndAction extends AbstractAction implements TableModelListener { 641 public AddSelectedAtEndAction() { 642 putValue(SHORT_DESCRIPTION, tr("Add all primitives selected in the current dataset after the last member")); 643 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copyendright")); 644 // putValue(NAME, tr("Add Selected")); 645 refreshEnabled(); 646 } 647 648 protected void refreshEnabled() { 649 setEnabled(selectionTableModel.getRowCount() > 0); 650 } 651 652 public void actionPerformed(ActionEvent e) { 653 memberTableModel.addMembersAtEnd(selectionTableModel.getSelection()); 654 } 655 656 public void tableChanged(TableModelEvent e) { 657 refreshEnabled(); 658 } 659 } 660 661 class AddSelectedBeforeSelection extends AbstractAction implements TableModelListener, ListSelectionListener { 662 public AddSelectedBeforeSelection() { 663 putValue(SHORT_DESCRIPTION, 664 tr("Add all primitives selected in the current dataset before the first selected member")); 665 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copybeforecurrentright")); 666 // putValue(NAME, tr("Add Selected")); 667 refreshEnabled(); 668 } 669 670 protected void refreshEnabled() { 671 setEnabled(selectionTableModel.getRowCount() > 0 672 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0); 673 } 674 675 public void actionPerformed(ActionEvent e) { 676 memberTableModel.addMembersBeforeIdx(selectionTableModel.getSelection(), memberTableModel 677 .getSelectionModel().getMinSelectionIndex()); 678 } 679 680 public void tableChanged(TableModelEvent e) { 681 refreshEnabled(); 682 } 683 684 public void valueChanged(ListSelectionEvent e) { 685 refreshEnabled(); 686 } 687 } 688 689 class AddSelectedAfterSelection extends AbstractAction implements TableModelListener, ListSelectionListener { 690 public AddSelectedAfterSelection() { 691 putValue(SHORT_DESCRIPTION, 692 tr("Add all primitives selected in the current dataset after the last selected member")); 693 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copyaftercurrentright")); 694 // putValue(NAME, tr("Add Selected")); 695 refreshEnabled(); 696 } 697 698 protected void refreshEnabled() { 699 setEnabled(selectionTableModel.getRowCount() > 0 700 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0); 701 } 702 703 public void actionPerformed(ActionEvent e) { 704 memberTableModel.addMembersAfterIdx(selectionTableModel.getSelection(), memberTableModel 705 .getSelectionModel().getMaxSelectionIndex()); 706 } 707 708 public void tableChanged(TableModelEvent e) { 709 refreshEnabled(); 710 } 711 712 public void valueChanged(ListSelectionEvent e) { 713 refreshEnabled(); 714 } 715 } 716 717 class RemoveSelectedAction extends AbstractAction implements TableModelListener { 718 public RemoveSelectedAction() { 719 putValue(SHORT_DESCRIPTION, tr("Remove all currently selected objects from relation")); 720 putValue(SMALL_ICON, ImageProvider.get("dialogs", "removeselected")); 721 // putValue(NAME, tr("Remove Selected")); 722 Shortcut.registerShortcut("relationeditor:removeselected", tr("Relation Editor: Remove Selected"), 723 KeyEvent.VK_S, Shortcut.GROUP_MNEMONIC); 724 725 DataSet ds = getLayer().data; 726 setEnabled(ds != null && !ds.getSelected().isEmpty()); 727 } 728 729 public void actionPerformed(ActionEvent e) { 730 memberTableModel.removeMembersReferringTo(selectionTableModel.getSelection()); 731 } 732 733 public void tableChanged(TableModelEvent e) { 734 setEnabled(selectionTableModel.getRowCount() > 0); 735 } 736 } 737 738 class SortAction extends AbstractAction { 739 public SortAction() { 740 putValue(SHORT_DESCRIPTION, tr("Sort the relation members")); 741 putValue(SMALL_ICON, ImageProvider.get("dialogs", "sort")); 742 // putValue(NAME, tr("Sort")); 743 Shortcut.registerShortcut("relationeditor:sort", tr("Relation Editor: Sort"), KeyEvent.VK_T, 744 Shortcut.GROUP_MNEMONIC); 745 //setEnabled(false); 746 } 747 748 public void actionPerformed(ActionEvent e) { 749 memberTableModel.sort(); 750 } 751 } 752 753 class MoveUpAction extends AbstractAction implements ListSelectionListener { 754 public MoveUpAction() { 755 putValue(SHORT_DESCRIPTION, tr("Move the currently selected members up")); 756 putValue(SMALL_ICON, ImageProvider.get("dialogs", "moveup")); 757 // putValue(NAME, tr("Move Up")); 758 Shortcut.registerShortcut("relationeditor:moveup", tr("Relation Editor: Move Up"), KeyEvent.VK_N, 759 Shortcut.GROUP_MNEMONIC); 760 setEnabled(false); 761 } 762 763 public void actionPerformed(ActionEvent e) { 764 memberTableModel.moveUp(memberTable.getSelectedRows()); 765 } 766 767 public void valueChanged(ListSelectionEvent e) { 768 setEnabled(memberTableModel.canMoveUp(memberTable.getSelectedRows())); 769 } 770 } 771 772 class MoveDownAction extends AbstractAction implements ListSelectionListener { 773 public MoveDownAction() { 774 putValue(SHORT_DESCRIPTION, tr("Move the currently selected members down")); 775 putValue(SMALL_ICON, ImageProvider.get("dialogs", "movedown")); 776 // putValue(NAME, tr("Move Down")); 777 Shortcut.registerShortcut("relationeditor:moveup", tr("Relation Editor: Move Down"), KeyEvent.VK_J, 778 Shortcut.GROUP_MNEMONIC); 779 setEnabled(false); 780 } 781 782 public void actionPerformed(ActionEvent e) { 783 memberTableModel.moveDown(memberTable.getSelectedRows()); 784 } 785 786 public void valueChanged(ListSelectionEvent e) { 787 setEnabled(memberTableModel.canMoveDown(memberTable.getSelectedRows())); 788 } 789 } 790 791 class RemoveAction extends AbstractAction implements ListSelectionListener { 792 public RemoveAction() { 793 putValue(SHORT_DESCRIPTION, tr("Remove the member in the current table row from this relation")); 794 putValue(SMALL_ICON, ImageProvider.get("dialogs", "remove")); 795 // putValue(NAME, tr("Remove")); 796 Shortcut.registerShortcut("relationeditor:remove", tr("Relation Editor: Remove"), KeyEvent.VK_J, 797 Shortcut.GROUP_MNEMONIC); 798 setEnabled(false); 799 } 800 801 public void actionPerformed(ActionEvent e) { 802 memberTableModel.remove(memberTable.getSelectedRows()); 803 } 804 805 public void valueChanged(ListSelectionEvent e) { 806 setEnabled(memberTableModel.canRemove(memberTable.getSelectedRows())); 807 } 808 } 809 810 class OKAction extends AbstractAction { 811 /** 812 * apply updates to a new relation 813 */ 814 protected void applyNewRelation() { 593 815 // If the user wanted to create a new relation, but hasn't added any members or 594 816 // tags, don't add an empty relation … … 600 822 Main.main.undoRedo.add(new AddCommand(newRelation)); 601 823 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 602 } else if (!memberTableModel.hasSameMembersAs(getRelation()) || tagEditorModel.isDirty()) { 824 } 825 826 /** 827 * apply updates to an existing relation 828 */ 829 protected void applyExistingRelation() { 603 830 Relation editedRelation = new Relation(getRelation()); 604 831 tagEditorModel.applyToPrimitive(editedRelation); … … 607 834 Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation); 608 835 getLayer().getConflicts().add(conflict); 609 JOptionPane op = new JOptionPane(tr("<html>The relation has changed outside of the editor.<br>" 610 + "Your edit can't be applied directly, a conflict has been created instead.</html>"), 611 JOptionPane.WARNING_MESSAGE); 612 JDialog dialog = op.createDialog(this, tr("Conflict created")); 836 JOptionPane op = new JOptionPane( 837 tr("<html>The relation has changed outside of the editor.<br>" 838 + "Your edits can't be applied directly, a conflict has been created instead.</html>"), 839 JOptionPane.WARNING_MESSAGE 840 ); 841 JDialog dialog = op.createDialog(GenericRelationEditor.this, tr("Conflict created")); 613 842 dialog.setAlwaysOnTop(true); 614 843 dialog.setModal(true); … … 616 845 dialog.setVisible(true); 617 846 } else { 618 Relation clone = new Relation(getRelation()); 619 tagEditorModel.applyToPrimitive(clone); 620 memberTableModel.applyToRelation(clone); 621 Main.main.undoRedo.add(new ChangeCommand(getRelation(), clone)); 847 tagEditorModel.applyToPrimitive(editedRelation); 848 memberTableModel.applyToRelation(editedRelation); 849 Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation)); 622 850 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 623 851 } 624 852 } 625 } 626 627 @Override 628 protected Dimension findMaxDialogSize() { 629 // FIXME: Make it remember dialog size 630 return new Dimension(700, 500); 631 } 632 633 /** 634 * Asynchronously download the members of the currently edited relation 635 * 636 */ 637 private void downloadRelationMembers() { 638 if (!memberTableModel.hasIncompleteMembers()) 639 return; 640 Main.worker.submit(new DownloadTask(this)); 641 } 642 643 @Override 644 public void dispose() { 645 selectionTableModel.unregister(); 646 super.dispose(); 647 } 648 649 @Override 650 public void setVisible(boolean b) { 651 super.setVisible(b); 652 if (!b) { 653 dispose(); 654 } 655 } 656 657 class AddSelectedAtStartAction extends AbstractAction implements TableModelListener { 658 public AddSelectedAtStartAction() { 659 putValue(SHORT_DESCRIPTION, 660 tr("Add all primitives selected in the current dataset before the first member")); 661 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copystartright")); 662 // putValue(NAME, tr("Add Selected")); 663 refreshEnabled(); 664 } 665 666 protected void refreshEnabled() { 667 setEnabled(selectionTableModel.getRowCount() > 0); 668 } 669 670 public void actionPerformed(ActionEvent e) { 671 memberTableModel.addMembersAtBeginning(selectionTableModel.getSelection()); 672 } 673 674 public void tableChanged(TableModelEvent e) { 675 refreshEnabled(); 676 } 677 } 678 679 class AddSelectedAtEndAction extends AbstractAction implements TableModelListener { 680 public AddSelectedAtEndAction() { 681 putValue(SHORT_DESCRIPTION, tr("Add all primitives selected in the current dataset after the last member")); 682 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copyendright")); 683 // putValue(NAME, tr("Add Selected")); 684 refreshEnabled(); 685 } 686 687 protected void refreshEnabled() { 688 setEnabled(selectionTableModel.getRowCount() > 0); 689 } 690 691 public void actionPerformed(ActionEvent e) { 692 memberTableModel.addMembersAtEnd(selectionTableModel.getSelection()); 693 } 694 695 public void tableChanged(TableModelEvent e) { 696 refreshEnabled(); 697 } 698 } 699 700 class AddSelectedBeforeSelection extends AbstractAction implements TableModelListener, ListSelectionListener { 701 public AddSelectedBeforeSelection() { 702 putValue(SHORT_DESCRIPTION, 703 tr("Add all primitives selected in the current dataset before the first selected member")); 704 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copybeforecurrentright")); 705 // putValue(NAME, tr("Add Selected")); 706 refreshEnabled(); 707 } 708 709 protected void refreshEnabled() { 710 setEnabled(selectionTableModel.getRowCount() > 0 711 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0); 712 } 713 714 public void actionPerformed(ActionEvent e) { 715 memberTableModel.addMembersBeforeIdx(selectionTableModel.getSelection(), memberTableModel 716 .getSelectionModel().getMinSelectionIndex()); 717 } 718 719 public void tableChanged(TableModelEvent e) { 720 refreshEnabled(); 721 } 722 723 public void valueChanged(ListSelectionEvent e) { 724 refreshEnabled(); 725 } 726 } 727 728 class AddSelectedAfterSelection extends AbstractAction implements TableModelListener, ListSelectionListener { 729 public AddSelectedAfterSelection() { 730 putValue(SHORT_DESCRIPTION, 731 tr("Add all primitives selected in the current dataset after the last selected member")); 732 putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copyaftercurrentright")); 733 // putValue(NAME, tr("Add Selected")); 734 refreshEnabled(); 735 } 736 737 protected void refreshEnabled() { 738 setEnabled(selectionTableModel.getRowCount() > 0 739 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0); 740 } 741 742 public void actionPerformed(ActionEvent e) { 743 memberTableModel.addMembersAfterIdx(selectionTableModel.getSelection(), memberTableModel 744 .getSelectionModel().getMaxSelectionIndex()); 745 } 746 747 public void tableChanged(TableModelEvent e) { 748 refreshEnabled(); 749 } 750 751 public void valueChanged(ListSelectionEvent e) { 752 refreshEnabled(); 753 } 754 } 755 756 class RemoveSelectedAction extends AbstractAction implements TableModelListener { 757 public RemoveSelectedAction() { 758 putValue(SHORT_DESCRIPTION, tr("Remove all currently selected objects from relation")); 759 putValue(SMALL_ICON, ImageProvider.get("dialogs", "removeselected")); 760 // putValue(NAME, tr("Remove Selected")); 761 Shortcut.registerShortcut("relationeditor:removeselected", tr("Relation Editor: Remove Selected"), 762 KeyEvent.VK_S, Shortcut.GROUP_MNEMONIC); 763 764 DataSet ds = getLayer().data; 765 setEnabled(ds != null && !ds.getSelected().isEmpty()); 766 } 767 768 public void actionPerformed(ActionEvent e) { 769 memberTableModel.removeMembersReferringTo(selectionTableModel.getSelection()); 770 } 771 772 public void tableChanged(TableModelEvent e) { 773 setEnabled(selectionTableModel.getRowCount() > 0); 774 } 775 } 776 777 class SortAction extends AbstractAction { 778 public SortAction() { 779 putValue(SHORT_DESCRIPTION, tr("Sort the relation members")); 780 putValue(SMALL_ICON, ImageProvider.get("dialogs", "sort")); 781 // putValue(NAME, tr("Sort")); 782 Shortcut.registerShortcut("relationeditor:sort", tr("Relation Editor: Sort"), KeyEvent.VK_T, 783 Shortcut.GROUP_MNEMONIC); 784 //setEnabled(false); 785 } 786 787 public void actionPerformed(ActionEvent e) { 788 memberTableModel.sort(); 789 } 790 } 791 792 class MoveUpAction extends AbstractAction implements ListSelectionListener { 793 public MoveUpAction() { 794 putValue(SHORT_DESCRIPTION, tr("Move the currently selected members up")); 795 putValue(SMALL_ICON, ImageProvider.get("dialogs", "moveup")); 796 // putValue(NAME, tr("Move Up")); 797 Shortcut.registerShortcut("relationeditor:moveup", tr("Relation Editor: Move Up"), KeyEvent.VK_N, 798 Shortcut.GROUP_MNEMONIC); 799 setEnabled(false); 800 } 801 802 public void actionPerformed(ActionEvent e) { 803 memberTableModel.moveUp(memberTable.getSelectedRows()); 804 } 805 806 public void valueChanged(ListSelectionEvent e) { 807 setEnabled(memberTableModel.canMoveUp(memberTable.getSelectedRows())); 808 } 809 } 810 811 class MoveDownAction extends AbstractAction implements ListSelectionListener { 812 public MoveDownAction() { 813 putValue(SHORT_DESCRIPTION, tr("Move the currently selected members down")); 814 putValue(SMALL_ICON, ImageProvider.get("dialogs", "movedown")); 815 // putValue(NAME, tr("Move Down")); 816 Shortcut.registerShortcut("relationeditor:moveup", tr("Relation Editor: Move Down"), KeyEvent.VK_J, 817 Shortcut.GROUP_MNEMONIC); 818 setEnabled(false); 819 } 820 821 public void actionPerformed(ActionEvent e) { 822 memberTableModel.moveDown(memberTable.getSelectedRows()); 823 } 824 825 public void valueChanged(ListSelectionEvent e) { 826 setEnabled(memberTableModel.canMoveDown(memberTable.getSelectedRows())); 827 } 828 } 829 830 class RemoveAction extends AbstractAction implements ListSelectionListener { 831 public RemoveAction() { 832 putValue(SHORT_DESCRIPTION, tr("Remove the member in the current table row from this relation")); 833 putValue(SMALL_ICON, ImageProvider.get("dialogs", "remove")); 834 // putValue(NAME, tr("Remove")); 835 Shortcut.registerShortcut("relationeditor:remove", tr("Relation Editor: Remove"), KeyEvent.VK_J, 836 Shortcut.GROUP_MNEMONIC); 837 setEnabled(false); 838 } 839 840 public void actionPerformed(ActionEvent e) { 841 memberTableModel.remove(memberTable.getSelectedRows()); 842 } 843 844 public void valueChanged(ListSelectionEvent e) { 845 setEnabled(memberTableModel.canRemove(memberTable.getSelectedRows())); 846 } 847 } 848 849 class OKAction extends AbstractAction { 853 854 /** 855 * Applies updates 856 */ 857 protected void applyChanges() { 858 if (getRelation() == null) { 859 applyNewRelation(); 860 } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) 861 || tagEditorModel.isDirty()) { 862 applyExistingRelation(); 863 } 864 } 865 850 866 public OKAction() { 851 867 putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog")); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r1829 r1830 64 64 members.clear(); 65 65 if (relation != null && relation.members != null) { 66 members.addAll(relation.members); 66 // make sure we work with clones of the relation members 67 // in the model. 68 members.addAll(new Relation(relation).members); 67 69 } 68 70 fireTableDataChanged(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r1828 r1830 108 108 } 109 109 110 /** 111 * Replies the currently edited relation 112 * 113 * @return the currently edited relation 114 */ 110 115 protected Relation getRelation() { 111 116 return relation; 112 117 } 113 118 119 /** 120 * Replies the {@see OsmDataLayer} in whose context this relation editor is 121 * open 122 * 123 * @return the {@see OsmDataLayer} in whose context this relation editor is 124 * open 125 */ 114 126 protected OsmDataLayer getLayer() { 115 127 return layer; 116 128 } 117 129 130 /** 131 * Replies the state of the edited relation when the editor has been launched 132 * 133 * @return the state of the edited relation when the editor has been launched 134 */ 118 135 protected Relation getRelationSnapshot() { 119 136 return relationSnapshot;
Note:
See TracChangeset
for help on using the changeset viewer.