Java Question Returning Value on BA.RaiseEvent method

Discussion in 'Libraries developers questions' started by walterf25, Aug 30, 2018.

  1. walterf25

    walterf25 Well-Known Member Licensed User

    Hi All, i'm trying to wrap a library and on one of the listeners for one of the properties i have the need to return an integer value, I was wondering if this is possible with any of the BA.RaiseEvent methods, if not is there any other way to accomplish this.

    Below is the java portion of the code that i'm trying to accomplish this task.

    Code:
    series1.setValueDependentColor(new ValueDependentColor<DataPoint>() {
                                @Override
                                
    public int get(DataPoint data) {
                                    BA.Log(
    "data.getx(): " + data.getX() + " " + "data.getY(): " + data.getY());
                                    
    return Color.rgb((int) data.getX()*255/4, (int) Math.abs(data.getY()*255/6), 100);
                                
    }
                            });
    As you can see the value returned is an Integer (color), but i would like to have the ability to customize the value returned, i would like to expose a method something like this:
    Code:
    Sub bar_SetColor(xdata as Double, ydata as Double) As Int
    Return RGB(xdata*255/4Abs(ydata*255/6100)
    End Sub
    And Basically pass the color value to the return value of the listener on the first code snippet above.

    So the final Java code would probably look something like this:

    Code:
    series1.setValueDependentColor(new ValueDependentColor<DataPoint>() {
                                @Override
                                
    public int get(DataPoint data) {
                                    BA.Log(
    "data.getx(): " + data.getX() + " " + "data.getY(): " + data.getY());
    int color;
    color = BA.RaiseEvent(
    null, EventName + "_setcolor", New Object[]{data.getX(), data.getY()});
                                    return color;
                                }
                            })
    Can this be done?

    Thanks all,
    Walter
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Yes. ba.raiseEvent returns the value returned from the event sub.

    You should however make sure that the value is not null before you cast it to an int. It will be null if the event cannot be raised for some reason.
     
    walterf25 likes this.
  3. walterf25

    walterf25 Well-Known Member Licensed User

    Hi @Erel thanks for your help, i was able to make it work just as you suggested, however because the listener gets called every time the user zooms in or out on the view (GraphView) things seem to slow down a lot, I can see the Event being raised but for some reason there is a huge lag, any ideas why this is and how to get around that?

    Thanks,
    Walter
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Have you tested it in release mode? How frequently is it called?
     
    walterf25 likes this.
  5. walterf25

    walterf25 Well-Known Member Licensed User

    In Release mode it works as expected, is it slow in Debug mode because of the debug engine, any way to make it work the same in debug and release mode?

    Thanks,
    Walter
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Clean the project (ctrl + P) and run it. It will be faster.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice