svn-gvsig-desktop / trunk / examples / exaLoadLayer / src / org / gvsig / example / memory / CreateMemoryLayer.java @ 7531
History | View | Annotate | Download (2.34 KB)
1 |
package org.gvsig.example.memory; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import com.hardcode.gdbms.engine.values.Value; |
6 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
7 |
import com.iver.andami.PluginServices; |
8 |
import com.iver.andami.plugins.Extension; |
9 |
import com.iver.andami.ui.mdiManager.IWindow; |
10 |
import com.iver.cit.gvsig.fmap.DriverException; |
11 |
import com.iver.cit.gvsig.fmap.MapControl; |
12 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
13 |
import com.iver.cit.gvsig.fmap.core.FShape; |
14 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
15 |
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
17 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
18 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
19 |
|
20 |
/**
|
21 |
* @author fjp
|
22 |
*
|
23 |
* Example of using a ConcreteMemoryDriver to obtain a "editable layer" where
|
24 |
* you can write your features.
|
25 |
*
|
26 |
*/
|
27 |
public class CreateMemoryLayer extends Extension { |
28 |
|
29 |
public void initialize() { |
30 |
|
31 |
} |
32 |
|
33 |
public void execute(String actionCommand) { |
34 |
View v = (View) PluginServices.getMDIManager().getActiveWindow(); |
35 |
MapControl mapCtrl = v.getMapControl(); |
36 |
|
37 |
|
38 |
// DRIVER DEFINITION (SHAPE TYPE AND FIELDS)
|
39 |
ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
|
40 |
driver.setShapeType(FShape.LINE); |
41 |
|
42 |
ArrayList arrayFields = new ArrayList(); |
43 |
arrayFields.add("ID");
|
44 |
Value[] auxRow = new Value[1]; |
45 |
|
46 |
driver.getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
47 |
|
48 |
|
49 |
// GEOMETRY DEFINITION
|
50 |
GeneralPathX gp = new GeneralPathX();
|
51 |
|
52 |
gp.moveTo(20,80); |
53 |
gp.lineTo(80,60); |
54 |
gp.lineTo(100, 140); |
55 |
|
56 |
FShape shp = new FPolyline2D(gp);
|
57 |
|
58 |
|
59 |
// ATRIBUTES
|
60 |
auxRow[0] = ValueFactory.createValue(0); |
61 |
|
62 |
// ADD RECORD
|
63 |
driver.addShape(shp, auxRow); |
64 |
|
65 |
|
66 |
// CREATE AND ADD LAYER
|
67 |
FLayer lyr; |
68 |
String layerName = "Example"; |
69 |
lyr = LayerFactory.createLayer(layerName,driver, mapCtrl.getProjection()); |
70 |
|
71 |
if (lyr != null) { |
72 |
lyr.setVisible(true);
|
73 |
mapCtrl.getMapContext().getLayers().addLayer(lyr); |
74 |
|
75 |
} |
76 |
|
77 |
|
78 |
} |
79 |
|
80 |
public boolean isEnabled() { |
81 |
return true; |
82 |
} |
83 |
|
84 |
public boolean isVisible() { |
85 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
86 |
|
87 |
if (v instanceof View) |
88 |
return true; |
89 |
else
|
90 |
return false; |
91 |
} |
92 |
|
93 |
|
94 |
} |
95 |
|