Changeset 10538 in osm for applications/editors/josm/plugins/validator/src
- Timestamp:
- 2008-09-07T17:14:26+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r10502 r10538 1 1 package org.openstreetmap.josm.plugins.validator; 2 2 3 import static org.openstreetmap.josm.tools.I18n.marktr; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.marktr;5 5 6 6 import java.awt.BorderLayout; … … 9 9 import java.awt.event.ActionListener; 10 10 import java.awt.event.KeyEvent; 11 import java.awt.event.MouseAdapter; 11 12 import java.awt.event.MouseEvent; 12 import java.awt.event.MouseAdapter;13 13 import java.util.Collection; 14 14 import java.util.Enumeration; 15 15 import java.util.HashSet; 16 import java.util.Map.Entry;17 16 import java.util.Set; 18 17 18 import javax.swing.JOptionPane; 19 19 import javax.swing.JPanel; 20 import javax.swing.JOptionPane;21 20 import javax.swing.JScrollPane; 22 21 import javax.swing.event.TreeSelectionEvent; … … 27 26 import org.openstreetmap.josm.Main; 28 27 import org.openstreetmap.josm.command.Command; 29 import org.openstreetmap.josm. command.SequenceCommand;28 import org.openstreetmap.josm.data.coor.EastNorth; 30 29 import org.openstreetmap.josm.data.osm.DataSet; 30 import org.openstreetmap.josm.data.osm.Node; 31 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 import org.openstreetmap.josm.data.osm.Way; 33 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 32 34 import org.openstreetmap.josm.gui.SideButton; 33 35 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 34 import org.openstreetmap.josm.plugins.validator.util.Bag;35 import org.openstreetmap.josm.plugins.validator.util.Util;36 36 import org.openstreetmap.josm.tools.ImageProvider; 37 37 … … 40 40 * respects clicks into the selection list. Ctrl-click will remove entries from 41 41 * the list while single click will make the clicked entry the only selection. 42 * 42 * 43 43 * @author frsantos 44 44 */ 45 public class ValidatorDialog extends ToggleDialog implements ActionListener 46 { 47 private OSMValidatorPlugin plugin; 48 49 /** Serializable ID */ 50 private static final long serialVersionUID = 2952292777351992696L; 51 52 /** The display tree */ 53 protected ErrorTreePanel tree; 54 55 private SideButton fixButton; /** The fix button */ 56 private SideButton ignoreButton; /** The ignore button */ 57 private SideButton selectButton; /** The select button */ 58 59 /** Last selected element */ 60 private DefaultMutableTreeNode lastSelectedNode = null; 61 62 /** 63 * Constructor 64 */ 65 public ValidatorDialog(OSMValidatorPlugin plugin) { 66 super(tr("Validation errors"), "validator", tr("Open the validation window."), KeyEvent.VK_V, 150); 67 68 this.plugin = plugin; 69 70 tree = new ErrorTreePanel(); 71 tree.addMouseListener(new ClickWatch()); 72 tree.addTreeSelectionListener(new SelectionWatch()); 73 74 add(new JScrollPane(tree), BorderLayout.CENTER); 75 76 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); 77 78 selectButton = new SideButton(marktr("Select"), "select", "Validator", 79 tr("Set the selected elements on the map to the selected items in the list above."), this); 80 selectButton.setEnabled(false); 81 buttonPanel.add(selectButton); 82 buttonPanel.add(new SideButton(marktr("Validate"), "refresh", "Validator", 83 tr("Validate either current selection or complete dataset."), this)); 84 fixButton = new SideButton(marktr("Fix"), "fix", "Validator", tr("Fix the selected errors."), this); 85 fixButton.setEnabled(false); 86 buttonPanel.add(fixButton); 87 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) 88 { 89 ignoreButton = new SideButton(marktr("Ignore"), "delete", "Validator", tr("Ignore the selected errors next time."), this); 90 ignoreButton.setEnabled(false); 91 buttonPanel.add(ignoreButton); 92 } 93 else 94 { 95 ignoreButton = null; 96 } 97 add(buttonPanel, BorderLayout.SOUTH); 98 } 99 100 @Override 101 public void setVisible(boolean v) 102 { 103 if( tree != null ) 104 tree.setVisible(v); 105 if( action != null && action.button != null ) 106 action.button.setSelected(v); 107 super.setVisible(v); 108 Main.map.repaint(); 109 } 110 111 112 /** 113 * Fix selected errors 114 * @param e 115 */ 116 @SuppressWarnings("unchecked") 117 private void fixErrors(ActionEvent e) 118 { 119 TreePath[] selectionPaths = tree.getSelectionPaths(); 120 if( selectionPaths == null ) 121 return; 122 123 Set<DefaultMutableTreeNode> processedNodes = new HashSet<DefaultMutableTreeNode>(); 124 for( TreePath path : selectionPaths ) 125 { 126 DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); 127 if( node == null ) 128 continue; 129 130 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 131 while( children.hasMoreElements() ) 132 { 133 DefaultMutableTreeNode childNode = children.nextElement(); 134 if( processedNodes.contains(childNode) ) 135 continue; 136 137 processedNodes.add(childNode); 138 Object nodeInfo = childNode.getUserObject(); 139 if( nodeInfo instanceof TestError) 140 { 141 TestError error = (TestError)nodeInfo; 142 Command fixCommand = error.getFix(); 143 if( fixCommand != null ) 144 { 145 Main.main.undoRedo.add(fixCommand); 146 error.setIgnored(true); 147 } 148 } 149 } 150 } 151 152 Main.map.repaint(); 153 tree.resetErrors(); 154 DataSet.fireSelectionChanged(Main.ds.getSelected()); 155 } 156 157 /** 158 * Set selected errors to ignore state 159 * @param e 160 */ 161 @SuppressWarnings("unchecked") 162 private void ignoreErrors(ActionEvent e) 163 { 164 int asked = JOptionPane.DEFAULT_OPTION; 165 boolean changed = false; 166 TreePath[] selectionPaths = tree.getSelectionPaths(); 167 if( selectionPaths == null ) 168 return; 169 170 Set<DefaultMutableTreeNode> processedNodes = new HashSet<DefaultMutableTreeNode>(); 171 for( TreePath path : selectionPaths ) 172 { 173 DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); 174 if( node == null ) 175 continue; 176 177 Object mainNodeInfo = node.getUserObject(); 178 if(!(mainNodeInfo instanceof TestError)) 179 { 180 int depth = 1; 181 Set<String> state = new HashSet<String>(); 182 // ask if the whole set should be ignored 183 if(asked == JOptionPane.DEFAULT_OPTION) 184 { 185 String[] a = new String[]{tr("Whole group"), tr("Single elements"),tr("Nothing")}; 186 asked = JOptionPane.showOptionDialog(Main.parent, tr("Ignore whole group or individual elements?"), 187 tr("Ignoring elements"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, 188 ImageProvider.get("dialogs", "delete"), a, a[1]); 189 } 190 if(asked == JOptionPane.YES_NO_OPTION) 191 { 192 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 193 while(children.hasMoreElements()) 194 { 195 DefaultMutableTreeNode childNode = children.nextElement(); 196 if(processedNodes.contains(childNode)) 197 continue; 198 199 processedNodes.add(childNode); 200 Object nodeInfo = childNode.getUserObject(); 201 if(nodeInfo instanceof TestError) 202 { 203 TestError err = (TestError)nodeInfo; 204 err.setIgnored(true); 205 changed = true; 206 state.add(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup()); 207 } 208 } 209 for(String s : state) 210 plugin.ignoredErrors.add(s); 211 continue; 212 } 213 else if(asked == JOptionPane.CANCEL_OPTION) 214 continue; 215 } 216 217 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 218 while( children.hasMoreElements() ) 219 { 220 DefaultMutableTreeNode childNode = children.nextElement(); 221 if( processedNodes.contains(childNode) ) 222 continue; 223 224 processedNodes.add(childNode); 225 Object nodeInfo = childNode.getUserObject(); 226 if( nodeInfo instanceof TestError) 227 { 228 TestError error = (TestError)nodeInfo; 229 String state = error.getIgnoreState(); 230 if(state != null) 231 plugin.ignoredErrors.add(state); 232 changed = true; 233 error.setIgnored(true); 234 } 235 } 236 } 237 if(changed) 238 { 239 tree.resetErrors(); 240 plugin.saveIgnoredErrors(); 241 Main.map.repaint(); 242 } 243 } 244 245 /** 246 * Sets the selection of the map to the current selected items. 247 */ 248 @SuppressWarnings("unchecked") 249 private void setSelectedItems() 250 { 251 if( tree == null ) 252 return; 253 254 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40); 255 256 TreePath[] selectedPaths = tree.getSelectionPaths(); 257 if( selectedPaths == null) 258 return; 259 260 for( TreePath path : selectedPaths) 261 { 262 DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); 263 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 264 while( children.hasMoreElements() ) 265 { 266 DefaultMutableTreeNode childNode = children.nextElement(); 267 Object nodeInfo = childNode.getUserObject(); 268 if( nodeInfo instanceof TestError) 269 { 270 TestError error = (TestError)nodeInfo; 271 sel.addAll( error.getPrimitives() ); 272 } 273 } 274 } 275 276 Main.ds.setSelected(sel); 277 } 278 279 public void actionPerformed(ActionEvent e) 280 { 281 String actionCommand = e.getActionCommand(); 282 if( actionCommand.equals("Select")) 283 setSelectedItems(); 284 else if( actionCommand.equals("Validate")) 285 plugin.validateAction.actionPerformed(e); 286 else if( actionCommand.equals("Fix")) 287 fixErrors(e); 288 else if( actionCommand.equals("Ignore")) 289 ignoreErrors(e); 290 } 291 292 /** 293 * Checks for fixes in selected element and, if needed, adds to the sel parameter all selected elements 294 * @param sel The collection where to add all selected elements 295 * @param addSelected if true, add all selected elements to collection 296 * @return whether the selected elements has any fix 297 */ 298 @SuppressWarnings("unchecked") 299 private boolean setSelection(Collection<OsmPrimitive> sel, boolean addSelected) 300 { 301 boolean hasFixes = false; 302 303 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 304 if( lastSelectedNode != null && !lastSelectedNode.equals(node) ) 305 { 306 Enumeration<DefaultMutableTreeNode> children = lastSelectedNode.breadthFirstEnumeration(); 307 while( children.hasMoreElements() ) 308 { 309 DefaultMutableTreeNode childNode = children.nextElement(); 310 Object nodeInfo = childNode.getUserObject(); 311 if( nodeInfo instanceof TestError) 312 { 313 TestError error = (TestError)nodeInfo; 314 error.setSelected(false); 315 } 316 } 317 } 318 319 lastSelectedNode = node; 320 if( node == null ) 321 return hasFixes; 322 323 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 324 while( children.hasMoreElements() ) 325 { 326 DefaultMutableTreeNode childNode = children.nextElement(); 327 Object nodeInfo = childNode.getUserObject(); 328 if( nodeInfo instanceof TestError) 329 { 330 TestError error = (TestError)nodeInfo; 331 error.setSelected(true); 332 333 hasFixes = hasFixes || error.isFixable(); 334 if( addSelected ) 335 { 336 sel.addAll( error.getPrimitives() ); 337 } 338 } 339 } 340 selectButton.setEnabled(true); 341 if(ignoreButton != null) 342 ignoreButton.setEnabled(true); 343 344 return hasFixes; 345 } 346 347 /** 348 * Watches for clicks. 349 */ 350 public class ClickWatch extends MouseAdapter 351 { 352 @Override 353 public void mouseClicked(MouseEvent e) 354 { 355 fixButton.setEnabled(false); 356 if(ignoreButton != null) 357 ignoreButton.setEnabled(false); 358 selectButton.setEnabled(false); 359 360 boolean isDblClick = e.getClickCount() > 1; 361 Collection<OsmPrimitive> sel = isDblClick ? new HashSet<OsmPrimitive>(40) : null; 362 363 boolean hasFixes = setSelection(sel, isDblClick); 364 fixButton.setEnabled(hasFixes); 365 366 if(isDblClick) 367 { 368 Main.ds.setSelected(sel); 369 } 370 } 371 } 372 373 /** 374 * Watches for tree selection. 375 */ 376 public class SelectionWatch implements TreeSelectionListener 377 { 378 @SuppressWarnings("unchecked") 379 public void valueChanged(TreeSelectionEvent e) 380 { 381 fixButton.setEnabled(false); 382 if(ignoreButton != null) 383 ignoreButton.setEnabled(false); 384 selectButton.setEnabled(false); 385 386 if(e.getSource() instanceof JScrollPane) 387 { 388 System.out.println(e.getSource()); 389 return; 390 } 391 392 boolean hasFixes = setSelection(null, false); 393 fixButton.setEnabled(hasFixes); 394 Main.map.repaint(); 395 } 396 } 45 public class ValidatorDialog extends ToggleDialog implements ActionListener { 46 private OSMValidatorPlugin plugin; 47 48 /** Serializable ID */ 49 private static final long serialVersionUID = 2952292777351992696L; 50 51 /** The display tree */ 52 protected ErrorTreePanel tree; 53 54 private SideButton fixButton; 55 /** The fix button */ 56 private SideButton ignoreButton; 57 /** The ignore button */ 58 private SideButton selectButton; 59 /** The select button */ 60 61 /** Last selected element */ 62 private DefaultMutableTreeNode lastSelectedNode = null; 63 64 /** 65 * Constructor 66 */ 67 public ValidatorDialog(OSMValidatorPlugin plugin) { 68 super(tr("Validation errors"), "validator", tr("Open the validation window."), KeyEvent.VK_V, 150); 69 70 this.plugin = plugin; 71 72 tree = new ErrorTreePanel(); 73 tree.addMouseListener(new ClickWatch()); 74 tree.addTreeSelectionListener(new SelectionWatch()); 75 76 add(new JScrollPane(tree), BorderLayout.CENTER); 77 78 JPanel buttonPanel = new JPanel(new GridLayout(1, 3)); 79 80 selectButton = new SideButton(marktr("Select"), "select", "Validator", 81 tr("Set the selected elements on the map to the selected items in the list above."), this); 82 selectButton.setEnabled(false); 83 buttonPanel.add(selectButton); 84 buttonPanel.add(new SideButton(marktr("Validate"), "refresh", "Validator", 85 tr("Validate either current selection or complete dataset."), this)); 86 fixButton = new SideButton(marktr("Fix"), "fix", "Validator", tr("Fix the selected errors."), this); 87 fixButton.setEnabled(false); 88 buttonPanel.add(fixButton); 89 if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) { 90 ignoreButton = new SideButton(marktr("Ignore"), "delete", "Validator", 91 tr("Ignore the selected errors next time."), this); 92 ignoreButton.setEnabled(false); 93 buttonPanel.add(ignoreButton); 94 } else { 95 ignoreButton = null; 96 } 97 add(buttonPanel, BorderLayout.SOUTH); 98 } 99 100 @Override 101 public void setVisible(boolean v) { 102 if (tree != null) 103 tree.setVisible(v); 104 if (action != null && action.button != null) 105 action.button.setSelected(v); 106 super.setVisible(v); 107 Main.map.repaint(); 108 } 109 110 /** 111 * Fix selected errors 112 * 113 * @param e 114 */ 115 @SuppressWarnings("unchecked") 116 private void fixErrors(ActionEvent e) { 117 TreePath[] selectionPaths = tree.getSelectionPaths(); 118 if (selectionPaths == null) 119 return; 120 121 Set<DefaultMutableTreeNode> processedNodes = new HashSet<DefaultMutableTreeNode>(); 122 for (TreePath path : selectionPaths) { 123 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 124 if (node == null) 125 continue; 126 127 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 128 while (children.hasMoreElements()) { 129 DefaultMutableTreeNode childNode = children.nextElement(); 130 if (processedNodes.contains(childNode)) 131 continue; 132 133 processedNodes.add(childNode); 134 Object nodeInfo = childNode.getUserObject(); 135 if (nodeInfo instanceof TestError) { 136 TestError error = (TestError) nodeInfo; 137 Command fixCommand = error.getFix(); 138 if (fixCommand != null) { 139 Main.main.undoRedo.add(fixCommand); 140 error.setIgnored(true); 141 } 142 } 143 } 144 } 145 146 Main.map.repaint(); 147 tree.resetErrors(); 148 DataSet.fireSelectionChanged(Main.ds.getSelected()); 149 } 150 151 /** 152 * Set selected errors to ignore state 153 * 154 * @param e 155 */ 156 @SuppressWarnings("unchecked") 157 private void ignoreErrors(ActionEvent e) { 158 int asked = JOptionPane.DEFAULT_OPTION; 159 boolean changed = false; 160 TreePath[] selectionPaths = tree.getSelectionPaths(); 161 if (selectionPaths == null) 162 return; 163 164 Set<DefaultMutableTreeNode> processedNodes = new HashSet<DefaultMutableTreeNode>(); 165 for (TreePath path : selectionPaths) { 166 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 167 if (node == null) 168 continue; 169 170 Object mainNodeInfo = node.getUserObject(); 171 if (!(mainNodeInfo instanceof TestError)) { 172 Set<String> state = new HashSet<String>(); 173 // ask if the whole set should be ignored 174 if (asked == JOptionPane.DEFAULT_OPTION) { 175 String[] a = new String[] { tr("Whole group"), tr("Single elements"), tr("Nothing") }; 176 asked = JOptionPane.showOptionDialog(Main.parent, tr("Ignore whole group or individual elements?"), 177 tr("Ignoring elements"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, 178 ImageProvider.get("dialogs", "delete"), a, a[1]); 179 } 180 if (asked == JOptionPane.YES_NO_OPTION) { 181 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 182 while (children.hasMoreElements()) { 183 DefaultMutableTreeNode childNode = children.nextElement(); 184 if (processedNodes.contains(childNode)) 185 continue; 186 187 processedNodes.add(childNode); 188 Object nodeInfo = childNode.getUserObject(); 189 if (nodeInfo instanceof TestError) { 190 TestError err = (TestError) nodeInfo; 191 err.setIgnored(true); 192 changed = true; 193 state.add(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup()); 194 } 195 } 196 for (String s : state) 197 plugin.ignoredErrors.add(s); 198 continue; 199 } else if (asked == JOptionPane.CANCEL_OPTION) 200 continue; 201 } 202 203 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 204 while (children.hasMoreElements()) { 205 DefaultMutableTreeNode childNode = children.nextElement(); 206 if (processedNodes.contains(childNode)) 207 continue; 208 209 processedNodes.add(childNode); 210 Object nodeInfo = childNode.getUserObject(); 211 if (nodeInfo instanceof TestError) { 212 TestError error = (TestError) nodeInfo; 213 String state = error.getIgnoreState(); 214 if (state != null) 215 plugin.ignoredErrors.add(state); 216 changed = true; 217 error.setIgnored(true); 218 } 219 } 220 } 221 if (changed) { 222 tree.resetErrors(); 223 plugin.saveIgnoredErrors(); 224 Main.map.repaint(); 225 } 226 } 227 228 /** 229 * Sets the selection of the map to the current selected items. 230 */ 231 @SuppressWarnings("unchecked") 232 private void setSelectedItems() { 233 if (tree == null) 234 return; 235 236 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40); 237 238 TreePath[] selectedPaths = tree.getSelectionPaths(); 239 if (selectedPaths == null) 240 return; 241 242 for (TreePath path : selectedPaths) { 243 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 244 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 245 while (children.hasMoreElements()) { 246 DefaultMutableTreeNode childNode = children.nextElement(); 247 Object nodeInfo = childNode.getUserObject(); 248 if (nodeInfo instanceof TestError) { 249 TestError error = (TestError) nodeInfo; 250 sel.addAll(error.getPrimitives()); 251 } 252 } 253 } 254 255 Main.ds.setSelected(sel); 256 } 257 258 public void actionPerformed(ActionEvent e) { 259 String actionCommand = e.getActionCommand(); 260 if (actionCommand.equals("Select")) 261 setSelectedItems(); 262 else if (actionCommand.equals("Validate")) 263 plugin.validateAction.actionPerformed(e); 264 else if (actionCommand.equals("Fix")) 265 fixErrors(e); 266 else if (actionCommand.equals("Ignore")) 267 ignoreErrors(e); 268 } 269 270 /** 271 * Checks for fixes in selected element and, if needed, adds to the sel 272 * parameter all selected elements 273 * 274 * @param sel 275 * The collection where to add all selected elements 276 * @param addSelected 277 * if true, add all selected elements to collection 278 * @return whether the selected elements has any fix 279 */ 280 @SuppressWarnings("unchecked") 281 private boolean setSelection(Collection<OsmPrimitive> sel, boolean addSelected) { 282 boolean hasFixes = false; 283 284 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); 285 if (lastSelectedNode != null && !lastSelectedNode.equals(node)) { 286 Enumeration<DefaultMutableTreeNode> children = lastSelectedNode.breadthFirstEnumeration(); 287 while (children.hasMoreElements()) { 288 DefaultMutableTreeNode childNode = children.nextElement(); 289 Object nodeInfo = childNode.getUserObject(); 290 if (nodeInfo instanceof TestError) { 291 TestError error = (TestError) nodeInfo; 292 error.setSelected(false); 293 } 294 } 295 } 296 297 lastSelectedNode = node; 298 if (node == null) 299 return hasFixes; 300 301 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 302 while (children.hasMoreElements()) { 303 DefaultMutableTreeNode childNode = children.nextElement(); 304 Object nodeInfo = childNode.getUserObject(); 305 if (nodeInfo instanceof TestError) { 306 TestError error = (TestError) nodeInfo; 307 error.setSelected(true); 308 309 hasFixes = hasFixes || error.isFixable(); 310 if (addSelected) { 311 sel.addAll(error.getPrimitives()); 312 } 313 } 314 } 315 selectButton.setEnabled(true); 316 if (ignoreButton != null) 317 ignoreButton.setEnabled(true); 318 319 return hasFixes; 320 } 321 322 /** 323 * Watches for clicks. 324 */ 325 public class ClickWatch extends MouseAdapter { 326 @Override 327 public void mouseClicked(MouseEvent e) { 328 fixButton.setEnabled(false); 329 if (ignoreButton != null) 330 ignoreButton.setEnabled(false); 331 selectButton.setEnabled(false); 332 333 boolean isDblClick = e.getClickCount() > 1; 334 335 Collection<OsmPrimitive> sel = isDblClick ? new HashSet<OsmPrimitive>(40) : null; 336 337 boolean hasFixes = setSelection(sel, isDblClick); 338 fixButton.setEnabled(hasFixes); 339 340 if (isDblClick) { 341 Main.ds.setSelected(sel); 342 if (sel.size() == 1) { 343 // Center the view on the selected item 344 double scale = Main.map.mapView.getScale(); 345 OsmPrimitive prim = sel.iterator().next(); 346 BoundingXYVisitor box = new BoundingXYVisitor(); 347 if (prim instanceof Way) { 348 Way way = (Way) prim; 349 way.visitNodes(box); 350 EastNorth center = new EastNorth(box.min.east() / 2 + box.max.east() / 2, box.min.north() / 2 351 + box.max.north() / 2); 352 Main.map.mapView.zoomTo(center, scale); 353 } else if (prim instanceof Node) { 354 Node node = (Node) prim; 355 Main.map.mapView.zoomTo(node.eastNorth, scale); 356 } 357 } 358 } 359 } 360 } 361 362 /** 363 * Watches for tree selection. 364 */ 365 public class SelectionWatch implements TreeSelectionListener { 366 public void valueChanged(TreeSelectionEvent e) { 367 fixButton.setEnabled(false); 368 if (ignoreButton != null) 369 ignoreButton.setEnabled(false); 370 selectButton.setEnabled(false); 371 372 if (e.getSource() instanceof JScrollPane) { 373 System.out.println(e.getSource()); 374 return; 375 } 376 377 boolean hasFixes = setSelection(null, false); 378 fixButton.setEnabled(hasFixes); 379 Main.map.repaint(); 380 } 381 } 397 382 }
Note:
See TracChangeset
for help on using the changeset viewer.