Revision 288
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/AreaMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import java.awt.Cursor; |
|
4 |
import java.awt.Graphics; |
|
5 |
import java.awt.Image; |
|
6 |
import java.awt.Point; |
|
7 |
import java.awt.Toolkit; |
|
8 |
import java.awt.event.MouseEvent; |
|
9 |
import java.awt.geom.Point2D; |
|
10 |
|
|
11 |
import javax.swing.ImageIcon; |
|
12 |
|
|
13 |
|
|
14 |
public class AreaMapTool extends MapTool{ |
|
15 |
private static final Image izoomin = new ImageIcon( |
|
16 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
17 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
18 |
new Point(16, 16), ""); |
|
19 |
private Point2D m_FirstPoint; |
|
20 |
private Point2D m_LastPoint; |
|
21 |
private Point2D m_PointAnt; |
|
22 |
|
|
23 |
/** |
|
24 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#paintComponent(java.awt.Graphics) |
|
25 |
*/ |
|
26 |
public void paintComponent(Graphics g) { |
|
27 |
/* g.drawImage(getMapControl().getImage(), 0, 0, null); |
|
28 |
g.setColor(Color.black); |
|
29 |
|
|
30 |
if (m_medidaFin != null) { |
|
31 |
drawPoliLine((Graphics2D) g); |
|
32 |
} |
|
33 |
|
|
34 |
if ((m_medidaFin != null) && (m_medidaLast != null)) { |
|
35 |
g.drawLine(m_medidaFin.x, m_medidaFin.y, m_medidaLast.x, |
|
36 |
m_medidaLast.y); |
|
37 |
} else { |
|
38 |
distAll = 0; |
|
39 |
} |
|
40 |
*/ |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#getCursor() |
|
45 |
*/ |
|
46 |
public Cursor getCursor() { |
|
47 |
return cur; |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
52 |
*/ |
|
53 |
public void mousePressed(MouseEvent e) { |
|
54 |
Point pScreen = e.getPoint(); |
|
55 |
m_PointAnt = pScreen; |
|
56 |
m_FirstPoint = m_PointAnt; |
|
57 |
|
|
58 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
59 |
m_PointAnt = pScreen; |
|
60 |
|
|
61 |
/* if (E.isControlDown()) |
|
62 |
m_Estado = PAN; */ |
|
63 |
m_FirstPoint = m_PointAnt; |
|
64 |
|
|
65 |
getMapControl().cancelDrawing(); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
71 |
*/ |
|
72 |
public void mouseDragged(MouseEvent e) { |
|
73 |
m_LastPoint = e.getPoint(); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* DOCUMENT ME! |
|
78 |
* |
|
79 |
* @param E DOCUMENT ME! |
|
80 |
*/ |
|
81 |
public void mouseClicked(MouseEvent E) { |
|
82 |
/* if (E.getClickCount() == 2) { |
|
83 |
poliLinesX.clear(); |
|
84 |
poliLinesY.clear(); |
|
85 |
m_medidaIni = null; |
|
86 |
m_medidaFin = null; |
|
87 |
m_medidaLast = null; |
|
88 |
distAll = 0; |
|
89 |
status = ACTUALIZADO; |
|
90 |
isClicked = false; |
|
91 |
} else { |
|
92 |
if (m_medidaIni == null) { |
|
93 |
m_medidaIni = E.getPoint(); |
|
94 |
|
|
95 |
//addPoint(m_medidaIni); |
|
96 |
} |
|
97 |
|
|
98 |
isClicked = true; |
|
99 |
distAll = distAll + dist; |
|
100 |
|
|
101 |
//status = MEDICION; |
|
102 |
m_medidaFin = E.getPoint(); |
|
103 |
addPoint(m_medidaFin); |
|
104 |
} |
|
105 |
} |
|
106 |
public void mouseMoved(MouseEvent E){ |
|
107 |
if (isClicked) { |
|
108 |
if ((getTool() == MEDICION) || (getTool() == AREA)) { |
|
109 |
m_medidaLast = E.getPoint(); |
|
110 |
|
|
111 |
if (m_medidaFin != null) { |
|
112 |
dist = getMapContext().toMapDistance((long) m_medidaFin.distance( |
|
113 |
m_medidaLast)); |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
if (getTool() == MEDICION) { |
|
118 |
try { |
|
119 |
App.instance.getMDIContext().setMessage("3", |
|
120 |
"Segmento = " + nf.format(changeToUnits(dist))); |
|
121 |
App.instance.getMDIContext().setMessage("4", |
|
122 |
"Total = " + |
|
123 |
nf.format(changeToUnits(distAll + dist))); |
|
124 |
} catch (Exception e) { |
|
125 |
} |
|
126 |
|
|
127 |
// System.out.println("Longitud Total = " + (distAll + dist)); |
|
128 |
} |
|
129 |
|
|
130 |
if (getTool() == AREA) { |
|
131 |
if ((m_medidaLast != null) && (m_medidaIni != null)) { |
|
132 |
try { |
|
133 |
App.instance.getMDIContext().setMessage("3", |
|
134 |
"Per?metro = " + |
|
135 |
nf.format(changeToUnits(distAll + dist + |
|
136 |
m_medidaIni.distance(m_medidaLast)))); |
|
137 |
App.instance.getMDIContext().setMessage("4", |
|
138 |
"Area = " + |
|
139 |
nf.format(changeToUnits(returnArea( |
|
140 |
getMapContext().toMapPoint(m_medidaLast))))); |
|
141 |
} catch (Exception e) { |
|
142 |
} |
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
} |
|
147 |
|
|
148 |
repaint(); |
|
149 |
} |
|
150 |
} |
|
151 |
*/ |
|
152 |
} |
|
153 |
} |
|
154 |
|
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/ZoomInMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
4 |
|
|
5 |
import java.awt.Color; |
|
6 |
import java.awt.Cursor; |
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.Image; |
|
9 |
import java.awt.Point; |
|
10 |
import java.awt.Rectangle; |
|
11 |
import java.awt.Toolkit; |
|
12 |
import java.awt.event.MouseEvent; |
|
13 |
import java.awt.geom.Point2D; |
|
14 |
import java.awt.geom.Rectangle2D; |
|
15 |
import java.awt.image.BufferedImage; |
|
16 |
|
|
17 |
import javax.swing.ImageIcon; |
|
18 |
|
|
19 |
|
|
20 |
/** |
|
21 |
* Zoom in. |
|
22 |
* |
|
23 |
* @author Vicente Caballero Navarro |
|
24 |
*/ |
|
25 |
public class ZoomInMapTool extends MapTool { |
|
26 |
private static final Image izoomin = new ImageIcon( |
|
27 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
28 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
29 |
new Point(16, 16), ""); |
|
30 |
private Point2D m_FirstPoint; |
|
31 |
private Point2D m_LastPoint; |
|
32 |
private Point2D m_PointAnt; |
|
33 |
|
|
34 |
/** |
|
35 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#paintComponent(java.awt.Graphics) |
|
36 |
*/ |
|
37 |
public void paintComponent(Graphics g) { |
|
38 |
BufferedImage img = getMapControl().getImage(); |
|
39 |
|
|
40 |
g.drawImage(img, 0, 0, null); |
|
41 |
|
|
42 |
g.setColor(Color.black); |
|
43 |
g.setXORMode(Color.white); |
|
44 |
|
|
45 |
// Borramos el anterior |
|
46 |
Rectangle r = new Rectangle(); |
|
47 |
|
|
48 |
// Dibujamos el actual |
|
49 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
|
50 |
r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
|
51 |
g.drawRect(r.x, r.y, r.width, r.height); |
|
52 |
} |
|
53 |
|
|
54 |
getMapControl().repaint(); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#getCursor() |
|
59 |
*/ |
|
60 |
public Cursor getCursor() { |
|
61 |
return cur; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
66 |
*/ |
|
67 |
public void mousePressed(MouseEvent e) { |
|
68 |
Point pScreen = e.getPoint(); |
|
69 |
m_PointAnt = pScreen; |
|
70 |
m_FirstPoint = m_PointAnt; |
|
71 |
|
|
72 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
73 |
m_PointAnt = pScreen; |
|
74 |
|
|
75 |
/* if (E.isControlDown()) |
|
76 |
m_Estado = PAN; */ |
|
77 |
m_FirstPoint = m_PointAnt; |
|
78 |
|
|
79 |
getMapControl().cancelDrawing(); |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
85 |
*/ |
|
86 |
public void mouseReleased(MouseEvent e) { |
|
87 |
Point2D p1; |
|
88 |
Point2D p2; |
|
89 |
Point pScreen = e.getPoint(); |
|
90 |
|
|
91 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
92 |
|
|
93 |
p1 = vp.toMapPoint(m_FirstPoint); |
|
94 |
p2 = vp.toMapPoint(pScreen); |
|
95 |
|
|
96 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
97 |
if (java.lang.Math.abs(m_FirstPoint.getX() - pScreen.x) <= 3) { |
|
98 |
double nuevoX; |
|
99 |
double nuevoY; |
|
100 |
double cX; |
|
101 |
double cY; |
|
102 |
|
|
103 |
cX = p2.getX(); |
|
104 |
cY = p2.getY(); |
|
105 |
|
|
106 |
double factor = 0.6; |
|
107 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
108 |
|
|
109 |
nuevoX = cX - ((vp.getExtent().getWidth() * factor) / 2.0); |
|
110 |
nuevoY = cY - ((vp.getExtent().getHeight() * factor) / 2.0); |
|
111 |
r.x = nuevoX; |
|
112 |
r.y = nuevoY; |
|
113 |
r.width = vp.getExtent().getWidth() * factor; |
|
114 |
r.height = vp.getExtent().getHeight() * factor; |
|
115 |
|
|
116 |
vp.setExtent(r); |
|
117 |
} else { |
|
118 |
// Fijamos el nuevo extent |
|
119 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
120 |
|
|
121 |
r.setFrameFromDiagonal(p1, p2); |
|
122 |
|
|
123 |
vp.setExtent(r); |
|
124 |
} |
|
125 |
|
|
126 |
getMapControl().drawMap(); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
132 |
*/ |
|
133 |
public void mouseDragged(MouseEvent e) { |
|
134 |
m_LastPoint = e.getPoint(); |
|
135 |
} |
|
136 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/ZoomOutMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
4 |
|
|
5 |
import java.awt.Color; |
|
6 |
import java.awt.Cursor; |
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.Image; |
|
9 |
import java.awt.Point; |
|
10 |
import java.awt.Rectangle; |
|
11 |
import java.awt.Toolkit; |
|
12 |
import java.awt.event.MouseEvent; |
|
13 |
import java.awt.geom.Point2D; |
|
14 |
import java.awt.geom.Rectangle2D; |
|
15 |
import java.awt.image.BufferedImage; |
|
16 |
|
|
17 |
import javax.swing.ImageIcon; |
|
18 |
|
|
19 |
|
|
20 |
/** |
|
21 |
* Zoom out. |
|
22 |
* |
|
23 |
* @author Vicente Caballero Navarro |
|
24 |
*/ |
|
25 |
public class ZoomOutMapTool extends MapTool { |
|
26 |
private static final Image izoomin = new ImageIcon( |
|
27 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
28 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
29 |
new Point(16, 16), ""); |
|
30 |
private Point2D m_FirstPoint; |
|
31 |
private Point2D m_PointAnt; |
|
32 |
|
|
33 |
/** |
|
34 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#getCursor() |
|
35 |
*/ |
|
36 |
public Cursor getCursor() { |
|
37 |
return cur; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#mousePressed(java.awt.event.MouseEvent) |
|
42 |
*/ |
|
43 |
public void mousePressed(MouseEvent e) { |
|
44 |
Point pScreen = e.getPoint(); |
|
45 |
m_PointAnt = pScreen; |
|
46 |
m_FirstPoint = m_PointAnt; |
|
47 |
|
|
48 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
49 |
m_PointAnt = pScreen; |
|
50 |
m_FirstPoint = m_PointAnt; |
|
51 |
getMapControl().cancelDrawing(); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#mouseReleased(java.awt.event.MouseEvent) |
|
57 |
*/ |
|
58 |
public void mouseReleased(MouseEvent e) { |
|
59 |
Point2D p1; |
|
60 |
Point2D p2; |
|
61 |
Point pScreen = e.getPoint(); |
|
62 |
|
|
63 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
64 |
|
|
65 |
p1 = vp.toMapPoint(m_FirstPoint); |
|
66 |
p2 = vp.toMapPoint(pScreen); |
|
67 |
|
|
68 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
69 |
double nuevoX; |
|
70 |
double nuevoY; |
|
71 |
double factor = 1.8; |
|
72 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
73 |
|
|
74 |
nuevoX = p2.getX() - ((vp.getExtent().getWidth() * factor) / 2.0); |
|
75 |
nuevoY = p2.getY() - ((vp.getExtent().getHeight() * factor) / 2.0); |
|
76 |
r.x = nuevoX; |
|
77 |
r.y = nuevoY; |
|
78 |
r.width = vp.getExtent().getWidth() * factor; |
|
79 |
r.height = vp.getExtent().getHeight() * factor; |
|
80 |
|
|
81 |
vp.setExtent(r); |
|
82 |
getMapControl().drawMap(); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/LinkMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
|
|
4 |
public class LinkMapTool extends MapTool{ |
|
5 |
|
|
6 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/PanMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
4 |
|
|
5 |
import java.awt.Color; |
|
6 |
import java.awt.Cursor; |
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.Image; |
|
9 |
import java.awt.Point; |
|
10 |
import java.awt.Rectangle; |
|
11 |
import java.awt.Toolkit; |
|
12 |
import java.awt.event.MouseEvent; |
|
13 |
import java.awt.geom.Point2D; |
|
14 |
import java.awt.geom.Rectangle2D; |
|
15 |
import java.awt.image.BufferedImage; |
|
16 |
|
|
17 |
import javax.swing.ImageIcon; |
|
18 |
|
|
19 |
|
|
20 |
/** |
|
21 |
* Pan. |
|
22 |
* |
|
23 |
* @author Vicente Caballero Navarro |
|
24 |
*/ |
|
25 |
public class PanMapTool extends MapTool { |
|
26 |
private static final Image izoomin = new ImageIcon( |
|
27 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
28 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
29 |
new Point(16, 16), ""); |
|
30 |
private Point2D m_FirstPoint; |
|
31 |
private Point2D m_LastPoint; |
|
32 |
private Point2D m_PointAnt; |
|
33 |
|
|
34 |
/** |
|
35 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#paintComponent(java.awt.Graphics) |
|
36 |
*/ |
|
37 |
public void paintComponent(Graphics g) { |
|
38 |
g.setColor(Color.white); |
|
39 |
g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight()); |
|
40 |
|
|
41 |
if (getMapControl().getImage() != null) { |
|
42 |
// g.clearRect(0, 0, getWidth(), getHeight()); |
|
43 |
if ((m_LastPoint == null) && (m_PointAnt == null)) { |
|
44 |
m_LastPoint = new Point(); |
|
45 |
m_PointAnt = new Point(); |
|
46 |
} |
|
47 |
|
|
48 |
g.drawImage(getMapControl().getImage(), |
|
49 |
(int) (m_LastPoint.getX() - m_PointAnt.getX()), |
|
50 |
(int) (m_LastPoint.getY() - m_PointAnt.getY()), getMapControl()); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#getCursor() |
|
56 |
*/ |
|
57 |
public Cursor getCursor() { |
|
58 |
return cur; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
63 |
*/ |
|
64 |
public void mousePressed(MouseEvent e) { |
|
65 |
Point pScreen = e.getPoint(); |
|
66 |
m_PointAnt = pScreen; |
|
67 |
m_FirstPoint = m_PointAnt; |
|
68 |
|
|
69 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
70 |
m_PointAnt = pScreen; |
|
71 |
|
|
72 |
/* if (E.isControlDown()) |
|
73 |
m_Estado = PAN; */ |
|
74 |
m_FirstPoint = m_PointAnt; |
|
75 |
|
|
76 |
getMapControl().cancelDrawing(); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
82 |
*/ |
|
83 |
public void mouseReleased(MouseEvent e) { |
|
84 |
Point2D p1; |
|
85 |
Point2D p2; |
|
86 |
Point pScreen = e.getPoint(); |
|
87 |
|
|
88 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
89 |
|
|
90 |
p1 = vp.toMapPoint(m_FirstPoint); |
|
91 |
p2 = vp.toMapPoint(pScreen); |
|
92 |
|
|
93 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
94 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
95 |
Rectangle2D extent = vp.getExtent(); |
|
96 |
|
|
97 |
r.x = extent.getX() - (p2.getX() - p1.getX()); |
|
98 |
r.y = extent.getY() - (p2.getY() - p1.getY()); |
|
99 |
r.width = extent.getWidth(); |
|
100 |
r.height = extent.getHeight(); |
|
101 |
|
|
102 |
vp.setExtent(r); |
|
103 |
getMapControl().drawMap(); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
109 |
*/ |
|
110 |
public void mouseDragged(MouseEvent e) { |
|
111 |
m_LastPoint = e.getPoint(); |
|
112 |
getMapControl().repaint(); |
|
113 |
} |
|
114 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MapTool.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 28-oct-2004 |
|
3 |
*/ |
|
4 |
package com.iver.cit.gvsig.fmap.tools; |
|
5 |
|
|
6 |
import java.awt.Cursor; |
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.event.MouseEvent; |
|
9 |
import java.awt.event.MouseListener; |
|
10 |
import java.awt.event.MouseMotionListener; |
|
11 |
import java.awt.event.MouseWheelEvent; |
|
12 |
import java.awt.event.MouseWheelListener; |
|
13 |
import java.awt.image.BufferedImage; |
|
14 |
|
|
15 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
16 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
|
17 |
|
|
18 |
/** |
|
19 |
* Herramienta del MapControl. |
|
20 |
* Ejecuta acciones respondiendo a eventos, por delegaci?n desde MapControl. |
|
21 |
* |
|
22 |
* @author Luis W. Sevilla <sevilla_lui@gva.es> |
|
23 |
*/ |
|
24 |
public abstract class MapTool implements MouseWheelListener, MouseListener, MouseMotionListener { |
|
25 |
private NewMapControl mapControl; |
|
26 |
private Cursor cursor; |
|
27 |
|
|
28 |
/** |
|
29 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#paintComponent(java.awt.Graphics) |
|
30 |
*/ |
|
31 |
public void paintComponent(Graphics g) { |
|
32 |
BufferedImage img = getMapControl().getImage(); |
|
33 |
|
|
34 |
g.drawImage(img, 0, 0, null); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
public void setCursor(Cursor c){ |
|
39 |
cursor = c; |
|
40 |
} |
|
41 |
|
|
42 |
public void setMapControl(NewMapControl mc){ |
|
43 |
mapControl = mc; |
|
44 |
} |
|
45 |
|
|
46 |
public Cursor getCursor(){ |
|
47 |
return cursor; |
|
48 |
} |
|
49 |
|
|
50 |
public NewMapControl getMapControl(){ |
|
51 |
return mapControl; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) |
|
56 |
*/ |
|
57 |
public void mouseClicked(MouseEvent e){ |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) |
|
63 |
*/ |
|
64 |
public void mouseEntered(MouseEvent e){ |
|
65 |
|
|
66 |
} |
|
67 |
/** |
|
68 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) |
|
69 |
*/ |
|
70 |
public void mouseExited(MouseEvent e){ |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
76 |
*/ |
|
77 |
public void mousePressed(MouseEvent e){ |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
83 |
*/ |
|
84 |
public void mouseReleased(MouseEvent e){ |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
90 |
*/ |
|
91 |
public void mouseDragged(MouseEvent e){ |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) |
|
97 |
*/ |
|
98 |
public void mouseMoved(MouseEvent e){ |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent) |
|
104 |
*/ |
|
105 |
public void mouseWheelMoved(MouseWheelEvent e){ |
|
106 |
|
|
107 |
} |
|
108 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MeasureMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
4 |
|
|
5 |
import java.awt.Color; |
|
6 |
import java.awt.Cursor; |
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.Graphics2D; |
|
9 |
import java.awt.Image; |
|
10 |
import java.awt.Point; |
|
11 |
import java.awt.Rectangle; |
|
12 |
import java.awt.Toolkit; |
|
13 |
import java.awt.event.MouseEvent; |
|
14 |
import java.awt.geom.Point2D; |
|
15 |
import java.awt.geom.Rectangle2D; |
|
16 |
import java.awt.image.BufferedImage; |
|
17 |
|
|
18 |
import javax.swing.ImageIcon; |
|
19 |
|
|
20 |
|
|
21 |
/** |
|
22 |
* Medici?n de distancias. |
|
23 |
* |
|
24 |
* @author Vicente Caballero Navarro |
|
25 |
*/ |
|
26 |
public class MeasureMapTool extends MapTool { |
|
27 |
private static final Image izoomin = new ImageIcon( |
|
28 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
29 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
30 |
new Point(16, 16), ""); |
|
31 |
private Point2D m_FirstPoint; |
|
32 |
private Point2D m_LastPoint; |
|
33 |
private Point2D m_PointAnt; |
|
34 |
|
|
35 |
/** |
|
36 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#paintComponent(java.awt.Graphics) |
|
37 |
*/ |
|
38 |
public void paintComponent(Graphics g) { |
|
39 |
/* g.drawImage(getMapControl().getImage(), 0, 0, null); |
|
40 |
g.setColor(Color.black); |
|
41 |
|
|
42 |
if (m_medidaFin != null) { |
|
43 |
drawPoliLine((Graphics2D) g); |
|
44 |
} |
|
45 |
|
|
46 |
if ((m_medidaFin != null) && (m_medidaLast != null)) { |
|
47 |
g.drawLine(m_medidaFin.x, m_medidaFin.y, m_medidaLast.x, |
|
48 |
m_medidaLast.y); |
|
49 |
} else { |
|
50 |
distAll = 0; |
|
51 |
} |
|
52 |
*/ |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* @see com.iver.cit.gvsig.fmap.tools.MapTool#getCursor() |
|
57 |
*/ |
|
58 |
public Cursor getCursor() { |
|
59 |
return cur; |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
64 |
*/ |
|
65 |
public void mousePressed(MouseEvent e) { |
|
66 |
Point pScreen = e.getPoint(); |
|
67 |
m_PointAnt = pScreen; |
|
68 |
m_FirstPoint = m_PointAnt; |
|
69 |
|
|
70 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
71 |
m_PointAnt = pScreen; |
|
72 |
|
|
73 |
/* if (E.isControlDown()) |
|
74 |
m_Estado = PAN; */ |
|
75 |
m_FirstPoint = m_PointAnt; |
|
76 |
|
|
77 |
getMapControl().cancelDrawing(); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
83 |
*/ |
|
84 |
public void mouseDragged(MouseEvent e) { |
|
85 |
m_LastPoint = e.getPoint(); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* DOCUMENT ME! |
|
90 |
* |
|
91 |
* @param E DOCUMENT ME! |
|
92 |
*/ |
|
93 |
public void mouseClicked(MouseEvent E) { |
|
94 |
/* if (E.getClickCount() == 2) { |
|
95 |
poliLinesX.clear(); |
|
96 |
poliLinesY.clear(); |
|
97 |
m_medidaIni = null; |
|
98 |
m_medidaFin = null; |
|
99 |
m_medidaLast = null; |
|
100 |
distAll = 0; |
|
101 |
status = ACTUALIZADO; |
|
102 |
isClicked = false; |
|
103 |
} else { |
|
104 |
if (m_medidaIni == null) { |
|
105 |
m_medidaIni = E.getPoint(); |
|
106 |
|
|
107 |
//addPoint(m_medidaIni); |
|
108 |
} |
|
109 |
|
|
110 |
isClicked = true; |
|
111 |
distAll = distAll + dist; |
|
112 |
|
|
113 |
//status = MEDICION; |
|
114 |
m_medidaFin = E.getPoint(); |
|
115 |
addPoint(m_medidaFin); |
|
116 |
} |
|
117 |
} |
|
118 |
public void mouseMoved(MouseEvent E){ |
|
119 |
if (isClicked) { |
|
120 |
if ((getTool() == MEDICION) || (getTool() == AREA)) { |
|
121 |
m_medidaLast = E.getPoint(); |
|
122 |
|
|
123 |
if (m_medidaFin != null) { |
|
124 |
dist = getMapContext().toMapDistance((long) m_medidaFin.distance( |
|
125 |
m_medidaLast)); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
if (getTool() == MEDICION) { |
|
130 |
try { |
|
131 |
App.instance.getMDIContext().setMessage("3", |
|
132 |
"Segmento = " + nf.format(changeToUnits(dist))); |
|
133 |
App.instance.getMDIContext().setMessage("4", |
|
134 |
"Total = " + |
|
135 |
nf.format(changeToUnits(distAll + dist))); |
|
136 |
} catch (Exception e) { |
|
137 |
} |
|
138 |
|
|
139 |
// System.out.println("Longitud Total = " + (distAll + dist)); |
|
140 |
} |
|
141 |
|
|
142 |
if (getTool() == AREA) { |
|
143 |
if ((m_medidaLast != null) && (m_medidaIni != null)) { |
|
144 |
try { |
|
145 |
App.instance.getMDIContext().setMessage("3", |
|
146 |
"Per?metro = " + |
|
147 |
nf.format(changeToUnits(distAll + dist + |
|
148 |
m_medidaIni.distance(m_medidaLast)))); |
|
149 |
App.instance.getMDIContext().setMessage("4", |
|
150 |
"Area = " + |
|
151 |
nf.format(changeToUnits(returnArea( |
|
152 |
getMapContext().toMapPoint(m_medidaLast))))); |
|
153 |
} catch (Exception e) { |
|
154 |
} |
|
155 |
|
|
156 |
} |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
repaint(); |
|
161 |
} |
|
162 |
} |
|
163 |
*/ |
|
164 |
} |
|
165 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/PanListenerImpl.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
4 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
|
5 |
import com.iver.cit.gvsig.fmap.tools.Listeners.MoveListener; |
|
6 |
|
|
7 |
import java.awt.geom.Point2D; |
|
8 |
import java.awt.geom.Rectangle2D; |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* DOCUMENT ME! |
|
13 |
* |
|
14 |
* @author Vicente Caballero Navarro |
|
15 |
*/ |
|
16 |
public class PanListenerImpl implements MoveListener { |
|
17 |
ViewPort vp; |
|
18 |
|
|
19 |
/** |
|
20 |
* Crea un nuevo RectangleListenerImpl. |
|
21 |
* |
|
22 |
* @param vp DOCUMENT ME! |
|
23 |
*/ |
|
24 |
public PanListenerImpl(ViewPort vp) { |
|
25 |
this.vp = vp; |
|
26 |
} |
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.MoveListener#move(java.awt.geom.Point2D, java.awt.geom.Point2D) |
|
31 |
*/ |
|
32 |
public void move(MoveEvent event) { |
|
33 |
Point2D from=vp.toMapPoint(event.getFrom()); |
|
34 |
Point2D to=vp.toMapPoint(event.getTo()); |
|
35 |
|
|
36 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
37 |
Rectangle2D extent = vp.getExtent(); |
|
38 |
r.x = extent.getX() - (to.getX() - from.getX()); |
|
39 |
r.y = extent.getY() - (to.getY() - from.getY()); |
|
40 |
r.width = extent.getWidth(); |
|
41 |
r.height = extent.getHeight(); |
|
42 |
vp.setExtent(r); |
|
43 |
} |
|
44 |
} |
|
0 | 45 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/Listeners/MeasureListener.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.Listeners; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent; |
|
4 |
|
|
5 |
/** |
|
6 |
* DOCUMENT ME! |
|
7 |
* |
|
8 |
* @author Vicente Caballero Navarro |
|
9 |
*/ |
|
10 |
public interface MeasureListener extends ToolListener { |
|
11 |
/** |
|
12 |
* DOCUMENT ME! |
|
13 |
*/ |
|
14 |
public void points(MeasureEvent event); |
|
15 |
} |
|
0 | 16 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/Listeners/RectangleListener.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.Listeners; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
4 |
|
|
5 |
/** |
|
6 |
* DOCUMENT ME! |
|
7 |
* |
|
8 |
* @author Vicente Caballero Navarro |
|
9 |
*/ |
|
10 |
public interface RectangleListener extends ToolListener { |
|
11 |
/** |
|
12 |
* DOCUMENT ME! |
|
13 |
* |
|
14 |
* @param event DOCUMENT ME! |
|
15 |
*/ |
|
16 |
public void rectangle(RectangleEvent event); |
|
17 |
} |
|
0 | 18 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/Listeners/MoveListener.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.Listeners; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* DOCUMENT ME! |
|
8 |
* |
|
9 |
* @author Vicente Caballero Navarro |
|
10 |
*/ |
|
11 |
public interface MoveListener extends ToolListener { |
|
12 |
/** |
|
13 |
* DOCUMENT ME! |
|
14 |
* |
|
15 |
* @param from DOCUMENT ME! |
|
16 |
* @param to DOCUMENT ME! |
|
17 |
*/ |
|
18 |
public void move(MoveEvent event); |
|
19 |
} |
|
0 | 20 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/Listeners/PointListener.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.Listeners; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
|
4 |
|
|
5 |
/** |
|
6 |
* DOCUMENT ME! |
|
7 |
* |
|
8 |
* @author Vicente Caballero Navarro |
|
9 |
*/ |
|
10 |
public interface PointListener extends ToolListener { |
|
11 |
/** |
|
12 |
* DOCUMENT ME! |
|
13 |
* |
|
14 |
* @param event DOCUMENT ME! |
|
15 |
*/ |
|
16 |
public void point(PointEvent event); |
|
17 |
} |
|
0 | 18 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/Listeners/ToolListener.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.Listeners; |
|
2 |
|
|
3 |
/** |
|
4 |
* DOCUMENT ME! |
|
5 |
* |
|
6 |
* @author Vicente Caballero Navarro |
|
7 |
*/ |
|
8 |
public interface ToolListener { |
|
9 |
} |
|
0 | 10 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MeasureListenerImpl.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
4 |
import com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent; |
|
5 |
import com.iver.cit.gvsig.fmap.tools.Listeners.MeasureListener; |
|
6 |
|
|
7 |
import java.awt.Point; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* DOCUMENT ME! |
|
12 |
* |
|
13 |
* @author Vicente Caballero Navarro |
|
14 |
*/ |
|
15 |
public class MeasureListenerImpl implements MeasureListener { |
|
16 |
ViewPort vp; |
|
17 |
|
|
18 |
/** |
|
19 |
* Crea un nuevo MeasureListenerImpl. |
|
20 |
* |
|
21 |
* @param vp DOCUMENT ME! |
|
22 |
*/ |
|
23 |
public MeasureListenerImpl(ViewPort vp) { |
|
24 |
this.vp = vp; |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* DOCUMENT ME! |
|
29 |
* |
|
30 |
* @param event DOCUMENT ME! |
|
31 |
*/ |
|
32 |
public void points(MeasureEvent event) { |
|
33 |
double dist = 0; |
|
34 |
double distAll = 0; |
|
35 |
|
|
36 |
for (int i = 0; i < (event.getXs().length - 1); i++) { |
|
37 |
dist = 0; |
|
38 |
|
|
39 |
Point p = new Point(event.getXs()[i].intValue(), |
|
40 |
event.getXs()[i].intValue()); |
|
41 |
Point p2 = new Point(event.getXs()[i + 1].intValue(), |
|
42 |
event.getXs()[i + 1].intValue()); |
|
43 |
dist = vp.toMapDistance((int) p.distance(p2)); |
|
44 |
distAll += dist; |
|
45 |
} |
|
46 |
|
|
47 |
System.out.println("Distancia = " + dist + " Distancia Total = " + |
|
48 |
(distAll)); |
|
49 |
} |
|
50 |
} |
|
0 | 51 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MapTools/MapTool.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 28-oct-2004 |
|
3 |
*/ |
|
4 |
package com.iver.cit.gvsig.fmap.tools.MapTools; |
|
5 |
|
|
6 |
import java.awt.Cursor; |
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.event.MouseEvent; |
|
9 |
import java.awt.event.MouseListener; |
|
10 |
import java.awt.event.MouseMotionListener; |
|
11 |
import java.awt.event.MouseWheelEvent; |
|
12 |
import java.awt.event.MouseWheelListener; |
|
13 |
import java.awt.image.BufferedImage; |
|
14 |
|
|
15 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
|
16 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
17 |
|
|
18 |
/** |
|
19 |
* Herramienta del MapControl. |
|
20 |
* Ejecuta acciones respondiendo a eventos, por delegaci?n desde MapControl. |
|
21 |
* |
|
22 |
* @author Luis W. Sevilla <sevilla_lui@gva.es> |
|
23 |
*/ |
|
24 |
public abstract class MapTool implements MouseWheelListener, MouseListener, MouseMotionListener { |
|
25 |
private NewMapControl mapControl; |
|
26 |
private Cursor cursor; |
|
27 |
|
|
28 |
public abstract void setListener(ToolListener listener); |
|
29 |
|
|
30 |
/** |
|
31 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#paintComponent(java.awt.Graphics) |
|
32 |
*/ |
|
33 |
public void paintComponent(Graphics g) { |
|
34 |
BufferedImage img = getMapControl().getImage(); |
|
35 |
|
|
36 |
g.drawImage(img, 0, 0, null); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
public void setCursor(Cursor c){ |
|
41 |
cursor = c; |
|
42 |
} |
|
43 |
|
|
44 |
public void setMapControl(NewMapControl mc){ |
|
45 |
mapControl = mc; |
|
46 |
} |
|
47 |
|
|
48 |
public Cursor getCursor(){ |
|
49 |
return cursor; |
|
50 |
} |
|
51 |
|
|
52 |
public NewMapControl getMapControl(){ |
|
53 |
return mapControl; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) |
|
58 |
*/ |
|
59 |
public void mouseClicked(MouseEvent e){ |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) |
|
65 |
*/ |
|
66 |
public void mouseEntered(MouseEvent e){ |
|
67 |
|
|
68 |
} |
|
69 |
/** |
|
70 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) |
|
71 |
*/ |
|
72 |
public void mouseExited(MouseEvent e){ |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
78 |
*/ |
|
79 |
public void mousePressed(MouseEvent e){ |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
85 |
*/ |
|
86 |
public void mouseReleased(MouseEvent e){ |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
92 |
*/ |
|
93 |
public void mouseDragged(MouseEvent e){ |
|
94 |
|
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) |
|
99 |
*/ |
|
100 |
public void mouseMoved(MouseEvent e){ |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent) |
|
106 |
*/ |
|
107 |
public void mouseWheelMoved(MouseWheelEvent e){ |
|
108 |
|
|
109 |
} |
|
110 |
} |
|
0 | 111 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MapTools/MeasureMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.MapTools; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
4 |
import com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent; |
|
5 |
import com.iver.cit.gvsig.fmap.tools.Listeners.MeasureListener; |
|
6 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
7 |
|
|
8 |
import java.awt.Color; |
|
9 |
import java.awt.Cursor; |
|
10 |
import java.awt.Graphics; |
|
11 |
import java.awt.Graphics2D; |
|
12 |
import java.awt.Image; |
|
13 |
import java.awt.Point; |
|
14 |
import java.awt.Toolkit; |
|
15 |
import java.awt.event.MouseEvent; |
|
16 |
|
|
17 |
import java.util.ArrayList; |
|
18 |
|
|
19 |
import javax.swing.ImageIcon; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* Medici?n de distancias. |
|
24 |
* |
|
25 |
* @author Vicente Caballero Navarro |
|
26 |
*/ |
|
27 |
public class MeasureMapTool extends MapTool { |
|
28 |
private static final Image izoomin = new ImageIcon( |
|
29 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
30 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
31 |
new Point(16, 16), ""); |
|
32 |
protected ArrayList arrayX = new ArrayList(); |
|
33 |
protected ArrayList arrayY = new ArrayList(); |
|
34 |
protected boolean isClicked = false; |
|
35 |
protected MeasureListener listener; |
|
36 |
|
|
37 |
/** |
|
38 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#paintComponent(java.awt.Graphics) |
|
39 |
*/ |
|
40 |
public void paintComponent(Graphics g) { |
|
41 |
g.drawImage(getMapControl().getImage(), 0, 0, null); |
|
42 |
g.setColor(Color.black); |
|
43 |
|
|
44 |
if (!arrayX.isEmpty()) { |
|
45 |
drawPolyLine((Graphics2D) g); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#getCursor() |
|
51 |
*/ |
|
52 |
public Cursor getCursor() { |
|
53 |
return cur; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* DOCUMENT ME! |
|
58 |
* |
|
59 |
* @param E DOCUMENT ME! |
|
60 |
*/ |
|
61 |
public void mouseClicked(MouseEvent E) { |
|
62 |
if (E.getClickCount() == 2) { |
|
63 |
arrayX.clear(); |
|
64 |
arrayY.clear(); |
|
65 |
isClicked = false; |
|
66 |
} else { |
|
67 |
isClicked = true; |
|
68 |
addPoint(E.getPoint()); |
|
69 |
|
|
70 |
if (arrayX.size() < 2) { |
|
71 |
addPoint(E.getPoint()); |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* DOCUMENT ME! |
|
78 |
* |
|
79 |
* @param p DOCUMENT ME! |
|
80 |
*/ |
|
81 |
protected void changeLastPoint(Point p) { |
|
82 |
arrayX.set(arrayX.size() - 1, new Double(p.getX())); |
|
83 |
arrayY.set(arrayY.size() - 1, new Double(p.getY())); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* DOCUMENT ME! |
|
88 |
* |
|
89 |
* @param E DOCUMENT ME! |
|
90 |
*/ |
|
91 |
public void mouseMoved(MouseEvent E) { |
|
92 |
if (isClicked) { |
|
93 |
changeLastPoint(E.getPoint()); |
|
94 |
|
|
95 |
MeasureEvent event = new MeasureEvent((Double[]) arrayX.toArray( |
|
96 |
new Double[0]), (Double[]) arrayX.toArray(new Double[0])); |
|
97 |
listener.points(event); |
|
98 |
getMapControl().repaint(); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* DOCUMENT ME! |
|
104 |
* |
|
105 |
* @param g2 DOCUMENT ME! |
|
106 |
*/ |
|
107 |
protected void drawPolyLine(Graphics2D g2) { |
|
108 |
GeneralPathX polyline = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, |
|
109 |
arrayX.size()); |
|
110 |
|
|
111 |
polyline.moveTo(((Double) arrayX.get(0)).doubleValue(), |
|
112 |
((Double) arrayY.get(0)).doubleValue()); |
|
113 |
|
|
114 |
for (int index = 1; index < arrayX.size(); index++) { |
|
115 |
polyline.lineTo(((Double) arrayX.get(index)).doubleValue(), |
|
116 |
((Double) arrayY.get(index)).doubleValue()); |
|
117 |
} |
|
118 |
|
|
119 |
g2.draw(polyline); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* DOCUMENT ME! |
|
124 |
* |
|
125 |
* @param p DOCUMENT ME! |
|
126 |
*/ |
|
127 |
protected void addPoint(Point p) { |
|
128 |
arrayX.add(new Double(p.x)); |
|
129 |
arrayY.add(new Double(p.y)); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener) |
|
134 |
*/ |
|
135 |
public void setListener(ToolListener listener) { |
|
136 |
this.listener = (MeasureListener) listener; |
|
137 |
} |
|
138 |
} |
|
0 | 139 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MapTools/RectangleMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.MapTools; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Cursor; |
|
5 |
import java.awt.Graphics; |
|
6 |
import java.awt.Image; |
|
7 |
import java.awt.Point; |
|
8 |
import java.awt.Rectangle; |
|
9 |
import java.awt.Toolkit; |
|
10 |
import java.awt.event.MouseEvent; |
|
11 |
import java.awt.geom.Point2D; |
|
12 |
import java.awt.geom.Rectangle2D; |
|
13 |
import java.awt.image.BufferedImage; |
|
14 |
|
|
15 |
import javax.swing.ImageIcon; |
|
16 |
|
|
17 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
18 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
19 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
20 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
21 |
|
|
22 |
|
|
23 |
/** |
|
24 |
* Zoom in. |
|
25 |
* |
|
26 |
* @author Vicente Caballero Navarro |
|
27 |
*/ |
|
28 |
public class RectangleMapTool extends MapTool { |
|
29 |
private static final Image izoomin = new ImageIcon( |
|
30 |
"file://C:/workspace/FMAP/src/com/iver/cit/gvsig/fmap/images/MagnifyCursor.gif").getImage(); |
|
31 |
private static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, |
|
32 |
new Point(16, 16), ""); |
|
33 |
private Point2D m_FirstPoint; |
|
34 |
private Point2D m_LastPoint; |
|
35 |
private Point2D m_PointAnt; |
|
36 |
|
|
37 |
private RectangleListener listener; |
|
38 |
|
|
39 |
/** |
|
40 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#paintComponent(java.awt.Graphics) |
|
41 |
*/ |
|
42 |
public void paintComponent(Graphics g) { |
|
43 |
g.setColor(Color.white); |
|
44 |
g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight()); |
|
45 |
|
|
46 |
BufferedImage img = getMapControl().getImage(); |
|
47 |
g.drawImage(img, 0, 0, null); |
|
48 |
g.setColor(Color.black); |
|
49 |
g.setXORMode(Color.white); |
|
50 |
|
|
51 |
// Borramos el anterior |
|
52 |
Rectangle r = new Rectangle(); |
|
53 |
|
|
54 |
// Dibujamos el actual |
|
55 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
|
56 |
r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
|
57 |
g.drawRect(r.x, r.y, r.width, r.height); |
|
58 |
} |
|
59 |
|
|
60 |
getMapControl().repaint(); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#getCursor() |
|
65 |
*/ |
|
66 |
public Cursor getCursor() { |
|
67 |
return cur; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
72 |
*/ |
|
73 |
public void mousePressed(MouseEvent e) { |
|
74 |
Point pScreen = e.getPoint(); |
|
75 |
m_PointAnt = pScreen; |
|
76 |
m_FirstPoint = m_PointAnt; |
|
77 |
|
|
78 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
79 |
m_PointAnt = pScreen; |
|
80 |
m_FirstPoint = m_PointAnt; |
|
81 |
|
|
82 |
getMapControl().cancelDrawing(); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
88 |
*/ |
|
89 |
public void mouseReleased(MouseEvent e) { |
|
90 |
Point2D p1; |
|
91 |
Point2D p2; |
|
92 |
Point pScreen = e.getPoint(); |
|
93 |
|
|
94 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
95 |
|
|
96 |
p1 = vp.toMapPoint(m_FirstPoint); |
|
97 |
p2 = vp.toMapPoint(pScreen); |
|
98 |
|
|
99 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
100 |
|
|
101 |
// Fijamos el nuevo extent |
|
102 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
103 |
|
|
104 |
r.setFrameFromDiagonal(p1, p2); |
|
105 |
RectangleEvent event=new RectangleEvent(r); |
|
106 |
listener.rectangle(event); |
|
107 |
|
|
108 |
getMapControl().drawMap(); |
|
109 |
} |
|
110 |
|
|
111 |
m_FirstPoint = null; |
|
112 |
m_LastPoint = null; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
|
117 |
*/ |
|
118 |
public void mouseDragged(MouseEvent e) { |
|
119 |
m_LastPoint = e.getPoint(); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* @see com.iver.cit.gvsig.fmap.tools.MapTools.MapTool#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener) |
|
124 |
*/ |
|
125 |
public void setListener(ToolListener listener) { |
|
126 |
this.listener = (RectangleListener) listener; |
|
127 |
} |
|
128 |
|
|
129 |
} |
|
0 | 130 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/MapTools/MoveMapTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.tools.MapTools; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Cursor; |
|
5 |
import java.awt.Graphics; |
|
6 |
import java.awt.Image; |
|
7 |
import java.awt.Point; |
|
8 |
import java.awt.Toolkit; |
|
9 |
import java.awt.event.MouseEvent; |
|
10 |
import java.awt.geom.Point2D; |
|
11 |
|
|
12 |
import javax.swing.ImageIcon; |
|
13 |
|
|
14 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
|
15 |
import com.iver.cit.gvsig.fmap.tools.Listeners.MoveListener; |
Also available in: Unified diff