コード例 #1
0
ファイル: ListBox.java プロジェクト: star003/sb
 /** @exclude {@inheritDoc} */
 @ControlP5.Invisible
 public void controlEvent(ControlEvent theEvent) {
   if (theEvent.getController() instanceof Button) {
     try {
       _myValue = theEvent.getController().getValue();
       ControlEvent myEvent = new ControlEvent(this);
       if (pulldown) {
         close();
         setLabel(theEvent.getController().getLabel());
       }
       for (ControlListener cl : _myControlListener) {
         cl.controlEvent(myEvent);
       }
       cp5.getControlBroadcaster().broadcast(myEvent, ControlP5Constants.FLOAT);
       theEvent.getController().onLeave();
       theEvent.getController().setIsInside(false);
       theEvent.getController().setMouseOver(false);
     } catch (Exception e) {
       ControlP5.logger().warning("ListBox.controlEvent exception:" + e);
     }
   } else {
     _myScrollValue = -(1 - theEvent.getValue());
     scroll();
   }
 }
コード例 #2
0
ファイル: KnobListener.java プロジェクト: Munzey/drumSeq
  public void controlEvent(ControlEvent theEvent) {
    char knobGroup = theEvent.getController().getName().charAt(0);
    int groupIndex = java.util.Arrays.asList(parent.getGroups()).indexOf(knobGroup);
    String knobType = theEvent.getController().getCaptionLabel().getText();
    int index = java.util.Arrays.asList(parent.getParams()).indexOf(knobType);

    // tempo
    if (theEvent.getId() == -1) {
      // TODO eliminate variable by having the conversion happen inside setValue
      parent.setTempo((int) ((60000 / theEvent.getValue()) * 4));
      parent.getTempoGl().setValue(parent.getTempo());
    }

    // master gain
    else if (theEvent.getId() == -2) {
      parent.setMasterVol(theEvent.getValue());
      parent.getGainGl().setValue(parent.getMasterVol());
    } else {
      switch (index) {
        case 0:
          // amp
          parent.getkAmp()[theEvent.getController().getId()] = theEvent.getValue();
          parent.getkGainGl()[theEvent.getId()].setValue(theEvent.getValue());
          break;
        case 1:
          // pitch
          parent.getKickPitchGlides()[theEvent.getId()].setValue(Pitch.mtof(theEvent.getValue()));
          break;
        case 2:
          // gate
          parent.getkGate()[theEvent.getController().getId()] = theEvent.getValue();
          break;
      }
    }
  }
コード例 #3
0
  public ControlBroadcaster broadcast(final ControlEvent theControlEvent, final int theType) {
    if (broadcast) {
      for (ControlListener cl : _myControlListeners) {
        cl.controlEvent(theControlEvent);
      }
      if (theControlEvent.isTab() == false && theControlEvent.isGroup() == false) {
        if (theControlEvent.getController().getControllerPlugList().size() > 0) {
          if (theType == ControlP5Constants.STRING) {
            for (ControllerPlug cp : theControlEvent.getController().getControllerPlugList()) {
              callTarget(cp, theControlEvent.getStringValue());
            }
          } else if (theType == ControlP5Constants.ARRAY) {

          } else {
            for (ControllerPlug cp : theControlEvent.getController().getControllerPlugList()) {
              if (cp.checkType(ControlP5Constants.EVENT)) {
                invokeMethod(cp.getObject(), cp.getMethod(), new Object[] {theControlEvent});
              } else {
                callTarget(cp, theControlEvent.getValue());
              }
            }
          }
        }
      }
      if (_myControlEventType == ControlP5Constants.METHOD) {
        invokeMethod(
            _myControlEventPlug.getObject(),
            _myControlEventPlug.getMethod(),
            new Object[] {theControlEvent});
      }
    }
    return this;
  }
コード例 #4
0
  public void controlEvent(ControlEvent theEvent) {
    // DropdownList is of type ControlGroup.
    // A controlEvent will be triggered from inside the ControlGroup class.
    // therefore you need to check the originator of the Event with
    // if (theEvent.isGroup())
    // to avoid an error message thrown by controlP5.

    /*  if (theEvent.getController().getName().equals("restart")) {
      paddles[0].points=0;
      paddles[1].points=0;
    }*/

    if (theEvent.isGroup()) {
      // check if the Event was triggered from a ControlGroup
      //  println("event from group : "+theEvent.getGroup().getValue()+" from
      // "+theEvent.getGroup());
      if (theEvent.getGroup().toString().equals("paddle1 [DropdownList]")) {
        println("paddle1 " + theEvent.getGroup().getValue());
        paddleSelector1 = translations[(int) theEvent.getGroup().getValue()];
        println(jointNames[paddleSelector1]);
      } else if (theEvent.getGroup().toString().equals("paddle2 [DropdownList]")) {
        println("paddle2 " + theEvent.getGroup().getValue());
        paddleSelector2 = translations[(int) theEvent.getGroup().getValue()];
        println(jointNames[paddleSelector2]);
      } else if (theEvent.getGroup().toString().equals("1_or_2_player [DropdownList]")) {
        if ((int) theEvent.getGroup().getValue() == 0) {
          onePlayer = true;
        } else {
          onePlayer = false;
        }
      } else if (theEvent.getGroup().toString().equals("speed [DropdownList]")) {
        if ((int) theEvent.getGroup().getValue() == 0) {
          ball.speed = new PVector(5, 5);
        } else if ((int) theEvent.getGroup().getValue() == 1) {
          ball.speed = new PVector(10, 10);
        } else if ((int) theEvent.getGroup().getValue() == 2) {
          ball.speed = new PVector(15, 15);
        }
      }
    } else if (theEvent.isController()) {
      println(
          "event from controller : "
              + theEvent.getController().getValue()
              + " from "
              + theEvent.getController());
    }
  }
コード例 #5
0
ファイル: RadioButton.java プロジェクト: cjsheedy/controlp5
 /**
  * {@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);
 }