Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / PxLine.java @ 2312

History | View | Annotate | Download (2.53 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.cresques.px;
25

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

    
31
import org.cresques.geo.ViewPortData;
32

    
33
public class PxLine extends PxObj implements IPoint, Colored {
34
        private int px=0, py=0;
35
        private int px2=0, py2=0;
36
        private Color pc;
37
        public PxLine(IPoint p, IPoint p2, Color color) {
38
                x(p.x()); y(p.y());
39
                x2(p2.x()); y2(p2.y());
40
                c(color);
41
                extent = new Extent(Math.min(x(),x2()), Math.min(y(),y2()), Math.max(x(),x2()), Math.max(y(),y2()));
42
        }
43
        public PxLine(int x, int y, int x2, int y2, Color color) {
44
                x(x); y(y);
45
                x2(x2); y2(y2);
46
                c(color);
47
                extent = new Extent(Math.min(x(),x2()), Math.min(y(),y2()), Math.max(x(),x2()), Math.max(y(),y2()));
48
        }
49
        public int x() {return px;}
50
        public int x(int x) {px = x; return px;}
51
        public int y() {return py;}
52
        public int y(int y) {py = y; return py;}
53

    
54
        public int x2() {return px2;}
55
        public int x2(int x) {px2 = x; return px2;}
56
        public int y2() {return py2;}
57
        public int y2(int y) {py2 = y; return py2;}
58

    
59
        public Color c() {return pc;}
60
        public Color c(Color color) {pc = color; return pc;}
61
        
62
        public void setStroke(Stroke stroke) {
63
                this.stroke = stroke;
64
        }
65

    
66
/*        public void draw(Graphics2D g) {
67
                draw(g, g.getTransform(), null);
68
        }
69
        
70
        public void draw(Graphics2D g, AffineTransform mat, Extent sz) {
71
*/        public void draw(Graphics2D g, ViewPortData vp) {
72
                Stroke strkSave = null;
73
                if (stroke != null) {
74
                        strkSave = g.getStroke();
75
                        g.setStroke(stroke);
76
                }
77
                AffineTransform msave=g.getTransform();
78
                g.setTransform(vp.mat);
79
                g.setColor(c());
80
                g.drawLine(x(), y(), x2(), y2());
81
                if (strkSave != null) g.setStroke(strkSave);
82
                g.setTransform(msave);
83
        }
84
}