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


001:        /*
002:         * Created on 09.06.2006
003:         *
004:         */
005:        package org.jdesktop.swingx;
006:
007:        import java.awt.Component;
008:        import java.awt.Dimension;
009:        import java.awt.GraphicsEnvironment;
010:        import java.awt.event.ActionEvent;
011:        import java.awt.event.MouseEvent;
012:        import java.util.logging.Logger;
013:
014:        import javax.swing.AbstractAction;
015:        import javax.swing.Action;
016:        import javax.swing.JTable;
017:        import javax.swing.KeyStroke;
018:        import javax.swing.table.DefaultTableCellRenderer;
019:        import javax.swing.table.DefaultTableModel;
020:        import javax.swing.table.TableCellRenderer;
021:        import javax.swing.table.TableColumn;
022:
023:        import org.jdesktop.swingx.table.TableColumnExt;
024:
025:        public class JXTableHeaderTest extends InteractiveTestCase {
026:            private static final Logger LOG = Logger
027:                    .getLogger(JXTableHeaderTest.class.getName());
028:
029:            /**
030:             * Issue #390-swingx: JXTableHeader: throws AIOOB on removing dragged column.
031:             * Test that getDraggedColumn is null if removed.
032:             * 
033:             * Problem was reported on mac:
034:             * http://forums.java.net/jive/thread.jspa?threadID=18368&tstart=0
035:             * when hiding column while drag(?) is in process.
036:             * 
037:             *
038:             */
039:            public void testDraggedColumnRemoved() {
040:                JXTable table = new JXTable(10, 2);
041:                TableColumnExt columnExt = table.getColumnExt(0);
042:                table.getTableHeader().setDraggedColumn(columnExt);
043:                // sanity assert
044:                assertEquals(columnExt, table.getTableHeader()
045:                        .getDraggedColumn());
046:                table.getColumnModel().removeColumn(columnExt);
047:                assertNull("draggedColumn must be null if removed", table
048:                        .getTableHeader().getDraggedColumn());
049:            }
050:
051:            /**
052:             * Issue #390-swingx: JXTableHeader: throws AIOOB on removing dragged column.
053:             * Test that getDraggedColumn is visible or null.
054:             * 
055:             * Problem was reported on mac:
056:             * http://forums.java.net/jive/thread.jspa?threadID=18368&tstart=0
057:             * when hiding column while drag(?) is in process.
058:             */
059:            public void testDraggedColumnVisible() {
060:                JXTable table = new JXTable(10, 2);
061:                TableColumnExt columnExt = table.getColumnExt(0);
062:                table.getTableHeader().setDraggedColumn(columnExt);
063:                // sanity assert
064:                assertEquals(columnExt, table.getTableHeader()
065:                        .getDraggedColumn());
066:                columnExt.setVisible(false);
067:                assertNull("dragged column must visible or null", table
068:                        .getTableHeader().getDraggedColumn());
069:            }
070:
071:            /**
072:             * Issue 334-swingx: BasicTableHeaderUI.getPrefSize doesn't respect 
073:             *   all renderere's size requirements.
074:             *
075:             */
076:            public void testPreferredHeight() {
077:                JXTable table = new JXTable(10, 2);
078:                TableColumnExt columnExt = table.getColumnExt(1);
079:                columnExt
080:                        .setTitle("<html><center>Line 1<br>Line 2</center></html>");
081:                JXTableHeader tableHeader = (JXTableHeader) table
082:                        .getTableHeader();
083:                TableCellRenderer renderer = tableHeader.getCellRenderer(1);
084:                Component comp = renderer.getTableCellRendererComponent(table,
085:                        columnExt.getHeaderValue(), false, false, -1, 1);
086:                Dimension prefRendererSize = comp.getPreferredSize();
087:                assertEquals("Header pref height must respect renderer",
088:                        prefRendererSize.height,
089:                        tableHeader.getPreferredSize().height);
090:            }
091:
092:            /**
093:             * test doc'ed xheader.getToolTipText(MouseEvent) behaviour.
094:             *
095:             */
096:            public void testColumnToolTip() {
097:                JXTable table = new JXTable(10, 2);
098:                TableColumnExt columnExt = table.getColumnExt(0);
099:                JXTableHeader tableHeader = (JXTableHeader) table
100:                        .getTableHeader();
101:                MouseEvent event = new MouseEvent(tableHeader, 0, 0, 0, 40, 5,
102:                        0, false);
103:                DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
104:                String rendererToolTip = "rendererToolTip";
105:                renderer.setToolTipText(rendererToolTip);
106:                columnExt.setHeaderRenderer(renderer);
107:                assertEquals(rendererToolTip, tableHeader.getToolTipText(event));
108:                String columnToolTip = "columnToolTip";
109:                columnExt.setToolTipText(columnToolTip);
110:                assertEquals(columnToolTip, tableHeader.getToolTipText(event));
111:
112:            }
113:
114:            /**
115:             * #212-swingx: second last column cannot be set to invisible programatically.
116:             * 
117:             * One reason for the "trick" of reselecting the last is that 
118:             * the header and with it the columnControl vanishes if there is 
119:             * no visible column.
120:             * 
121:             * 
122:             *
123:             */
124:            public void testHeaderVisibleWithoutColumns() {
125:                // This test will not work in a headless configuration.
126:                if (GraphicsEnvironment.isHeadless()) {
127:                    LOG.info("cannot run headerVisible - headless environment");
128:                    return;
129:                }
130:                JXTable table = new JXTable();
131:                table.setColumnControlVisible(true);
132:                wrapWithScrollingInFrame(table, "");
133:                assertEquals("headerHeight must be > 0", 16, table
134:                        .getTableHeader().getHeight());
135:                assertEquals("headerWidth must be table width", table
136:                        .getWidth(), table.getTableHeader().getWidth());
137:
138:            }
139:
140:            /**
141:             * #212-swingx: second last column cannot be set to invisible programatically.
142:             * 
143:             * One reason for the "trick" of reselecting the last is that 
144:             * the header and with it the columnControl vanishes if there is 
145:             * no visible column.
146:             * 
147:             * 
148:             *
149:             */
150:            public void testHeaderVisibleWithColumns() {
151:                // This test will not work in a headless configuration.
152:                if (GraphicsEnvironment.isHeadless()) {
153:                    LOG.info("cannot run headerVisible - headless environment");
154:                    return;
155:                }
156:                JXTable table = new JXTable(10, 2);
157:                table.setColumnControlVisible(true);
158:                wrapWithScrollingInFrame(table, "");
159:                assertEquals("headerHeight must be > 0", 16, table
160:                        .getTableHeader().getHeight());
161:                table.setModel(new DefaultTableModel());
162:                assertEquals("headerHeight must be > 0", 16, table
163:                        .getTableHeader().getHeight());
164:
165:            }
166:
167:            //--------------------------------- visual checks
168:            /**
169:             * Issue #390-swingx: JXTableHeader: throws AIOOB on removing dragged column.
170:             * 
171:             */
172:            public void interactiveDraggedColumnRemoved() {
173:                final JXTable table = new JXTable(10, 5);
174:                Action deleteColumn = new AbstractAction("deleteCurrentColumn") {
175:
176:                    public void actionPerformed(ActionEvent e) {
177:                        TableColumn column = table.getTableHeader()
178:                                .getDraggedColumn();
179:                        if (column == null)
180:                            return;
181:                        table.getColumnModel().removeColumn(column);
182:                    }
183:
184:                };
185:                KeyStroke keyStroke = KeyStroke.getKeyStroke("F1");
186:                table.getInputMap(JTable.WHEN_IN_FOCUSED_WINDOW).put(keyStroke,
187:                        "f1");
188:                table.getActionMap().put("f1", deleteColumn);
189:                JXFrame frame = wrapWithScrollingInFrame(table,
190:                        "Remove dragged column with F1");
191:                frame.setVisible(true);
192:            }
193:
194:            /**
195:             * Visual demo that header is always visible.
196:             */
197:            public void interactiveHeaderVisible() {
198:                final JXTable table = new JXTable();
199:                table.setColumnControlVisible(true);
200:                JXFrame frame = wrapWithScrollingInFrame(table,
201:                        "header always visible");
202:                Action action = new AbstractAction("toggle model") {
203:
204:                    public void actionPerformed(ActionEvent e) {
205:                        int columnCount = table.getColumnCount(true);
206:                        table
207:                                .setModel(columnCount > 0 ? new DefaultTableModel()
208:                                        : new DefaultTableModel(10, 2));
209:
210:                    }
211:
212:                };
213:                addAction(frame, action);
214:                frame.setVisible(true);
215:
216:            }
217:
218:            public static void main(String args[]) {
219:                JXTableHeaderTest test = new JXTableHeaderTest();
220:                try {
221:                    test.runInteractiveTests();
222:                    //   test.runInteractiveTests("interactive.*Siz.*");
223:                } catch (Exception e) {
224:                    System.err
225:                            .println("exception when executing interactive tests:");
226:                    e.printStackTrace();
227:                }
228:            }
229:
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.