Package lejos.util

Examples of lejos.util.TextMenu


    private void fileMenu(File file)
    {
        String fileName = file.getName();
        String ext = getExtension(fileName);
        newScreen();
        TextMenu menu = new TextMenu(null, 2);
        menu.setTitle(fileName);
        if (ext.equals("nxj") || ext.equals("bin"))
        {
            menu.setItems(new String[]{"Execute program", "Set as Default", "Delete file"});
            switch(getSelection(menu, 0))
            {
                case 0:
                    try {
                        file.exec();
                    }
                    catch (FlashError fe)
                    {
                        msg("Invalid program");
                    }
                    break;
                case 1:
                    Settings.setProperty(defaultProgramProperty, getBaseName(fileName));
                    break;
                case 2:
                    deleteFile(file);
                    break;
            }
        }
        else if (ext.equals("wav"))
        {
            menu.setItems(new String[]{"Play sample", "Delete file"});
            switch (getSelection(menu, 0))
            {
                case 0:
                    Sound.playSample(file);
                    break;
                case 1:
                    deleteFile(file);
                    break;
            }
        }
        else
        {
            menu.setItems(new String[]{"Delete file"});
            switch (getSelection(menu, 0))
            {
                case 0:
                    deleteFile(file);
                    break;
View Full Code Here


            for (int i = 0; i < files.length && files[i] != null; i++)
                len++;
            String fileNames[] = new String[len];
            for (int i = 0; i < len; i++)
                fileNames[i] = files[i].getName();
            TextMenu menu = new TextMenu(fileNames, 1);
            selection = getSelection(menu, 0);
            if (selection >= 0)
                fileMenu(files[selection]);
        } while (selection >= 0);
    }
View Full Code Here

     */
    private void soundMenu()
    {
        String[] soundMenuData = new String[]{"Volume:    ", "Key click: "};
        String[] soundMenuData2 = new String[soundMenuData.length];
        TextMenu menu = new TextMenu(soundMenuData2, 2);
        int[][] Volumes =
        {
            {
                Sound.getVolume() / 10, 784, 250, 0
            },
            {
                Button.getKeyClickVolume() / 10, Button.getKeyClickTone(1), Button.getKeyClickLength(), 0
            }
        };
        int selection = 0;
        // Make a note of starting volumes so we know if it changes
        for (int i = 0; i < Volumes.length; i++)
            Volumes[i][3] = Volumes[i][0];
        // remember and Turn of tone for the enter key
        int tone = Button.getKeyClickTone(Button.ID_ENTER);
        Button.setKeyClickTone(Button.ID_ENTER, 0);
        do {
            newScreen("Sound");
            for (int i = 0; i < Volumes.length; i++)
                soundMenuData2[i] = soundMenuData[i] + formatVol(Volumes[i][0]);
            menu.setItems(soundMenuData2);
            selection = getSelection(menu, selection);
            if (selection >= 0)
            {
                Volumes[selection][0]++;
                Volumes[selection][0] %= 11;
View Full Code Here

     * @param prompt A description of the action about to be performed
     * @return 1=yes 0=no < 0 escape
     */
    private int getYesNo(String prompt)
    {
        TextMenu menu = new TextMenu(new String[]{"No", "Yes"}, 6, prompt);
        return getSelection(menu, 0);
    }
View Full Code Here

     * the default program usage.
     */
    private void systemMenu()
    {
        String[] menuData = {"Format", "", "Auto Run"};
        TextMenu menu = new TextMenu(null, 5);
        int selection = 0;
        do {
            newScreen("System");
            LCD.drawString("Flash", 0, 2);
            LCD.drawInt(File.freeMemory(), 6, 10, 2);
            LCD.drawString("RAM", 0, 3);
            LCD.drawInt((int) (Runtime.getRuntime().freeMemory()), 11, 3);
            LCD.drawString("Battery", 0, 4);
            int millis = Battery.getVoltageMilliVolt() + 50;
            LCD.drawInt((millis - millis % 1000) / 1000, 11, 4);
            LCD.drawString(".", 12, 4);
            LCD.drawInt((millis % 1000) / 100, 13, 4);
            if (Battery.isRechargeable())
                LCD.drawString("R", 15, 4);
            menuData[1] = "Sleep time: " + timeout;
            menu.setItems(menuData);
            selection = getSelection(menu, selection);
            switch (selection)
            {
                case 0:
                    if (getYesNo("Delete all files?") == 1)
View Full Code Here

     * Display the main system menu.
     * Allow the user to select File, Bluetooth, Sound, System operations.
     */
    private void mainMenu()
    {
        TextMenu menu = new TextMenu(new String[]
                {
                    "Run Default", "Files", "Bluetooth", "Sound", "System", "Version"
                }, 1);
        int selection;
        do
View Full Code Here

      {"P1", "P2", "P3", "P4", "P5",
       "Stop", "Beep",
       "A fwd", "A bwd", "B fwd",
       "B bwd", "C fwd", "C bwd",
       "Msg 1", "Msg 2", "Msg 3"}
    TextMenu menu = new TextMenu(menuItems,1,"RCX Remote");   
    int menu_item;
   
    do {
      menu_item = menu.select();
     
      if (menu_item >= 0 && menu_item <= 4) {
        link.runProgram(menu_item + 1);
      }
     
View Full Code Here

    String pressed = "pressed ";
    String released = "released";
   
      String[] viewItems = {"System", "Sensors", "Motors", "Exit"};
     
    TextMenu main = new TextMenu(viewItems, 1, "View Example");
   
    String[] sensorItems = {"Touch","Light(Floodlit)","Light(Ambient)","Sound DB","Sound DBA","RCX Light","Ultrasonic"};
   
    TextMenu pickSensor = new TextMenu(sensorItems, 1, "Pick Sensor");
   
    String[] sensorPorts = {"S1","S2","S3","S4"};
    TextMenu pickSensorPort = new TextMenu(sensorPorts, 1, "Pick Port");

    String[] motors = {"A","B","C","A&B","A&C","B&C"};
    TextMenu pickMotor = new TextMenu(motors,1,"Pick Motor");
   
    String[] motorMethods = {"forward","backward","flt","stop"};
    TextMenu operation = new TextMenu(motorMethods, 1, "Pick option");
   
    int selection;
   
    for(;;)
    {
      LCD.clear();
      selection = main.select();
     
      if (selection == -1 || selection == 3)
      {
        LCD.clear();
        LCD.drawString("Finished",3,4);
        LCD.refresh()
        return;
      }
     
      if (selection == 0) // System Info
      {
        LCD.clear();
        LCD.drawString(sys, 0, 0);
        LCD.drawString(batt, 0, 2);
        LCD.drawInt(Battery.getVoltageMilliVolt(), 4, 10, 2);
        LCD.drawString(tot, 0, 3);
          LCD.drawInt((int)(Runtime.getRuntime().totalMemory()), 5, 10, 3);
        LCD.drawString(free, 0, 4);
          LCD.drawInt((int)(Runtime.getRuntime().freeMemory()), 5, 10,4);
          LCD.refresh();
         
          Button.ESCAPE.waitForPressAndRelease();
      }
     
      if (selection == 1) // Sensors       
      {
        LCD.clear();
        int portId = pickSensorPort.select();
        if (portId < 0)
        {
          Button.ESCAPE.waitForPressAndRelease();
          continue;
        }

        LCD.clear();
        int sensor = pickSensor.select();       
        if (sensor < 0)
        {
          Button.ESCAPE.waitForPressAndRelease();
          continue;
        }
       
        LCD.clear();
        LCD.drawString(sensVal, 0, 0);       
        LCD.drawString(port, 0, 2);
        LCD.drawString(sensorPorts[portId],6,2);
        LCD.drawString(type, 0, 3);
        LCD.drawString(sensorItems[sensor],6,3);
        LCD.drawString(val,0,4);
       
        if (sensor == 0)
        {
          TouchSensor touch = new TouchSensor(SensorPort.PORTS[portId]);
         
          while (!Button.ESCAPE.isPressed())
          {
            if (touch.isPressed()) LCD.drawString(pressed,7,4);
            else LCD.drawString(released, 7, 4);
           
            LCD.refresh();
            Thread.sleep(100);
          }
        }
       
        if (sensor == 1 || sensor == 2)
        {
          LightSensor light = new LightSensor(SensorPort.PORTS[portId], sensor == 1);
         
          while (!Button.ESCAPE.isPressed())
          {
            LCD.drawInt(light.readValue(), 3, 7, 4);
           
            LCD.refresh();
            Thread.sleep(100);
          }
        }

        if (sensor == 3 || sensor == 4)
        {
          SoundSensor sound = new SoundSensor(SensorPort.PORTS[portId], sensor == 4);
         
          while (!Button.ESCAPE.isPressed())
          {
            LCD.drawInt(sound.readValue(), 3, 7, 4);
           
            LCD.refresh();
            Thread.sleep(100);
          }
        } 
       
        if (sensor == 5) // RCX Light Sensor
        {
          RCXLightSensor light = new RCXLightSensor(SensorPort.PORTS[portId]);
         
          while (!Button.ESCAPE.isPressed())
          {
            LCD.drawInt(light.readValue(), 3, 7, 4);
           
            LCD.refresh();
            Thread.sleep(100);
          }
        }
       
        if (sensor == 6) // Ultrasonic
        {
          UltrasonicSensor sonar = new UltrasonicSensor(SensorPort.PORTS[portId]);
         
          while (!Button.ESCAPE.isPressed())
          {
            LCD.drawInt(sonar.getDistance(), 3, 7, 4);
           
            LCD.refresh();
            Thread.sleep(100);
          }
        }
        Button.ESCAPE.waitForPressAndRelease();
      }
     
      if (selection == 2) // Motors
      {
        LCD.clear();
        int motor = pickMotor.select();       
        if (motor < 0)
        {
          Button.ESCAPE.waitForPressAndRelease();
          continue;
        }
       
        for(;;)
        {       
          LCD.clear();
          int op = operation.select();         
          if (op < 0)
          {
            Button.ESCAPE.waitForPressAndRelease();
            break;
          }
View Full Code Here

TOP

Related Classes of lejos.util.TextMenu

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.