Changeset 2792 in osm for applications/editors/josm/plugins
- Timestamp:
- 2007-05-06T19:51:19+02:00 (18 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java
r2673 r2792 8 8 import javax.swing.tree.DefaultMutableTreeNode; 9 9 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.actions.RenameLayerAction; 11 12 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 12 13 import org.openstreetmap.josm.gui.MapView; 14 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 13 15 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 14 16 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 21 23 * @author frsantos 22 24 */ 23 public class ErrorLayer extends Layer 25 public class ErrorLayer extends Layer implements LayerChangeListener 24 26 { 25 27 /** … … 30 32 { 31 33 super(name); 34 Main.map.mapView.addLayerChangeListener(this); 32 35 } 33 36 … … 48 51 public void paint(final Graphics g, final MapView mv) 49 52 { 50 DefaultMutableTreeNode root = (DefaultMutableTreeNode) OSMValidatorPlugin.getPlugin().validationDialog.treeModel.getRoot();53 DefaultMutableTreeNode root = OSMValidatorPlugin.getPlugin().validationDialog.tree.getRoot(); 51 54 if( root == null || root.getChildCount() == 0) 52 55 return; … … 113 116 114 117 @Override public void destroy() { } 118 119 public void activeLayerChange(Layer oldLayer, Layer newLayer) { } 120 121 public void layerAdded(Layer newLayer) { } 122 123 /** 124 * If layer is the OSM Data layer, remove all errors 125 */ 126 public void layerRemoved(Layer oldLayer) 127 { 128 if(oldLayer == Main.map.mapView.editLayer ) 129 { 130 Main.map.mapView.removeLayer(this); 131 } 132 } 115 133 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r2672 r2792 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.actions.UploadAction; 12 13 import org.openstreetmap.josm.gui.MapFrame; 13 14 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 72 73 newFrame.addToggleDialog(validationDialog); 73 74 Main.main.addLayer(new ErrorLayer(tr("Validation errors"))); 75 try 76 { 77 ((UploadAction)Main.main.menu.upload).uploadHooks.add( new ValidateUploadHook() ); 78 } 79 catch(Throwable t) 80 { 81 // JOSM has no upload hooks in older versions 82 } 74 83 } 75 84 } … … 107 116 } 108 117 test.enabled = true; 109 enabledTests.put(testClass.getSimpleName(), test); 118 119 String simpleName = testClass.getSimpleName(); 120 test.testBeforeUpload = Main.pref.getBoolean( "tests." + simpleName + ".checkBeforeUpload"); 121 enabledTests.put(simpleName, test); 110 122 } 111 123 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/PreferenceEditor.java
r2453 r2792 32 32 testPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 33 33 34 testPanel.add( new JLabel(), GBC.std() ); 35 testPanel.add( new JLabel("On upload"), GBC.eop() ); 36 34 37 allTests = OSMValidatorPlugin.getTests(false); 35 38 for(final Test test: allTests) … … 37 40 final JCheckBox testCheck = new JCheckBox(test.name, test.enabled); 38 41 testCheck.setToolTipText(test.description); 39 testPanel.add(testCheck, GBC.eop().insets(20,0,0,0)); 40 test.addGui(testPanel); 42 testPanel.add(testCheck, GBC.std().insets(20,0,0,0)); 41 43 42 testCheck.addActionListener(new ActionListener(){ 43 public void actionPerformed(ActionEvent e) { 44 test.enabled = testCheck.isSelected(); 45 } 46 }); 44 testCheck.addActionListener(new ActionListener(){ 45 public void actionPerformed(ActionEvent e) { 46 boolean selected = testCheck.isSelected(); 47 test.enabled = selected; 48 test.setGuiEnabled(selected ); 49 } 50 }); 51 52 test.addGui(testPanel); 53 test.setGuiEnabled(test.enabled); 47 54 } 48 55 49 JScrollPane testPane = new JScrollPane(testPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ NEVER);56 JScrollPane testPane = new JScrollPane(testPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 50 57 testPane.setBorder(null); 51 58 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java
r2672 r2792 1 1 package org.openstreetmap.josm.plugins.validator; 2 2 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.List; 3 import java.util.*; 6 4 5 import javax.swing.JCheckBox; 7 6 import javax.swing.JPanel; 8 7 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.command.Command; 10 10 import org.openstreetmap.josm.data.osm.*; 11 11 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 import org.openstreetmap.josm.tools.GBC; 12 13 13 14 /** … … 28 29 protected String description; 29 30 30 /** Whether this test is enabled. Used by peferences */ 31 protected boolean enabled; 31 /** Whether this test is enabled. Used by peferences */ 32 protected boolean enabled; 33 34 /** The preferences check for validation on upload */ 35 protected JCheckBox checkBeforeUpload; 36 37 /** Whether this test must check before upload. Used by peferences */ 38 protected boolean testBeforeUpload; 39 40 /** Whether this test is performing just before an upload */ 41 protected boolean isBeforeUpload; 32 42 33 43 /** The list of errors */ … … 124 134 public void addGui(@SuppressWarnings("unused") JPanel testPanel) 125 135 { 136 checkBeforeUpload = new JCheckBox(); 137 checkBeforeUpload.setSelected(testBeforeUpload); 138 testPanel.add(checkBeforeUpload, GBC.eop().insets(20,0,0,0)); 126 139 } 140 141 /** 142 * Enables or disables the test in the preferences gui 143 * @param enabled 144 */ 145 public void setGuiEnabled(boolean enabled) 146 { 147 checkBeforeUpload.setEnabled(enabled); 148 } 127 149 128 150 /** … … 131 153 public void ok() 132 154 { 155 String simpleName = getClass().getSimpleName(); 156 Main.pref.put("tests." + simpleName + ".checkBeforeUpload", checkBeforeUpload.isSelected() ); 133 157 } 134 158 … … 153 177 { 154 178 return false; 155 } 179 } 180 181 /** 182 * Returns true if this plugin must check the uploaded data before uploading 183 * @return true if this plugin must check the uploaded data before uploading 184 */ 185 public boolean testBeforeUpload() 186 { 187 return testBeforeUpload; 188 } 189 190 /** 191 * Sets the flag that marks an upload check 192 * @param isUpload if true, the test is before upload 193 */ 194 public void setBeforeUpload(boolean isUpload) 195 { 196 this.isBeforeUpload = isUpload; 197 } 156 198 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r2672 r2792 53 53 { 54 54 OSMValidatorPlugin plugin = OSMValidatorPlugin.getPlugin(); 55 if( plugin.validateAction == null || Main.map == null || !Main.map.isVisible() ) 56 return; 57 55 58 plugin.errors = new ArrayList<TestError>(); 56 59 plugin.validationDialog.setVisible(true); … … 94 97 tests = null; 95 98 96 plugin.validationDialog.refresh( );99 plugin.validationDialog.refresh(plugin.errors); 97 100 Main.map.repaint(); 98 101 Main.ds.fireSelectionChanged(Main.ds.getSelected()); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r2672 r2792 23 23 24 24 /** 25 * A small tool dialog for displaying the current selection. The selection manager25 * A small tool dialog for displaying the current errors. The selection manager 26 26 * respects clicks into the selection list. Ctrl-click will remove entries from 27 27 * the list while single click will make the clicked entry the only selection. 28 28 * 29 * @author imi29 * @author frsantos 30 30 */ 31 31 public class ValidatorDialog extends ToggleDialog implements ActionListener … … 34 34 private static final long serialVersionUID = 2952292777351992696L; 35 35 36 /**37 * The validation data.38 */39 protected DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());40 41 36 /** 42 37 * The display tree. 43 38 */ 44 protected JTree tree = new JTree(treeModel);39 protected ErrorTreePanel tree; 45 40 46 41 /** … … 54 49 private JButton selectButton; 55 50 56 /** Last selected trueeelement */51 /** Last selected element */ 57 52 private DefaultMutableTreeNode lastSelectedNode = null; 58 53 … … 64 59 super(tr("Validation errors"), "validator", tr("Open the validation window."), KeyEvent.VK_V, 150); 65 60 66 tree.setRootVisible(false); 67 tree.setShowsRootHandles(true); 68 tree.expandRow(0); 69 tree.setVisibleRowCount(8); 61 tree = new ErrorTreePanel(); 70 62 tree.addMouseListener(new ClickWatch()); 71 63 tree.addTreeSelectionListener(new SelectionWatch()); 72 tree.setCellRenderer(new ErrorTreeRenderer());73 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);74 64 75 65 add(new JScrollPane(tree), BorderLayout.CENTER); … … 90 80 91 81 @Override 92 public void setVisible(boolean v) { 93 if (v) 94 buildTree(); 95 else if (tree != null) 96 treeModel.setRoot(new DefaultMutableTreeNode()); 82 public void setVisible(boolean v) 83 { 84 if( tree != null ) 85 tree.setVisible(v); 97 86 if( action != null && action.button != null ) 98 87 action.button.setSelected(v); … … 101 90 102 91 103 /**104 * Builds the errors tree105 */106 private void buildTree()107 {108 DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();109 110 List<TestError> errorList = OSMValidatorPlugin.getPlugin().errors;111 if( errorList == null || errorList.isEmpty() )112 {113 treeModel.setRoot(rootNode);114 return;115 }116 117 Map<Severity, Bag<String, TestError>> errorTree = new HashMap<Severity, Bag<String, TestError>>();118 for(Severity s : Severity.values())119 {120 errorTree.put(s, new Bag<String, TestError>(20));121 }122 123 for(TestError e : errorList)124 {125 errorTree.get(e.getSeverity()).add(e.getMessage(), e);126 }127 128 for(Severity s : Severity.values())129 {130 Bag<String, TestError> severityErrors = errorTree.get(s);131 if( severityErrors.isEmpty() )132 continue;133 134 // Severity node135 DefaultMutableTreeNode severityNode = new DefaultMutableTreeNode(s);136 rootNode.add(severityNode);137 138 for(Entry<String, List<TestError>> msgErrors : severityErrors.entrySet() )139 {140 // Message node141 List<TestError> errors = msgErrors.getValue();142 String msg = msgErrors.getKey() + " (" + errors.size() + ")";143 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg);144 severityNode.add(messageNode);145 146 for (TestError error : errors)147 {148 // Error node149 DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode(error);150 messageNode.add(errorNode);151 }152 }153 }154 155 treeModel.setRoot(rootNode);156 tree.scrollRowToVisible(treeModel.getChildCount(rootNode)-1);157 }158 159 92 /** 160 93 * Fix selected errors … … 216 149 217 150 OSMValidatorPlugin.getPlugin().validateAction.doValidate(e, false); 151 // TODO keep the tree open as it was before the fix 218 152 } 219 153 … … 265 199 /** 266 200 * Refresh the error messages display 201 * @param errors The errors to display 267 202 */ 268 public void refresh() 269 { 270 buildTree(); 203 public void refresh(List<TestError> errors) 204 { 205 tree.setErrors(errors); 206 tree.buildTree(); 271 207 } 272 208 … … 332 268 public void mouseClicked(MouseEvent e) 333 269 { 334 System.out.println("mouseClicked " + e.getClickCount() + " " + e.getSource());335 270 fixButton.setEnabled(false); 336 271 selectButton.setEnabled(false); … … 357 292 public void valueChanged(TreeSelectionEvent e) 358 293 { 359 System.out.println("valueChanged");360 294 fixButton.setEnabled(false); 361 295 selectButton.setEnabled(false);
Note:
See TracChangeset
for help on using the changeset viewer.