Changeset 7743 in josm
- Timestamp:
- 2014-11-23T23:54:40+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java
r7005 r7743 18 18 import java.util.regex.Pattern; 19 19 20 import org.openstreetmap.josm.Main; 20 21 import org.openstreetmap.josm.tools.Utils; 21 22 … … 722 723 /** 723 724 * Replies the concatenation of all tag values (concatenated by a semicolon) 725 * @param key the key to look up 724 726 * 725 727 * @return the concatenation of all tag values … … 750 752 } 751 753 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 752 776 @Override 753 777 public String toString() { -
trunk/src/org/openstreetmap/josm/gui/conflict/ConflictColors.java
r6624 r7743 40 40 BGCOLOR_TAG_KEEP_ALL (marktr("Conflict background: keep all tags"), new Color(255,234,213)), 41 41 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), 42 44 43 45 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 22 22 import javax.swing.table.TableCellEditor; 23 23 24 import org.openstreetmap.josm.Main; 24 25 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 25 26 … … 52 53 private CopyOnWriteArrayList<NavigationListener> listeners; 53 54 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) { 55 60 if (listener != null) { 56 61 listeners.addIfAbsent(listener); … … 58 63 } 59 64 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) { 61 70 listeners.remove(listener); 62 71 } … … 134 143 editorModel.addElement(value); 135 144 } 145 if (decision.canSumAllNumeric()) { 146 editorModel.addElement(MultiValueDecisionType.SUM_ALL_NUMERIC); 147 } 136 148 if (decision.canKeepNone()) { 137 149 editorModel.addElement(MultiValueDecisionType.KEEP_NONE); … … 152 164 case KEEP_ALL: 153 165 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()); 154 172 } 155 173 } … … 217 235 setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD)); 218 236 break; 237 case SUM_ALL_NUMERIC: 238 setText(tr("sum")); 239 setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD)); 240 break; 219 241 default: 220 242 // don't display other values -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellRenderer.java
r7017 r7743 66 66 setBackground(ConflictColors.BGCOLOR_TAG_KEEP_ALL.get()); 67 67 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; 68 72 default: 69 Main.error("Unknown decision type : "+decision.getDecisionType());73 Main.error("Unknown decision type in renderColors(): "+decision.getDecisionType()); 70 74 } 71 75 } else { … … 86 90 cbDecisionRenderer.setSelectedIndex(0); 87 91 break; 88 case KEEP_ONE:89 model.addElement(decision.getChosenValue());90 cbDecisionRenderer.setFont(getFont());91 cbDecisionRenderer.setSelectedIndex(0);92 break;93 92 case KEEP_NONE: 94 93 model.addElement(tr("deleted")); … … 96 95 cbDecisionRenderer.setSelectedIndex(0); 97 96 break; 97 case KEEP_ONE: 98 98 case KEEP_ALL: 99 case SUM_ALL_NUMERIC: 99 100 model.addElement(decision.getChosenValue()); 100 101 cbDecisionRenderer.setFont(getFont()); 101 102 cbDecisionRenderer.setSelectedIndex(0); 102 103 break; 104 default: 105 Main.error("Unknown decision type in renderValue(): "+decision.getDecisionType()); 103 106 } 104 107 } … … 108 111 */ 109 112 protected void renderToolTipText(MultiValueResolutionDecision decision) { 110 String toolTipText ;113 String toolTipText = null; 111 114 switch (decision.getDecisionType()) { 112 115 case UNDECIDED: 113 116 toolTipText = tr("Please decide which values to keep"); 114 setToolTipText(toolTipText);115 cbDecisionRenderer.setToolTipText(toolTipText);116 117 break; 117 118 case KEEP_ONE: 118 119 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()); 121 123 break; 122 124 case KEEP_NONE: 123 125 toolTipText = tr("The key ''{0}'' and all its values are going to be removed", decision.getKey()); 124 setToolTipText(toolTipText);125 cbDecisionRenderer.setToolTipText(toolTipText);126 126 break; 127 127 case KEEP_ALL: 128 128 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);131 129 break; 132 130 } 131 setToolTipText(toolTipText); 132 cbDecisionRenderer.setToolTipText(toolTipText); 133 133 } 134 134 -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueDecisionType.java
r3083 r7743 4 4 /** 5 5 * Represents a decision for a tag conflict due to multiple possible values. 6 * 7 * 6 * @since 2008 8 7 */ 9 8 public enum MultiValueDecisionType { … … 12 11 /** keep exactly one values */ 13 12 KEEP_ONE, 13 /** sum all numeric values; only available for a few keys (eg: capacity) */ 14 SUM_ALL_NUMERIC, 14 15 /** keep no value, delete the tag */ 15 16 KEEP_NONE, -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueResolutionDecision.java
r7005 r7743 16 16 import org.openstreetmap.josm.data.osm.TagCollection; 17 17 import org.openstreetmap.josm.tools.CheckParameterUtil; 18 18 19 /** 19 20 * Represents a decision for a conflict due to multiple possible value for a tag. 20 * 21 * 21 * @since 2008 22 22 */ 23 23 public class MultiValueResolutionDecision { … … 26 26 private MultiValueDecisionType type; 27 27 /** the collection of tags for which a decision is needed */ 28 private TagCollection 28 private TagCollection tags; 29 29 /** the selected value if {@link #type} is {@link MultiValueDecisionType#KEEP_ONE} */ 30 30 private String value; … … 89 89 90 90 /** 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 /** 91 99 * Apply the decision to keep exactly one value 92 100 * … … 135 143 case UNDECIDED: throw new IllegalStateException(tr("Not decided yet.")); 136 144 case KEEP_ONE: return value; 145 case SUM_ALL_NUMERIC: return tags.getSummedValues(getKey()); 137 146 case KEEP_NONE: return null; 138 147 case KEEP_ALL: return tags.getJoinedValues(getKey()); 139 } 140 // should not happen 141 return null; 148 default: return null; 149 } 142 150 } 143 151 … … 180 188 public boolean canKeepAll() { 181 189 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(); 182 200 } 183 201 … … 275 293 public Tag getResolution() { 276 294 switch(type) { 295 case SUM_ALL_NUMERIC: return new Tag(getKey(), tags.getSummedValues(getKey())); 277 296 case KEEP_ALL: return new Tag(getKey(), tags.getJoinedValues(getKey())); 278 297 case KEEP_ONE: return new Tag(getKey(),value); 279 298 case KEEP_NONE: return new Tag(getKey(), ""); 280 299 case UNDECIDED: return null; 281 }282 return null;300 default: return null; 301 } 283 302 } 284 303 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java
r7643 r7743 178 178 decision.keepAll(); 179 179 break; 180 case SUM_ALL_NUMERIC: 181 decision.sumAllNumeric(); 182 break; 180 183 } 181 184 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverTable.java
r7022 r7743 40 40 getActionMap().put("selectPreviousColumnCell", selectPreviousColumnCellAction); 41 41 42 ((MultiValueCellEditor)getColumnModel().getColumn(2).getCellEditor()).addNavigationListener s(this);42 ((MultiValueCellEditor)getColumnModel().getColumn(2).getCellEditor()).addNavigationListener(this); 43 43 44 44 setRowHeight((int)new JosmComboBox<String>().getPreferredSize().getHeight());
Note:
See TracChangeset
for help on using the changeset viewer.