Ignore:
Timestamp:
2014-04-21T11:37:24+02:00 (10 years ago)
Author:
Balaitous
Message:

fix little bug: In TagConflictResolver dialog, when user select a value dialog status don't update until user select another cell

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellEditor.java

    r6883 r6991  
    88import java.awt.event.FocusAdapter;
    99import java.awt.event.FocusEvent;
     10import java.awt.event.ItemEvent;
     11import java.awt.event.ItemListener;
    1012import java.awt.event.KeyEvent;
    1113import java.util.concurrent.CopyOnWriteArrayList;
     
    3537public class MultiValueCellEditor extends AbstractCellEditor implements TableCellEditor{
    3638
     39    /**
     40     * Defines the interface for an object implementing navigation between rows
     41     */
    3742    public static interface NavigationListener {
     43        /** Call when need to go to next row */
    3844        void gotoNextDecision();
     45        /** Call when need to go to previous row */
    3946        void gotoPreviousDecision();
    4047    }
     
    5158    }
    5259
    53     public void removeavigationListeners(NavigationListener listener) {
     60    public void removeNavigationListeners(NavigationListener listener) {
    5461        listeners.remove(listener);
    5562    }
     
    6774    }
    6875
     76    /**
     77     * Construct a new {@link MultiValueCellEditor}
     78     */
    6979    public MultiValueCellEditor() {
    7080        editorModel = new DefaultComboBoxModel();
     
    99109                }
    100110        );
     111        editor.addItemListener(
     112                new ItemListener() {
     113                    @Override
     114                    public void itemStateChanged(ItemEvent e) {
     115                        if(e.getStateChange() == ItemEvent.SELECTED)
     116                            fireEditingStopped();
     117                    }
     118                }
     119        );
    101120        editor.setRenderer(new EditorCellRenderer());
    102121        listeners = new CopyOnWriteArrayList<NavigationListener>();
    103122    }
    104123
     124    /**
     125     * Populate model with possible values for a decision, and select current choice.
     126     * @param decision The {@link MultiValueResolutionDecision} to proceed
     127     */
    105128    protected void initEditor(MultiValueResolutionDecision decision) {
    106129        editorModel.removeAllElements();
     130        if (!decision.isDecided()) {
     131            editorModel.addElement(MultiValueDecisionType.UNDECIDED);
     132        }
    107133        for (String value: decision.getValues()) {
    108134            editorModel.addElement(value);
     
    116142        switch(decision.getDecisionType()) {
    117143        case UNDECIDED:
    118             editor.setSelectedIndex(0);
     144            editor.setSelectedItem(MultiValueDecisionType.UNDECIDED);
    119145            break;
    120146        case KEEP_ONE:
     
    143169
    144170    /**
    145      * The cell renderer used in the combo box
     171     * The cell renderer used in the edit combo box
    146172     *
    147173     */
    148174    private static class EditorCellRenderer extends JLabel implements ListCellRenderer {
    149175
     176        /**
     177         * Construct a new {@link EditorCellRenderer}.
     178         */
    150179        public EditorCellRenderer() {
    151180            setOpaque(true);
    152181        }
    153182
     183        /**
     184         * Set component color.
     185         * @param selected true if is selected
     186         */
    154187        protected void renderColors(boolean selected) {
    155188            if (selected) {
     
    162195        }
    163196
     197        /**
     198         * Set text for a value
     199         * @param value {@link String} or {@link MultiValueDecisionType}
     200         */
    164201        protected void renderValue(Object value) {
    165202            setFont(UIManager.getFont("ComboBox.font"));
     
    168205            } else if (MultiValueDecisionType.class.isInstance(value)) {
    169206                switch(MultiValueDecisionType.class.cast(value)) {
     207                case UNDECIDED:
     208                    setText(tr("Choose a value"));
     209                    setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
     210                    break;
    170211                case KEEP_NONE:
    171212                    setText(tr("none"));
Note: See TracChangeset for help on using the changeset viewer.