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


001:        package com.xoetrope.swing;
002:
003:        import java.awt.Color;
004:        import java.awt.Component;
005:        import java.awt.event.MouseAdapter;
006:        import java.awt.event.MouseEvent;
007:        import javax.swing.JCheckBox;
008:        import javax.swing.JList;
009:        import javax.swing.ListCellRenderer;
010:        import javax.swing.ListModel;
011:        import javax.swing.ListSelectionModel;
012:        import javax.swing.UIManager;
013:        import javax.swing.border.Border;
014:        import javax.swing.border.EmptyBorder;
015:        import net.xoetrope.swing.XList;
016:        import net.xoetrope.xui.helper.XuiUtilities;
017:        import com.xoetrope.swing.list.XCheckListCellRenderer;
018:
019:        /**
020:         * A list box that contains a list of check boxes
021:         *
022:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
023:         * the GNU Public License (GPL), please see license.txt for more details. If
024:         * you make commercial use of this software you must purchase a commercial
025:         * license from Xoetrope.</p>
026:         * <p> $Revision: 1.8 $</p>
027:         */
028:        public class XCheckList extends XList {
029:            private XCheckListCellRenderer renderer;
030:
031:            /**
032:             * Create a new checked list
033:             */
034:            public XCheckList() {
035:                super ();
036:                init();
037:            }
038:
039:            /**
040:             * Create a new checked list
041:             * @param items an array of items to add to the list
042:             */
043:            public XCheckList(Object[] items) {
044:                super ();
045:
046:                JCheckBox[] checkItems = new JCheckBox[items.length];
047:                for (int i = 0; i < items.length; i++)
048:                    checkItems[i] = new JCheckBox(items[i].toString());
049:
050:                setListData(checkItems);
051:                init();
052:            }
053:
054:            void init() {
055:                setCellRenderer(renderer = new XCheckListCellRenderer(this ));
056:
057:                addMouseListener(new MouseAdapter() {
058:                    public void mousePressed(MouseEvent e) {
059:                        int index = locationToIndex(e.getPoint());
060:
061:                        if (index != -1) {
062:                            JCheckBox checkbox = (JCheckBox) getModel()
063:                                    .getElementAt(index);
064:                            checkbox.setSelected(!checkbox.isSelected());
065:                            repaint();
066:                        }
067:                    }
068:                });
069:
070:                setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
071:            }
072:
073:            /**
074:             * Set the list to its default selection state
075:             */
076:            public void setDefaultSelection() {
077:            }
078:
079:            /**
080:             * Add an item to the listmodel
081:             * @param s the item to be added
082:             */
083:            public void addItem(String s) {
084:                listModel.add(listModel.getSize(), new JCheckBox(s));
085:            }
086:
087:            /**
088:             * Set the colors for alternate ( odd ) row colors
089:             * @param frgd the foreground color
090:             * @param bkgd the background color
091:             */
092:            public void setAltUnselectedColors(Color frgd, Color bkgd) {
093:                renderer.setAltUnselectedColors(frgd, bkgd);
094:            }
095:
096:            /**
097:             * Sets the delegate that is used to paint each cell in the list.
098:             * The job of a cell renderer is discussed in detail in the
099:             * <a href="#renderer">class level documentation</a>.
100:             * <p>
101:             * If the {@code prototypeCellValue} property is {@code non-null},
102:             * setting the cell renderer also causes the {@code fixedCellWidth} and
103:             * {@code fixedCellHeight} properties to be re-calculated. Only one
104:             * <code>PropertyChangeEvent</code> is generated however -
105:             * for the <code>cellRenderer</code> property.
106:             * <p>
107:             * The default value of this property is provided by the {@code ListUI}
108:             * delegate, i.e. by the look and feel implementation.
109:             * <p>
110:             * This is a JavaBeans bound property.
111:             *
112:             * @param cellRenderer the <code>ListCellRenderer</code>
113:             * 				that paints list cells
114:             * @see #getCellRenderer
115:             * @beaninfo
116:             *       bound: true
117:             *   attribute: visualUpdate true
118:             * description: The component used to draw the cells.
119:             */
120:            public void setCellRenderer(ListCellRenderer cellRenderer) {
121:                if (cellRenderer instanceof  XCheckListCellRenderer)
122:                    renderer = (XCheckListCellRenderer) cellRenderer;
123:
124:                super .setCellRenderer(cellRenderer);
125:            }
126:
127:            /**
128:             * @return the selected objects in the list
129:             */
130:            public Object[] getSelectedObjects() {
131:                return getSelectedItems();
132:            }
133:
134:            /**
135:             * Get a list of the checked items in the list
136:             * @return the checked items
137:             */
138:            public String[] getSelectedItems() {
139:                ListModel lm = getModel();
140:                int listItems = lm.getSize();
141:
142:                // Count the selected items
143:                int numSelected = 0;
144:                for (int i = 0; i < listItems; i++) {
145:                    if (((JCheckBox) lm.getElementAt(i)).isSelected())
146:                        numSelected++;
147:                }
148:
149:                // Store the selected texts.
150:                String selItems[] = new String[numSelected];
151:                int j = 0;
152:                for (int i = 0; i < listItems; i++) {
153:                    JCheckBox cbi = (JCheckBox) lm.getElementAt(i);
154:                    if (cbi.isSelected())
155:                        selItems[j++] = cbi.getText();
156:                }
157:
158:                return selItems;
159:            }
160:
161:            /**
162:             * Enable the selection of an item in the list
163:             * @param idx the index of the item
164:             * @param selected true to force selection of the item
165:             */
166:            public void enableItem(int idx, boolean selected) {
167:                ((JCheckBox) getModel().getElementAt(idx)).setEnabled(selected);
168:            }
169:
170:            /**
171:             * Force the selection of an item in the list
172:             * @param idx the index of the item
173:             * @param selected true to force selection of the item
174:             */
175:            public void selectItem(int idx, boolean selected) {
176:                ((JCheckBox) getModel().getElementAt(idx))
177:                        .setSelected(selected);
178:            }
179:
180:            /**
181:             * Get the checked state of the indexed item
182:             * @param idx the index of the item
183:             * @return true if the item is checked
184:             */
185:            public boolean isItemChecked(int idx) {
186:                return ((JCheckBox) getModel().getElementAt(idx)).isSelected();
187:            }
188:
189:            /**
190:             * Select/unselect all the items in the list
191:             * @param select true to select the items, false to unselect
192:             */
193:            public void toggleAll(boolean select) {
194:                ListModel lm = getModel();
195:                int listItems = lm.getSize();
196:
197:                for (int i = 0; i < listItems; i++)
198:                    ((JCheckBox) lm.getElementAt(i)).setSelected(select);
199:
200:                if (invoker != null)
201:                    invoker.invoke();
202:
203:                repaint();
204:            }
205:
206:            /**
207:             * Get the list selection mode. This component returns 2. The selection 
208:             * corresponds to the items that are checked and not the items that are 
209:             * highlighted.
210:             * @return 
211:             * <ul>
212:             * <li>0=ListSelectionModel.SINGLE_SELECTION,</li>
213:             * <li>1=ListSelectionModel.SINGLE_INTERVAL_SELECTION,</li>
214:             * <li>2=ListSelectionModel.MULTIPLE_INTERVAL_SELECTION</li>
215:             * </ul> 
216:             */
217:            public int getSelectionMode() {
218:                return 2;
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.