Source Code Cross Referenced for BasicTabbedPaneUITest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » basic » 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.plaf.basic 
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 Vadim L. Bogdanov
019:         * @version $Revision$
020:         */package javax.swing.plaf.basic;
021:
022:        import java.awt.Component;
023:        import java.awt.Font;
024:        import java.awt.FontMetrics;
025:        import java.awt.Insets;
026:        import java.awt.KeyboardFocusManager;
027:        import java.awt.Rectangle;
028:        import java.beans.PropertyChangeListener;
029:        import java.util.Arrays;
030:        import javax.swing.ImageIcon;
031:        import javax.swing.JButton;
032:        import javax.swing.JComponent;
033:        import javax.swing.JFrame;
034:        import javax.swing.JLabel;
035:        import javax.swing.JTabbedPane;
036:        import javax.swing.JToolBar;
037:        import javax.swing.SwingConstants;
038:        import javax.swing.SwingUtilities;
039:        import javax.swing.UIManager;
040:        import javax.swing.plaf.ComponentUI;
041:        import javax.swing.plaf.UIResource;
042:        import javax.swing.SwingTestCase;
043:
044:        public class BasicTabbedPaneUITest extends SwingTestCase {
045:            private JTabbedPane tabbed;
046:
047:            private BasicTabbedPaneUI ui;
048:
049:            private JFrame frame;
050:
051:            @Override
052:            protected void setUp() throws Exception {
053:                super .setUp();
054:                tabbed = new JTabbedPane() {
055:                    private static final long serialVersionUID = 1L;
056:
057:                    @Override
058:                    public FontMetrics getFontMetrics(Font f) {
059:                        return BasicTabbedPaneUITest.this .getFontMetrics(f);
060:                    }
061:                };
062:                ui = new BasicTabbedPaneUI();
063:                tabbed.setUI(ui);
064:                tabbed.addTab("tab1", new JLabel());
065:                tabbed.setIconAt(0, new ImageIcon());
066:                tabbed.setDisabledIconAt(0, new ImageIcon());
067:                tabbed.addTab("tabtab2", new JLabel());
068:                FontMetrics fm = ui.getFontMetrics();
069:                tabbed.setSize(ui.calculateTabWidth(tabbed.getTabPlacement(),
070:                        0, fm)
071:                        + ui.calculateTabWidth(tabbed.getTabPlacement(), 1, fm)
072:                        + 10, 100);
073:                tabbed.doLayout();
074:            }
075:
076:            @Override
077:            protected void tearDown() throws Exception {
078:                super .tearDown();
079:                if (frame != null) {
080:                    frame.dispose();
081:                    frame = null;
082:                }
083:            }
084:
085:            public BasicTabbedPaneUITest(final String name) {
086:                super (name);
087:            }
088:
089:            /*
090:             * Class under test for ComponentUI createUI(JComponent)
091:             */
092:            public void testCreateUI() {
093:                ComponentUI ui1 = BasicTabbedPaneUI.createUI(tabbed);
094:                assertTrue(ui1 instanceof  BasicTabbedPaneUI);
095:                ComponentUI ui2 = BasicTabbedPaneUI.createUI(tabbed);
096:                assertNotSame(ui1, ui2);
097:            }
098:
099:            public void testRotateInsets() {
100:                Insets insets = new Insets(1, 2, 3, 4);
101:                Insets rotated = new Insets(0, 0, 0, 0);
102:                BasicTabbedPaneUI.rotateInsets(insets, rotated,
103:                        SwingConstants.LEFT);
104:                assertEquals(new Insets(2, 1, 4, 3), rotated);
105:                BasicTabbedPaneUI.rotateInsets(insets, rotated,
106:                        SwingConstants.BOTTOM);
107:                assertEquals(new Insets(3, 2, 1, 4), rotated);
108:                BasicTabbedPaneUI.rotateInsets(insets, rotated,
109:                        SwingConstants.RIGHT);
110:                assertEquals(new Insets(2, 3, 4, 1), rotated);
111:            }
112:
113:            public void testBasicTabbedPaneUI() {
114:                // does nothing
115:            }
116:
117:            public void testAssureRectsCreated() {
118:                ui.assureRectsCreated(5);
119:                assertEquals(5, ui.rects.length);
120:                assertNotNull(ui.rects[4]);
121:            }
122:
123:            public void testCalculateMaxTabHeight() {
124:                int tabPlacement = tabbed.getTabPlacement();
125:                int fontHeight = tabbed.getFontMetrics(tabbed.getFont())
126:                        .getHeight();
127:                int height1 = ui
128:                        .calculateTabHeight(tabPlacement, 0, fontHeight);
129:                int height2 = ui
130:                        .calculateTabHeight(tabPlacement, 1, fontHeight);
131:                assertEquals(Math.max(height1, height2), ui
132:                        .calculateMaxTabHeight(tabPlacement));
133:            }
134:
135:            public void testCalculateMaxTabWidth() {
136:                int tabPlacement = tabbed.getTabPlacement();
137:                FontMetrics fm = tabbed.getFontMetrics(tabbed.getFont());
138:                int w1 = ui.calculateTabWidth(tabPlacement, 0, fm);
139:                int w2 = ui.calculateTabWidth(tabPlacement, 1, fm);
140:                assertEquals(Math.max(w1, w2), ui
141:                        .calculateMaxTabWidth(tabPlacement));
142:            }
143:
144:            public void testCalculateTabAreaHeight() {
145:                int tabPlacement = SwingConstants.TOP;
146:                assertEquals(14, ui.calculateTabAreaHeight(tabPlacement, 1, 10));
147:                assertEquals(22, ui.calculateTabAreaHeight(tabPlacement, 2, 10));
148:                assertEquals(30, ui.calculateTabAreaHeight(tabPlacement, 3, 10));
149:            }
150:
151:            public void testCalculateTabAreaWidth() {
152:                int tabPlacement = SwingConstants.LEFT;
153:                assertEquals(14, ui.calculateTabAreaWidth(tabPlacement, 1, 10));
154:                assertEquals(22, ui.calculateTabAreaWidth(tabPlacement, 2, 10));
155:                assertEquals(30, ui.calculateTabAreaWidth(tabPlacement, 3, 10));
156:            }
157:
158:            public void testCalculateTabHeight() {
159:                if (!isHarmony()) {
160:                    return;
161:                }
162:                tabbed.setSelectedIndex(0);
163:                assertEquals(27, ui.calculateTabHeight(
164:                        tabbed.getTabPlacement(), 0, 20));
165:                tabbed.setSelectedIndex(1);
166:                assertEquals(27, ui.calculateTabHeight(
167:                        tabbed.getTabPlacement(), 0, 20));
168:            }
169:
170:            public void testCalculateTabWidth() {
171:                final FontMetrics fm = tabbed.getFontMetrics(tabbed.getFont());
172:                final int tabIndex = 0;
173:                final int textWidth = fm.stringWidth(tabbed
174:                        .getTitleAt(tabIndex));
175:                assertEquals(textWidth + 24, ui.calculateTabWidth(tabbed
176:                        .getTabPlacement(), tabIndex, fm));
177:            }
178:
179:            public void testCreateChangeListener() {
180:                assertTrue(ui.createChangeListener() instanceof  BasicTabbedPaneUI.TabSelectionHandler);
181:            }
182:
183:            public void testCreateFocusListener() {
184:                assertTrue(ui.createFocusListener() instanceof  BasicTabbedPaneUI.FocusHandler);
185:            }
186:
187:            public void testCreateLayoutManager() {
188:                assertTrue(ui.createLayoutManager() instanceof  BasicTabbedPaneUI.TabbedPaneLayout);
189:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
190:                assertFalse(ui.createLayoutManager().getClass() == BasicTabbedPaneUI.TabbedPaneLayout.class);
191:            }
192:
193:            public void testCreateMouseListener() {
194:                assertTrue(ui.createMouseListener() instanceof  BasicTabbedPaneUI.MouseHandler);
195:            }
196:
197:            public void testCreatePropertyChangeListener() {
198:                PropertyChangeListener l = ui.createPropertyChangeListener();
199:                assertTrue(l instanceof  BasicTabbedPaneUI.PropertyChangeHandler);
200:            }
201:
202:            public void testCreateScrollButton() {
203:                JButton b = ui.createScrollButton(SwingConstants.NORTH);
204:                assertTrue(b instanceof  UIResource);
205:                assertFalse(b.isFocusable());
206:                assertTrue(b.getWidth() > 5);
207:                assertTrue(b.getHeight() > 5);
208:
209:                try {
210:                    new BasicTabbedPaneUI() {
211:                        public JButton createScrollButton(int direction) {
212:                            return super .createScrollButton(direction);
213:                        }
214:                    }.createScrollButton(80);
215:
216:                    fail("IllegalArgumentException expected");
217:                } catch (IllegalArgumentException e) {
218:                    // PASSED          
219:                }
220:            }
221:
222:            public void testExpandTabRunsArray() {
223:                int oldLength = ui.tabRuns.length;
224:                ui.expandTabRunsArray();
225:                assertTrue(ui.tabRuns.length > oldLength);
226:            }
227:
228:            public void testGetContentBorderInsets() {
229:                assertEquals(ui.contentBorderInsets, ui
230:                        .getContentBorderInsets(SwingConstants.TOP));
231:                assertSame(ui.contentBorderInsets, ui
232:                        .getContentBorderInsets(SwingConstants.TOP));
233:                assertEquals(ui.contentBorderInsets, ui
234:                        .getContentBorderInsets(SwingConstants.LEFT));
235:                assertEquals(ui.contentBorderInsets, ui
236:                        .getContentBorderInsets(SwingConstants.BOTTOM));
237:                assertEquals(ui.contentBorderInsets, ui
238:                        .getContentBorderInsets(SwingConstants.RIGHT));
239:            }
240:
241:            public void testGetFocusIndex() {
242:                showTabPane();
243:                Component focusOwner = KeyboardFocusManager
244:                        .getCurrentKeyboardFocusManager().getFocusOwner();
245:                int expected = focusOwner != tabbed ? -1 : tabbed
246:                        .getSelectedIndex();
247:                assertEquals(expected, ui.getFocusIndex());
248:            }
249:
250:            public void testGetFontMetrics() {
251:                tabbed = new JTabbedPane();
252:                tabbed.setUI(ui);
253:                assertSame(tabbed.getFontMetrics(tabbed.getFont()), ui
254:                        .getFontMetrics());
255:            }
256:
257:            public void testGetIconForTab() {
258:                tabbed.setEnabledAt(0, true);
259:                assertSame(tabbed.getIconAt(0), ui.getIconForTab(0));
260:                tabbed.setEnabledAt(0, false);
261:                assertSame(tabbed.getDisabledIconAt(0), ui.getIconForTab(0));
262:                tabbed.setDisabledIconAt(0, null);
263:                assertNull(ui.getIconForTab(0));
264:            }
265:
266:            public void testGetMaximumSize() {
267:                assertNull(ui.getMaximumSize(tabbed));
268:            }
269:
270:            public void testGetMinimumSize() {
271:                assertNull(ui.getMinimumSize(tabbed));
272:            }
273:
274:            public void testGetNextTabIndex() {
275:                assertEquals(1, ui.getNextTabIndex(0));
276:                assertEquals(0, ui.getNextTabIndex(tabbed.getTabCount() - 1));
277:            }
278:
279:            public void testGetPreviousTabIndex() {
280:                assertEquals(tabbed.getTabCount() - 1, ui
281:                        .getPreviousTabIndex(0));
282:                assertEquals(0, ui.getPreviousTabIndex(1));
283:            }
284:
285:            public void testGetNextTabIndexInRun() {
286:                create2TabRuns();
287:                int tabCount = tabbed.getTabCount();
288:                assertEquals(1, ui.getNextTabIndexInRun(tabCount, 0));
289:                assertEquals(0, ui.getNextTabIndexInRun(tabCount, 1));
290:                assertEquals(2, ui.getNextTabIndexInRun(tabCount, 2));
291:            }
292:
293:            public void testGetNextTabRun() {
294:                create3TabRuns();
295:                assertEquals(1, ui.getNextTabRun(0));
296:                assertEquals(0, ui.getNextTabRun(2));
297:            }
298:
299:            public void testGetPreviousTabIndexInRun() {
300:                create2TabRuns();
301:                int tabCount = tabbed.getTabCount();
302:                assertEquals(1, ui.getPreviousTabIndexInRun(tabCount, 0));
303:                assertEquals(0, ui.getPreviousTabIndexInRun(tabCount, 1));
304:                assertEquals(2, ui.getPreviousTabIndexInRun(tabCount, 2));
305:            }
306:
307:            public void testGetPreviousTabRun() {
308:                create3TabRuns();
309:                assertEquals(2, ui.getPreviousTabRun(0));
310:                assertEquals(0, ui.getPreviousTabRun(1));
311:            }
312:
313:            public void testGetRunForTab() {
314:                assertEquals(0, ui.getRunForTab(tabbed.getTabCount(), 1));
315:            }
316:
317:            public void testGetSelectedTabPadInsets() {
318:                Insets rotatedInsets = new Insets(0, 0, 0, 0);
319:                BasicTabbedPaneUI.rotateInsets(ui.selectedTabPadInsets,
320:                        rotatedInsets, SwingConstants.LEFT);
321:                assertEquals(rotatedInsets, ui
322:                        .getSelectedTabPadInsets(SwingConstants.LEFT));
323:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
324:                assertEquals(rotatedInsets, ui
325:                        .getSelectedTabPadInsets(SwingConstants.LEFT));
326:            }
327:
328:            public void testGetTabAreaInsets() {
329:                ui.tabAreaInsets = new Insets(1, 2, 3, 4);
330:                assertEquals(ui.tabAreaInsets, ui
331:                        .getTabAreaInsets(SwingConstants.TOP));
332:                assertEquals(new Insets(2, 1, 4, 3), ui
333:                        .getTabAreaInsets(SwingConstants.LEFT));
334:                assertEquals(new Insets(3, 2, 1, 4), ui
335:                        .getTabAreaInsets(SwingConstants.BOTTOM));
336:                assertEquals(new Insets(2, 3, 4, 1), ui
337:                        .getTabAreaInsets(SwingConstants.RIGHT));
338:                assertNotSame(ui.tabAreaInsets, ui
339:                        .getTabAreaInsets(SwingConstants.TOP));
340:            }
341:
342:            public void testGetTabBoundsintRectangle() {
343:                tabbed.setSize(220, 100);
344:                tabbed.doLayout();
345:                Rectangle r = new Rectangle();
346:                Rectangle rc = ui.getTabBounds(0, r);
347:                assertSame(r, rc);
348:                assertEquals(ui.rects[0], r);
349:                assertTrue(r.x >= 0 && r.x <= 10);
350:                assertTrue(r.y >= 0 && r.y <= 10);
351:                assertTrue(r.width < 80 && r.width > 0);
352:                assertTrue(r.height < 50 && r.height > 0);
353:            }
354:
355:            public void testGetTabBoundsJTabbedPaneint() {
356:                tabbed.setSize(220, 100);
357:                tabbed.doLayout();
358:                Rectangle r1 = ui.getTabBounds(tabbed, 0);
359:                Rectangle r2 = new Rectangle();
360:                ui.getTabBounds(0, r2);
361:                assertEquals(r2, r1);
362:            }
363:
364:            public void testGetTabInsets() {
365:                tabbed.setSelectedIndex(0);
366:                assertSame(ui.tabInsets, ui
367:                        .getTabInsets(SwingConstants.LEFT, 0));
368:                tabbed.setSelectedIndex(1);
369:                assertSame(ui.tabInsets, ui
370:                        .getTabInsets(SwingConstants.LEFT, 0));
371:                assertSame(ui.tabInsets, ui.getTabInsets(SwingConstants.TOP, 1));
372:                assertSame(ui.tabInsets, ui.getTabInsets(SwingConstants.RIGHT,
373:                        1));
374:                assertSame(ui.tabInsets, ui.getTabInsets(SwingConstants.BOTTOM,
375:                        1));
376:            }
377:
378:            public void testGetTabLabelShiftX() {
379:                if (!isHarmony()) {
380:                    return;
381:                }
382:                tabbed.setSelectedIndex(0);
383:                tabbed.doLayout();
384:                assertEquals(-1, ui.getTabLabelShiftX(SwingConstants.TOP, 0,
385:                        true));
386:                assertEquals(-1, ui.getTabLabelShiftX(SwingConstants.LEFT, 0,
387:                        true));
388:                assertEquals(1, ui.getTabLabelShiftX(SwingConstants.RIGHT, 0,
389:                        true));
390:                assertEquals(-1, ui.getTabLabelShiftX(SwingConstants.BOTTOM, 0,
391:                        true));
392:                assertEquals(-1, ui.getTabLabelShiftX(SwingConstants.TOP, 0,
393:                        false));
394:                assertEquals(1, ui.getTabLabelShiftX(SwingConstants.LEFT, 0,
395:                        false));
396:                assertEquals(-1, ui.getTabLabelShiftX(SwingConstants.RIGHT, 0,
397:                        false));
398:                assertEquals(-1, ui.getTabLabelShiftX(SwingConstants.BOTTOM, 0,
399:                        false));
400:            }
401:
402:            public void testGetTabLabelShiftY() {
403:                assertEquals(-1, ui.getTabLabelShiftY(SwingConstants.TOP, 0,
404:                        true));
405:                assertEquals(1, ui.getTabLabelShiftY(SwingConstants.LEFT, 0,
406:                        true));
407:                assertEquals(1, ui.getTabLabelShiftY(SwingConstants.RIGHT, 0,
408:                        true));
409:                assertEquals(1, ui.getTabLabelShiftY(SwingConstants.BOTTOM, 0,
410:                        true));
411:                assertEquals(1, ui.getTabLabelShiftY(SwingConstants.TOP, 0,
412:                        false));
413:                assertEquals(1, ui.getTabLabelShiftY(SwingConstants.LEFT, 0,
414:                        false));
415:                assertEquals(1, ui.getTabLabelShiftY(SwingConstants.RIGHT, 0,
416:                        false));
417:                assertEquals(-1, ui.getTabLabelShiftY(SwingConstants.BOTTOM, 0,
418:                        false));
419:            }
420:
421:            /*
422:             * Class under test for int getTabRunCount(JTabbedPane)
423:             */
424:            public void testGetTabRunCount() {
425:                create2TabRuns();
426:                assertEquals(2, ui.getTabRunCount(tabbed));
427:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
428:                assertEquals(1, ui.getTabRunCount(tabbed));
429:            }
430:
431:            public void testGetTabRunIndent() {
432:                assertEquals(0, ui.getTabRunIndent(SwingConstants.LEFT, 0));
433:                assertEquals(0, ui.getTabRunIndent(SwingConstants.TOP, 1));
434:                assertEquals(0, ui.getTabRunIndent(SwingConstants.BOTTOM, 1));
435:                assertEquals(0, ui.getTabRunIndent(SwingConstants.RIGHT, 1));
436:            }
437:
438:            public void testGetTabRunOffset() {
439:                // the documentation is empty
440:            }
441:
442:            public void testGetTabRunOverlay() {
443:                assertEquals(ui.tabRunOverlay, ui
444:                        .getTabRunOverlay(SwingConstants.LEFT));
445:                assertEquals(ui.tabRunOverlay, ui
446:                        .getTabRunOverlay(SwingConstants.TOP));
447:            }
448:
449:            public void testGetTextViewForTab() {
450:                assertNull(ui.getTextViewForTab(0));
451:                //TODO HTML styled text is not supported
452:            }
453:
454:            public void testSetGetVisibleComponent() {
455:                assertSame(tabbed.getSelectedComponent(), ui
456:                        .getVisibleComponent());
457:                assertTrue(ui.getVisibleComponent().isVisible());
458:                JComponent comp = new JLabel("label");
459:                Component oldVisible = ui.getVisibleComponent();
460:                ui.setVisibleComponent(comp);
461:                assertSame(comp, ui.getVisibleComponent());
462:                assertNotSame(comp, tabbed.getSelectedComponent());
463:                assertFalse(oldVisible.isVisible());
464:                assertTrue(comp.isVisible());
465:                assertFalse(tabbed.isAncestorOf(comp));
466:                ui.setVisibleComponent(null);
467:                assertNull(ui.getVisibleComponent());
468:            }
469:
470:            public void testInstallUninstallComponents() {
471:                int count = tabbed.getComponentCount();
472:                ui.uninstallComponents();
473:                assertEquals(count, tabbed.getComponentCount());
474:                ui.installComponents();
475:                assertEquals(count, tabbed.getComponentCount());
476:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
477:                ui.uninstallComponents();
478:                count = tabbed.getComponentCount();
479:                ui.installComponents();
480:                if (isHarmony()) {
481:                    assertEquals(count + 2, tabbed.getComponentCount());
482:                }
483:                ui.uninstallComponents();
484:                assertEquals(count, tabbed.getComponentCount());
485:            }
486:
487:            public void testInstallDefaults() {
488:                tabbed.setBackgroundAt(0, null);
489:                tabbed.setBackground(null);
490:                tabbed.setForeground(null);
491:                tabbed.setLayout(null);
492:                tabbed.setFont(null);
493:                ui.installDefaults();
494:                assertTrue(tabbed.getBackground() instanceof  UIResource);
495:                assertTrue(tabbed.getForeground() instanceof  UIResource);
496:                assertTrue(tabbed.getFont() instanceof  UIResource);
497:                assertTrue(tabbed.getBackgroundAt(0) instanceof  UIResource);
498:                assertNull(tabbed.getLayout());
499:            }
500:
501:            public void testUninstallDefaults() {
502:                // nothing to test
503:            }
504:
505:            public void testInstallUninstallKeyboardActions() {
506:                ui.uninstallKeyboardActions();
507:                ui.installKeyboardActions();
508:                assertSame(UIManager.get("TabbedPane.focusInputMap"),
509:                        SwingUtilities.getUIInputMap(tabbed,
510:                                JComponent.WHEN_FOCUSED));
511:                assertSame(UIManager.get("TabbedPane.ancestorInputMap"),
512:                        SwingUtilities.getUIInputMap(tabbed,
513:                                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
514:                assertNotNull(SwingUtilities.getUIActionMap(tabbed));
515:                ui.uninstallKeyboardActions();
516:                assertNull(SwingUtilities.getUIInputMap(tabbed,
517:                        JComponent.WHEN_FOCUSED));
518:                assertNull(SwingUtilities.getUIInputMap(tabbed,
519:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
520:                assertNull(SwingUtilities.getUIActionMap(tabbed));
521:            }
522:
523:            public void testInstallUninstallListeners() {
524:                ui.uninstallListeners();
525:                ui.installListeners();
526:                assertTrue(Arrays.asList(tabbed.getPropertyChangeListeners())
527:                        .contains(ui.propertyChangeListener));
528:                assertTrue(Arrays.asList(tabbed.getMouseListeners()).contains(
529:                        ui.mouseListener));
530:                assertTrue(Arrays.asList(tabbed.getFocusListeners()).contains(
531:                        ui.focusListener));
532:                assertTrue(Arrays.asList(tabbed.getChangeListeners()).contains(
533:                        ui.tabChangeListener));
534:                ui.uninstallListeners();
535:                assertFalse(Arrays.asList(tabbed.getPropertyChangeListeners())
536:                        .contains(ui.propertyChangeListener));
537:                assertFalse(Arrays.asList(tabbed.getMouseListeners()).contains(
538:                        ui.mouseListener));
539:                assertFalse(Arrays.asList(tabbed.getFocusListeners()).contains(
540:                        ui.focusListener));
541:                assertFalse(Arrays.asList(tabbed.getChangeListeners())
542:                        .contains(ui.tabChangeListener));
543:            }
544:
545:            public void testInstallUI() {
546:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
547:                ui.uninstallListeners();
548:                ui.uninstallComponents();
549:                ui.uninstallKeyboardActions();
550:                int compCount = tabbed.getComponentCount();
551:                tabbed.setLayout(null);
552:                tabbed.setBackground(null);
553:                ui.installUI(tabbed);
554:                assertNotNull(tabbed.getLayout());
555:                assertTrue("called installDefaults()",
556:                        tabbed.getBackground() instanceof  UIResource);
557:                assertTrue("called installComponents()", tabbed
558:                        .getComponentCount() > compCount);
559:                if (isHarmony()) {
560:                    assertTrue("called installListeners()", Arrays.asList(
561:                            tabbed.getMouseListeners()).contains(
562:                            ui.mouseListener));
563:                }
564:                assertSame("called installKeyboardActions()", UIManager
565:                        .get("TabbedPane.focusInputMap"), SwingUtilities
566:                        .getUIInputMap(tabbed, JComponent.WHEN_FOCUSED));
567:            }
568:
569:            public void testUninstallUI() {
570:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
571:                int compCount = tabbed.getComponentCount();
572:                ui.uninstallUI(tabbed);
573:                assertNull(tabbed.getLayout());
574:                assertTrue("called uninstallComponents()", tabbed
575:                        .getComponentCount() < compCount);
576:                assertFalse("called uninstallListeners()", Arrays.asList(
577:                        tabbed.getMouseListeners()).contains(ui.mouseListener));
578:                assertNull("called uninstallKeyboardActions()", SwingUtilities
579:                        .getUIInputMap(tabbed, JComponent.WHEN_FOCUSED));
580:            }
581:
582:            public void testLastTabInRun() {
583:                int lastTabIndex = tabbed.getTabCount() - 1;
584:                assertEquals(lastTabIndex, ui.lastTabInRun(
585:                        tabbed.getTabCount(), 0));
586:            }
587:
588:            public void testLayoutLabel() {
589:                // no documentation
590:            }
591:
592:            public void testNavigateSelectedTab() {
593:                create2TabRuns();
594:                tabbed.setSelectedIndex(0);
595:                ui.navigateSelectedTab(SwingConstants.EAST);
596:                assertEquals(ui.getNextTabIndexInRun(tabbed.getTabCount(), 0),
597:                        tabbed.getSelectedIndex());
598:                tabbed.setEnabledAt(0, false);
599:                ui.navigateSelectedTab(SwingConstants.WEST);
600:                assertEquals(1, tabbed.getSelectedIndex());
601:                tabbed.setEnabledAt(0, true);
602:                ui.navigateSelectedTab(SwingConstants.NORTH);
603:                assertEquals(2, tabbed.getSelectedIndex());
604:                if (isHarmony()) {
605:                    ui.navigateSelectedTab(SwingConstants.SOUTH);
606:                    assertEquals(1, tabbed.getSelectedIndex());
607:                }
608:            }
609:
610:            public void testPaintGraphicsJComponent() {
611:                BasicTabbedPaneUI localBasicTabbedPaneUI = new BasicTabbedPaneUI();
612:                localBasicTabbedPaneUI.installUI(new JTabbedPane());
613:                try {
614:                    localBasicTabbedPaneUI.paint(null, new JToolBar());
615:                    fail("NPE is not thrown");
616:                } catch (NullPointerException e) {
617:                    // PASSED
618:                }
619:            }
620:
621:            public void testPaintContentBorder() {
622:                // Note: painting code, cannot test
623:            }
624:
625:            public void testPaintContentBorderBottomEdge() {
626:                // Note: painting code, cannot test
627:            }
628:
629:            public void testPaintContentBorderLeftEdge() {
630:                // Note: painting code, cannot test
631:            }
632:
633:            public void testPaintContentBorderRightEdge() {
634:                // Note: painting code, cannot test
635:            }
636:
637:            public void testPaintContentBorderTopEdge() {
638:                // Note: painting code, cannot test
639:            }
640:
641:            public void testPaintFocusIndicator() {
642:                // Note: painting code, cannot test
643:            }
644:
645:            public void testPaintIcon() {
646:                // Note: painting code, cannot test
647:            }
648:
649:            public void testPaintTab() {
650:                // Note: painting code, cannot test
651:            }
652:
653:            public void testPaintTabArea() {
654:                // Note: painting code, cannot test
655:            }
656:
657:            public void testPaintTabBackground() {
658:                // Note: painting code, cannot test
659:            }
660:
661:            public void testPaintTabBorder() {
662:                // Note: painting code, cannot test
663:            }
664:
665:            public void testPaintText() {
666:                // Note: painting code, cannot test
667:            }
668:
669:            public void testSelectAdjacentRunTab() {
670:                create3TabRuns();
671:                tabbed.setSelectedIndex(0);
672:                int tabRunOffset = ui.getTabRunOffset(tabbed.getTabPlacement(),
673:                        tabbed.getTabCount(), 0, true);
674:                ui.selectAdjacentRunTab(tabbed.getTabPlacement(), 0,
675:                        tabRunOffset);
676:                assertEquals(3, tabbed.getSelectedIndex());
677:            }
678:
679:            public void testSelectNextTab() {
680:                create2TabRuns();
681:                int initIndex = 0;
682:                tabbed.setSelectedIndex(initIndex);
683:                ui.selectNextTab(initIndex);
684:                assertEquals(ui.getNextTabIndex(initIndex), tabbed
685:                        .getSelectedIndex());
686:            }
687:
688:            public void testSelectPreviousTab() {
689:                create2TabRuns();
690:                int initIndex = 0;
691:                tabbed.setSelectedIndex(initIndex);
692:                ui.selectPreviousTab(initIndex);
693:                assertEquals(ui.getPreviousTabIndex(initIndex), tabbed
694:                        .getSelectedIndex());
695:            }
696:
697:            public void testSelectNextTabInRun() {
698:                create2TabRuns();
699:                int initIndex = 0;
700:                tabbed.setSelectedIndex(initIndex);
701:                ui.selectNextTabInRun(initIndex);
702:                assertEquals(ui.getNextTabIndexInRun(tabbed.getTabCount(),
703:                        initIndex), tabbed.getSelectedIndex());
704:            }
705:
706:            public void testSelectPreviousTabInRun() {
707:                create2TabRuns();
708:                int initIndex = 0;
709:                tabbed.setSelectedIndex(initIndex);
710:                ui.selectPreviousTabInRun(initIndex);
711:                assertEquals(ui.getPreviousTabIndexInRun(tabbed.getTabCount(),
712:                        initIndex), tabbed.getSelectedIndex());
713:            }
714:
715:            public void testSetGetRolloverTab() {
716:                assertEquals(-1, ui.getRolloverTab());
717:                ui.setRolloverTab(1);
718:                assertEquals(1, ui.getRolloverTab());
719:                ui.setRolloverTab(5);
720:                assertEquals(5, ui.getRolloverTab());
721:            }
722:
723:            public void testShouldPadTabRun() {
724:                assertFalse(ui.shouldPadTabRun(tabbed.getTabPlacement(), 0));
725:                create2TabRuns();
726:                assertTrue(ui.shouldPadTabRun(tabbed.getTabPlacement(), 0));
727:                assertTrue(ui.shouldPadTabRun(tabbed.getTabPlacement(), 1));
728:                assertTrue(ui.shouldPadTabRun(tabbed.getTabPlacement(), 2));
729:            }
730:
731:            public void testShouldRotateTabRuns() {
732:                assertTrue(ui.shouldRotateTabRuns(tabbed.getTabPlacement()));
733:            }
734:
735:            /*
736:             * Class under test for int tabForCoordinate(JTabbedPane, int, int)
737:             */
738:            public void testTabForCoordinate() {
739:                tabbed.setSize(40, 30);
740:                tabbed.doLayout();
741:                Rectangle tabBounds = ui.getTabBounds(tabbed, 0);
742:                assertEquals(0, ui.tabForCoordinate(null, tabBounds.x,
743:                        tabBounds.y));
744:                assertEquals(-1, ui.tabForCoordinate(null, tabBounds.x - 1,
745:                        tabBounds.y - 1));
746:                tabBounds = ui.getTabBounds(tabbed, 1);
747:                assertEquals(1, ui.tabForCoordinate(null, tabBounds.x + 1,
748:                        tabBounds.y + 1));
749:            }
750:
751:            private void create2TabRuns() {
752:                tabbed.addTab("tab3", new JLabel());
753:                FontMetrics fm = ui.getFontMetrics();
754:                tabbed.setSize(ui.calculateTabWidth(tabbed.getTabPlacement(),
755:                        0, fm)
756:                        + ui.calculateTabWidth(tabbed.getTabPlacement(), 1, fm)
757:                        + 10, 100);
758:                tabbed.getLayout().layoutContainer(tabbed);
759:                assertEquals("initialized incorrectly", 2, tabbed
760:                        .getTabRunCount());
761:            }
762:
763:            private void create3TabRuns() {
764:                tabbed.add("tab4", new JLabel());
765:                tabbed.add("tabtabtabtab5", new JLabel());
766:                tabbed.getLayout().layoutContainer(tabbed);
767:                assertEquals("initialized incorrectly", 3, tabbed
768:                        .getTabRunCount());
769:            }
770:
771:            private void showTabPane() {
772:                frame = new JFrame();
773:                frame.getContentPane().add(tabbed);
774:                frame.pack();
775:                frame.setVisible(true);
776:            }
777:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.