Source Code Cross Referenced for XGraphicListCellRenderer.java in  » XML-UI » xui32 » com » xoetrope » tools » 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 » XML UI » xui32 » com.xoetrope.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.tools;
002:
003:        import com.xoetrope.svg.XSvgImageMap;
004:        import com.xoetrope.swing.list.XAltListCellRenderer;
005:        import java.awt.AlphaComposite;
006:        import java.awt.Color;
007:        import java.awt.Component;
008:        import java.awt.Composite;
009:        import java.awt.Font;
010:        import java.awt.FontMetrics;
011:        import java.awt.Graphics;
012:        import java.awt.Graphics2D;
013:        import java.awt.Image;
014:        import java.lang.reflect.Method;
015:        import java.text.BreakIterator;
016:        import java.util.ArrayList;
017:        import java.util.HashMap;
018:        import java.util.LinkedList;
019:        import javax.accessibility.AccessibleContext;
020:        import javax.swing.DefaultListCellRenderer;
021:        import javax.swing.DefaultListModel;
022:        import javax.swing.ImageIcon;
023:        import javax.swing.JComponent;
024:        import javax.swing.JLabel;
025:        import javax.swing.JList;
026:        import javax.swing.JPanel;
027:        import javax.swing.JTextArea;
028:        import javax.swing.ListModel;
029:        import javax.swing.UIManager;
030:        import javax.swing.event.AncestorListener;
031:        import net.xoetrope.optional.svg.svgsalamander.XSvgPainter;
032:        import net.xoetrope.swing.XImage;
033:        import net.xoetrope.swing.XList;
034:        import net.xoetrope.swing.dnd.XDragInfo;
035:        import net.xoetrope.xui.XProject;
036:        import net.xoetrope.xui.XProjectManager;
037:        import net.xoetrope.xui.helper.XuiUtilities;
038:        import net.xoetrope.xui.style.XStyle;
039:        import net.xoetrope.xui.style.XStyleManager;
040:
041:        /**
042:         * Renders a combobox list with an image icon
043:         */
044:        public class XGraphicListCellRenderer extends XAltListCellRenderer {
045:            private XStyle comboStyle;
046:            private ArrayList imageNames;
047:            private XStyleManager styleManager;
048:            private String previousEntry;
049:            private boolean first;
050:            private HashMap info;
051:            private JLabel totalPrice;
052:            private JPanel detailsPanel;
053:            private XImage image;
054:            private XSvgImageMap imageMap;
055:            private XSvgPainter painter;
056:            private JLabel infoLabel, priceLabel;
057:            private double imageWidth, priceX, priceWidth, infoWidth;
058:            private int previousSize;
059:
060:            private Color unselectedForeground;
061:            private Color unselectedBackground;
062:            private Color altUnselectedForeground;
063:            private Color altUnselectedBackground;
064:
065:            public XGraphicListCellRenderer(JLabel t) {
066:                super ();
067:
068:                totalPrice = t;
069:
070:                XProject currentProject = XProjectManager.getCurrentProject();
071:                styleManager = currentProject.getStyleManager();
072:                comboStyle = styleManager.getStyle("base/edit");
073:
074:                imageWidth = 0.0862;
075:                priceX = 0.8154;
076:                priceWidth = 0.1847;
077:                infoWidth = 0.7262;
078:
079:                Font font = new Font("Arial", Font.BOLD, 12);
080:
081:                image = new XImage();
082:
083:                //    painter = new XSvgPainter( image );
084:                //    image.setPainter( painter );
085:                add(image);
086:
087:                infoLabel = new JLabel();
088:                infoLabel.setFont(font);
089:                add(infoLabel);
090:
091:                priceLabel = new JLabel();
092:                priceLabel.setFont(font);
093:                priceLabel.setHorizontalAlignment(JLabel.RIGHT);
094:                add(priceLabel);
095:
096:                first = true;
097:            }
098:
099:            /**
100:             * Set the colors for alternate ( odd ) row colors
101:             * @param frgd the foreground color
102:             * @param bkgd the background color
103:             */
104:            public void setAltUnselectedColors(Color frgd, Color bkgd) {
105:                altUnselectedForeground = frgd;
106:                altUnselectedBackground = bkgd;
107:            }
108:
109:            /*
110:             * This method finds the image and text corresponding
111:             * to the selected value and returns the label, set-up
112:             * to display the text and image.
113:             */
114:            public Component getListCellRendererComponent(JList list,
115:                    Object value, int index, boolean isSelected,
116:                    boolean cellHasFocus) {
117:                Component renderer = super .getListCellRendererComponent(list,
118:                        value, index, isSelected, cellHasFocus);
119:                renderer.setFont(list.getFont());
120:
121:                if (first) {
122:                    image.setBounds(1, 1, (int) (list.getWidth() * imageWidth),
123:                            28);
124:                    priceLabel.setBounds((int) (list.getWidth() * priceX), 1,
125:                            (int) (list.getWidth() * priceWidth), 28);
126:                    infoLabel.setBounds(
127:                            (int) (list.getWidth() * imageWidth + 5), 1,
128:                            (int) (list.getWidth() * infoWidth), 28);
129:
130:                    first = false;
131:                }
132:
133:                XDragInfo dragInfo = (XDragInfo) value;
134:                //    painter.setImage( XProjectManager.getCurrentProject().findResource( (String)dragInfo.get( "image" ) ) ); 
135:                String s = (String) dragInfo.get("image");
136:                image.setImage(XProjectManager.getCurrentProject().getImage(s));
137:
138:                Font font = new Font("Arial", Font.PLAIN, 12);
139:                FontMetrics fontMetrics = getFontMetrics(font);
140:                String info = clipStringIfNecessary(infoLabel, fontMetrics,
141:                        (String) dragInfo.get(dragInfo.TITLE), (int) (list
142:                                .getWidth() * infoWidth) - 15);
143:
144:                infoLabel.setText(info);
145:                priceLabel.setText((String) dragInfo.get("price") + " ");
146:
147:                int percentage = 100;
148:                if (!list.isEnabled()) {
149:                    percentage = 50;
150:                }
151:
152:                if (unselectedForeground == null) {
153:                    unselectedForeground = list.getForeground();
154:                    unselectedBackground = new Color(213, 247, 251);
155:                }
156:
157:                if (altUnselectedForeground == null) {
158:                    altUnselectedForeground = list.getForeground();
159:                    altUnselectedBackground = list.getBackground();
160:                }
161:
162:                if (isSelected) {
163:                    renderer.setBackground(XuiUtilities.unsaturateColor(list
164:                            .getSelectionBackground(), percentage));
165:                    renderer.setForeground(XuiUtilities.unsaturateColor(list
166:                            .getSelectionBackground(), percentage));
167:
168:                    infoLabel.setForeground(XuiUtilities.unsaturateColor(list
169:                            .getSelectionForeground(), percentage));
170:                    priceLabel.setForeground(XuiUtilities.unsaturateColor(list
171:                            .getSelectionForeground(), percentage));
172:                } else {
173:                    XStyle comboStyle = styleManager.getStyle("base/edit");
174:
175:                    renderer
176:                            .setBackground(index % 2 == 0 ? XuiUtilities
177:                                    .unsaturateColor((unselectedBackground),
178:                                            percentage) : comboStyle
179:                                    .getStyleAsColor(comboStyle.COLOR_BACK));
180:                    renderer
181:                            .setForeground(index % 2 == 0 ? XuiUtilities
182:                                    .unsaturateColor((unselectedBackground),
183:                                            percentage) : comboStyle
184:                                    .getStyleAsColor(comboStyle.COLOR_BACK));
185:
186:                    infoLabel.setForeground(comboStyle
187:                            .getStyleAsColor(comboStyle.COLOR_FORE));
188:                    priceLabel.setForeground(comboStyle
189:                            .getStyleAsColor(comboStyle.COLOR_FORE));
190:                }
191:
192:                return renderer;
193:            }
194:
195:            public String clipStringIfNecessary(JComponent c, FontMetrics fm,
196:                    String caption, int availTextWidth) {
197:                if ((caption == null) || (caption.length() == 0))
198:                    return "";
199:                try {
200:                    /* This is a hack, using a private class so expect it to break when the JDK
201:                     * is upgraded */
202:                    Class klass = Class.forName("sun.swing.SwingUtilities2");
203:                    Class params[] = new Class[4];
204:                    params[0] = JComponent.class;
205:                    params[1] = FontMetrics.class;
206:                    params[2] = String.class;
207:                    params[3] = int.class;
208:                    Method clipIfNecessary = klass.getMethod(
209:                            "clipStringIfNecessary", params);
210:
211:                    if (clipIfNecessary != null) {
212:                        Object args[] = new Object[4];
213:                        args[0] = this ;
214:                        args[1] = fm;
215:                        args[2] = caption;
216:                        args[3] = new Integer(availTextWidth);
217:                        caption = (String) clipIfNecessary.invoke(null, args);
218:                        return caption;
219:                    }
220:                } catch (Exception ex) {
221:                    ex.printStackTrace();
222:                }
223:                return "";
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.