

import cds.aladin.*;

public class ImageLoaderPlug extends AladinPlugin {
   
   public String menu() { return "ESO DSS1 thumbnail image loader"; }
   public String description()   {
      return "This plugin will provide a DSS1 image for each source " +
            "of the selected catalog plane. It uses the ESO DSS1 server which is very " +
            "fast. This plugin is limited to the 16 first sources. It will proceed " +
            "4 by 4 sources and move the resulting images in a dedicated folder.";
   }   
   public String author()        { return "Pierre Fernique [CDS]"; }
   public String version()       { return "1.1 - January 2007"; }
   public String url() { return "http://aladin.u-strasbg.fr/java/Plugins/ImageLoaderPlug.java"; }
   public String category()      { return "Image"; }
   public boolean inSeparatedThread() { return true; }
   
   static final int BLOC = 4;
   
   public void exec() {
      
      try {
         // Browse objects from current catalog
         AladinData ad = aladin.getAladinData();
         Obj [] obj = ad.seeObj();
         
         // 16 views, and a folder in position 1 in the Aladin stack
         aladin.execCommand("mview 16;md Fold;mv Fold 1");
         
         // load an DSS1 ESO image for each target
         for( int i=0; i<ad.getNbObj() && i<16; i++ ) {
            aladin.execCommand("get ESO(DSS1,5,5) "+obj[i].getSexa());
            
            // Wait the first BLOC images, and move them
            // into the folder.
            if( i%BLOC==0 && i>0 ) {
               aladin.execCommand("sync");
               for( int j=0; j<=BLOC; j++ ) {
                  aladin.execCommand("mv ESO* Fold");
               }
            }
         }
         aladin.execCommand("collapse Fold");
       
      } catch( AladinException e ) { e.printStackTrace(); }
   }
}