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

Last change on this file since 29516 was 29516, checked in by donvip, 12 years ago

[jmapviewer] fix some stuff causing compilation problems in JOSM

  • Property svn:eol-style set to native
File size: 2.8 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 extends MapObjectImpl implements MapRectangle {
18
19 private Coordinate topLeft;
20 private Coordinate bottomRight;
21
22 public MapRectangleImpl(String name, Coordinate topLeft, Coordinate bottomRight) {
23 this(null, name, topLeft, bottomRight);
24 }
25 public MapRectangleImpl(Layer layer, Coordinate topLeft, Coordinate bottomRight) {
26 this(layer, null, topLeft, bottomRight);
27 }
28 public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight) {
29 this(layer, name, topLeft, bottomRight, getDefaultStyle());
30 }
31 public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight, Style style) {
32 super(layer, name, style);
33 this.topLeft = topLeft;
34 this.bottomRight = bottomRight;
35 }
36
37 /* (non-Javadoc)
38 * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getTopLeft()
39 */
40 @Override
41 public Coordinate getTopLeft() {
42 return topLeft;
43 }
44
45 /* (non-Javadoc)
46 * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getBottomRight()
47 */
48 @Override
49 public Coordinate getBottomRight() {
50 return bottomRight;
51 }
52
53 /* (non-Javadoc)
54 * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#paint(java.awt.Graphics, java.awt.Point, java.awt.Point)
55 */
56 @Override
57 public void paint(Graphics g, Point topLeft, Point bottomRight) {
58 // Prepare graphics
59 Color oldColor = g.getColor();
60 g.setColor(getColor());
61 Stroke oldStroke = null;
62 if (g instanceof Graphics2D) {
63 Graphics2D g2 = (Graphics2D) g;
64 oldStroke = g2.getStroke();
65 g2.setStroke(getStroke());
66 }
67 // Draw
68 g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
69 // Restore graphics
70 g.setColor(oldColor);
71 if (g instanceof Graphics2D) {
72 ((Graphics2D) g).setStroke(oldStroke);
73 }
74 int width=bottomRight.x-topLeft.x;
75 int height=bottomRight.y-topLeft.y;
76 Point p= new Point(topLeft.x+(width/2), topLeft.y+(height/2));
77 if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p);
78 }
79 public static Style getDefaultStyle(){
80 return new Style(Color.BLUE, null, new BasicStroke(2), getDefaultFont());
81 }
82 @Override
83 public String toString() {
84 return "MapRectangle from " + topLeft + " to " + bottomRight;
85 }
86}
Note: See TracBrowser for help on using the repository browser.