Example #1
0
 /**
  * Adds a popup menu.
  *
  * @param label the label
  * @param items the menu items
  * @param defaultItem the menu item initially selected
  */
 public void addChoice(String label, String[] items, String defaultItem) {
   String label2 = label;
   if (label2.indexOf('_') != -1) label2 = label2.replace('_', ' ');
   Label theLabel = makeLabel(label2);
   c.gridx = 0;
   c.gridy = y;
   c.anchor = GridBagConstraints.EAST;
   c.gridwidth = 1;
   if (choice == null) {
     choice = new Vector(4);
     defaultChoiceIndexes = new Vector(4);
     c.insets = getInsets(5, 0, 5, 0);
   } else c.insets = getInsets(0, 0, 5, 0);
   grid.setConstraints(theLabel, c);
   add(theLabel);
   Choice thisChoice = new Choice();
   thisChoice.addKeyListener(this);
   thisChoice.addItemListener(this);
   for (int i = 0; i < items.length; i++) thisChoice.addItem(items[i]);
   if (defaultItem != null) thisChoice.select(defaultItem);
   else thisChoice.select(0);
   c.gridx = 1;
   c.gridy = y;
   c.anchor = GridBagConstraints.WEST;
   grid.setConstraints(thisChoice, c);
   add(thisChoice);
   choice.addElement(thisChoice);
   int index = thisChoice.getSelectedIndex();
   defaultChoiceIndexes.addElement(new Integer(index));
   if (Recorder.record || macro) saveLabel(thisChoice, label);
   y++;
 }
Example #2
0
 /** Returns the index of the selected item in the next popup menu. */
 public int getNextChoiceIndex() {
   if (choice == null) return -1;
   Choice thisChoice = (Choice) (choice.elementAt(choiceIndex));
   int index = thisChoice.getSelectedIndex();
   if (macro) {
     String label = (String) labels.get((Object) thisChoice);
     String oldItem = thisChoice.getSelectedItem();
     int oldIndex = thisChoice.getSelectedIndex();
     String item = Macro.getValue(macroOptions, label, oldItem);
     if (item != null && item.startsWith("&")) // value is macro variable
     item = getChoiceVariable(item);
     thisChoice.select(item);
     index = thisChoice.getSelectedIndex();
     if (index == oldIndex && !item.equals(oldItem)) {
       // is value a macro variable?
       Interpreter interp = Interpreter.getInstance();
       String s = interp != null ? interp.getStringVariable(item) : null;
       if (s == null)
         IJ.error(getTitle(), "\"" + item + "\" is not a valid choice for \"" + label + "\"");
       else item = s;
     }
   }
   if (recorderOn) {
     int defaultIndex = ((Integer) (defaultChoiceIndexes.elementAt(choiceIndex))).intValue();
     if (!(smartRecording && index == defaultIndex)) {
       String item = thisChoice.getSelectedItem();
       if (!(item.equals("*None*") && getTitle().equals("Merge Channels")))
         recordOption(thisChoice, thisChoice.getSelectedItem());
     }
   }
   choiceIndex++;
   return index;
 }
 {
   clientStatus.add("Online");
   clientStatus.add("Offline");
   clientStatus.add("Busy");
   clientStatus.select("Offline");
   clientStatus.addItemListener(
       new ItemListener() {
         public void itemStateChanged(ItemEvent e) {
           new Thread("icqtest/chooser control handler") {
             public void run() {
               try {
                 if (clientStatus.getSelectedItem().equals("Online")) {
                   if (plugin.getClientStatus(getMyLoginId())
                       == org.jcq2k.MessagingNetwork.STATUS_OFFLINE) login();
                   plugin.setClientStatus(
                       getMyLoginId(), org.jcq2k.MessagingNetwork.STATUS_ONLINE);
                 } else if (clientStatus.getSelectedItem().equals("Busy")) {
                   if (plugin.getClientStatus(getMyLoginId())
                       == org.jcq2k.MessagingNetwork.STATUS_OFFLINE) login();
                   plugin.setClientStatus(getMyLoginId(), org.jcq2k.MessagingNetwork.STATUS_BUSY);
                 } else if (clientStatus.getSelectedItem().equals("Offline")) {
                   if (plugin.getClientStatus(getMyLoginId())
                       != org.jcq2k.MessagingNetwork.STATUS_OFFLINE)
                     plugin.setClientStatus(
                         getMyLoginId(), org.jcq2k.MessagingNetwork.STATUS_OFFLINE);
                 } else {
                   org.jcq2k.util.joe.Lang.ASSERT_FALSE("invalid clientStatus.getSelectedItem()");
                 }
               } catch (Throwable tr) {
                 printException(tr);
               }
             }
           }.start();
         }
       });
 }