Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libProjectionCresques / src / org / gvsig / projection / cresques / px / PxLine.java @ 21932

History | View | Annotate | Download (3.36 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.gvsig.projection.cresques.px;
25

    
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.Stroke;
29
import java.awt.geom.AffineTransform;
30

    
31
import org.gvsig.projection.geo.ViewPortData;
32
import org.gvsig.projection.px.Extent;
33
import org.gvsig.projection.px.PxObj;
34

    
35

    
36
public class PxLine extends PxObj implements IPoint, Colored {
37
    private int px = 0;
38
    private int py = 0;
39
    private int px2 = 0;
40
    private int py2 = 0;
41
    private Color pc;
42

    
43
    public PxLine(IPoint p, IPoint p2, Color color) {
44
        x(p.x());
45
        y(p.y());
46
        x2(p2.x());
47
        y2(p2.y());
48
        c(color);
49
        extent = new Extent(Math.min(x(), x2()), Math.min(y(), y2()),
50
                            Math.max(x(), x2()), Math.max(y(), y2()));
51
    }
52

    
53
    public PxLine(int x, int y, int x2, int y2, Color color) {
54
        x(x);
55
        y(y);
56
        x2(x2);
57
        y2(y2);
58
        c(color);
59
        extent = new Extent(Math.min(x(), x2()), Math.min(y(), y2()),
60
                            Math.max(x(), x2()), Math.max(y(), y2()));
61
    }
62

    
63
    public int x() {
64
        return px;
65
    }
66

    
67
    public int x(int x) {
68
        px = x;
69

    
70
        return px;
71
    }
72

    
73
    public int y() {
74
        return py;
75
    }
76

    
77
    public int y(int y) {
78
        py = y;
79

    
80
        return py;
81
    }
82

    
83
    public int x2() {
84
        return px2;
85
    }
86

    
87
    public int x2(int x) {
88
        px2 = x;
89

    
90
        return px2;
91
    }
92

    
93
    public int y2() {
94
        return py2;
95
    }
96

    
97
    public int y2(int y) {
98
        py2 = y;
99

    
100
        return py2;
101
    }
102

    
103
    public Color c() {
104
        return pc;
105
    }
106

    
107
    public Color c(Color color) {
108
        pc = color;
109

    
110
        return pc;
111
    }
112

    
113
    public void setStroke(Stroke stroke) {
114
        this.stroke = stroke;
115
    }
116

    
117
    /*        public void draw(Graphics2D g) {
118
                    draw(g, g.getTransform(), null);
119
            }
120

121
            public void draw(Graphics2D g, AffineTransform mat, Extent sz) {
122
    */
123
    public void draw(Graphics2D g, ViewPortData vp) {
124
        Stroke strkSave = null;
125

    
126
        if (stroke != null) {
127
            strkSave = g.getStroke();
128
            g.setStroke(stroke);
129
        }
130

    
131
        AffineTransform msave = g.getTransform();
132
        g.setTransform(vp.mat);
133
        g.setColor(c());
134
        g.drawLine(x(), y(), x2(), y2());
135

    
136
        if (strkSave != null) {
137
            g.setStroke(strkSave);
138
        }
139

    
140
        g.setTransform(msave);
141
    }
142
}