svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / impl / DefaultPrimitivesDrawer.java @ 47357
History | View | Annotate | Download (3.86 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.mapcontrol.impl; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Graphics; |
28 |
import java.awt.Graphics2D; |
29 |
import java.awt.RenderingHints; |
30 |
import java.awt.Stroke; |
31 |
import java.awt.image.BufferedImage; |
32 |
|
33 |
import org.gvsig.fmap.mapcontrol.MapControl; |
34 |
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
/**
|
39 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
40 |
*/
|
41 |
public class DefaultPrimitivesDrawer implements PrimitivesDrawer { |
42 |
|
43 |
private static final Logger LOG = LoggerFactory |
44 |
.getLogger(DefaultPrimitivesDrawer.class); |
45 |
|
46 |
protected Graphics2D graphics = null; |
47 |
protected Color color = Color.BLACK; |
48 |
protected Color xorColor = Color.WHITE; |
49 |
private Object lockObject = null; |
50 |
|
51 |
public DefaultPrimitivesDrawer() {
|
52 |
super();
|
53 |
} |
54 |
|
55 |
public DefaultPrimitivesDrawer(Graphics2D graphics) { |
56 |
super();
|
57 |
this.graphics = graphics;
|
58 |
} |
59 |
|
60 |
public void drawLine(int x1, int y1, int x2, int y2) { |
61 |
Color prevColor = graphics.getColor();
|
62 |
graphics.setXORMode(xorColor); |
63 |
graphics.setColor(color); |
64 |
graphics.drawLine(x1, y1, x2, y2); |
65 |
graphics.setPaintMode(); |
66 |
graphics.setColor(prevColor); |
67 |
} |
68 |
|
69 |
public void drawOval(int x, int y, int width, int height) { |
70 |
Color prevColor = graphics.getColor();
|
71 |
graphics.setXORMode(xorColor); |
72 |
graphics.setColor(color); |
73 |
graphics.drawOval(x, y, width, height); |
74 |
graphics.setPaintMode(); |
75 |
graphics.setColor(prevColor); |
76 |
} |
77 |
|
78 |
public void drawRect(int x, int y, int width, int height) { |
79 |
Color prevColor = graphics.getColor();
|
80 |
graphics.setXORMode(xorColor); |
81 |
graphics.setColor(color); |
82 |
graphics.drawRect(x, y, width, height); |
83 |
graphics.setPaintMode(); |
84 |
graphics.setColor(prevColor); |
85 |
} |
86 |
|
87 |
public void fillRect(int x, int y, int width, int height) { |
88 |
graphics.setColor(color); |
89 |
graphics.fillRect(x, y, width, height); |
90 |
} |
91 |
|
92 |
public void setColor(Color color) { |
93 |
this.color = color;
|
94 |
} |
95 |
|
96 |
public void setGraphics(Graphics graphics) { |
97 |
this.graphics = (Graphics2D) graphics; |
98 |
} |
99 |
|
100 |
public void stopDrawing(Object obj) { |
101 |
if (lockObject != obj) {
|
102 |
LOG.info("Trying to unlock a resource that is not locked");
|
103 |
return;
|
104 |
} |
105 |
lockObject = null;
|
106 |
} |
107 |
|
108 |
public void startDrawing(Object obj) throws InterruptedException { |
109 |
while ((lockObject != null) && (obj != lockObject)) { |
110 |
Thread.sleep(100); |
111 |
} |
112 |
lockObject = obj; |
113 |
} |
114 |
|
115 |
public void setRenderingHints(RenderingHints hints) { |
116 |
this.graphics.setRenderingHints(hints);
|
117 |
} |
118 |
|
119 |
public void setStroke(Stroke stroke) { |
120 |
this.graphics.setStroke(stroke);
|
121 |
} |
122 |
|
123 |
public void cleanCanvas(MapControl mapCtrl) { |
124 |
BufferedImage img = mapCtrl.getImage();
|
125 |
this.graphics.drawImage(img, 0, 0, null); |
126 |
} |
127 |
} |