|
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 StringItemTests2 extends MIDlet implements CommandListener, ItemCommandListener |
|
29 { |
|
30 |
|
31 //the form to add the StringItems |
|
32 private Form stringItemForm = null; |
|
33 //the main form |
|
34 private Form mainForm = null; |
|
35 //the StringItem to test |
|
36 private StringItem si = null; |
|
37 //list for StringItem types |
|
38 private ChoiceGroup cgType = null; |
|
39 //list for labels |
|
40 private ChoiceGroup cgLabel = null; |
|
41 //list for texts |
|
42 private ChoiceGroup cgText = null; |
|
43 //the StringItem types |
|
44 private String[] siTypes = {"PLAIN", "HYPERLINK", "BUTTON"}; |
|
45 private String[] siLabels = {"empty", "Short label", "This is a very long label that might not fit on the screen."}; |
|
46 private String[] siStrings = |
|
47 { |
|
48 "1 This fits on one line.", |
|
49 "2 This is one short paragraph that should fit on 2 lines.", |
|
50 "3 This is one longer paragraph that might take about 3 lines in the device, depends on screen size.", |
|
51 "4 This paragraph\nhas one linefeed.", |
|
52 "5 This is a somewhat longer paragraph that might take about three lines.\nHere was a linefeed.", |
|
53 "6TheWrappingBasedOnCharacterBoundariesCanBeTestedWithThisLineOfText." |
|
54 }; |
|
55 |
|
56 private Command cmdAdd = new Command("Add item", Command.SCREEN, 1); |
|
57 private Command cmdForward = new Command("Switch form", Command.SCREEN, 1); |
|
58 // Command to go back to main form |
|
59 private Command cmdBack = new Command("Back", Command.BACK, 1); |
|
60 // Command to clear the test form |
|
61 private Command cmdClear = new Command("Clear form", Command.SCREEN, 1); |
|
62 |
|
63 // Commands for the StringItems |
|
64 private Command cmdItem1 = new Command("Itemcommand1", Command.ITEM, 1); |
|
65 private Command cmdItem2 = new Command("Itemcommand2", Command.ITEM, 1); |
|
66 |
|
67 /** |
|
68 * Signals the MIDlet to start and enter the Active state. |
|
69 */ |
|
70 protected void startApp() |
|
71 { |
|
72 stringItemForm = new Form("StringItem"); |
|
73 mainForm = new Form("Main"); |
|
74 cgType = new ChoiceGroup("Type:", ChoiceGroup.POPUP, siTypes, null); |
|
75 cgLabel = new ChoiceGroup("Label:", ChoiceGroup.POPUP, siLabels, null); |
|
76 cgText = new ChoiceGroup("Text:", ChoiceGroup.POPUP, siStrings, null); |
|
77 |
|
78 mainForm.append(cgType); |
|
79 mainForm.append(cgLabel); |
|
80 mainForm.append(cgText); |
|
81 |
|
82 mainForm.addCommand(cmdAdd); |
|
83 mainForm.addCommand(cmdForward); |
|
84 mainForm.setCommandListener(this); |
|
85 stringItemForm.addCommand(cmdBack); |
|
86 stringItemForm.addCommand(cmdClear); |
|
87 stringItemForm.setCommandListener(this); |
|
88 Display.getDisplay(this).setCurrent(mainForm); |
|
89 } |
|
90 |
|
91 /** |
|
92 * Signals the MIDlet to terminate and enter the Destroyed state. |
|
93 * |
|
94 */ |
|
95 protected void destroyApp(boolean unconditional) |
|
96 { |
|
97 System.out.println("destroyApp is called"); |
|
98 } |
|
99 |
|
100 /** |
|
101 * Signals the MIDlet to stop and enter the Paused state. |
|
102 */ |
|
103 protected void pauseApp() |
|
104 { |
|
105 } |
|
106 |
|
107 /** |
|
108 * This method handles command invocations. |
|
109 * |
|
110 *@param c This is the command responsible for the event. |
|
111 *@param s Should be equal to this. |
|
112 */ |
|
113 public void commandAction(Command c, Displayable s) |
|
114 { |
|
115 if (c == cmdAdd) |
|
116 { |
|
117 // Create correct type of stringitem |
|
118 int index = cgType.getSelectedIndex(); |
|
119 if (index == 0) |
|
120 si = new StringItem("", "", Item.PLAIN); |
|
121 else |
|
122 { |
|
123 if (index == 1) |
|
124 si = new StringItem("", "", Item.HYPERLINK); |
|
125 else if (index == 2) |
|
126 si = new StringItem("", "", Item.BUTTON); |
|
127 si.addCommand(cmdItem1); |
|
128 si.addCommand(cmdItem2); |
|
129 si.setItemCommandListener(this); |
|
130 } |
|
131 |
|
132 // Set the label |
|
133 index = cgLabel.getSelectedIndex(); |
|
134 if (index == 0) |
|
135 si.setLabel(""); |
|
136 else |
|
137 si.setLabel(cgLabel.getString(index)); |
|
138 // Set the text |
|
139 index = cgText.getSelectedIndex(); |
|
140 si.setText(cgText.getString(index)); |
|
141 stringItemForm.append(si); |
|
142 Display.getDisplay(this).setCurrent(stringItemForm); |
|
143 } |
|
144 |
|
145 else if (c == cmdBack) |
|
146 { |
|
147 Display.getDisplay(this).setCurrent(mainForm); |
|
148 } |
|
149 else if (c == cmdClear) |
|
150 { |
|
151 stringItemForm.deleteAll(); |
|
152 } |
|
153 else if (c == cmdForward) |
|
154 { |
|
155 Display.getDisplay(this).setCurrent(stringItemForm); |
|
156 } |
|
157 } |
|
158 |
|
159 public void commandAction(Command c, Item i) |
|
160 { |
|
161 Alert alert = new Alert(c.getLabel(),"Command executed.",null, AlertType.INFO); |
|
162 Display.getDisplay(this).setCurrent(alert); |
|
163 } |
|
164 } |
|
165 |