root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / demo / ImageFrame.java @ 276
History | View | Annotate | Download (2.96 KB)
1 |
package com.iver.cit.gvsig.fmap.demo; |
---|---|
2 |
|
3 |
import java.awt.BasicStroke; |
4 |
import java.awt.Color; |
5 |
import java.io.File; |
6 |
|
7 |
import javax.swing.JFrame; |
8 |
import javax.swing.JPanel; |
9 |
|
10 |
import org.geotools.renderer.style.PolygonStyle2D; |
11 |
|
12 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
13 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
14 |
import com.iver.cit.gvsig.fmap.drivers.shp.DemoSHPDriver; |
15 |
import com.iver.cit.gvsig.fmap.layers.ChildrenNotAllowedException; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
17 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
18 |
import com.iver.cit.gvsig.fmap.layers.LayerPath; |
19 |
import com.iver.cit.gvsig.fmap.layers.ProjectionMismatchException; |
20 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
21 |
import com.iver.cit.gvsig.fmap.tools.ZoomInMapTool; |
22 |
public class ImageFrame extends JFrame { |
23 |
|
24 |
private javax.swing.JPanel jContentPane = null; |
25 |
|
26 |
/**
|
27 |
* This is the default constructor
|
28 |
*/
|
29 |
public ImageFrame() {
|
30 |
super();
|
31 |
initialize(); |
32 |
} |
33 |
/**
|
34 |
* This method initializes this
|
35 |
*
|
36 |
* @return void
|
37 |
*/
|
38 |
private void initialize() { |
39 |
this.setSize(300,200); |
40 |
this.setContentPane(getJContentPane());
|
41 |
this.setTitle("JFrame"); |
42 |
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
43 |
} |
44 |
/**
|
45 |
* This method initializes jContentPane
|
46 |
*
|
47 |
* @return javax.swing.JPanel
|
48 |
*/
|
49 |
private javax.swing.JPanel getJContentPane() {
|
50 |
if(jContentPane == null) { |
51 |
jContentPane = new javax.swing.JPanel();
|
52 |
jContentPane.setLayout(new java.awt.BorderLayout());
|
53 |
jContentPane.add(getJPanel(), java.awt.BorderLayout.CENTER); |
54 |
} |
55 |
return jContentPane;
|
56 |
} |
57 |
|
58 |
private NewMapControl jPanel = null; |
59 |
/**
|
60 |
* This method initializes jPanel
|
61 |
*
|
62 |
* @return javax.swing.JPanel
|
63 |
*/
|
64 |
private NewMapControl getJPanel() {
|
65 |
if (jPanel == null) { |
66 |
try {
|
67 |
jPanel = new NewMapControl();
|
68 |
DemoSHPDriver driver = new DemoSHPDriver();
|
69 |
FLyrVect l = LayerFactory.createLayer(driver, new File("d:/fjp/chiara/plano/vias.shp"), null); |
70 |
l.setName("Vias");
|
71 |
DemoSHPDriver driver2 = new DemoSHPDriver();
|
72 |
FLyrVect l2 = LayerFactory.createLayer(driver2, new File("d:/fjp/chiara/plano/provin.shp"), null); |
73 |
l2.setName("Provin");
|
74 |
PolygonStyle2D psd = new PolygonStyle2D();
|
75 |
psd.setContour(Color.DARK_GRAY);
|
76 |
psd.setStroke(new BasicStroke(3)); |
77 |
psd.setFill(Color.LIGHT_GRAY);
|
78 |
l2.setLegend(LegendFactory.createUniqueSymbolLegend(psd)); |
79 |
try {
|
80 |
jPanel.getMapContext().getLayers().addLayer(new LayerPath(), l2);
|
81 |
jPanel.getMapContext().getLayers().addLayer(new LayerPath(), l);
|
82 |
l.getSource().start(); |
83 |
jPanel.getMapContext().getViewPort().setExtent(l.getFullExtent()); |
84 |
l.getSource().stop(); |
85 |
jPanel.addMapTool("rectangulo", new ZoomInMapTool()); |
86 |
jPanel.addTool("zoomMas", "rectangulo"); |
87 |
jPanel.setTool("zoomMas");
|
88 |
} catch (ProjectionMismatchException e) {
|
89 |
e.printStackTrace(); |
90 |
} catch (ChildrenNotAllowedException e) {
|
91 |
e.printStackTrace(); |
92 |
} |
93 |
|
94 |
|
95 |
} catch (DriverIOException e) {
|
96 |
e.printStackTrace(); |
97 |
} |
98 |
} |
99 |
return jPanel;
|
100 |
} |
101 |
} |