Personal tools
You are here: Home gvSIG Projects gvSIG Desktop Documentation Developers documentation org.gvsig.fmap.geom 2.0.0 Operations Create operations
gvSIG Desktop
gvSIG Desktop

Cached time 11/21/13 11:24:39 Clear cache and reload

 

In gvSIG 2.0 is defined the operation concept. This is a class which inherits from GeometryOperation that implements a specific operation and associate it to a concrete GeometryType.

The GeometryOperation class needs two methods to be implemented: in one hand will be getOperationInxex, which returns the internal operation code. Operations must have a name but, in runtime, gvSIG will establish a correspondency between the names and codes of the operations. Following the convention, all the operations must have a public and static variable of the int type which will be intialized with the getGeometryOperationCode method from the GeometryManager. This method fixes the operation code value and it would be consulted to execute a concrete operation in a third class.

In the other hand, besides getOperationInxex, an operation will have a method called invoke which will be invoke when the operation is executed. The parameters are the geometry, in which we are going to do the operation, and the operation context (commented in the next sections).

In the next example we will create an operation called println which prints in the console the geometry that executes the operation:

public class PrintLn extends GeometryOperation {
  public static final String NAME = "println";
  public static final int CODE = GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);

  public int getOperationIndex() {
    return CODE;
  }

  public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException {
    System.out.println(geom.toString());
    return null;
  }
}

When we will have created an operation, we must register it in the application. The next section shows how to do it.


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: