Changeset 7631 in josm


Ignore:
Timestamp:
2014-10-18T20:50:35+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10647 - Shortcuts are activated while in dialogs

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r7021 r7631  
    2828
    2929/**
     30 * Auto-completing ComboBox.
    3031 * @author guilhem.bonnefille@gmail.com
     32 * @since 272
    3133 */
    3234public class AutoCompletingComboBox extends JosmComboBox<AutoCompletionListItem> {
     
    3941    /**
    4042     * Auto-complete a JosmComboBox.
    41      *
    42      * Inspired by http://www.orbital-computer.de/JComboBox/
     43     * <br>
     44     * Inspired by <a href="http://www.orbital-computer.de/JComboBox">Thomas Bierhance example</a>.
    4345     */
    4446    class AutoCompletingComboBoxDocument extends PlainDocument {
     
    4648        private boolean selecting = false;
    4749
     50        /**
     51         * Constructs a new {@code AutoCompletingComboBoxDocument}.
     52         * @param comboBox the combobox
     53         */
    4854        public AutoCompletingComboBoxDocument(final JosmComboBox<AutoCompletionListItem> comboBox) {
    4955            this.comboBox = comboBox;
    5056        }
    5157
    52         @Override public void remove(int offs, int len) throws BadLocationException {
     58        @Override
     59        public void remove(int offs, int len) throws BadLocationException {
    5360            if (selecting)
    5461                return;
     
    5663        }
    5764
    58         @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
     65        @Override
     66        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
    5967            if (selecting || (offs == 0 && str.equals(getText(0, getLength()))))
    6068                return;
    6169            if (maxTextLength > -1 && str.length()+getLength() > maxTextLength)
    6270                return;
    63             boolean initial = (offs == 0 && getLength() == 0 && str.length() > 1);
     71            boolean initial = offs == 0 && getLength() == 0 && str.length() > 1;
    6472            super.insertString(offs, str, a);
    6573
     
    104112            if (item != null) {
    105113                String newText = ((AutoCompletionListItem) item).getValue();
    106                 if (!newText.equals(curText))
    107                 {
     114                if (!newText.equals(curText)) {
    108115                    selecting = true;
    109116                    super.remove(0, size);
     
    139146                if (currentItem.getValue().equals(pattern))
    140147                    return currentItem;
    141                 if (!match && currentItem.getValue().startsWith(pattern)) {
    142                     if (bestItem == null || currentItem.getPriority().compareTo(bestItem.getPriority()) > 0) {
    143                         bestItem = currentItem;
    144                     }
     148                if (!match && currentItem.getValue().startsWith(pattern)
     149                && (bestItem == null || currentItem.getPriority().compareTo(bestItem.getPriority()) > 0)) {
     150                    bestItem = currentItem;
    145151                }
    146152            }
     
    158164    /**
    159165     * Creates a <code>AutoCompletingComboBox</code> with the specified prototype display value.
    160      * @param prototype the <code>Object</code> used to compute the maximum number of elements to be displayed at once before displaying a scroll bar.
    161      *                  It also affects the initial width of the combo box.
     166     * @param prototype the <code>Object</code> used to compute the maximum number of elements to be displayed at once
     167     *                  before displaying a scroll bar. It also affects the initial width of the combo box.
    162168     * @since 5520
    163169     */
     
    171177                    @Override
    172178                    public void focusLost(FocusEvent e) {
     179                        Main.map.keyDetector.setEnabled(true);
    173180                    }
    174181                    @Override
    175182                    public void focusGained(FocusEvent e) {
     183                        Main.map.keyDetector.setEnabled(false);
    176184                        // save unix system selection (middle mouse paste)
    177185                        Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
     
    188196    }
    189197
     198    /**
     199     * Sets the maximum text length.
     200     * @param length the maximum text length in number of characters
     201     */
    190202    public void setMaxTextLength(int length) {
    191203        this.maxTextLength = length;
     
    236248
    237249    /**
    238      * sets the items of the combobox to the given strings
     250     * Sets the items of the combobox to the given {@code String}s.
     251     * @param elems String items
    239252     */
    240253    public void setPossibleItems(Collection<String> elems) {
     
    252265
    253266    /**
    254      * sets the items of the combobox to the given AutoCompletionListItems
     267     * Sets the items of the combobox to the given {@code AutoCompletionListItem}s.
     268     * @param elems AutoCompletionListItem items
    255269     */
    256270    public void setPossibleACItems(Collection<AutoCompletionListItem> elems) {
     
    266280    }
    267281
    268     protected boolean isAutocompleteEnabled() {
     282    /**
     283     * Determines if autocompletion is enabled.
     284     * @return {@code true} if autocompletion is enabled, {@code false} otherwise.
     285     */
     286    public final boolean isAutocompleteEnabled() {
    269287        return autocompleteEnabled;
    270288    }
     
    277295     * If the locale is fixed, English keyboard layout will be used by default for this combobox
    278296     * all other components can still have different keyboard layout selected
     297     * @param f fixed locale
    279298     */
    280299    public void setFixedLocale(boolean f) {
     
    314333                int index,
    315334                boolean isSelected,
    316                 boolean cellHasFocus)
    317         {
     335                boolean cellHasFocus) {
    318336            if (isSelected) {
    319337                setBackground(list.getSelectionBackground());
  • trunk/src/org/openstreetmap/josm/gui/widgets/DisableShortcutsOnFocusGainedTextField.java

    r7618 r7631  
    104104        disableMenuActions();
    105105        unregisterActionShortcuts();
    106         Main.map.keyDetector.setEnabled(false);
    107106    }
    108107
     
    110109    public void focusLost(FocusEvent e) {
    111110        super.focusLost(e);
    112         Main.map.keyDetector.setEnabled(true);
    113111        restoreActionShortcuts();
    114112        restoreMenuActions();
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmPasswordField.java

    r6920 r7631  
    33
    44import java.awt.event.ActionEvent;
     5import java.awt.event.FocusEvent;
     6import java.awt.event.FocusListener;
    57import java.beans.PropertyChangeListener;
    68
     
    1618 * A subclass of {@link JPasswordField} to implement a workaround to
    1719 * <a href="https://bugs.openjdk.java.net/browse/JDK-6322854">JDK bug 6322854</a>.
    18  * This class can be deleted after Oracle decides to fix this bug...
    1920 *
    2021 * @since 5752
     
    2223 * @see <a href="https://hg.netbeans.org/main/rev/33cb2e81b640">https://hg.netbeans.org/main/rev/33cb2e81b640</a>
    2324 */
    24 public class JosmPasswordField extends JPasswordField {
     25public class JosmPasswordField extends JPasswordField implements FocusListener {
    2526
    2627    /**
     
    3132    public JosmPasswordField() {
    3233        workaroundJdkBug6322854(this);
     34        addFocusListener(this);
    3335    }
    3436
     
    5153        super(doc, txt, columns);
    5254        workaroundJdkBug6322854(this);
     55        addFocusListener(this);
    5356    }
    5457
     
    6366        super(columns);
    6467        workaroundJdkBug6322854(this);
     68        addFocusListener(this);
    6569    }
    6670
     
    7680        super(text, columns);
    7781        workaroundJdkBug6322854(this);
     82        addFocusListener(this);
    7883    }
    7984
     
    8893        super(text);
    8994        workaroundJdkBug6322854(this);
     95        addFocusListener(this);
     96    }
     97
     98    @Override
     99    public void focusGained(FocusEvent e) {
     100        Main.map.keyDetector.setEnabled(false);
     101    }
     102
     103    @Override
     104    public void focusLost(FocusEvent e) {
     105        Main.map.keyDetector.setEnabled(true);
    90106    }
    91107
    92108    /**
    93109     * Implements a workaround to <a href="https://bugs.openjdk.java.net/browse/JDK-6322854">JDK bug 6322854</a>.
     110     * This method can be deleted after Oracle decides to fix this bug...
    94111     * @param text The {@link JTextComponent} to protect.
    95112     */
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextArea.java

    r6830 r7631  
    22package org.openstreetmap.josm.gui.widgets;
    33
     4import java.awt.event.FocusEvent;
     5import java.awt.event.FocusListener;
     6
    47import javax.swing.JTextArea;
    58import javax.swing.text.Document;
     9
     10import org.openstreetmap.josm.Main;
    611
    712/**
     
    914 * @since 5886
    1015 */
    11 public class JosmTextArea extends JTextArea {
     16public class JosmTextArea extends JTextArea implements FocusListener {
    1217
    1318    /**
     
    8287        super(doc, text, rows, columns);
    8388        TextContextualPopupMenu.enableMenuFor(this);
     89        addFocusListener(this);
     90    }
     91
     92    @Override
     93    public void focusGained(FocusEvent e) {
     94        Main.map.keyDetector.setEnabled(false);
     95    }
     96
     97    @Override
     98    public void focusLost(FocusEvent e) {
     99        Main.map.keyDetector.setEnabled(true);
    84100    }
    85101}
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r7505 r7631  
    1414import javax.swing.text.Document;
    1515
     16import org.openstreetmap.josm.Main;
     17
    1618/**
    17  * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all)
    18  * and an optional "hint" displayed when no text has been entered.
     19 * Subclass of {@link JTextField} that:<ul>
     20 * <li>adds a "native" context menu (cut/copy/paste/select all)</li>
     21 * <li>adds an optional "hint" displayed when no text has been entered</li>
     22 * <li>disables the global advanced key press detector when focused</li>
     23 * <br>This class must be used everywhere in core and plugins instead of {@code JTextField}.
    1924 * @since 5886
    2025 */
     
    136141    @Override
    137142    public void focusGained(FocusEvent e) {
     143        Main.map.keyDetector.setEnabled(false);
    138144        repaint();
    139145    }
     
    141147    @Override
    142148    public void focusLost(FocusEvent e) {
     149        Main.map.keyDetector.setEnabled(true);
    143150        repaint();
    144151    }
Note: See TracChangeset for help on using the changeset viewer.