Changeset 1904 in josm
- Timestamp:
- 2009-08-04T09:32:43+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/ConflictResolver.java
r1690 r1904 7 7 import java.beans.PropertyChangeEvent; 8 8 import java.beans.PropertyChangeListener; 9 import java.beans.PropertyChangeSupport; 9 10 import java.util.ArrayList; 10 11 import java.util.logging.Logger; … … 35 36 * An UI component for resolving conflicts between two {@see OsmPrimitive}s. 36 37 * 38 * This component emits {@see PropertyChangeEvent}s for three properties: 39 * <ul> 40 * <li>{@see #RESOLVED_COMPLETELY_PROP} - new value is <code>true</code>, if the conflict is 41 * completely resolved</li> 42 * <li>{@see #MY_PRIMITIVE_PROP} - new value is the {@see OsmPrimitive} in the role of 43 * my primitive</li> 44 * <li>{@see #THEIR_PRIMITIVE_PROP} - new value is the {@see OsmPrimitive} in the role of 45 * their primitive</li> 46 * </ul> 47 * 37 48 */ 38 49 public class ConflictResolver extends JPanel implements PropertyChangeListener { 50 static public final String RESOLVED_COMPLETELY_PROP = ConflictResolver.class.getName() + ".resolvedCompletely"; 51 static public final String MY_PRIMITIVE_PROP = ConflictResolver.class.getName() + ".myPrimitive"; 52 static public final String THEIR_PRIMITIVE_PROP = ConflictResolver.class.getName() + ".theirPrimitive"; 53 39 54 40 55 private static final Logger logger = Logger.getLogger(ConflictResolver.class.getName()); … … 51 66 private ImageIcon mergeIncomplete; 52 67 68 /** the property change listeners */ 69 private PropertyChangeSupport listeners; 70 71 /** indicates whether the current conflict is resolved completely */ 72 private boolean resolvedCompletely; 73 53 74 protected void loadIcons() { 54 75 mergeComplete = ImageProvider.get("dialogs/conflict","mergecomplete.png" ); … … 83 104 } 84 105 106 85 107 public ConflictResolver() { 108 listeners = new PropertyChangeSupport(this); 109 resolvedCompletely = false; 86 110 build(); 87 111 loadIcons(); 112 } 113 114 115 protected void setMy(OsmPrimitive my) { 116 OsmPrimitive old = this.my; 117 this.my = my; 118 if (old != this.my) { 119 fireMyPrimitive(old, this.my); 120 } 121 } 122 123 protected void setTheir(OsmPrimitive their) { 124 OsmPrimitive old = this.their; 125 this.their = their; 126 if (old != this.their) { 127 fireTheirPrimitive(old, this.their); 128 } 129 } 130 131 protected void fireResolvedCompletely(boolean oldValue,boolean newValue) { 132 if (listeners == null) return; 133 listeners.firePropertyChange(RESOLVED_COMPLETELY_PROP, oldValue, newValue); 134 } 135 136 protected void fireMyPrimitive(OsmPrimitive oldValue,OsmPrimitive newValue) { 137 if (listeners == null) return; 138 listeners.firePropertyChange(MY_PRIMITIVE_PROP, oldValue, newValue); 139 } 140 141 protected void fireTheirPrimitive(OsmPrimitive oldValue,OsmPrimitive newValue) { 142 if (listeners == null) return; 143 listeners.firePropertyChange(THEIR_PRIMITIVE_PROP, oldValue, newValue); 144 } 145 146 /** 147 * Adds a property change listener 148 * 149 * @param listener the listener 150 */ 151 @Override 152 public void addPropertyChangeListener(PropertyChangeListener listener) { 153 listeners.addPropertyChangeListener(listener); 154 } 155 156 /** 157 * Removes a property change listener 158 * 159 * @param listener the listener 160 */ 161 162 @Override 163 public void removePropertyChangeListener(PropertyChangeListener listener) { 164 listeners.removePropertyChangeListener(listener); 88 165 } 89 166 … … 100 177 tabbedPane.setIconAt(1, mergeIncomplete); 101 178 } 179 updateResolvedCompletely(); 102 180 } else if (evt.getPropertyName().equals(ListMergeModel.FROZEN_PROP)) { 103 181 boolean frozen = (Boolean)evt.getNewValue(); … … 120 198 tabbedPane.setIconAt(3, mergeIncomplete); 121 199 } 200 updateResolvedCompletely(); 122 201 } else if (evt.getPropertyName().equals(PropertiesMergeModel.RESOLVED_COMPLETELY_PROP)) { 123 202 boolean resolved = (Boolean)evt.getNewValue(); … … 131 210 tabbedPane.setIconAt(0, mergeIncomplete); 132 211 } 212 updateResolvedCompletely(); 133 213 } 134 214 } … … 143 223 */ 144 224 public void populate(OsmPrimitive my, OsmPrimitive their) { 145 this.my = my;146 this.their = their;225 setMy(my); 226 setTheir(their); 147 227 propertiesMerger.getModel().populate(my, their); 148 228 if (propertiesMerger.getModel().hasVisibleStateConflict()) { … … 172 252 tabbedPane.setEnabledAt(3, true); 173 253 } 174 175 } 176 177 /** 178 * Builds the resolution command(s) for forthe resolved conflicts in this254 updateResolvedCompletely(); 255 } 256 257 /** 258 * Builds the resolution command(s) for the resolved conflicts in this 179 259 * ConflictResolver 180 260 * … … 208 288 } 209 289 210 public boolean isResolvedCompletely() { 290 protected void updateResolvedCompletely() { 291 boolean oldValueResolvedCompletely = resolvedCompletely; 211 292 if (my instanceof Node) { 212 293 // resolve the version conflict if this is a node and all tag 213 294 // conflicts have been resolved 214 295 // 215 if (tagMerger.getModel().isResolvedCompletely()216 && propertiesMerger.getModel().isResolvedCompletely())217 return true;296 this.resolvedCompletely = 297 tagMerger.getModel().isResolvedCompletely() 298 && propertiesMerger.getModel().isResolvedCompletely(); 218 299 } else if (my instanceof Way) { 219 300 // resolve the version conflict if this is a way, all tag … … 221 302 // have been resolved 222 303 // 223 if (tagMerger.getModel().isResolvedCompletely()224 && propertiesMerger.getModel().isResolvedCompletely()225 && nodeListMerger.getModel().isFrozen())226 return true;304 this.resolvedCompletely = 305 tagMerger.getModel().isResolvedCompletely() 306 && propertiesMerger.getModel().isResolvedCompletely() 307 && nodeListMerger.getModel().isFrozen(); 227 308 } else if (my instanceof Relation) { 228 309 // resolve the version conflict if this is a relation, all tag … … 230 311 // have been resolved 231 312 // 232 if (tagMerger.getModel().isResolvedCompletely() 233 && propertiesMerger.getModel().isResolvedCompletely() 234 && relationMemberMerger.getModel().isFrozen()) 235 return true; 236 } 237 return false; 313 this.resolvedCompletely = 314 tagMerger.getModel().isResolvedCompletely() 315 && propertiesMerger.getModel().isResolvedCompletely() 316 && relationMemberMerger.getModel().isFrozen(); 317 } 318 if (this.resolvedCompletely != oldValueResolvedCompletely) { 319 fireResolvedCompletely(oldValueResolvedCompletely, this.resolvedCompletely); 320 } 321 } 322 323 /** 324 * Replies true all differences in this conflicts are resolved 325 * 326 * @return true all differences in this conflicts are resolved 327 */ 328 public boolean isResolvedCompletely() { 329 return resolvedCompletely; 238 330 } 239 331 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
r1857 r1904 10 10 import java.awt.Point; 11 11 import java.awt.event.ActionEvent; 12 import java.beans.PropertyChangeEvent; 13 import java.beans.PropertyChangeListener; 12 14 import java.util.logging.Logger; 13 15 … … 22 24 import org.openstreetmap.josm.Main; 23 25 import org.openstreetmap.josm.command.Command; 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 27 import org.openstreetmap.josm.gui.OptionPaneUtil; 28 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 25 29 import org.openstreetmap.josm.gui.conflict.ConflictResolver; 26 30 import org.openstreetmap.josm.gui.conflict.properties.OperationCancelledException; … … 28 32 29 33 /** 30 * This is an extended dialog for resolving conflict between {@see OsmPrimitive}. 31 * 34 * This is an extended dialog for resolving conflict between {@see OsmPrimitive}s. 32 35 * 33 36 */ 34 public class ConflictResolutionDialog extends JDialog {37 public class ConflictResolutionDialog extends JDialog implements PropertyChangeListener { 35 38 private static final Logger logger = Logger.getLogger(ConflictResolutionDialog.class.getName()); 36 39 public final static Dimension DEFAULT_SIZE = new Dimension(600,400); … … 114 117 pnl.setLayout(new FlowLayout(FlowLayout.CENTER)); 115 118 116 JButton btn = new JButton(new ApplyResolutionAction()); 119 ApplyResolutionAction applyResolutionAction = new ApplyResolutionAction(); 120 resolver.addPropertyChangeListener(applyResolutionAction); 121 JButton btn = new JButton(applyResolutionAction); 117 122 btn.setName("button.apply"); 118 123 pnl.add(btn); … … 130 135 */ 131 136 protected void build() { 132 setTitle(tr("Resolve conflicts"));137 updateTitle(); 133 138 try { 134 139 setAlwaysOnTop(true); … … 142 147 getContentPane().add(resolver, BorderLayout.CENTER); 143 148 getContentPane().add(buildButtonRow(), BorderLayout.SOUTH); 149 150 resolver.addPropertyChangeListener(this); 144 151 } 145 152 … … 154 161 } 155 162 163 /** 164 * Action for canceling conflict resolution 165 */ 156 166 class CancelAction extends AbstractAction { 157 167 public CancelAction() { … … 168 178 } 169 179 170 class ApplyResolutionAction extends AbstractAction { 180 /** 181 * Action for applying resolved differences in a conflict 182 * 183 */ 184 class ApplyResolutionAction extends AbstractAction implements PropertyChangeListener { 171 185 public ApplyResolutionAction() { 172 186 putValue(Action.SHORT_DESCRIPTION, tr("Apply resolved conflicts and close the dialog")); 173 187 putValue(Action.NAME, tr("Apply Resolution")); 174 188 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs", "conflict")); 175 setEnabled(true); 189 updateEnabledState(); 190 } 191 192 protected void updateEnabledState() { 193 setEnabled(resolver.isResolvedCompletely()); 176 194 } 177 195 … … 179 197 if (! resolver.isResolvedCompletely()) { 180 198 Object[] options = { 181 tr(" Apply partial resolutions"),199 tr("Close anyway"), 182 200 tr("Continue resolving")}; 183 int n = OptionPaneUtil.showOptionDialog(null, 184 tr("<html>You didn''t finish to resolve all conflicts.<br>" 185 + "Click <strong>{0}</strong> to apply already resolved conflicts anyway.<br>" 186 + "You can resolve the remaining conflicts later.<br>" 201 int ret = OptionPaneUtil.showOptionDialog(Main.parent, 202 tr("<html>You didn''t finish to merge the differences in this conflict.<br>" 203 + "Conflict resolutions won't be applied unless all differences<br>" 204 + "are resolved." 205 + "Click <strong>{0}</strong> to close anyway.<strong>Already<br>" 206 + "resolved differences won't be applied.</strong><br>" 187 207 + "Click <strong>{1}</strong> to return to resolving conflicts.</html>" 188 208 , options[0].toString(), options[1].toString() 189 209 ), 190 tr(" Warning"),210 tr("Conflict not resolved completely"), 191 211 JOptionPane.YES_NO_OPTION, 192 212 JOptionPane.WARNING_MESSAGE, … … 194 214 options[1] 195 215 ); 196 if (n == JOptionPane.NO_OPTION || n == JOptionPane.CLOSED_OPTION) 216 switch(ret) { 217 case JOptionPane.YES_OPTION: 218 setVisible(false); 219 break; 220 default: 197 221 return; 222 } 198 223 } 199 224 try { 200 225 Command cmd = resolver.buildResolveCommand(); 201 226 Main.main.undoRedo.add(cmd); 227 setVisible(false); 202 228 } catch(OperationCancelledException e) { 203 229 // do nothing. Exception already reported 204 230 } 205 setVisible(false); 231 } 232 233 public void propertyChange(PropertyChangeEvent evt) { 234 if (evt.getPropertyName().equals(ConflictResolver.RESOLVED_COMPLETELY_PROP)) { 235 updateEnabledState(); 236 } 237 } 238 } 239 240 protected void updateTitle() { 241 updateTitle(null); 242 } 243 244 protected void updateTitle(OsmPrimitive my) { 245 if (my == null) { 246 setTitle(tr("Resolve conflicts")); 247 } else { 248 PrimitiveNameFormatter formatter = new PrimitiveNameFormatter(); 249 setTitle(tr("Resolve conflicts for ''{0}''", formatter.getName(my))); 250 } 251 } 252 253 public void propertyChange(PropertyChangeEvent evt) { 254 if (evt.getPropertyName().equals(ConflictResolver.MY_PRIMITIVE_PROP)) { 255 updateTitle((OsmPrimitive)evt.getNewValue()); 206 256 } 207 257 }
Note:
See TracChangeset
for help on using the changeset viewer.