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); } }
public void keyPressed(KeyEvent e) { // if (e.isConsumed()) return; int keyCode = e.getKeyCode(); IJ.setKeyDown(keyCode); hotkey = false; if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT) return; char keyChar = e.getKeyChar(); int flags = e.getModifiers(); if (IJ.debugMode) IJ.log( "keyPressed: code=" + keyCode + " (" + KeyEvent.getKeyText(keyCode) + "), char=\"" + keyChar + "\" (" + (int) keyChar + "), flags=" + KeyEvent.getKeyModifiersText(flags)); boolean shift = (flags & KeyEvent.SHIFT_MASK) != 0; boolean control = (flags & KeyEvent.CTRL_MASK) != 0; boolean alt = (flags & KeyEvent.ALT_MASK) != 0; boolean meta = (flags & KeyEvent.META_MASK) != 0; String cmd = null; ImagePlus imp = WindowManager.getCurrentImage(); boolean isStack = (imp != null) && (imp.getStackSize() > 1); if (imp != null && !control && ((keyChar >= 32 && keyChar <= 255) || keyChar == '\b' || keyChar == '\n')) { Roi roi = imp.getRoi(); if (roi instanceof TextRoi) { if ((flags & KeyEvent.META_MASK) != 0 && IJ.isMacOSX()) return; if (alt) { switch (keyChar) { case 'u': case 'm': keyChar = IJ.micronSymbol; break; case 'A': keyChar = IJ.angstromSymbol; break; default: } } ((TextRoi) roi).addChar(keyChar); return; } } // Handle one character macro shortcuts if (!control && !meta) { Hashtable macroShortcuts = Menus.getMacroShortcuts(); if (macroShortcuts.size() > 0) { if (shift) cmd = (String) macroShortcuts.get(new Integer(keyCode + 200)); else cmd = (String) macroShortcuts.get(new Integer(keyCode)); if (cmd != null) { // MacroInstaller.runMacroCommand(cmd); commandName = cmd; MacroInstaller.runMacroShortcut(cmd); return; } } } if ((!Prefs.requireControlKey || control || meta) && keyChar != '+') { Hashtable shortcuts = Menus.getShortcuts(); if (shift) cmd = (String) shortcuts.get(new Integer(keyCode + 200)); else cmd = (String) shortcuts.get(new Integer(keyCode)); } if (cmd == null) { switch (keyChar) { case '<': case ',': if (isStack) cmd = "Previous Slice [<]"; break; case '>': case '.': case ';': if (isStack) cmd = "Next Slice [>]"; break; case '+': case '=': cmd = "In [+]"; break; case '-': cmd = "Out [-]"; break; case '/': cmd = "Reslice [/]..."; break; default: } } if (cmd == null) { switch (keyCode) { case KeyEvent.VK_TAB: WindowManager.putBehind(); return; case KeyEvent.VK_BACK_SPACE: // delete if (deleteOverlayRoi(imp)) return; cmd = "Clear"; hotkey = true; break; // case KeyEvent.VK_BACK_SLASH: cmd=IJ.altKeyDown()?"Animation Options...":"Start // Animation"; break; case KeyEvent.VK_EQUALS: cmd = "In [+]"; break; case KeyEvent.VK_MINUS: cmd = "Out [-]"; break; case KeyEvent.VK_SLASH: case 0xbf: cmd = "Reslice [/]..."; break; case KeyEvent.VK_COMMA: case 0xbc: if (isStack) cmd = "Previous Slice [<]"; break; case KeyEvent.VK_PERIOD: case 0xbe: if (isStack) cmd = "Next Slice [>]"; break; case KeyEvent.VK_LEFT: case KeyEvent.VK_RIGHT: case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: // arrow keys if (imp == null) return; Roi roi = imp.getRoi(); if (IJ.shiftKeyDown() && imp == Orthogonal_Views.getImage()) return; boolean stackKey = imp.getStackSize() > 1 && (roi == null || IJ.shiftKeyDown()); boolean zoomKey = roi == null || IJ.shiftKeyDown() || IJ.controlKeyDown(); if (stackKey && keyCode == KeyEvent.VK_RIGHT) cmd = "Next Slice [>]"; else if (stackKey && keyCode == KeyEvent.VK_LEFT) cmd = "Previous Slice [<]"; else if (zoomKey && keyCode == KeyEvent.VK_DOWN && !ignoreArrowKeys(imp) && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "Out [-]"; else if (zoomKey && keyCode == KeyEvent.VK_UP && !ignoreArrowKeys(imp) && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "In [+]"; else if (roi != null) { if ((flags & KeyEvent.ALT_MASK) != 0) roi.nudgeCorner(keyCode); else roi.nudge(keyCode); return; } break; case KeyEvent.VK_ESCAPE: abortPluginOrMacro(imp); return; case KeyEvent.VK_ENTER: WindowManager.toFront(this); return; default: break; } } if (cmd != null && !cmd.equals("")) { commandName = cmd; if (cmd.equals("Fill") || cmd.equals("Draw")) hotkey = true; if (cmd.charAt(0) == MacroInstaller.commandPrefix) MacroInstaller.runMacroShortcut(cmd); else { doCommand(cmd); keyPressedTime = System.currentTimeMillis(); lastKeyCommand = cmd; } } }