
import cds.aladin.*;

public class GraphicCreationPlug extends AladinPlugin {
   
   public String menu() { return "Graphical overlay creation"; }
   public String description()   {
      return "PLUGIN TUTORIAL:\n" +
             "This plugin is an example of an overlay plane creation.\n" +
             "It will draw some graphical overlays and will use some VOApp" +
             "methods to control Aladin (modifying some plane properties)...\n\n" +
             "This plugin can be called by the \"mygraph someText\" script command.";
   }   
   public String author()        { return "Pierre Fernique [CDS]"; }
   public String version()       { return "1.0 - January 2007"; }
   public String url() { return "http://aladin.u-strasbg.fr/java/Plugins/GraphicCreationPlug.java"; }
   public String category()      { return "Plugin tutorial/Overlay"; }
   
   /** This plugin can be called by this Aladin script command */
   public String scriptCommand() { return "mygraph"; }
   
   /** Via the script command, the plugin accepts parameters */
   public String execScriptCommand(String [] param) {
      if( param.length>0 ) MYTEXT = param[0];
      return super.execScriptCommand(param);
   }
   
   private String MYTEXT = "This is a text";
   /**
    * Graphic usage by VOApp
    * 1) access to the background image
    * 2) Ask Aladin to create a graphical plane via the "draw" script command passed
    *    to Aladin via the VOApp.execCommand() method
    * 3) Show several examples of Aladin controls via the VOApp.execCommand()
    */
   public void exec() {
      try {
         AladinData sd = aladin.getAladinImage();
         
         // Access to the size of the current image
         int w = sd.getWidth();
         int h = sd.getHeight();
         
         // Creating a graphical overlay plane by script commands
         aladin.execCommand("draw mode(XY)");
         aladin.execCommand("draw string(100,"+(h/2+20)+",\""+MYTEXT+"\")");
         aladin.execCommand("draw line(0,"+h/2+","+w+","+h/2+")");
         aladin.execCommand("draw circle("+w/2+","+h/2+",200)");
         
         // Aladin control by VOApp
         aladin.execCommand("sync");                            // wait until all arriving data are ok
         System.out.println( aladin.execCommand("status") );    // Print Aladin full status
         aladin.execCommand("set MyCatalog Color=yellow");      // Modify a plane property
         aladin.execCommand("select MyCatalog");                // select the plane MyCatalog
         
      } catch( AladinException e ) { e.printStackTrace(); }
   } 
}