Source Code Cross Referenced for CheckBoxListCellRenderer.java in  » Swing-Library » jide-common » com » jidesoft » swing » 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 » Swing Library » jide common » com.jidesoft.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)CheckBoxtListCellRenderer.java 5/11/2005
003:         *
004:         * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005:         */
006:
007:        package com.jidesoft.swing;
008:
009:        import javax.swing.*;
010:        import javax.swing.border.Border;
011:        import javax.swing.border.EmptyBorder;
012:        import java.awt.*;
013:        import java.awt.event.MouseEvent;
014:        import java.io.Serializable;
015:
016:        /**
017:         * Renders an item in a list using JCheckBox.
018:         */
019:        public class CheckBoxListCellRenderer extends JPanel implements 
020:                ListCellRenderer, Serializable {
021:
022:            protected static Border noFocusBorder;
023:
024:            /**
025:             * The checkbox that is used to paint the check box in cell renderer
026:             */
027:            protected JCheckBox _checkBox = new NullCheckBox();
028:            protected JLabel _label = new NullLabel();
029:
030:            /**
031:             * The label which appears after the check box.
032:             */
033:            protected ListCellRenderer _actualListRenderer;
034:
035:            public CheckBoxListCellRenderer(ListCellRenderer renderer) {
036:                if (noFocusBorder == null) {
037:                    noFocusBorder = new EmptyBorder(1, 1, 1, 1);
038:                }
039:                setOpaque(true);
040:                setBorder(noFocusBorder);
041:                setLayout(new BorderLayout(0, 0));
042:                add(_checkBox, BorderLayout.BEFORE_LINE_BEGINS);
043:                _actualListRenderer = renderer;
044:            }
045:
046:            /**
047:             * Constructs a default renderer object for an item
048:             * in a list.
049:             */
050:            public CheckBoxListCellRenderer() {
051:                this (null);
052:            }
053:
054:            public ListCellRenderer getActualListRenderer() {
055:                return _actualListRenderer;
056:            }
057:
058:            public void setActualListRenderer(
059:                    ListCellRenderer actualListRenderer) {
060:                _actualListRenderer = actualListRenderer;
061:            }
062:
063:            @Override
064:            public String getToolTipText(MouseEvent event) {
065:                if (_actualListRenderer instanceof  JComponent) {
066:                    Point p = event.getPoint();
067:                    p.translate(-_checkBox.getWidth(), 0);
068:                    MouseEvent newEvent = new MouseEvent(
069:                            ((JComponent) _actualListRenderer), event.getID(),
070:                            event.getWhen(), event.getModifiers(), p.x, p.y,
071:                            event.getClickCount(), event.isPopupTrigger());
072:
073:                    String tip = ((JComponent) _actualListRenderer)
074:                            .getToolTipText(newEvent);
075:
076:                    if (tip != null) {
077:                        return tip;
078:                    }
079:                }
080:                return super .getToolTipText(event);
081:            }
082:
083:            public Component getListCellRendererComponent(JList list,
084:                    Object value, int index, boolean isSelected,
085:                    boolean cellHasFocus) {
086:
087:                _checkBox.setPreferredSize(new Dimension(_checkBox
088:                        .getPreferredSize().width, 0));
089:                setComponentOrientation(list.getComponentOrientation());
090:
091:                Object actualValue;
092:                if (list instanceof  CheckBoxList) {
093:                    CheckBoxListSelectionModel selectionModel = ((CheckBoxList) list)
094:                            .getCheckBoxListSelectionModel();
095:                    if (selectionModel != null) {
096:                        boolean enabled = list.isEnabled()
097:                                && ((CheckBoxList) list).isCheckBoxEnabled()
098:                                && ((CheckBoxList) list)
099:                                        .isCheckBoxEnabled(index);
100:                        if (!enabled && !isSelected) {
101:                            setForeground(getBackground().darker());
102:                        }
103:                        _checkBox.setEnabled(enabled);
104:                        _checkBox.setSelected(selectionModel
105:                                .isSelectedIndex(index));
106:                    }
107:                    actualValue = value;
108:                } else if (list instanceof  CheckBoxListWithSelectable) {
109:                    if (value instanceof  Selectable) {
110:                        _checkBox
111:                                .setSelected(((Selectable) value).isSelected());
112:                        boolean enabled = list.isEnabled()
113:                                && ((Selectable) value).isEnabled()
114:                                && ((CheckBoxListWithSelectable) list)
115:                                        .isCheckBoxEnabled();
116:                        if (!enabled && !isSelected) {
117:                            setForeground(getBackground().darker());
118:                        }
119:                        _checkBox.setEnabled(enabled);
120:                    } else {
121:                        boolean enabled = list.isEnabled();
122:                        if (!enabled && !isSelected) {
123:                            setForeground(getBackground().darker());
124:                        }
125:                        _checkBox.setEnabled(enabled);
126:                    }
127:
128:                    if (value instanceof  DefaultSelectable) {
129:                        actualValue = ((DefaultSelectable) value).getObject();
130:                    } else {
131:                        actualValue = value;
132:                    }
133:                } else {
134:                    throw new IllegalArgumentException(
135:                            "CheckBoxListCellRenderer should only be used for CheckBoxList.");
136:                }
137:
138:                if (_actualListRenderer != null) {
139:                    JComponent listCellRendererComponent = (JComponent) _actualListRenderer
140:                            .getListCellRendererComponent(list, value, index,
141:                                    isSelected, cellHasFocus);
142:                    if (list instanceof  CheckBoxList) {
143:                        if (!((CheckBoxList) list).isCheckBoxVisible(index)) {
144:                            return listCellRendererComponent;
145:                        }
146:                    } else if (list instanceof  CheckBoxListWithSelectable) {
147:                        if (!((CheckBoxListWithSelectable) list)
148:                                .isCheckBoxVisible(index)) {
149:                            return listCellRendererComponent;
150:                        }
151:                    }
152:                    Border border = listCellRendererComponent.getBorder();
153:                    setBorder(border);
154:                    listCellRendererComponent.setBorder(BorderFactory
155:                            .createEmptyBorder());
156:                    if (getComponentCount() == 2) {
157:                        remove(1);
158:                    }
159:                    add(listCellRendererComponent);
160:                    setBackground(listCellRendererComponent.getBackground());
161:                    setForeground(listCellRendererComponent.getForeground());
162:                } else {
163:                    if (isSelected) {
164:                        setBackground(list.getSelectionBackground());
165:                        setForeground(list.getSelectionForeground());
166:                    } else {
167:                        setBackground(list.getBackground());
168:                        setForeground(list.getForeground());
169:                    }
170:                    if (getComponentCount() == 2) {
171:                        remove(1);
172:                    }
173:                    add(_label);
174:                    customizeDefaultCellRenderer(actualValue);
175:                    setFont(list.getFont());
176:                }
177:
178:                return this ;
179:            }
180:
181:            /**
182:             * Customizes the cell renderer. By default, it will use toString to covert the object
183:             * and use it as the text for the checkbox. You can subclass it to set an icon, change alignment etc.
184:             * Since "this" is a JCheckBox, you can call all methods available on JCheckBox in the overridden method.
185:             *
186:             * @param value
187:             */
188:            protected void customizeDefaultCellRenderer(Object value) {
189:                if (value instanceof  Icon) {
190:                    _label.setIcon((Icon) value);
191:                    _label.setText("");
192:                } else {
193:                    _label.setIcon(null);
194:                    _label.setText((value == null) ? "" : value.toString());
195:                }
196:            }
197:
198:            /**
199:             * A subclass of DefaultListCellRenderer that implements UIResource.
200:             * DefaultListCellRenderer doesn't implement UIResource
201:             * directly so that applications can safely override the
202:             * cellRenderer property with DefaultListCellRenderer subclasses.
203:             * <p/>
204:             * <strong>Warning:</strong>
205:             * Serialized objects of this class will not be compatible with
206:             * future Swing releases. The current serialization support is
207:             * appropriate for short term storage or RMI between applications running
208:             * the same version of Swing.  As of 1.4, support for long term storage
209:             * of all JavaBeans<sup><font size="-2">TM</font></sup>
210:             * has been added to the <code>java.beans</code> package.
211:             * Please see {@link java.beans.XMLEncoder}.
212:             */
213:            public static class UIResource extends CheckBoxListCellRenderer
214:                    implements  javax.swing.plaf.UIResource {
215:            }
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.