private void invokeField(final Object theObject, final Field theField, final Object theParam) {
   try {
     theField.set(theObject, theParam);
   } catch (IllegalAccessException e) {
     ControlP5.logger().warning(e.toString());
   }
 }
Esempio n. 2
0
 /** @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();
   }
 }
 private void printSecurityWarning(Exception e) {
   // AccessControlException required for applets.
   if (e.getClass().equals(AccessControlException.class)) {
     ControlP5.isApplet = true;
     ControlP5.logger()
         .warning(
             "You are probably running in applet mode.\n"
                 + "make sure fields and methods in your code are public.\n"
                 + e);
   }
 }
 private void printMethodError(Method theMethod, Exception theException) {
   if (!ignoreErrorMessage) {
     ControlP5.logger()
         .severe(
             "An error occured while forwarding a Controller event, please check your code at "
                 + theMethod.getName()
                 + (!setPrintStackTrace ? " " + "exception:  " + theException : ""));
     if (setPrintStackTrace) {
       theException.printStackTrace();
     }
   }
 }
Esempio n. 5
0
 /**
  * @exclude
  * @param theIndex
  */
 public RadioButton toggle(int theIndex) {
   // TODO
   // boolean itemState = ((Toggle)
   // _myRadioToggles.get(theIndex)).getState();
   // if (theIndex < _myRadioToggles.size()) {
   // Toggle t = ((Toggle) _myRadioToggles.get(theIndex));
   // if (t.isActive) {
   // t.deactivate();
   // _myValue = -1;
   // updateValues(true);
   // }
   // }
   ControlP5.logger().info("toggle() not yet implemented, working on it.");
   return this;
 }
Esempio n. 6
0
  /*
   * (non-Javadoc)
   */
  public void setup() {
    try {
      Thread.sleep(100);
    } catch (Exception e) {
    }
    if (_myRenderer.length() == 0) {
      size(width, height);
    } else {
      size(width, height, _myRenderer);
      ControlP5.logger().finer("ControlWindow: using renderer " + _myRenderer);
    }
    try {
      Thread.sleep(100);
    } catch (Exception e) {

    }
    frameRate(_myFrameRate);
  }
Esempio n. 7
0
 /**
  * Removes an item from the ListBox using the unique name of the item given when added to the
  * list.
  *
  * @see controlP5.ListBox#addItem(String,int)
  * @param theItemName String
  */
 public ListBox removeItem(String theItemName) {
   try {
     for (int i = items.size() - 1; i >= 0; i--) {
       if ((items.get(i)).name.equals(theItemName)) {
         items.remove(i);
       }
     }
     if ((buttons.size()) > items.size()) {
       String buttonName = ((Button) controllers.get(buttons.size())).getName();
       buttons.remove(cp5.getController(buttonName));
       controllers.remove(cp5.getController(buttonName));
       cp5.remove(buttonName);
     }
     updateScroll();
   } catch (Exception e) {
     ControlP5.logger().finer("ScrollList.removeItem exception:" + e);
   }
   return this;
 }
 private void invokeMethod(
     final Object theObject, final Method theMethod, final Object[] theParam) {
   try {
     if (theParam[0] == null) {
       theMethod.invoke(theObject, new Object[0]);
     } else {
       theMethod.invoke(theObject, theParam);
     }
   } catch (IllegalArgumentException e) {
     ControlP5.logger().warning(e.toString());
     /** TODO thrown when plugging a String method/field. */
   } catch (IllegalAccessException e) {
     printMethodError(theMethod, e);
   } catch (InvocationTargetException e) {
     printMethodError(theMethod, e);
   } catch (NullPointerException e) {
     printMethodError(theMethod, e);
   }
 }
  public void set(
      final Object theObject,
      final String theName,
      final int theType,
      final int theParameterType,
      final Class<?>[] theAcceptClassList) {
    _myObject = theObject;
    _myName = theName;
    _myType = theType;
    _myParameterType = theParameterType;
    _myAcceptClassList = theAcceptClassList;
    Class<?> myClass = theObject.getClass();

    /* check for methods */
    if (_myType == ControlP5Constants.METHOD) {
      try {
        Method[] myMethods = myClass.getDeclaredMethods();
        for (int i = 0; i < myMethods.length; i++) {
          if ((myMethods[i].getName()).equals(theName)) {
            if (myMethods[i].getParameterTypes().length == 1) {
              for (int j = 0; j < _myAcceptClassList.length; j++) {
                if (myMethods[i].getParameterTypes()[0] == _myAcceptClassList[j]) {
                  _myParameterClass = myMethods[i].getParameterTypes()[0];
                  break;
                }
              }
            } else if (myMethods[i].getParameterTypes().length == 0) {
              _myParameterClass = null;
              break;
            }
            break;
          }
        }
        Class<?>[] myArgs =
            (_myParameterClass == null) ? new Class[] {} : new Class[] {_myParameterClass};
        _myMethod = myClass.getDeclaredMethod(_myName, myArgs);
        _myMethod.setAccessible(true);
      } catch (SecurityException e) {
        printSecurityWarning(e);
      } catch (NoSuchMethodException e) {
        if (_myParameterClass != CallbackEvent.class) {
          ControlP5.logger()
              .warning(
                  " plug() failed. If function " + theName + " does exist, make it public. " + e);
        }
      }

      /* check for controlEvent */
    } else if (_myType == ControlP5Constants.EVENT) {
      try {

        _myMethod = _myObject.getClass().getMethod(_myName, new Class[] {_myEventMethodParameter});
        _myMethod.setAccessible(true);
        _myParameterClass = _myEventMethodParameter;
      } catch (SecurityException e) {
        printSecurityWarning(e);
      } catch (NoSuchMethodException e) {
        if (_myEventMethodParameter != CallbackEvent.class) {
          ControlP5.logger()
              .warning(
                  " plug() failed "
                      + _myParameterClass
                      + ". If function "
                      + theName
                      + " does exist, make it public. "
                      + e);
        }
      }
      /* check for fields */
    } else if (_myType == ControlP5Constants.FIELD) {

      Field[] myFields = ControlBroadcaster.getFieldsFor(myClass);

      for (int i = 0; i < myFields.length; i++) {
        if (myFields[i].getName().equals(_myName)) {
          _myParameterClass = myFields[i].getType();
        }
      }
      if (_myParameterClass != null) {
        /**
         * note. when running in applet mode. for some reason setAccessible(true) works for methods
         * but not for fields. theAccessControlException is thrown. therefore, make fields in your
         * code public.
         */
        try {
          _myField = myClass.getDeclaredField(_myName);
          try {
            _myField.setAccessible(true);
          } catch (java.security.AccessControlException e) {
            printSecurityWarning(e);
          }
          try {
            _myValue = (_myField.get(theObject));
          } catch (Exception ex) {
            printSecurityWarning(ex);
          }
        } catch (NoSuchFieldException e) {
          ControlP5.logger().warning(e.toString());
        }
      }
    }
  }
Esempio n. 10
0
 /**
  * @see controlP5.Tooltip#setWidth(int)
  * @param theHeight
  * @return Tooltip
  */
 public Tooltip setHeight(int theHeight) {
   ControlP5.logger().warning("Tooltip.setHeight is disabled with this version");
   _myHeight = theHeight;
   return this;
 }