Statistics
| Revision:

root / trunk / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / operators / PointX.java @ 13444

History | View | Annotate | Download (2.48 KB)

1
package com.iver.cit.gvsig.project.documents.table.operators;
2

    
3
import org.apache.bsf.BSFException;
4
import org.apache.bsf.BSFManager;
5

    
6
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
7
import com.iver.andami.PluginServices;
8
import com.iver.andami.messages.NotificationManager;
9
import com.iver.cit.gvsig.ExpressionFieldExtension;
10
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
11
import com.iver.cit.gvsig.fmap.core.FShape;
12
import com.iver.cit.gvsig.fmap.core.IGeometry;
13
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
14
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
15
import com.iver.cit.gvsig.project.documents.table.GraphicOperator;
16
import com.iver.cit.gvsig.project.documents.table.IOperator;
17
import com.iver.cit.gvsig.project.documents.table.Index;
18
/**
19
 * @author Vicente Caballero Navarro
20
 */
21
public class PointX extends GraphicOperator{
22

    
23
        public String addText(String s) {
24
                return s.concat(toString()+"()");
25
        }
26
        public double process(Index index) throws DriverIOException {
27
                ReadableVectorial adapter = getLayer().getSource();
28
                IGeometry geom=null;
29
                try {
30
                        geom = adapter.getShape(index.get());
31
                } catch (ExpansionFileReadException e) {
32
                        throw new DriverIOException(e);
33
                } catch (ReadDriverException e) {
34
                        throw new DriverIOException(e);
35
                }
36
                Double[][] xsys=getXY(geom);
37
                return xsys[0][0].doubleValue();
38
        }
39
        public void eval(BSFManager interpreter) throws BSFException {
40
                interpreter.declareBean("pointX",this,PointX.class);
41
//                interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double x(){return pointX.process(indexRow);};");
42
                interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def x():\n" +
43
                                "  return pointX.process(indexRow)");
44
        }
45
        public String toString() {
46
                return "x";
47
        }
48
        public boolean isEnable() {
49
                if (getLayer()==null)
50
                        return false;
51
                ReadableVectorial adapter = getLayer().getSource();
52
                int type=FShape.POINT;
53
                try {
54
                        type=adapter.getShapeType();
55
                } catch (ReadDriverException e) {
56
                        NotificationManager.addError(e);
57
                }
58
                return (getType()==IOperator.NUMBER && type==FShape.POINT);
59
        }
60
        public String getTooltip(){
61
                return PluginServices.getText(this,"operator")+":  "+addText("")+"\n"+getDescription();
62
        }
63
        public String getDescription() {
64
        return PluginServices.getText(this, "returns") + ": " +
65
        PluginServices.getText(this, "numeric_value") + "\n" +
66
        PluginServices.getText(this, "description") + ": " +
67
        "Returns the X coordenate of point geometry of this row.";
68
    }
69
}