Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / PxLine.java @ 2249

History | View | Annotate | Download (3.01 KB)

1
/*
2
 * Created on 21-jun-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.cresques.px;
48

    
49
import java.awt.Color;
50
import java.awt.Stroke;
51
import java.awt.Graphics2D;
52
import java.awt.geom.AffineTransform;
53

    
54
import org.cresques.geo.ViewPortData;
55

    
56
public class PxLine extends PxObj implements IPoint, Colored {
57
        private int px=0, py=0;
58
        private int px2=0, py2=0;
59
        private Color pc;
60
        public PxLine(IPoint p, IPoint p2, Color color) {
61
                x(p.x()); y(p.y());
62
                x2(p2.x()); y2(p2.y());
63
                c(color);
64
                extent = new Extent(Math.min(x(),x2()), Math.min(y(),y2()), Math.max(x(),x2()), Math.max(y(),y2()));
65
        }
66
        public PxLine(int x, int y, int x2, int y2, Color color) {
67
                x(x); y(y);
68
                x2(x2); y2(y2);
69
                c(color);
70
                extent = new Extent(Math.min(x(),x2()), Math.min(y(),y2()), Math.max(x(),x2()), Math.max(y(),y2()));
71
        }
72
        public int x() {return px;}
73
        public int x(int x) {px = x; return px;}
74
        public int y() {return py;}
75
        public int y(int y) {py = y; return py;}
76

    
77
        public int x2() {return px2;}
78
        public int x2(int x) {px2 = x; return px2;}
79
        public int y2() {return py2;}
80
        public int y2(int y) {py2 = y; return py2;}
81

    
82
        public Color c() {return pc;}
83
        public Color c(Color color) {pc = color; return pc;}
84
        
85
        public void setStroke(Stroke stroke) {
86
                this.stroke = stroke;
87
        }
88

    
89
/*        public void draw(Graphics2D g) {
90
                draw(g, g.getTransform(), null);
91
        }
92
        
93
        public void draw(Graphics2D g, AffineTransform mat, Extent sz) {
94
*/        public void draw(Graphics2D g, ViewPortData vp) {
95
                Stroke strkSave = null;
96
                if (stroke != null) {
97
                        strkSave = g.getStroke();
98
                        g.setStroke(stroke);
99
                }
100
                AffineTransform msave=g.getTransform();
101
                g.setTransform(vp.mat);
102
                g.setColor(c());
103
                g.drawLine(x(), y(), x2(), y2());
104
                if (strkSave != null) g.setStroke(strkSave);
105
                g.setTransform(msave);
106
        }
107
}