Changeset 14847 in josm for trunk/src/org
- Timestamp:
- 2019-03-06T12:08:32+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r14846 r14847 27 27 import javax.swing.event.TreeSelectionListener; 28 28 import javax.swing.tree.DefaultMutableTreeNode; 29 import javax.swing.tree.TreeNode;30 29 import javax.swing.tree.TreePath; 31 30 … … 42 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 42 import org.openstreetmap.josm.data.osm.WaySegment; 43 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 44 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 45 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 46 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 44 47 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 45 48 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 77 80 * @author frsantos 78 81 */ 79 public class ValidatorDialog extends ToggleDialog implements DataSelectionListener, ActiveLayerChangeListener { 82 public class ValidatorDialog extends ToggleDialog 83 implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdapter.Listener { 80 84 81 85 /** The display tree */ … … 85 89 public static final ValidateAction validateAction = new ValidateAction(); 86 90 87 /** The fix button */88 private final SideButton fixButton;89 /** The ignore button */90 private final SideButton ignoreButton;91 /** The reset ignorelist button */92 private final SideButton ignorelistManagement;93 /** The select button */94 private final SideButton selectButton;95 /** The lookup button */96 private final SideButton lookupButton;91 /** The fix action */ 92 private final transient Action fixAction; 93 /** The ignore action */ 94 private final transient Action ignoreAction; 95 /** The ignore-list management action */ 96 private final transient Action ignorelistManagementAction; 97 /** The select action */ 98 private final transient Action selectAction; 99 /** The lookup action */ 100 private final transient LookupAction lookupAction; 97 101 98 102 private final JPopupMenu popupMenu = new JPopupMenu(); 99 103 private final transient PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu); 104 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 100 105 101 106 /** Last selected element */ … … 120 125 List<SideButton> buttons = new LinkedList<>(); 121 126 122 select Button = new SideButton(new AbstractSelectAction() {127 selectAction = new AbstractSelectAction() { 123 128 @Override 124 129 public void actionPerformed(ActionEvent e) { 125 130 setSelectedItems(); 126 131 } 127 }); 128 InputMapUtils.addEnterAction(tree, selectButton.getAction()); 129 130 selectButton.setEnabled(false); 131 buttons.add(selectButton); 132 133 lookupButton = new SideButton(new LookupAction()); 134 buttons.add(lookupButton); 132 }; 133 selectAction.setEnabled(false); 134 InputMapUtils.addEnterAction(tree, selectAction); 135 buttons.add(new SideButton(selectAction)); 136 137 lookupAction = new LookupAction(); 138 buttons.add(new SideButton(lookupAction)); 135 139 136 140 buttons.add(new SideButton(validateAction)); 137 141 138 fix Button = new SideButton(new AbstractAction() {142 fixAction = new AbstractAction() { 139 143 { 140 144 putValue(NAME, tr("Fix")); … … 146 150 fixErrors(); 147 151 } 148 } );149 fix Button.setEnabled(false);150 buttons.add( fixButton);152 }; 153 fixAction.setEnabled(false); 154 buttons.add(new SideButton(fixAction)); 151 155 152 156 if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) { 153 ignore Button = new SideButton(new AbstractAction() {157 ignoreAction = new AbstractAction() { 154 158 { 155 159 putValue(NAME, tr("Ignore")); … … 161 165 ignoreErrors(); 162 166 } 163 }); 164 ignoreButton.setEnabled(false); 165 buttons.add(ignoreButton); 166 167 ignorelistManagement = new SideButton(new AbstractAction() { 168 { 169 putValue(NAME, tr("Manage Ignore")); 170 putValue(SHORT_DESCRIPTION, tr("Manage the ignore list")); 171 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); 172 } 173 174 @Override 175 public void actionPerformed(ActionEvent e) { 176 new ValidatorListManagementDialog("Ignore"); 177 } 178 }); 179 buttons.add(ignorelistManagement); 167 }; 168 ignoreAction.setEnabled(false); 169 buttons.add(new SideButton(ignoreAction)); 170 171 ignorelistManagementAction = new IgnorelistManagementAction(); 172 buttons.add(new SideButton(ignorelistManagementAction)); 180 173 } else { 181 ignore Button = null;182 ignorelistManagement = null;174 ignoreAction = null; 175 ignorelistManagementAction = null; 183 176 } 184 177 … … 187 180 188 181 /** 182 * The action to manage the ignore list. 183 */ 184 static class IgnorelistManagementAction extends AbstractAction { 185 IgnorelistManagementAction() { 186 putValue(NAME, tr("Manage Ignore")); 187 putValue(SHORT_DESCRIPTION, tr("Manage the ignore list")); 188 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); 189 } 190 191 @Override 192 public void actionPerformed(ActionEvent e) { 193 new ValidatorListManagementDialog("Ignore"); 194 } 195 } 196 197 /** 189 198 * The action to lookup the selection in the error tree. 190 199 */ 191 class LookupAction extends AbstractAction implements DataSelectionListener { 192 200 class LookupAction extends AbstractAction { 193 201 LookupAction() { 194 202 putValue(NAME, tr("Lookup")); 195 203 putValue(SHORT_DESCRIPTION, tr("Looks up the selected primitives in the error list.")); 196 204 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true); 197 SelectionEventManager.getInstance().addSelectionListener(this);198 205 updateEnabledState(); 199 206 } … … 208 215 } 209 216 210 p rotectedvoid updateEnabledState() {217 public void updateEnabledState() { 211 218 boolean found = false; 212 219 for (TestError e : tree.getErrors()) { … … 220 227 setEnabled(found); 221 228 } 222 223 @Override224 public void selectionChanged(SelectionChangeEvent event) {225 updateEnabledState();226 }227 229 } 228 230 229 231 @Override 230 232 public void showNotify() { 233 DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED); 231 234 SelectionEventManager.getInstance().addSelectionListener(this); 232 235 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); … … 235 238 } 236 239 MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this); 240 237 241 } 238 242 239 243 @Override 240 244 public void hideNotify() { 245 DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter); 241 246 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 242 247 SelectionEventManager.getInstance().removeSelectionListener(this); … … 349 354 for (TreePath path : selectedPaths) { 350 355 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 351 Enumeration< TreeNode> children = node.breadthFirstEnumeration();356 Enumeration<?> children = node.breadthFirstEnumeration(); 352 357 while (children.hasMoreElements()) { 353 358 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); … … 394 399 } 395 400 }); 396 select Button.setEnabled(true);397 if (ignore Button != null) {398 ignore Button.setEnabled(node.getDepth() <= 1);401 selectAction.setEnabled(true); 402 if (ignoreAction != null) { 403 ignoreAction.setEnabled(node.getDepth() <= 1); 399 404 } 400 405 } … … 472 477 } 473 478 474 fix Button.setEnabled(false);475 if (ignore Button != null) {476 ignore Button.setEnabled(false);477 } 478 select Button.setEnabled(false);479 fixAction.setEnabled(false); 480 if (ignoreAction != null) { 481 ignoreAction.setEnabled(false); 482 } 483 selectAction.setEnabled(false); 479 484 480 485 boolean isDblClick = isDoubleClick(e); … … 483 488 484 489 boolean hasFixes = setSelection(sel, isDblClick); 485 fix Button.setEnabled(hasFixes);490 fixAction.setEnabled(hasFixes); 486 491 487 492 if (isDblClick) { … … 514 519 @Override 515 520 public void valueChanged(TreeSelectionEvent e) { 516 fixButton.setEnabled(false); 517 if (ignoreButton != null) { 518 ignoreButton.setEnabled(false); 519 } 520 selectButton.setEnabled(false); 521 if (ignoreAction != null) { 522 ignoreAction.setEnabled(false); 523 } 524 selectAction.setEnabled(false); 521 525 522 526 Collection<OsmPrimitive> sel = new HashSet<>(); 523 527 boolean hasFixes = setSelection(sel, true); 524 fix Button.setEnabled(hasFixes);528 fixAction.setEnabled(hasFixes); 525 529 popupMenuHandler.setPrimitives(sel); 526 530 invalidateValidatorLayers(); … … 578 582 public void selectionChanged(SelectionChangeEvent event) { 579 583 updateSelection(event.getSelection()); 584 lookupAction.updateEnabledState(); 580 585 } 581 586 … … 682 687 683 688 @Override 684 public void destroy() { 685 if (lookupButton != null && lookupButton.getAction() instanceof DataSelectionListener) { 686 Action a = lookupButton.getAction(); 687 SelectionEventManager.getInstance().removeSelectionListener((DataSelectionListener) a); 688 } 689 super.destroy(); 689 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 690 validateAction.updateEnabledState(); 690 691 } 691 692
Note:
See TracChangeset
for help on using the changeset viewer.