001: package com.xoetrope.carousel.catalog.templates.javaclasses;
002:
003: import net.xoetrope.swing.XPanel;
004: import java.util.HashMap; //BEGIN_BLOCK_CART
005: import javax.swing.DefaultListModel;
006: import javax.swing.ListSelectionModel;
007: import javax.swing.JLabel;
008: import javax.swing.ListModel;
009: import net.xoetrope.swing.XList;
010: import java.beans.PropertyChangeEvent;
011: import java.beans.PropertyChangeListener;
012: import java.util.ArrayList;
013: import net.xoetrope.xui.data.XBaseModel;
014: import net.xoetrope.swing.dnd.XDragInfo;
015: import net.xoetrope.xui.data.XModel; //END_BLOCK_CART
016: import net.xoetrope.xui.XPage; //BEGIN_BLOCK_MOUSE
017: import java.awt.event.MouseEvent;
018: import java.awt.event.MouseListener; //END_BLOCK_MOUSE
019: //BEGIN_BLOCK_IMPORTS
020: import net.xoetrope.xui.XPage; //IMPORT_NAME_1
021: import com.xoetrope.swing.XCaptionedImage;
022: import java.awt.Component;
023: import java.awt.Font;
024: import net.xoetrope.swing.XApplet;
025: import net.xoetrope.swing.XDialog;
026: import net.xoetrope.swing.XTextArea;
027: import net.xoetrope.swing.dnd.XDragManager; //END_BLOCK_IMPORTS
028: //BEGIN_BLOCK_STYLE
029: import net.xoetrope.xui.style.XStyle;
030: import net.xoetrope.xui.style.XStyleManager; //END_BLOCK_STYLE
031: //BEGIN_BLOCK_DRAGINFO
032: import net.xoetrope.swing.dnd.XDragInfo;
033: import net.xoetrope.swing.dnd.XDragManager;
034:
035: //END_BLOCK_DRAGINFO
036: public class Products extends XPage
037: //BEGIN_BLOCK_DRAGINFO
038: implements XDragManager
039: //END_BLOCK_DRAGINFO
040: {
041: //BEGIN_BLOCK_CART
042: protected XList cartList;
043: protected DefaultListModel model;
044: protected XGraphicListCellRenderer renderer;
045: protected JLabel totalPrice;
046: protected XPanel cartPanel;
047: protected ArrayList keys;
048: protected HashMap cartMap;
049: private XModel currentProduct;
050: private int previousSize2;
051: //END_BLOCK_CART
052: //BEGIN_BLOCK_VARS
053: protected XPanel productsPanel, detailsPanel, mainPanel;
054: //BEGIN_BLOCK_DESCRIP
055: protected XTextArea descriptionArea;
056: //END_BLOCK_DESCRIP
057: protected HashMap infoMap;
058: protected Component[] products;
059: protected Object[][] values;
060: private int previousSize;
061: private XModel newNode;
062:
063: //END_BLOCK_VARS
064: //BEGIN_BLOCK_DRAGINFO
065: public Products() {
066: setupDragInfo();
067: cartMap = new HashMap();
068: keys = new ArrayList();
069: }
070:
071: //END_BLOCK_DRAGINFO
072: public void pageCreated() {
073: //BEGIN_BLOCK_CART
074: cartList = (XList) findComponent("cartList");
075: totalPrice = (JLabel) findComponent("totalPrice");
076: cartPanel = (XPanel) findComponent("cartPanel");
077: //END_BLOCK_CART
078: //BEGIN_BLOCK_VARS
079: mainPanel = (XPanel) findComponent("mainPanel");
080: //BEGIN_BLOCK_PRODUCTS
081: productsPanel = (XPanel) findComponent("productsPanel");
082: //END_BLOCK_PRODUCTS
083: //BEGIN_BLOCK_STYLE
084: XStyleManager styleManager = project.getStyleManager();
085: XStyle comboStyle = styleManager.getStyle("base/edit");
086: //END_BLOCK_STYLE
087: //BEGIN_BLOCK_DESCRIP
088: descriptionArea = (XTextArea) findComponent("descriptionArea");
089: descriptionArea.setFont(new Font("Arial", Font.PLAIN, 12));
090: descriptionArea.setForeground(comboStyle
091: .getStyleAsColor(comboStyle.COLOR_FORE));
092: //END_BLOCK_DESCRIP
093: //END_BLOCK_VARS
094: //BEGIN_BLOCK_CART
095: renderer = new XGraphicListCellRenderer(totalPrice);
096: cartList.setCellRenderer(renderer);
097: cartList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
098: cartList.setFixedCellHeight(30);
099: cartList.setFocusable(false);
100: cartList.setDragEnabled(true);
101: //END_BLOCK_CART
102: //BEGIN_BLOCK_MOUSE
103: //BEGIN_BLOCK_DETAILS
104: MouseListener mouseListener = new MouseListener() {
105: public void mouseEntered(MouseEvent e) {
106: if (e.getSource() == productsPanel) {
107: descriptionArea.setText("");
108: } else {
109: for (int i = 0; i < products.length; i++) {
110: if (e.getSource() == products[i]) {
111: descriptionArea
112: .setText((String) values[i][4]);
113: break;
114: }
115: }
116: }
117: }
118:
119: public void mouseExited(MouseEvent e) {
120: }
121:
122: public void mouseClicked(MouseEvent e) {
123: }
124:
125: public void mousePressed(MouseEvent e) {
126: }
127:
128: public void mouseReleased(MouseEvent e) {
129: }
130: };
131:
132: productsPanel.addMouseListener(mouseListener);
133: Component[] components = productsPanel.getComponents();
134: products = new Component[components.length - 2];
135:
136: for (int i = 0; i < products.length; i++) {
137: products[i] = components[i + 2];
138: ((XCaptionedImage) products[i])
139: .addCaptionListener(mouseListener);
140: }
141: //END_BLOCK_DETAILS
142: //END_BLOCK_MOUSE
143: //BEGIN_BLOCK_CART
144: cartList
145: .addPropertyChangeListener(new PropertyChangeListener() {
146: public void propertyChange(PropertyChangeEvent evt) {
147: //BEGIN_BLOCK_PRICES
148: calculateTotal(cartList);
149: //END_BLOCK_PRICES
150: storeCartInfo(cartList);
151: }
152: });
153: //END_BLOCK_CART
154: }
155:
156: //BEGIN_BLOCK_ABOUT
157: public void openAbout() {
158: XDialog dlg = (XDialog) pageMgr.loadPage("About");
159: dlg.pack();
160: dlg.showDialog(this );
161: }
162:
163: //END_BLOCK_ABOUT
164: //BEGIN_BLOCK_PREVIOUS
165: public void openWelcome() {
166: pageMgr.showPage("Welcome");
167: }
168:
169: //END_BLOCK_PREVIOUS
170: //BEGIN_BLOCK_NEXT
171: public void openCheckout() {
172: //BEGIN_BLOCK_CART
173: ListModel model = cartList.getModel();
174:
175: if (keys != null) {
176: for (int i = 0; i < keys.size(); i++) {
177: if (cartMap.containsKey(keys.get(i).toString())) {
178: Object[] o = (Object[]) cartMap.get(keys.get(i)
179: .toString());
180:
181: currentProduct = (XModel) rootModel
182: .get("productsCart");
183:
184: XBaseModel newRow = (XBaseModel) currentProduct
185: .get("newNode" + i);
186: newRow.setAttribValue(XBaseModel.VALUE_ATTRIBUTE,
187: ("newNode" + i));
188:
189: newRow.set("1", o[0]);
190: newRow.set("2", o[1]);
191:
192: String result = "";
193: //BEGIN_BLOCK_PRICES
194: double cost = Double.parseDouble(((String) o[2])
195: .substring(1));
196: double totalCost = cost
197: * Double.parseDouble((String) o[1]);
198: result = "$" + totalCost;
199: result = result.substring(0,
200: result.indexOf(".") + 3);
201: //END_BLOCK_PRICES
202: newRow.set("3", (Object) result);
203: }
204: }
205: }
206: //END_BLOCK_CART
207:
208: pageMgr.showPage("Checkout");
209: }
210:
211: //END_BLOCK_NEXT
212: //BEGIN_BLOCK_DRAGINFO
213: public XDragInfo getDragInfo(String key) {
214: return (XDragInfo) infoMap.get(key);
215: }
216:
217: private void setupDragInfo() {
218: String[] prices = new String[12];
219: for (int i = 0; i < prices.length; i++) {
220: prices[i] = " ";
221: }
222: //BEGIN_BLOCK_PRICES
223: String[] p = { "$249.99", "$99.99", "$39.99", "$399.99",
224: "$299.99", "$19.99", "$49.99", "$799.99", "$699.99",
225: "$99.99", "$89.99", "$1599.99" };
226: prices = p;
227: //END_BLOCK_PRICES
228:
229: String[] photos = new String[12];
230: for (int i = 0; i < photos.length; i++) {
231: photos[i] = " ";
232: }
233:
234: //BEGIN_BLOCK_PHOTOS
235: String[] ph = { "camera.jpg", "networkstorage.jpg",
236: "wirelesscard.jpg", "blackberry.jpg",
237: "graphicscard.jpg", "earphones.jpg", "dictionary.jpg",
238: "iphone.jpg", "tabletpc.jpg", "mp3player.jpg",
239: "harddrive.jpg", "digitaltv.jpg" };
240: photos = ph;
241: //END_BLOCK_PHOTOS
242:
243: infoMap = new HashMap();
244: String[] keys = { XDragInfo.TITLE, XDragInfo.KEY, "price",
245: "image", XDragInfo.DESCRIPTION };
246:
247: Object[][] v = {
248: {
249: "Canon Digital Camera",
250: "camera",
251: prices[0],
252: photos[0],
253: "The Canon PowerShot SD550 is a sleek 7 megapixel ultracompact. The Canon PowerShot SD550 is the older brother of the PowerShot SD450. The camera also features an oversized 2.5-inch LCD display that gives excellent previews of your 7.1 megapixel photos. An orientation sensor rotates your preview image depending on which way you hold the camera, horizontally or vertically." },
254: {
255: "Netgear Network Storage Device",
256: "netstore",
257: prices[1],
258: photos[1],
259: "NETGEAR’s Storage Central is an innovation for storing and protecting music, games, photos, videos, and other important files on a secure network device. It functions just like a local disk drive, accessible from any network computer, but without requiring a dedicated PC. " }
260: //BEGIN_BLOCK_PROD4
261: ,
262: {
263: "Netgear Wireless Card",
264: "wireless",
265: prices[2],
266: photos[2],
267: "With the RangeMax NEXT Notebook adapter inserted, your PC will maintain a steady, constant connection (when used in conjunction with the WNR834B or DG834N Wireless Router), with sufficient bandwidth available to stream, download, browse the Internet, and transfer files all at the same time.With RangeMax NEXT you should not experience any more frustrating interruptions or freezes, just a constant connection that enables you and your household to use the Internet and wireless network as you choose, whenever you choose." },
268: {
269: "Blackberry",
270: "blackberry",
271: prices[3],
272: photos[3],
273: "The BlackBerry Pearl comes complete with digital camera, multimedia capabilities and expandable memory, while also offering push-based wireless access to email, phone that includes Speaker-Independent Voice Activated Dialling, text messaging, Internet and intranet browsing, organiser, and other data applications." }
274: //END_BLOCK_PROD4
275: //BEGIN_BLOCK_PROD8
276: ,
277: {
278: "ATI Graphics Card",
279: "graphicscard",
280: prices[4],
281: photos[4],
282: "Designed from the ground up to deliver maximum graphical detail at the best possible frame rates, the Radeon X1900’s state-of-the-art architecture includes an ultra-threaded engine for unparalleled shader performance. In addition, it is CrossFire™ ready, allowing your greatest multi-GPU fantasies to come true. The Radeon X1900 ups the ante with Avivo™ video and display technology delivering movies, games, and photos in high-definition format with stunning color and realism." },
283: {
284: "Noise Reduction Earphones",
285: "earphones",
286: prices[5],
287: photos[5],
288: "This Able Planet Clear Harmony Stereo Headset has Able Planet LINX technology installed, which provides people with all levels of hearing loss the opportunity to hear better by enhancing the clarity in speech, providing richer sounding music, and enhancing the overall sound quality. Clear Harmony increases the perception of loudness without increasing the volume control of the device. Youll hear premium sound with reduced distortion. Adjustable headband gives you a comfortable and secure fit. Volume control on the cord for easy level adjustment. Straight, dual entry 4-foot cord with 1/8 and 1/4 stereo plugs for use with stereos, personal computers, CD players, MP3 players and IPOD's. Cannot be used with hearing aids." },
289: {
290: "Electronic Dictionary",
291: "dictionary",
292: prices[6],
293: photos[6],
294: "Invest in yourself with this easy-to-use Speaking Electronic Dictionary and learn a new word each time you turn the unit on. You will master grammar, solve crossword puzzles, expand your vocabulary and improve your spelling before you know it! The right words are easy to find with Franklin's talking thesaurus and renowned phonetic spell correction feature that allows you to enter words by how they sound, while the large 8-line display screen offers visibility with and without your reading glasses." },
295: {
296: "i-Phone",
297: "iphone",
298: prices[7],
299: photos[7],
300: "iPhone combines three amazing products — a revolutionary mobile phone, a widescreen iPod with touch controls, and a breakthrough Internet communications device with desktop-class email, web browsing, maps, and searching — into one small and lightweight handheld device. iPhone also introduces an entirely new user interface based on a large multi-touch display and pioneering new software, letting you control everything with just your fingers. So it ushers in an era of software power and sophistication never before seen in a mobile device, completely redefining what you can do on a mobile phone." }
301: //END_BLOCK_PROD8
302: //BEGIN_BLOCK_PROD12
303: ,
304: {
305: "Tablet PC",
306: "tabletpc",
307: prices[8],
308: photos[8],
309: "The revolutionary Compaq Tablet PC operates as a full function PC, delivering performance and compatibility while weighing less than three pounds. Designed to operate in multiple modes including tablet, portable notebook and desktop, the Compaq Tablet PC was engineered to allow mobile professionals to transition through different working environments quickly, easily and discreetly." },
310: {
311: "MP3 Player",
312: "mp3player",
313: prices[9],
314: photos[9],
315: "Creative's Zen Vision:M is the ultimate player for people who want to enjoy music and movies on the go. This stylish, versatile system features an advanced 2.5-inch high-resolution colour screen that can display movies and stills up to an amazing 262,144 colours! The Zen Vision:M's rechargeable battery delivers playtimes up to four hours with video, up to 14 hours with music. For live entertainment or capturing those special moments there's also a built-in FM radio and voice recorder." },
316: {
317: "Hard-Drive",
318: "harddrive",
319: prices[10],
320: photos[10],
321: "This 4gb jumbo-drive features an AutoRun, user friendly interface, password protectionability to schedule and back up specified files, SKYPE application, portable Thunderbird (portable client email server) application, portable open office suite (Spread sheet, word processing,draw,presentation,data base), 180 degree turn around USB connection." },
322: {
323: "Philips Digital TV",
324: "digitaltv",
325: prices[11],
326: photos[11],
327: "Enjoy the ultimate viewing experience of this Philips Cineos Flat TV with Pixel Plus 3 HD, Ambilight Surround and Clear LCD technology. The Digital Media Reader with PC link gives you full access to multimedia content." }
328: //END_BLOCK_PROD12
329: };
330:
331: for (int i = 0; i < v.length; i++) {
332: XDragInfo dragInfo = new XDragInfo();
333: dragInfo.addValues(keys, v[i]);
334: infoMap.put((String) v[i][1], dragInfo);
335: }
336:
337: values = v;
338: }
339:
340: //END_BLOCK_DRAGINFO
341: //BEGIN_BLOCK_CART
342: //BEGIN_BLOCK_PRICES
343: public void calculateTotal(XList list) {
344: ListModel model = list.getModel();
345:
346: if (model.getSize() > previousSize) {
347: double total = 0;
348: for (int i = 0; i < model.getSize(); i++) {
349: XDragInfo info = (XDragInfo) model.getElementAt(i);
350: String price = (String) info.get("price");
351:
352: double current = Double.parseDouble(price.substring(1));
353: total = total + current;
354:
355: String result = "$" + total;
356: result = result.substring(0, result.indexOf(".") + 3);
357: totalPrice.setText(result);
358: }
359: previousSize = model.getSize();
360: }
361: }
362:
363: //END_BLOCK_PRICES
364:
365: public void storeCartInfo(XList list) {
366: ListModel model = list.getModel();
367: if (model.getSize() > previousSize2) {
368: XDragInfo info = (XDragInfo) model.getElementAt(model
369: .getSize() - 1);
370:
371: if (!cartMap.containsKey(info.get("title"))) {
372: cartMap.put(info.get("title"), new Object[] {
373: info.get("title"), "1", info.get("price") });
374: keys.add(info.get("title"));
375: } else {
376: Object[] o = (Object[]) cartMap.remove(info
377: .get("title"));
378: String amt = (String) o[1];
379: int i = Integer.parseInt(amt) + 1;
380: cartMap.put(info.get("title"), new Object[] {
381: info.get("title"), Integer.toString(i),
382: info.get("price") });
383: }
384: previousSize2 = model.getSize();
385: }
386: }
387: //END_BLOCK_CART
388: }
|