Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / impl / DefaultPrimitivesDrawer.java @ 34679

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

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol.impl;
29

    
30
import java.awt.Color;
31
import java.awt.Graphics;
32
import java.awt.Graphics2D;
33

    
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

    
37
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer;
38

    
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41
 */
42
public class DefaultPrimitivesDrawer implements PrimitivesDrawer{
43

    
44
    private static final Logger LOG = LoggerFactory
45
        .getLogger(DefaultPrimitivesDrawer.class);
46

    
47
    protected Graphics2D graphics = null;
48
        protected Color color = Color.BLACK;
49
        protected Color xorColor = Color.WHITE;
50
        private Object lockObject = null;
51

    
52
        public DefaultPrimitivesDrawer() {
53
                super();                
54
        }        
55
        
56
        public DefaultPrimitivesDrawer(Graphics2D graphics) {
57
                super();
58
                this.graphics = graphics;
59
        }
60
        
61
        /*
62
         * (non-Javadoc)
63
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#drawLine(int, int, int, int)
64
         */
65
        public void drawLine(int x1, int y1, int x2, int y2) {
66
                graphics.setXORMode(xorColor);
67
                graphics.drawLine(x1, y1, x2, y2);
68
                graphics.setPaintMode();
69
        }
70

    
71
        /*
72
         * (non-Javadoc)
73
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#drawOval(int, int, int, int)
74
         */
75
        public void drawOval(int x, int y, int width, int height) {
76
                graphics.setXORMode(xorColor);
77
                graphics.drawOval(x, y, width, height);
78
                graphics.setPaintMode();
79
        }
80

    
81
        /*
82
         * (non-Javadoc)
83
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#drawRect(int, int, int, int)
84
         */
85
        public void drawRect(int x, int y, int width, int height) {
86
                graphics.setXORMode(xorColor);
87
                graphics.drawRect(x, y, width, height);        
88
                graphics.setPaintMode();
89
        }
90
        
91
        /*
92
         * (non-Javadoc)
93
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#fillRect(int, int, int, int)
94
         */
95
        public void fillRect(int x, int y, int width, int height) {
96
                graphics.setXORMode(xorColor);
97
                graphics.fillRect(x, y, width, height);
98
                graphics.setPaintMode();
99
        }
100

    
101
        /*
102
         * (non-Javadoc)
103
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#setColor(java.awt.Color)
104
         */
105
        public void setColor(Color color) {
106
                this.color = color;                
107
        }
108

    
109
        /*
110
         * (non-Javadoc)
111
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#setGraphics(java.awt.Graphics)
112
         */
113
        public void setGraphics(Graphics graphics) {
114
                this.graphics = (Graphics2D)graphics;
115
        }
116
        
117
        /*
118
         * (non-Javadoc)
119
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#stopDrawing(java.lang.Object)
120
         */
121
        public void stopDrawing(Object obj) {
122
                if (lockObject != obj){
123
            LOG.warn("Trying to unlock a resource that is not locked");
124
                        return;
125
                }
126
                lockObject = null;
127
        }
128
        
129
        /*
130
         * (non-Javadoc)
131
         * @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#startDrawing(java.lang.Object)
132
         */
133
        public void startDrawing(Object obj) throws InterruptedException {
134
                while ((lockObject != null) && (obj != lockObject)){
135
                        Thread.sleep(100);
136
                }
137
                lockObject = obj;
138
        }
139
}
140