Exemplo n.º 1
0
  public void loadEmbeddedMacros() {
    boolean altDown = IJ.altKeyDown(); // 3.8.2009
    boolean shiftDown = IJ.shiftKeyDown(); // 18.8.2009
    if (shiftDown) {
      shiftDown = shiftDown && true;
    }
    if (IJ.debugMode) {
      IJ.log("alt=" + altDown + "   shift=" + shiftDown);
    }
    String macros_text = null;
    String macroFileName = null;
    if (OJ.isProjectOpen) {
      DataOJ data = OJ.getData();
      String project_name = data.getName();

      String directory = data.getDirectory();
      macroFileName = project_name + ".txt";
      File macros_file = new File(directory, macroFileName);
      MacroInstaller mi = new MacroInstaller();
      // mechanism to remove manually loaded project files
      macros_text = OJ.getData().getLinkedMacroText(); // 18.3.2010
      boolean externalMacroExists = macros_file.exists() && macros_file.isFile();
      boolean internalMacroExists = (macros_text != null);
      if (!internalMacroExists && !externalMacroExists) {
        // mi.install(macros_text);16.9.2010
        return;
      }
      if (externalMacroExists && internalMacroExists) {
        IJ.showMessage("Project has internal macro, so external macro is ignored");
      }
      if (externalMacroExists && !internalMacroExists) {
        String thisVersion = IJ.getVersion();
        boolean is143d = thisVersion.compareToIgnoreCase("1.43d") >= 0;
        if (is143d) {
          String oldMacroName = ij.plugin.MacroInstaller.getFileName();
          if (oldMacroName != null && oldMacroName.equalsIgnoreCase(macroFileName)) {
            oldMacroName = oldMacroName + "";
            String macro = "macro 'Dummy Tool-Cf00O8822' {}\n"; // kill old tools
            mi.install(macro);

            String dir = IJ.getDirectory("macros") + "StartupMacros.txt";
            File startup_file = new File(IJ.getDirectory("macros"), "StartupMacros.txt");
            if (startup_file.exists()) {
              IJ.showMessage("Macros in \"" + macroFileName + "\" will appear under ObjectJ menu");
              mi.installFile(dir);
            }
            mi.setFileName(""); // 15.7.2009
          }
        }

        macros_text = UtilsOJ.readStringFromFile(macros_file);
      }
      OJ.getData().setLinkedMacroText(macros_text);
      doInstall(macros_text);
    }
  }
Exemplo n.º 2
0
  public void doInstall(String macros_text) { // Normal Load Project Macros  //20.9.2010

    Interpreter intp = Interpreter.getInstance();
    if (intp != null) {
      Interpreter.getInstance().abortMacro(); // 11.8.2013
    }

    // ImageJAccessOJ.InterpreterAccess.
    OJ.initMacroProcessor(); // 4.7.2013
    // OJ.getMacroProcessor().setTarget("exit");//4.7.2013

    macros_text = UtilsOJ.fixLineFeeds(macros_text);
    // }
    String clean_macro_text = UtilsOJ.maskComments(macros_text);
    clean_macro_text = clean_macro_text.replaceAll("macro\"", "macro \""); // 19.10.2010
    if ((clean_macro_text != null) && (!clean_macro_text.equals(""))) {
      boolean leadingPart = !clean_macro_text.startsWith("macro");
      String[] macros = clean_macro_text.split("macro "); //
      int numMacros = macros.length;
      if (leadingPart) {
        numMacros--;
      }
      String project_name = OJ.getData().getName();
      if (numMacros > 0) { // 7.9.2010
        MacroSetOJ macroSet = OJ.getData().getMacroSet();
        macroSet = new MacroSetOJ();
        macroSet.setName(project_name);
        macroSet.installText(macros_text);
        OJ.getData().setMacroSet(macroSet);
        OJ.getEventProcessor()
            .fireMacroChangedEvent(project_name, MacroChangedEventOJ.MACROSET_EDITED);
        ij.IJ.showStatus("" + numMacros + " embedded macros have been loaded");
      }
    }
    ToolManagerOJ.getInstance().reload();
  }
Exemplo n.º 3
0
        public void actionPerformed(ActionEvent e) {

          // Interpreter.abort();//17.9.2010 -checks for null instance etc removed 11.8.2013
          Editor ed = OJ.editor;

          String theText = ed.getText();
          theText = UtilsOJ.fixLineFeeds(theText); // 7.9.2010
          OJ.getData().setLinkedMacroText(theText);
          int caretPos = ed.getTextArea().getCaretPosition();
          ed.getTextArea().setText(theText);
          ed.getTextArea().setCaretPosition(caretPos);

          doInstall(theText);
          setEditorUnchanged(ed);
          ij.IJ.getInstance().setVisible(true);
        }
Exemplo n.º 4
0
  public void showEmbeddedMacros(int modifier) {

    showPopUp = ((modifier & KeyEvent.ALT_MASK) != 0);
    String macros_text = OJ.getData().getLinkedMacroText();
    if (macros_text == null) {
      macros_text = "";
    }
    Window theWindow = OJ.editorWindow;
    if (theWindow != null && theWindow.isShowing() && OJ.editor != null) {
      theWindow.setVisible(true);
      return;
    }

    String version = IJ.getFullVersion();
    Editor ed;
    if (version.compareToIgnoreCase("1.49i03") >= 0) {
      ed = new EditorOJ(16, 60, 0, Editor.MONOSPACED + Editor.MENU_BAR);
    } else {
      ed = new Editor(16, 60, 0, Editor.MONOSPACED + Editor.MENU_BAR);
    }
    ed.create("Embedded Macros", macros_text);
    JButton loadButton = new JButton("Install in ObjectJ menu");
    loadButton.addActionListener(LoadEmbeddedMacroAction);

    TextArea ta = ed.getTextArea();
    ed.remove(ta);
    ed.setLayout(new BorderLayout());
    JPanel panel1 = new JPanel();

    panel1.setLayout(new FlowLayout());
    loadButton.setFont(new Font("SansSerif", Font.PLAIN, 14));
    panel1.add(loadButton);

    JLabel myLabel = new JLabel("Macros Overview");

    if (showPopUp) {
      panel1.add(myLabel);
    }
    myLabel.setForeground(Color.blue);
    myLabel.setAutoscrolls(true);

    macrosPopup = new javax.swing.JPopupMenu();

    myLabel.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseEntered(java.awt.event.MouseEvent evt) {

            refreshPopupItems();
          }

          public void mouseReleased(java.awt.event.MouseEvent evt) {
            if ((evt.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
              ij.IJ.showStatus("Right-Click to navigate through macros");
              //                            + "\n-"
              //                            + "\nYou also can enter bookmark tags into the macro
              // text:"
              //                            + "\n //<<   bookmarks left part of line"
              //                            + "\n //>>   bookmarks right part of line");
            }
          }
        });

    myLabel.setComponentPopupMenu(macrosPopup);

    ed.add(BorderLayout.NORTH, panel1);
    ed.add(BorderLayout.CENTER, ta);

    Font monoFont = new Font("Monospaced", Font.PLAIN, 14);
    ta.setFont(monoFont);
    OJ.editor = ed;
    Frame[] frames = WindowManager.getNonImageWindows();
    Frame frame = frames[frames.length - 1];
    // ij.IJ.log(WindowManager.getFrontWindow().getTitle());
    // ij.IJ.log(frame.getTitle());//"Embedded Macros"
    // ij.IJ.log("---");//"Embedded Macros"
    OJ.editorWindow = WindowManager.getFrontWindow();
    refreshPopupItems();
    loadButton.transferFocus();
  }