//
//  Mark's Example Plugin
//
//  (c) 2011
//
//  For Java tutorials look at: http://download.oracle.com/javase/tutorial/
//
//  Remember to restart MM between testing each build.
//

//  Imports to let the program know what APIs we wish to access.
import org.micromanager.utils.MMFrame;
import org.micromanager.api.MMPlugin;
import org.micromanager.api.ScriptInterface;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//  Class definition that subclasses the MMFrame (a Micromamanger controlled
//  window) and (promises to) implement the MMPlugin interface.
public class MarkIsStillGreat extends MMFrame implements MMPlugin {
   //  The name that appears in the plugin menu in MM.
   public static final String menuName = "Mark";

   //  Class variable that we can access from any function.
   private ScriptInterface moApp;

   //  Constructor - called once the menu is selected.
   public MarkIsStillGreat () {
      super();
      setTitle(menuName);
      setResizable(true);
      setSize(200,80);

      // Read about Layout Managers to understand UI design in Java.
      setLayout(new FlowLayout());

      JButton loButton1 = new JButton();
      loButton1.setText("Snap");
      loButton1.setSize(100,10);
      loButton1.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
               int i = 0;
               double a = 3.4;
               //  Write a message to the system log "CoreLogYYYMMDD.txt"
               //  Use BareTail to read in real time.
               moApp.logMessage("Hello button pressed; " + i + " " + a);
               try {
                  //  Take an image.
                  moApp.snapSingleImage();
               } catch (Exception loE) {
                  //  Ignore any exceptions that are thrown.
               }
            }
         }
      );
      //  Adds this button to the window
      add(loButton1);
      JButton loButton2 = new JButton();
      loButton2.setText("About");
      loButton2.setSize(100,10);
      loButton2.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
               about();
            }
         }
      );
      //  Adds this button to the window, read about Layout Managers to
      //  understand UI design in Java.
      add(loButton2);
   }

   private void about() {
      JOptionPane.showMessageDialog(this, menuName + " : version ", "About " + menuName, JOptionPane.DEFAULT_OPTION);
   }

   //  Fulfil the promise to implement the MMPlugin interface, and store the
   //  ScriptInterface object that we are passed.
   public void setApp(ScriptInterface si) {
      moApp = si;
   }
   public void configurationChanged() { }
   public String getDescription() { return "M";}
   public String getInfo() { return "A"; }
   public String getVersion() { return "R"; }
   public String getCopyright() { return "K"; }

   //  An example function that is not called anywhere.
   private String mark (int piA, String psB) {
      int i;
      String rsB = "";
      for (i = 0; i < piA; i++) {
         rsB = rsB + psB;
      }
      return rsB;
   }
}

