/** * Deactivates a RadioButton by name and sets the value of the RadioButton to the default value * -1. * * @param theName */ public RadioButton deactivate(String theName) { int n = _myRadioToggles.size(); for (int i = 0; i < n; i++) { Toggle t = _myRadioToggles.get(i); if (theName.equals(t.getName())) { t.deactivate(); _myValue = -1; updateValues(true); return this; } } return this; }
/** @param theIndex */ public RadioButton deactivate(int theIndex) { if (!isMultipleChoice && !noneSelectedAllowed) { return this; } if (theIndex < _myRadioToggles.size()) { Toggle t = _myRadioToggles.get(theIndex); if (t.isActive) { t.deactivate(); _myValue = -1; updateValues(true); } } return this; }
/** * {@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); }