Changeset 7743 in josm


Ignore:
Timestamp:
2014-11-23T23:54:40+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #10775 - allow to sum all numeric values as conflict resolution of capacity

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java

    r7005 r7743  
    1818import java.util.regex.Pattern;
    1919
     20import org.openstreetmap.josm.Main;
    2021import org.openstreetmap.josm.tools.Utils;
    2122
     
    722723    /**
    723724     * Replies the concatenation of all tag values (concatenated by a semicolon)
     725     * @param key the key to look up
    724726     *
    725727     * @return the concatenation of all tag values
     
    750752    }
    751753
     754    /**
     755     * Replies the sum of all numeric tag values.
     756     * @param key the key to look up
     757     *
     758     * @return the sum of all numeric tag values, as string
     759     * @since 7743
     760     */
     761    public String getSummedValues(String key) {
     762        int result = 0;
     763        for (String value : getValues(key)) {
     764            try {
     765                result += Integer.parseInt(value);
     766            } catch (NumberFormatException e) {
     767                if (Main.isTraceEnabled()) {
     768                    Main.trace(e.getMessage());
     769                }
     770            }
     771        }
     772        return Integer.toString(result);
     773    }
     774
     775
    752776    @Override
    753777    public String toString() {
  • trunk/src/org/openstreetmap/josm/gui/conflict/ConflictColors.java

    r6624 r7743  
    4040    BGCOLOR_TAG_KEEP_ALL (marktr("Conflict background: keep all tags"), new Color(255,234,213)),
    4141    FGCOLOR_TAG_KEEP_ALL (marktr("Conflict foreground: keep all tags"), Color.black),
     42    BGCOLOR_TAG_SUM_ALL_NUM(marktr("Conflict background: sum all numeric tags"), new Color(255,234,213)),
     43    FGCOLOR_TAG_SUM_ALL_NUM(marktr("Conflict foreground: sum all numeric tags"), Color.black),
    4244
    4345    BGCOLOR_MEMBER_KEEP  (marktr("Conflict background: keep member"), new Color(217,255,217)),
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellEditor.java

    r7015 r7743  
    2222import javax.swing.table.TableCellEditor;
    2323
     24import org.openstreetmap.josm.Main;
    2425import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    2526
     
    5253    private CopyOnWriteArrayList<NavigationListener> listeners;
    5354
    54     public void addNavigationListeners(NavigationListener listener) {
     55    /**
     56     * Adds a navigation listener.
     57     * @param listener navigation listener to add
     58     */
     59    public void addNavigationListener(NavigationListener listener) {
    5560        if (listener != null) {
    5661            listeners.addIfAbsent(listener);
     
    5863    }
    5964
    60     public void removeNavigationListeners(NavigationListener listener) {
     65    /**
     66     * Removes a navigation listener.
     67     * @param listener navigation listener to remove
     68     */
     69    public void removeNavigationListener(NavigationListener listener) {
    6170        listeners.remove(listener);
    6271    }
     
    134143            editorModel.addElement(value);
    135144        }
     145        if (decision.canSumAllNumeric()) {
     146            editorModel.addElement(MultiValueDecisionType.SUM_ALL_NUMERIC);
     147        }
    136148        if (decision.canKeepNone()) {
    137149            editorModel.addElement(MultiValueDecisionType.KEEP_NONE);
     
    152164        case KEEP_ALL:
    153165            editor.setSelectedItem(MultiValueDecisionType.KEEP_ALL);
     166            break;
     167        case SUM_ALL_NUMERIC:
     168            editor.setSelectedItem(MultiValueDecisionType.SUM_ALL_NUMERIC);
     169            break;
     170        default:
     171            Main.error("Unknown decision type in initEditor(): "+decision.getDecisionType());
    154172        }
    155173    }
     
    217235                    setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
    218236                    break;
     237                case SUM_ALL_NUMERIC:
     238                    setText(tr("sum"));
     239                    setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
     240                    break;
    219241                default:
    220242                    // don't display other values
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellRenderer.java

    r7017 r7743  
    6666                        setBackground(ConflictColors.BGCOLOR_TAG_KEEP_ALL.get());
    6767                        break;
     68                    case SUM_ALL_NUMERIC:
     69                        setForeground(ConflictColors.FGCOLOR_TAG_SUM_ALL_NUM.get());
     70                        setBackground(ConflictColors.BGCOLOR_TAG_SUM_ALL_NUM.get());
     71                        break;
    6872                    default:
    69                         Main.error("Unknown decision type: "+decision.getDecisionType());
     73                        Main.error("Unknown decision type in renderColors(): "+decision.getDecisionType());
    7074                    }
    7175                } else {
     
    8690            cbDecisionRenderer.setSelectedIndex(0);
    8791            break;
    88         case KEEP_ONE:
    89             model.addElement(decision.getChosenValue());
    90             cbDecisionRenderer.setFont(getFont());
    91             cbDecisionRenderer.setSelectedIndex(0);
    92             break;
    9392        case KEEP_NONE:
    9493            model.addElement(tr("deleted"));
     
    9695            cbDecisionRenderer.setSelectedIndex(0);
    9796            break;
     97        case KEEP_ONE:
    9898        case KEEP_ALL:
     99        case SUM_ALL_NUMERIC:
    99100            model.addElement(decision.getChosenValue());
    100101            cbDecisionRenderer.setFont(getFont());
    101102            cbDecisionRenderer.setSelectedIndex(0);
    102103            break;
     104        default:
     105            Main.error("Unknown decision type in renderValue(): "+decision.getDecisionType());
    103106        }
    104107    }
     
    108111     */
    109112    protected void renderToolTipText(MultiValueResolutionDecision decision) {
    110         String toolTipText;
     113        String toolTipText = null;
    111114        switch (decision.getDecisionType()) {
    112115        case UNDECIDED:
    113116            toolTipText = tr("Please decide which values to keep");
    114             setToolTipText(toolTipText);
    115             cbDecisionRenderer.setToolTipText(toolTipText);
    116117            break;
    117118        case KEEP_ONE:
    118119            toolTipText = tr("Value ''{0}'' is going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey());
    119             setToolTipText(toolTipText);
    120             cbDecisionRenderer.setToolTipText(toolTipText);
     120            break;
     121        case SUM_ALL_NUMERIC:
     122            toolTipText = tr("All numeric values sumed as ''{0}'' are going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey());
    121123            break;
    122124        case KEEP_NONE:
    123125            toolTipText = tr("The key ''{0}'' and all its values are going to be removed", decision.getKey());
    124             setToolTipText(toolTipText);
    125             cbDecisionRenderer.setToolTipText(toolTipText);
    126126            break;
    127127        case KEEP_ALL:
    128128            toolTipText = tr("All values joined as ''{0}'' are going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey());
    129             setToolTipText(toolTipText);
    130             cbDecisionRenderer.setToolTipText(toolTipText);
    131129            break;
    132130        }
     131        setToolTipText(toolTipText);
     132        cbDecisionRenderer.setToolTipText(toolTipText);
    133133    }
    134134
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueDecisionType.java

    r3083 r7743  
    44/**
    55 * Represents a decision for a tag conflict due to multiple possible values.
    6  *
    7  *
     6 * @since 2008
    87 */
    98public enum MultiValueDecisionType {
     
    1211    /** keep exactly one values */
    1312    KEEP_ONE,
     13    /** sum all numeric values; only available for a few keys (eg: capacity) */
     14    SUM_ALL_NUMERIC,
    1415    /** keep no value, delete the tag */
    1516    KEEP_NONE,
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueResolutionDecision.java

    r7005 r7743  
    1616import org.openstreetmap.josm.data.osm.TagCollection;
    1717import org.openstreetmap.josm.tools.CheckParameterUtil;
     18
    1819/**
    1920 * Represents a decision for a conflict due to multiple possible value for a tag.
    20  *
    21  *
     21 * @since 2008
    2222 */
    2323public class MultiValueResolutionDecision {
     
    2626    private MultiValueDecisionType type;
    2727    /** the collection of tags for which a decision is needed */
    28     private TagCollection  tags;
     28    private TagCollection tags;
    2929    /** the selected value if {@link #type} is {@link MultiValueDecisionType#KEEP_ONE} */
    3030    private String value;
     
    8989
    9090    /**
     91     * Apply the decision to sum all numeric values
     92     * @since 7743
     93     */
     94    public void sumAllNumeric() {
     95        this.type = MultiValueDecisionType.SUM_ALL_NUMERIC;
     96    }
     97
     98    /**
    9199     * Apply the decision to keep exactly one value
    92100     *
     
    135143        case UNDECIDED: throw new IllegalStateException(tr("Not decided yet."));
    136144        case KEEP_ONE: return value;
     145        case SUM_ALL_NUMERIC: return tags.getSummedValues(getKey());
    137146        case KEEP_NONE: return null;
    138147        case KEEP_ALL: return tags.getJoinedValues(getKey());
    139         }
    140         // should not happen
    141         return null;
     148        default: return null;
     149        }
    142150    }
    143151
     
    180188    public boolean canKeepAll() {
    181189        return getValues().size() > 1;
     190    }
     191
     192    /**
     193     * Replies true, if summing all numeric values is a possible value in this resolution
     194     *
     195     * @return true, if summing all numeric values is a possible value in this resolution
     196     * @since 7743
     197     */
     198    public boolean canSumAllNumeric() {
     199        return "capacity".equals(getKey()) && canKeepAll();
    182200    }
    183201
     
    275293    public Tag getResolution() {
    276294        switch(type) {
     295        case SUM_ALL_NUMERIC: return new Tag(getKey(), tags.getSummedValues(getKey()));
    277296        case KEEP_ALL: return new Tag(getKey(), tags.getJoinedValues(getKey()));
    278297        case KEEP_ONE: return new Tag(getKey(),value);
    279298        case KEEP_NONE: return new Tag(getKey(), "");
    280299        case UNDECIDED: return null;
    281         }
    282         return null;
     300        default: return null;
     301        }
    283302    }
    284303}
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java

    r7643 r7743  
    178178                decision.keepAll();
    179179                break;
     180            case SUM_ALL_NUMERIC:
     181                decision.sumAllNumeric();
     182                break;
    180183            }
    181184        }
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverTable.java

    r7022 r7743  
    4040        getActionMap().put("selectPreviousColumnCell", selectPreviousColumnCellAction);
    4141
    42         ((MultiValueCellEditor)getColumnModel().getColumn(2).getCellEditor()).addNavigationListeners(this);
     42        ((MultiValueCellEditor)getColumnModel().getColumn(2).getCellEditor()).addNavigationListener(this);
    4343
    4444        setRowHeight((int)new JosmComboBox<String>().getPreferredSize().getHeight());
Note: See TracChangeset for help on using the changeset viewer.