2 * Copyright 2009 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.client.j2me;
\r
19 import javax.microedition.lcdui.Command;
\r
20 import javax.microedition.lcdui.CommandListener;
\r
21 import javax.microedition.lcdui.Display;
\r
22 import javax.microedition.lcdui.Displayable;
\r
23 import javax.microedition.lcdui.List;
\r
26 * The Menu form simply adds Command Listener functionality
\r
27 * to the standard List User Interface component.
\r
29 * @author Simon Flannery (simon.flannery@gmail.com)
\r
31 final class Menu extends List implements CommandListener {
\r
33 private final ZXingMIDlet zXingMIDlet;
\r
34 private final Command cancelCommand;
\r
35 private final Command barcodeCommand;
\r
38 * Creates a new Search List and initialises all components.
\r
40 * @param parent The Parent ZXing MIDlet.
\r
41 * @param title The title of the List.
\r
42 * @param item The caption of the item action Command.
\r
44 Menu(ZXingMIDlet parent, String title, String item) {
\r
45 super(title, IMPLICIT); // Set the title of the form
\r
46 zXingMIDlet = parent;
\r
47 // Build the UI components
\r
48 cancelCommand = new Command("Cancel", Command.CANCEL, 0);
\r
49 barcodeCommand = new Command(item, Command.ITEM, 0);
\r
50 addCommand(cancelCommand);
\r
51 addCommand(barcodeCommand);
\r
52 setCommandListener(this);
\r
56 * A convenience method for getting the selected option item.
\r
58 * @return The selected option represented as a String. If no option is
\r
59 * selected, then the empty string is returned.
\r
61 public String getSelectedString() {
\r
63 if (getSelectedIndex() != -1) {
\r
64 result = getString(getSelectedIndex());
\r
70 * A convenience method for removing all items from the list.
\r
71 * While the size of the list does not equal zero, the first item of the list is deleted.
\r
73 public void clear() {
\r
74 while (size() != 0) { // Delete the first-most element until there is no first-most element
\r
80 * CommandListener Required Implementation for capturing soft key presses.
\r
81 * This is where all call back methods (of the MIDlet) are serviced.
\r
83 * @param command The command requiring attention.
\r
84 * @param displayable The Display.
\r
86 public void commandAction(Command command, Displayable displayable) {
\r
87 if (command == cancelCommand) { /* Detecting the soft key press. */
\r
88 Display.getDisplay(zXingMIDlet).setCurrent(zXingMIDlet.getCanvas());
\r
89 } else if (command == barcodeCommand || command == SELECT_COMMAND) {
\r
90 if (getSelectedIndex() != -1) {
\r
91 zXingMIDlet.itemRequest();
\r