Changeset 12778 in osm for applications/editors/josm/plugins/slippy_map_chooser/src/OsmMapControl.java
- Timestamp:
- 2009-01-01T18:28:53+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippy_map_chooser/src/OsmMapControl.java
r9623 r12778 23 23 public class OsmMapControl extends MouseAdapter implements MouseMotionListener, MouseListener { 24 24 25 // start and end point of selection rectangle26 private Point iStartSelectionPoint;27 private Point iEndSelectionPoint;25 // start and end point of selection rectangle 26 private Point iStartSelectionPoint; 27 private Point iEndSelectionPoint; 28 28 29 // the SlippyMapChooserComponent30 private final SlippyMapChooser iSlippyMapChooser;29 // the SlippyMapChooserComponent 30 private final SlippyMapChooser iSlippyMapChooser; 31 31 32 private SizeButton iSizeButton = null;33 private SourceButton iSourceButton = null;32 private SizeButton iSizeButton = null; 33 private SourceButton iSourceButton = null; 34 34 35 /**36 * Create a new OsmMapControl37 */38 public OsmMapControl(SlippyMapChooser navComp, JPanel contentPane, SizeButton sizeButton, SourceButton sourceButton) {39 this.iSlippyMapChooser = navComp;40 iSlippyMapChooser.addMouseListener(this);41 iSlippyMapChooser.addMouseMotionListener(this);35 /** 36 * Create a new OsmMapControl 37 */ 38 public OsmMapControl(SlippyMapChooser navComp, JPanel contentPane, SizeButton sizeButton, SourceButton sourceButton) { 39 this.iSlippyMapChooser = navComp; 40 iSlippyMapChooser.addMouseListener(this); 41 iSlippyMapChooser.addMouseMotionListener(this); 42 42 43 String[] n = { ",", ".", "up", "right", "down", "left" };44 int[] k =45 { KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT,46 KeyEvent.VK_DOWN, KeyEvent.VK_LEFT };43 String[] n = { ",", ".", "up", "right", "down", "left" }; 44 int[] k = 45 { KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, 46 KeyEvent.VK_DOWN, KeyEvent.VK_LEFT }; 47 47 48 if (contentPane != null) {49 for (int i = 0; i < n.length; ++i) {50 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(51 KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK),52 "MapMover.Zoomer." + n[i]);53 }54 }55 iSizeButton = sizeButton;56 iSourceButton = sourceButton;57 }48 if (contentPane != null) { 49 for (int i = 0; i < n.length; ++i) { 50 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 51 KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK), 52 "MapMover.Zoomer." + n[i]); 53 } 54 } 55 iSizeButton = sizeButton; 56 iSourceButton = sourceButton; 57 } 58 58 59 /**60 * Start drawing the selection rectangle if it was the 1st button (left61 * button)62 */63 @Override64 public void mousePressed(MouseEvent e) {65 if (e.getButton() == MouseEvent.BUTTON1) {66 if (!iSizeButton.hit(e.getPoint())) {67 iStartSelectionPoint = e.getPoint();68 iEndSelectionPoint = e.getPoint();69 }70 }71 72 }59 /** 60 * Start drawing the selection rectangle if it was the 1st button (left 61 * button) 62 */ 63 @Override 64 public void mousePressed(MouseEvent e) { 65 if (e.getButton() == MouseEvent.BUTTON1) { 66 if (!iSizeButton.hit(e.getPoint())) { 67 iStartSelectionPoint = e.getPoint(); 68 iEndSelectionPoint = e.getPoint(); 69 } 70 } 71 72 } 73 73 74 public void mouseDragged(MouseEvent e) {75 if((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK){76 if (iStartSelectionPoint != null) {77 iEndSelectionPoint = e.getPoint();78 iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint);79 }80 }81 }74 public void mouseDragged(MouseEvent e) { 75 if((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK){ 76 if (iStartSelectionPoint != null) { 77 iEndSelectionPoint = e.getPoint(); 78 iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint); 79 } 80 } 81 } 82 82 83 /**84 * When dragging the map change the cursor back to it's pre-move cursor. If85 * a double-click occurs center and zoom the map on the clicked location.86 */87 @Override88 public void mouseReleased(MouseEvent e) {89 if (e.getButton() == MouseEvent.BUTTON1) {90 91 int sourceButton = iSourceButton.hit(e.getPoint());92 93 if (iSizeButton.hit(e.getPoint())) {94 iSizeButton.toggle();95 iSlippyMapChooser.resizeSlippyMap();96 }97 else if(sourceButton == SourceButton.HIDE_OR_SHOW) {98 iSourceButton.toggle();99 iSlippyMapChooser.repaint();100 101 }else if(sourceButton == SourceButton.MAPNIK || sourceButton == SourceButton.OSMARENDER) {102 iSlippyMapChooser.toggleMapSource(sourceButton);103 }104 else {105 if (e.getClickCount() == 1) {106 iSlippyMapChooser.setSelection(iStartSelectionPoint, e.getPoint());83 /** 84 * When dragging the map change the cursor back to it's pre-move cursor. If 85 * a double-click occurs center and zoom the map on the clicked location. 86 */ 87 @Override 88 public void mouseReleased(MouseEvent e) { 89 if (e.getButton() == MouseEvent.BUTTON1) { 90 91 int sourceButton = iSourceButton.hit(e.getPoint()); 92 93 if (iSizeButton.hit(e.getPoint())) { 94 iSizeButton.toggle(); 95 iSlippyMapChooser.resizeSlippyMap(); 96 } 97 else if(sourceButton == SourceButton.HIDE_OR_SHOW) { 98 iSourceButton.toggle(); 99 iSlippyMapChooser.repaint(); 100 101 }else if(sourceButton == SourceButton.MAPNIK || sourceButton == SourceButton.OSMARENDER) { 102 iSlippyMapChooser.toggleMapSource(sourceButton); 103 } 104 else { 105 if (e.getClickCount() == 1) { 106 iSlippyMapChooser.setSelection(iStartSelectionPoint, e.getPoint()); 107 107 108 // reset the selections start and end109 iEndSelectionPoint = null;110 iStartSelectionPoint = null;111 }112 }113 114 }115 }108 // reset the selections start and end 109 iEndSelectionPoint = null; 110 iStartSelectionPoint = null; 111 } 112 } 113 114 } 115 } 116 116 117 public void mouseMoved(MouseEvent e) {118 }117 public void mouseMoved(MouseEvent e) { 118 } 119 119 120 120 }
Note:
See TracChangeset
for help on using the changeset viewer.
