Changeset 5704 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2013-02-09T18:08:26+01:00 (11 years ago)
Author:
akks
Message:

see #8412, #4828: Add tag and Edit tag dialogs: added context menu
default EN keyboard layout for tag; customize number of recent tags; paste tag/value

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r5697 r5704  
    4242import javax.swing.AbstractAction;
    4343import javax.swing.Action;
     44import javax.swing.BorderFactory;
    4445import javax.swing.Box;
    4546import javax.swing.DefaultListCellRenderer;
    4647import javax.swing.ImageIcon;
     48import javax.swing.JCheckBoxMenuItem;
    4749import javax.swing.JComponent;
    4850import javax.swing.JLabel;
    4951import javax.swing.JList;
     52import javax.swing.JMenuItem;
     53import javax.swing.JOptionPane;
    5054import javax.swing.JPanel;
     55import javax.swing.JPopupMenu;
    5156import javax.swing.KeyStroke;
    5257import javax.swing.table.DefaultTableModel;
     
    6267import org.openstreetmap.josm.data.osm.OsmPrimitive;
    6368import org.openstreetmap.josm.data.osm.Tag;
     69import org.openstreetmap.josm.data.preferences.BooleanProperty;
     70import org.openstreetmap.josm.data.preferences.IntegerProperty;
    6471import org.openstreetmap.josm.gui.ExtendedDialog;
    6572import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     
    6875import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    6976import org.openstreetmap.josm.gui.util.GuiHelper;
     77import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    7078import org.openstreetmap.josm.io.XmlWriter;
    7179import org.openstreetmap.josm.tools.GBC;
    7280import org.openstreetmap.josm.tools.Shortcut;
     81import org.openstreetmap.josm.tools.Utils;
    7382import org.openstreetmap.josm.tools.WindowGeometry;
    7483
     
    96105
    97106    public static final int DEFAULT_LRU_TAGS_NUMBER = 5;
    98     public static final int MAX_LRU_TAGS_NUMBER = 9;
     107    public static final int MAX_LRU_TAGS_NUMBER = 30;
    99108
    100109    // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
     
    250259            keys.setSelectedItem(key);
    251260
     261            p.add(Box.createVerticalStrut(5),GBC.eol());
    252262            p.add(new JLabel(tr("Key")), GBC.std());
    253263            p.add(Box.createHorizontalStrut(10), GBC.std());
     
    266276            values.setSelectedItem(selection);
    267277            values.getEditor().setItem(selection);
     278            p.add(Box.createVerticalStrut(5),GBC.eol());
    268279            p.add(new JLabel(tr("Value")), GBC.std());
    269280            p.add(Box.createHorizontalStrut(10), GBC.std());
     
    364375    }
    365376
     377    public static final BooleanProperty PROPERTY_FIX_TAG_LOCALE = new BooleanProperty("properties.fix-tag-combobox-locale", false);
     378    public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags", DEFAULT_LRU_TAGS_NUMBER);
     379
    366380    abstract class AbstractTagsDialog extends ExtendedDialog {
    367381        AutoCompletingComboBox keys;
    368382        AutoCompletingComboBox values;
     383        Component componentUnderMouse;
    369384       
    370385        public AbstractTagsDialog(Component parent, String title, String[] buttonTexts) {
    371386            super(parent, title, buttonTexts);
     387            addMouseListener(new PopupMenuLauncher(popupMenu));
    372388        }
    373389
     
    392408                    rememberWindowGeometry(geometry);
    393409                }
     410                keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get());
    394411            }
    395412            super.setVisible(visible);
     
    445462           editor.addFocusListener(focus);
    446463           return focus;
    447        }
    448        
     464        }
     465       
     466        protected JPopupMenu popupMenu = new JPopupMenu() {
     467            JCheckBoxMenuItem fixTagLanguageCb = new JCheckBoxMenuItem(
     468                new AbstractAction(tr("Use English language for tag by default")){
     469                public void actionPerformed(ActionEvent e) {
     470                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
     471                    PROPERTY_FIX_TAG_LOCALE.put(sel);
     472                }
     473            });
     474            JMenuItem pasteK = new JMenuItem(
     475                new AbstractAction(tr("Paste tag")){
     476                public void actionPerformed(ActionEvent e) {
     477                    String buf = Utils.getClipboardContent().trim();
     478                    if (buf.isEmpty()) return;
     479                    keys.setSelectedItem(buf);
     480                }
     481            });
     482            JMenuItem pasteV = new JMenuItem(
     483                new AbstractAction(tr("Paste value")){
     484                public void actionPerformed(ActionEvent e) {
     485                    String buf = Utils.getClipboardContent().trim();
     486                    if (buf.isEmpty()) return;
     487                    values.setSelectedItem(buf);
     488                }
     489            });
     490           
     491            {
     492                add(pasteK);
     493                add(pasteV);
     494                addSeparator();
     495                add(fixTagLanguageCb);
     496                fixTagLanguageCb.setState(PROPERTY_FIX_TAG_LOCALE.get());
     497            }
     498        };
     499               
    449500    }
    450501
     
    511562            focus.focusGained(null);
    512563
    513             int recentTagsToShow = Main.pref.getInteger("properties.recently-added-tags", DEFAULT_LRU_TAGS_NUMBER);
     564            int recentTagsToShow = PROPERTY_RECENT_TAGS_NUMBER.get();
    514565            if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) {
    515566                recentTagsToShow = MAX_LRU_TAGS_NUMBER;
     
    532583           
    533584            selectKeysComboBox();
    534         }
    535 
     585           
     586            popupMenu.add(new AbstractAction(tr("Set number of recently added tags")) {
     587                public void actionPerformed(ActionEvent e) {
     588                    selectNumberOfTags();
     589                }
     590            });
     591        }
     592       
     593        private void selectNumberOfTags() {
     594            String s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display"));
     595            if (s!=null) try {
     596                int v = Integer.parseInt(s);
     597                if (v>=0 && v<=MAX_LRU_TAGS_NUMBER) {
     598                    PROPERTY_RECENT_TAGS_NUMBER.put(v);
     599                    return;
     600                }
     601            } catch (NumberFormatException ex) { }
     602            JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER));
     603           
     604        }
     605       
    536606        private void suggestRecentlyAddedTags(JPanel mainPanel, int tagsToShow, final FocusAdapter focus) {
    537607            if (!(tagsToShow > 0 && !recentTags.isEmpty()))
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r5520 r5704  
    88import java.awt.event.FocusEvent;
    99import java.awt.event.FocusListener;
     10import java.awt.im.InputContext;
    1011import java.util.Collection;
     12import java.util.Locale;
    1113
    1214import javax.swing.ComboBoxEditor;
     
    3335
    3436    private int maxTextLength = -1;
     37    private boolean useFixedLocale;
    3538
    3639    /**
     
    272275
    273276    /**
     277     * If the locale is fixed, English keyboard layout will be used by default for this combobox
     278     * all other components can still have different keyboard layout selected
     279     */
     280    public void setFixedLocale(boolean f) {
     281        useFixedLocale = f;
     282        if (useFixedLocale) {
     283            privateInputContext.selectInputMethod(new Locale("en", "US"));
     284        }
     285    }
     286
     287    private static InputContext privateInputContext = InputContext.getInstance();
     288   
     289    @Override
     290    public InputContext getInputContext() {
     291        if (useFixedLocale) {
     292            return privateInputContext;
     293        }
     294        return super.getInputContext();
     295    }
     296
     297    /**
    274298     * ListCellRenderer for AutoCompletingComboBox
    275299     * renders an AutoCompletionListItem by showing only the string value part
Note: See TracChangeset for help on using the changeset viewer.