Search in sources :

Example 1 with MacroInstaller

use of ij.plugin.MacroInstaller in project imagej1 by imagej.

the class Menus method installStartupMacroSet.

void installStartupMacroSet() {
    if (macrosPath == null) {
        try {
            (new MacroInstaller()).installFromIJJar("/macros/StartupMacros.txt");
        } catch (Exception e) {
        }
        return;
    }
    String path = macrosPath + "StartupMacros.txt";
    File f = new File(path);
    if (!f.exists()) {
        path = macrosPath + "StartupMacros.ijm";
        f = new File(path);
        if (!f.exists()) {
            (new MacroInstaller()).installFromIJJar("/macros/StartupMacros.txt");
            return;
        }
    } else {
        if ("StartupMacros.fiji.ijm".equals(f.getName()))
            path = f.getPath();
    }
    String libraryPath = macrosPath + "Library.txt";
    f = new File(libraryPath);
    boolean isLibrary = f.exists();
    try {
        MacroInstaller mi = new MacroInstaller();
        if (isLibrary)
            mi.installLibrary(libraryPath);
        mi.installStartupMacros(path);
        nMacros += mi.getMacroCount();
    } catch (Exception e) {
    }
}
Also used : MacroInstaller(ij.plugin.MacroInstaller)

Example 2 with MacroInstaller

use of ij.plugin.MacroInstaller in project imagej1 by imagej.

the class Toolbar method installStartupMacros.

private void installStartupMacros() {
    resetTools();
    String path = IJ.getDir("macros") + "StartupMacros.txt";
    File f = new File(path);
    if (!f.exists()) {
        path = IJ.getDir("macros") + "StartupMacros.ijm";
        f = new File(path);
    }
    if (!f.exists()) {
        path = IJ.getDir("macros") + "StartupMacros.fiji.ijm";
        f = new File(path);
    }
    if (!f.exists()) {
        IJ.error("StartupMacros not found in\n \n" + IJ.getDir("macros"));
        return;
    }
    if (IJ.shiftKeyDown()) {
        IJ.open(path);
        IJ.setKeyUp(KeyEvent.VK_SHIFT);
    } else {
        try {
            MacroInstaller mi = new MacroInstaller();
            mi.installFile(path);
        } catch (Exception ex) {
        }
    }
}
Also used : MacroInstaller(ij.plugin.MacroInstaller) File(java.io.File)

Example 3 with MacroInstaller

use of ij.plugin.MacroInstaller in project imagej1 by imagej.

the class Toolbar method installToolsetTool.

// install tool from ImageJ/macros/toolsets
private boolean installToolsetTool(String name) {
    String path = IJ.getDir("macros") + "toolsets" + File.separator + name + ".ijm";
    if (!((new File(path)).exists())) {
        name = name.replaceAll(" ", "_");
        path = IJ.getDir("macros") + "toolsets" + File.separator + name + ".ijm";
    }
    String text = IJ.openAsString(path);
    if (text == null || text.startsWith("Error"))
        return false;
    new MacroInstaller().installSingleTool(text);
    return true;
}
Also used : MacroInstaller(ij.plugin.MacroInstaller) File(java.io.File)

Example 4 with MacroInstaller

use of ij.plugin.MacroInstaller in project TrakEM2 by trakem2.

the class ProjectToolbar method setProjectToolbar.

/**
 * Set macro buttons for TrakEM2 in ImageJ's toolbar
 */
public static synchronized void setProjectToolbar() {
    if (null == instance)
        instance = new ProjectToolbar();
    // check if macros are installed already
    MacroInstaller installer = new MacroInstaller();
    boolean toolbar_present = false;
    try {
        java.awt.event.ActionListener[] al = ij.Menus.getMacrosMenu().getActionListeners();
        MacroInstaller minst = null;
        for (int j = al.length - 1; j > -1; j--) {
            if (al[j] instanceof MacroInstaller) {
                minst = (MacroInstaller) al[j];
                break;
            }
        }
        if (null != minst) {
            java.lang.reflect.Field f_macroNames = MacroInstaller.class.getDeclaredField("macroNames");
            f_macroNames.setAccessible(true);
            Object ob = f_macroNames.get(minst);
            if (null != ob) {
                String[] macroNames = (String[]) ob;
                if (null == macroNames)
                    return;
                if (macroNames.length > 3 && null != macroNames[0] && 0 == macroNames[0].indexOf("Select and Transform") && null != macroNames[1] && 0 == macroNames[1].indexOf("Freehand") && null != macroNames[2] && 0 == macroNames[2].indexOf("Pen") && null != macroNames[3] && 0 == macroNames[3].indexOf("Align")) {
                    toolbar_present = true;
                }
            }
        }
    } catch (Exception e) {
        // the above is not thread safe, will fail many times because the Display being show is also trying to set the toolbar
        Utils.log2("Can't check if toolbar is in place.");
    // IJError.print(e);
    // if it fails, toolbar_present still is false and thus will result in the macros being installed again.
    }
    // sort of a constructor: an embedded macro set
    if (!toolbar_present) {
        int tool = Toolbar.getToolId();
        final StringBuilder sb_tools = new StringBuilder();
        sb_tools.append("macro 'Select and Transform Tool-C000L2242L2363L3494L35b5L46c6L4797L48a8L49b9L5a6aL8acaL5b6bL9bdbL5c5cLacdcLbdcd' {\ncall('ini.trakem2.utils.ProjectToolbar.toolChanged', 'SELECT');\n}\n").append("macro 'Freehand Tool-C000Lb0c0La1d1L92e2L83f3L74f4L65e5L56d6L47c7L38b8L29a9L2a2aL4a9aL1b2bL5b8bL1c1cL6c7cL0d1dL5d6dL0e0eL3e5eL0f3f' {\ncall('ini.trakem2.utils.ProjectToolbar.toolChanged', 'PENCIL');\n}\n").append("macro 'Pen Tool-C000L8080L7191L7292L6363L8383La3a3L6464L8484Lb4b4L5555L8585Lb5b5L4646L8686Lc6c6L4747Lc7c7L3838Ld8d8L4949Lc9c9L4a4aLcacaL5b5bLbbbbL5c5cLbcbcL4dcdL5e5eLbebeL5fbf' {\ncall('ini.trakem2.utils.ProjectToolbar.toolChanged', 'PEN');\n}\n").append("macro 'Brush Tool - C037La077Ld098L6859L4a2fL2f4fL3f99L5e9bL9b98L6888L5e8dL888c' {\ncall('ini.trakem2.utils.ProjectToolbar.toolChanged', 'BRUSH');\n}\n");
        // another call to install erases the previous, so it needs all at the same time
        installer.install(sb_tools.toString());
        Toolbar.getInstance().setTool(tool);
    }
}
Also used : MacroInstaller(ij.plugin.MacroInstaller)

Example 5 with MacroInstaller

use of ij.plugin.MacroInstaller in project imagej1 by imagej.

the class Toolbar method itemStateChanged.

public void itemStateChanged(ItemEvent e) {
    CheckboxMenuItem item = (CheckboxMenuItem) e.getSource();
    String previousName = getToolName();
    if (item == rectItem || item == roundRectItem || item == rotatedRectItem) {
        if (item == roundRectItem)
            rectType = ROUNDED_RECT_ROI;
        else if (item == rotatedRectItem)
            rectType = ROTATED_RECT_ROI;
        else
            rectType = RECT_ROI;
        repaintTool(RECTANGLE);
        showMessage(RECTANGLE);
        ImagePlus imp = WindowManager.getCurrentImage();
        Roi roi = imp != null ? imp.getRoi() : null;
        if (roi != null && roi.getType() == Roi.RECTANGLE)
            roi.setCornerDiameter(rectType == ROUNDED_RECT_ROI ? arcSize : 0);
        if (!previousName.equals(getToolName()))
            IJ.notifyEventListeners(IJEventListener.TOOL_CHANGED);
    } else if (item == ovalItem || item == ellipseItem || item == brushItem) {
        if (item == brushItem)
            ovalType = BRUSH_ROI;
        else if (item == ellipseItem)
            ovalType = ELLIPSE_ROI;
        else
            ovalType = OVAL_ROI;
        repaintTool(OVAL);
        showMessage(OVAL);
        if (!previousName.equals(getToolName()))
            IJ.notifyEventListeners(IJEventListener.TOOL_CHANGED);
    } else if (item == pointItem || item == multiPointItem) {
        multiPointMode = item == multiPointItem;
        Prefs.multiPointMode = multiPointMode;
        repaintTool(POINT);
        showMessage(POINT);
        if (!previousName.equals(getToolName()))
            IJ.notifyEventListeners(IJEventListener.TOOL_CHANGED);
    } else if (item == straightLineItem) {
        lineType = LINE;
        arrowMode = false;
        setTool2(LINE);
        showMessage(LINE);
    } else if (item == polyLineItem) {
        lineType = POLYLINE;
        setTool2(POLYLINE);
        showMessage(POLYLINE);
    } else if (item == freeLineItem) {
        lineType = FREELINE;
        setTool2(FREELINE);
        showMessage(FREELINE);
    } else if (item == arrowItem) {
        lineType = LINE;
        arrowMode = true;
        setTool2(LINE);
        showMessage(LINE);
    } else {
        String label = item.getLabel();
        String cmd = item.getActionCommand();
        boolean isTool = cmd.equals("Tool") || cmd.equals("Plugin Tool");
        if (!(label.equals("Help...") || label.equals("Remove Custom Tools")) && !isTool && !label.endsWith("Tool") && !label.endsWith("Tool "))
            currentSet = label;
        if (isTool) {
            if (// built in tool
            cmd.equals("Tool"))
                installBuiltinTool(label);
            else
                // plugin or macro tool in ImageJ/plugins/Tools
                IJ.run(label);
            return;
        }
        String path;
        if (label.equals("Remove Custom Tools")) {
            removeTools();
        } else if (label.equals("Restore Startup Tools")) {
            removeTools();
            installStartupMacros();
        } else if (label.equals("Help...")) {
            IJ.showMessage("Tool Switcher and Loader", "Use this drop down menu to switch to alternative\n" + "macro toolsets or to load additional plugin tools.\n" + "The toolsets listed in the menu are located\n" + "in the ImageJ/macros/toolsets folder and the\n" + "plugin tools are the ones installed in the\n" + "Plugins>Tools submenu.\n" + " \n" + "Hold the shift key down while selecting a\n" + "toolset to view its source code.\n" + " \n" + "More macro toolsets are available at\n" + "  <" + IJ.URL + "/macros/toolsets/>\n" + " \n" + "Plugin tools can be downloaded from\n" + "the Tools section of the Plugins page at\n" + "  <" + IJ.URL + "/plugins/>\n");
            return;
        } else if (label.endsWith("*")) {
            // load from ij.jar
            MacroInstaller mi = new MacroInstaller();
            label = label.substring(0, label.length() - 1) + ".txt";
            path = "/macros/" + label;
            if (IJ.shiftKeyDown())
                showCode(label, mi.openFromIJJar(path));
            else {
                resetTools();
                mi.installFromIJJar(path);
            }
        } else {
            // load from ImageJ/macros/toolsets
            if (label.equals("Startup Macros")) {
                installStartupMacros();
                return;
            } else if (label.endsWith(" "))
                path = IJ.getDir("macros") + "toolsets" + File.separator + label.substring(0, label.length() - 1) + ".ijm";
            else
                path = IJ.getDir("macros") + "toolsets" + File.separator + label + ".txt";
            try {
                if (IJ.shiftKeyDown()) {
                    IJ.open(path);
                    IJ.setKeyUp(KeyEvent.VK_SHIFT);
                } else
                    new MacroInstaller().run(path);
            } catch (Exception ex) {
            }
        }
    }
}
Also used : MacroInstaller(ij.plugin.MacroInstaller)

Aggregations

MacroInstaller (ij.plugin.MacroInstaller)7 File (java.io.File)3 MouseListener (java.awt.event.MouseListener)1