root / trunk / prototypes / mobile / desktop / extensions / extExportMobile / src / es / prodevelop / gvsig / exportMobile / rectangle / DrawRectangle.java @ 19196
History | View | Annotate | Download (3.85 KB)
1 |
package es.prodevelop.gvsig.exportMobile.rectangle; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.cresques.cts.IProjection; |
7 |
|
8 |
import com.hardcode.gdbms.engine.values.Value; |
9 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
10 |
import com.iver.cit.gvsig.fmap.MapControl; |
11 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
12 |
import com.iver.cit.gvsig.fmap.core.FShape; |
13 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
14 |
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
15 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB; |
17 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
18 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
19 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
20 |
|
21 |
/**
|
22 |
* Utility to create layers with rectangles
|
23 |
*
|
24 |
* @author Anabel Moreno
|
25 |
*
|
26 |
*/
|
27 |
public class DrawRectangle { |
28 |
|
29 |
private Rectangle2D rect; |
30 |
|
31 |
private FShape shp;
|
32 |
|
33 |
private View v; |
34 |
|
35 |
private static String RECTANGLE = "Rectangle"; |
36 |
|
37 |
public DrawRectangle(View view) { |
38 |
|
39 |
v = view; |
40 |
} |
41 |
|
42 |
public Rectangle2D getRectangle() { |
43 |
|
44 |
return rect;
|
45 |
} |
46 |
|
47 |
/**
|
48 |
* Set the rectangle of the view
|
49 |
*/
|
50 |
public void setRectView() { |
51 |
|
52 |
rect = v.getMapControl().getViewPort().getAdjustedExtent(); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* Set rectangle of the extent
|
57 |
* @param recExtent
|
58 |
*/
|
59 |
public void setRectExtent(Rectangle2D recExtent) { |
60 |
|
61 |
rect = recExtent; |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Create and draw a new rectangle poligon
|
66 |
*
|
67 |
* @param mapCtrl
|
68 |
* @return layer
|
69 |
*/
|
70 |
public FLayer draw(MapControl mapCtrl) {
|
71 |
|
72 |
/* DRIVER DEFINITION (SHAPE TYPE AND FIELDS) */
|
73 |
ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
|
74 |
driver.setShapeType(FShape.POLYGON); |
75 |
|
76 |
ArrayList arrayFields = new ArrayList(); |
77 |
arrayFields.add("ID");
|
78 |
Value[] auxRow = new Value[1]; |
79 |
|
80 |
driver.getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
81 |
|
82 |
/* GEOMETRY DEFINITION */
|
83 |
GeneralPathX rectangulo = new GeneralPathX();
|
84 |
|
85 |
// rect is the rectangle extent of the view
|
86 |
/* NEW RECTANGLE */
|
87 |
rectangulo.moveTo(rect.getMinX(), rect.getMinY()); |
88 |
rectangulo.lineTo(rect.getMinX(), rect.getMaxY()); |
89 |
rectangulo.lineTo(rect.getMaxX(), rect.getMaxY()); |
90 |
rectangulo.lineTo(rect.getMaxX(), rect.getMinY()); |
91 |
rectangulo.closePath(); |
92 |
|
93 |
shp = new FPolygon2D(rectangulo);
|
94 |
|
95 |
/* ATRIBUTES */
|
96 |
auxRow[0] = ValueFactory.createValue(0); |
97 |
|
98 |
/* ADD RECORD */
|
99 |
driver.addShape(shp, auxRow); |
100 |
|
101 |
/* CREATE AND ADD LAYER */
|
102 |
FLayer lyr; |
103 |
String layerName = RECTANGLE;
|
104 |
lyr = LayerFactory.createLayer(layerName, driver, mapCtrl |
105 |
.getProjection()); |
106 |
|
107 |
return lyr;
|
108 |
|
109 |
} |
110 |
/**
|
111 |
* Create and draw a new rectangle poligon
|
112 |
*
|
113 |
* @param rect
|
114 |
* @return layer
|
115 |
*/
|
116 |
public static FLyrVect createRectangleLayer(Rectangle2D rect, IProjection projection) { |
117 |
|
118 |
/* DRIVER DEFINITION (SHAPE TYPE AND FIELDS) */
|
119 |
ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
|
120 |
driver.setShapeType(FShape.POLYGON); |
121 |
|
122 |
ArrayList arrayFields = new ArrayList(); |
123 |
arrayFields.add("ID");
|
124 |
Value[] auxRow = new Value[1]; |
125 |
|
126 |
driver.getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
127 |
|
128 |
/* GEOMETRY DEFINITION */
|
129 |
GeneralPathX rectangulo = new GeneralPathX();
|
130 |
|
131 |
// rect is the rectangle extent of the view
|
132 |
/* NEW RECTANGLE */
|
133 |
rectangulo.moveTo(rect.getMinX(), rect.getMinY()); |
134 |
rectangulo.lineTo(rect.getMinX(), rect.getMaxY()); |
135 |
rectangulo.lineTo(rect.getMaxX(), rect.getMaxY()); |
136 |
rectangulo.lineTo(rect.getMaxX(), rect.getMinY()); |
137 |
rectangulo.closePath(); |
138 |
|
139 |
FPolygon2D shp = new FPolygon2D(rectangulo);
|
140 |
|
141 |
/* ATRIBUTES */
|
142 |
auxRow[0] = ValueFactory.createValue(0); |
143 |
|
144 |
/* ADD RECORD */
|
145 |
driver.addShape(shp, auxRow); |
146 |
|
147 |
/* CREATE AND ADD LAYER */
|
148 |
FLyrVect lyr; |
149 |
String layerName = RECTANGLE;
|
150 |
lyr = (FLyrVect)LayerFactory.createLayer(layerName, driver, projection); |
151 |
|
152 |
return lyr;
|
153 |
|
154 |
} |
155 |
|
156 |
} |