Revision 2894
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/georeferencing/GeoreferencingToolsModule.java | ||
---|---|---|
52 | 52 |
import com.iver.andami.plugins.Extension; |
53 | 53 |
import com.iver.cit.gvsig.LayoutControls; |
54 | 54 |
import com.iver.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
|
56 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
|
57 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior; |
|
58 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
|
59 | 55 |
import com.iver.cit.gvsig.gui.View; |
60 | 56 |
import com.iver.cit.gvsig.gui.layout.Layout; |
61 |
import com.iver.cit.gvsig.gui.toolListeners.GeorefPanListener; |
|
62 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
|
63 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomInGeorefListener; |
|
64 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomOutGeorefListener; |
|
65 | 57 |
|
66 | 58 |
|
67 | 59 |
/** |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/ZoomInGeorefListenerImpl.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.tools; |
|
42 |
|
|
43 |
import java.awt.Cursor; |
|
44 |
import java.awt.Image; |
|
45 |
import java.awt.Point; |
|
46 |
import java.awt.Toolkit; |
|
47 |
import java.awt.geom.Rectangle2D; |
|
48 |
|
|
49 |
import javax.swing.ImageIcon; |
|
50 |
|
|
51 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
52 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
53 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* Implementaci?n de la interfaz RectangleListener como herramienta para |
|
58 |
* realizar un zoom m?s en la imagen a georeferenciar. |
|
59 |
* |
|
60 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
61 |
*/ |
|
62 |
public class ZoomInGeorefListenerImpl implements RectangleListener { |
|
63 |
private static final Image izoomin = new ImageIcon(MapControl.class.getResource( |
|
64 |
"images/ZoomInCursor.gif")).getImage(); |
|
65 |
|
|
66 |
public static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, new Point(16, 16), ""); |
|
67 |
|
|
68 |
private MapControl mapCtrl; |
|
69 |
|
|
70 |
/** |
|
71 |
* Crea un nuevo RectangleListenerImpl. |
|
72 |
* |
|
73 |
* @param mapCtrl MapControl. |
|
74 |
*/ |
|
75 |
public ZoomInGeorefListenerImpl(MapControl mapCtrl) { |
|
76 |
this.mapCtrl = mapCtrl; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent) |
|
81 |
*/ |
|
82 |
public void rectangle(RectangleEvent event) { |
|
83 |
Rectangle2D rect = event.getWorldCoordRect(); |
|
84 |
Rectangle2D pixelRect = event.getPixelCoordRect(); |
|
85 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
90 |
*/ |
|
91 |
public Cursor getCursor() { |
|
92 |
return cur; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
97 |
*/ |
|
98 |
public boolean cancelDrawing() { |
|
99 |
System.out.println("cancelDrawing del ZoomOutListenerImpl"); |
|
100 |
return true; |
|
101 |
} |
|
102 |
} |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/ZoomOutGeorefListenerImpl.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.tools; |
|
42 |
|
|
43 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
44 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
45 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
|
46 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
|
47 |
|
|
48 |
import java.awt.Cursor; |
|
49 |
import java.awt.Image; |
|
50 |
import java.awt.Point; |
|
51 |
import java.awt.Toolkit; |
|
52 |
import java.awt.geom.Point2D; |
|
53 |
import java.awt.geom.Rectangle2D; |
|
54 |
|
|
55 |
import javax.swing.ImageIcon; |
|
56 |
|
|
57 |
|
|
58 |
/** |
|
59 |
* Implementaci?n de la interfaz PointListener como herramienta para realizar |
|
60 |
* un zoom menos. |
|
61 |
* |
|
62 |
* @author Vicente Caballero Navarro |
|
63 |
*/ |
|
64 |
public class ZoomOutGeorefListenerImpl implements PointListener { |
|
65 |
private final Image izoomout = new ImageIcon(MapControl.class.getResource( |
|
66 |
"images/ZoomOutCursor.gif")).getImage(); |
|
67 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomout, |
|
68 |
new Point(16, 16), ""); |
|
69 |
private MapControl mapControl; |
|
70 |
|
|
71 |
/** |
|
72 |
* Crea un nuevo ZoomOutListenerImpl. |
|
73 |
* |
|
74 |
* @param mapControl MapControl. |
|
75 |
*/ |
|
76 |
public ZoomOutGeorefListenerImpl(MapControl mapControl) { |
|
77 |
this.mapControl = mapControl; |
|
78 |
System.out.println("****ZOOMOUT"); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.PointEvent) |
|
83 |
*/ |
|
84 |
public void point(PointEvent event) { |
|
85 |
ViewPort vp = mapControl.getMapContext().getViewPort(); |
|
86 |
Point2D p2 = vp.toMapPoint(event.getPoint()); |
|
87 |
|
|
88 |
double nuevoX; |
|
89 |
double nuevoY; |
|
90 |
double factor = 1.8; |
|
91 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
92 |
|
|
93 |
nuevoX = p2.getX() - ((vp.getExtent().getWidth() * factor) / 2.0); |
|
94 |
nuevoY = p2.getY() - ((vp.getExtent().getHeight() * factor) / 2.0); |
|
95 |
r.x = nuevoX; |
|
96 |
r.y = nuevoY; |
|
97 |
r.width = vp.getExtent().getWidth() * factor; |
|
98 |
r.height = vp.getExtent().getHeight() * factor; |
|
99 |
|
|
100 |
vp.setExtent(r); |
|
101 |
|
|
102 |
// mapControl.drawMap(false); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
107 |
*/ |
|
108 |
public Cursor getCursor() { |
|
109 |
return cur; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
114 |
*/ |
|
115 |
public boolean cancelDrawing() { |
|
116 |
System.out.println("cancelDrawing del ZoomOutListenerImpl"); |
|
117 |
return true; |
|
118 |
} |
|
119 |
} |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/ZoomGeorefListenerImpl.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.tools; |
|
42 |
|
|
43 |
import java.awt.Cursor; |
|
44 |
import java.awt.Image; |
|
45 |
import java.awt.Point; |
|
46 |
import java.awt.Toolkit; |
|
47 |
import java.awt.geom.Rectangle2D; |
|
48 |
|
|
49 |
import javax.swing.ImageIcon; |
|
50 |
|
|
51 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
52 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
53 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* Implementaci?n de la interfaz RectangleListener como herramienta para |
|
58 |
* realizar un zoom m?s en la imagen a georeferenciar. |
|
59 |
* |
|
60 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
61 |
*/ |
|
62 |
public class ZoomGeorefListenerImpl implements RectangleListener { |
|
63 |
private static final Image izoomin = new ImageIcon(MapControl.class.getResource( |
|
64 |
"images/ZoomInCursor.gif")).getImage(); |
|
65 |
|
|
66 |
public static Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin, new Point(16, 16), ""); |
|
67 |
|
|
68 |
private MapControl mapCtrl; |
|
69 |
|
|
70 |
/** |
|
71 |
* Crea un nuevo RectangleListenerImpl. |
|
72 |
* |
|
73 |
* @param mapCtrl MapControl. |
|
74 |
*/ |
|
75 |
public ZoomGeorefListenerImpl(MapControl mapCtrl) { |
|
76 |
this.mapCtrl = mapCtrl; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent) |
|
81 |
*/ |
|
82 |
public void rectangle(RectangleEvent event) { |
|
83 |
Rectangle2D rect = event.getWorldCoordRect(); |
|
84 |
Rectangle2D pixelRect = event.getPixelCoordRect(); |
|
85 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
90 |
*/ |
|
91 |
public Cursor getCursor() { |
|
92 |
return cur; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
97 |
*/ |
|
98 |
public boolean cancelDrawing() { |
|
99 |
System.out.println("cancelDrawing del ZoomOutListenerImpl"); |
|
100 |
return true; |
|
101 |
} |
|
102 |
} |
|
0 | 103 |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/GeorefPanListenerImpl.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.fmap.tools; |
42 | 42 |
|
43 |
import com.hardcode.driverManager.DriverLoadException; |
|
44 |
import com.iver.andami.messages.NotificationManager; |
|
43 | 45 |
import com.iver.cit.gvsig.fmap.MapControl; |
44 | 46 |
import com.iver.cit.gvsig.fmap.ViewPort; |
47 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
48 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
49 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
50 |
import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
|
51 |
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter; |
|
45 | 52 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
46 | 53 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener; |
47 | 54 |
|
... | ... | |
51 | 58 |
import java.awt.Toolkit; |
52 | 59 |
import java.awt.geom.Point2D; |
53 | 60 |
import java.awt.geom.Rectangle2D; |
61 |
import java.io.File; |
|
54 | 62 |
|
55 | 63 |
import javax.swing.ImageIcon; |
56 | 64 |
|
65 |
import org.cresques.io.GeoRasterFile; |
|
66 |
import org.cresques.px.Extent; |
|
57 | 67 |
|
68 |
|
|
58 | 69 |
/** |
59 | 70 |
* Implementaci?n de la interfaz MoveListener como herramienta para realizar el |
60 | 71 |
* Pan. |
... | ... | |
63 | 74 |
*/ |
64 | 75 |
public class GeorefPanListenerImpl implements PanListener { |
65 | 76 |
private final Image ipan = new ImageIcon(MapControl.class.getResource( |
66 |
"images/Hand.gif")).getImage();
|
|
77 |
"images/CruxCursor.png")).getImage();
|
|
67 | 78 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(ipan, |
68 | 79 |
new Point(16, 16), ""); |
69 | 80 |
private MapControl mapControl; |
81 |
private FLyrRaster lyrRaster = null; |
|
82 |
private String pathToFile = null; |
|
83 |
|
|
70 | 84 |
|
71 | 85 |
/** |
72 | 86 |
* Crea un nuevo RectangleListenerImpl. |
... | ... | |
96 | 110 |
r.height = extent.getHeight(); |
97 | 111 |
vp.setExtent(r); |
98 | 112 |
|
113 |
|
|
99 | 114 |
// mapControl.drawMap(); |
100 | 115 |
} |
101 | 116 |
|
... | ... | |
112 | 127 |
public boolean cancelDrawing() { |
113 | 128 |
return true; |
114 | 129 |
} |
130 |
|
|
131 |
/** |
|
132 |
* @return Returns the lyrRaster. |
|
133 |
*/ |
|
134 |
public FLyrRaster getLyrRaster() { |
|
135 |
return lyrRaster; |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* @param lyrRaster The lyrRaster to set. |
|
140 |
*/ |
|
141 |
public void setLyrRaster(FLyrRaster lyrRaster) { |
|
142 |
this.lyrRaster = lyrRaster; |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* @return Returns the pathToFile. |
|
147 |
*/ |
|
148 |
public String getPathToFile() { |
|
149 |
return pathToFile; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* @param pathToFile The pathToFile to set. |
|
154 |
*/ |
|
155 |
public void setPathToFile(String pathToFile) { |
|
156 |
this.pathToFile = pathToFile; |
|
157 |
} |
|
115 | 158 |
} |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/Behavior/RedimBehavior.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.tools.Behavior; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Cursor; |
|
45 |
import java.awt.Graphics; |
|
46 |
import java.awt.Image; |
|
47 |
import java.awt.Point; |
|
48 |
import java.awt.Rectangle; |
|
49 |
import java.awt.Toolkit; |
|
50 |
import java.awt.event.MouseEvent; |
|
51 |
import java.awt.geom.Point2D; |
|
52 |
import java.awt.geom.Rectangle2D; |
|
53 |
import java.awt.image.BufferedImage; |
|
54 |
import java.io.File; |
|
55 |
|
|
56 |
import javax.swing.ImageIcon; |
|
57 |
|
|
58 |
import org.cresques.io.GeoRasterFile; |
|
59 |
import org.cresques.px.Extent; |
|
60 |
|
|
61 |
import com.hardcode.driverManager.DriverLoadException; |
|
62 |
import com.iver.andami.messages.NotificationManager; |
|
63 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
64 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
65 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
66 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
67 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
68 |
import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
|
69 |
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter; |
|
70 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
71 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
72 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
73 |
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
|
74 |
|
|
75 |
|
|
76 |
/** |
|
77 |
* Behaviour que espera un listener de tipo RedimListener. |
|
78 |
* Nacho Brodin (brodin_ign@gva.es) |
|
79 |
* |
|
80 |
*/ |
|
81 |
public class RedimBehavior extends Behavior { |
|
82 |
private RectangleListener listener; |
|
83 |
private Cursor cur = null; |
|
84 |
|
|
85 |
private final Image iconHoriz = new ImageIcon(MapControl.class.getResource( |
|
86 |
"images/FlechaHorizCursor.gif")).getImage(); |
|
87 |
private final Image iconVert = new ImageIcon(MapControl.class.getResource( |
|
88 |
"images/FlechaVertCursor.gif")).getImage(); |
|
89 |
private final Image iconInclDer = new ImageIcon(MapControl.class.getResource( |
|
90 |
"images/FlechaInclDerCursor.gif")).getImage(); |
|
91 |
private final Image iconInclIzq = new ImageIcon(MapControl.class.getResource( |
|
92 |
"images/FlechaInclIzqCursor.gif")).getImage(); |
|
93 |
private final Image defaultCursor = new ImageIcon(MapControl.class.getResource( |
|
94 |
"images/ZoomInCursor.gif")).getImage(); |
|
95 |
|
|
96 |
private final int WIDTH_BORDER = 25; |
|
97 |
private final int LONG_CORNER = 35; |
|
98 |
|
|
99 |
/** |
|
100 |
* Cada elemento del vector corresponde a un tipo de icono que |
|
101 |
* estar? a true si est? activo y a false si no lo est?. |
|
102 |
* horizontal, vertical, inclinado derecha, inclinado izquierda |
|
103 |
*/ |
|
104 |
private boolean[] iconActive = {false, false, false, false}; |
|
105 |
|
|
106 |
private Point2D ul = null; |
|
107 |
private Point2D lr = null; |
|
108 |
private Point2D tmpUl = null; |
|
109 |
private Point2D tmpLr = null; |
|
110 |
|
|
111 |
/** |
|
112 |
* Cada elemento corresponde a la acivaci?n de redimensionado en una |
|
113 |
* direcci?n que estar? activa a true. |
|
114 |
* vertical derecha, vertical izquierda, horizontal arriba, horizontal abajo, |
|
115 |
* inclinado |
|
116 |
*/ |
|
117 |
private boolean[] redimActive = new boolean[5]; |
|
118 |
|
|
119 |
private Point2D pointInit = null; |
|
120 |
private Rectangle2D rectInit = null; |
|
121 |
|
|
122 |
private FLyrRaster lyrRaster = null; |
|
123 |
private String pathToFile = null; |
|
124 |
|
|
125 |
/** |
|
126 |
* Crea un nuevo RectangleBehavior. |
|
127 |
* |
|
128 |
* @param zili listener. |
|
129 |
*/ |
|
130 |
public RedimBehavior(RectangleListener zili) { |
|
131 |
listener = zili; |
|
132 |
for(int i=0; i<redimActive.length;i++) |
|
133 |
redimActive[i] = false; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Cuando se produce un evento de pintado dibujamos el marco de la imagen para |
|
138 |
* que el usuario pueda seleccionar y redimensionar. |
|
139 |
*/ |
|
140 |
public void paintComponent(Graphics g) { |
|
141 |
|
|
142 |
BufferedImage img = getMapControl().getImage(); |
|
143 |
g.drawImage(img, 0, 0, null); |
|
144 |
g.setColor(Color.red); |
|
145 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
146 |
|
|
147 |
Rectangle r = new Rectangle(); |
|
148 |
|
|
149 |
if(tmpLr == null || tmpUl == null){ |
|
150 |
ul = vp.fromMapPoint(this.lyrRaster.getMinX(), this.lyrRaster.getMinY()); |
|
151 |
lr = vp.fromMapPoint(this.lyrRaster.getMaxX(), this.lyrRaster.getMaxY()); |
|
152 |
r.setFrameFromDiagonal(ul, lr); |
|
153 |
}else |
|
154 |
r.setFrameFromDiagonal(tmpUl, tmpLr); |
|
155 |
|
|
156 |
g.drawRect(r.x, r.y, r.width, r.height); |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Reimplementaci?n del m?todo mousePressed de Behavior. Cuando se pulsa |
|
162 |
* estando sobre el marco de la imagen activamos la posibilidad de arrastrar |
|
163 |
* para redimensionar la imagen. |
|
164 |
* |
|
165 |
* @param e MouseEvent |
|
166 |
*/ |
|
167 |
public void mousePressed(MouseEvent e) { |
|
168 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
169 |
tmpUl = ul; |
|
170 |
tmpLr = lr; |
|
171 |
if(iconActive[0]){//Estirar en horizontal activado |
|
172 |
if(e.getX() > (tmpLr.getX() - WIDTH_BORDER) && e.getX() < tmpLr.getX()) |
|
173 |
redimActive[0] = true; |
|
174 |
if(e.getX() < (tmpUl.getX() + WIDTH_BORDER) && e.getX() > tmpUl.getX()) |
|
175 |
redimActive[1] = true; |
|
176 |
} |
|
177 |
if(iconActive[1]){//Estirar en vertical activado |
|
178 |
if(e.getY() < (tmpLr.getY() + WIDTH_BORDER) && e.getY() > tmpLr.getY()) |
|
179 |
redimActive[3] = true; |
|
180 |
if(e.getY() > (tmpUl.getY() - WIDTH_BORDER) && e.getY() < tmpUl.getY()) |
|
181 |
redimActive[2] = true; |
|
182 |
} |
|
183 |
if(iconActive[2] || iconActive[3]){ //Estirar en oblicuo activado |
|
184 |
redimActive[4] = true; |
|
185 |
pointInit = e.getPoint(); |
|
186 |
rectInit = new Rectangle2D.Double(tmpUl.getX(), tmpUl.getY(), tmpLr.getX() - tmpUl.getX(), tmpLr.getY() - tmpUl.getY()); |
|
187 |
} |
|
188 |
|
|
189 |
} |
|
190 |
|
|
191 |
if (listener.cancelDrawing()) { |
|
192 |
getMapControl().cancelDrawing(); |
|
193 |
} |
|
194 |
|
|
195 |
getMapControl().repaint(); |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Reimplementaci?n del m?todo mouseReleased de Behavior. Desactivamos |
|
200 |
* los flags de redimensionado y a partir de la selecci?n del usuario |
|
201 |
* creamos un nuevo extent para la imagen. Con este extent creamos una nueva |
|
202 |
* capa que sustituir? a la anterior. |
|
203 |
* |
|
204 |
* @param e MouseEvent |
|
205 |
* |
|
206 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior. |
|
207 |
*/ |
|
208 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
209 |
|
|
210 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
211 |
//Desactivamos los flags de redimensionado |
|
212 |
for(int i=0;i<redimActive.length;i++) |
|
213 |
redimActive[i] = false; |
|
214 |
//Asignamos el nuevo extent a la imagen |
|
215 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
216 |
Extent ext = new Extent(vp.toMapPoint((int)tmpUl.getX(), (int)tmpUl.getY()).getX(), |
|
217 |
vp.toMapPoint((int)tmpUl.getX(), (int)tmpUl.getY()).getY(), |
|
218 |
vp.toMapPoint((int)tmpLr.getX(), (int)tmpLr.getY()).getX(), |
|
219 |
vp.toMapPoint((int)tmpLr.getX(), (int)tmpLr.getY()).getY()); |
|
220 |
|
|
221 |
if(this.pathToFile != null && this.lyrRaster != null){ |
|
222 |
File fich = new File(this.pathToFile); |
|
223 |
RasterAdapter adapter = new RasterFileAdapter(fich); |
|
224 |
try{ |
|
225 |
adapter.setDriver(LayerFactory.getDM().getDriver("gvSIG Image Driver")); |
|
226 |
}catch(DriverLoadException exc){ |
|
227 |
NotificationManager.addError("No se pudo acceder a los drivers", exc); |
|
228 |
} |
|
229 |
FLyrRaster capa = new FLyrRaster(); |
|
230 |
if (capa != null) { |
|
231 |
capa.setName(lyrRaster.getName()); |
|
232 |
capa.setSource(adapter); |
|
233 |
capa.setProjection(lyrRaster.getProjection()); |
|
234 |
capa.setTempExtent(ext); |
|
235 |
capa.setExtentFlag(GeoRasterFile.ASSIGNED_EXTENT); |
|
236 |
try { |
|
237 |
capa.load(); |
|
238 |
} catch (DriverIOException exc) { |
|
239 |
|
|
240 |
} |
|
241 |
capa.setVisible(true); |
|
242 |
} |
|
243 |
|
|
244 |
getMapControl().getMapContext().getLayers().removeLayer(lyrRaster.getName()); |
|
245 |
lyrRaster = null; |
|
246 |
getMapControl().getMapContext().getLayers().addLayer(capa); |
|
247 |
this.setLyrRaster(capa); |
|
248 |
getMapControl().repaint(); |
|
249 |
tmpUl = null; |
|
250 |
tmpLr = null; |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* Al arrastrar cuando se ha pulsado sobre el marco de la imagen recalculamos |
|
259 |
* el marco de la imagen |
|
260 |
* |
|
261 |
* @param e MouseEvent |
|
262 |
*/ |
|
263 |
public void mouseDragged(MouseEvent e) { |
|
264 |
double longLadoLargo = Math.abs(tmpLr.getX() - tmpUl.getX()); |
|
265 |
double longLadoCorto = Math.abs(tmpLr.getY() - tmpUl.getY()); |
|
266 |
|
|
267 |
if(redimActive[0]){//vertical derecha |
|
268 |
double newLadoLargo = (e.getX() - tmpUl.getX()); |
|
269 |
double newLadoCorto = (newLadoLargo * longLadoCorto) / longLadoLargo; |
|
270 |
double coordCentro = tmpLr.getY() + (Math.abs(tmpLr.getY() - tmpUl.getY()) / 2); |
|
271 |
tmpUl = new Point2D.Double(tmpUl.getX(), coordCentro + (newLadoCorto/2)); |
|
272 |
tmpLr = new Point2D.Double(e.getX(), coordCentro - (newLadoCorto/2)); |
|
273 |
} |
|
274 |
if(redimActive[1]){//vertical izquierda |
|
275 |
double newLadoLargo = (e.getX() - tmpLr.getX()); |
|
276 |
double newLadoCorto = (newLadoLargo * longLadoCorto) / longLadoLargo; |
|
277 |
double coordCentro = tmpLr.getY() + (Math.abs(tmpLr.getY() - tmpUl.getY()) / 2); |
|
278 |
tmpLr = new Point2D.Double(tmpLr.getX(), coordCentro + (newLadoCorto/2)); |
|
279 |
tmpUl = new Point2D.Double(e.getX(), coordCentro - (newLadoCorto/2)); |
|
280 |
} |
|
281 |
if(redimActive[2]){//horizontal abajo |
|
282 |
double newLadoCorto = (e.getY() - tmpLr.getY()); |
|
283 |
double newLadoLargo = (newLadoCorto * longLadoLargo) / longLadoCorto; |
|
284 |
double coordCentro = tmpLr.getX() - (Math.abs(tmpLr.getX() - tmpUl.getX()) / 2); |
|
285 |
tmpLr = new Point2D.Double(coordCentro + (newLadoLargo/2), tmpLr.getY()); |
|
286 |
tmpUl = new Point2D.Double(coordCentro - (newLadoLargo/2), e.getY()); |
|
287 |
} |
|
288 |
if(redimActive[3]){//horizontal arriba |
|
289 |
double newLadoCorto = (e.getY() - tmpUl.getY()); |
|
290 |
double newLadoLargo = (newLadoCorto * longLadoLargo) / longLadoCorto; |
|
291 |
double coordCentro = tmpLr.getX() - (Math.abs(tmpLr.getX() - tmpUl.getX()) / 2); |
|
292 |
tmpUl = new Point2D.Double(coordCentro + (newLadoLargo/2), tmpUl.getY()); |
|
293 |
tmpLr = new Point2D.Double(coordCentro - (newLadoLargo/2), e.getY()); |
|
294 |
} |
|
295 |
if(redimActive[4]){//inclinado |
|
296 |
double distX = (e.getX() - pointInit.getX()); |
|
297 |
double distY = (e.getY() - pointInit.getY()); |
|
298 |
double incrLadoLargo = 0D, incrLadoCorto = 0D; |
|
299 |
incrLadoLargo = distX; |
|
300 |
//Calculamos la distancia que incrementaremos al lado corto |
|
301 |
boolean ejeXLargo = true; |
|
302 |
if(longLadoCorto > longLadoLargo){ |
|
303 |
double tmp = longLadoLargo; |
|
304 |
longLadoLargo = longLadoCorto; |
|
305 |
longLadoCorto = tmp; |
|
306 |
ejeXLargo = false; |
|
307 |
} |
|
308 |
|
|
309 |
incrLadoCorto = (incrLadoLargo * longLadoCorto) / longLadoLargo; |
|
310 |
Point2D antUl = tmpUl; |
|
311 |
Point2D antLr = tmpLr; |
|
312 |
if(distX > 0 && e.getX() > lr.getX()){ |
|
313 |
tmpUl = new Point2D.Double(rectInit.getMinX() - Math.abs(incrLadoLargo), rectInit.getMinY() + Math.abs(incrLadoCorto)); |
|
314 |
tmpLr = new Point2D.Double(rectInit.getMaxX() + Math.abs(incrLadoLargo), rectInit.getMaxY() - Math.abs(incrLadoCorto)); |
|
315 |
}else if(distX < 0 && e.getX() < ul.getX()){ |
|
316 |
tmpUl = new Point2D.Double(rectInit.getMinX() - Math.abs(incrLadoLargo), rectInit.getMinY() + Math.abs(incrLadoCorto)); |
|
317 |
tmpLr = new Point2D.Double(rectInit.getMaxX() + Math.abs(incrLadoLargo), rectInit.getMaxY() - Math.abs(incrLadoCorto)); |
|
318 |
}else if(distX > 0 && e.getX() < lr.getX() && e.getX() > ul.getX()){ |
|
319 |
tmpUl = new Point2D.Double(rectInit.getMinX() + Math.abs(incrLadoLargo), rectInit.getMinY() - Math.abs(incrLadoCorto)); |
|
320 |
tmpLr = new Point2D.Double(rectInit.getMaxX() - Math.abs(incrLadoLargo), rectInit.getMaxY() + Math.abs(incrLadoCorto)); |
|
321 |
}else if(distX < 0 && e.getX() < lr.getX() && e.getX() > ul.getX()){ |
|
322 |
tmpUl = new Point2D.Double(rectInit.getMinX() + Math.abs(incrLadoLargo), rectInit.getMinY() - Math.abs(incrLadoCorto)); |
|
323 |
tmpLr = new Point2D.Double(rectInit.getMaxX() - Math.abs(incrLadoLargo), rectInit.getMaxY() + Math.abs(incrLadoCorto)); |
|
324 |
} |
|
325 |
//A partir de un tama?o m?nimo no reducimos m?s |
|
326 |
if((tmpLr.getX() - tmpUl.getX()) < 100 || (tmpUl.getY() - tmpLr.getY()) < 100){ |
|
327 |
tmpUl = antUl; |
|
328 |
tmpLr = antLr; |
|
329 |
} |
|
330 |
|
|
331 |
} |
|
332 |
|
|
333 |
getMapControl().repaint(); |
|
334 |
} |
|
335 |
|
|
336 |
/** |
|
337 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener) |
|
338 |
*/ |
|
339 |
public void setListener(ToolListener listener) { |
|
340 |
this.listener = (RectangleListener) listener; |
|
341 |
} |
|
342 |
|
|
343 |
/** |
|
344 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
|
345 |
*/ |
|
346 |
public ToolListener getListener() { |
|
347 |
return listener; |
|
348 |
} |
|
349 |
|
|
350 |
/** |
|
351 |
* Cuando movemos el rat?n detecta si estamos en el marco de la |
|
352 |
* imagen y pone el icono del cursor del rat?n adecuado. |
|
353 |
*/ |
|
354 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
355 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
356 |
double wcX = vp.toMapPoint(e.getX(), e.getY()).getX(); |
|
357 |
double wcY = vp.toMapPoint(e.getX(), e.getY()).getY(); |
|
358 |
int iconPosActive = -1; |
|
359 |
|
|
360 |
//Flecha horizontal |
|
361 |
if( ((wcX > lyrRaster.getMinX() && wcX < lyrRaster.getMinX() + WIDTH_BORDER) || |
|
362 |
(wcX < lyrRaster.getMaxX() && wcX > lyrRaster.getMaxX() - WIDTH_BORDER )) && |
|
363 |
(wcY < (lyrRaster.getMaxY() - LONG_CORNER)) && |
|
364 |
(wcY > (lyrRaster.getMinY() + LONG_CORNER))){ |
|
365 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, |
|
366 |
new Point(16, 16), "")); |
|
367 |
iconPosActive = 0; |
|
368 |
|
|
369 |
}else{ |
|
370 |
//Flecha Vertical |
|
371 |
if( ((wcY > lyrRaster.getMinY() && wcY < lyrRaster.getMinY() + WIDTH_BORDER) || |
|
372 |
(wcY < lyrRaster.getMaxY() && wcY > lyrRaster.getMaxY() - WIDTH_BORDER )) && |
|
373 |
(wcX < (lyrRaster.getMaxX() - LONG_CORNER)) && |
|
374 |
(wcX > (lyrRaster.getMinX() + LONG_CORNER))){ |
|
375 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconVert, |
|
376 |
new Point(16, 16), "")); |
|
377 |
iconPosActive = 1; |
|
378 |
}else{ |
|
379 |
//Flecha oblicua derecha |
|
380 |
if((wcX > (lyrRaster.getMaxX() - LONG_CORNER) && wcX < lyrRaster.getMaxX() && |
|
381 |
wcY < (lyrRaster.getMinY() + LONG_CORNER) && wcY > lyrRaster.getMinY()) || |
|
382 |
(wcX > lyrRaster.getMinX() && wcX < (lyrRaster.getMinX() + LONG_CORNER) && |
|
383 |
wcY < lyrRaster.getMaxY() && wcY > (lyrRaster.getMaxY() - LONG_CORNER))){ |
|
384 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconInclIzq, |
|
385 |
new Point(16, 16), "")); |
|
386 |
iconPosActive = 2; |
|
387 |
}else{ |
|
388 |
//Flecha oblicua izquierda |
|
389 |
if((wcX > lyrRaster.getMinX() && wcX < (lyrRaster.getMinX() + LONG_CORNER) && |
|
390 |
wcY < (lyrRaster.getMinY() + LONG_CORNER) && wcY > lyrRaster.getMinY()) || |
|
391 |
(wcX > (lyrRaster.getMaxX() - LONG_CORNER) && wcX < lyrRaster.getMaxX() && |
|
392 |
wcY > (lyrRaster.getMaxY() - LONG_CORNER) && wcY < lyrRaster.getMaxY())){ |
|
393 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconInclDer, |
|
394 |
new Point(16, 16), "")); |
|
395 |
iconPosActive = 3; |
|
396 |
}else{ |
|
397 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(defaultCursor, |
|
398 |
new Point(16, 16), "")); |
|
399 |
iconPosActive = -1; |
|
400 |
} |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
|
|
405 |
//Ponemos a true el incono activado y a false el resto |
|
406 |
for(int i=0;i<iconActive.length;i++){ |
|
407 |
if(i==iconPosActive) |
|
408 |
iconActive[i] = true; |
|
409 |
else |
|
410 |
iconActive[i] = false; |
|
411 |
} |
|
412 |
getMapControl().repaint(); |
|
413 |
} |
|
414 |
|
|
415 |
/** |
|
416 |
* @return Returns the lyrRaster. |
|
417 |
*/ |
|
418 |
public FLyrRaster getLyrRaster() { |
|
419 |
return lyrRaster; |
|
420 |
} |
|
421 |
|
|
422 |
/** |
|
423 |
* @param lyrRaster The lyrRaster to set. |
|
424 |
*/ |
|
425 |
public void setLyrRaster(FLyrRaster lyrRaster) { |
|
426 |
this.lyrRaster = lyrRaster; |
|
427 |
} |
|
428 |
|
|
429 |
/** |
|
430 |
* @return Returns the pathToFile. |
|
431 |
*/ |
|
432 |
public String getPathToFile() { |
|
433 |
return pathToFile; |
|
434 |
} |
|
435 |
|
|
436 |
/** |
|
437 |
* @param pathToFile The pathToFile to set. |
|
438 |
*/ |
|
439 |
public void setPathToFile(String pathToFile) { |
|
440 |
this.pathToFile = pathToFile; |
|
441 |
} |
|
442 |
} |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/Behavior/GeoRedimBehavior.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.tools.Behavior; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Cursor; |
|
45 |
import java.awt.Graphics; |
|
46 |
import java.awt.Image; |
|
47 |
import java.awt.Point; |
|
48 |
import java.awt.Rectangle; |
|
49 |
import java.awt.Toolkit; |
|
50 |
import java.awt.event.MouseEvent; |
|
51 |
import java.awt.geom.Point2D; |
|
52 |
import java.awt.geom.Rectangle2D; |
|
53 |
import java.awt.image.BufferedImage; |
|
54 |
import java.io.File; |
|
55 |
|
|
56 |
import javax.swing.ImageIcon; |
|
57 |
|
|
58 |
import org.cresques.io.GeoRasterFile; |
|
59 |
import org.cresques.px.Extent; |
|
60 |
|
|
61 |
import com.hardcode.driverManager.DriverLoadException; |
|
62 |
import com.iver.andami.messages.NotificationManager; |
|
63 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
64 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
65 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
66 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
67 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
68 |
import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
|
69 |
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter; |
|
70 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
71 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
72 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* Behaviour que espera un listener de tipo RedimListener. |
|
77 |
* Nacho Brodin (brodin_ign@gva.es) |
|
78 |
* |
|
79 |
*/ |
|
80 |
public class GeoRedimBehavior extends Behavior { |
|
81 |
private RectangleListener listener; |
|
82 |
private Cursor cur = null; |
|
83 |
|
|
84 |
private final Image iconHoriz = new ImageIcon(MapControl.class.getResource( |
|
85 |
"images/FlechaHorizCursor.gif")).getImage(); |
|
86 |
private final Image iconVert = new ImageIcon(MapControl.class.getResource( |
|
87 |
"images/FlechaVertCursor.gif")).getImage(); |
|
88 |
private final Image iconInclDer = new ImageIcon(MapControl.class.getResource( |
|
89 |
"images/FlechaInclDerCursor.gif")).getImage(); |
|
90 |
private final Image iconInclIzq = new ImageIcon(MapControl.class.getResource( |
|
91 |
"images/FlechaInclIzqCursor.gif")).getImage(); |
|
92 |
private final Image defaultCursor = new ImageIcon(MapControl.class.getResource( |
|
93 |
"images/ZoomInCursor.gif")).getImage(); |
|
94 |
|
|
95 |
private int WIDTH_BORDER = 25; |
|
96 |
private int LONG_CORNER = 35; |
|
97 |
|
|
98 |
/** |
|
99 |
* Cada elemento del vector corresponde a un tipo de icono que |
|
100 |
* estar? a true si est? activo y a false si no lo est?. |
|
101 |
* horizontal, vertical, inclinado derecha, inclinado izquierda |
|
102 |
*/ |
|
103 |
private boolean[] iconActive = {false, false, false, false}; |
|
104 |
|
|
105 |
private Point2D ul = null; |
|
106 |
private Point2D lr = null; |
|
107 |
private Point2D tmpUl = null; |
|
108 |
private Point2D tmpLr = null; |
|
109 |
|
|
110 |
/** |
|
111 |
* Cada elemento corresponde a la acivaci?n de redimensionado en una |
|
112 |
* direcci?n que estar? activa a true. |
|
113 |
* vertical derecha, vertical izquierda, horizontal arriba, horizontal abajo, |
|
114 |
* inclinado |
|
115 |
*/ |
|
116 |
private boolean[] redimActive = new boolean[5]; |
|
117 |
|
|
118 |
private Point2D pointInit = null; |
|
119 |
private Rectangle2D rectInit = null; |
|
120 |
|
|
121 |
private FLyrRaster lyrRaster = null; |
|
122 |
private String pathToFile = null; |
|
123 |
|
|
124 |
/** |
|
125 |
* Crea un nuevo RectangleBehavior. |
|
126 |
* |
|
127 |
* @param zili listener. |
|
128 |
*/ |
|
129 |
public GeoRedimBehavior(RectangleListener zili) { |
|
130 |
listener = zili; |
|
131 |
for(int i=0; i<redimActive.length;i++) |
|
132 |
redimActive[i] = false; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Cuando se produce un evento de pintado dibujamos el marco de la imagen para |
|
137 |
* que el usuario pueda seleccionar y redimensionar. |
|
138 |
*/ |
|
139 |
public void paintComponent(Graphics g) { |
|
140 |
|
|
141 |
BufferedImage img = getMapControl().getImage(); |
|
142 |
g.drawImage(img, 0, 0, null); |
|
143 |
g.setColor(Color.red); |
|
144 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
145 |
|
|
146 |
Rectangle r = new Rectangle(); |
|
147 |
|
|
148 |
if(tmpLr == null || tmpUl == null){ |
|
149 |
ul = vp.fromMapPoint(this.lyrRaster.getMinX(), this.lyrRaster.getMinY()); |
|
150 |
lr = vp.fromMapPoint(this.lyrRaster.getMaxX(), this.lyrRaster.getMaxY()); |
|
151 |
r.setFrameFromDiagonal(ul, lr); |
|
152 |
}else |
|
153 |
r.setFrameFromDiagonal(tmpUl, tmpLr); |
|
154 |
|
|
155 |
g.drawRect(r.x, r.y, r.width, r.height); |
|
156 |
|
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Reimplementaci?n del m?todo mousePressed de Behavior. Cuando se pulsa |
|
161 |
* estando sobre el marco de la imagen activamos la posibilidad de arrastrar |
|
162 |
* para redimensionar la imagen. |
|
163 |
* |
|
164 |
* @param e MouseEvent |
|
165 |
*/ |
|
166 |
public void mousePressed(MouseEvent e) { |
|
167 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
168 |
tmpUl = ul; |
|
169 |
tmpLr = lr; |
|
170 |
if(iconActive[0]){//Estirar en horizontal activado |
|
171 |
if(e.getX() > (tmpLr.getX() - WIDTH_BORDER) && e.getX() < tmpLr.getX()) |
|
172 |
redimActive[0] = true; |
|
173 |
if(e.getX() < (tmpUl.getX() + WIDTH_BORDER) && e.getX() > tmpUl.getX()) |
|
174 |
redimActive[1] = true; |
|
175 |
} |
|
176 |
if(iconActive[1]){//Estirar en vertical activado |
|
177 |
if(e.getY() < (tmpLr.getY() + WIDTH_BORDER) && e.getY() > tmpLr.getY()) |
|
178 |
redimActive[3] = true; |
|
179 |
if(e.getY() > (tmpUl.getY() - WIDTH_BORDER) && e.getY() < tmpUl.getY()) |
|
180 |
redimActive[2] = true; |
|
181 |
} |
|
182 |
if(iconActive[2] || iconActive[3]){ //Estirar en oblicuo activado |
|
183 |
redimActive[4] = true; |
|
184 |
pointInit = e.getPoint(); |
|
185 |
rectInit = new Rectangle2D.Double(tmpUl.getX(), tmpUl.getY(), tmpLr.getX() - tmpUl.getX(), tmpLr.getY() - tmpUl.getY()); |
|
186 |
} |
|
187 |
|
|
188 |
} |
|
189 |
|
|
190 |
if (listener.cancelDrawing()) { |
|
191 |
getMapControl().cancelDrawing(); |
|
192 |
} |
|
193 |
|
|
194 |
getMapControl().repaint(); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Reimplementaci?n del m?todo mouseReleased de Behavior. Desactivamos |
|
199 |
* los flags de redimensionado y a partir de la selecci?n del usuario |
|
200 |
* creamos un nuevo extent para la imagen. Con este extent creamos una nueva |
|
201 |
* capa que sustituir? a la anterior. |
|
202 |
* |
|
203 |
* @param e MouseEvent |
|
204 |
* |
|
205 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior. |
|
206 |
*/ |
|
207 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
208 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
209 |
//Desactivamos los flags de redimensionado |
|
210 |
for(int i=0;i<redimActive.length;i++) |
|
211 |
redimActive[i] = false; |
|
212 |
//Asignamos el nuevo extent a la imagen |
|
213 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
214 |
Extent ext = new Extent(vp.toMapPoint((int)tmpUl.getX(), (int)tmpUl.getY()).getX(), |
|
215 |
vp.toMapPoint((int)tmpUl.getX(), (int)tmpUl.getY()).getY(), |
|
216 |
vp.toMapPoint((int)tmpLr.getX(), (int)tmpLr.getY()).getX(), |
|
217 |
vp.toMapPoint((int)tmpLr.getX(), (int)tmpLr.getY()).getY()); |
|
218 |
|
|
219 |
if(this.pathToFile != null && this.lyrRaster != null){ |
|
220 |
File fich = new File(this.pathToFile); |
|
221 |
RasterAdapter adapter = new RasterFileAdapter(fich); |
|
222 |
try{ |
|
223 |
adapter.setDriver(LayerFactory.getDM().getDriver("gvSIG Image Driver")); |
|
224 |
}catch(DriverLoadException exc){ |
|
225 |
NotificationManager.addError("No se pudo acceder a los drivers", exc); |
|
226 |
} |
|
227 |
FLyrRaster capa = new FLyrRaster(); |
|
228 |
if (capa != null) { |
|
229 |
capa.setName(lyrRaster.getName()); |
|
230 |
capa.setSource(adapter); |
|
231 |
capa.setProjection(lyrRaster.getProjection()); |
|
232 |
capa.setTempExtent(ext); |
|
233 |
capa.setExtentFlag(GeoRasterFile.ASSIGNED_EXTENT); |
|
234 |
try { |
|
235 |
capa.load(); |
|
236 |
} catch (DriverIOException exc) { |
|
237 |
|
|
238 |
} |
|
239 |
capa.setVisible(true); |
|
240 |
} |
|
241 |
|
|
242 |
getMapControl().getMapContext().getLayers().removeLayer(lyrRaster.getName()); |
|
243 |
lyrRaster = null; |
|
244 |
getMapControl().getMapContext().getLayers().addLayer(capa); |
|
245 |
this.setLyrRaster(capa); |
|
246 |
getMapControl().repaint(); |
|
247 |
tmpUl = null; |
|
248 |
tmpLr = null; |
|
249 |
} |
|
250 |
} |
|
251 |
|
|
252 |
|
|
253 |
} |
|
254 |
|
|
255 |
/** |
|
256 |
* Al arrastrar cuando se ha pulsado sobre el marco de la imagen recalculamos |
|
257 |
* el marco de la imagen |
|
258 |
* |
|
259 |
* @param e MouseEvent |
|
260 |
*/ |
|
261 |
public void mouseDragged(MouseEvent e) { |
|
262 |
double longLadoLargo = Math.abs(tmpLr.getX() - tmpUl.getX()); |
|
263 |
double longLadoCorto = Math.abs(tmpLr.getY() - tmpUl.getY()); |
|
264 |
|
|
265 |
if(redimActive[0]){//vertical derecha |
|
266 |
System.out.println("Vertical derecha "+e.getPoint()); |
|
267 |
double newLadoLargo = (e.getX() - tmpUl.getX()); |
|
268 |
double newLadoCorto = (newLadoLargo * longLadoCorto) / longLadoLargo; |
|
269 |
double coordCentro = tmpLr.getY() + (Math.abs(tmpLr.getY() - tmpUl.getY()) / 2); |
|
270 |
tmpUl = new Point2D.Double(tmpUl.getX(), coordCentro + (newLadoCorto/2)); |
|
271 |
tmpLr = new Point2D.Double(e.getX(), coordCentro - (newLadoCorto/2)); |
|
272 |
} |
|
273 |
if(redimActive[1]){//vertical izquierda |
|
274 |
double newLadoLargo = (e.getX() - tmpLr.getX()); |
|
275 |
double newLadoCorto = (newLadoLargo * longLadoCorto) / longLadoLargo; |
|
276 |
double coordCentro = tmpLr.getY() + (Math.abs(tmpLr.getY() - tmpUl.getY()) / 2); |
|
277 |
tmpLr = new Point2D.Double(tmpLr.getX(), coordCentro + (newLadoCorto/2)); |
|
278 |
tmpUl = new Point2D.Double(e.getX(), coordCentro - (newLadoCorto/2)); |
|
279 |
} |
|
280 |
if(redimActive[2]){//horizontal abajo |
|
281 |
double newLadoCorto = (e.getY() - tmpLr.getY()); |
|
282 |
double newLadoLargo = (newLadoCorto * longLadoLargo) / longLadoCorto; |
|
283 |
double coordCentro = tmpLr.getX() - (Math.abs(tmpLr.getX() - tmpUl.getX()) / 2); |
|
284 |
tmpLr = new Point2D.Double(coordCentro + (newLadoLargo/2), tmpLr.getY()); |
|
285 |
tmpUl = new Point2D.Double(coordCentro - (newLadoLargo/2), e.getY()); |
|
286 |
} |
|
287 |
if(redimActive[3]){//horizontal arriba |
|
288 |
double newLadoCorto = (e.getY() - tmpUl.getY()); |
|
289 |
double newLadoLargo = (newLadoCorto * longLadoLargo) / longLadoCorto; |
|
290 |
double coordCentro = tmpLr.getX() - (Math.abs(tmpLr.getX() - tmpUl.getX()) / 2); |
|
291 |
tmpUl = new Point2D.Double(coordCentro + (newLadoLargo/2), tmpUl.getY()); |
|
292 |
tmpLr = new Point2D.Double(coordCentro - (newLadoLargo/2), e.getY()); |
|
293 |
} |
|
294 |
if(redimActive[4]){//inclinado |
|
295 |
double distX = (e.getX() - pointInit.getX()); |
|
296 |
double distY = (e.getY() - pointInit.getY()); |
|
297 |
double incrLadoLargo = 0D, incrLadoCorto = 0D; |
|
298 |
incrLadoLargo = distX; |
|
299 |
//Calculamos la distancia que incrementaremos al lado corto |
|
300 |
boolean ejeXLargo = true; |
|
301 |
if(longLadoCorto > longLadoLargo){ |
|
302 |
double tmp = longLadoLargo; |
|
303 |
longLadoLargo = longLadoCorto; |
|
304 |
longLadoCorto = tmp; |
|
305 |
ejeXLargo = false; |
|
306 |
} |
|
307 |
|
|
308 |
incrLadoCorto = (incrLadoLargo * longLadoCorto) / longLadoLargo; |
|
309 |
Point2D antUl = tmpUl; |
|
310 |
Point2D antLr = tmpLr; |
|
311 |
if(distX > 0 && e.getX() > lr.getX()){ |
|
312 |
tmpUl = new Point2D.Double(rectInit.getMinX() - Math.abs(incrLadoLargo), rectInit.getMinY() + Math.abs(incrLadoCorto)); |
|
313 |
tmpLr = new Point2D.Double(rectInit.getMaxX() + Math.abs(incrLadoLargo), rectInit.getMaxY() - Math.abs(incrLadoCorto)); |
|
314 |
}else if(distX < 0 && e.getX() < ul.getX()){ |
|
315 |
tmpUl = new Point2D.Double(rectInit.getMinX() - Math.abs(incrLadoLargo), rectInit.getMinY() + Math.abs(incrLadoCorto)); |
|
316 |
tmpLr = new Point2D.Double(rectInit.getMaxX() + Math.abs(incrLadoLargo), rectInit.getMaxY() - Math.abs(incrLadoCorto)); |
|
317 |
}else if(distX > 0 && e.getX() < lr.getX() && e.getX() > ul.getX()){ |
|
318 |
tmpUl = new Point2D.Double(rectInit.getMinX() + Math.abs(incrLadoLargo), rectInit.getMinY() - Math.abs(incrLadoCorto)); |
|
319 |
tmpLr = new Point2D.Double(rectInit.getMaxX() - Math.abs(incrLadoLargo), rectInit.getMaxY() + Math.abs(incrLadoCorto)); |
|
320 |
}else if(distX < 0 && e.getX() < lr.getX() && e.getX() > ul.getX()){ |
|
321 |
tmpUl = new Point2D.Double(rectInit.getMinX() + Math.abs(incrLadoLargo), rectInit.getMinY() - Math.abs(incrLadoCorto)); |
|
322 |
tmpLr = new Point2D.Double(rectInit.getMaxX() - Math.abs(incrLadoLargo), rectInit.getMaxY() + Math.abs(incrLadoCorto)); |
|
323 |
} |
|
324 |
//A partir de un tama?o m?nimo no reducimos m?s |
|
325 |
if((tmpLr.getX() - tmpUl.getX()) < 100 || (tmpUl.getY() - tmpLr.getY()) < 100){ |
|
326 |
tmpUl = antUl; |
|
327 |
tmpLr = antLr; |
|
328 |
} |
|
329 |
|
|
330 |
} |
|
331 |
|
|
332 |
getMapControl().repaint(); |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener) |
|
337 |
*/ |
|
338 |
public void setListener(ToolListener listener) { |
|
339 |
this.listener = (RectangleListener) listener; |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
|
344 |
*/ |
|
345 |
public ToolListener getListener() { |
|
346 |
return listener; |
|
347 |
} |
|
348 |
|
|
349 |
/** |
|
350 |
* Cuando movemos el rat?n detecta si estamos en el marco de la |
|
351 |
* imagen y pone el icono del cursor del rat?n adecuado. |
|
352 |
*/ |
|
353 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
354 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
355 |
double wcX = vp.toMapPoint(e.getX(), e.getY()).getX(); |
|
356 |
double wcY = vp.toMapPoint(e.getX(), e.getY()).getY(); |
|
357 |
WIDTH_BORDER = (int)((lyrRaster.getMaxX() - lyrRaster.getMinX()) * 0.01); |
|
358 |
LONG_CORNER = (int)((lyrRaster.getMaxX() - lyrRaster.getMinX()) * 0.02); |
|
359 |
|
|
360 |
int iconPosActive = -1; |
|
361 |
|
|
362 |
//Flecha horizontal |
|
363 |
if( ((wcX > lyrRaster.getMinX() && wcX < lyrRaster.getMinX() + WIDTH_BORDER) || |
|
364 |
(wcX < lyrRaster.getMaxX() && wcX > lyrRaster.getMaxX() - WIDTH_BORDER )) && |
|
365 |
(wcY < (lyrRaster.getMaxY() - LONG_CORNER)) && |
|
366 |
(wcY > (lyrRaster.getMinY() + LONG_CORNER))){ |
|
367 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, |
|
368 |
new Point(16, 16), "")); |
|
369 |
iconPosActive = 0; |
|
370 |
|
|
371 |
}else{ |
|
372 |
//Flecha Vertical |
|
373 |
if( ((wcY > lyrRaster.getMinY() && wcY < lyrRaster.getMinY() + WIDTH_BORDER) || |
|
374 |
(wcY < lyrRaster.getMaxY() && wcY > lyrRaster.getMaxY() - WIDTH_BORDER )) && |
|
375 |
(wcX < (lyrRaster.getMaxX() - LONG_CORNER)) && |
|
376 |
(wcX > (lyrRaster.getMinX() + LONG_CORNER))){ |
|
377 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconVert, |
|
378 |
new Point(16, 16), "")); |
|
379 |
iconPosActive = 1; |
|
380 |
}else{ |
|
381 |
//Flecha oblicua derecha |
|
382 |
if((wcX > (lyrRaster.getMaxX() - LONG_CORNER) && wcX < lyrRaster.getMaxX() && |
|
383 |
wcY < (lyrRaster.getMinY() + LONG_CORNER) && wcY > lyrRaster.getMinY()) || |
|
384 |
(wcX > lyrRaster.getMinX() && wcX < (lyrRaster.getMinX() + LONG_CORNER) && |
|
385 |
wcY < lyrRaster.getMaxY() && wcY > (lyrRaster.getMaxY() - LONG_CORNER))){ |
|
386 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconInclIzq, |
|
387 |
new Point(16, 16), "")); |
|
388 |
iconPosActive = 2; |
|
389 |
}else{ |
|
390 |
//Flecha oblicua izquierda |
|
391 |
if((wcX > lyrRaster.getMinX() && wcX < (lyrRaster.getMinX() + LONG_CORNER) && |
|
392 |
wcY < (lyrRaster.getMinY() + LONG_CORNER) && wcY > lyrRaster.getMinY()) || |
|
393 |
(wcX > (lyrRaster.getMaxX() - LONG_CORNER) && wcX < lyrRaster.getMaxX() && |
|
394 |
wcY > (lyrRaster.getMaxY() - LONG_CORNER) && wcY < lyrRaster.getMaxY())){ |
|
395 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconInclDer, |
|
396 |
new Point(16, 16), "")); |
|
397 |
iconPosActive = 3; |
|
398 |
}else{ |
|
399 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(defaultCursor, |
|
400 |
new Point(16, 16), "")); |
|
401 |
iconPosActive = -1; |
|
402 |
} |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
406 |
|
|
407 |
//Ponemos a true el incono activado y a false el resto |
|
408 |
for(int i=0;i<iconActive.length;i++){ |
|
409 |
if(i==iconPosActive) |
|
410 |
iconActive[i] = true; |
|
411 |
else |
|
412 |
iconActive[i] = false; |
|
413 |
} |
|
414 |
getMapControl().repaint(); |
|
415 |
} |
|
416 |
|
|
417 |
/** |
|
418 |
* @return Returns the lyrRaster. |
|
419 |
*/ |
|
420 |
public FLyrRaster getLyrRaster() { |
|
421 |
return lyrRaster; |
|
422 |
} |
|
423 |
|
|
424 |
/** |
|
425 |
* @param lyrRaster The lyrRaster to set. |
|
426 |
*/ |
|
427 |
public void setLyrRaster(FLyrRaster lyrRaster) { |
|
428 |
this.lyrRaster = lyrRaster; |
|
429 |
} |
|
430 |
|
|
431 |
/** |
|
432 |
* @return Returns the pathToFile. |
|
433 |
*/ |
|
434 |
public String getPathToFile() { |
|
435 |
return pathToFile; |
|
436 |
} |
|
437 |
|
|
438 |
/** |
|
439 |
* @param pathToFile The pathToFile to set. |
|
440 |
*/ |
|
441 |
public void setPathToFile(String pathToFile) { |
|
442 |
this.pathToFile = pathToFile; |
|
443 |
} |
|
444 |
} |
|
0 | 445 |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/Behavior/GeoMoveBehavior.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.tools.Behavior; |
|
42 |
|
|
43 |
import java.awt.Cursor; |
|
44 |
import java.awt.Graphics; |
|
45 |
import java.awt.Image; |
|
46 |
import java.awt.Point; |
|
47 |
import java.awt.Toolkit; |
|
48 |
import java.awt.event.MouseEvent; |
|
49 |
import java.awt.event.MouseWheelEvent; |
|
50 |
import java.awt.geom.Point2D; |
|
51 |
|
|
52 |
import javax.swing.ImageIcon; |
|
53 |
|
|
54 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
55 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
56 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
57 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
58 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener; |
|
59 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
60 |
|
|
61 |
|
|
62 |
/** |
|
63 |
* Behaviour que espera un listener de tipo GeoMoveListener. |
|
64 |
* Nacho Brodin (brodin_ign@gva.es) |
|
65 |
* |
|
66 |
*/ |
|
67 |
public class GeoMoveBehavior extends Behavior { |
|
68 |
|
|
69 |
private PanListener listener; |
|
70 |
private Cursor cur = null; |
|
71 |
|
|
72 |
private final Image defaultCursor = new ImageIcon(MapControl.class.getResource( |
|
73 |
"images/CruxCursor.png")).getImage(); |
|
74 |
private final Image handCursor = new ImageIcon(MapControl.class.getResource( |
|
75 |
"images/Hand.gif")).getImage(); |
|
76 |
|
|
77 |
private FLyrRaster lyrRaster = null; |
|
78 |
private String pathToFile = null; |
|
79 |
private boolean isMoveable = false; |
|
80 |
|
|
81 |
/** |
|
82 |
* Crea un nuevo RectangleBehavior. |
|
83 |
* |
|
84 |
* @param zili listener. |
|
85 |
*/ |
|
86 |
public GeoMoveBehavior(PanListener zili) { |
|
87 |
listener = zili; |
|
88 |
cur = zili.getCursor(); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Coloca el cursor del rat?n con el icono adecuado cuando entra dentro de la |
|
93 |
* imagen. |
|
94 |
*/ |
|
95 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
96 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
97 |
Point2D pto = vp.toMapPoint(e.getX(), e.getY()); |
|
98 |
//System.out.println(pto); |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Obtiene el cursor actual |
|
104 |
*/ |
|
105 |
public Cursor getCursor() { |
|
106 |
return this.cur; |
|
107 |
} |
|
108 |
/* (non-Javadoc) |
|
109 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
|
110 |
*/ |
|
111 |
public ToolListener getListener() { |
|
112 |
// TODO Auto-generated method stub |
|
113 |
return null; |
|
114 |
} |
|
115 |
/* (non-Javadoc) |
|
116 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getMapControl() |
|
117 |
*/ |
|
118 |
public MapControl getMapControl() { |
|
119 |
// TODO Auto-generated method stub |
|
120 |
return super.getMapControl(); |
|
121 |
} |
|
122 |
/* (non-Javadoc) |
|
123 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent) |
|
124 |
*/ |
|
125 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
|
126 |
// TODO Auto-generated method stub |
|
127 |
super.mouseClicked(e); |
|
128 |
} |
|
129 |
/* (non-Javadoc) |
|
130 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent) |
|
131 |
*/ |
|
132 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
133 |
// TODO Auto-generated method stub |
|
134 |
super.mouseDragged(e); |
Also available in: Unified diff