Source Code Cross Referenced for DefaultTableCellRendererTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » table » 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 » Apache Harmony Java SE » javax package » javax.swing.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Anton Avtamonov
019:         * @version $Revision$
020:         */package javax.swing.table;
021:
022:        import java.awt.Color;
023:        import java.awt.Insets;
024:        import javax.swing.BasicSwingTestCase;
025:        import javax.swing.JTable;
026:        import javax.swing.UIManager;
027:        import javax.swing.border.EmptyBorder;
028:        import javax.swing.plaf.ComponentUI;
029:        import javax.swing.plaf.LabelUI;
030:
031:        public class DefaultTableCellRendererTest extends BasicSwingTestCase {
032:            private DefaultTableCellRenderer renderer;
033:
034:            public DefaultTableCellRendererTest(final String name) {
035:                super (name);
036:            }
037:
038:            @Override
039:            protected void setUp() throws Exception {
040:                renderer = new DefaultTableCellRenderer();
041:            }
042:
043:            @Override
044:            protected void tearDown() throws Exception {
045:                renderer = null;
046:            }
047:
048:            public void testDefaultTableCellRenderer() throws Exception {
049:                assertTrue(DefaultTableCellRenderer.noFocusBorder instanceof  EmptyBorder);
050:                assertEquals(new Insets(1, 1, 1, 1),
051:                        DefaultTableCellRenderer.noFocusBorder
052:                                .getBorderInsets(null));
053:            }
054:
055:            public void testSetForegroundBackground() throws Exception {
056:                PropertyChangeController controller = new PropertyChangeController();
057:                renderer.addPropertyChangeListener(controller);
058:                renderer.setForeground(Color.RED);
059:                assertEquals(Color.RED, renderer.getForeground());
060:                assertFalse(controller.isChanged());
061:                renderer.setBackground(Color.GREEN);
062:                assertEquals(Color.GREEN, renderer.getBackground());
063:                assertFalse(controller.isChanged());
064:                renderer.setBackground(null);
065:                renderer.setForeground(null);
066:                assertNull(renderer.getForeground());
067:                assertNull(renderer.getBackground());
068:                JTable table = new JTable();
069:                table.setBackground(Color.BLUE);
070:                table.setForeground(Color.RED);
071:                table.setSelectionBackground(Color.MAGENTA);
072:                table.setSelectionForeground(Color.CYAN);
073:                assertNull(renderer.getForeground());
074:                assertNull(renderer.getBackground());
075:                assertSame(renderer, renderer.getTableCellRendererComponent(
076:                        table, null, false, false, 0, 0));
077:                assertEquals(table.getBackground(), renderer.getBackground());
078:                assertEquals(table.getForeground(), renderer.getForeground());
079:                renderer.setForeground(Color.GRAY);
080:                renderer.setBackground(Color.YELLOW);
081:                renderer.getTableCellRendererComponent(table, null, false,
082:                        false, 0, 0);
083:                if (isHarmony()) {
084:                    assertEquals(table.getBackground(), renderer
085:                            .getBackground());
086:                    assertEquals(table.getForeground(), renderer
087:                            .getForeground());
088:                } else {
089:                    assertEquals(Color.YELLOW, renderer.getBackground());
090:                    assertEquals(Color.GRAY, renderer.getForeground());
091:                }
092:                renderer.getTableCellRendererComponent(table, null, true,
093:                        false, 0, 0);
094:                assertEquals(table.getSelectionBackground(), renderer
095:                        .getBackground());
096:                assertEquals(table.getSelectionForeground(), renderer
097:                        .getForeground());
098:            }
099:
100:            public void testUpdateUI() throws Exception {
101:                ComponentUI ui = renderer.getUI();
102:                assertTrue(ui instanceof  LabelUI);
103:                renderer.updateUI();
104:                assertSame(ui, renderer.getUI());
105:            }
106:
107:            public void testGetTableCellRendererComponent() throws Exception {
108:                JTable table = new JTable();
109:                table.setBackground(Color.BLUE);
110:                table.setForeground(Color.RED);
111:                table.setSelectionBackground(Color.MAGENTA);
112:                table.setSelectionForeground(Color.CYAN);
113:                assertSame(renderer, renderer.getTableCellRendererComponent(
114:                        table, null, false, false, 0, 0));
115:                assertEquals("", renderer.getText());
116:                assertSame(DefaultTableCellRenderer.noFocusBorder, renderer
117:                        .getBorder());
118:                assertEquals(table.getBackground(), renderer.getBackground());
119:                assertEquals(table.getForeground(), renderer.getForeground());
120:                assertEquals(table.getFont(), renderer.getFont());
121:                assertSame(renderer, renderer.getTableCellRendererComponent(
122:                        table, "any value", false, true, -1, -1));
123:                assertEquals("any value", renderer.getText());
124:                assertSame(UIManager
125:                        .getBorder("Table.focusCellHighlightBorder"), renderer
126:                        .getBorder());
127:                assertEquals(UIManager.getColor("Table.focusCellBackground"),
128:                        renderer.getBackground());
129:                assertEquals(UIManager.getColor("Table.focusCellForeground"),
130:                        renderer.getForeground());
131:                assertEquals(table.getFont(), renderer.getFont());
132:                assertSame(renderer, renderer.getTableCellRendererComponent(
133:                        table, "any value", true, false, 0, 0));
134:                assertEquals("any value", renderer.getText());
135:                assertSame(DefaultTableCellRenderer.noFocusBorder, renderer
136:                        .getBorder());
137:                assertEquals(table.getSelectionBackground(), renderer
138:                        .getBackground());
139:                assertEquals(table.getSelectionForeground(), renderer
140:                        .getForeground());
141:                assertEquals(table.getFont(), renderer.getFont());
142:                assertSame(renderer, renderer.getTableCellRendererComponent(
143:                        table, "any value", true, true, -1, -1));
144:                assertEquals("any value", renderer.getText());
145:                assertSame(UIManager
146:                        .getBorder("Table.focusCellHighlightBorder"), renderer
147:                        .getBorder());
148:                assertEquals(table.getSelectionBackground(), renderer
149:                        .getBackground());
150:                assertEquals(table.getSelectionForeground(), renderer
151:                        .getForeground());
152:                assertEquals(table.getFont(), renderer.getFont());
153:                table.addColumn(new TableColumn());
154:                assertSame(renderer, renderer.getTableCellRendererComponent(
155:                        table, "any value", true, true, 0, 0));
156:                assertEquals("any value", renderer.getText());
157:                assertSame(UIManager
158:                        .getBorder("Table.focusCellHighlightBorder"), renderer
159:                        .getBorder());
160:                assertEquals(table.getSelectionBackground(), renderer
161:                        .getBackground());
162:                assertEquals(table.getSelectionForeground(), renderer
163:                        .getForeground());
164:                assertEquals(table.getFont(), renderer.getFont());
165:                table.setModel(new DefaultTableModel() {
166:                    private static final long serialVersionUID = 1L;
167:
168:                    @Override
169:                    public boolean isCellEditable(final int row,
170:                            final int column) {
171:                        return false;
172:                    }
173:                });
174:                table.addColumn(new TableColumn());
175:                assertSame(renderer, renderer.getTableCellRendererComponent(
176:                        table, "any value", true, true, 0, 0));
177:                assertEquals("any value", renderer.getText());
178:                assertSame(UIManager
179:                        .getBorder("Table.focusCellHighlightBorder"), renderer
180:                        .getBorder());
181:                assertEquals(table.getSelectionBackground(), renderer
182:                        .getBackground());
183:                assertEquals(table.getSelectionForeground(), renderer
184:                        .getForeground());
185:                assertEquals(table.getFont(), renderer.getFont());
186:
187:                // regression test for HARMONY-1721
188:                DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
189:                Color c = renderer.getBackground();
190:                assertNull(c);
191:            }
192:
193:            public void testIsOpaque() throws Exception {
194:                assertTrue(renderer.isOpaque());
195:            }
196:
197:            public void testFirePropertyChange() throws Exception {
198:                PropertyChangeController controller = new PropertyChangeController();
199:                renderer.addPropertyChangeListener(controller);
200:                renderer.firePropertyChange("any", "a", "b");
201:                assertFalse(controller.isChanged());
202:                renderer.firePropertyChange("any", true, false);
203:                assertFalse(controller.isChanged());
204:            }
205:
206:            public void testSetText() throws Exception {
207:                assertEquals("", renderer.getText());
208:                renderer.setValue(null);
209:                assertEquals("", renderer.getText());
210:                renderer.setValue("any");
211:                assertEquals("any", renderer.getText());
212:                renderer.setValue(new Integer("4"));
213:                assertEquals("4", renderer.getText());
214:            }
215:
216:            public void testGetName() {
217:                DefaultTableCellRenderer cr = new DefaultTableCellRenderer();
218:                assertNull(cr.getName());
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.