|
1 /* |
|
2 * Copyright (c) 2009-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 is the main class for StringItemTests1 tests. |
|
26 */ |
|
27 |
|
28 public class StringItemTests1 extends MIDlet implements CommandListener, ItemCommandListener |
|
29 { |
|
30 |
|
31 //the form to add the StringItems |
|
32 private Form stringItemForm = null; |
|
33 //the StringItem to test |
|
34 private StringItem si = null; |
|
35 //the StringItem types |
|
36 private String[] siTypes = {"PLAIN", "HYPERLINK", "BUTTON"}; |
|
37 |
|
38 // commands for StringItem type |
|
39 private Command cmdSI1 = new Command(siTypes[0], Command.SCREEN, 1); |
|
40 private Command cmdSI2 = new Command(siTypes[1], Command.SCREEN, 1); |
|
41 private Command cmdSI3 = new Command(siTypes[2], Command.SCREEN, 1); |
|
42 |
|
43 // Commands for label and text |
|
44 private Command cmd01 = new Command("Label and text", Command.SCREEN, 1); |
|
45 private Command cmd02 = new Command("Text, empty label", Command.SCREEN, 1); |
|
46 private Command cmd03 = new Command("Whitespace in label, normal text", Command.SCREEN, 1); |
|
47 private Command cmd04 = new Command("Very long text, normal label", Command.SCREEN, 1); |
|
48 private Command cmd09 = new Command("Very long label, normal text", Command.SCREEN, 1); |
|
49 // Commands for new line char tests |
|
50 private Command cmd05 = new Command("Label with 1 newline, normal text", Command.SCREEN, 1); |
|
51 private Command cmd06 = new Command("Label with 2 newline, normal text", Command.SCREEN, 1); |
|
52 private Command cmd07 = new Command("Text with 1 newline, normal label", Command.SCREEN, 1); |
|
53 private Command cmd08 = new Command("Text with 2 newline, normal label", Command.SCREEN, 1); |
|
54 // Commands for the StringItems |
|
55 private Command cmdItem1 = new Command("Itemcommand1", Command.ITEM, 1); |
|
56 private Command cmdItem2 = new Command("Itemcommand2", Command.ITEM, 1); |
|
57 |
|
58 /** |
|
59 * Signals the MIDlet to start and enter the Active state. |
|
60 */ |
|
61 protected void startApp() |
|
62 { |
|
63 stringItemForm = new Form("StringItem"); |
|
64 si = new StringItem("Label", "Text"); |
|
65 stringItemForm.append(si); |
|
66 stringItemForm.addCommand(cmdSI1); |
|
67 stringItemForm.addCommand(cmdSI2); |
|
68 stringItemForm.addCommand(cmdSI3); |
|
69 stringItemForm.addCommand(cmd01); |
|
70 stringItemForm.addCommand(cmd02); |
|
71 stringItemForm.addCommand(cmd03); |
|
72 stringItemForm.addCommand(cmd04); |
|
73 stringItemForm.addCommand(cmd05); |
|
74 stringItemForm.addCommand(cmd06); |
|
75 stringItemForm.addCommand(cmd07); |
|
76 stringItemForm.addCommand(cmd08); |
|
77 stringItemForm.addCommand(cmd09); |
|
78 stringItemForm.setCommandListener(this); |
|
79 Display.getDisplay(this).setCurrent(stringItemForm); |
|
80 } |
|
81 |
|
82 /** |
|
83 * Signals the MIDlet to terminate and enter the Destroyed state. |
|
84 * |
|
85 */ |
|
86 protected void destroyApp(boolean unconditional) |
|
87 { |
|
88 System.out.println("destroyApp is called"); |
|
89 } |
|
90 |
|
91 /** |
|
92 * Signals the MIDlet to stop and enter the Paused state. |
|
93 */ |
|
94 protected void pauseApp() |
|
95 { |
|
96 } |
|
97 |
|
98 /** |
|
99 * This method handles command invocations. |
|
100 * |
|
101 *@param c This is the command responsible for the event. |
|
102 *@param s Should be equal to this. |
|
103 */ |
|
104 public void commandAction(Command c, Displayable s) |
|
105 { |
|
106 if (c == cmdSI1) |
|
107 { |
|
108 // Plain type |
|
109 stringItemForm.deleteAll(); |
|
110 si = new StringItem("Label", "Text"); |
|
111 stringItemForm.append(si); |
|
112 } |
|
113 else if (c == cmdSI2) |
|
114 { |
|
115 // Hyperlink type |
|
116 stringItemForm.deleteAll(); |
|
117 si = new StringItem("Label", "Text", Item.HYPERLINK); |
|
118 stringItemForm.append(si); |
|
119 si.addCommand(cmdItem1); |
|
120 si.addCommand(cmdItem2); |
|
121 si.setItemCommandListener(this); |
|
122 } |
|
123 else if (c == cmdSI3) |
|
124 { |
|
125 // Button type |
|
126 stringItemForm.deleteAll(); |
|
127 si = new StringItem("Label", "Text", Item.BUTTON); |
|
128 stringItemForm.append(si); |
|
129 si.addCommand(cmdItem1); |
|
130 si.addCommand(cmdItem2); |
|
131 si.setItemCommandListener(this); |
|
132 } |
|
133 else if (c == cmd01) |
|
134 { |
|
135 si.setLabel("This is the label"); |
|
136 si.setText("This is the text."); |
|
137 } |
|
138 else if (c == cmd02) |
|
139 { |
|
140 si.setLabel(""); |
|
141 si.setText("This is the text."); |
|
142 } |
|
143 else if (c == cmd03) |
|
144 { |
|
145 si.setLabel(" "); |
|
146 si.setText("This is the text."); |
|
147 } |
|
148 else if (c == cmd04) |
|
149 { |
|
150 si.setLabel("This is the label"); |
|
151 si.setText("This is a very long text. " + |
|
152 "This is a very long text. " + |
|
153 "This is a very long text. " + |
|
154 "This is a very long text. " + |
|
155 "This is a very long text. " + |
|
156 "This is a very long text. " + |
|
157 "This is a very long text."); |
|
158 } |
|
159 else if (c == cmd05) |
|
160 { |
|
161 si.setLabel("Label with 1\nnewline char"); |
|
162 si.setText("This is the text."); |
|
163 } |
|
164 else if (c == cmd06) |
|
165 { |
|
166 si.setLabel("Label with 2\n\nnewline chars"); |
|
167 si.setText("This is the text."); |
|
168 } |
|
169 else if (c == cmd07) |
|
170 { |
|
171 si.setLabel("This is the label"); |
|
172 si.setText("Text with 1\nnewline char."); |
|
173 } |
|
174 else if (c == cmd08) |
|
175 { |
|
176 si.setLabel("This is the label"); |
|
177 si.setText("Text with 2\n\nnewline chars."); |
|
178 } |
|
179 else if (c == cmd09) |
|
180 { |
|
181 si.setText("This is the text."); |
|
182 si.setLabel("This is a very long label. " + |
|
183 "This is a very long label. " + |
|
184 "This is a very long label. " + |
|
185 "This is a very long label. " + |
|
186 "This is a very long label. " + |
|
187 "This is a very long label. " + |
|
188 "This is a very long label."); |
|
189 } |
|
190 } |
|
191 |
|
192 public void commandAction(Command c, Item i) |
|
193 { |
|
194 Alert alert = new Alert(c.getLabel(),"Command executed.",null, AlertType.INFO); |
|
195 Display.getDisplay(this).setCurrent(alert); |
|
196 } |
|
197 } |
|
198 |