/* Machine-made version of this file copyright (c) 2005 Somusar */ /* Derived from samples that are Copyright (c) 2003, Nokia. All rights reserved */ package com.series60.examples.rms.shopping; import javax.microedition.lcdui.*; import javax.microedition.rms.*; import java.io.*; /** * UI to edit the details of a PlumbingShoppingItem. * * The implementation is discussed in the package documentation for * {@link com.series60.examples.rms.shopping} . * * @author Nokia * @version 1 */ public class PlumbingEditItemScreen extends Form { /** Maximum number of characters in each text field. */ private static final int TEXT_FIELD_MAX_SIZE = 30; /** Reference to the parent midlet. */ private PlumbingShoppingListMIDlet midlet; /** Graphical component. */ private TextField itemName; /** Graphical component. */ private TextField itemQuantity; /** The item being editted. */ private PlumbingShoppingItem item; /** * Constructor. * After construction, a call to editItem() is expected before the EditItemScreen is displayed. * *@param midlet The parent ShoppingListMIDlet. */ public PlumbingEditItemScreen(PlumbingShoppingListMIDlet midlet) { super("Plumbing list"); this.midlet = midlet; itemQuantity = new TextField("Quantity", "", TEXT_FIELD_MAX_SIZE, TextField.NUMERIC); itemName = new TextField("Item", "", TEXT_FIELD_MAX_SIZE, TextField.ANY); append(itemQuantity); append(itemName); //the parent ShoppingListMIDlet acts as the CommandListener for //this component, and also handles adding the Commands. } /** * Starts editing an item. Any changes will be saved to the item itself, * not a copy. * *@param item The item to edit; */ public void editItem(PlumbingShoppingItem item) { int quantity = item.getQuantity(); this.item = item; itemName.setString(item.getName()); if (quantity > 0) itemQuantity.setString(""+quantity); else itemQuantity.setString(""); } /** * Saves the details into the original item, and returns it. */ public PlumbingShoppingItem saveChanges() { item.setDetails(itemName.getString(), Integer.parseInt(itemQuantity.getString())); return item; } }