Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/px/PxLine.java
PxLine.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.px; |
25 | 25 |
|
26 |
import org.cresques.geo.ViewPortData; |
|
27 |
|
|
26 | 28 |
import java.awt.Color; |
29 |
import java.awt.Graphics2D; |
|
27 | 30 |
import java.awt.Stroke; |
28 |
import java.awt.Graphics2D; |
|
29 | 31 |
import java.awt.geom.AffineTransform; |
30 | 32 |
|
31 |
import org.cresques.geo.ViewPortData; |
|
32 | 33 |
|
33 | 34 |
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;} |
|
35 |
private int px = 0; |
|
36 |
private int py = 0; |
|
37 |
private int px2 = 0; |
|
38 |
private int py2 = 0; |
|
39 |
private Color pc; |
|
53 | 40 |
|
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;} |
|
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 |
} |
|
58 | 50 |
|
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 |
} |
|
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 |
} |
|
65 | 60 |
|
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 |
} |
|
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 |
} |
|
84 | 140 |
} |
Also available in: Unified diff