- Timestamp:
- 2014-10-18T20:50:35+02:00 (10 years ago)
- 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 28 28 29 29 /** 30 * Auto-completing ComboBox. 30 31 * @author guilhem.bonnefille@gmail.com 32 * @since 272 31 33 */ 32 34 public class AutoCompletingComboBox extends JosmComboBox<AutoCompletionListItem> { … … 39 41 /** 40 42 * 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>. 43 45 */ 44 46 class AutoCompletingComboBoxDocument extends PlainDocument { … … 46 48 private boolean selecting = false; 47 49 50 /** 51 * Constructs a new {@code AutoCompletingComboBoxDocument}. 52 * @param comboBox the combobox 53 */ 48 54 public AutoCompletingComboBoxDocument(final JosmComboBox<AutoCompletionListItem> comboBox) { 49 55 this.comboBox = comboBox; 50 56 } 51 57 52 @Override public void remove(int offs, int len) throws BadLocationException { 58 @Override 59 public void remove(int offs, int len) throws BadLocationException { 53 60 if (selecting) 54 61 return; … … 56 63 } 57 64 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 { 59 67 if (selecting || (offs == 0 && str.equals(getText(0, getLength())))) 60 68 return; 61 69 if (maxTextLength > -1 && str.length()+getLength() > maxTextLength) 62 70 return; 63 boolean initial = (offs == 0 && getLength() == 0 && str.length() > 1);71 boolean initial = offs == 0 && getLength() == 0 && str.length() > 1; 64 72 super.insertString(offs, str, a); 65 73 … … 104 112 if (item != null) { 105 113 String newText = ((AutoCompletionListItem) item).getValue(); 106 if (!newText.equals(curText)) 107 { 114 if (!newText.equals(curText)) { 108 115 selecting = true; 109 116 super.remove(0, size); … … 139 146 if (currentItem.getValue().equals(pattern)) 140 147 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; 145 151 } 146 152 } … … 158 164 /** 159 165 * 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. 162 168 * @since 5520 163 169 */ … … 171 177 @Override 172 178 public void focusLost(FocusEvent e) { 179 Main.map.keyDetector.setEnabled(true); 173 180 } 174 181 @Override 175 182 public void focusGained(FocusEvent e) { 183 Main.map.keyDetector.setEnabled(false); 176 184 // save unix system selection (middle mouse paste) 177 185 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); … … 188 196 } 189 197 198 /** 199 * Sets the maximum text length. 200 * @param length the maximum text length in number of characters 201 */ 190 202 public void setMaxTextLength(int length) { 191 203 this.maxTextLength = length; … … 236 248 237 249 /** 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 239 252 */ 240 253 public void setPossibleItems(Collection<String> elems) { … … 252 265 253 266 /** 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 255 269 */ 256 270 public void setPossibleACItems(Collection<AutoCompletionListItem> elems) { … … 266 280 } 267 281 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() { 269 287 return autocompleteEnabled; 270 288 } … … 277 295 * If the locale is fixed, English keyboard layout will be used by default for this combobox 278 296 * all other components can still have different keyboard layout selected 297 * @param f fixed locale 279 298 */ 280 299 public void setFixedLocale(boolean f) { … … 314 333 int index, 315 334 boolean isSelected, 316 boolean cellHasFocus) 317 { 335 boolean cellHasFocus) { 318 336 if (isSelected) { 319 337 setBackground(list.getSelectionBackground()); -
trunk/src/org/openstreetmap/josm/gui/widgets/DisableShortcutsOnFocusGainedTextField.java
r7618 r7631 104 104 disableMenuActions(); 105 105 unregisterActionShortcuts(); 106 Main.map.keyDetector.setEnabled(false);107 106 } 108 107 … … 110 109 public void focusLost(FocusEvent e) { 111 110 super.focusLost(e); 112 Main.map.keyDetector.setEnabled(true);113 111 restoreActionShortcuts(); 114 112 restoreMenuActions(); -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmPasswordField.java
r6920 r7631 3 3 4 4 import java.awt.event.ActionEvent; 5 import java.awt.event.FocusEvent; 6 import java.awt.event.FocusListener; 5 7 import java.beans.PropertyChangeListener; 6 8 … … 16 18 * A subclass of {@link JPasswordField} to implement a workaround to 17 19 * <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...19 20 * 20 21 * @since 5752 … … 22 23 * @see <a href="https://hg.netbeans.org/main/rev/33cb2e81b640">https://hg.netbeans.org/main/rev/33cb2e81b640</a> 23 24 */ 24 public class JosmPasswordField extends JPasswordField {25 public class JosmPasswordField extends JPasswordField implements FocusListener { 25 26 26 27 /** … … 31 32 public JosmPasswordField() { 32 33 workaroundJdkBug6322854(this); 34 addFocusListener(this); 33 35 } 34 36 … … 51 53 super(doc, txt, columns); 52 54 workaroundJdkBug6322854(this); 55 addFocusListener(this); 53 56 } 54 57 … … 63 66 super(columns); 64 67 workaroundJdkBug6322854(this); 68 addFocusListener(this); 65 69 } 66 70 … … 76 80 super(text, columns); 77 81 workaroundJdkBug6322854(this); 82 addFocusListener(this); 78 83 } 79 84 … … 88 93 super(text); 89 94 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); 90 106 } 91 107 92 108 /** 93 109 * 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... 94 111 * @param text The {@link JTextComponent} to protect. 95 112 */ -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextArea.java
r6830 r7631 2 2 package org.openstreetmap.josm.gui.widgets; 3 3 4 import java.awt.event.FocusEvent; 5 import java.awt.event.FocusListener; 6 4 7 import javax.swing.JTextArea; 5 8 import javax.swing.text.Document; 9 10 import org.openstreetmap.josm.Main; 6 11 7 12 /** … … 9 14 * @since 5886 10 15 */ 11 public class JosmTextArea extends JTextArea {16 public class JosmTextArea extends JTextArea implements FocusListener { 12 17 13 18 /** … … 82 87 super(doc, text, rows, columns); 83 88 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); 84 100 } 85 101 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java
r7505 r7631 14 14 import javax.swing.text.Document; 15 15 16 import org.openstreetmap.josm.Main; 17 16 18 /** 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}. 19 24 * @since 5886 20 25 */ … … 136 141 @Override 137 142 public void focusGained(FocusEvent e) { 143 Main.map.keyDetector.setEnabled(false); 138 144 repaint(); 139 145 } … … 141 147 @Override 142 148 public void focusLost(FocusEvent e) { 149 Main.map.keyDetector.setEnabled(true); 143 150 repaint(); 144 151 }
Note:
See TracChangeset
for help on using the changeset viewer.