use of ij.plugin.MacroInstaller in project imagej1 by imagej.
the class Editor method installMacros.
void installMacros(String text, boolean installInPluginsMenu) {
String functions = Interpreter.getAdditionalFunctions();
if (functions != null && text != null) {
if (!(text.endsWith("\n") || functions.startsWith("\n")))
text = text + "\n" + functions;
else
text = text + functions;
}
installer = new MacroInstaller();
installer.setFileName(getTitle());
int nShortcutsOrTools = installer.install(text, macrosMenu);
if (installInPluginsMenu || nShortcutsOrTools > 0)
installer.install(null);
dontShowWindow = installer.isAutoRunAndHide();
currentMacroEditor = this;
}
use of ij.plugin.MacroInstaller in project TrakEM2 by trakem2.
the class ProjectToolbar method setImageJToolbar.
/**
* Restore ImageJ's toolbar.
*/
public static void setImageJToolbar() {
// remove mouse listener
MouseListener[] ml = Toolbar.getInstance().getMouseListeners();
for (int i = 0; i < ml.length; i++) {
if (ml[i].equals(instance)) {
Toolbar.getInstance().removeMouseListener(instance);
break;
}
}
// but checking whether the startupmacros.txt file exists
if (null == startup_macros) {
String macros_path = ij.Menus.getMacrosPath();
if (null != macros_path) {
File f = new File(macros_path);
if (f.isDirectory()) {
String[] mf = f.list();
for (int i = 0; i < mf.length; i++) {
if (mf[i].toLowerCase().equals("startupmacros.txt")) {
startup_macros = Utils.openTextFile(macros_path + "/" + mf[i]);
break;
}
}
}
}
}
// else, try to run
if (null == startup_macros && ImageJ.VERSION.compareTo("1.38a") >= 0) {
try {
/* // works locally, but won't on registered applets or java web start
Toolbar tb = Toolbar.getInstance();
Field f_sp = Toolbar.class.getDeclaredField("switchPopup");
f_sp.setAccessible(true);
PopupMenu popup = (PopupMenu)f_sp.get(tb);
MenuItem item = null;
for (int i=popup.getItemCount() -1; i>-1; i--) {
item = popup.getItem(i);
if (item.getLabel().equals("StartupMacros*")) {
break;
}
}
// simulate click
ItemEvent event = new ItemEvent((ItemSelectable)item,(int)System.currentTimeMillis(),item,1);
tb.itemStateChanged(event);
*/
// Wayne Rasband's solution:
MacroInstaller mi = new MacroInstaller();
String path = "/macros/StartupMacros.txt";
// mi.installFromIJJar(path); // fails absurdly on IJ < 1.38a despite the 'if' clause
java.lang.reflect.Method m = MacroInstaller.class.getDeclaredMethod("installFromIJJar", new Class[] {});
m.invoke(mi, new Object[] { path });
return;
} catch (Exception e) {
// e.printStackTrace();
if (null != IJ.getInstance() && IJ.getInstance().quitting()) {
Utils.log("Failed to restore ImageJ toolbar");
}
}
}
if (null != startup_macros) {
new MacroInstaller().install(startup_macros);
}
}
Aggregations