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


Ignore:
Timestamp:
2013-01-02T15:46:42+01:00 (11 years ago)
Author:
akks
Message:

Patch by Don-Vip fix #8311: Should focus on the proper column when double-clicking to edit a key/value +
see #8024: focus on Value after Alt-E, focus on Key after Shift-Enter, recent tag Click or Shift-Click

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  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trn;
    65
    76import java.awt.Component;
     
    131130                int row = propertyTable.rowAtPoint(e.getPoint());
    132131                if (row > -1) {
    133                     editHelper.editProperty(row);
     132                    boolean focusOnKey = (propertyTable.columnAtPoint(e.getPoint()) == 0);
     133                    editHelper.editProperty(row, focusOnKey);
    134134                } else {
    135135                    editHelper.addProperty();
     
    876876            if (propertyTable.getSelectedRowCount() == 1) {
    877877                int row = propertyTable.getSelectedRow();
    878                 editHelper.editProperty(row);
     878                editHelper.editProperty(row, false);
    879879            } else if (membershipTable.getSelectedRowCount() == 1) {
    880880                int row = membershipTable.getSelectedRow();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r5646 r5656  
    2424import java.awt.event.MouseAdapter;
    2525import java.awt.event.MouseEvent;
     26import java.awt.event.WindowAdapter;
     27import java.awt.event.WindowEvent;
    2628import java.awt.image.BufferedImage;
    2729import java.util.ArrayList;
     
    138140    * Edit the value in the properties table row
    139141    * @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
    140144    */
    141     public void editProperty(final int row) {
     145    public void editProperty(final int row, boolean focusOnKey) {
    142146        changedKey = null;
    143147        sel = Main.main.getCurrentDataSet().getSelected();
     
    148152       
    149153        final EditTagDialog editDialog = new EditTagDialog(key, row,
    150                 (Map<String, Integer>) propertyData.getValueAt(row, 1));
     154                (Map<String, Integer>) propertyData.getValueAt(row, 1), focusOnKey);
    151155        editDialog.showDialog();
    152156        if (editDialog.getValue() !=1 ) return;
     
    178182    }
    179183
    180     /**
    181      * Create a focus handling adapter and apply in to the editor component of value
    182      * autocompletion box.
    183      * @param keys Box for keys entering and autocompletion
    184      * @param values Box for values entering and autocompletion
    185      * @param autocomplete Manager handling the autocompletion
    186      * @param comparator Class to decide what values are offered on autocompletion
    187      * @return The created adapter
    188      */
    189     private FocusAdapter addFocusAdapter(final AutoCompletingComboBox keys, final AutoCompletingComboBox values,
    190             final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) {
    191         // get the combo box' editor component
    192         JTextComponent editor = (JTextComponent)values.getEditor()
    193                 .getEditorComponent();
    194         // Refresh the values model when focus is gained
    195         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        
    211184    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;
    216188
    217189        Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() {
     
    249221            };
    250222       
    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) {
    252224            super(Main.parent, trn("Change value?", "Change values?", map.size()), new String[] {tr("OK"),tr("Cancel")});
    253225            setButtonIcons(new String[] {"ok","cancel"});
     
    302274                }
    303275            });
    304             addFocusAdapter(keys, values, autocomplete, usedValuesAwareComparator);
     276            addFocusAdapter(autocomplete, usedValuesAwareComparator);
    305277           
    306278            setContent(mainPanel, false);
    307279           
    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            });
    321290        }
    322291       
     
    426395            super.setVisible(visible);
    427396        }
     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       
    428449    }
    429450
     
    485506            }
    486507
    487             FocusAdapter focus = addFocusAdapter(keys, values, autocomplete, defaultACItemComparator);
     508            FocusAdapter focus = addFocusAdapter(autocomplete, defaultACItemComparator);
    488509            // fire focus event in advance or otherwise the popup list will be too small at first
    489510            focus.focusGained(null);
     
    501522                    public void actionPerformed(ActionEvent e) {
    502523                        performTagAdding();
     524                        selectKeysComboBox();
    503525                    }
    504526                });
     
    508530            setContent(mainPanel, false);
    509531           
    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();
    523533        }
    524534
     
    547557                        focus.focusGained(null);
    548558                        values.setSelectedItem(t.getValue());
     559                        selectValuesCombobox();
    549560                    }
    550561                };
     
    583594                            if (e.isShiftDown()) {
    584595                                performTagAdding();
     596                                selectKeysComboBox();
    585597                            }
    586598                        }
Note: See TracChangeset for help on using the changeset viewer.