| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.gui.jmapviewer;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.Color;
|
|---|
| 5 | import java.awt.Graphics;
|
|---|
| 6 | import java.awt.Point;
|
|---|
| 7 |
|
|---|
| 8 | import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle;
|
|---|
| 9 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * @author Vincent
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | public class MapRectangleImpl implements MapRectangle {
|
|---|
| 16 |
|
|---|
| 17 | private Coordinate topLeft;
|
|---|
| 18 | private Coordinate bottomRight;
|
|---|
| 19 | Color color;
|
|---|
| 20 |
|
|---|
| 21 | public MapRectangleImpl(Bounds bounds) {
|
|---|
| 22 | this(bounds, Color.BLUE);
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | public MapRectangleImpl(Bounds bounds, Color color) {
|
|---|
| 26 | this.topLeft = new Coordinate(bounds.getMax().lat(), bounds.getMin().lon());
|
|---|
| 27 | this.bottomRight = new Coordinate(bounds.getMin().lat(), bounds.getMax().lon());
|
|---|
| 28 | this.color = color;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | /* (non-Javadoc)
|
|---|
| 32 | * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getTopLeft()
|
|---|
| 33 | */
|
|---|
| 34 | @Override
|
|---|
| 35 | public Coordinate getTopLeft() {
|
|---|
| 36 | return topLeft;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | /* (non-Javadoc)
|
|---|
| 40 | * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getBottomRight()
|
|---|
| 41 | */
|
|---|
| 42 | @Override
|
|---|
| 43 | public Coordinate getBottomRight() {
|
|---|
| 44 | return bottomRight;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /* (non-Javadoc)
|
|---|
| 48 | * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#paint(java.awt.Graphics, java.awt.Point, java.awt.Point)
|
|---|
| 49 | */
|
|---|
| 50 | @Override
|
|---|
| 51 | public void paint(Graphics g, Point topLeft, Point bottomRight) {
|
|---|
| 52 | g.setColor(color);
|
|---|
| 53 | g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | @Override
|
|---|
| 57 | public String toString() {
|
|---|
| 58 | return "MapRectangle from " + topLeft + " to " + bottomRight;
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|