Skip to content

Instantly share code, notes, and snippets.

@dscho
Last active December 15, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscho/5286408 to your computer and use it in GitHub Desktop.
Save dscho/5286408 to your computer and use it in GitHub Desktop.
;; Command_Launcher.clj starts here
(import '(java.awt Color)
'(java.awt.event TextListener)
'(ij.gui GenericDialog)
'(ij IJ)
'(ij Menus))
(let [commands (keys (. Menus getCommands))
gd (GenericDialog. "Command Launcher")]
(.addStringField gd "Command: " "")
(let [prompt (. (. gd getStringFields) get 0)]
(doto prompt
(.setForeground (. Color red))
(.addTextListener (proxy [TextListener] []
(textValueChanged [tvc]
(let [text (.getText prompt)]
(.setForeground prompt
(if (some #{text} commands)
(. Color black)
(. Color red)))))))))
(.showDialog gd)
(when-not (.wasCanceled gd)
(IJ/doCommand (.getNextString gd))))
;; end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment