javauis/tsrc/fute/lcdui/Midp_TextBox_01/src/ScreenTextBoxTests.java
branchRCL_3
changeset 25 9ac0a0a7da70
child 78 71ad690e91f5
equal deleted inserted replaced
24:0fd27995241b 25:9ac0a0a7da70
       
     1 /*
       
     2 * Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19  * import midp classes.
       
    20  */
       
    21 import javax.microedition.midlet.*;
       
    22 import javax.microedition.lcdui.*;
       
    23 
       
    24 /**
       
    25  * This class is to test the below TextBox test cases:
       
    26  * 1.Layout
       
    27  * 2.TextBox constraints and T9 support
       
    28  *
       
    29  */
       
    30 
       
    31 public class ScreenTextBoxTests extends Form implements CommandListener
       
    32 {
       
    33 
       
    34     //parent MIDlet
       
    35     private static Midp_TextBox_01 parent = null;
       
    36 
       
    37     //the instance of this class
       
    38     private static ScreenTextBoxTests instance = null;
       
    39 
       
    40     //TextBox1 for testing test1
       
    41     private TextBox tb1 = null;
       
    42 
       
    43     //TextBox2 for testing test2
       
    44     private TextBox tb2 = null;
       
    45 
       
    46     //TextBox3 for testing test3
       
    47     private TextBox tb3 = null;
       
    48 
       
    49     //Form for testing test3 which contains textFields title and maxSize
       
    50     private Form formTest3 = null;
       
    51 
       
    52     //TextField to set TextBox title for test3
       
    53     private TextField titleT = null;
       
    54 
       
    55     //TextField to set TextBox maxSize for test3
       
    56     private TextField maxSizeT = null;
       
    57 
       
    58     //List which contains TextField constraints name as elements to test Test2
       
    59     private List listConstraints = null;
       
    60 
       
    61     //elements in the listConstraints
       
    62     private final String listElements[] =
       
    63     {
       
    64         "ANY", "URL", "PHONENUMBER", "NUMERIC",
       
    65         "EMAILADDR", "PASSWORD", "PWD|EMAILADDR",
       
    66         "PWD|NUMERIC", "PWD|PNO", "PWD|URL",
       
    67         "DECIMAL", "INITAL_CAPS_SENTENCE",
       
    68         "INITIAL_CAPS_WORD", "UNEDITABLE", "NON_PREDICTIVE",
       
    69         "SENSITIVE",
       
    70         "DECIMAL|PWD", "NUMERIC|UNEDITABLE",
       
    71         "DECIMAL|UNEDITABLE", "URL|UNEDITABLE", "EMAILADDR|UNEDITABLE",
       
    72         "PHONENUMBER|UNEDITABLE", "ANY|PWD|UNEDITABLE", "NUMERIC|PWD|UNEDITABLE",
       
    73         "DECIMAL|PWD|UNEDITABLE", "URL|PWD|UNEDITABLE", "EMAILADDR|PWD|UNDEDITABLE",
       
    74         "PNO|PWD|UNDEDITABLE"
       
    75     };
       
    76 
       
    77     //command for test3
       
    78     private Command cmdGetMaxSize = new Command("getMaxSize", Command.SCREEN, 1);
       
    79 
       
    80     //command to show tb3
       
    81     private Command cmdShowTextBox3 = new Command("ShowTextBox3", Command.SCREEN, 1);
       
    82 
       
    83     //Command for test1
       
    84     private Command cmdTest1 = new Command("Test1", Command.SCREEN, 1);
       
    85 
       
    86     //Command for test2
       
    87     private Command cmdTest2 = new Command("Test2", Command.SCREEN, 1);
       
    88 
       
    89     //Command for test3
       
    90     private Command cmdTest3 = new Command("Test3", Command.SCREEN, 1);
       
    91 
       
    92     //Command to set title to TextBox1
       
    93     private Command cmdNullT = new Command("Null Title", Command.OK, 1);
       
    94 
       
    95     //Command to set title to TextBox1
       
    96     private Command cmdEmptyT = new Command("Empty Title", Command.SCREEN, 1);
       
    97 
       
    98     //Command to set title to TextBox1
       
    99     private Command cmdBigT = new Command("Big Title", Command.SCREEN, 1);
       
   100 
       
   101     //Command to go Back to the previous Screen
       
   102     private Command cmdBack = new Command("Back", Command.BACK, 1);
       
   103 
       
   104     //Command to Ok whic is added to the listConstraints
       
   105     private Command cmdOk = new Command("Ok", Command.OK, 1);
       
   106 
       
   107     private Command cmdExit = new Command("Exit", Command.EXIT, 1);
       
   108 
       
   109     //maximum size which is specified while creating TextBox
       
   110     private final int MAX_SIZE = 100;
       
   111 
       
   112     /**
       
   113      *
       
   114      * @param parent The parent MIDlet of this class
       
   115      */
       
   116     public ScreenTextBoxTests(Midp_TextBox_01 parent)
       
   117     {
       
   118 
       
   119         //set the title of the form as the name of the MIDlet
       
   120         super(parent.getClass().getName());
       
   121         this.parent = parent;
       
   122 
       
   123         if (instance == null)
       
   124         {
       
   125             instance = this;
       
   126         }
       
   127         //add test commands
       
   128         instance.addCommand(cmdTest1);
       
   129         instance.addCommand(cmdTest2);
       
   130         instance.addCommand(cmdTest3);
       
   131         instance.addCommand(cmdExit);
       
   132 
       
   133         //create TextBox with constraints ANY
       
   134         tb3 = new TextBox("ANY", null, MAX_SIZE, TextField.ANY);
       
   135 
       
   136         //add cmdBack to tb2
       
   137         tb3.addCommand(cmdBack);
       
   138         tb3.setCommandListener(this);
       
   139         setCommandListener(this);
       
   140         show();
       
   141     }
       
   142 
       
   143     /**
       
   144      * creates and sets the current screen to be tb1
       
   145      */
       
   146     private void addTextBoxTest1()
       
   147     {
       
   148         //create TextBox
       
   149         tb1 = new TextBox("ANY", null, MAX_SIZE, TextField.ANY);
       
   150         //add commands to TextBox1
       
   151         Ticker t = new Ticker("Test1");
       
   152         tb1.setTicker(t);
       
   153         tb1.addCommand(cmdNullT);
       
   154         tb1.addCommand(cmdEmptyT);
       
   155         tb1.addCommand(cmdBigT);
       
   156         tb1.addCommand(cmdBack);
       
   157         tb1.setCommandListener(this);
       
   158         Display.getDisplay(parent).setCurrent(tb1);
       
   159     }
       
   160 
       
   161     /**
       
   162      * creates and sets the current screen to be tb2
       
   163      */
       
   164     private void addTextBoxTest2(String title, int constraints)
       
   165     {
       
   166         //create TextBox with constraints ANY
       
   167         tb2 = new TextBox(title, null, MAX_SIZE, constraints);
       
   168         //add cmdBack to tb2
       
   169         tb2.addCommand(cmdBack);
       
   170         tb2.setCommandListener(this);
       
   171         Display.getDisplay(parent).setCurrent(tb2);
       
   172     }
       
   173     private void addUneditableTextBoxTest2(String title, int constraints)
       
   174     {
       
   175         //create TextBox with constraints ANY
       
   176         tb2 = new TextBox(title, "Uneditable", MAX_SIZE, constraints);
       
   177         //add cmdBack to tb2
       
   178         tb2.addCommand(cmdBack);
       
   179         tb2.setCommandListener(this);
       
   180         Display.getDisplay(parent).setCurrent(tb2);
       
   181     }
       
   182 
       
   183     private void addNumericUneditableTextBoxTest2(String title, int constraints)
       
   184     {
       
   185         //create TextBox with constraints ANY
       
   186         tb2 = new TextBox(title, "123", MAX_SIZE, constraints);
       
   187         //add cmdBack to tb2
       
   188         tb2.addCommand(cmdBack);
       
   189         tb2.setCommandListener(this);
       
   190         Display.getDisplay(parent).setCurrent(tb2);
       
   191     }
       
   192     /**
       
   193      * Method to create and set the current screen
       
   194      * to be formTest3
       
   195      */
       
   196     private void addFormTest3()
       
   197     {
       
   198         //create form with title
       
   199         formTest3 = new Form("Test3");
       
   200         titleT = new TextField("Title", "ANY", 50, TextField.ANY);
       
   201         maxSizeT = new TextField("MaxSize", null, 6, TextField.NUMERIC);
       
   202         formTest3.append(titleT);
       
   203         formTest3.append(maxSizeT);
       
   204         formTest3.addCommand(cmdBack);
       
   205         formTest3.addCommand(cmdGetMaxSize);
       
   206         formTest3.addCommand(cmdShowTextBox3);
       
   207         formTest3.setCommandListener(this);
       
   208         Display.getDisplay(parent).setCurrent(formTest3);
       
   209     }
       
   210 
       
   211     /**
       
   212      * create the listConstraints with elements.
       
   213      * This is called when Test2 command is pressed
       
   214      */
       
   215     private void addListConstraints()
       
   216     {
       
   217         listConstraints = new List("ListConstraints", List.IMPLICIT, listElements, null);
       
   218         listConstraints.setCommandListener(this);
       
   219         listConstraints.addCommand(cmdBack);
       
   220         listConstraints.addCommand(cmdOk);
       
   221         Display.getDisplay(parent).setCurrent(listConstraints);
       
   222     }
       
   223 
       
   224     /**
       
   225      *  Show this screen
       
   226      */
       
   227     public static void show()
       
   228     {
       
   229         Display.getDisplay(parent).setCurrent(instance);
       
   230     }
       
   231 
       
   232     /**
       
   233      *  This method handles command invocations.
       
   234      *
       
   235      *@param  c  This is the command responsible for the event.
       
   236      *@param  s  Should be equal to this.
       
   237      */
       
   238     public void commandAction(Command c, Displayable s)
       
   239     {
       
   240         if (c == cmdTest1)
       
   241         {
       
   242             addTextBoxTest1();
       
   243             Display.getDisplay(parent).setCurrent(tb1);
       
   244         }
       
   245         else if (c == cmdNullT)
       
   246         {
       
   247             tb1.setTitle(null);
       
   248             Display.getDisplay(parent).setCurrent(tb1);
       
   249         }
       
   250         else if (c == cmdEmptyT)
       
   251         {
       
   252             tb1.setTitle(" ");
       
   253             Display.getDisplay(parent).setCurrent(tb1);
       
   254         }
       
   255         else if (c == cmdBigT)
       
   256         {
       
   257             tb1.setTitle("The title of this TextBox is too long to fit in to the" +
       
   258                          " reserved space");
       
   259             Display.getDisplay(parent).setCurrent(tb1);
       
   260         }
       
   261         else if (c == cmdBack)
       
   262         {
       
   263             if (s == tb1 || s == listConstraints || s == formTest3)
       
   264                 Display.getDisplay(parent).setCurrent(instance);
       
   265             else if (s == tb2)
       
   266                 Display.getDisplay(parent).setCurrent(listConstraints);
       
   267             else if (s == tb3)
       
   268                 Display.getDisplay(parent).setCurrent(formTest3);
       
   269         }
       
   270         else if (c == cmdTest2)
       
   271             addListConstraints();
       
   272         else if (c == cmdOk)
       
   273         {
       
   274             int index = listConstraints.getSelectedIndex();
       
   275             String element = listConstraints.getString(index);
       
   276             if (element.equals(listElements[0]))
       
   277                 addTextBoxTest2("ANY", TextField.ANY);
       
   278             else if (element.equals(listElements[1]))
       
   279                 addTextBoxTest2("URL", TextField.URL);
       
   280             else if (element.equals(listElements[2]))
       
   281                 addTextBoxTest2("PHONENUMBER", TextField.PHONENUMBER);
       
   282             else if (element.equals(listElements[3]))
       
   283                 addTextBoxTest2("NUMERIC", TextField.NUMERIC);
       
   284             else if (element.equals(listElements[4]))
       
   285                 addTextBoxTest2("EMAILADDR", TextField.EMAILADDR);
       
   286             else if (element.equals(listElements[5]))
       
   287                 addTextBoxTest2("PASSWORD", TextField.PASSWORD);
       
   288             else if (element.equals(listElements[6]))
       
   289                 addTextBoxTest2("PWD|EMAILADDR", TextField.PASSWORD|TextField.EMAILADDR);
       
   290             else if (element.equals(listElements[7]))
       
   291                 addTextBoxTest2("PWD|NUMERIC", TextField.PASSWORD|TextField.NUMERIC);
       
   292             else if (element.equals(listElements[8]))
       
   293                 addTextBoxTest2("PWD|PNO", TextField.PASSWORD|TextField.PHONENUMBER);
       
   294             else if (element.equals(listElements[9]))
       
   295                 addTextBoxTest2("PWD|URL", TextField.PASSWORD|TextField.URL);
       
   296             else if (element.equals(listElements[10]))
       
   297                 addTextBoxTest2("DECIMAL", TextField.DECIMAL);
       
   298             else if (element.equals(listElements[11]))
       
   299                 addTextBoxTest2("INITIAL_CAPS_SENTENCE", TextField.INITIAL_CAPS_SENTENCE);
       
   300             else if (element.equals(listElements[12]))
       
   301                 addTextBoxTest2("INITIAL_CAPS_WORD", TextField.INITIAL_CAPS_WORD);
       
   302             else if (element.equals(listElements[13]))
       
   303                 addUneditableTextBoxTest2("UNEDITABLE", TextField.UNEDITABLE);
       
   304             else if (element.equals(listElements[14]))
       
   305                 addTextBoxTest2("NON_PREDICTIVE", TextField.NON_PREDICTIVE);
       
   306             else if (element.equals(listElements[15]))
       
   307                 addTextBoxTest2("SENSITIVE", TextField.SENSITIVE);
       
   308 
       
   309             else if (element.equals(listElements[16]))
       
   310                 addTextBoxTest2("DECIMAL|PWD", TextField.DECIMAL|TextField.PASSWORD);
       
   311             else if (element.equals(listElements[17]))
       
   312                 addNumericUneditableTextBoxTest2("NUMERIC|UNEDITABLE", TextField.NUMERIC|TextField.UNEDITABLE);
       
   313             else if (element.equals(listElements[18]))
       
   314                 addNumericUneditableTextBoxTest2("DECIMAL|UNEDITABLE", TextField.DECIMAL|TextField.UNEDITABLE);
       
   315             else if (element.equals(listElements[19]))
       
   316                 addUneditableTextBoxTest2("URL|UNEDITABLE", TextField.URL|TextField.UNEDITABLE);
       
   317             else if (element.equals(listElements[20]))
       
   318                 addUneditableTextBoxTest2("EMAILADDR|UNEDITABLE", TextField.EMAILADDR|TextField.UNEDITABLE);
       
   319             else if (element.equals(listElements[21]))
       
   320                 addNumericUneditableTextBoxTest2("PHONENUMBER|UNEDITABLE", TextField.PHONENUMBER|TextField.UNEDITABLE);
       
   321 
       
   322             else if (element.equals(listElements[22]))
       
   323                 addUneditableTextBoxTest2("ANY|PWD|UNEDITABLE", TextField.ANY|TextField.PASSWORD|TextField.UNEDITABLE);
       
   324             else if (element.equals(listElements[23]))
       
   325                 addNumericUneditableTextBoxTest2("NUMERIC|PWD|UNEDITABLE", TextField.NUMERIC|TextField.PASSWORD|TextField.UNEDITABLE);
       
   326             else if (element.equals(listElements[24]))
       
   327                 addNumericUneditableTextBoxTest2("DECIMAL|PWD|UNEDITABLE", TextField.DECIMAL|TextField.PASSWORD|TextField.UNEDITABLE);
       
   328             else if (element.equals(listElements[25]))
       
   329                 addUneditableTextBoxTest2("URL|PWD|UNEDITABLE", TextField.URL|TextField.PASSWORD|TextField.UNEDITABLE);
       
   330             else if (element.equals(listElements[26]))
       
   331                 addUneditableTextBoxTest2("EMAILADDR|PWD|UNDEDITABLE", TextField.EMAILADDR|TextField.PASSWORD|TextField.UNEDITABLE);
       
   332             else if (element.equals(listElements[27]))
       
   333                 addNumericUneditableTextBoxTest2("PNO|PWD|UNDEDITABLE", TextField.PHONENUMBER|TextField.PASSWORD|TextField.UNEDITABLE);
       
   334         }
       
   335         else if (c == cmdTest3)
       
   336             addFormTest3();
       
   337         else if (c == cmdGetMaxSize)
       
   338         {
       
   339             String sz = maxSizeT.getString();
       
   340             if (sz.length() != 0)
       
   341                 tb3.setMaxSize(Integer.parseInt(sz));
       
   342             int mSize = tb3.getMaxSize();
       
   343             Alert a = new Alert("Max Size", new Integer(mSize).toString(),
       
   344                                 null, AlertType.INFO);
       
   345             a.setTimeout(Alert.FOREVER);
       
   346             Display.getDisplay(parent).setCurrent(a);
       
   347         }
       
   348         else if (c == cmdShowTextBox3)
       
   349         {
       
   350             tb3.setTitle(titleT.getString());
       
   351             Display.getDisplay(parent).setCurrent(tb3);
       
   352         }
       
   353         else if (c == cmdExit)
       
   354         {
       
   355             parent.destroyApp(false);
       
   356             parent.notifyDestroyed();
       
   357         }
       
   358     }
       
   359     //end method
       
   360 
       
   361 }