Source Code Cross Referenced for TableUtils.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » components » 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 » abeille forms designer » com.jeta.swingbuilder.gui.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.gui.components;
020:
021:        import java.awt.Container;
022:
023:        import javax.swing.JScrollPane;
024:        import javax.swing.JTable;
025:        import javax.swing.JViewport;
026:        import javax.swing.table.JTableHeader;
027:        import javax.swing.table.TableColumn;
028:        import javax.swing.table.TableColumnModel;
029:        import javax.swing.table.TableModel;
030:
031:        /**
032:         * This class contains utility methods for doing common tasks with JTables
033:         * 
034:         * @author Jeff Tassin
035:         */
036:        public class TableUtils {
037:
038:            /**
039:             * Clears the column header icons for a given table
040:             */
041:            public static void clearColumnHeaders(JTable table) {
042:                if (table == null)
043:                    return;
044:
045:                TableColumnModel columnmodel = table.getColumnModel();
046:                // reset all other column sort modes to NONE at this point
047:                int count = columnmodel.getColumnCount();
048:
049:                for (int index = 0; index < count; index++) {
050:                    TableColumn tc = columnmodel.getColumn(index);
051:                    Object robj = tc.getHeaderRenderer();
052:                    if (robj instanceof  SortedColumnHeaderRenderer)
053:                        ((SortedColumnHeaderRenderer) robj)
054:                                .setSortMode(SortMode.NONE);
055:                }
056:                JTableHeader th = table.getTableHeader();
057:                th.repaint();
058:            }
059:
060:            /**
061:             * Converts a table row the the corresponding model index. This is needed
062:             * when the table is sorted. If the table is not sorted, the table index
063:             * will equal the model index
064:             * 
065:             * @param table
066:             *            the table whose index to convert
067:             * @param index
068:             *            the table index to convert
069:             * @return the corresponding model index
070:             */
071:            public static int convertTableToModelIndex(JTable table, int index) {
072:                if (index >= 0 && (table.getModel() instanceof  TableSorter)) {
073:                    TableSorter sorter = (TableSorter) table.getModel();
074:                    return sorter.getModelRow(index);
075:                } else
076:                    return index;
077:            }
078:
079:            /**
080:             * Creates a panel that contains a table that can be sorted can be sorted.
081:             * The table is scrollable and has automatically resized subsequent columns
082:             * 
083:             * @param model
084:             *            the data model for the table. Don't send in a TableSorter
085:             *            here.
086:             * @param sortable
087:             *            if true, then we will return a table that has sortable
088:             *            columns. This will wrap the tablemodel with a TableSorter.
089:             * @return a container that contains the table.
090:             */
091:            public static JTable createBasicTablePanel(TableModel model,
092:                    boolean sortable) {
093:                JTable table = null;
094:                if (sortable) {
095:                    TableSorter sorter = new TableSorter(model);
096:                    table = new JTable(sorter);
097:                    initializeTableSorter(sorter, table);
098:                } else {
099:                    table = new JTable(model);
100:                }
101:
102:                table.setCellSelectionEnabled(true);
103:                return table;
104:            }
105:
106:            /**
107:             * Intializes a table and a table sorter
108:             */
109:            public static void initializeTableSorter(TableSorter sorter,
110:                    JTable table) {
111:                sorter.addMouseListenerToHeaderInTable(table);
112:
113:                // set the renderer for each column
114:                TableColumnModel columnmodel = table.getColumnModel();
115:                int count = columnmodel.getColumnCount();
116:                for (int index = 0; index < count; index++) {
117:                    TableColumn column = columnmodel.getColumn(index);
118:                    column.setHeaderRenderer(new SortedColumnHeaderRenderer());
119:                }
120:            }
121:
122:            /**
123:             * * Creates row header for table with row number (starting with 1)
124:             * displayed
125:             */
126:            public static void removeRowHeader(JTable table) {
127:                Container p = table.getParent();
128:                if (p instanceof  JViewport) {
129:                    Container gp = p.getParent();
130:                    if (gp instanceof  JScrollPane) {
131:                        JScrollPane scrollPane = (JScrollPane) gp;
132:                        scrollPane.setRowHeader(null);
133:                    }
134:                }
135:            }
136:
137:            /** Creates row header for table with row number (starting with 1) displayed */
138:            public static TableRowHeader setRowHeader(JTable table) {
139:                return setRowHeader(table, -1);
140:            }
141:
142:            /**
143:             * Creats a row header for the given table. The row number is displayed to
144:             * the left of the table ( starting with row 1).
145:             * 
146:             * @param table
147:             *            the table to create the row header for
148:             * @param headerWidth
149:             *            the number of characters to size the header
150:             */
151:            public static TableRowHeader setRowHeader(JTable table,
152:                    int headerWidth) {
153:                boolean isok = false;
154:
155:                TableRowHeader result = null;
156:                Container p = table.getParent();
157:                if (p instanceof  JViewport) {
158:                    Container gp = p.getParent();
159:                    if (gp instanceof  JScrollPane) {
160:                        JScrollPane scrollPane = (JScrollPane) gp;
161:                        result = new TableRowHeader(table);
162:                        scrollPane.setRowHeaderView(result);
163:                        isok = true;
164:                    }
165:                }
166:                assert (isok);
167:                return result;
168:            }
169:
170:            /**
171:             * Stops any editing for a given cell on a table.
172:             */
173:            public static void stopEditing(JTable table) {
174:                if (table == null) {
175:                    assert (false);
176:                    return;
177:                }
178:
179:                if (table.isEditing()) {
180:                    int row = table.getEditingColumn();
181:                    int col = table.getEditingRow();
182:                    if (row >= 0 && col >= 0) {
183:                        javax.swing.CellEditor editor = table.getCellEditor(
184:                                row, col);
185:                        editor.stopCellEditing();
186:                    }
187:                }
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.