source: osm/applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java@ 26668

Last change on this file since 26668 was 26668, checked in by bastik, 13 years ago

fixed josm 6858 - Unnecessary JMapViewer Dependencies (patch by Don-vip)

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.gui.jmapviewer;
3
4import java.awt.BasicStroke;
5import java.awt.Color;
6import java.awt.Graphics;
7import java.awt.Graphics2D;
8import java.awt.Point;
9import java.awt.Stroke;
10
11import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle;
12
13/**
14 * @author Vincent
15 *
16 */
17public class MapRectangleImpl implements MapRectangle {
18
19 private Coordinate topLeft;
20 private Coordinate bottomRight;
21 private Color color;
22 private Stroke stroke;
23
24 public MapRectangleImpl(Coordinate topLeft, Coordinate bottomRight) {
25 this(topLeft, bottomRight, Color.BLUE, new BasicStroke(2));
26 }
27
28 public MapRectangleImpl(Coordinate topLeft, Coordinate bottomRight, Color color, Stroke stroke) {
29 this.topLeft = topLeft;
30 this.bottomRight = bottomRight;
31 this.color = color;
32 this.stroke = stroke;
33 }
34
35 /* (non-Javadoc)
36 * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getTopLeft()
37 */
38 @Override
39 public Coordinate getTopLeft() {
40 return topLeft;
41 }
42
43 /* (non-Javadoc)
44 * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getBottomRight()
45 */
46 @Override
47 public Coordinate getBottomRight() {
48 return bottomRight;
49 }
50
51 /* (non-Javadoc)
52 * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#paint(java.awt.Graphics, java.awt.Point, java.awt.Point)
53 */
54 @Override
55 public void paint(Graphics g, Point topLeft, Point bottomRight) {
56 // Prepare graphics
57 Color oldColor = g.getColor();
58 g.setColor(color);
59 Stroke oldStroke = null;
60 if (g instanceof Graphics2D) {
61 Graphics2D g2 = (Graphics2D) g;
62 oldStroke = g2.getStroke();
63 g2.setStroke(stroke);
64 }
65 // Draw
66 g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
67 // Restore graphics
68 g.setColor(oldColor);
69 if (g instanceof Graphics2D) {
70 ((Graphics2D) g).setStroke(oldStroke);
71 }
72 }
73
74 @Override
75 public String toString() {
76 return "MapRectangle from " + topLeft + " to " + bottomRight;
77 }
78}
Note: See TracBrowser for help on using the repository browser.