- Timestamp:
- 2016-01-30T00:54:35+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r9576 r9683 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 … … 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(); … … 645 646 }); 646 647 647 suggestRecentlyAddedTags(mainPanel , focus);648 suggestRecentlyAddedTags(mainPanel); 648 649 649 650 mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill()); … … 656 657 public void actionPerformed(ActionEvent e) { 657 658 selectNumberOfTags(); 659 suggestRecentlyAddedTags(mainPanel); 658 660 } 659 661 }); … … 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); 711 } 712 JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER)); 713 } 714 715 protected void suggestRecentlyAddedTags(JPanel mainPanel, final FocusAdapter focus) { 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)); 717 } 718 } 719 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. … … 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"; … … 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()) { … … 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 }
Note:
See TracChangeset
for help on using the changeset viewer.