Changeset 5704 in josm
- Timestamp:
- 2013-02-09T18:08:26+01:00 (12 years ago)
- 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 42 42 import javax.swing.AbstractAction; 43 43 import javax.swing.Action; 44 import javax.swing.BorderFactory; 44 45 import javax.swing.Box; 45 46 import javax.swing.DefaultListCellRenderer; 46 47 import javax.swing.ImageIcon; 48 import javax.swing.JCheckBoxMenuItem; 47 49 import javax.swing.JComponent; 48 50 import javax.swing.JLabel; 49 51 import javax.swing.JList; 52 import javax.swing.JMenuItem; 53 import javax.swing.JOptionPane; 50 54 import javax.swing.JPanel; 55 import javax.swing.JPopupMenu; 51 56 import javax.swing.KeyStroke; 52 57 import javax.swing.table.DefaultTableModel; … … 62 67 import org.openstreetmap.josm.data.osm.OsmPrimitive; 63 68 import org.openstreetmap.josm.data.osm.Tag; 69 import org.openstreetmap.josm.data.preferences.BooleanProperty; 70 import org.openstreetmap.josm.data.preferences.IntegerProperty; 64 71 import org.openstreetmap.josm.gui.ExtendedDialog; 65 72 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 68 75 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 69 76 import org.openstreetmap.josm.gui.util.GuiHelper; 77 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 70 78 import org.openstreetmap.josm.io.XmlWriter; 71 79 import org.openstreetmap.josm.tools.GBC; 72 80 import org.openstreetmap.josm.tools.Shortcut; 81 import org.openstreetmap.josm.tools.Utils; 73 82 import org.openstreetmap.josm.tools.WindowGeometry; 74 83 … … 96 105 97 106 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; 99 108 100 109 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) … … 250 259 keys.setSelectedItem(key); 251 260 261 p.add(Box.createVerticalStrut(5),GBC.eol()); 252 262 p.add(new JLabel(tr("Key")), GBC.std()); 253 263 p.add(Box.createHorizontalStrut(10), GBC.std()); … … 266 276 values.setSelectedItem(selection); 267 277 values.getEditor().setItem(selection); 278 p.add(Box.createVerticalStrut(5),GBC.eol()); 268 279 p.add(new JLabel(tr("Value")), GBC.std()); 269 280 p.add(Box.createHorizontalStrut(10), GBC.std()); … … 364 375 } 365 376 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 366 380 abstract class AbstractTagsDialog extends ExtendedDialog { 367 381 AutoCompletingComboBox keys; 368 382 AutoCompletingComboBox values; 383 Component componentUnderMouse; 369 384 370 385 public AbstractTagsDialog(Component parent, String title, String[] buttonTexts) { 371 386 super(parent, title, buttonTexts); 387 addMouseListener(new PopupMenuLauncher(popupMenu)); 372 388 } 373 389 … … 392 408 rememberWindowGeometry(geometry); 393 409 } 410 keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get()); 394 411 } 395 412 super.setVisible(visible); … … 445 462 editor.addFocusListener(focus); 446 463 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 449 500 } 450 501 … … 511 562 focus.focusGained(null); 512 563 513 int recentTagsToShow = Main.pref.getInteger("properties.recently-added-tags", DEFAULT_LRU_TAGS_NUMBER);564 int recentTagsToShow = PROPERTY_RECENT_TAGS_NUMBER.get(); 514 565 if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) { 515 566 recentTagsToShow = MAX_LRU_TAGS_NUMBER; … … 532 583 533 584 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 536 606 private void suggestRecentlyAddedTags(JPanel mainPanel, int tagsToShow, final FocusAdapter focus) { 537 607 if (!(tagsToShow > 0 && !recentTags.isEmpty())) -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r5520 r5704 8 8 import java.awt.event.FocusEvent; 9 9 import java.awt.event.FocusListener; 10 import java.awt.im.InputContext; 10 11 import java.util.Collection; 12 import java.util.Locale; 11 13 12 14 import javax.swing.ComboBoxEditor; … … 33 35 34 36 private int maxTextLength = -1; 37 private boolean useFixedLocale; 35 38 36 39 /** … … 272 275 273 276 /** 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 /** 274 298 * ListCellRenderer for AutoCompletingComboBox 275 299 * renders an AutoCompletionListItem by showing only the string value part
Note:
See TracChangeset
for help on using the changeset viewer.