

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;

import cds.aladin.*;

public class StackScanPlug extends AladinPlugin {
   
   public String menu() { return "Stack scanning"; }
   public String description()   {
      return "PLUGIN TUTORIAL:\n" +
             "This plugin is an example for manipulating the Aladin stack.\n" +
             "It will create a JPanel to display the state of the Aladin stack.";
   }   
   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/StackScanPlug.java"; }
   public String category()      { return "Plugin tutorial"; }
   
   /*
    * 1) Create Java Swing objects to display the result in a JTextArea
    * 2) Scan the Aladin stack and display the result
    */
   public void exec() {
      
      try {
         JFrame f = new JFrame();
         f.getContentPane().setLayout(new BorderLayout());
         JTextArea t = new JTextArea(20,40);
         f.getContentPane().add( t, "Center");
         f.pack();
         
         String [] planeID = aladin.getAladinStack();
         StringBuffer s = new StringBuffer();
         for( int i=0; i<planeID.length; i++ ) {
            AladinData sd = aladin.getAladinData(planeID[i]);
            s.append(".Aladin plane "+i
                  +"\n\t.name="+sd.getLabel()
                  +"\n\t.type="+sd.getPlaneType()
                  +"\n\t.selected="+sd.isSelected()
                  +"\n\t.url="+sd.getUrl()
                  +"\n\t.from="+sd.getOrigin()
                  +"\n\t.error="+sd.getError()
                  +"\n");
         }
         t.setText(s.toString());
         f.setVisible(true);
        
      } catch( AladinException e ) { e.printStackTrace(); }
   }
}