Source Code Cross Referenced for DefaultItemRenderer.java in  » Web-Framework » wingS » com » javujavu » javux » wings » item » 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 » Web Framework » wingS » com.javujavu.javux.wings.item 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *	Javu WingS - Lightweight Java Component Set
003:         *	Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004:         *	e-mail: ksadlocha@programics.com
005:         *
006:         *	This library is free software; you can redistribute it and/or
007:         *	modify it under the terms of the GNU Lesser General Public
008:         *	License as published by the Free Software Foundation; either
009:         *	version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *	This library is distributed in the hope that it will be useful,
012:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *	Lesser General Public License for more details.
015:         *
016:         *	You should have received a copy of the GNU Lesser General Public
017:         *	License along with this library; if not, write to the Free Software
018:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        package com.javujavu.javux.wings.item;
022:
023:        import java.awt.Dimension;
024:        import java.awt.Graphics;
025:        import java.awt.Image;
026:        import java.awt.Insets;
027:        import java.awt.Rectangle;
028:        import com.javujavu.javux.wings.Style;
029:        import com.javujavu.javux.wings.WingComponent;
030:        import com.javujavu.javux.wings.WingImage;
031:        import com.javujavu.javux.wings.WingSkin;
032:        import com.javujavu.javux.wings.WingToolkit;
033:
034:        /**
035:         * This class implements item renderer used by WingS components by default.
036:         * This renderer treat item objects in the following way:<br>
037:         * <ul>
038:         * <li>if the item object implements <code>ItemRenderer</code> uses the item as a renderer
039:         * <li>if the item object is a <code>WingImage</code> renders it as an image
040:         * <li>it the item object is a <code>Boolean</code> renders it as an image using checkbox images
041:         * <li>if the item object is not null renders it as a <code>String</code> using <code>item.toString()</code>
042:         * </ul>
043:         * <br>
044:         * <b>This is one of the core WingS classes required by all the components</b><br>
045:         * <br>
046:         * <b>This class is thread safe.</b>
047:         **/
048:        public class DefaultItemRenderer implements  ItemRenderer {
049:            /**
050:             * @see ItemRenderer#getItemSize(java.lang.Object, com.javujavu.javux.wings.WingComponent, com.javujavu.javux.wings.Style, java.lang.Object)
051:             */
052:            public Dimension getItemSize(Object item, WingComponent owner,
053:                    Style style, Object context) {
054:                if (item instanceof  ItemRenderer) {
055:                    return ((ItemRenderer) item).getItemSize(item, owner,
056:                            style, context);
057:                } else {
058:                    WingImage icon = null;
059:                    String text = null;
060:                    if (item instanceof  WingImage) {
061:                        icon = (WingImage) item;
062:                    } else if (item instanceof  Boolean) {
063:                        icon = WingSkin.getImage(((Boolean) item)
064:                                .booleanValue() ? "checkbox.on.normal.icon"
065:                                : "checkbox.normal.icon", null);
066:                    }
067:
068:                    if (icon == null && item != null) {
069:                        text = item.toString();
070:                    }
071:                    if (icon == null)
072:                        icon = style.icon;
073:                    return WingToolkit.calcLabelSize(icon, text, style
074:                            .getFont(owner.getWingFont()), style.margin,
075:                            style.gap, owner);
076:                }
077:            }
078:
079:            /**
080:             * @see ItemRenderer#drawItem(java.awt.Graphics, int, int, int, int, java.lang.Object, com.javujavu.javux.wings.WingComponent, com.javujavu.javux.wings.Style, java.awt.Insets, int, int, java.lang.Object)
081:             */
082:            public void drawItem(Graphics g, int x, int y, int width,
083:                    int height, Object item, WingComponent owner, Style style,
084:                    Insets margin, int alignment, int textPosition,
085:                    Object context) {
086:                if (item instanceof  ItemRenderer) {
087:                    ((ItemRenderer) item).drawItem(g, x, y, width, height,
088:                            item, owner, style, margin, alignment,
089:                            textPosition, context);
090:                } else {
091:                    WingToolkit.drawBackground(g, x, y, width, height, style,
092:                            owner);
093:                    WingImage icon = null;
094:                    String text = null;
095:                    if (item instanceof  WingImage) {
096:                        icon = (WingImage) item;
097:                    } else if (item instanceof  Boolean) {
098:                        icon = WingSkin.getImage(((Boolean) item)
099:                                .booleanValue() ? "checkbox.on.normal.icon"
100:                                : "checkbox.normal.icon", null);
101:                    }
102:                    if (icon == null && item != null) {
103:                        text = item.toString();
104:                    }
105:                    if (icon == null)
106:                        icon = style.icon;
107:                    WingToolkit.drawLabel(g, x, y, width, height, icon, text,
108:                            style.getFont(owner.getWingFont()), style
109:                                    .getForeground(owner.getForeground()),
110:                            style.focus, margin, style.gap, alignment,
111:                            textPosition, owner);
112:                }
113:            }
114:
115:            /**
116:             * @see ItemRenderer#imageUpdate(java.awt.Image, int, int, int, int, int, java.lang.Object, com.javujavu.javux.wings.WingComponent, com.javujavu.javux.wings.Style, java.awt.Rectangle)
117:             */
118:            public boolean imageUpdate(Image img, int infoflags, int x, int y,
119:                    int width, int height, Object item, WingComponent owner,
120:                    Style style, Rectangle itemBounds) {
121:                if (item instanceof  ItemRenderer) {
122:                    return ((ItemRenderer) item).imageUpdate(img, infoflags, x,
123:                            y, width, height, item, owner, style, itemBounds);
124:                }
125:                if ((item instanceof  WingImage && ((WingImage) item).getImage()
126:                        .equals(img))
127:                        || (style.image != null && style.image.getImage()
128:                                .equals(img))
129:                        || (style.icon != null && style.icon.getImage().equals(
130:                                img))) {
131:                    return owner.repaintVisible(itemBounds.x, itemBounds.y,
132:                            itemBounds.width, itemBounds.height)
133:                            && (infoflags & (WingComponent.ALLBITS | WingComponent.ABORT)) == 0;
134:                }
135:                return false;
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.