0001: /*
0002: *
0003: * Copyright (c) 2007, Sun Microsystems, Inc.
0004: *
0005: * All rights reserved.
0006: *
0007: * Redistribution and use in source and binary forms, with or without
0008: * modification, are permitted provided that the following conditions
0009: * are met:
0010: *
0011: * * Redistributions of source code must retain the above copyright
0012: * notice, this list of conditions and the following disclaimer.
0013: * * Redistributions in binary form must reproduce the above copyright
0014: * notice, this list of conditions and the following disclaimer in the
0015: * documentation and/or other materials provided with the distribution.
0016: * * Neither the name of Sun Microsystems nor the names of its contributors
0017: * may be used to endorse or promote products derived from this software
0018: * without specific prior written permission.
0019: *
0020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0031: */
0032: package example.auction;
0033:
0034: import java.util.*;
0035:
0036: import javax.microedition.lcdui.*;
0037: import javax.microedition.lcdui.List;
0038: import javax.microedition.midlet.*;
0039:
0040: public class NewTicketAuction extends MIDlet implements CommandListener {
0041: // Wait for 2sec
0042: static final int DefaultTimeout = 2000;
0043: static final Command BACK_CMD = new Command("Back", Command.BACK, 1);
0044: static final Command SAVE_CMD = new Command("Save", Command.SCREEN,
0045: 2);
0046: static final Command NEXT_CMD = new Command("Next", Command.SCREEN,
0047: 2);
0048: static final Command SUBMIT_CMD = new Command("Submit",
0049: Command.ITEM, 2);
0050: static final Command AUCTION_CMD = new Command("Auction",
0051: Command.ITEM, 2);
0052: static final Command CANCEL_CMD = new Command("Cancel",
0053: Command.CANCEL, 1);
0054: static final Command STOP_CMD = new Command("Stop", Command.STOP, 1);
0055: static final Command EXIT_CMD = new Command("Exit", Command.EXIT, 1);
0056:
0057: // commands for Band Screen bandForm
0058: static final Command SHOW_CMD = new Command("Show Auctions",
0059: Command.SCREEN, 1);
0060: static final Command ADD_CMD = new Command("Add Bands",
0061: Command.SCREEN, 1);
0062: static final Command RMV_CMD = new Command("Remove Bands",
0063: Command.SCREEN, 2);
0064: static final Command SETTING_CMD = new Command("Settings",
0065: Command.SCREEN, 3);
0066:
0067: // commands for Auction Screen ticketList
0068: static final Command SHOW_INFO_CMD = new Command("Show More Info",
0069: Command.ITEM, 1);
0070: static final Command MAKE_BID_CMD = new Command("Make a Bid",
0071: Command.ITEM, 2);
0072: static final Command SET_ALERT_CMD = new Command("Set an Alert",
0073: Command.ITEM, 3);
0074:
0075: // command for Bid screen ticketForm
0076: static final Command BAND_CMD = new Command("Bands",
0077: Command.SCREEN, 1);
0078: Display display;
0079:
0080: /** user interface alert component. */
0081: Alert splashScreenAlert;
0082: Image splashScreen;
0083: boolean imageLoaded;
0084: Band band = new Band();
0085: Login login = new Login();
0086: TextBox addBand;
0087: RmBand rmBand = new RmBand();
0088: List mainMenu; // bandList, ticketList;
0089: List cateMenu; // bandList, ticketList;
0090: List ticketList; // bandList, ticketList;
0091: Ticker ticker;
0092: Alert notImpl;
0093: Alert savedMsg;
0094: Alert alertMsg;
0095: Form band_ticket_Form;
0096: Form ticketForm;
0097: Form enterForm;
0098: Form bidForm;
0099: Form submitMsg;
0100: TextField enterText;
0101: ChoiceGroup bandCg;
0102: ChoiceGroup auctionCg;
0103: StringItem auctionName;
0104: UpdateAlert updateAlert = new UpdateAlert();
0105: Gauge submitGauge;
0106: Timer TimerService;
0107: SetMenuForm setMenu2 = new SetMenuForm();
0108:
0109: // Band Name and Index number of the selected band in
0110: // Band Screen band_ticket_Form
0111: String _bandName;
0112: int _bandIndex = 0;
0113: private boolean firstTime;
0114:
0115: public NewTicketAuction() {
0116: display = Display.getDisplay(this );
0117: notImpl = new Alert("Sorry!!!", "Not Implemented", null, null);
0118:
0119: savedMsg = new Alert(null,
0120: "Your new settings have been saved!", null, null);
0121:
0122: alertMsg = new Alert(null, "Your alerts have been saved!",
0123: null, null);
0124:
0125: submitGauge = new Gauge("", false, 100, 0);
0126: submitMsg = new Form("Submitting bid...");
0127: submitMsg.append(submitGauge);
0128: submitMsg.addCommand(STOP_CMD);
0129: submitMsg.setCommandListener(this );
0130:
0131: ticker = new Ticker("");
0132: ticker.setString(band.toTickerString(null));
0133:
0134: band_ticket_Form = new Form("Welcome To Tickets");
0135:
0136: band_ticket_Form.addCommand(SHOW_INFO_CMD);
0137: band_ticket_Form.addCommand(MAKE_BID_CMD);
0138: band_ticket_Form.addCommand(SET_ALERT_CMD);
0139:
0140: band_ticket_Form.addCommand(ADD_CMD);
0141: band_ticket_Form.addCommand(RMV_CMD);
0142: band_ticket_Form.addCommand(SETTING_CMD);
0143: band_ticket_Form.addCommand(EXIT_CMD);
0144: band_ticket_Form.setCommandListener(this );
0145: band_ticket_Form.setTicker(ticker);
0146:
0147: // bandCg = new ChoiceGroup("Choose a Band", Choice.EXCLUSIVE);
0148: bandCg = new ChoiceGroup("Choose a Band", Choice.POPUP);
0149: band_ticket_Form.append(bandCg);
0150:
0151: String[] list = band.getList();
0152:
0153: for (int i = 0; i < list.length; i++) {
0154: bandCg.append(list[i], null);
0155: }
0156:
0157: String bandName = band.getName(bandCg.getSelectedIndex());
0158: auctionCg = new ChoiceGroup(bandName + " Auctions:",
0159: Choice.EXCLUSIVE);
0160: auctionCg.setLayout(Item.LAYOUT_EXPAND);
0161: band_ticket_Form.append(auctionCg);
0162: reconstructList(auctionCg, band.getTicketList(bandName));
0163: band_ticket_Form.setItemStateListener(new ItemStateListener() {
0164: public void itemStateChanged(Item item) {
0165: if (item instanceof ChoiceGroup) {
0166: ChoiceGroup obj = (ChoiceGroup) item;
0167:
0168: if (obj == bandCg) {
0169: int idx = obj.getSelectedIndex();
0170: String bandName = band.getName(idx);
0171: auctionCg.setLabel(bandName + " Auctions:");
0172: reconstructList(auctionCg, band
0173: .getTicketList(bandName));
0174: }
0175: }
0176: }
0177: });
0178:
0179: try {
0180: splashScreen = Image
0181: .createImage("/example/auction/images/splashScreen.png");
0182: imageLoaded = true;
0183: } catch (java.io.IOException ex) {
0184: }
0185:
0186: splashScreenAlert = new Alert("Welcome to Ticket Auction", "",
0187: splashScreen, AlertType.INFO);
0188: splashScreenAlert.setTimeout(DefaultTimeout);
0189:
0190: ticketForm = new Form("unknown");
0191: ticketForm.append("unknown");
0192: ticketForm.addCommand(BACK_CMD);
0193: ticketForm.addCommand(BAND_CMD);
0194: ticketForm.addCommand(MAKE_BID_CMD);
0195: ticketForm.addCommand(SET_ALERT_CMD);
0196: ticketForm.setCommandListener(this );
0197:
0198: enterText = new TextField("Tell me when bid reaches:", "", 10,
0199: TextField.DECIMAL);
0200:
0201: enterForm = new Form("Set an Alert");
0202: enterForm.append(enterText);
0203: enterForm.addCommand(BACK_CMD);
0204: enterForm.addCommand(SAVE_CMD);
0205: enterForm.setCommandListener(this );
0206:
0207: addBand = new TextBox("Add Bands, Bands:", "", 100,
0208: TextField.ANY);
0209: addBand.addCommand(BACK_CMD);
0210: addBand.addCommand(SAVE_CMD);
0211: addBand.setCommandListener(this );
0212: firstTime = true;
0213: }
0214:
0215: public void startApp() {
0216: if (firstTime) {
0217: display.setCurrent(splashScreenAlert, band_ticket_Form);
0218: firstTime = false;
0219: }
0220: }
0221:
0222: public void destroyApp(boolean unconditional) {
0223: }
0224:
0225: public void pauseApp() {
0226: }
0227:
0228: public void commandAction(Command c, Displayable s) {
0229: if (s instanceof Form) {
0230: Form obj = (Form) s;
0231:
0232: if (obj == band_ticket_Form) {
0233: int idx = auctionCg.getSelectedIndex();
0234: _bandIndex = idx;
0235:
0236: int bandIdx = bandCg.getSelectedIndex();
0237: String bandName = "";
0238:
0239: if (bandIdx >= 0) {
0240: bandName = band.getName(bandIdx);
0241: }
0242:
0243: _bandName = bandName;
0244:
0245: if (c == SHOW_INFO_CMD) {
0246: deleteFormItem(ticketForm);
0247: ticketForm.setTitle(band.getTicketDataTitle(
0248: bandName, idx));
0249: band.getTicketData(ticketForm, bandName, idx);
0250: display.setCurrent(ticketForm);
0251: } else if (c == MAKE_BID_CMD) {
0252: login.setBandAttributes(bandName, _bandIndex);
0253: deleteFormItem(login);
0254: login.append(login.id);
0255: login.id.setLabel("Enter Your ID:");
0256: login.append(login.pd);
0257: login.pd.setLabel("Enter PIN:");
0258: login.append(login.curBid);
0259: login.append(login.incBid);
0260: login.append(login.minBid);
0261: login.append(login.bidText);
0262: login.id.setString(null);
0263: login.pd.setString(null);
0264: login.bidText.setString(null);
0265: band
0266: .getTicketBidTitle(login, _bandName,
0267: _bandIndex);
0268: display.setCurrent(login);
0269: } else if (c == SET_ALERT_CMD) {
0270: display.setCurrent(enterForm);
0271: } else if (c == ADD_CMD) {
0272: display.setCurrent(addBand);
0273: } else if (c == RMV_CMD) {
0274: display.setCurrent(rmBand);
0275: } else if (c == SETTING_CMD) {
0276: display.setCurrent(setMenu2);
0277: } else if (c == EXIT_CMD) {
0278: notifyDestroyed();
0279: }
0280: } else if (obj == ticketForm) {
0281: if (c == BACK_CMD) {
0282: display.setCurrent(band_ticket_Form);
0283: } else if (c == BAND_CMD) {
0284: display.setCurrent(band_ticket_Form);
0285: } else if (c == MAKE_BID_CMD) {
0286: login.setBandAttributes(band.getName(bandCg
0287: .getSelectedIndex()), _bandIndex);
0288: deleteFormItem(login);
0289: login.append(login.id);
0290: login.id.setLabel("Enter Auction ID:");
0291: login.append(login.pd);
0292: login.pd.setLabel("Enter PIN:");
0293: login.append(login.curBid);
0294: login.append(login.incBid);
0295: login.append(login.minBid);
0296: login.append(login.bidText);
0297: login.id.setString(null);
0298: login.pd.setString(null);
0299: login.bidText.setString(null);
0300: band
0301: .getTicketBidTitle(login, _bandName,
0302: _bandIndex);
0303: display.setCurrent(login);
0304: } else if (c == SET_ALERT_CMD) {
0305: deleteFormItem(enterForm);
0306:
0307: int selectedBand = bandCg.getSelectedIndex();
0308: String ticketID = band.getTicketID(band
0309: .getName(selectedBand), login._bandIndex);
0310: enterForm.append(new StringItem("Auction:", band
0311: .getName(selectedBand)
0312: + " " + ticketID));
0313:
0314: String curBid = band.getCurrentBid(band
0315: .getName(selectedBand), login._bandIndex);
0316: enterForm.append(new StringItem("Current Bid:", "$"
0317: + curBid));
0318: enterForm.append(enterText);
0319: display.setCurrent(enterForm);
0320: }
0321: } else if (obj == enterForm) {
0322: if (c == BACK_CMD) {
0323: enterText.setString(null);
0324: display.setCurrent(band_ticket_Form);
0325: } else if (c == SAVE_CMD) {
0326: updateAlert
0327: .set(
0328: band.getName(bandCg
0329: .getSelectedIndex()),
0330: enterText.getString());
0331: display.setCurrent(alertMsg, band_ticket_Form);
0332: }
0333: } else if (obj == submitMsg) {
0334: if (c == STOP_CMD) {
0335: TimerService.cancel();
0336: display.setCurrent(login.confirm);
0337: }
0338: }
0339: } else if (s instanceof TextBox) {
0340: TextBox obj = (TextBox) s;
0341:
0342: if (obj == addBand) {
0343: if (c == BACK_CMD) {
0344: // display.setCurrent(setMenu);
0345: display.setCurrent(band_ticket_Form);
0346: } else if (c == SAVE_CMD) {
0347: updateBandList(addBand.getString());
0348: display.setCurrent(savedMsg, band_ticket_Form);
0349: }
0350: }
0351: }
0352: }
0353:
0354: void updateBandList(String list) {
0355: if (list.length() == 0) {
0356: return;
0357: }
0358:
0359: Vector vec = new Vector();
0360: int fidx = 0;
0361:
0362: while (true) {
0363: int idx = list.indexOf(',', fidx);
0364:
0365: if (idx == -1) {
0366: vec.addElement(list.substring(fidx));
0367:
0368: break;
0369: }
0370:
0371: vec.addElement(list.substring(fidx, idx));
0372: fidx = idx + 1;
0373: }
0374:
0375: for (int i = 0; i < vec.size(); i++) {
0376: String str = (String) vec.elementAt(i);
0377: int j = 0;
0378: int len = str.length();
0379:
0380: for (; j < len; j++) {
0381: if (str.charAt(j) != ' ') {
0382: break;
0383: }
0384: }
0385:
0386: if (j == len) {
0387: continue;
0388: }
0389:
0390: if (j == 0) {
0391: band.add(str);
0392: } else {
0393: band.add(str.substring(j));
0394: }
0395: }
0396:
0397: reconstructBandTicketForm(band.getList());
0398: rmBand.reset();
0399: }
0400:
0401: void reconstructBandTicketForm(String[] items) {
0402: if ((items == null) || (items.length == 0)) {
0403: bandCg.deleteAll();
0404: auctionCg.setLabel(null);
0405: auctionCg.deleteAll();
0406:
0407: return;
0408: }
0409:
0410: reconstructList(bandCg, items);
0411:
0412: bandCg.setSelectedIndex(0, true);
0413:
0414: String bandName = band.getName(bandCg.getSelectedIndex());
0415: auctionCg.setLabel(bandName + " Auctions:");
0416: reconstructList(auctionCg, band.getTicketList(bandName));
0417: }
0418:
0419: void reconstructList(Choice list, String[] items) {
0420: list.deleteAll();
0421:
0422: for (int i = 0; i < items.length; i++) {
0423: list.append(items[i], null);
0424: }
0425: }
0426:
0427: void deleteFormItem(Form f) {
0428: int num = f.size();
0429:
0430: while (--num >= 0) {
0431: f.delete(num);
0432: }
0433: }
0434:
0435: class Login extends Form implements CommandListener {
0436: TextField id = new TextField("", "", 10, TextField.ANY);
0437: TextField pd = new TextField("", "", 10,
0438: (TextField.NUMERIC | TextField.PASSWORD));
0439: TextField bidText = new TextField("Enter Bid:", "", 10,
0440: TextField.DECIMAL);
0441: StringItem submitButton = new StringItem("", "Submit",
0442: Item.BUTTON);
0443: StringItem auctionHyperlink = new StringItem("Auction:", "",
0444: Item.HYPERLINK);
0445: StringItem curBid = new StringItem("Current Bid:", "");
0446: StringItem incBid = new StringItem("Increment:", "");
0447: StringItem minBid = new StringItem("Minimum Bid:", "");
0448: Form confirm = new Form("Confirm Bid");
0449: Form notice = new Form("Bid Received");
0450: Form auctionForm = new Form("unknown");
0451: Alert loginAlert = new Alert("Alert",
0452: "Your must enter your ID and password"
0453: + " before you can proceed.", null, null);
0454: String bandName;
0455: String bid;
0456: String ticketID;
0457: String _bandName;
0458: int _bandIndex;
0459:
0460: Login() {
0461: super ("Make A Bid");
0462: id.setLabel("Enter Auction ID:");
0463: append(id);
0464: pd.setLabel("Enter PIN:");
0465: append(pd);
0466: append(curBid);
0467: append(incBid);
0468: append(minBid);
0469: append(bidText);
0470: addCommand(BACK_CMD);
0471: addCommand(NEXT_CMD);
0472: setCommandListener(this );
0473:
0474: ItemCommandListener icl = new MyItemCommandListener();
0475: confirm.append("unknown");
0476: confirm.addCommand(CANCEL_CMD);
0477: confirm.setCommandListener(this );
0478:
0479: auctionHyperlink.setDefaultCommand(AUCTION_CMD);
0480: auctionHyperlink.setItemCommandListener(icl);
0481:
0482: submitButton.setDefaultCommand(SUBMIT_CMD);
0483: submitButton.setItemCommandListener(icl);
0484:
0485: deleteFormItem(notice);
0486: notice.append(new StringItem("Your bid has been received:",
0487: ""));
0488: notice.append(new StringItem("Confirm #:", "12-B455-31"));
0489: notice.addCommand(BAND_CMD);
0490: notice.setCommandListener(this );
0491: loginAlert.setTimeout(Alert.FOREVER);
0492:
0493: auctionForm.append("unknown");
0494: auctionForm.addCommand(BACK_CMD);
0495: auctionForm.setCommandListener(this );
0496: }
0497:
0498: void setBid(String bandName, String bid) {
0499: this .bandName = bandName;
0500: this .bid = bid;
0501: }
0502:
0503: void setID(String bandName, String ticketID) {
0504: this .bandName = bandName;
0505: this .ticketID = ticketID;
0506: }
0507:
0508: void setBandAttributes(String bandName, int bandIndex) {
0509: _bandName = bandName;
0510: _bandIndex = bandIndex;
0511: }
0512:
0513: void doSubmit() {
0514: TimerService = new Timer();
0515:
0516: TimerClient timerClient = new TimerClient();
0517: TimerService.schedule(timerClient, 0, 1000);
0518: display.setCurrent(submitMsg);
0519: }
0520:
0521: public void commandAction(Command c, Displayable s) {
0522: if (s instanceof Form) {
0523: Form obj = (Form) s;
0524:
0525: if (obj == this ) {
0526: if (c == BACK_CMD) {
0527: display.setCurrent(band_ticket_Form);
0528: } else if (c == NEXT_CMD) {
0529: if ((id.getString().length() == 0)
0530: || (pd.getString().length() == 0)) { // ||
0531: // (bidText.getString().length() == 0)) {
0532: display.setCurrent(loginAlert);
0533: } else {
0534: login.setID(_bandName, band.getTicketID(
0535: _bandName, _bandIndex));
0536:
0537: String bidAmt = bidText.getString();
0538: System.err.println("\n\n #### bidAmt : "
0539: + bidAmt);
0540:
0541: // check if bid text is valid, if not pop up an alert
0542: if (bidAmt.equals("")) {
0543: Alert errorAlert = new Alert(
0544: "Alert",
0545: "The bid amount you have entered is invalid.",
0546: null, AlertType.ERROR);
0547: errorAlert.setTimeout(Alert.FOREVER);
0548: display.setCurrent(errorAlert);
0549: } else {
0550: deleteFormItem(login.confirm);
0551: login.confirm
0552: .append(new StringItem(
0553: "Please confirm this information is correct before submitting your bid",
0554: ""));
0555: auctionHyperlink
0556: .setText(login.ticketID);
0557: login.confirm.append(auctionHyperlink);
0558: login.confirm.append(new StringItem(
0559: "Band: " + login.bandName, ""));
0560: login.confirm.append(new StringItem(
0561: "Bid Amount:", "$" + bidAmt));
0562: login.confirm.append(submitButton);
0563:
0564: display.setCurrent(login.confirm);
0565: }
0566: }
0567: }
0568: } else if (obj == confirm) {
0569: if (c == CANCEL_CMD) {
0570: display.setCurrent(this );
0571: }
0572: } else if (obj == notice) {
0573: if (c == BAND_CMD) {
0574: display.setCurrent(band_ticket_Form);
0575: }
0576: } else if (obj == auctionForm) {
0577: if (c == BACK_CMD) {
0578: display.setCurrent(confirm);
0579: }
0580: }
0581: }
0582: }
0583:
0584: class MyItemCommandListener implements ItemCommandListener {
0585: public void commandAction(Command c, Item item) {
0586: if (c == SUBMIT_CMD) {
0587: doSubmit();
0588: } else if (c == AUCTION_CMD) {
0589: deleteFormItem(auctionForm);
0590: auctionForm.setTitle("Auction:" + login.ticketID);
0591: band.getAuctionData(auctionForm, login.bandName,
0592: login._bandIndex);
0593: display.setCurrent(auctionForm);
0594: }
0595: }
0596: }
0597:
0598: private class TimerClient extends TimerTask {
0599: public final void run() {
0600: if (submitGauge.getValue() == submitGauge.getMaxValue()) {
0601: TimerService.cancel();
0602: submitGauge.setValue(0);
0603: display.setCurrent(notice);
0604: } else {
0605: submitGauge.setValue(submitGauge.getValue() + 10);
0606: }
0607: }
0608: }
0609: }
0610:
0611: class Band {
0612: private BandListTable table;
0613: String def_ticker = "BootWare & Fr. 2 tix $90.00 2 tix $110.00"
0614: + " 2 tix $200.00 Escalators in Images band... 2 tix $65.00";
0615: String alt_ticker = "Another Group LTD. 2 tix $58.00 4 tix $115.00"
0616: + " Jets 2 Jets 2 tix $37.00";
0617:
0618: Band() {
0619: table = new BandListTable();
0620:
0621: TicketItem t;
0622:
0623: /**
0624: * 0: Ticket one
0625: */
0626: t = new TicketItem("BootWare & Friends", "18 & 19",
0627: "XF, Row 17", "Aug 23, 2002", "Eagle Stadium",
0628: "San Francisco, CA", "#7720", "2", "45.00",
0629: "69.00", "2.00", "3", "12:00 am on Aug 16, 2002");
0630: add(0, "BootWare & Friends", t);
0631:
0632: /**
0633: * 1: Ticket two
0634: */
0635: t = new TicketItem("Escalators In Images band",
0636: "10, 11, 12, 13", "F9, Row A", "Sep 7, 2002",
0637: "Fly Center", "Santa Cruz, CA", "4509", "4",
0638: "100.00", "101.00", "1.00", "1",
0639: "9:45 pm on Sep 1, 2002");
0640: add(1, "Escalators In Images band", t);
0641:
0642: t = new TicketItem("Escalators In Images band", "69 & 70",
0643: "PIT Row 1", "Aug 9, 2002",
0644: "Montezuma Civic Amphitheatre", "Monterey, CA",
0645: "3058", "2", "9.00", "175.00", "2.50", "40",
0646: "9:00 pm on Aug 2, 2002");
0647: add(1, "Escalators In Images band", t);
0648:
0649: t = new TicketItem("Escalators In Images band",
0650: "5 & 6 & 7", "PIT Rw 11", "Aug 10, 2002",
0651: "Monterey Civic Amphitheatre", "Monterey, CA",
0652: "3541", "3", "28.00", "97.00", "1.00", "11",
0653: "11:15 pm on Aug 2, 2002");
0654: add(1, "Escalators In Images band", t);
0655:
0656: /**
0657: * 2: Another group
0658: */
0659: t = new TicketItem("Another Group LTD.",
0660: "General Admission", "- NA -", "Aug 3, 2002",
0661: "Under the Hill", "San Francisco, CA", "3489", "2",
0662: "30.00", "44.00", "2.00", "5",
0663: "11:30 pm on Jul 7, 2002");
0664: add(2, "Another Group LTD.", t);
0665:
0666: /**
0667: * 3:
0668: */
0669: t = new TicketItem("Jets 2 Jets", "General Admission",
0670: "- NA -", "Jul 19, 2001", "The Fillless",
0671: "San Francisco, CA", "3861", "2", "55.00", "62.50",
0672: "2.50", "3", "6:30 pm on Jul 12, 2002");
0673: add(3, "Jets 2 Jets", t);
0674:
0675: t = new TicketItem("Jets 2 Jets", "4 & 6", "N2 Row 5",
0676: "Jul 18, 2002", "Czech Gallery",
0677: "Mountain View, CA", "9916", "2", "65.00",
0678: "200.00", "10.00", "12", "9:30 pm on Jul 10, 2002");
0679: add(3, "Jets 2 Jets", t);
0680:
0681: /**
0682: * 4: Kingware
0683: */
0684: t = new TicketItem("Kingware", "General Admission",
0685: "- NA -", "Aug 3, 2002", "Valley Stadium",
0686: "San Francisco", "1313", "2", "30.00", "37.00",
0687: "1.00", "7", "5:35 pm on Jul 27, 2002");
0688: add(4, "Kingware", t);
0689:
0690: /**
0691: * 5: Anna And Her Nerves
0692: */
0693: t = new TicketItem("Anna And Her Nerves", "N & O",
0694: "S, Row 14", "Aug 3, 2002", "Bell Park",
0695: "San Francisco, CA", "8120", "2", "80.00",
0696: "125.00", "2.00", "5", "11:30 am on Jul 7, 2002");
0697: add(5, "Anna And Her Nerves", t);
0698:
0699: /**
0700: * 6: The Human Experience & Co.
0701: */
0702: t = new TicketItem("The Human Experience & Co.", "15 & 16",
0703: "B, Row 14", "Aug 30, 2002", "Bell Park",
0704: "Prague, CZ", "1770", "2", "100.00", "175.00",
0705: "2.00", "5", "11:30 pm on Aug 23, 2002");
0706: add(6, "The Human Experience & Co.", t);
0707:
0708: /**
0709: * 7: Thirty Thirsty Fourties
0710: */
0711: t = new TicketItem("Thirty Thirsty Fourties", "11 & 12",
0712: "F Row J", "Jul 19, 2001", "Open Amphitheatre",
0713: "Austin, TX", "3766", "2", "60.00", "90.00",
0714: "5.00", "3", "6:30 pm on Jul 12, 2002");
0715: add(7, "Thirty Thirsty Fourties", t);
0716:
0717: t = new TicketItem("Thirty Thirsty Fourties", "4 & 6",
0718: "N2 Row 5", "Jul 18, 2002", "Seattle Downtown",
0719: "Seattle, WA", "9135", "2", "70.00", "200.00",
0720: "10.00", "12", "9:30 pm on Jul 10, 2002");
0721: add(7, "Thirty Thirsty Fourties", t);
0722:
0723: t = new TicketItem("Thirty Thirsty Fourties",
0724: "General Admission", "- NA -", "Jul 20, 2002",
0725: "The Stadium", "San Francisco, CA", "2722", "2",
0726: "75.00", "110.00", "2.00", "12",
0727: "4:00 pm on Jul 13, 2002");
0728: add(7, "Thirty Thirsty Fourties", t);
0729: }
0730:
0731: void add(String bandName) {
0732: add(table.size(), bandName, new TicketItem(bandName));
0733: }
0734:
0735: void add(int i, String bandName) {
0736: add(i, bandName, new TicketItem(bandName));
0737: }
0738:
0739: void add(int i, String bandName, TicketItem item) {
0740: Object obj = table.get(bandName);
0741: Vector vec = (obj == null) ? new Vector() : (Vector) obj;
0742: vec.addElement(item);
0743: table.put(i, vec);
0744: }
0745:
0746: void remove(int i) {
0747: table.remove(i);
0748: }
0749:
0750: String[] getList() {
0751: int num = table.size();
0752: String[] seq = new String[num];
0753:
0754: for (int i = 0; i < num; i++) {
0755: Vector vec = (Vector) table.elementAt(i);
0756: TicketItem item = (TicketItem) vec.elementAt(0);
0757: seq[i] = item.name;
0758: }
0759:
0760: return seq;
0761: }
0762:
0763: String getName(int nth) {
0764: Vector vec = (Vector) table.elementAt(nth);
0765:
0766: if (vec != null) {
0767: TicketItem item = (TicketItem) vec.elementAt(0);
0768:
0769: if (item != null) {
0770: return item.name;
0771: }
0772: }
0773:
0774: return null;
0775: }
0776:
0777: String[] getTicketList(String bandName) {
0778: Object obj = table.get(bandName);
0779:
0780: if (obj == null) {
0781: return null;
0782: }
0783:
0784: Vector vec = (Vector) obj;
0785: int num = vec.size();
0786: String[] seq = new String[num];
0787:
0788: for (int i = 0; i < num; i++) {
0789: TicketItem item = (TicketItem) vec.elementAt(i);
0790: seq[i] = new String("#" + item.id + " $" + item.curBid
0791: + "\n" + item.place + ", " + item.state + "\n"
0792: + item.sect + "," + item.seat + " ...");
0793: }
0794:
0795: return seq;
0796: }
0797:
0798: TicketItem getTicketItem(String bandName, int nth) {
0799: Object obj = table.get(bandName);
0800:
0801: if (obj == null) {
0802: return null;
0803: }
0804:
0805: Vector vec = (Vector) obj;
0806:
0807: return (TicketItem) vec.elementAt(nth);
0808: }
0809:
0810: String getTicketID(String bandName, int nth) {
0811: TicketItem item = getTicketItem(bandName, nth);
0812:
0813: if (item == null) {
0814: return null;
0815: }
0816:
0817: return item.id;
0818: }
0819:
0820: String getTicketDataTitle(String bandName, int nth) {
0821: TicketItem item = getTicketItem(bandName, nth);
0822:
0823: if (item == null) {
0824: return null;
0825: }
0826:
0827: return item.name + " " + item.id + ":";
0828: }
0829:
0830: void getTicketData(Form form, String bandName, int nth) {
0831: TicketItem item = getTicketItem(bandName, nth);
0832:
0833: if (item == null) {
0834: return;
0835: }
0836:
0837: form.append(new StringItem("Quantity:", item.numItem
0838: + " tickets"));
0839: form.append(new StringItem("Bid starts at:", "$"
0840: + item.begBid));
0841: form.append(new StringItem("Current bid:", "$"
0842: + item.curBid));
0843: form
0844: .append(new StringItem("Number of Bids:",
0845: item.numBids));
0846: form
0847: .append(new StringItem("Bidding ends at:",
0848: item.endsAt));
0849: // form.append(new StringItem("Sec:", item.sect));
0850: form.append(new StringItem("Seat(s):", item.seat));
0851: form.append(new StringItem("Concert Date:", item.date));
0852: form.append(new StringItem("Concert Venue:", item.place
0853: + "," + item.state));
0854: }
0855:
0856: void getAuctionData(Form form, String bandName, int nth) {
0857: TicketItem item = getTicketItem(bandName, nth);
0858:
0859: if (item == null) {
0860: return;
0861: }
0862:
0863: form.append(new StringItem("Band Name:", item.name
0864: + " tickets"));
0865: form.append(new StringItem("Concert Date:", item.date));
0866: form.append(new StringItem("Quantity:", item.numItem));
0867: form.append(new StringItem("Concert Venue:", item.place
0868: + "," + item.state));
0869: }
0870:
0871: String getCurrentBid(String bandName, int nth) {
0872: TicketItem item = getTicketItem(bandName, nth);
0873:
0874: if (item == null) {
0875: return "";
0876: }
0877:
0878: return item.curBid;
0879: }
0880:
0881: boolean isTicketData(String bandName, String itemID) {
0882: return (getTicketItem(bandName, itemID) == null) ? false
0883: : true;
0884: }
0885:
0886: TicketItem getTicketItem(String bandName, String itemID) {
0887: Object obj = table.get(bandName);
0888:
0889: if (obj == null) {
0890: return null;
0891: }
0892:
0893: Vector vec = (Vector) obj;
0894: int num = vec.size();
0895:
0896: for (int i = 0; i < num; i++) {
0897: TicketItem item = (TicketItem) vec.elementAt(i);
0898:
0899: if (item.id.equals(itemID)) {
0900: return item;
0901: }
0902: }
0903:
0904: return null;
0905: }
0906:
0907: void getTicketBidTitle(Form f, String bandName, int itemID) {
0908: TicketItem item = getTicketItem(bandName, itemID);
0909: long min = stringToLong1000(item.curBid)
0910: + stringToLong1000(item.incBid);
0911: String minBid = long1000ToString(min);
0912:
0913: login.curBid.setText("$" + item.curBid);
0914: login.incBid.setText("$" + item.incBid);
0915: login.minBid.setText("$" + minBid);
0916: }
0917:
0918: String toTickerString(boolean[] selected) {
0919: String s = "";
0920:
0921: if (selected == null) {
0922: return alt_ticker;
0923: }
0924:
0925: // Rock Bands
0926: if (selected[0]) {
0927: s += def_ticker;
0928: }
0929:
0930: // Pop
0931: if (selected[1]) {
0932: }
0933:
0934: // Country
0935: if (selected[2]) {
0936: }
0937:
0938: // Alternative
0939: if (selected[3]) {
0940: if (s.length() > 0) {
0941: s += " ";
0942: }
0943:
0944: s += alt_ticker;
0945: }
0946:
0947: // Jazz
0948: if (selected[4]) {
0949: }
0950:
0951: // Classical
0952: if (selected[5]) {
0953: }
0954:
0955: return s;
0956: }
0957:
0958: long stringToLong1000(String s) {
0959: if ((s == null) || s.equals("")) {
0960: return 0;
0961: }
0962:
0963: try {
0964: int index = s.indexOf('.');
0965:
0966: if (index == -1) {
0967: return (long) 1000 * Integer.parseInt(s);
0968: }
0969:
0970: long integerPart = 1000 * Integer.parseInt(s.substring(
0971: 0, index));
0972: String fracString = s.substring(index + 1);
0973: int multBy = 0;
0974:
0975: switch (fracString.length()) {
0976: case 0:
0977: multBy = 0;
0978:
0979: break;
0980:
0981: case 1:
0982: multBy = 100;
0983:
0984: break;
0985:
0986: case 2:
0987: multBy = 10;
0988:
0989: break;
0990:
0991: case 3:
0992: multBy = 1;
0993:
0994: break;
0995: }
0996:
0997: long fractionalPart = multBy
0998: * Integer.parseInt(fracString);
0999:
1000: return integerPart + fractionalPart;
1001: } catch (NumberFormatException nfe) {
1002: return 0;
1003: }
1004: }
1005:
1006: String long1000ToString(long l) {
1007: if (l == 0) {
1008: return "0";
1009: }
1010:
1011: String s = String.valueOf(l);
1012:
1013: if (s.length() < 4) {
1014: return "0";
1015: }
1016:
1017: String newStr = s.substring(0, s.length() - 3) + "."
1018: + s.substring(s.length() - 2);
1019:
1020: return newStr;
1021: }
1022:
1023: class TicketItem {
1024: // Ticket info
1025: String name; // item name i.e. band name
1026: String seat; // seat number
1027: String sect; // seat section
1028: String date; // concert date
1029: String place; // concert place
1030: String state; // place's state
1031:
1032: // Bid info
1033: String id; // id i.e. item number
1034: String numItem; // quantity
1035: String begBid; // beginning bid price
1036: String curBid; // current bid price
1037: String incBid; // bid increment
1038: String numBids; // # of bids
1039: String endsAt; // Bid close time
1040:
1041: TicketItem(String name, String seat, String sect,
1042: String date, String place, String state, String id,
1043: String numItem, String begBid, String curBid,
1044: String incBid, String numBids, String endsAt) {
1045: this .name = name;
1046: this .seat = seat;
1047: this .sect = sect;
1048: this .date = date;
1049: this .place = place;
1050: this .state = state;
1051: this .id = id;
1052: this .numItem = numItem;
1053: this .begBid = begBid;
1054: this .curBid = curBid;
1055: this .incBid = incBid;
1056: this .numBids = numBids;
1057: this .endsAt = endsAt;
1058: }
1059:
1060: TicketItem(String name) {
1061: this (name, "n/a", "n/a", "n/a", "n/a", "n/a", "0", "0",
1062: "0", "0", "0", "0", "0");
1063: }
1064: }
1065:
1066: class BandListTable {
1067: private Vector vec = new Vector();
1068:
1069: BandListTable() {
1070: vec = new Vector();
1071: }
1072:
1073: void put(int nth, Object obj) {
1074: Object o = null;
1075:
1076: try {
1077: o = vec.elementAt(nth);
1078: } catch (ArrayIndexOutOfBoundsException e) {
1079: o = null;
1080: }
1081:
1082: if (o == null) {
1083: vec.addElement(obj);
1084: } else {
1085: vec.setElementAt(obj, nth);
1086: }
1087: }
1088:
1089: Object get(String bandName) {
1090: int num = vec.size();
1091:
1092: for (int i = 0; i < num; i++) {
1093: Object obj = vec.elementAt(i);
1094:
1095: if (obj instanceof Vector) {
1096: Vector v = (Vector) obj;
1097: TicketItem item = (TicketItem) v.elementAt(0);
1098:
1099: if (item.name.equals(bandName)) {
1100: return obj;
1101: }
1102: }
1103: }
1104:
1105: return null;
1106: }
1107:
1108: Object elementAt(int index) {
1109: return vec.elementAt(index);
1110: }
1111:
1112: void remove(int i) {
1113: Object o = null;
1114:
1115: try {
1116: o = vec.elementAt(i);
1117: } catch (ArrayIndexOutOfBoundsException e) {
1118: o = null;
1119: }
1120:
1121: if (o != null) {
1122: vec.removeElementAt(i);
1123: }
1124: }
1125:
1126: int size() {
1127: return vec.size();
1128: }
1129: }
1130: } // end band
1131:
1132: class RmBand extends List implements CommandListener {
1133: RmBand() {
1134: super ("Remove Bands", Choice.MULTIPLE);
1135:
1136: String[] list = band.getList();
1137:
1138: for (int i = 0; i < list.length; i++) {
1139: append(list[i], null);
1140: }
1141:
1142: addCommand(BACK_CMD);
1143: addCommand(SAVE_CMD);
1144: setCommandListener(this );
1145: }
1146:
1147: public void commandAction(Command c, Displayable s) {
1148: if (c == SAVE_CMD) {
1149: // Make the ChoiceGroup invisible before doing
1150: // reconstruction
1151: boolean[] ret = new boolean[size()];
1152: getSelectedFlags(ret);
1153: removeBandList(ret);
1154:
1155: // go back to band_ticket_Form after save
1156: display.setCurrent(savedMsg, band_ticket_Form);
1157: } else if (c == BACK_CMD) {
1158: display.setCurrent(band_ticket_Form);
1159: }
1160: }
1161:
1162: void reset() {
1163: reconstructList(this , band.getList());
1164: }
1165:
1166: void removeBandList(boolean[] t) {
1167: int i = t.length;
1168:
1169: while (--i >= 0) {
1170: if (t[i]) {
1171: band.remove(i);
1172: }
1173: }
1174:
1175: reconstructBandTicketForm(band.getList());
1176: reconstructList(this , band.getList());
1177: }
1178: } // end rm band
1179:
1180: class UpdateAlert {
1181: String band = "";
1182: String bid = "";
1183: Alert soundAlert;
1184:
1185: UpdateAlert() {
1186: soundAlert = new Alert("Alert", "", null, AlertType.ALARM);
1187: soundAlert.setTimeout(Alert.FOREVER);
1188: }
1189:
1190: void set(String band, String bid) {
1191: this .band = band;
1192: this .bid = bid;
1193: }
1194:
1195: boolean hasDataToUpdate() {
1196: return ((band != null) && (band != "") && (bid != null) && (bid != ""));
1197: }
1198:
1199: void show() {
1200: // no-op if band & bid aren't set
1201: if (hasDataToUpdate()) {
1202: String s = new String(band + "\n" + "ticket bids\n"
1203: + "have reached\n" + "$" + bid);
1204: soundAlert.setString(s);
1205: display.setCurrent(soundAlert);
1206: }
1207: }
1208: } // end UpdateAlert
1209:
1210: class SetMenuForm extends Form implements CommandListener,
1211: ItemStateListener {
1212: Timer timerService = new Timer();
1213: ChoiceGroup tickerCg;
1214: ChoiceGroup updatesCg;
1215: Gauge gauge;
1216: DateField dateTimeItem;
1217: int updateChoice;
1218: int volumeValue;
1219: boolean[] musicChoice;
1220: boolean systemCurrentDate = true;
1221: long setTimeMillisDelta;
1222: long curTimeMillisDelta;
1223:
1224: SetMenuForm() {
1225: super ("Settings");
1226:
1227: tickerCg = new ChoiceGroup("Ticker Display",
1228: Choice.MULTIPLE);
1229: tickerCg.append("Rock", null);
1230: tickerCg.append("Pop", null);
1231: tickerCg.append("Country", null);
1232: tickerCg.append("Alternative", null);
1233: tickerCg.append("Jazz", null);
1234: tickerCg.append("Classical", null);
1235: musicChoice = new boolean[] { false, false, false, true,
1236: false, false };
1237: append(tickerCg);
1238:
1239: updatesCg = new ChoiceGroup("Updates", Choice.EXCLUSIVE);
1240: updatesCg.append("Continuous", null);
1241: updatesCg.append("15 minutes", null);
1242: updatesCg.append("30 minutes", null);
1243: updatesCg.append("1 hour", null);
1244: updatesCg.append("3 hours", null);
1245: updateChoice = 0;
1246: append(updatesCg);
1247:
1248: /* Set Number */
1249: gauge = new Gauge(null, true, 40, 0);
1250: volumeValue = 0;
1251: append(gauge);
1252: setItemStateListener(this );
1253:
1254: setTimeMillisDelta = curTimeMillisDelta = 0;
1255:
1256: dateTimeItem = new DateField("Set Date:",
1257: DateField.DATE_TIME) {
1258: public void showNotify() {
1259: long millis = System.currentTimeMillis();
1260:
1261: if (curTimeMillisDelta != 0) {
1262: millis -= curTimeMillisDelta;
1263: }
1264:
1265: setDate(new java.util.Date(millis));
1266: }
1267: };
1268:
1269: append(dateTimeItem);
1270:
1271: settings(musicChoice, updateChoice, volumeValue,
1272: setTimeMillisDelta);
1273:
1274: addCommand(BACK_CMD);
1275: addCommand(SAVE_CMD);
1276: setCommandListener(this );
1277: }
1278:
1279: public void settings(boolean[] musicChoice, int updateChoice,
1280: int volumeValue, long curTimeMillisDelta) {
1281: tickerCg.setSelectedFlags(musicChoice);
1282: updatesCg.setSelectedIndex(updateChoice, true);
1283: gauge.setValue(volumeValue);
1284: gauge.setLabel("Set Alert Volume: " + volumeValue);
1285:
1286: long millis = System.currentTimeMillis();
1287:
1288: if (curTimeMillisDelta != 0) {
1289: millis -= curTimeMillisDelta;
1290: }
1291:
1292: dateTimeItem.setDate(new java.util.Date(millis));
1293: }
1294:
1295: public void commandAction(Command c, Displayable s) {
1296: if (c == SAVE_CMD) {
1297: tickerCg.getSelectedFlags(musicChoice);
1298:
1299: String str = band.toTickerString(musicChoice);
1300:
1301: if (str != null) {
1302: ticker.setString(str);
1303: }
1304:
1305: updateChoice = updatesCg.getSelectedIndex();
1306:
1307: volumeValue = gauge.getValue();
1308:
1309: setTimeMillisDelta = curTimeMillisDelta;
1310:
1311: if (updateAlert.hasDataToUpdate()) {
1312: int idx = updatesCg.getSelectedIndex();
1313: TimerTask timerClient = new TimerTask() {
1314: public final void run() {
1315: updateAlert.show();
1316: }
1317: };
1318:
1319: switch (idx) {
1320: case 0:
1321: timerService.schedule(timerClient, 3000);
1322:
1323: break;
1324:
1325: case 1:
1326: timerService.schedule(timerClient, 3000);
1327:
1328: break;
1329:
1330: case 2:
1331: timerService.schedule(timerClient, 3000);
1332:
1333: break;
1334:
1335: case 3:
1336: timerService.schedule(timerClient, 3000);
1337:
1338: break;
1339:
1340: case 4:
1341: timerService.schedule(timerClient, 3000);
1342:
1343: break;
1344: }
1345: }
1346:
1347: display.setCurrent(savedMsg, band_ticket_Form);
1348: } else if (c == BACK_CMD) {
1349: display.setCurrent(band_ticket_Form);
1350: settings(musicChoice, updateChoice, volumeValue,
1351: setTimeMillisDelta);
1352: }
1353: }
1354:
1355: public void itemStateChanged(Item item) {
1356: if (item == gauge) {
1357: int currentValue = gauge.getValue();
1358: gauge.setLabel("Set Alert Volume: "
1359: + String.valueOf(currentValue));
1360: } else if (item == dateTimeItem) {
1361: curTimeMillisDelta = System.currentTimeMillis()
1362: - dateTimeItem.getDate().getTime();
1363: }
1364: }
1365: }
1366: }
|