root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / impl / DefaultPrimitivesDrawer.java @ 38626
History | View | Annotate | Download (3.46 KB)
1 | 30349 | jpiera | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 36372 | cordinyana | *
|
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 | 30349 | jpiera | package org.gvsig.fmap.mapcontrol.impl; |
23 | |||
24 | import java.awt.Color; |
||
25 | import java.awt.Graphics; |
||
26 | import java.awt.Graphics2D; |
||
27 | 38626 | nbrodin | import java.awt.RenderingHints; |
28 | import java.awt.Stroke; |
||
29 | import java.awt.image.BufferedImage; |
||
30 | 30349 | jpiera | |
31 | 38626 | nbrodin | import org.gvsig.fmap.mapcontrol.MapControl; |
32 | 38564 | jjdelcerro | import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
33 | 34679 | cordinyana | import org.slf4j.Logger; |
34 | import org.slf4j.LoggerFactory; |
||
35 | |||
36 | 30349 | jpiera | /**
|
37 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
38 | */
|
||
39 | 36372 | cordinyana | public class DefaultPrimitivesDrawer implements PrimitivesDrawer { |
40 | 34679 | cordinyana | |
41 | private static final Logger LOG = LoggerFactory |
||
42 | .getLogger(DefaultPrimitivesDrawer.class); |
||
43 | |||
44 | protected Graphics2D graphics = null; |
||
45 | 36372 | cordinyana | protected Color color = Color.BLACK; |
46 | protected Color xorColor = Color.WHITE; |
||
47 | private Object lockObject = null; |
||
48 | 30349 | jpiera | |
49 | 36372 | cordinyana | public DefaultPrimitivesDrawer() {
|
50 | super();
|
||
51 | } |
||
52 | 30349 | jpiera | |
53 | 36372 | cordinyana | public DefaultPrimitivesDrawer(Graphics2D graphics) { |
54 | super();
|
||
55 | this.graphics = graphics;
|
||
56 | } |
||
57 | 30349 | jpiera | |
58 | 36372 | cordinyana | 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 | 30349 | jpiera | |
64 | 36372 | cordinyana | 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 | 30349 | jpiera | |
70 | 36372 | cordinyana | 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 | 36374 | cordinyana | graphics.setColor(color); |
78 | 36372 | cordinyana | 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 | 34679 | cordinyana | LOG.warn("Trying to unlock a resource that is not locked");
|
92 | 36372 | cordinyana | return;
|
93 | } |
||
94 | lockObject = null;
|
||
95 | } |
||
96 | 30349 | jpiera | |
97 | 36372 | cordinyana | public void startDrawing(Object obj) throws InterruptedException { |
98 | while ((lockObject != null) && (obj != lockObject)) { |
||
99 | Thread.sleep(100); |
||
100 | } |
||
101 | lockObject = obj; |
||
102 | } |
||
103 | 38626 | nbrodin | |
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 | 36372 | cordinyana | } |