Changeset 31104 in osm for applications/editors
- Timestamp:
- 2015-04-27T11:14:22+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java
r31095 r31104 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.AWTEvent;9 8 import java.awt.BasicStroke; 10 9 import java.awt.Color; … … 15 14 import java.awt.RenderingHints; 16 15 import java.awt.Toolkit; 17 import java.awt.event.AWTEventListener;18 16 import java.awt.event.KeyEvent; 19 17 import java.awt.event.MouseEvent; … … 22 20 import java.util.Collection; 23 21 import java.util.LinkedList; 22 import java.util.Map; 23 import java.util.Map.Entry; 24 24 25 25 import org.openstreetmap.josm.Main; … … 37 37 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 38 38 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 39 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 40 import org.openstreetmap.josm.gui.util.ModifierListener; 39 41 import org.openstreetmap.josm.tools.ImageProvider; 40 42 import org.openstreetmap.josm.tools.Shortcut; 41 43 42 44 @SuppressWarnings("serial") 43 public class DrawBuildingAction extends MapMode implements MapViewPaintable, AWTEventListener, SelectionChangedListener { 45 public class DrawBuildingAction extends MapMode implements MapViewPaintable, SelectionChangedListener, 46 KeyPressReleaseListener, ModifierListener { 44 47 private enum Mode { 45 48 None, Drawing, DrawingWidth, DrawingAngFix … … 54 57 private Mode nextMode = Mode.None; 55 58 56 private final Color selectedColor;59 private Color selectedColor = Color.red; 57 60 private Point drawStartPos; 58 61 private Point mousePos; 59 private boolean isCtrlDown;60 private boolean isShiftDown;61 private boolean isAltDown;62 62 63 63 final Building building = new Building(); … … 73 73 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 74 74 currCursor = cursorCrosshair; 75 76 selectedColor = Main.pref.getColor(marktr("selected"), Color.red);77 75 } 78 76 … … 113 111 private void showAddrDialog(Way w) { 114 112 AddressDialog dlg = new AddressDialog(); 115 if (! isAltDown) {113 if (!alt) { 116 114 dlg.showDialog(); 117 115 if (dlg.getValue() != 1) … … 134 132 return; 135 133 } 134 selectedColor = Main.pref.getColor(marktr("selected"), selectedColor); 136 135 currCursor = cursorCrosshair; 137 136 Main.map.mapView.addMouseListener(this); 138 137 Main.map.mapView.addMouseMotionListener(this); 139 138 Main.map.mapView.addTemporaryLayer(this); 139 Main.map.keyDetector.addKeyListener(this); 140 Main.map.keyDetector.addModifierListener(this); 140 141 DataSet.addSelectionListener(this); 141 142 updateSnap(getCurrentDataSet().getSelected()); 142 try {143 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);144 } catch (SecurityException ex) {145 Main.error(ex);146 }147 143 } 148 144 … … 153 149 Main.map.mapView.removeMouseMotionListener(this); 154 150 Main.map.mapView.removeTemporaryLayer(this); 151 Main.map.keyDetector.removeKeyListener(this); 152 Main.map.keyDetector.removeModifierListener(this); 155 153 DataSet.removeSelectionListener(this); 156 try {157 Toolkit.getDefaultToolkit().removeAWTEventListener(this);158 } catch (SecurityException ex) {159 Main.error(ex);160 }161 154 if (mode != Mode.None) 162 155 Main.map.mapView.repaint(); … … 176 169 177 170 @Override 178 public void eventDispatched(AWTEvent arg0) { 179 if (!(arg0 instanceof KeyEvent)) 180 return; 181 KeyEvent ev = (KeyEvent) arg0; 182 int modifiers = ev.getModifiersEx(); 183 boolean isCtrlDown = (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0; 184 boolean isShiftDown = (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0; 185 if (this.isCtrlDown != isCtrlDown || this.isShiftDown != isShiftDown) { 186 this.isCtrlDown = isCtrlDown; 187 this.isShiftDown = isShiftDown; 171 public void modifiersChanged(int modifiers) { 172 boolean oldCtrl = ctrl; 173 boolean oldShift = shift; 174 updateKeyModifiers(modifiers); 175 if (ctrl != oldCtrl || shift != oldShift) { 188 176 processMouseEvent(null); 189 177 updCursor(); … … 191 179 Main.map.mapView.repaint(); 192 180 } 193 isAltDown = (modifiers & KeyEvent.ALT_DOWN_MASK) != 0; 194 195 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) { 196 if (mode != Mode.None) { 197 ev.consume(); 198 } 181 } 182 183 @Override 184 public void doKeyPressed(KeyEvent e) { 185 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { 186 if (mode != Mode.None) 187 e.consume(); 199 188 200 189 cancelDrawing(); 201 190 } 191 } 192 193 @Override 194 public void doKeyReleased(KeyEvent e) { 202 195 } 203 196 204 197 private EastNorth getEastNorth() { 205 198 Node n; 206 if ( isCtrlDown) {199 if (ctrl) { 207 200 n = null; 208 201 } else { … … 217 210 218 211 private boolean isRectDrawing() { 219 return building.isRectDrawing() && (! isShiftDown|| ToolSettings.isBBMode());212 return building.isRectDrawing() && (!shift || ToolSettings.isBBMode()); 220 213 } 221 214 … … 224 217 if (isRectDrawing()) { 225 218 building.setPlaceRect(p); 226 return isShiftDown? Mode.DrawingAngFix : Mode.None;227 } else { 228 building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), isShiftDown);219 return shift ? Mode.DrawingAngFix : Mode.None; 220 } else { 221 building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), shift); 229 222 Main.map.statusLine.setDist(building.getLength()); 230 223 this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None; … … 247 240 if (e != null) { 248 241 mousePos = e.getPoint(); 249 isCtrlDown = e.isControlDown(); 250 isShiftDown = e.isShiftDown(); 251 isAltDown = e.isAltDown(); 242 updateKeyModifiers(e); 252 243 } 253 244 if (mode == Mode.None) { … … 310 301 Way w = building.create(); 311 302 if (w != null) { 312 if (!isAltDown || ToolSettings.isUsingAddr()) 313 w.setKeys(ToolSettings.getTags()); 303 if (!alt || ToolSettings.isUsingAddr()) 304 for (Entry<String, String> kv : ToolSettings.getTags().entrySet()) 305 w.put(kv.getKey(), kv.getValue()); 314 306 if (ToolSettings.isUsingAddr()) 315 307 showAddrDialog(w); 316 308 if (ToolSettings.isAutoSelect() 317 && (Main.main.getCurrentDataSet().getSelected().isEmpty() || isShiftDown)) {309 && (Main.main.getCurrentDataSet().getSelected().isEmpty() || shift)) { 318 310 Main.main.getCurrentDataSet().setSelected(w); 319 311 } … … 369 361 return; 370 362 Node n = null; 371 if (! isCtrlDown)363 if (!ctrl) 372 364 n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate); 373 365 if (n != null) { 374 366 setCursor(cursorJoinNode); 375 367 } else { 376 if (customCursor != null && (! isShiftDown|| isRectDrawing()))368 if (customCursor != null && (!ctrl || isRectDrawing())) 377 369 setCursor(customCursor); 378 370 else
Note:
See TracChangeset
for help on using the changeset viewer.