Ticket #7671: 7671.patch

File 7671.patch, 4.8 KB (added by simon04, 12 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
    index 9075624..825af36 100644
    a b import java.awt.event.ActionEvent;  
    1818import java.awt.event.ActionListener;
    1919import java.awt.event.FocusAdapter;
    2020import java.awt.event.FocusEvent;
    21 import java.awt.event.InputEvent;
    2221import java.awt.event.KeyEvent;
    2322import java.awt.event.MouseAdapter;
    2423import java.awt.event.MouseEvent;
    import java.util.EnumSet;  
    3433import java.util.HashMap;
    3534import java.util.HashSet;
    3635import java.util.Iterator;
     36import java.util.LinkedHashMap;
    3737import java.util.LinkedList;
    3838import java.util.List;
    3939import java.util.Map;
    import javax.swing.AbstractAction;  
    4747import javax.swing.Action;
    4848import javax.swing.Box;
    4949import javax.swing.DefaultListCellRenderer;
    50 import javax.swing.InputMap;
    5150import javax.swing.JComboBox;
    5251import javax.swing.JComponent;
    5352import javax.swing.JDialog;
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    451450
    452451    private static String lastAddKey = null;
    453452    private static String lastAddValue = null;
     453    // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
     454    private static final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(5, 1.1f, true);
     455
    454456    /**
    455457     * Open the add selection dialog and add a new key/value to the table (and
    456458     * to the dataset, of course).
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    461463        Collection<OsmPrimitive> sel = ds.getSelected();
    462464        if (sel.isEmpty()) return;
    463465
    464         JPanel p = new JPanel(new BorderLayout());
     466        JPanel p = new JPanel(new GridBagLayout());
    465467        p.add(new JLabel("<html>"+trn("This will change up to {0} object.",
    466468                "This will change up to {0} objects.", sel.size(),sel.size())
    467                 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH);
     469                +"<br><br>"+tr("Please select a key")), GBC.eol());
    468470        final AutoCompletingComboBox keys = new AutoCompletingComboBox();
    469471        AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager();
    470472        List<AutoCompletionListItem> keyList = autocomplete.getKeys();
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    492494        keys.setPossibleACItems(keyList);
    493495        keys.setEditable(true);
    494496
    495         p.add(keys, BorderLayout.CENTER);
     497        p.add(keys, GBC.eop().fill());
    496498
    497         JPanel p2 = new JPanel(new BorderLayout());
    498         p.add(p2, BorderLayout.SOUTH);
    499         p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH);
     499        p.add(new JLabel(tr("Please select a value")), GBC.eol());
    500500        final AutoCompletingComboBox values = new AutoCompletingComboBox();
    501501        values.setEditable(true);
    502         p2.add(values, BorderLayout.CENTER);
     502        p.add(values, GBC.eop().fill());
    503503        if (itemToSelect != null) {
    504504            keys.setSelectedItem(itemToSelect);
    505505            /* don't add single chars, as they are no properly selected */
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    508508            }
    509509        }
    510510
     511        if (!recentTags.isEmpty()) {
     512            p.add(new JLabel(tr("Recently added tags")), GBC.eol());
     513        }
     514        for (final Tag t : recentTags.keySet()) {
     515            final JLabel l = new JLabel("<html>"
     516                    + "<style>td{border:1px solid gray; font-weight:normal;}</style>"
     517                    + "<table><tr><td>" + t.toString() + "</td></tr></table></html>");
     518            l.addMouseListener(new MouseAdapter() {
     519                @Override
     520                public void mouseClicked(MouseEvent e) {
     521                    keys.getEditor().setItem(t.getKey());
     522                    values.getEditor().setItem(t.getValue());
     523                }
     524            });
     525            p.add(l, GBC.eol());
     526        }
     527
    511528        FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator);
    512529        // fire focus event in advance or otherwise the popup list will be too small at first
    513530        focus.focusGained(null);
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    539556            return;
    540557        lastAddKey = key;
    541558        lastAddValue = value;
     559        recentTags.put(new Tag(key, value), null);
    542560        Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
    543561        btnAdd.requestFocusInWindow();
    544562    }