Source Code Cross Referenced for ItemPanel.java in  » J2EE » JOnAS-4.8.6 » olstore » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » olstore.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2005 Red Hat, Inc. All rights reserved.
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
017:         * USA
018:         *
019:         * Component of: Red Hat Application Server
020:         *
021:         * Initial Developers: Gregory Lapouchnian
022:         *                     Patrick Smith
023:         * --------------------------------------------------------------------------
024:         * $Id: ItemPanel.java 7027 2005-07-08 14:00:45Z glapouch $
025:         * --------------------------------------------------------------------------
026:         */package olstore.client;
027:
028:        import java.awt.Color;
029:        import java.awt.Component;
030:        import java.awt.Dimension;
031:        import java.awt.GridBagConstraints;
032:        import java.awt.GridBagLayout;
033:        import java.awt.GridLayout;
034:        import java.awt.event.MouseEvent;
035:        import java.awt.event.MouseListener;
036:        import java.awt.event.MouseMotionListener;
037:        import java.awt.image.BufferedImage;
038:
039:        import javax.swing.BorderFactory;
040:        import javax.swing.Box;
041:        import javax.swing.Icon;
042:        import javax.swing.ImageIcon;
043:        import javax.swing.JComponent;
044:        import javax.swing.JLabel;
045:        import javax.swing.JPanel;
046:        import javax.swing.JTextArea;
047:        import javax.swing.TransferHandler;
048:        import javax.swing.border.TitledBorder;
049:
050:        /**
051:         * A panel to display all the available information about an item to the user.
052:         */
053:        public class ItemPanel extends JPanel implements  MouseListener,
054:                MouseMotionListener {
055:
056:            /** Used to determine whether the mouse motion is considered to be a drag */
057:            private MouseEvent firstMouseEvent = null;
058:
059:            /** The product item that this panel represents. */
060:            private Item item;
061:
062:            /** The alternating background color. */
063:            private Color background;
064:
065:            /** The number of pixels that define a mouse drag */
066:            private static final int PIXEL_DISTANCE = 5;
067:
068:            /**
069:             * Panel to display information about an item.
070:             * @param title the name of the product
071:             * @param description the description of the item
072:             * @param price the item's price
073:             * @param category the item's product category
074:             * @param id the item's unique ID
075:             * @param image the image showing the item
076:             * @param bgColor which of the alternating colors to use for this panel
077:             */
078:            public ItemPanel(String title, String description, String price,
079:                    String category, String id, BufferedImage image,
080:                    Color bgColor) {
081:
082:                background = bgColor;
083:                addMouseMotionListener(this );
084:                addMouseListener(this );
085:
086:                item = new Item(title, description, price, category, id, image);
087:
088:                buildPanel();
089:            }
090:
091:            /**
092:             * Build up the components that make up this panel.
093:             */
094:            public void buildPanel() {
095:                Icon icon = new ImageIcon(item.getImage());
096:
097:                GridBagLayout gbl = new GridBagLayout();
098:                GridBagConstraints c = new GridBagConstraints();
099:                c.fill = GridBagConstraints.HORIZONTAL;
100:                gbl.setConstraints(this , c);
101:                setLayout(gbl);
102:
103:                Component spacer = Box.createRigidArea(new Dimension(20, 75));
104:
105:                JLabel imageLabel = new JLabel(icon);
106:
107:                add(imageLabel);
108:                add(spacer);
109:
110:                JPanel descrip = new JPanel();
111:                descrip.setLayout(new GridLayout(3, 1));
112:
113:                descrip.add(new JLabel(item.getTitle()));
114:                JTextArea descriptionLabel = new JTextArea(item
115:                        .getDescription());
116:
117:                descriptionLabel.setSize(350, 250);
118:                descriptionLabel.setOpaque(false);
119:                descriptionLabel.setEditable(false);
120:                descriptionLabel.setFocusable(false);
121:                descriptionLabel.setEnabled(false);
122:                descriptionLabel.setDisabledTextColor(Color.BLACK);
123:                descriptionLabel.setBorder(null);
124:                descriptionLabel.setLineWrap(true);
125:                descriptionLabel.setWrapStyleWord(true);
126:
127:                descrip.add(descriptionLabel);
128:                descrip.setBackground(background);
129:                descrip.add(new JLabel("Price: $" + item.getPrice()));
130:                add(descrip);
131:
132:                TitledBorder border = BorderFactory.createTitledBorder(item
133:                        .getCategory());
134:                border.setTitleJustification(TitledBorder.CENTER);
135:                setBorder(border);
136:            }
137:
138:            /**
139:             * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
140:             */
141:            public void mousePressed(MouseEvent e) {
142:                firstMouseEvent = e;
143:                e.consume();
144:            }
145:
146:            /**
147:             * Determine whether the mouse drag is long enough to initiate drag and drop
148:             * operation.
149:             * @param e the mouse event
150:             */
151:            public void mouseDragged(MouseEvent e) {
152:                if (firstMouseEvent != null) {
153:                    e.consume();
154:
155:                    int dx = Math.abs(e.getX() - firstMouseEvent.getX());
156:                    int dy = Math.abs(e.getY() - firstMouseEvent.getY());
157:                    //Arbitrarily define a 5-pixel shift as the
158:                    //official beginning of a drag.
159:                    if (dx > PIXEL_DISTANCE || dy > PIXEL_DISTANCE) {
160:                        //This is a drag, not a click.
161:                        JComponent c = (JComponent) e.getSource();
162:                        TransferHandler handler = c.getTransferHandler();
163:                        //Tell the transfer handler to initiate the drag.
164:                        handler.exportAsDrag(c, firstMouseEvent,
165:                                TransferHandler.COPY);
166:                        firstMouseEvent = null;
167:                    }
168:                }
169:            }
170:
171:            /**
172:             * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
173:             */
174:            public void mouseReleased(MouseEvent e) {
175:                firstMouseEvent = null;
176:            }
177:
178:            /**
179:             * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
180:             */
181:            public void mouseMoved(MouseEvent e) {
182:            }
183:
184:            /**
185:             * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
186:             */
187:            public void mouseClicked(MouseEvent arg0) {
188:            }
189:
190:            /**
191:             * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
192:             */
193:            public void mouseEntered(MouseEvent arg0) {
194:            }
195:
196:            /**
197:             * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
198:             */
199:            public void mouseExited(MouseEvent arg0) {
200:            }
201:
202:            /**
203:             * Get the item from this panel.
204:             * @return Returns the item.
205:             */
206:            public Item getItem() {
207:                return item;
208:            }
209:
210:            /**
211:             * Set the item for this panel.
212:             * @param item The item to set.
213:             */
214:            public void setItem(Item item) {
215:                this.item = item;
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.