Opens an example from the Help/Examples menu and runs if "Autorun Exampes" is checked.
(String name)
| 1030 | /** Opens an example from the Help/Examples menu |
| 1031 | and runs if "Autorun Exampes" is checked. */ |
| 1032 | public static boolean openExample(String name) { |
| 1033 | boolean isJava = name.endsWith(".java"); |
| 1034 | boolean isJavaScript = name.endsWith(".js"); |
| 1035 | boolean isBeanShell = name.endsWith(".bsh"); |
| 1036 | boolean isPython = name.endsWith(".py"); |
| 1037 | boolean isMacro = name.endsWith(".ijm"); |
| 1038 | if (!(isMacro||isJava||isJavaScript||isBeanShell||isPython)) |
| 1039 | return false; |
| 1040 | boolean run = !isJava && !name.contains("_Tool") && Prefs.autoRunExamples; |
| 1041 | int rows = 24; |
| 1042 | int columns = 70; |
| 1043 | int options = MENU_BAR + RUN_BAR; |
| 1044 | if (isMacro) |
| 1045 | options += INSTALL_BUTTON; |
| 1046 | String text = null; |
| 1047 | Editor ed = new Editor(rows, columns, 0, options); |
| 1048 | String dir = "Macro/"; |
| 1049 | if (isJava) |
| 1050 | dir = "Java/"; |
| 1051 | else if (isJavaScript) |
| 1052 | dir = "JavaScript/"; |
| 1053 | else if (isBeanShell) |
| 1054 | dir = "BeanShell/"; |
| 1055 | else if (isPython) |
| 1056 | dir = "Python/"; |
| 1057 | String url = "http://wsr.imagej.net/download/Examples/"+dir+name; |
| 1058 | text = IJ.openUrlAsString(url); |
| 1059 | if (text.startsWith("<Error: ")) { |
| 1060 | IJ.error("Open Example", text); |
| 1061 | return true; |
| 1062 | } |
| 1063 | ed.create(name, text); |
| 1064 | if (run) |
| 1065 | ed.runMacro(false); |
| 1066 | return true; |
| 1067 | } |
| 1068 | |
| 1069 | protected void showMacroFunctions() { |
| 1070 | String url= "/developer/macro/functions.html"; |
no test coverage detected