// Look Up Tables Tool
// G. Landini 6/4/2006
// 23/5/06: fixed spaces in file name bug
//
// This tool looks for LUT files in the 'ImageJ/luts' directory
// and each time  the icon is clicked it loads the next LUT.
// Click+[shift] goes back in the list of LUTs
// Click+[alt] sets the first LUT in the list (Gray LUT in my setup) and resets the list order
// 
// Tip 1: the LUT names are sorted in alphabetical order, so to force loading the
// files in a particular order, you should rename the files accordingly.
// For instance 000-gray.lut, 001-fire.lut, etc.

// Tip 2: You can open a LUT file be double clicking on it if you
// associate the .lut extension with ImageJ. You can also open
// a LUT file by dragging and dropping it on the ImageJ icon.
// On Windows, you can open a LUT by dragging and dropping
// in on the main ImageJ window.

// A 'luts' folder with 68 LUT files is available at
// <http://rsb.info.nih.gov/ij/download/luts/luts.zip>

    var GLlut=0;
    var lutdir=getDirectory("startup")+"luts"+File.separator;
    var list = getFileList(lutdir);

   macro "Look Up Tables Tool - C900L222e Cf00L323e Cf90L424e Cfd0L525e Cff3L626e Cce4L727e C4f0L828e C3ecL929e C5cdLa2ae C79fLb2be C77fLc2ce Cb6fLd2de CfafLe2ee CfefLf2fe C000R11fe"{
   }

   macro "Look Up Tables Tool Selected" {
       restorePreviousTool();
       if (!File.exists(lutdir) || list.length<1)
           exit("No LUTs in the '/ImageJ/luts' folder.\nThe LUT Tool will not work.");
       if (isKeyDown("alt"))
           GLlut=0;
      else if (isKeyDown("shift"))
          GLlut-=1;
      else
          GLlut+=1;
      if (GLlut<0) GLlut=list.length-1;
      if (GLlut>list.length-1) GLlut=0;
      if (bitDepth()!=24)
         run("LUT... ", "open=["+lutdir+list[GLlut]+"]");
      wait(20);
      showStatus(list[GLlut]);
  }

