Changeset 5645 in josm for trunk/src/org


Ignore:
Timestamp:
2012-12-29T07:27:52+01:00 (11 years ago)
Author:
akks
Message:

fix #8301 (Exception while editing key value); Shift-Enter in Add Tag dialog adds tag without closing, see #8300

File:
1 edited

Legend:

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

    r5642 r5645  
    88import java.awt.Component;
    99import java.awt.Cursor;
    10 import java.awt.Dialog;
    11 import java.awt.Dimension;
    1210import java.awt.FlowLayout;
    1311import java.awt.Font;
     
    2119import java.awt.event.FocusAdapter;
    2220import java.awt.event.FocusEvent;
     21import java.awt.event.InputEvent;
    2322import java.awt.event.KeyEvent;
    2423import java.awt.event.MouseAdapter;
    2524import java.awt.event.MouseEvent;
    2625import java.awt.image.BufferedImage;
     26import java.security.KeyStore;
    2727import java.util.ArrayList;
    2828import java.util.Arrays;
     
    3737import java.util.Map;
    3838import java.util.Vector;
     39import javax.swing.AbstractAction;
    3940import javax.swing.Action;
    4041import javax.swing.Box;
     
    4243import javax.swing.ImageIcon;
    4344import javax.swing.JComponent;
    44 import javax.swing.JDialog;
    4545import javax.swing.JLabel;
    4646import javax.swing.JList;
    4747import javax.swing.JOptionPane;
    4848import javax.swing.JPanel;
     49import javax.swing.KeyStroke;
    4950import javax.swing.table.DefaultTableModel;
    5051import javax.swing.text.JTextComponent;
     
    6667import org.openstreetmap.josm.tools.GBC;
    6768import org.openstreetmap.josm.tools.Shortcut;
    68 import org.openstreetmap.josm.tools.WindowGeometry;
    6969
    7070/**
     
    7575    private final Map<String, Map<String, Integer>> valueCount;
    7676
     77    // Selection that we are editing by using both dialogs
     78    Collection<OsmPrimitive> sel;
     79   
    7780    private String changedKey;
    78 
    79    
    8081    private String objKey;
    8182
     
    8687    };
    8788
    88     Collection<OsmPrimitive> sel;
    89        
    90             private String lastAddKey = null;
    91         private String lastAddValue = null;
    92 
    93         public static final int DEFAULT_LRU_TAGS_NUMBER = 5;
    94         public static final int MAX_LRU_TAGS_NUMBER = 9;
    95 
    96         // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
    97         private final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) {
    98             @Override
    99             protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) {
    100                 return size() > MAX_LRU_TAGS_NUMBER;
    101             }
    102         };
     89    private String lastAddKey = null;
     90    private String lastAddValue = null;
     91
     92    public static final int DEFAULT_LRU_TAGS_NUMBER = 5;
     93    public static final int MAX_LRU_TAGS_NUMBER = 9;
     94
     95    // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
     96    private final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) {
     97        @Override
     98        protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) {
     99            return size() > MAX_LRU_TAGS_NUMBER;
     100        }
     101    };
    103102
    104103    TagEditHelper(DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) {
     
    139138    public void editProperty(final int row) {
    140139        changedKey = null;
    141         Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     140        sel = Main.main.getCurrentDataSet().getSelected();
    142141        if (sel.isEmpty()) return;
    143142
     
    472471                recentTagsToShow = MAX_LRU_TAGS_NUMBER;
    473472            }
     473           
     474            // Add tag on Shift-Enter
     475            mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     476                        KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK), "addAndContinue");
     477                mainPanel.getActionMap().put("addAndContinue", new AbstractAction() {
     478                    @Override
     479                    public void actionPerformed(ActionEvent e) {
     480                        performTagAdding();
     481                    }
     482                });
     483                   
    474484            suggestRecentlyAddedTags(mainPanel, recentTagsToShow, focus);
    475485           
Note: See TracChangeset for help on using the changeset viewer.