svn-gvsig-desktop / branches / v10 / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / operators / PointX.java @ 20331
History | View | Annotate | Download (2.18 KB)
1 | 10229 | caballero | package com.iver.cit.gvsig.project.documents.table.operators; |
---|---|---|---|
2 | |||
3 | 19023 | vcaballero | import java.util.ArrayList; |
4 | |||
5 | 10229 | caballero | import org.apache.bsf.BSFException; |
6 | import org.apache.bsf.BSFManager; |
||
7 | |||
8 | 11111 | caballero | import com.iver.andami.PluginServices; |
9 | 10229 | caballero | import com.iver.cit.gvsig.ExpresionFieldExtension; |
10 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
11 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
12 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
13 | import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
||
14 | import com.iver.cit.gvsig.project.documents.table.GraphicOperator; |
||
15 | import com.iver.cit.gvsig.project.documents.table.IOperator; |
||
16 | import com.iver.cit.gvsig.project.documents.table.Index; |
||
17 | /**
|
||
18 | * @author Vicente Caballero Navarro
|
||
19 | */
|
||
20 | public class PointX extends GraphicOperator{ |
||
21 | |||
22 | public String addText(String s) { |
||
23 | return s.concat(toString()+"()"); |
||
24 | } |
||
25 | public double process(Index index) throws DriverIOException { |
||
26 | ReadableVectorial adapter = getLayer().getSource(); |
||
27 | IGeometry geom=adapter.getShape(index.get()); |
||
28 | 19023 | vcaballero | ArrayList parts=getXY(geom);
|
29 | Double[][] xsys=(Double[][])parts.get(0);//getXY(geom); |
||
30 | 10229 | caballero | return xsys[0][0].doubleValue(); |
31 | } |
||
32 | public void eval(BSFManager interpreter) throws BSFException { |
||
33 | interpreter.declareBean("pointX",this,PointX.class); |
||
34 | 11222 | caballero | // interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,"double x(){return pointX.process(indexRow);};");
|
35 | interpreter.exec(ExpresionFieldExtension.JYTHON,null,-1,-1,"def x():\n" + |
||
36 | " return pointX.process(indexRow)");
|
||
37 | 10229 | caballero | } |
38 | public String toString() { |
||
39 | return "x"; |
||
40 | } |
||
41 | public boolean isEnable() { |
||
42 | if (getLayer()==null) |
||
43 | return false; |
||
44 | ReadableVectorial adapter = getLayer().getSource(); |
||
45 | int type=FShape.POINT;
|
||
46 | try {
|
||
47 | type=adapter.getShapeType(); |
||
48 | } catch (DriverIOException e) {
|
||
49 | e.printStackTrace(); |
||
50 | } |
||
51 | return (getType()==IOperator.NUMBER && type==FShape.POINT);
|
||
52 | } |
||
53 | 11111 | caballero | public String getTooltip(){ |
54 | return PluginServices.getText(this,"operator")+": "+addText("")+"\n"+getDescription(); |
||
55 | } |
||
56 | public String getDescription() { |
||
57 | return PluginServices.getText(this, "returns") + ": " + |
||
58 | PluginServices.getText(this, "numeric_value") + "\n" + |
||
59 | PluginServices.getText(this, "description") + ": " + |
||
60 | "Returns the X coordenate of point geometry of this row.";
|
||
61 | } |
||
62 | 10229 | caballero | } |