public void controlEvent(ControlEvent theEvent) { // PulldownMenu is if type ControlGroup. // A controlEvent will be triggered from within the ControlGroup. // therefore you need to check the originator of the Event with // if (theEvent.isGroup()) // to avoid an error message from controlP5. if (theEvent.isGroup()) { if (theEvent.group().name() == "ruleChoiceList") { // println(theEvent.group().value()+" from "+theEvent.group()); selectedRule = PApplet.parseInt(theEvent.group().value()); // has to be here for the controlp5 library } } else if (theEvent.isController()) { // println(theEvent.controller().value()+" from "+theEvent.controller()); } // switch(theEvent.controller().id()) { // case(1): // myColorRect = (int)(theEvent.controller().value()); // break; // case(2): // myColorBackground = (int)(theEvent.controller().value()); // break; // case(3): // println(theEvent.controller().stringValue()); // break; // } }
public void controlEvent(ControlEvent theEvent) { // select com from list if (theEvent.isGroup() && theEvent.name().equals("portComList")) { println("Select portComList" + " value = " + theEvent.group().value()); // for debugging InitSerial(theEvent.group().value()); // initialize the serial port selected } }
public void controlEvent(ControlEvent theEvent) { if (theEvent.isGroup()) { if (theEvent.group().name() == "optionsbox") { for (int i = 0; i < theEvent.group().arrayValue().length; i++) { optionsArray[i] = (int) theEvent.group().arrayValue()[i]; } if (optionsArray[0] == 1) { translator = true; } else { translator = false; } } } }
/** * {@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); }
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; }
public void controlEvent(ControlEvent evt) { switch (evt.getEventType()) { case UPDATE: /* Perform an update - executes in a seperate thread!! */ performUpdate(evt.getSource(), evt.getIonMessage()); break; case SHUTDOWN: log.debug( "Shutting down DatasetAgentController {MessagingID=" + controlThread.getMessagingName() + "}"); boolean terminated = false; String terminationStatus = "Termination Successful!!"; try { processService.shutdown(); try { // Wait a while for existing tasks to terminate if (!(terminated = processService.awaitTermination(60, TimeUnit.SECONDS))) { processService.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!(terminated = processService.awaitTermination(60, TimeUnit.SECONDS))) { /* Failed to terminate!! */ terminationStatus = "Failed to Terminate Process!!"; } } } catch (InterruptedException ex) { // (Re-)Cancel if current thread also interrupted processService.shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); terminationStatus = "Control thread interrupted"; } } finally { if (terminated) { controlThread.terminate(); } } break; } }
/** @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(); } }
// Add control event into queue and wait for completion. // In case the control lock is free, this method also tries to apply the control change directly. private void queueControlEvent(ControlEvent ev) { // pollsetCtl blocks when a poll call is ongoing. This is very probable. // Therefore we let the polling thread do the pollsetCtl call. synchronized (controlQueue) { controlQueue.add(ev); // write byte to socketpair to force wakeup try { interrupt(ctlSp[1]); } catch (IOException x) { throw new AssertionError(x); } do { // Directly empty queue if no poll call is ongoing. if (controlLock.tryLock()) { try { processControlQueue(); } finally { controlLock.unlock(); } } else { try { // Do not starve in case the polling thread returned before // we could write to ctlSp[1] but the polling thread did not // release the control lock until we checked. Therefore, use // a timed wait for the time being. controlQueue.wait(100); } catch (InterruptedException e) { // ignore exception and try again } } } while (controlQueue.contains(ev)); } if (ev.error() != 0) { throw new AssertionError(); } }
// Process all events currently stored in the control queue. private void processControlQueue() { synchronized (controlQueue) { // On Aix it is only possible to set the event // bits on the first call of pollsetCtl. Later // calls only add bits, but cannot remove them. // Therefore, we always remove the file // descriptor ignoring the error and then add it. Iterator<ControlEvent> iter = controlQueue.iterator(); while (iter.hasNext()) { ControlEvent ev = iter.next(); pollsetCtl(pollset, PS_DELETE, ev.fd(), 0); if (!ev.removeOnly()) { ev.setError(pollsetCtl(pollset, PS_MOD, ev.fd(), ev.events())); } iter.remove(); } controlQueue.notifyAll(); } }
public void doRedrawFake(final Control control) { int evtId = ControlEvent.CONTROL_RESIZED; ControlEvent evt = new ControlEvent(control, evtId); evt.processEvent(); }
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()); } }
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; } } }
public void controlEvent(ControlEvent theEvent) { if (theEvent.isController()) { if (theEvent.controller().name() == "Clear Screen") { background(255); } if (theEvent.controller().name() == "Leaf Red") { leafRed = theEvent.controller().value(); } if (theEvent.controller().name() == "Leaf Blue") { leafBlue = theEvent.controller().value(); } if (theEvent.controller().name() == "Leaf Green") { leafGreen = theEvent.controller().value(); } if (theEvent.controller().name() == "Branch Random") { branchRandom = theEvent.controller().value(); } if (theEvent.controller().name() == "Leaf Random") { leafRandom = theEvent.controller().value(); } if (theEvent.controller().name() == "Leaf Size") { leafSize = theEvent.controller().value(); } if (theEvent.controller().name() == "Start Size") { startSize = theEvent.controller().value(); } } }