Changeset 3371 in josm
- Timestamp:
- 2010-07-09T08:24:57+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java
r3367 r3371 61 61 } 62 62 63 public static boolean executeFilters(OsmPrimitive primitive, FilterMatcher filterMatcher) { 64 boolean hidden = primitive.isDisabledAndHidden(); 65 boolean disabled = primitive.isDisabled(); 66 if (filterMatcher.isHidden(primitive)) { 67 primitive.setDisabledState(true); 68 } else if (filterMatcher.isDisabled(primitive)) { 69 primitive.setDisabledState(false); 70 } else { 71 primitive.unsetDisabledState(); 72 } 73 return hidden != primitive.isDisabledAndHidden() || disabled != primitive.isDisabled(); 74 } 75 63 76 public static void clearFilterFlags(Collection<OsmPrimitive> prims) { 64 77 for (OsmPrimitive osm : prims) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/FilterDialog.java
r3356 r3371 12 12 import java.awt.event.KeyEvent; 13 13 import java.awt.event.MouseEvent; 14 import java.util.Collection; 15 import java.util.HashSet; 16 import java.util.Set; 17 import java.util.Stack; 14 18 15 19 import javax.swing.JCheckBox; … … 26 30 import org.openstreetmap.josm.actions.search.SearchAction; 27 31 import org.openstreetmap.josm.data.osm.Filter; 32 import org.openstreetmap.josm.data.osm.OsmPrimitive; 33 import org.openstreetmap.josm.data.osm.Relation; 34 import org.openstreetmap.josm.data.osm.RelationMember; 35 import org.openstreetmap.josm.data.osm.Way; 28 36 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 37 import org.openstreetmap.josm.data.osm.event.DataChangedEvent; 29 38 import org.openstreetmap.josm.data.osm.event.DataSetListener; 30 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;31 39 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 32 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener; 40 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent; 41 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent; 42 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent; 43 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent; 44 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 45 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 33 46 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 34 47 import org.openstreetmap.josm.gui.SideButton; … … 39 52 * @author Petr_Dlouhý 40 53 */ 41 public class FilterDialog extends ToggleDialog implements Listener {54 public class FilterDialog extends ToggleDialog implements DataSetListener { 42 55 43 56 private JTable userTable; … … 49 62 private SideButton downButton; 50 63 51 private final DataSetListener listenerAdapter = new DataSetListenerAdapter(this);52 64 53 65 public FilterDialog(){ … … 59 71 @Override 60 72 public void showNotify() { 61 DatasetEventManager.getInstance().addDatasetListener( listenerAdapter, FireMode.IN_EDT_CONSOLIDATED);73 DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED); 62 74 filterModel.executeFilters(); 63 75 } … … 65 77 @Override 66 78 public void hideNotify() { 67 DatasetEventManager.getInstance().removeDatasetListener( listenerAdapter);79 DatasetEventManager.getInstance().removeDatasetListener(this); 68 80 filterModel.clearFilterFlags(); 69 81 Main.map.mapView.repaint(); … … 181 193 } 182 194 183 public void processDatasetEvent(AbstractDatasetChangedEvent event) {184 filterModel.executeFilters();185 }186 187 195 static class StringRenderer extends DefaultTableCellRenderer { 188 196 @Override … … 216 224 filterModel.drawOSDText(g); 217 225 } 226 227 /** 228 * 229 * @param primitive 230 * @return List of primitives whose filtering can be affected by change in primitive 231 */ 232 private Collection<OsmPrimitive> getAffectedPrimitives(Collection<? extends OsmPrimitive> primitives) { 233 // Filters can use nested parent/child expression so complete tree is necessary 234 Set<OsmPrimitive> result = new HashSet<OsmPrimitive>(); 235 Stack<OsmPrimitive> stack = new Stack<OsmPrimitive>(); 236 stack.addAll(primitives); 237 238 while (!stack.isEmpty()) { 239 OsmPrimitive p = stack.pop(); 240 241 if (result.contains(p)) { 242 continue; 243 } 244 245 result.add(p); 246 247 if (p instanceof Way) { 248 for (OsmPrimitive n: ((Way)p).getNodes()) { 249 stack.push(n); 250 } 251 } else if (p instanceof Relation) { 252 for (RelationMember rm: ((Relation)p).getMembers()) { 253 stack.push(rm.getMember()); 254 } 255 } 256 257 for (OsmPrimitive ref: p.getReferrers()) { 258 stack.push(ref); 259 } 260 } 261 262 return result; 263 } 264 265 266 @Override 267 public void dataChanged(DataChangedEvent event) { 268 filterModel.executeFilters(); 269 } 270 271 @Override 272 public void nodeMoved(NodeMovedEvent event) { 273 // Do nothing 274 } 275 276 @Override 277 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 278 filterModel.executeFilters(); 279 } 280 281 @Override 282 public void primtivesAdded(PrimitivesAddedEvent event) { 283 filterModel.executeFilters(event.getPrimitives()); 284 } 285 286 @Override 287 public void primtivesRemoved(PrimitivesRemovedEvent event) { 288 filterModel.executeFilters(); 289 } 290 291 @Override 292 public void relationMembersChanged(RelationMembersChangedEvent event) { 293 filterModel.executeFilters(getAffectedPrimitives(event.getPrimitives())); 294 } 295 296 @Override 297 public void tagsChanged(TagsChangedEvent event) { 298 filterModel.executeFilters(getAffectedPrimitives(event.getPrimitives())); 299 } 300 301 @Override 302 public void wayNodesChanged(WayNodesChangedEvent event) { 303 filterModel.executeFilters(getAffectedPrimitives(event.getPrimitives())); 304 } 218 305 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java
r3356 r3371 8 8 import java.awt.Graphics; 9 9 import java.awt.Graphics2D; 10 import java.util.ArrayList; 10 11 import java.util.Collection; 11 12 import java.util.HashSet; … … 25 26 import org.openstreetmap.josm.data.osm.FilterMatcher; 26 27 import org.openstreetmap.josm.data.osm.FilterWorker; 28 import org.openstreetmap.josm.data.osm.Node; 27 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 28 30 … … 59 61 60 62 61 63 62 64 public void executeFilters() { 63 65 DataSet ds = Main.main.getCurrentDataSet(); … … 65 67 return; 66 68 67 final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives();68 69 FilterWorker.executeFilters(all, filterMatcher);70 71 disabledCount = 0;72 disabledAndHiddenCount = 0;73 // collect disabled and selected the primitives74 69 final Collection<OsmPrimitive> deselect = new HashSet<OsmPrimitive>(); 75 for (OsmPrimitive osm : all) { 76 if (osm.isDisabled()) { 77 disabledCount++; 78 if (osm.isSelected()) { 79 deselect.add(osm); 80 } 81 if (osm.isDisabledAndHidden()) { 82 disabledAndHiddenCount++; 70 71 ds.beginUpdate(); 72 try { 73 74 final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives(); 75 76 FilterWorker.executeFilters(all, filterMatcher); 77 78 disabledCount = 0; 79 disabledAndHiddenCount = 0; 80 // collect disabled and selected the primitives 81 for (OsmPrimitive osm : all) { 82 if (osm.isDisabled()) { 83 disabledCount++; 84 if (osm.isSelected()) { 85 deselect.add(osm); 86 } 87 if (osm.isDisabledAndHidden()) { 88 disabledAndHiddenCount++; 89 } 83 90 } 84 91 } 85 } 86 disabledCount -= disabledAndHiddenCount; 92 disabledCount -= disabledAndHiddenCount; 93 } finally { 94 ds.endUpdate(); 95 } 96 87 97 if (!deselect.isEmpty()) { 88 98 ds.clearSelection(deselect); … … 91 101 Main.map.mapView.repaint(); 92 102 Main.map.filterDialog.updateDialogHeader(); 103 } 104 105 106 public void executeFilters(Collection<? extends OsmPrimitive> primitives) { 107 DataSet ds = Main.main.getCurrentDataSet(); 108 if (ds == null) 109 return; 110 111 boolean changed = false; 112 List<OsmPrimitive> deselect = new ArrayList<OsmPrimitive>(); 113 114 ds.beginUpdate(); 115 try { 116 for (int i=0; i<2; i++) { 117 for (OsmPrimitive primitive: primitives) { 118 119 if (i == 0 && primitive instanceof Node) { 120 continue; 121 } 122 123 if (i == 1 && !(primitive instanceof Node)) { 124 continue; 125 } 126 127 if (primitive.isDisabled()) { 128 disabledCount--; 129 } 130 if (primitive.isDisabledAndHidden()) { 131 disabledAndHiddenCount--; 132 } 133 changed = changed | FilterWorker.executeFilters(primitive, filterMatcher); 134 if (primitive.isDisabled()) { 135 disabledCount++; 136 } 137 if (primitive.isDisabledAndHidden()) { 138 disabledAndHiddenCount++; 139 } 140 141 if (primitive.isSelected() && primitive.isDisabled()) { 142 deselect.add(primitive); 143 } 144 145 } 146 } 147 } finally { 148 ds.endUpdate(); 149 } 150 151 if (changed) { 152 Main.map.mapView.repaint(); 153 Main.map.filterDialog.updateDialogHeader(); 154 ds.clearSelection(deselect); 155 } 156 93 157 } 94 158
Note:
See TracChangeset
for help on using the changeset viewer.