Statistics
| Revision:

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 @ 43510

History | View | Annotate | Download (3.5 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40559 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 40435 jjdelcerro
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8 40559 jjdelcerro
 * as published by the Free Software Foundation; either version 3
9 40435 jjdelcerro
 * of the License, or (at your option) any later version.
10 40559 jjdelcerro
 *
11 40435 jjdelcerro
 * 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 40559 jjdelcerro
 *
16 40435 jjdelcerro
 * 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 40559 jjdelcerro
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 40435 jjdelcerro
 * MA  02110-1301, USA.
20 40559 jjdelcerro
 *
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 40435 jjdelcerro
 */
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
        graphics.setXORMode(xorColor);
62
        graphics.drawLine(x1, y1, x2, y2);
63
        graphics.setPaintMode();
64
    }
65
66
    public void drawOval(int x, int y, int width, int height) {
67
        graphics.setXORMode(xorColor);
68
        graphics.drawOval(x, y, width, height);
69
        graphics.setPaintMode();
70
    }
71
72
    public void drawRect(int x, int y, int width, int height) {
73
        graphics.setXORMode(xorColor);
74
        graphics.drawRect(x, y, width, height);
75
        graphics.setPaintMode();
76
    }
77
78
    public void fillRect(int x, int y, int width, int height) {
79
        graphics.setColor(color);
80
        graphics.fillRect(x, y, width, height);
81
    }
82
83
    public void setColor(Color color) {
84
        this.color = color;
85
    }
86
87
    public void setGraphics(Graphics graphics) {
88
        this.graphics = (Graphics2D) graphics;
89
    }
90
91
    public void stopDrawing(Object obj) {
92
        if (lockObject != obj) {
93
            LOG.info("Trying to unlock a resource that is not locked");
94
            return;
95
        }
96
        lockObject = null;
97
    }
98
99
    public void startDrawing(Object obj) throws InterruptedException {
100
        while ((lockObject != null) && (obj != lockObject)) {
101
            Thread.sleep(100);
102
        }
103
        lockObject = obj;
104
    }
105
106
    public void setRenderingHints(RenderingHints hints) {
107
            this.graphics.setRenderingHints(hints);
108
    }
109
110
    public void setStroke(Stroke stroke) {
111
            this.graphics.setStroke(stroke);
112
    }
113
114
    public void cleanCanvas(MapControl mapCtrl) {
115
            BufferedImage img = mapCtrl.getImage();
116
            this.graphics.drawImage(img, 0, 0, null);
117
    }
118
}