ImageJ base code to get access to all the classes and their methods to test new Plugins. https://imagejdocu.tudor.lu/howto/plugins/the_imagej_eclipse_howto
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.5 KiB

2 years ago
  1. // An ImageJ tool that makes nice and easy labels
  2. // as seen https://twitter.com/Astbury_BSL/status/1258677104696311809
  3. // Author: Jerome Mutterer
  4. var label = 'label';
  5. var lineWidth = 2;
  6. var globalLineWidth = parseInt(call('ij.gui.Line.getWidth'));
  7. macro "Label Tool (double click for options) - C037o0d55L3d65L65f5T830ca" {
  8. width = parseInt(call('ij.gui.Line.getWidth'));
  9. if (width>1 || width!=globalLineWidth) {
  10. lineWidth=width;
  11. globalLineWidth = width;
  12. }
  13. radius = maxOf(4,lineWidth*2);
  14. getCursorLoc(x, y, z, flags);
  15. if (flags&9>0) { // shift or alt
  16. removeLabel(x,y);
  17. exit();
  18. }
  19. getDateAndTime(yr, mo, dw, d, h, m, s, ms);
  20. uid = "labeltool_"+yr+""+mo+""+d+""+h+""+m+""+s+""+ms;
  21. nbefore = Overlay.size;
  22. getCursorLoc(x1, y1, z, flags);
  23. setLineWidth(lineWidth);
  24. while (flags&16>0) {
  25. getCursorLoc(x1, y1, z, flags);
  26. drawItem();
  27. wait(30);
  28. while (Overlay.size>nbefore)
  29. Overlay.removeSelection(Overlay.size-1);
  30. }
  31. drawItem();
  32. label =getString("Enter label", label);
  33. while (Overlay.size>nbefore)
  34. Overlay.removeSelection(Overlay.size-1);
  35. drawItem();
  36. }
  37. function drawItem() {
  38. makeOval(x-radius, y-radius, radius*2, radius*2);
  39. Roi.setName(uid);
  40. Overlay.addSelection("",0,""+hexCol());
  41. makeLine(x, y,x1,y1,x1+(((x1<x)*-1)+((x1>=x)*1))*getStringWidth(label),y1);
  42. Roi.setName(uid);
  43. Overlay.addSelection(""+hexCol(), lineWidth);
  44. setFont("user");
  45. makeText(label, x1 - (x1<x)*getStringWidth(label), y1-getValue("font.height")-lineWidth);
  46. Roi.setName(uid);
  47. Overlay.addSelection(""+hexCol(), lineWidth);
  48. run("Select None");
  49. }
  50. function hexCol() {
  51. return IJ.pad(toHex(getValue("rgb.foreground")),6);
  52. }
  53. function removeLabel(x,y) {
  54. index = Overlay.indexAt(x,y);
  55. if (index>=0) {
  56. Overlay.activateSelection(index);
  57. name = Roi.getName();
  58. Overlay.removeRois(name);
  59. Roi.remove;
  60. }
  61. }
  62. macro "Label Tool (double click for options) Options" {
  63. Dialog.create("Label Maker Tool Options");
  64. Dialog.addNumber("Line width:", lineWidth, 0, 3, "pixels");
  65. m1 = "Shift or alt click to remove a label.\n";
  66. m2 = "Double click on text tool to change\n";
  67. m3 = "font size and color.";
  68. Dialog.setInsets(0, 0, 0);
  69. Dialog.addMessage(m1+m2+m3);
  70. Dialog.show();
  71. lineWidth = Dialog.getNumber();
  72. }