Exemple #1
0
 /**
  * @param theToggle
  * @param theValue
  * @return
  */
 public RadioButton addItem(final Toggle theToggle, final float theValue) {
   theToggle.setGroup(this);
   theToggle.isMoveable = false;
   theToggle.setInternalValue(theValue);
   theToggle.isBroadcast = false;
   _myRadioToggles.add(theToggle);
   updateLayout();
   getColor().copyTo(theToggle);
   theToggle.addListener(this);
   updateValues(false);
   cp5.removeProperty(theToggle);
   return this;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  *
  * @exclude
  */
 @ControlP5.Invisible
 @Override
 public void controlEvent(ControlEvent theEvent) {
   if (!isMultipleChoice) {
     if (noneSelectedAllowed == false && theEvent.getController().getValue() < 1) {
       if (theEvent.getController() instanceof Toggle) {
         Toggle t = ((Toggle) theEvent.getController());
         boolean b = t.isBroadcast();
         t.setBroadcast(false);
         t.setState(true);
         t.setBroadcast(b);
         return;
       }
     }
     _myValue = -1;
     int n = _myRadioToggles.size();
     for (int i = 0; i < n; i++) {
       Toggle t = _myRadioToggles.get(i);
       if (!t.equals(theEvent.getController())) {
         t.deactivate();
       } else {
         if (t.isOn) {
           _myValue = t.internalValue();
         }
       }
     }
   }
   if (_myPlug != null) {
     try {
       Method method = _myPlug.getClass().getMethod(_myPlugName, int.class);
       method.invoke(_myPlug, (int) _myValue);
     } catch (SecurityException ex) {
       ex.printStackTrace();
     } catch (NoSuchMethodException ex) {
       ex.printStackTrace();
     } catch (IllegalArgumentException ex) {
       ex.printStackTrace();
     } catch (IllegalAccessException ex) {
       ex.printStackTrace();
     } catch (InvocationTargetException ex) {
       ex.printStackTrace();
     }
   }
   updateValues(true);
 }