Ejemplo n.º 1
0
 /**
  * set the width of a radioButton/checkBox item. by default the width is 11px. in order to
  * recognize a custom width, the itemWidth has to be set before adding items to a
  * radioButton/checkBox.
  *
  * @param theItemWidth
  */
 public RadioButton setItemWidth(int theItemWidth) {
   itemWidth = theItemWidth;
   for (Toggle t : _myRadioToggles) {
     t.setWidth(theItemWidth);
   }
   updateLayout();
   return this;
 }
Ejemplo n.º 2
0
 public Toggle getItem(String theName) {
   for (Toggle t : _myRadioToggles) {
     if (theName.equals(t.getName())) {
       return t;
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 /**
  * set the height of a radioButton/checkBox item. by default the height is 11px. in order to
  * recognize a custom height, the itemHeight has to be set before adding items to a
  * radioButton/checkBox.
  *
  * @param theItemHeight
  */
 public RadioButton setItemHeight(int theItemHeight) {
   itemHeight = theItemHeight;
   for (Toggle t : _myRadioToggles) {
     t.setHeight(theItemHeight);
   }
   updateLayout();
   return this;
 }
Ejemplo n.º 4
0
 public RadioButton setLabelPadding(int thePaddingX, int thePaddingY) {
   _myPaddingX = thePaddingX;
   _myPaddingY = thePaddingY;
   for (Toggle t : _myRadioToggles) {
     t.getCaptionLabel().setPadding(thePaddingX, thePaddingY);
   }
   return this;
 }
Ejemplo n.º 5
0
 /**
  * @param theName
  * @param theValue
  * @return
  */
 public RadioButton addItem(final String theName, final float theValue) {
   Toggle t = cp5.addToggle(theName, 0, 0, itemWidth, itemHeight);
   t.getCaptionLabel().align(alignX, alignY).setPadding(_myPaddingX, _myPaddingY);
   t.setMode(ControlP5.DEFAULT);
   t.setImages(images[0], images[1], images[2]);
   t.setSize(images[0]);
   addItem(t, theValue);
   return this;
 }
Ejemplo n.º 6
0
 /**
  * Gets the state of an item - this can be true (for on) or false (for off) - by name.
  *
  * @param theName
  * @return
  */
 public boolean getState(String theName) {
   int n = _myRadioToggles.size();
   for (int i = 0; i < n; i++) {
     Toggle t = _myRadioToggles.get(i);
     if (theName.equals(t.getName())) {
       return t.getState();
     }
   }
   return false;
 }
Ejemplo n.º 7
0
 /**
  * Actives an item of the Radio button by name.
  *
  * @param theName
  */
 public RadioButton activate(String theName) {
   int n = _myRadioToggles.size();
   for (int i = 0; i < n; i++) {
     Toggle t = _myRadioToggles.get(i);
     if (theName.equals(t.getName())) {
       activate(i);
       return this;
     }
   }
   return this;
 }
Ejemplo n.º 8
0
 protected void updateValues(boolean theBroadcastFlag) {
   int n = _myRadioToggles.size();
   _myArrayValue = new float[n];
   for (int i = 0; i < n; i++) {
     Toggle t = ((Toggle) _myRadioToggles.get(i));
     _myArrayValue[i] = t.getValue();
   }
   if (theBroadcastFlag) {
     ControlEvent myEvent = new ControlEvent(this);
     cp5.getControlBroadcaster().broadcast(myEvent, ControlP5Constants.FLOAT);
   }
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /** @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;
 }
Ejemplo n.º 12
0
  /** @exclude */
  public void updateLayout() {
    int nn = 0;
    int xx = 0;
    int yy = 0;
    int n = _myRadioToggles.size();
    for (int i = 0; i < n; i++) {
      Toggle t = _myRadioToggles.get(i);
      set(t.position, xx, yy);

      xx += t.getWidth() + spacingColumn;
      nn++;
      if (nn == itemsPerRow) {
        nn = 0;
        _myWidth = xx;
        yy += t.getHeight() + spacingRow;
        xx = 0;
      } else {
        _myWidth = xx;
      }
    }
  }
Ejemplo n.º 13
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);
 }
Ejemplo n.º 14
0
 public RadioButton toUpperCase(boolean theValue) {
   for (Toggle t : _myRadioToggles) {
     t.getCaptionLabel().toUpperCase(theValue);
   }
   return this;
 }
Ejemplo n.º 15
0
 public RadioButton showLabels() {
   for (Toggle t : _myRadioToggles) {
     t.getCaptionLabel().setVisible(true);
   }
   return this;
 }
Ejemplo n.º 16
0
 public RadioButton hideLabels() {
   for (Toggle t : _myRadioToggles) {
     t.getCaptionLabel().setVisible(false);
   }
   return this;
 }
Ejemplo n.º 17
0
 public RadioButton setColorLabels(int theColor) {
   for (Toggle t : _myRadioToggles) {
     t.getCaptionLabel().setColor(theColor);
   }
   return this;
 }
Ejemplo n.º 18
0
 private void updateAlign() {
   for (Toggle t : _myRadioToggles) {
     t.getCaptionLabel().align(alignX, alignY);
   }
 }