Changeset 2741 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-01-05T21:55:49+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2678 r2741 216 216 WayData data = new WayData(); 217 217 saveCommonAttributes(data); 218 for (Node node: getNodes()) {218 for (Node node:nodes) { 219 219 data.getNodes().add(node.getUniqueId()); 220 220 } … … 387 387 388 388 public boolean hasIncompleteNodes() { 389 for (Node node: getNodes()) {389 for (Node node:nodes) { 390 390 if (node.isIncomplete()) 391 391 return true; -
trunk/src/org/openstreetmap/josm/data/osm/event/DataChangedEvent.java
r2711 r2741 10 10 public class DataChangedEvent extends AbstractDatasetChangedEvent { 11 11 12 private final List<AbstractDatasetChangedEvent> events; 13 14 public DataChangedEvent(DataSet dataSet, List<AbstractDatasetChangedEvent> events) { 15 super(dataSet); 16 this.events = events; 17 } 18 12 19 public DataChangedEvent(DataSet dataSet) { 13 super(dataSet);20 this(dataSet, null); 14 21 } 15 22 … … 32 39 } 33 40 41 /** 42 * 43 * @return List of events that caused this DataChangedEvent. Might be null 44 */ 45 public List<AbstractDatasetChangedEvent> getEvents() { 46 return events; 47 } 48 34 49 } -
trunk/src/org/openstreetmap/josm/data/osm/event/DatasetEventManager.java
r2711 r2741 2 2 package org.openstreetmap.josm.data.osm.event; 3 3 4 import java.util.ArrayList; 5 import java.util.Arrays; 6 import java.util.List; 4 7 import java.util.Queue; 5 8 import java.util.concurrent.CopyOnWriteArrayList; … … 8 11 import javax.swing.SwingUtilities; 9 12 13 import org.openstreetmap.josm.data.osm.DataSet; 10 14 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener; 11 15 import org.openstreetmap.josm.gui.MapView; … … 25 29 private static final DatasetEventManager instance = new DatasetEventManager(); 26 30 31 public enum FireMode { 32 IMMEDIATELY, 33 IN_EDT, 34 /** 35 * Fire in event dispatch thread. If more than one event arrived when event queue is checked, merged them to 36 * one event 37 */ 38 IN_EDT_CONSOLIDATED} 39 40 private static class ListenerInfo { 41 final DataSetListener listener; 42 final boolean consolidate; 43 44 public ListenerInfo(DataSetListener listener, boolean consolidate) { 45 this.listener = listener; 46 this.consolidate = consolidate; 47 } 48 49 @Override 50 public int hashCode() { 51 return listener.hashCode(); 52 } 53 54 @Override 55 public boolean equals(Object o) { 56 return o instanceof ListenerInfo && ((ListenerInfo)o).listener == listener; 57 } 58 } 59 27 60 public static DatasetEventManager getInstance() { 28 61 return instance; … … 30 63 31 64 private final Queue<AbstractDatasetChangedEvent> eventsInEDT = new LinkedBlockingQueue<AbstractDatasetChangedEvent>(); 32 private final CopyOnWriteArrayList< DataSetListener> inEDTListeners = new CopyOnWriteArrayList<DataSetListener>();33 private final CopyOnWriteArrayList< DataSetListener> normalListeners = new CopyOnWriteArrayList<DataSetListener>();65 private final CopyOnWriteArrayList<ListenerInfo> inEDTListeners = new CopyOnWriteArrayList<ListenerInfo>(); 66 private final CopyOnWriteArrayList<ListenerInfo> normalListeners = new CopyOnWriteArrayList<ListenerInfo>(); 34 67 private final DataSetListener myListener = new DataSetListenerAdapter(this); 35 68 … … 44 77 * instead of thread that caused the dataset change 45 78 */ 46 public void addDatasetListener(DataSetListener listener, boolean fireInEDT) {47 if (fire InEDT) {48 inEDTListeners.addIfAbsent( listener);79 public void addDatasetListener(DataSetListener listener, FireMode fireMode) { 80 if (fireMode == FireMode.IN_EDT || fireMode == FireMode.IN_EDT_CONSOLIDATED) { 81 inEDTListeners.addIfAbsent(new ListenerInfo(listener, fireMode == FireMode.IN_EDT_CONSOLIDATED)); 49 82 } else { 50 normalListeners.addIfAbsent( listener);83 normalListeners.addIfAbsent(new ListenerInfo(listener, false)); 51 84 } 52 85 } 53 86 54 87 public void removeDatasetListener(DataSetListener listener) { 55 inEDTListeners.remove(listener); 56 normalListeners.remove(listener); 88 ListenerInfo searchListener = new ListenerInfo(listener, false); 89 inEDTListeners.remove(searchListener); 90 normalListeners.remove(searchListener); 57 91 } 58 92 … … 70 104 } 71 105 106 private void fireEvents(List<ListenerInfo> listeners, AbstractDatasetChangedEvent event) { 107 for (ListenerInfo listener: listeners) { 108 if (!listener.consolidate) { 109 event.fire(listener.listener); 110 } 111 } 112 } 113 114 private void fireConsolidatedEvents(List<ListenerInfo> listeners, AbstractDatasetChangedEvent event) { 115 for (ListenerInfo listener: listeners) { 116 if (listener.consolidate) { 117 event.fire(listener.listener); 118 } 119 } 120 } 121 72 122 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 73 for (DataSetListener listener: normalListeners) { 74 event.fire(listener); 75 } 123 fireEvents(normalListeners, event); 76 124 eventsInEDT.add(event); 77 125 SwingUtilities.invokeLater(edtRunnable); … … 80 128 private final Runnable edtRunnable = new Runnable() { 81 129 public void run() { 82 AbstractDatasetChangedEvent event = null; 83 while ((event = eventsInEDT.poll()) != null) { 84 for (DataSetListener listener: inEDTListeners) { 85 event.fire(listener); 130 while (!eventsInEDT.isEmpty()) { 131 List<AbstractDatasetChangedEvent> events = new ArrayList<AbstractDatasetChangedEvent>(); 132 events.addAll(eventsInEDT); 133 134 DataSet dataSet = null; 135 AbstractDatasetChangedEvent consolidatedEvent = null; 136 AbstractDatasetChangedEvent event = null; 137 138 while ((event = eventsInEDT.poll()) != null) { 139 fireEvents(inEDTListeners, event); 140 141 // DataSet changed - fire consolidated event early 142 if (consolidatedEvent != null && dataSet != event.getDataset()) { 143 fireConsolidatedEvents(inEDTListeners, consolidatedEvent); 144 dataSet = event.getDataset(); 145 consolidatedEvent = null; 146 } 147 148 // Build consolidated event 149 if (consolidatedEvent == null) { 150 consolidatedEvent = event; 151 dataSet = event.getDataset(); 152 } else if (consolidatedEvent instanceof DataChangedEvent) { 153 ((DataChangedEvent)consolidatedEvent).getEvents().add(event); 154 } else { 155 consolidatedEvent = new DataChangedEvent(dataSet, 156 new ArrayList<AbstractDatasetChangedEvent>(Arrays.asList(consolidatedEvent))); 157 } 86 158 } 159 160 // Fire consolidated event 161 fireConsolidatedEvents(inEDTListeners, consolidatedEvent); 87 162 } 88 163 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r2711 r2741 26 26 import javax.swing.JPopupMenu; 27 27 import javax.swing.JScrollPane; 28 import javax.swing.JToolBar;29 28 import javax.swing.ListSelectionModel; 30 29 import javax.swing.SwingUtilities; … … 39 38 import org.openstreetmap.josm.data.osm.OsmPrimitive; 40 39 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 40 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 41 41 import org.openstreetmap.josm.gui.MapFrame; 42 42 import org.openstreetmap.josm.gui.MapView; … … 154 154 public void showNotify() { 155 155 registerAsListener(); 156 DatasetEventManager.getInstance().addDatasetListener(inActiveDataLayerModel, true);156 DatasetEventManager.getInstance().addDatasetListener(inActiveDataLayerModel, FireMode.IN_EDT); 157 157 } 158 158 -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r2710 r2741 22 22 import javax.swing.DefaultListSelectionModel; 23 23 import javax.swing.JList; 24 import javax.swing.JPanel; 24 25 import javax.swing.JPopupMenu; 25 26 import javax.swing.JScrollPane; 26 import javax.swing.JPanel;27 27 import javax.swing.KeyStroke; 28 28 import javax.swing.ListSelectionModel; … … 46 46 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 47 47 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 48 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 48 49 import org.openstreetmap.josm.gui.DefaultNameFormatter; 49 50 import org.openstreetmap.josm.gui.MapView; … … 143 144 MapView.addLayerChangeListener(newAction); 144 145 newAction.updateEnabledState(); 145 DatasetEventManager.getInstance().addDatasetListener(this, true);146 DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT); 146 147 dataChanged(null); 147 148 } … … 518 519 } 519 520 520 public synchronizedvoid sort() {521 public void sort() { 521 522 Collections.sort( 522 523 relations, … … 535 536 } 536 537 537 public synchronizedvoid setRelations(Collection<Relation> relations) {538 public void setRelations(Collection<Relation> relations) { 538 539 List<Relation> sel = getSelectedRelations(); 539 540 this.relations.clear(); … … 561 562 * ways, and relations. 562 563 */ 563 public synchronizedvoid addRelations(Collection<? extends OsmPrimitive> addedPrimitives) {564 public void addRelations(Collection<? extends OsmPrimitive> addedPrimitives) { 564 565 boolean added = false; 565 566 for (OsmPrimitive p: addedPrimitives) { … … 591 592 * and relations 592 593 */ 593 public synchronizedvoid removeRelations(Collection<? extends OsmPrimitive> removedPrimitives) {594 public void removeRelations(Collection<? extends OsmPrimitive> removedPrimitives) { 594 595 if (removedPrimitives == null) return; 595 596 // extract the removed relations … … 664 665 * @return sel the list of selected relations 665 666 */ 666 public synchronizedvoid setSelectedRelations(List<Relation> sel) {667 public void setSelectedRelations(List<Relation> sel) { 667 668 selectionModel.clearSelection(); 668 669 if (sel == null || sel.isEmpty()) -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r2723 r2741 11 11 import java.awt.Font; 12 12 import java.awt.GridBagLayout; 13 import java.awt.GridLayout;14 13 import java.awt.Point; 15 14 import java.awt.event.ActionEvent; … … 65 64 import org.openstreetmap.josm.data.osm.RelationMember; 66 65 import org.openstreetmap.josm.data.osm.Way; 66 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 67 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 67 68 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 69 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 68 70 import org.openstreetmap.josm.gui.DefaultNameFormatter; 69 71 import org.openstreetmap.josm.gui.ExtendedDialog; … … 99 101 * @author imi 100 102 */ 101 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener {103 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener { 102 104 /** 103 105 * Watches for double clicks and from editing or new property, depending on the … … 144 146 private final ListOfUsedTags listOfUsedTags = new ListOfUsedTags(); 145 147 148 private DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 149 146 150 @Override 147 151 public void showNotify() { 148 DatasetEventManager.getInstance().addDatasetListener(listOfUsedTags, false); 152 DatasetEventManager.getInstance().addDatasetListener(listOfUsedTags, FireMode.IMMEDIATELY); 153 DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED); 149 154 listOfUsedTags.rebuildNecessary(); 150 155 DataSet.selListeners.add(this); … … 155 160 public void hideNotify() { 156 161 DatasetEventManager.getInstance().removeDatasetListener(listOfUsedTags); 162 DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter); 157 163 DataSet.selListeners.remove(this); 158 164 } … … 310 316 * @param row 311 317 */ 318 @SuppressWarnings("unchecked") 312 319 void membershipEdit(int row) { 313 320 Relation relation = (Relation)membershipData.getValueAt(row, 0); … … 455 462 if (value instanceof String) { 456 463 str = (String) value; 457 } else if (value instanceof Map ) {458 Map v = (Map) value;464 } else if (value instanceof Map<?, ?>) { 465 Map<?, ?> v = (Map<?, ?>) value; 459 466 if (v.size() != 1) { 460 467 str=tr("<different>"); 461 468 c.setFont(c.getFont().deriveFont(Font.ITALIC)); 462 469 } else { 463 final Map.Entry entry = (Map.Entry)v.entrySet().iterator().next();470 final Map.Entry<?, ?> entry = v.entrySet().iterator().next(); 464 471 str = (String) entry.getKey(); 465 472 } … … 810 817 } 811 818 819 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 820 updateSelection(); 821 } 822 812 823 class DeleteAction extends AbstractAction implements ListSelectionListener { 813 824 … … 922 933 } 923 934 924 class SelectRelationAction extends AbstractAction {935 static class SelectRelationAction extends AbstractAction { 925 936 boolean selectionmode; 926 937 Relation relation; … … 929 940 relation = r; 930 941 if(select) { 931 putValue(NAME, tr("Select relation"));932 putValue(SHORT_DESCRIPTION, tr("Select relation in main selection."));942 putValue(NAME, tr("Select relation")); 943 putValue(SHORT_DESCRIPTION, tr("Select relation in main selection.")); 933 944 } else { 934 putValue(NAME, tr("Select in relation list"));935 putValue(SHORT_DESCRIPTION, tr("Select relation in relation list."));945 putValue(NAME, tr("Select in relation list")); 946 putValue(SHORT_DESCRIPTION, tr("Select relation in relation list.")); 936 947 } 937 948 } 938 949 939 950 public void actionPerformed(ActionEvent e) { 940 if(selectionmode) 951 if(selectionmode) { 941 952 Main.map.mapView.getEditLayer().data.setSelected(relation); 942 else953 } else { 943 954 Main.map.relationListDialog.selectRelation(relation); 955 } 944 956 } 945 957 } -
trunk/src/org/openstreetmap/josm/tools/CopyList.java
r2512 r2741 22 22 23 23 import java.util.AbstractList; 24 import java.util.ConcurrentModificationException; 25 import java.util.Iterator; 26 import java.util.NoSuchElementException; 24 27 import java.util.RandomAccess; 25 28 … … 32 35 * @author nenik 33 36 */ 34 public class CopyList<E> extends AbstractList<E> implements RandomAccess, Cloneable {37 public final class CopyList<E> extends AbstractList<E> implements RandomAccess, Cloneable { 35 38 private E[] array; 36 39 private int size; … … 107 110 108 111 public @Override void clear() { 109 modCount++;112 modCount++; 110 113 111 114 // clean up the array 112 while (size > 0) array[--size] = null; 115 while (size > 0) { 116 array[--size] = null; 117 } 113 118 } 114 119 … … 125 130 126 131 private void rangeCheck(int index) { 127 if (index >= size || index < 0) throw new IndexOutOfBoundsException();132 if (index >= size || index < 0) throw new IndexOutOfBoundsException(); 128 133 } 129 134 … … 145 150 System.arraycopy(old, 0, array, 0, size); 146 151 pristine = false; 147 } 148 } 152 } 153 } 154 155 @Override 156 public Iterator<E> iterator() { 157 return new Itr(); 158 } 159 160 private class Itr implements Iterator<E> { 161 /** 162 * Index of element to be returned by subsequent call to next. 163 */ 164 int cursor = 0; 165 166 /** 167 * Index of element returned by most recent call to next or 168 * previous. Reset to -1 if this element is deleted by a call 169 * to remove. 170 */ 171 int lastRet = -1; 172 173 /** 174 * The modCount value that the iterator believes that the backing 175 * List should have. If this expectation is violated, the iterator 176 * has detected concurrent modification. 177 */ 178 int expectedModCount = modCount; 179 180 public boolean hasNext() { 181 return cursor != size; 182 } 183 184 public E next() { 185 checkForComodification(); 186 try { 187 E next = array[cursor]; 188 lastRet = cursor++; 189 return next; 190 } catch (IndexOutOfBoundsException e) { 191 checkForComodification(); 192 throw new NoSuchElementException(); 193 } 194 } 195 196 public void remove() { 197 if (lastRet == -1) 198 throw new IllegalStateException(); 199 checkForComodification(); 200 201 try { 202 CopyList.this.remove(lastRet); 203 if (lastRet < cursor) { 204 cursor--; 205 } 206 lastRet = -1; 207 expectedModCount = modCount; 208 } catch (IndexOutOfBoundsException e) { 209 throw new ConcurrentModificationException(); 210 } 211 } 212 213 final void checkForComodification() { 214 if (modCount != expectedModCount) 215 throw new ConcurrentModificationException(); 216 } 217 } 218 149 219 }
Note:
See TracChangeset
for help on using the changeset viewer.