diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java b/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
index b7ffcc6..38d625b 100644
|
a
|
b
|
public class TagEditHelper {
|
| 573 | 573 | protected class AddTagsDialog extends AbstractTagsDialog { |
| 574 | 574 | private final List<JosmAction> recentTagsActions = new ArrayList<>(); |
| 575 | 575 | protected final transient FocusAdapter focus; |
| | 576 | private JPanel recentTagsPanel; |
| 576 | 577 | |
| 577 | 578 | // Counter of added commands for possible undo |
| 578 | 579 | private int commandCount; |
| … |
… |
public class TagEditHelper {
|
| 583 | 584 | setCancelButton(2); |
| 584 | 585 | configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */); |
| 585 | 586 | |
| 586 | | JPanel mainPanel = new JPanel(new GridBagLayout()); |
| | 587 | final JPanel mainPanel = new JPanel(new GridBagLayout()); |
| 587 | 588 | keys = new AutoCompletingComboBox(); |
| 588 | 589 | values = new AutoCompletingComboBox(); |
| 589 | 590 | |
| … |
… |
public class TagEditHelper {
|
| 644 | 645 | } |
| 645 | 646 | }); |
| 646 | 647 | |
| 647 | | suggestRecentlyAddedTags(mainPanel, focus); |
| | 648 | suggestRecentlyAddedTags(mainPanel); |
| 648 | 649 | |
| 649 | 650 | mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill()); |
| 650 | 651 | setContent(mainPanel, false); |
| … |
… |
public class TagEditHelper {
|
| 655 | 656 | @Override |
| 656 | 657 | public void actionPerformed(ActionEvent e) { |
| 657 | 658 | selectNumberOfTags(); |
| | 659 | suggestRecentlyAddedTags(mainPanel); |
| 658 | 660 | } |
| 659 | 661 | }); |
| 660 | 662 | JCheckBoxMenuItem rememberLastTags = new JCheckBoxMenuItem( |
| … |
… |
public class TagEditHelper {
|
| 696 | 698 | } |
| 697 | 699 | |
| 698 | 700 | protected void selectNumberOfTags() { |
| 699 | | String s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display")); |
| 700 | | if (s == null) { |
| 701 | | return; |
| 702 | | } |
| 703 | | try { |
| 704 | | int v = Integer.parseInt(s); |
| 705 | | if (v >= 0 && v <= MAX_LRU_TAGS_NUMBER) { |
| 706 | | PROPERTY_RECENT_TAGS_NUMBER.put(v); |
| | 701 | String s = String.format("%d", PROPERTY_RECENT_TAGS_NUMBER.get()); |
| | 702 | while (true) { |
| | 703 | s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display"), s); |
| | 704 | if (s == null) { |
| 707 | 705 | return; |
| 708 | 706 | } |
| 709 | | } catch (NumberFormatException ex) { |
| 710 | | Main.warn(ex); |
| | 707 | try { |
| | 708 | int v = Integer.parseInt(s); |
| | 709 | if (v >= 0 && v <= MAX_LRU_TAGS_NUMBER) { |
| | 710 | PROPERTY_RECENT_TAGS_NUMBER.put(v); |
| | 711 | return; |
| | 712 | } |
| | 713 | } catch (NumberFormatException ex) { |
| | 714 | Main.warn(ex); |
| | 715 | } |
| | 716 | JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER)); |
| 711 | 717 | } |
| 712 | | JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER)); |
| 713 | 718 | } |
| 714 | 719 | |
| 715 | | protected void suggestRecentlyAddedTags(JPanel mainPanel, final FocusAdapter focus) { |
| | 720 | protected void suggestRecentlyAddedTags(JPanel mainPanel) { |
| | 721 | |
| | 722 | if (recentTagsPanel == null) { |
| | 723 | recentTagsPanel = new JPanel(new GridBagLayout()); |
| | 724 | suggestRecentlyAddedTags(); |
| | 725 | mainPanel.add(recentTagsPanel, GBC.eol().fill(GBC.HORIZONTAL)); |
| | 726 | } else { |
| | 727 | Dimension panelOldSize = panelOldSize = recentTagsPanel.getPreferredSize(); |
| | 728 | recentTagsPanel.removeAll(); |
| | 729 | suggestRecentlyAddedTags(); |
| | 730 | Dimension panelNewSize = recentTagsPanel.getPreferredSize(); |
| | 731 | Dimension dialogOldSize = getMinimumSize(); |
| | 732 | Dimension dialogNewSize = new Dimension(dialogOldSize.width, dialogOldSize.height-panelOldSize.height+panelNewSize.height); |
| | 733 | setMinimumSize(dialogNewSize); |
| | 734 | setPreferredSize(dialogNewSize); |
| | 735 | setSize(dialogNewSize); |
| | 736 | revalidate(); |
| | 737 | repaint(); |
| | 738 | } |
| | 739 | } |
| | 740 | |
| | 741 | protected void suggestRecentlyAddedTags() { |
| 716 | 742 | final int tagsToShow = Math.min(PROPERTY_RECENT_TAGS_NUMBER.get(), MAX_LRU_TAGS_NUMBER); |
| 717 | 743 | if (!(tagsToShow > 0 && !recentTags.isEmpty())) |
| 718 | 744 | return; |
| 719 | | |
| 720 | | mainPanel.add(new JLabel(tr("Recently added tags")), GBC.eol()); |
| | 745 | recentTagsPanel.add(new JLabel(tr("Recently added tags")), GBC.eol()); |
| 721 | 746 | |
| 722 | 747 | int count = 1; |
| 723 | | // We store the maximum number (9) of recent tags to allow dynamic change of number of tags shown in the preferences. |
| | 748 | // We store the maximum number of recent tags to allow dynamic change of number of tags shown in the preferences. |
| 724 | 749 | // This implies to iterate in descending order, as the oldest elements will only be removed after we reach the maximum |
| 725 | 750 | // number and not the number of tags to show. |
| 726 | 751 | // However, as Set does not allow to iterate in descending order, we need to copy its elements into a List we can access |
| … |
… |
public class TagEditHelper {
|
| 777 | 802 | } |
| 778 | 803 | GridBagConstraints gbc = new GridBagConstraints(); |
| 779 | 804 | gbc.ipadx = 5; |
| 780 | | mainPanel.add(new JLabel(action.isEnabled() ? icon : GuiHelper.getDisabledIcon(icon)), gbc); |
| | 805 | recentTagsPanel.add(new JLabel(action.isEnabled() ? icon : GuiHelper.getDisabledIcon(icon)), gbc); |
| 781 | 806 | // Create tag label |
| 782 | 807 | final String color = action.isEnabled() ? "" : "; color:gray"; |
| 783 | 808 | final JLabel tagLabel = new JLabel("<html>" |
| … |
… |
public class TagEditHelper {
|
| 789 | 814 | tagLabel.setFont(tagLabel.getFont().deriveFont(Font.PLAIN)); |
| 790 | 815 | if (action.isEnabled() && sc != null && scShift != null) { |
| 791 | 816 | // Register action |
| 792 | | mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "choose"+count); |
| 793 | | mainPanel.getActionMap().put("choose"+count, action); |
| 794 | | mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scShift.getKeyStroke(), "apply"+count); |
| 795 | | mainPanel.getActionMap().put("apply"+count, actionShift); |
| | 817 | recentTagsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "choose"+count); |
| | 818 | recentTagsPanel.getActionMap().put("choose"+count, action); |
| | 819 | recentTagsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scShift.getKeyStroke(), "apply"+count); |
| | 820 | recentTagsPanel.getActionMap().put("apply"+count, actionShift); |
| 796 | 821 | } |
| 797 | 822 | if (action.isEnabled()) { |
| 798 | 823 | // Make the tag label clickable and set tooltip to the action description (this displays also the keyboard shortcut) |
| … |
… |
public class TagEditHelper {
|
| 822 | 847 | // Finally add label to the resulting panel |
| 823 | 848 | JPanel tagPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
| 824 | 849 | tagPanel.add(tagLabel); |
| 825 | | mainPanel.add(tagPanel, GBC.eol().fill(GBC.HORIZONTAL)); |
| | 850 | recentTagsPanel.add(tagPanel, GBC.eol().fill(GBC.HORIZONTAL)); |
| 826 | 851 | } |
| 827 | 852 | } |
| 828 | 853 | |