Changeset 5656 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-01-02T15:46:42+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/properties
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5633 r5656 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn;6 5 7 6 import java.awt.Component; … … 131 130 int row = propertyTable.rowAtPoint(e.getPoint()); 132 131 if (row > -1) { 133 editHelper.editProperty(row); 132 boolean focusOnKey = (propertyTable.columnAtPoint(e.getPoint()) == 0); 133 editHelper.editProperty(row, focusOnKey); 134 134 } else { 135 135 editHelper.addProperty(); … … 876 876 if (propertyTable.getSelectedRowCount() == 1) { 877 877 int row = propertyTable.getSelectedRow(); 878 editHelper.editProperty(row );878 editHelper.editProperty(row, false); 879 879 } else if (membershipTable.getSelectedRowCount() == 1) { 880 880 int row = membershipTable.getSelectedRow(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r5646 r5656 24 24 import java.awt.event.MouseAdapter; 25 25 import java.awt.event.MouseEvent; 26 import java.awt.event.WindowAdapter; 27 import java.awt.event.WindowEvent; 26 28 import java.awt.image.BufferedImage; 27 29 import java.util.ArrayList; … … 138 140 * Edit the value in the properties table row 139 141 * @param row The row of the table from which the value is edited. 142 * @param focusOnKey Determines if the initial focus should be set on key instead of value 143 * @since 5653 140 144 */ 141 public void editProperty(final int row ) {145 public void editProperty(final int row, boolean focusOnKey) { 142 146 changedKey = null; 143 147 sel = Main.main.getCurrentDataSet().getSelected(); … … 148 152 149 153 final EditTagDialog editDialog = new EditTagDialog(key, row, 150 (Map<String, Integer>) propertyData.getValueAt(row, 1) );154 (Map<String, Integer>) propertyData.getValueAt(row, 1), focusOnKey); 151 155 editDialog.showDialog(); 152 156 if (editDialog.getValue() !=1 ) return; … … 178 182 } 179 183 180 /**181 * Create a focus handling adapter and apply in to the editor component of value182 * autocompletion box.183 * @param keys Box for keys entering and autocompletion184 * @param values Box for values entering and autocompletion185 * @param autocomplete Manager handling the autocompletion186 * @param comparator Class to decide what values are offered on autocompletion187 * @return The created adapter188 */189 private FocusAdapter addFocusAdapter(final AutoCompletingComboBox keys, final AutoCompletingComboBox values,190 final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) {191 // get the combo box' editor component192 JTextComponent editor = (JTextComponent)values.getEditor()193 .getEditorComponent();194 // Refresh the values model when focus is gained195 FocusAdapter focus = new FocusAdapter() {196 @Override public void focusGained(FocusEvent e) {197 String key = keys.getEditor().getItem().toString();198 199 List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));200 Collections.sort(valueList, comparator);201 202 values.setPossibleACItems(valueList);203 objKey=key;204 }205 };206 editor.addFocusListener(focus);207 return focus;208 }209 210 211 184 public class EditTagDialog extends AbstractTagsDialog { 212 String oldValue; 213 String key; 214 Map<String, Integer> m; 215 int row; 185 final String key; 186 final Map<String, Integer> m; 187 final int row; 216 188 217 189 Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() { … … 249 221 }; 250 222 251 private EditTagDialog(String key, int row, Map<String, Integer> map ) {223 private EditTagDialog(String key, int row, Map<String, Integer> map, final boolean initialFocusOnKey) { 252 224 super(Main.parent, trn("Change value?", "Change values?", map.size()), new String[] {tr("OK"),tr("Cancel")}); 253 225 setButtonIcons(new String[] {"ok","cancel"}); … … 302 274 } 303 275 }); 304 addFocusAdapter( keys, values,autocomplete, usedValuesAwareComparator);276 addFocusAdapter(autocomplete, usedValuesAwareComparator); 305 277 306 278 setContent(mainPanel, false); 307 279 308 // TODO: Is it correct place for thois code - was in 309 // new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) { 310 // @Override public void selectInitialValue() { 311 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 312 if(sysSel != null) { 313 Transferable old = sysSel.getContents(null); 314 values.requestFocusInWindow(); 315 values.getEditor().selectAll(); 316 sysSel.setContents(old, null); 317 } else { 318 values.requestFocusInWindow(); 319 values.getEditor().selectAll(); 320 } 280 addWindowListener(new WindowAdapter() { 281 @Override 282 public void windowOpened(WindowEvent e) { 283 if (initialFocusOnKey) { 284 selectKeysComboBox(); 285 } else { 286 selectValuesCombobox(); 287 } 288 } 289 }); 321 290 } 322 291 … … 426 395 super.setVisible(visible); 427 396 } 397 398 private void selectACComboBoxSavingUnixBuffer(AutoCompletingComboBox cb) { 399 // select compbobox with saving unix system selection (middle mouse paste) 400 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 401 if(sysSel != null) { 402 Transferable old = sysSel.getContents(null); 403 cb.requestFocusInWindow(); 404 cb.getEditor().selectAll(); 405 sysSel.setContents(old, null); 406 } else { 407 cb.requestFocusInWindow(); 408 cb.getEditor().selectAll(); 409 } 410 } 411 412 public void selectKeysComboBox() { 413 selectACComboBoxSavingUnixBuffer(keys); 414 } 415 416 public void selectValuesCombobox() { 417 selectACComboBoxSavingUnixBuffer(values); 418 } 419 420 /** 421 * Create a focus handling adapter and apply in to the editor component of value 422 * autocompletion box. 423 * @param keys Box for keys entering and autocompletion 424 * @param values Box for values entering and autocompletion 425 * @param autocomplete Manager handling the autocompletion 426 * @param comparator Class to decide what values are offered on autocompletion 427 * @return The created adapter 428 */ 429 protected FocusAdapter addFocusAdapter(final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) { 430 // get the combo box' editor component 431 JTextComponent editor = (JTextComponent)values.getEditor() 432 .getEditorComponent(); 433 // Refresh the values model when focus is gained 434 FocusAdapter focus = new FocusAdapter() { 435 @Override public void focusGained(FocusEvent e) { 436 String key = keys.getEditor().getItem().toString(); 437 438 List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key)); 439 Collections.sort(valueList, comparator); 440 441 values.setPossibleACItems(valueList); 442 objKey=key; 443 } 444 }; 445 editor.addFocusListener(focus); 446 return focus; 447 } 448 428 449 } 429 450 … … 485 506 } 486 507 487 FocusAdapter focus = addFocusAdapter( keys, values,autocomplete, defaultACItemComparator);508 FocusAdapter focus = addFocusAdapter(autocomplete, defaultACItemComparator); 488 509 // fire focus event in advance or otherwise the popup list will be too small at first 489 510 focus.focusGained(null); … … 501 522 public void actionPerformed(ActionEvent e) { 502 523 performTagAdding(); 524 selectKeysComboBox(); 503 525 } 504 526 }); … … 508 530 setContent(mainPanel, false); 509 531 510 // TODO: Is it correct place for this code - was in 511 // new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) { 512 // @Override public void selectInitialValue() { 513 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 514 if(sysSel != null) { 515 Transferable old = sysSel.getContents(null); 516 values.requestFocusInWindow(); 517 values.getEditor().selectAll(); 518 sysSel.setContents(old, null); 519 } else { 520 values.requestFocusInWindow(); 521 values.getEditor().selectAll(); 522 } 532 selectKeysComboBox(); 523 533 } 524 534 … … 547 557 focus.focusGained(null); 548 558 values.setSelectedItem(t.getValue()); 559 selectValuesCombobox(); 549 560 } 550 561 }; … … 583 594 if (e.isShiftDown()) { 584 595 performTagAdding(); 596 selectKeysComboBox(); 585 597 } 586 598 }
Note:
See TracChangeset
for help on using the changeset viewer.