svn-gvsig-desktop / tags / v2_0_0_Build_2051 / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / impl / DefaultPrimitivesDrawer.java @ 38733
History | View | Annotate | Download (3.46 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.mapcontrol.impl; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Graphics; |
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.RenderingHints; |
28 |
import java.awt.Stroke; |
29 |
import java.awt.image.BufferedImage; |
30 |
|
31 |
import org.gvsig.fmap.mapcontrol.MapControl; |
32 |
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
33 |
import org.slf4j.Logger; |
34 |
import org.slf4j.LoggerFactory; |
35 |
|
36 |
/**
|
37 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
38 |
*/
|
39 |
public class DefaultPrimitivesDrawer implements PrimitivesDrawer { |
40 |
|
41 |
private static final Logger LOG = LoggerFactory |
42 |
.getLogger(DefaultPrimitivesDrawer.class); |
43 |
|
44 |
protected Graphics2D graphics = null; |
45 |
protected Color color = Color.BLACK; |
46 |
protected Color xorColor = Color.WHITE; |
47 |
private Object lockObject = null; |
48 |
|
49 |
public DefaultPrimitivesDrawer() {
|
50 |
super();
|
51 |
} |
52 |
|
53 |
public DefaultPrimitivesDrawer(Graphics2D graphics) { |
54 |
super();
|
55 |
this.graphics = graphics;
|
56 |
} |
57 |
|
58 |
public void drawLine(int x1, int y1, int x2, int y2) { |
59 |
graphics.setXORMode(xorColor); |
60 |
graphics.drawLine(x1, y1, x2, y2); |
61 |
graphics.setPaintMode(); |
62 |
} |
63 |
|
64 |
public void drawOval(int x, int y, int width, int height) { |
65 |
graphics.setXORMode(xorColor); |
66 |
graphics.drawOval(x, y, width, height); |
67 |
graphics.setPaintMode(); |
68 |
} |
69 |
|
70 |
public void drawRect(int x, int y, int width, int height) { |
71 |
graphics.setXORMode(xorColor); |
72 |
graphics.drawRect(x, y, width, height); |
73 |
graphics.setPaintMode(); |
74 |
} |
75 |
|
76 |
public void fillRect(int x, int y, int width, int height) { |
77 |
graphics.setColor(color); |
78 |
graphics.fillRect(x, y, width, height); |
79 |
} |
80 |
|
81 |
public void setColor(Color color) { |
82 |
this.color = color;
|
83 |
} |
84 |
|
85 |
public void setGraphics(Graphics graphics) { |
86 |
this.graphics = (Graphics2D) graphics; |
87 |
} |
88 |
|
89 |
public void stopDrawing(Object obj) { |
90 |
if (lockObject != obj) {
|
91 |
LOG.warn("Trying to unlock a resource that is not locked");
|
92 |
return;
|
93 |
} |
94 |
lockObject = null;
|
95 |
} |
96 |
|
97 |
public void startDrawing(Object obj) throws InterruptedException { |
98 |
while ((lockObject != null) && (obj != lockObject)) { |
99 |
Thread.sleep(100); |
100 |
} |
101 |
lockObject = obj; |
102 |
} |
103 |
|
104 |
public void setRenderingHints(RenderingHints hints) { |
105 |
this.graphics.setRenderingHints(hints);
|
106 |
} |
107 |
|
108 |
public void setStroke(Stroke stroke) { |
109 |
this.graphics.setStroke(stroke);
|
110 |
} |
111 |
|
112 |
public void cleanCanvas(MapControl mapCtrl) { |
113 |
BufferedImage img = mapCtrl.getImage();
|
114 |
this.graphics.drawImage(img, 0, 0, null); |
115 |
} |
116 |
} |