Adds a tool to the toolbar. The 'toolTip' string is displayed in the status bar when the mouse is over the tool icon. The 'toolTip' string may include icon (http://imagej.net/ij/developer/macro/macros.html#tools). Returns the tool ID, or -1 if all tool slots are in use.
(String toolTip)
| 1771 | (http://imagej.net/ij/developer/macro/macros.html#tools). |
| 1772 | Returns the tool ID, or -1 if all tool slots are in use. */ |
| 1773 | public int addTool(String toolTip) { |
| 1774 | int index = toolTip.indexOf('-'); |
| 1775 | boolean hasIcon = index>=0 && (toolTip.length()-index)>4; |
| 1776 | int tool =-1; |
| 1777 | for (int i=CUSTOM1; i<=getNumTools()-2; i++) { |
| 1778 | if (names[i]==null || toolTip.startsWith(names[i])) { |
| 1779 | tool = i; |
| 1780 | break; |
| 1781 | } |
| 1782 | } |
| 1783 | if (tool==CUSTOM1) |
| 1784 | legacyMode = toolTip.startsWith("Select and Transform Tool"); //TrakEM2 |
| 1785 | if (tool==-1 && (nExtraTools<MAX_EXTRA_TOOLS)) { |
| 1786 | nExtraTools++; |
| 1787 | names[getNumTools()-1] = names[getNumTools()-2]; |
| 1788 | icons[getNumTools()-1] = icons[getNumTools()-2]; |
| 1789 | names[getNumTools()-2] = null; |
| 1790 | icons[getNumTools()-2] = null; |
| 1791 | ps = new Dimension(buttonWidth*NUM_BUTTONS-(buttonWidth-gapSize)+nExtraTools*buttonWidth, buttonHeight); |
| 1792 | IJ.getInstance().pack(); |
| 1793 | tool = getNumTools()-2; |
| 1794 | } |
| 1795 | if (tool==-1) { |
| 1796 | if (addingSingleTool) |
| 1797 | tool = getNumTools()-2; |
| 1798 | else |
| 1799 | return -1; |
| 1800 | } |
| 1801 | if (hasIcon) { |
| 1802 | icons[tool] = toolTip.substring(index+1); |
| 1803 | if (index>0 && toolTip.charAt(index-1)==' ') |
| 1804 | names[tool] = toolTip.substring(0, index-1); |
| 1805 | else |
| 1806 | names[tool] = toolTip.substring(0, index); |
| 1807 | } else { |
| 1808 | if (toolTip.endsWith("-")) |
| 1809 | toolTip = toolTip.substring(0, toolTip.length()-1); |
| 1810 | else if (toolTip.endsWith("- ")) |
| 1811 | toolTip = toolTip.substring(0, toolTip.length()-2); |
| 1812 | names[tool] = toolTip; |
| 1813 | } |
| 1814 | if (tool==current && (names[tool].indexOf("Action Tool")!=-1||names[tool].indexOf("Unused Tool")!=-1)) |
| 1815 | setTool(RECTANGLE); |
| 1816 | if (names[tool].endsWith(" Menu Tool")) |
| 1817 | installMenu(tool); |
| 1818 | if (IJ.debugMode) IJ.log("Toolbar.addTool: "+tool+" "+toolTip); |
| 1819 | return tool; |
| 1820 | } |
| 1821 | |
| 1822 | void installMenu(int tool) { |
| 1823 | Program pgm = macroInstaller.getProgram(); |
no test coverage detected