Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / impl / DefaultPrimitivesDrawer.java @ 38564

History | View | Annotate | Download (2.97 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

    
28
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

    
32
/**
33
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
34
 */
35
public class DefaultPrimitivesDrawer implements PrimitivesDrawer {
36

    
37
    private static final Logger LOG = LoggerFactory
38
        .getLogger(DefaultPrimitivesDrawer.class);
39

    
40
    protected Graphics2D graphics = null;
41
    protected Color color = Color.BLACK;
42
    protected Color xorColor = Color.WHITE;
43
    private Object lockObject = null;
44

    
45
    public DefaultPrimitivesDrawer() {
46
        super();
47
    }
48

    
49
    public DefaultPrimitivesDrawer(Graphics2D graphics) {
50
        super();
51
        this.graphics = graphics;
52
    }
53

    
54
    public void drawLine(int x1, int y1, int x2, int y2) {
55
        graphics.setXORMode(xorColor);
56
        graphics.drawLine(x1, y1, x2, y2);
57
        graphics.setPaintMode();
58
    }
59

    
60
    public void drawOval(int x, int y, int width, int height) {
61
        graphics.setXORMode(xorColor);
62
        graphics.drawOval(x, y, width, height);
63
        graphics.setPaintMode();
64
    }
65

    
66
    public void drawRect(int x, int y, int width, int height) {
67
        graphics.setXORMode(xorColor);
68
        graphics.drawRect(x, y, width, height);
69
        graphics.setPaintMode();
70
    }
71

    
72
    public void fillRect(int x, int y, int width, int height) {
73
        graphics.setColor(color);
74
        graphics.fillRect(x, y, width, height);
75
    }
76

    
77
    public void setColor(Color color) {
78
        this.color = color;
79
    }
80

    
81
    public void setGraphics(Graphics graphics) {
82
        this.graphics = (Graphics2D) graphics;
83
    }
84

    
85
    public void stopDrawing(Object obj) {
86
        if (lockObject != obj) {
87
            LOG.warn("Trying to unlock a resource that is not locked");
88
            return;
89
        }
90
        lockObject = null;
91
    }
92

    
93
    public void startDrawing(Object obj) throws InterruptedException {
94
        while ((lockObject != null) && (obj != lockObject)) {
95
            Thread.sleep(100);
96
        }
97
        lockObject = obj;
98
    }
99
}