Adds a popup menu. @param label the label @param items the menu items @param defaultItem the menu item initially selected
(String label, String[] items, String defaultItem)
| 816 | * @param defaultItem the menu item initially selected |
| 817 | */ |
| 818 | public void addChoice(String label, String[] items, String defaultItem) { |
| 819 | String label2 = label; |
| 820 | if (label2.indexOf('_')!=-1) |
| 821 | label2 = label2.replace('_', ' '); |
| 822 | Label fieldLabel = makeLabel(label2); |
| 823 | this.lastLabelAdded = fieldLabel; |
| 824 | if (addToSameRow) { |
| 825 | c.gridx = GridBagConstraints.RELATIVE; |
| 826 | addToSameRow = false; |
| 827 | } else { |
| 828 | c.gridx = 0; c.gridy++; |
| 829 | if (choice==null) |
| 830 | c.insets = getInsets(5, 0, 5, 0); |
| 831 | else |
| 832 | c.insets = getInsets(0, 0, 5, 0); |
| 833 | } |
| 834 | c.anchor = GridBagConstraints.EAST; |
| 835 | c.gridwidth = 1; |
| 836 | if (choice==null) { |
| 837 | choice = new Vector(4); |
| 838 | defaultChoiceIndexes = new Vector(4); |
| 839 | } |
| 840 | add(fieldLabel, c); |
| 841 | Choice thisChoice = new Choice(); |
| 842 | thisChoice.addKeyListener(this); |
| 843 | thisChoice.addItemListener(this); |
| 844 | for (int i=0; i<items.length; i++) |
| 845 | thisChoice.addItem(items[i]); |
| 846 | if (defaultItem!=null) |
| 847 | thisChoice.select(defaultItem); |
| 848 | else |
| 849 | thisChoice.select(0); |
| 850 | c.gridx = GridBagConstraints.RELATIVE; |
| 851 | c.anchor = GridBagConstraints.WEST; |
| 852 | add(thisChoice, c); |
| 853 | choice.addElement(thisChoice); |
| 854 | int index = thisChoice.getSelectedIndex(); |
| 855 | defaultChoiceIndexes.addElement(Integer.valueOf(index)); |
| 856 | if (IJ.recording() || macro) |
| 857 | saveLabel(thisChoice, label); |
| 858 | } |
| 859 | |
| 860 | /** Adds a message consisting of one or more lines of text. */ |
| 861 | public void addMessage(String text) { |
no test coverage detected