Changeset 9683 in josm


Ignore:
Timestamp:
2016-01-30T00:54:35+01:00 (8 years ago)
Author:
bastiK
Message:

applied #12421 - fixed dialog to set number of recently added tags (patch by kolesar)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r9576 r9683  
    574574        private final List<JosmAction> recentTagsActions = new ArrayList<>();
    575575        protected final transient FocusAdapter focus;
     576        private JPanel recentTagsPanel;
    576577
    577578        // Counter of added commands for possible undo
     
    584585            configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */);
    585586
    586             JPanel mainPanel = new JPanel(new GridBagLayout());
     587            final JPanel mainPanel = new JPanel(new GridBagLayout());
    587588            keys = new AutoCompletingComboBox();
    588589            values = new AutoCompletingComboBox();
     
    645646                });
    646647
    647             suggestRecentlyAddedTags(mainPanel, focus);
     648            suggestRecentlyAddedTags(mainPanel);
    648649
    649650            mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill());
     
    656657                public void actionPerformed(ActionEvent e) {
    657658                    selectNumberOfTags();
     659                    suggestRecentlyAddedTags(mainPanel);
    658660                }
    659661            });
     
    697699
    698700        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) {
    707705                    return;
    708706                }
    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() {
    716742            final int tagsToShow = Math.min(PROPERTY_RECENT_TAGS_NUMBER.get(), MAX_LRU_TAGS_NUMBER);
    717743            if (!(tagsToShow > 0 && !recentTags.isEmpty()))
    718744                return;
    719 
    720             mainPanel.add(new JLabel(tr("Recently added tags")), GBC.eol());
     745            recentTagsPanel.add(new JLabel(tr("Recently added tags")), GBC.eol());
    721746
    722747            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.
    724749            // This implies to iterate in descending order, as the oldest elements will only be removed after we reach the maximum
    725750            // number and not the number of tags to show.
     
    778803                GridBagConstraints gbc = new GridBagConstraints();
    779804                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);
    781806                // Create tag label
    782807                final String color = action.isEnabled() ? "" : "; color:gray";
     
    790815                if (action.isEnabled() && sc != null && scShift != null) {
    791816                    // 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);
    796821                }
    797822                if (action.isEnabled()) {
     
    823848                JPanel tagPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    824849                tagPanel.add(tagLabel);
    825                 mainPanel.add(tagPanel, GBC.eol().fill(GBC.HORIZONTAL));
     850                recentTagsPanel.add(tagPanel, GBC.eol().fill(GBC.HORIZONTAL));
    826851            }
    827852        }
Note: See TracChangeset for help on using the changeset viewer.