Source Code Cross Referenced for ComponentAdapter.java in  » Swing-Library » swingx » org » jdesktop » swingx » decorator » 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 » swingx » org.jdesktop.swingx.decorator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ComponentAdapter.java,v 1.8 2006/07/21 09:38:26 kleopatra Exp $
003:         *
004:         * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005:         * Santa Clara, California 95054, U.S.A. All rights reserved.
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         * 
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020:         */
021:
022:        package org.jdesktop.swingx.decorator;
023:
024:        import javax.swing.JComponent;
025:
026:        /**
027:         * Abstract base class for all component data adapter classes.
028:         * A <code>ComponentAdapter</code> allows a {@link Filter}, {@link Sorter},
029:         * or {@link Highlighter} to interact with a {@link #target} component through a
030:         * common API.
031:         * 
032:         * It has two aspects:
033:         * <ul>
034:         * <li> interact with the data of the component. The methods for this are those 
035:         * taking row/column indices as parameters. The coordinates
036:         * are in model coordinate system. Typical clients of are Filters.
037:         * <li> interact with the view state for a given data element. The row/cloumn fields and the
038:         * parameterless methods service this aspect. The coordinates are in view coordinate system.
039:         * Typical clients are the highlighting part of Highlighters.
040:         * </ul>
041:         * 
042:         * The adapter is responsible for mapping column coordinates. 
043:         * 
044:         * All input column 
045:         * indices are in model coordinates with exactly two exceptions:
046:         * <ul>
047:         * <li> {@link #column} in column view coordinates
048:         * <li> the mapping method {@link #viewToModel(int)} in view coordinates
049:         * </ul>
050:         * 
051:         * All input row indices are in model coordinates with exactly two exceptions:
052:         * <ul>
053:         * <li> {@link #row} in row view coordinates
054:         * <li> the getter for the filtered value {@link #getFilteredValueAt(int, int)} 
055:         * takes the row in view coordinates.
056:         * </ul>
057:         *  
058:         * 
059:         * @author Ramesh Gupta
060:         */
061:        public abstract class ComponentAdapter {
062:            /** current row in view coordinates. */
063:            public int row = 0;
064:            /** current column in view coordinates. */
065:            public int column = 0;
066:            protected final JComponent target;
067:
068:            /**
069:             * Constructs a ComponentAdapter, setting the specified component as the
070:             * target component.
071:             *
072:             * @param component target component for this adapter
073:             */
074:            public ComponentAdapter(JComponent component) {
075:                target = component;
076:            }
077:
078:            public JComponent getComponent() {
079:                return target;
080:            }
081:
082:            //---------------------------- accessing the target's model
083:
084:            /**
085:             * returns the column's label (= headerValue).
086:             * 
087:             * Used f.i. in SearchPanel to fill the field with the 
088:             * column name.
089:             * 
090:             * Note: it's up to the implementation to decide for which
091:             * columns it returns a name - most will do so for the
092:             * subset with isTestable = true.
093:             * 
094:             * @param columnIndex in model coordinates
095:             * @return column name or null if not found/not testable.
096:             */
097:            public abstract String getColumnName(int columnIndex);
098:
099:            /**
100:             * returns the logical name (== identifier) of the column at 
101:             * columnIndex in model coordinates.
102:             * 
103:             * Used f.i. JNTable to store and apply column properties by identifier.
104:             * 
105:             * Note: it's up to the implementation to decide for which
106:             * columns it returns a name - most will do so for the
107:             * subset with isTestable = true.
108:             * 
109:             * @param columnIndex in model coordinates
110:             * @return the String value of the column identifier at columnIndex
111:             *   or null if no identifier set
112:             */
113:            public abstract String getColumnIdentifier(int columnIndex);
114:
115:            /**
116:             * Returns the number of columns in the target's data model.
117:             *
118:             * @return the number of columns in the target's data model.
119:             */
120:            public int getColumnCount() {
121:                return 1; // default for combo-boxes, lists, and trees
122:            }
123:
124:            /**
125:             * Returns the number of rows in the target's data model.
126:             *
127:             * @return the number of rows in the target's data model.
128:             */
129:            public int getRowCount() {
130:                return 0;
131:            }
132:
133:            /**
134:             * Returns the value of the target component's cell identified by the
135:             * specified row and column in model coordinates.
136:             *
137:             * @param row in model coordinates
138:             * @param column in model coordinates
139:             * @return the value of the target component's cell identified by the
140:             * specified row and column
141:             */
142:            public abstract Object getValueAt(int row, int column);
143:
144:            public abstract void setValueAt(Object aValue, int row, int column);
145:
146:            public abstract boolean isCellEditable(int row, int column);
147:
148:            /**
149:             * returns true if the column should be included in testing.
150:             * Here: returns true if visible (that is modelToView gives a valid
151:             * view column coordinate).
152:             * 
153:             * @param column in model coordinates
154:             * @return true if the column should be included in testing
155:             */
156:            public boolean isTestable(int column) {
157:                return modelToView(column) >= 0;
158:            }
159:
160:            //----------------------- accessing the target's view state
161:
162:            /**
163:             * Returns the value of the cell identified by this adapter by invoking
164:             * {@link #getValueAt(int, int)}, passing in the {@link #row} and
165:             * {@link #column} values of this adapter. For target components that don't
166:             * support multiple columns, the value of <code>column</code> is always zero.
167:             *
168:             * PENDING: needs clarification/cleanup - getValueAt(row, column) expects 
169:             * model coordinates!.
170:             * 
171:             * @return the value of the cell identified by this adapter
172:             */
173:            public Object getValue() {
174:                return getValueAt(row, column);
175:            }
176:
177:            /**
178:             * returns the filtered value of the cell identified by the row
179:             * in view coordinate and the column in model coordinates.
180:             * 
181:             * Note: the asymetry of the coordinates is intentional - clients like
182:             * Highlighters are interested in view values but might need to access
183:             * non-visible columns for testing.
184:             * 
185:             * @param row
186:             * @param column
187:             * @return the filtered value of the cell identified by the row
188:             * in view coordinate and the column in model coordiantes
189:             */
190:            public abstract Object getFilteredValueAt(int row, int column);
191:
192:            /**
193:             * Returns true if the cell identified by this adapter currently has focus;
194:             * Otherwise, it returns false.
195:             *
196:             * @return true if the cell identified by this adapter currently has focus;
197:             * 	Otherwise, return false
198:             */
199:            public abstract boolean hasFocus();
200:
201:            /**
202:             * Returns true if the cell identified by this adapter is currently selected;
203:             * Otherwise, it returns false.
204:             *
205:             * @return true if the cell identified by this adapter is currently selected;
206:             * 	Otherwise, return false
207:             */
208:            public abstract boolean isSelected();
209:
210:            /**
211:             * Returns true if the cell identified by this adapter is currently expanded;
212:             * Otherwise, it returns false. For components that do not support
213:             * hierarchical data, this method always returns true because the cells in
214:             * such components can never be collapsed.
215:             *
216:             * @return true if the cell identified by this adapter is currently expanded;
217:             * 	Otherwise, return false
218:             */
219:            public boolean isExpanded() {
220:                return true; // sensible default for JList and JTable
221:            }
222:
223:            /**
224:             * Returns true if the cell identified by this adapter is a leaf node;
225:             * Otherwise, it returns false. For components that do not support
226:             * hierarchical data, this method always returns true because the cells in
227:             * such components can never have children.
228:             *
229:             * @return true if the cell identified by this adapter is a leaf node;
230:             * 	Otherwise, return false
231:             */
232:            public boolean isLeaf() {
233:                return true; // sensible default for JList and JTable
234:            }
235:
236:            /**
237:             * Returns true if the cell identified by this adapter displays the hierarchical node;
238:             * Otherwise, it returns false. For components that do not support
239:             * hierarchical data, this method always returns false because the cells in
240:             * such components can never have children.
241:             *
242:             * @return true if the cell identified by this adapter displays the hierarchical node;
243:             * 	Otherwise, return false
244:             */
245:            public boolean isHierarchical() {
246:                return false; // sensible default for JList and JTable
247:            }
248:
249:            /**
250:             * For target components that support multiple columns in their model,
251:             * along with column reordering in the view, this method transforms the
252:             * specified columnIndex from model coordinates to view coordinates. For all
253:             * other types of target components, this method returns the columnIndex
254:             * unchanged.
255:             *
256:             * @param columnIndex index of a column in model coordinates
257:             * @return index of the specified column in view coordinates
258:             */
259:            public int modelToView(int columnIndex) {
260:                return columnIndex; // sensible default for JList and JTree
261:            }
262:
263:            /**
264:             * For target components that support multiple columns in their model,
265:             * along with column reordering in the view, this method transforms the
266:             * specified columnIndex from view coordinates to model coordinates. For all
267:             * other types of target components, this method returns the columnIndex
268:             * unchanged.
269:             *
270:             * @param columnIndex index of a column in view coordinates
271:             * @return index of the specified column in model coordinates
272:             */
273:            public int viewToModel(int columnIndex) {
274:                return columnIndex; // sensible default for JList and JTree
275:            }
276:
277:            public void refresh() {
278:                target.revalidate();
279:                target.repaint();
280:            }
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.