Source Code Cross Referenced for JSplitPaneTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » 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 » Apache Harmony Java SE » javax package » javax.swing 
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;
021:
022:        import java.awt.Component;
023:        import java.awt.Dimension;
024:        import java.awt.Graphics;
025:        import javax.swing.plaf.SplitPaneUI;
026:        import javax.swing.plaf.basic.BasicSplitPaneUI;
027:        import javax.swing.plaf.metal.MetalSplitPaneUI;
028:
029:        public class JSplitPaneTest extends SwingTestCase {
030:            private JSplitPane pane;
031:
032:            public JSplitPaneTest(final String name) {
033:                super (name);
034:            }
035:
036:            @Override
037:            protected void setUp() throws Exception {
038:                pane = new JSplitPane();
039:                propertyChangeController = new PropertyChangeController();
040:                pane.addPropertyChangeListener(propertyChangeController);
041:            }
042:
043:            @Override
044:            protected void tearDown() throws Exception {
045:                pane = null;
046:            }
047:
048:            public void testJSplitPane() throws Exception {
049:                assertTrue(pane.getLeftComponent() instanceof  JButton);
050:                assertTrue(pane.getRightComponent() instanceof  JButton);
051:                assertFalse(pane.isContinuousLayout());
052:                assertEquals(0, pane.getLastDividerLocation());
053:                assertEquals(-1, pane.getDividerLocation());
054:                assertEquals(JSplitPane.HORIZONTAL_SPLIT, pane.getOrientation());
055:                pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
056:                assertNull(pane.getLeftComponent());
057:                assertNull(pane.getRightComponent());
058:                assertFalse(pane.isContinuousLayout());
059:                assertEquals(0, pane.getLastDividerLocation());
060:                assertEquals(-1, pane.getDividerLocation());
061:                assertEquals(JSplitPane.VERTICAL_SPLIT, pane.getOrientation());
062:                pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
063:                assertEquals(JSplitPane.HORIZONTAL_SPLIT, pane.getOrientation());
064:                testExceptionalCase(new IllegalArgumentCase() {
065:                    @Override
066:                    public void exceptionalAction() throws Exception {
067:                        new JSplitPane(2);
068:                    }
069:                });
070:                pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
071:                assertTrue(pane.isContinuousLayout());
072:                assertEquals(JSplitPane.HORIZONTAL_SPLIT, pane.getOrientation());
073:                pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false);
074:                assertFalse(pane.isContinuousLayout());
075:                assertEquals(JSplitPane.VERTICAL_SPLIT, pane.getOrientation());
076:                testExceptionalCase(new IllegalArgumentCase() {
077:                    @Override
078:                    public void exceptionalAction() throws Exception {
079:                        new JSplitPane(-1, true);
080:                    }
081:                });
082:                Component left = new JButton();
083:                Component right = new JButton();
084:                pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, left, right);
085:                assertEquals(left, pane.getLeftComponent());
086:                assertEquals(right, pane.getRightComponent());
087:                assertFalse(pane.isContinuousLayout());
088:                assertEquals(JSplitPane.VERTICAL_SPLIT, pane.getOrientation());
089:                pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, left,
090:                        right);
091:                assertEquals(left, pane.getLeftComponent());
092:                assertEquals(right, pane.getRightComponent());
093:                assertTrue(pane.isContinuousLayout());
094:                assertEquals(JSplitPane.VERTICAL_SPLIT, pane.getOrientation());
095:                testExceptionalCase(new IllegalArgumentCase() {
096:                    @Override
097:                    public void exceptionalAction() throws Exception {
098:                        new JSplitPane(2, true, new JButton(), new JButton());
099:                    }
100:                });
101:            }
102:
103:            public void testGetSetUpdateUI() throws Exception {
104:                assertNotNull(pane.getUI());
105:                SplitPaneUI ui = new MetalSplitPaneUI();
106:                pane.setUI(ui);
107:                assertEquals(ui, pane.getUI());
108:                pane.updateUI();
109:                assertNotSame(ui, pane.getUI());
110:            }
111:
112:            public void testGetUIClassID() throws Exception {
113:                assertEquals("SplitPaneUI", pane.getUIClassID());
114:            }
115:
116:            public void testGetSetDividerSize() throws Exception {
117:                assertEquals(UIManager.getInt("SplitPane.dividerSize"), pane
118:                        .getDividerSize());
119:                pane.setDividerSize(20);
120:                assertEquals(20, pane.getDividerSize());
121:                assertTrue(propertyChangeController.isChanged("dividerSize"));
122:            }
123:
124:            public void testGetSetLeftTopComponent() throws Exception {
125:                assertTrue(pane.getLeftComponent() instanceof  JButton);
126:                Component left = new JPanel();
127:                pane.setLeftComponent(left);
128:                assertEquals(left, pane.getLeftComponent());
129:                assertEquals(left, pane.getTopComponent());
130:                assertEquals(left, pane.getComponent(2));
131:                Component top = new JPanel();
132:                pane.setTopComponent(top);
133:                assertEquals(top, pane.getLeftComponent());
134:                assertEquals(top, pane.getTopComponent());
135:                assertEquals(top, pane.getComponent(2));
136:            }
137:
138:            public void testGetSetRightBottomComponent() throws Exception {
139:                assertTrue(pane.getRightComponent() instanceof  JButton);
140:                Component right = new JPanel();
141:                pane.setRightComponent(right);
142:                assertEquals(right, pane.getRightComponent());
143:                assertEquals(right, pane.getBottomComponent());
144:                assertEquals(right, pane.getComponent(2));
145:                Component bottom = new JPanel();
146:                pane.setBottomComponent(bottom);
147:                assertEquals(bottom, pane.getRightComponent());
148:                assertEquals(bottom, pane.getBottomComponent());
149:                assertEquals(bottom, pane.getComponent(2));
150:            }
151:
152:            public void testIsSetOneTouchExpandable() throws Exception {
153:                assertFalse(pane.isOneTouchExpandable());
154:                pane.setOneTouchExpandable(true);
155:                assertTrue(pane.isOneTouchExpandable());
156:                assertTrue(propertyChangeController
157:                        .isChanged("oneTouchExpandable"));
158:            }
159:
160:            public void testGetSetLastDividerLocation() throws Exception {
161:                assertEquals(0, pane.getLastDividerLocation());
162:                pane.setLastDividerLocation(20);
163:                assertEquals(20, pane.getLastDividerLocation());
164:                assertTrue(propertyChangeController
165:                        .isChanged("lastDividerLocation"));
166:            }
167:
168:            public void testGetSetOrientation() throws Exception {
169:                assertEquals(JSplitPane.HORIZONTAL_SPLIT, pane.getOrientation());
170:                pane.setOrientation(JSplitPane.VERTICAL_SPLIT);
171:                assertEquals(JSplitPane.VERTICAL_SPLIT, pane.getOrientation());
172:                assertTrue(propertyChangeController.isChanged("orientation"));
173:            }
174:
175:            public void testIsSetContinuousLayout() throws Exception {
176:                assertFalse(pane.isContinuousLayout());
177:                pane.setContinuousLayout(true);
178:                assertTrue(pane.isContinuousLayout());
179:                assertTrue(propertyChangeController
180:                        .isChanged("continuousLayout"));
181:            }
182:
183:            public void testGetSetResizeWeight() throws Exception {
184:                assertEquals(0, 0, pane.getResizeWeight());
185:                pane.setResizeWeight(0.4);
186:                assertEquals(0, 0.4, pane.getResizeWeight());
187:                assertTrue(propertyChangeController.isChanged("resizeWeight"));
188:                testExceptionalCase(new IllegalArgumentCase() {
189:                    @Override
190:                    public void exceptionalAction() throws Exception {
191:                        pane.setResizeWeight(-1);
192:                    }
193:                });
194:                testExceptionalCase(new IllegalArgumentCase() {
195:                    @Override
196:                    public void exceptionalAction() throws Exception {
197:                        pane.setResizeWeight(1.5);
198:                    }
199:                });
200:            }
201:
202:            public void testResetToPreferredSizes() throws Exception {
203:                if (isHarmony()) {
204:                    ((JComponent) pane.getLeftComponent())
205:                            .setPreferredSize(new Dimension(100, 50));
206:                    ((JComponent) pane.getRightComponent())
207:                            .setPreferredSize(new Dimension(100, 50));
208:                    pane.setSize(300, 100);
209:                    pane.setBorder(BorderFactory.createEmptyBorder(10, 20, 30,
210:                            40));
211:                    pane.setDividerLocation(40);
212:                    assertEquals(40, pane.getDividerLocation());
213:                    pane.resetToPreferredSizes();
214:                    assertEquals(120, pane.getDividerLocation());
215:                }
216:            }
217:
218:            public void testGetSetDividerLocation() throws Exception {
219:                assertEquals(-1, pane.getDividerLocation());
220:                ((JComponent) pane.getLeftComponent())
221:                        .setPreferredSize(new Dimension(100, 50));
222:                ((JComponent) pane.getRightComponent())
223:                        .setPreferredSize(new Dimension(100, 50));
224:                pane.setSize(300, 100);
225:                pane.setBorder(BorderFactory.createEmptyBorder(10, 20, 30, 40));
226:                pane.setDividerLocation(40);
227:                assertTrue(propertyChangeController
228:                        .isChanged("dividerLocation"));
229:                assertTrue(propertyChangeController
230:                        .isChanged("lastDividerLocation"));
231:                assertEquals(40, pane.getDividerLocation());
232:                assertEquals(0, pane.getUI().getDividerLocation(pane));
233:                pane.getUI().setDividerLocation(pane, 50);
234:                assertEquals(0, pane.getUI().getDividerLocation(pane));
235:                assertEquals(40, pane.getDividerLocation());
236:                pane.getLayout().layoutContainer(pane);
237:                assertEquals(40, pane.getDividerLocation());
238:                assertEquals(40, pane.getUI().getDividerLocation(pane));
239:                pane.setDividerLocation(0.3);
240:                assertEquals((300 - 10) * 0.3, pane.getDividerLocation(), 0);
241:                pane.setDividerLocation(0.5);
242:                assertEquals((300 - 10) * 0.5, pane.getDividerLocation(), 0);
243:                pane.setDividerLocation(0.6);
244:                assertEquals((300 - 10) * 0.6, pane.getDividerLocation(), 0);
245:            }
246:
247:            public void testGetMinimumMaximumDividerLocation() throws Exception {
248:                SplitPaneUI ui = new BasicSplitPaneUI() {
249:                    @Override
250:                    public int getMinimumDividerLocation(final JSplitPane sp) {
251:                        return 20;
252:                    }
253:
254:                    @Override
255:                    public int getMaximumDividerLocation(final JSplitPane sp) {
256:                        return 40;
257:                    }
258:                };
259:                pane.setUI(ui);
260:                assertEquals(20, pane.getMinimumDividerLocation());
261:                assertEquals(40, pane.getMaximumDividerLocation());
262:            }
263:
264:            public void testRemove() throws Exception {
265:                assertNotNull(pane.getLeftComponent());
266:                pane.remove(pane.getLeftComponent());
267:                assertNull(pane.getLeftComponent());
268:                assertNotNull(pane.getRightComponent());
269:                pane.remove(pane.getRightComponent());
270:                assertNull(pane.getRightComponent());
271:                pane = new JSplitPane();
272:                assertNotNull(pane.getRightComponent());
273:                pane.remove(1);
274:                assertNull(pane.getRightComponent());
275:                assertNotNull(pane.getLeftComponent());
276:                pane.remove(0);
277:                assertNull(pane.getLeftComponent());
278:                pane = new JSplitPane();
279:                assertNotNull(pane.getLeftComponent());
280:                assertNotNull(pane.getRightComponent());
281:                pane.removeAll();
282:                assertNull(pane.getLeftComponent());
283:                assertNull(pane.getRightComponent());
284:            }
285:
286:            public void testIsValidateRoot() throws Exception {
287:                assertTrue(pane.isValidateRoot());
288:            }
289:
290:            public void testAddImpl() throws Exception {
291:                pane.removeAll();
292:                assertEquals(0, pane.getComponentCount());
293:                Component left = new JButton();
294:                pane.add(left, JSplitPane.LEFT);
295:                assertEquals(1, pane.getComponentCount());
296:                assertEquals(left, pane.getLeftComponent());
297:                assertEquals(left, pane.getTopComponent());
298:                Component top = new JButton();
299:                pane.add(top, JSplitPane.TOP);
300:                assertEquals(1, pane.getComponentCount());
301:                assertEquals(top, pane.getLeftComponent());
302:                assertEquals(top, pane.getTopComponent());
303:                Component right = new JButton();
304:                pane.add(right, JSplitPane.RIGHT);
305:                assertEquals(2, pane.getComponentCount());
306:                assertEquals(right, pane.getRightComponent());
307:                assertEquals(right, pane.getBottomComponent());
308:                Component bottom = new JButton();
309:                pane.add(bottom, JSplitPane.BOTTOM);
310:                assertEquals(2, pane.getComponentCount());
311:                assertEquals(bottom, pane.getRightComponent());
312:                assertEquals(bottom, pane.getBottomComponent());
313:                Component divider = new JButton();
314:                pane.add(divider, JSplitPane.DIVIDER);
315:                assertEquals(3, pane.getComponentCount());
316:                pane.removeAll();
317:                left = new JButton();
318:                right = new JButton();
319:                pane.addImpl(right, JSplitPane.RIGHT, 1);
320:                pane.addImpl(left, JSplitPane.LEFT, 0);
321:                assertSame(right, pane.getComponent(0));
322:                assertSame(left, pane.getComponent(1));
323:                pane.removeAll();
324:                left = new JButton();
325:                pane.add(left);
326:                assertEquals(left, pane.getLeftComponent());
327:                right = new JButton();
328:                pane.add(right);
329:                assertEquals(right, pane.getRightComponent());
330:                testExceptionalCase(new IllegalArgumentCase() {
331:                    @Override
332:                    public void exceptionalAction() throws Exception {
333:                        pane.add(new JButton());
334:                    }
335:                });
336:                testExceptionalCase(new IllegalArgumentCase() {
337:                    @Override
338:                    public void exceptionalAction() throws Exception {
339:                        pane.add(new JButton(), "wrong");
340:                    }
341:                });
342:            }
343:
344:            public void testPaintChildren() throws Exception {
345:                final Marker m = new Marker();
346:                SplitPaneUI ui = new BasicSplitPaneUI() {
347:                    @Override
348:                    public void finishedPaintingChildren(final JSplitPane sp,
349:                            final Graphics g) {
350:                        m.mark();
351:                    }
352:                };
353:                pane.setUI(ui);
354:                pane.paintChildren(createTestGraphics());
355:                assertTrue(m.isMarked());
356:            }
357:
358:            public void testGetAccessibleContext() throws Exception {
359:                assertTrue(pane.getAccessibleContext() instanceof  JSplitPane.AccessibleJSplitPane);
360:            }
361:
362:            public void testIsOpaque() throws Exception {
363:                assertTrue(pane.isOpaque());
364:            }
365:
366:            private class Marker {
367:                private boolean marked;
368:
369:                public void mark() {
370:                    marked = true;
371:                }
372:
373:                public boolean isMarked() {
374:                    return marked;
375:                }
376:            }
377:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.