root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / PxLine.java @ 8026
History | View | Annotate | Download (3.12 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 org.cresques.geo.ViewPortData; |
27 |
|
28 |
import java.awt.Color; |
29 |
import java.awt.Graphics2D; |
30 |
import java.awt.Stroke; |
31 |
import java.awt.geom.AffineTransform; |
32 |
|
33 |
|
34 |
public class PxLine extends PxObj implements IPoint, Colored { |
35 |
private int px = 0; |
36 |
private int py = 0; |
37 |
private int px2 = 0; |
38 |
private int py2 = 0; |
39 |
private Color pc; |
40 |
|
41 |
public PxLine(IPoint p, IPoint p2, Color color) { |
42 |
x(p.x()); |
43 |
y(p.y()); |
44 |
x2(p2.x()); |
45 |
y2(p2.y()); |
46 |
c(color); |
47 |
extent = new Extent(Math.min(x(), x2()), Math.min(y(), y2()), |
48 |
Math.max(x(), x2()), Math.max(y(), y2())); |
49 |
} |
50 |
|
51 |
public PxLine(int x, int y, int x2, int y2, Color color) { |
52 |
x(x); |
53 |
y(y); |
54 |
x2(x2); |
55 |
y2(y2); |
56 |
c(color); |
57 |
extent = new Extent(Math.min(x(), x2()), Math.min(y(), y2()), |
58 |
Math.max(x(), x2()), Math.max(y(), y2())); |
59 |
} |
60 |
|
61 |
public int x() { |
62 |
return px;
|
63 |
} |
64 |
|
65 |
public int x(int x) { |
66 |
px = x; |
67 |
|
68 |
return px;
|
69 |
} |
70 |
|
71 |
public int y() { |
72 |
return py;
|
73 |
} |
74 |
|
75 |
public int y(int y) { |
76 |
py = y; |
77 |
|
78 |
return py;
|
79 |
} |
80 |
|
81 |
public int x2() { |
82 |
return px2;
|
83 |
} |
84 |
|
85 |
public int x2(int x) { |
86 |
px2 = x; |
87 |
|
88 |
return px2;
|
89 |
} |
90 |
|
91 |
public int y2() { |
92 |
return py2;
|
93 |
} |
94 |
|
95 |
public int y2(int y) { |
96 |
py2 = y; |
97 |
|
98 |
return py2;
|
99 |
} |
100 |
|
101 |
public Color c() { |
102 |
return pc;
|
103 |
} |
104 |
|
105 |
public Color c(Color color) { |
106 |
pc = color; |
107 |
|
108 |
return pc;
|
109 |
} |
110 |
|
111 |
public void setStroke(Stroke stroke) { |
112 |
this.stroke = stroke;
|
113 |
} |
114 |
|
115 |
/* public void draw(Graphics2D g) {
|
116 |
draw(g, g.getTransform(), null);
|
117 |
}
|
118 |
|
119 |
public void draw(Graphics2D g, AffineTransform mat, Extent sz) {
|
120 |
*/
|
121 |
public void draw(Graphics2D g, ViewPortData vp) { |
122 |
Stroke strkSave = null; |
123 |
|
124 |
if (stroke != null) { |
125 |
strkSave = g.getStroke(); |
126 |
g.setStroke(stroke); |
127 |
} |
128 |
|
129 |
AffineTransform msave = g.getTransform();
|
130 |
g.setTransform(vp.mat); |
131 |
g.setColor(c()); |
132 |
g.drawLine(x(), y(), x2(), y2()); |
133 |
|
134 |
if (strkSave != null) { |
135 |
g.setStroke(strkSave); |
136 |
} |
137 |
|
138 |
g.setTransform(msave); |
139 |
} |
140 |
} |