- Timestamp:
- 2012-03-18T11:42:54+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r5053 r5098 2 2 package org.openstreetmap.josm.actions.mapmode; 3 3 4 import javax.swing.JCheckBoxMenuItem;5 import javax.swing.JMenuItem;4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.marktr; 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 import static org.openstreetmap.josm.tools.I18n.trn; 8 import static org.openstreetmap.josm.tools.I18n.marktr;9 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;10 8 11 9 import java.awt.AWTEvent; … … 14 12 import java.awt.Cursor; 15 13 import java.awt.Graphics2D; 16 import java.awt.MenuItem;17 14 import java.awt.Point; 18 15 import java.awt.Stroke; … … 38 35 import java.util.Set; 39 36 import java.util.TreeSet; 37 40 38 import javax.swing.AbstractAction; 39 import javax.swing.JCheckBoxMenuItem; 40 import javax.swing.JMenuItem; 41 41 import javax.swing.JOptionPane; 42 42 import javax.swing.JPopupMenu; … … 66 66 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 67 67 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 68 import org.openstreetmap.josm.tools.Geometry; 68 69 import org.openstreetmap.josm.tools.ImageProvider; 69 70 import org.openstreetmap.josm.tools.Pair; 70 71 import org.openstreetmap.josm.tools.Shortcut; 71 72 import org.openstreetmap.josm.tools.Utils; 72 import org.openstreetmap.josm.tools.Geometry;73 73 74 74 /** … … 84 84 private Node mouseOnExistingNode; 85 85 private Set<Way> mouseOnExistingWays = new HashSet<Way>(); 86 // old highlights store which primitives are currently highlighted. This 87 // is true, even if target highlighting is disabled since the status bar 88 // derives its information from this list as well. 86 89 private Set<OsmPrimitive> oldHighlights = new HashSet<OsmPrimitive>(); 90 // new highlights contains a list of primitives that should be highlighted 91 // but haven’t been so far. The idea is to compare old and new and only 92 // repaint if there are changes. 93 private Set<OsmPrimitive> newHighlights = new HashSet<OsmPrimitive>(); 87 94 private boolean drawHelperLine; 88 95 private boolean wayIsFinished = false; … … 132 139 private void redrawIfRequired() { 133 140 updateStatusLine(); 141 // repaint required if the helper line is active. 142 boolean needsRepaint = drawHelperLine && !wayIsFinished; 143 // move newHighlights to oldHighlights; only update changed primitives 144 for(OsmPrimitive x : newHighlights) { 145 if(oldHighlights.contains(x)) { 146 continue; 147 } 148 needsRepaint = true; 149 x.setHighlighted(true); 150 } 151 oldHighlights.removeAll(newHighlights); 152 for(OsmPrimitive x : oldHighlights) { 153 x.setHighlighted(false); 154 needsRepaint = true; 155 } 156 oldHighlights = newHighlights; 157 134 158 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) 135 159 return; 160 136 161 // update selection to reflect which way being modified 137 162 if (currentBaseNode != null && getCurrentDataSet().getSelected().isEmpty() == false) { 138 163 Way continueFrom = getWayForNode(currentBaseNode); 139 if (alt && continueFrom != null ) {164 if (alt && continueFrom != null && (!currentBaseNode.isSelected() || continueFrom.isSelected())) { 140 165 getCurrentDataSet().beginUpdate(); // to prevent the selection listener to screw around with the state 141 166 getCurrentDataSet().addSelected(currentBaseNode); 142 167 getCurrentDataSet().clearSelection(continueFrom); 143 168 getCurrentDataSet().endUpdate(); 144 } else if (!alt && continueFrom != null) { 169 needsRepaint = true; 170 } else if (!alt && continueFrom != null && !continueFrom.isSelected()) { 145 171 getCurrentDataSet().addSelected(continueFrom); 146 } 147 } 148 Main.map.mapView.repaint(); 172 needsRepaint = true; 173 } 174 } 175 176 if(needsRepaint) { 177 Main.map.mapView.repaint(); 178 } 149 179 } 150 180 … … 228 258 computeHelperLine(); 229 259 addHighlighting(); 230 redrawIfRequired();231 260 } 232 261 … … 278 307 computeHelperLine(); 279 308 addHighlighting(); 280 redrawIfRequired();281 309 } 282 310 … … 303 331 computeHelperLine(); 304 332 removeHighlighting(); 305 redrawIfRequired();306 333 } 307 334 … … 579 606 computeHelperLine(); 580 607 removeHighlighting(); 581 redrawIfRequired();582 608 } 583 609 … … 707 733 computeHelperLine(); 708 734 addHighlighting(); 709 redrawIfRequired();710 735 } 711 736 … … 723 748 return; 724 749 } 725 726 double distance = -1;727 double angle = -1;728 750 729 751 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); … … 972 994 /** 973 995 * Takes the data from computeHelperLine to determine which ways/nodes should be highlighted 974 * (if feature enabled). Also sets the target cursor if appropriate. 996 * (if feature enabled). Also sets the target cursor if appropriate. It adds the to-be- 997 * highlighted primitives to newHighlights but does not actually highlight them. This work is 998 * done in redrawIfRequired. This means, calling addHighlighting() without redrawIfRequired() 999 * will leave the data in an inconsistent state. 1000 * 1001 * The status bar derives its information from oldHighlights, so in order to update the status 1002 * bar both addHighlighting() and repaintIfRequired() are needed, since former fills newHighlights 1003 * and latter processes them into oldHighlights. 975 1004 */ 976 1005 private void addHighlighting() { 977 removeHighlighting(); 1006 newHighlights = new HashSet<OsmPrimitive>(); 1007 978 1008 // if ctrl key is held ("no join"), don't highlight anything 979 1009 if (ctrl) { 980 1010 Main.map.mapView.setNewCursor(cursor, this); 1011 redrawIfRequired(); 981 1012 return; 982 1013 } … … 990 1021 if (mouseOnExistingNode != null) { 991 1022 Main.map.mapView.setNewCursor(cursorJoinNode, this); 992 // We also need this list for the statusbar help text 993 oldHighlights.add(mouseOnExistingNode); 994 if(drawTargetHighlight) { 995 mouseOnExistingNode.setHighlighted(true); 996 } 1023 newHighlights.add(mouseOnExistingNode); 1024 redrawIfRequired(); 997 1025 return; 998 1026 } … … 1001 1029 if (mouseOnExistingWays.size() == 0) { 1002 1030 Main.map.mapView.setNewCursor(cursor, this); 1031 redrawIfRequired(); 1003 1032 return; 1004 1033 } 1005 1034 1006 1035 Main.map.mapView.setNewCursor(cursorJoinWay, this); 1007 1008 // We also need this list for the statusbar help text 1009 oldHighlights.addAll(mouseOnExistingWays); 1010 if (!drawTargetHighlight) return; 1011 for (Way w : mouseOnExistingWays) { 1012 w.setHighlighted(true); 1013 } 1036 newHighlights.addAll(mouseOnExistingWays); 1037 redrawIfRequired(); 1014 1038 } 1015 1039 1016 1040 /** 1017 * Removes target highlighting from primitives 1041 * Removes target highlighting from primitives. Issues repaint if required. 1018 1042 */ 1019 1043 private void removeHighlighting() { 1020 for(OsmPrimitive prim : oldHighlights) { 1021 prim.setHighlighted(false); 1022 } 1023 oldHighlights = new HashSet<OsmPrimitive>(); 1044 newHighlights = new HashSet<OsmPrimitive>(); 1045 redrawIfRequired(); 1024 1046 } 1025 1047 … … 1041 1063 g2.setColor(selectedColor); 1042 1064 g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 1043 } else if (!snapHelper.drawConstructionGeometry) { 1044 return; 1045 } 1065 } else if (!snapHelper.drawConstructionGeometry) 1066 return; 1046 1067 GeneralPath b = new GeneralPath(); 1047 1068 Point p1=mv.getPoint(currentBaseNode); … … 1169 1190 wayIsFinished=false; 1170 1191 } else { 1171 // if more than 1 node were affected by previous command,1172 // we have no way to continue, so we forget about found node1192 // if more than 1 node were affected by previous command, 1193 // we have no way to continue, so we forget about found node 1173 1194 n=null; 1174 1195 break; … … 1178 1199 // select last added node - maybe we will continue drawing from it 1179 1200 if (n!=null) getCurrentDataSet().addSelected(n); 1180 }1201 } 1181 1202 } 1182 1203 … … 1616 1637 @Override 1617 1638 public void actionPerformed(ActionEvent e) { 1618 1639 if (snapHelper!=null) snapHelper.toggleSnapping(); 1619 1640 } 1620 1641 }
Note:
See TracChangeset
for help on using the changeset viewer.