root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / demo / ImageFrame.java @ 305
History | View | Annotate | Download (7.54 KB)
1 |
package com.iver.cit.gvsig.fmap.demo; |
---|---|
2 |
|
3 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
4 |
import com.iver.cit.gvsig.fmap.ViewPort; |
5 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
6 |
import com.iver.cit.gvsig.fmap.drivers.shp.DemoSHPDriver; |
7 |
import com.iver.cit.gvsig.fmap.layers.ChildrenNotAllowedException; |
8 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
9 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
10 |
import com.iver.cit.gvsig.fmap.layers.LayerPath; |
11 |
import com.iver.cit.gvsig.fmap.layers.ProjectionMismatchException; |
12 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
13 |
import com.iver.cit.gvsig.fmap.tools.AreaListenerImpl; |
14 |
import com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent; |
15 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
16 |
import com.iver.cit.gvsig.fmap.tools.Listeners.MeasureListener; |
17 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
18 |
import com.iver.cit.gvsig.fmap.tools.MapTools.AreaMapTool; |
19 |
import com.iver.cit.gvsig.fmap.tools.MapTools.MeasureMapTool; |
20 |
import com.iver.cit.gvsig.fmap.tools.MapTools.MoveMapTool; |
21 |
import com.iver.cit.gvsig.fmap.tools.MapTools.PointMapTool; |
22 |
import com.iver.cit.gvsig.fmap.tools.MapTools.RectangleMapTool; |
23 |
import com.iver.cit.gvsig.fmap.tools.MeasureListenerImpl; |
24 |
import com.iver.cit.gvsig.fmap.tools.PanListenerImpl; |
25 |
import com.iver.cit.gvsig.fmap.tools.ZoomInListenerImpl; |
26 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutListenerImpl; |
27 |
|
28 |
import org.cresques.cts.IProjection; |
29 |
import org.geotools.renderer.style.Java2DMark; |
30 |
import org.geotools.renderer.style.MarkStyle2D; |
31 |
import org.geotools.renderer.style.PolygonStyle2D; |
32 |
|
33 |
import java.awt.BasicStroke; |
34 |
import java.awt.Color; |
35 |
import java.awt.Point; |
36 |
import java.awt.Shape; |
37 |
import java.awt.geom.Point2D; |
38 |
import java.awt.geom.Rectangle2D; |
39 |
|
40 |
import java.io.File; |
41 |
|
42 |
import java.util.Iterator; |
43 |
|
44 |
import javax.swing.JFrame; |
45 |
import javax.swing.JPanel; |
46 |
|
47 |
|
48 |
/**
|
49 |
* DOCUMENT ME!
|
50 |
*
|
51 |
* @author Vicente Caballero Navarro
|
52 |
*/
|
53 |
public class ImageFrame extends JFrame { |
54 |
private javax.swing.JPanel jContentPane = null; |
55 |
private NewMapControl jPanel = null; |
56 |
|
57 |
/**
|
58 |
* This is the default constructor
|
59 |
*/
|
60 |
public ImageFrame() {
|
61 |
super();
|
62 |
initialize(); |
63 |
} |
64 |
|
65 |
/**
|
66 |
* This method initializes this
|
67 |
*/
|
68 |
private void initialize() { |
69 |
this.setSize(300, 200); |
70 |
this.setContentPane(getJContentPane());
|
71 |
this.setTitle("JFrame"); |
72 |
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* This method initializes jContentPane
|
77 |
*
|
78 |
* @return javax.swing.JPanel
|
79 |
*/
|
80 |
private javax.swing.JPanel getJContentPane() {
|
81 |
if (jContentPane == null) { |
82 |
jContentPane = new javax.swing.JPanel();
|
83 |
jContentPane.setLayout(new java.awt.BorderLayout());
|
84 |
jContentPane.add(getJPanel(), java.awt.BorderLayout.CENTER); |
85 |
} |
86 |
|
87 |
return jContentPane;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* This method initializes jPanel
|
92 |
*
|
93 |
* @return javax.swing.JPanel
|
94 |
*/
|
95 |
private NewMapControl getJPanel() {
|
96 |
if (jPanel == null) { |
97 |
try {
|
98 |
jPanel = new NewMapControl();
|
99 |
|
100 |
DemoSHPDriver driver = new DemoSHPDriver();
|
101 |
IProjection proj = null; //ProjectionPool.get("ed50utm30"); |
102 |
FLyrVect l = LayerFactory.createLayer(driver, new File("d:/fjp/chiara/plano/vias.shp"), proj); |
103 |
l.setName("Vias");
|
104 |
DemoSHPDriver driver2 = new DemoSHPDriver();
|
105 |
FLyrVect l2 = LayerFactory.createLayer(driver2, new File("d:/fjp/chiara/plano/provin.shp"), proj); |
106 |
l2.setName("Provin");
|
107 |
PolygonStyle2D psd = new PolygonStyle2D();
|
108 |
psd.setContour(Color.DARK_GRAY);
|
109 |
psd.setStroke(new BasicStroke(3)); |
110 |
psd.setFill(Color.LIGHT_GRAY);
|
111 |
l2.setLegend(LegendFactory.createUniqueSymbolLegend(psd)); |
112 |
|
113 |
DemoSHPDriver driver3 = new DemoSHPDriver();
|
114 |
|
115 |
MarkStyle2D pointSym = new MarkStyle2D();
|
116 |
|
117 |
pointSym.setShape(Java2DMark.getWellKnownMark(""));
|
118 |
pointSym.setFill(Color.RED);
|
119 |
pointSym.setSize(10);
|
120 |
FLyrVect l3 = LayerFactory.createLayer(driver3, new File("d:/fjp/chiara/plano/poblac.shp"), null); |
121 |
l3.setName("Poblac");
|
122 |
l3.setLegend(LegendFactory.createUniqueSymbolLegend(pointSym)); |
123 |
|
124 |
try {
|
125 |
jPanel.getMapContext().getLayers().addLayer(new LayerPath(), l2);
|
126 |
jPanel.getMapContext().getLayers().addLayer(new LayerPath(),
|
127 |
l3); |
128 |
l.getSource().start(); |
129 |
jPanel.getMapContext().getViewPort().setExtent(l.getFullExtent()); |
130 |
l.getSource().stop(); |
131 |
|
132 |
int sel = 4; |
133 |
|
134 |
switch (sel) {
|
135 |
case (0): |
136 |
jPanel.addMapTool("zoomout", new PointMapTool()); |
137 |
|
138 |
ZoomOutListenerImpl zoli = new ZoomOutListenerImpl(jPanel.getMapContext()
|
139 |
.getViewPort()); |
140 |
jPanel.setCursor(zoli.getCursor()); |
141 |
jPanel.addTool("zoomout", "zoomout", zoli); |
142 |
jPanel.setTool("zoomout");
|
143 |
|
144 |
break;
|
145 |
|
146 |
case (1): |
147 |
jPanel.addMapTool("pan", new MoveMapTool()); |
148 |
|
149 |
PanListenerImpl pli = new PanListenerImpl(jPanel.getMapContext()
|
150 |
.getViewPort()); |
151 |
jPanel.setCursor(pli.getCursor()); |
152 |
jPanel.addTool("pan", "pan", pli); |
153 |
jPanel.setTool("pan");
|
154 |
|
155 |
break;
|
156 |
|
157 |
case (2): |
158 |
jPanel.addMapTool("medicion", new MeasureMapTool()); |
159 |
|
160 |
MeasureListenerImpl mli = new MeasureListenerImpl(jPanel.getMapContext()
|
161 |
.getViewPort()); |
162 |
jPanel.setCursor(mli.getCursor()); |
163 |
jPanel.addTool("medicion", "medicion", mli); |
164 |
jPanel.setTool("medicion");
|
165 |
|
166 |
break;
|
167 |
|
168 |
case (3): |
169 |
jPanel.addMapTool("area", new AreaMapTool()); |
170 |
|
171 |
AreaListenerImpl ali = new AreaListenerImpl(jPanel.getMapContext()
|
172 |
.getViewPort()); |
173 |
jPanel.setCursor(ali.getCursor()); |
174 |
jPanel.addTool("area", "area", ali); |
175 |
jPanel.setTool("area");
|
176 |
|
177 |
break;
|
178 |
|
179 |
case (4): |
180 |
jPanel.addMapTool("rectangle",
|
181 |
new RectangleMapTool());
|
182 |
|
183 |
ZoomInListenerImpl zili = new ZoomInListenerImpl(jPanel.getMapContext()
|
184 |
.getViewPort()); |
185 |
jPanel.setCursor(zili.getCursor()); |
186 |
jPanel.addTool("rectangle", "rectangle", zili); |
187 |
jPanel.setTool("rectangle");
|
188 |
|
189 |
break;
|
190 |
} |
191 |
} catch (ProjectionMismatchException e) {
|
192 |
e.printStackTrace(); |
193 |
} catch (ChildrenNotAllowedException e) {
|
194 |
e.printStackTrace(); |
195 |
} |
196 |
} catch (DriverIOException e) {
|
197 |
e.printStackTrace(); |
198 |
} |
199 |
} |
200 |
|
201 |
return jPanel;
|
202 |
} |
203 |
} |