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.

58 lines
1.7 KiB

2 years ago
  1. package ij.plugin;
  2. import ij.*;
  3. import ij.io.*;
  4. import java.awt.Desktop;
  5. import java.awt.desktop.*;
  6. import java.io.File;
  7. import java.util.Vector;
  8. /** This Mac-specific plugin is designed to handle the "About ImageJ"
  9. * command in the ImageJ menu, to open files dropped on ImageJ.app
  10. * and to open double-clicked files with creator code "imgJ".
  11. * With Java 9 or newer, we use java.awt.desktop instead of the
  12. * previous com.apple.eawt.* classes.
  13. * @author Alan Brooks
  14. */
  15. public class MacAdapter9 implements PlugIn, AboutHandler, OpenFilesHandler, QuitHandler, Runnable {
  16. static Vector<String> paths = new Vector<String>();
  17. public void run(String arg) {
  18. Desktop dtop = Desktop.getDesktop();
  19. dtop.setOpenFileHandler(this);
  20. dtop.setAboutHandler(this);
  21. dtop.setQuitHandler(this);
  22. }
  23. @Override
  24. public void handleAbout(AboutEvent e) {
  25. IJ.doCommand("About ImageJ...");
  26. }
  27. @Override
  28. public void openFiles(OpenFilesEvent e) {
  29. for (File file: e.getFiles()) {
  30. paths.add(file.getPath());
  31. Thread thread = new Thread(this, "Open");
  32. thread.setPriority(thread.getPriority()-1);
  33. thread.start();
  34. }
  35. }
  36. @Override
  37. public void handleQuitRequestWith(QuitEvent e, QuitResponse response) {
  38. new Executer("Quit", null); // works with the CommandListener
  39. }
  40. // Not adding preference handling
  41. // because we don't have the equivalent of app.setEnabledPreferencesMenu(true);
  42. // @Override
  43. // public void handlePreferences(PreferencesEvent e) {
  44. // IJ.error("The ImageJ preferences are in the Edit>Options menu.");
  45. // }
  46. public void run() {
  47. if (paths.size() > 0) {
  48. (new Opener()).openAndAddToRecent(paths.remove(0));
  49. }
  50. }
  51. }