How to take data from a ControlP5 scrollable list, and use it to select a row in spreadsheet?

edited March 2017 in Library Questions

Hello I'm trying to make a program which calculates values which it gets from a spreadsheet. I'm using a ControlP5 scrollable list to show all the possible selection. Each item in the list represents a row in the spreadsheet. To each row there is 7 columns.

So my question is how do i let processing know or rather code, that the item selected in the list is a row in the spreadsheet? It's very poorly explained i know, but i will try to explain further if need! Thank you so much in advance!

A simplified version of my code:

`

    import controlP5.*;
    import java.util.*;

    ControlP5 cp5;

    ScrollableList initialBodyList;

    Button butDeltaVplanet;

    Table Planeter;

    Textfield required_delta_V;

    void setup() {
      size(500, 500);
      cp5 = new ControlP5(this);

       Planeter = loadTable("DatasheetPlanets.csv", "header");

      butDeltaVplanet = cp5.addButton("Calculate required Delta V")
        .setPosition(300, 50)
        .setColorForeground(#EA0037)
        .setColorActive(#FF4343)
        .setSize(130, 30);
      List body = Arrays.asList("Kerbol", "Moho", "Eve", "     Gilly", "Kerbin", "     Mun", "     Minmus", "Duna", "     Ike", "Dres", "Jool", "     Laythe", "     Vall", "     Tylo", "     Bop", "     Pol", "Eeloo");

      initialBodyList = cp5.addScrollableList("Initial body")
        .setPosition(70, 50)
        .setSize(200, 300)
        .setBarHeight(30)
        .setItemHeight(20)
        .setBackgroundColor(#EA0037)
        .setColorForeground(#EA0037)
        .setColorActive(#FF4343)
        .addItems(body)
        .setOpen(false);

      required_delta_V = cp5.addTextfield("Required Delta V m/s")
        .setPosition(300, 120)
        .setSize(130, 30);


      ControlP5.printPublicMethodsFor(Textfield.class);
    }

    void draw() {
      background(200);
    }

    public void controlEvent(ControlEvent theEvent) {

      if (theEvent.isFrom(butDeltaVplanet)) {

        int planet1 = Planeter.getRow(3).getInt("DeltaVtoKerbinorbit");

        int planet2 = Planeter.getRow(4).getInt("DeltaVtoKerbinorbit");

        float deltaV = 0;

        deltaV = planet1 + planet2;

        required_delta_V.setText("   " + deltaV);
      }
    }`

Answers

Sign In or Register to comment.