Source Code Cross Referenced for TabGroup.java in  » Testing » UISpec4J » org » uispec4j » 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 » Testing » UISpec4J » org.uispec4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j;
002:
003:        import junit.framework.Assert;
004:        import org.uispec4j.assertion.Assertion;
005:        import org.uispec4j.assertion.UISpecAssert;
006:        import org.uispec4j.finder.StringMatcher;
007:        import org.uispec4j.utils.ColorUtils;
008:        import org.uispec4j.xml.XmlWriter;
009:
010:        import javax.swing.*;
011:        import java.awt.*;
012:
013:        /**
014:         * Wrapper for JTabbedPane components.
015:         */
016:        public class TabGroup extends AbstractUIComponent {
017:            public static final String TYPE_NAME = "tabGroup";
018:            public static final Class[] SWING_CLASSES = { JTabbedPane.class };
019:
020:            private JTabbedPane jTabbedPane;
021:
022:            public TabGroup(JTabbedPane jTab) {
023:                this .jTabbedPane = jTab;
024:            }
025:
026:            public String getDescriptionTypeName() {
027:                return TYPE_NAME;
028:            }
029:
030:            public Component getAwtComponent() {
031:                return jTabbedPane;
032:            }
033:
034:            public Panel getSelectedTab() {
035:                Component selectedComponent = jTabbedPane
036:                        .getSelectedComponent();
037:                if (!JPanel.class.isInstance(selectedComponent)) {
038:                    Assert
039:                            .fail("tabGroup.getSelectedTab() only supports JPanel components inside a JTabbedPane");
040:                }
041:                return new Panel((JPanel) selectedComponent);
042:            }
043:
044:            public void selectTab(String tabLabel) {
045:                final int index = getTabIndex(tabLabel);
046:                Assert.assertTrue(tabNotFound(tabLabel), index >= 0);
047:                jTabbedPane.setSelectedIndex(index);
048:                UISpecAssert.assertTrue(new Assertion() {
049:                    public void check() throws Exception {
050:                        Assert
051:                                .assertTrue(jTabbedPane.getSelectedIndex() == index);
052:                    }
053:                });
054:            }
055:
056:            public Assertion tabColorEquals(final String[] colors) {
057:                return new Assertion() {
058:                    public void check() {
059:                        int tabCount = jTabbedPane.getTabCount();
060:                        Assert.assertEquals("You specified " + colors.length
061:                                + " colors but there are " + tabCount
062:                                + " tabs -", colors.length, tabCount);
063:                        for (int i = 0; i < colors.length; i++) {
064:                            String color = colors[i];
065:                            if (!ColorUtils.equals(color, jTabbedPane
066:                                    .getForegroundAt(i))) {
067:                                Assert
068:                                        .fail("Unexpected color for tab '"
069:                                                + jTabbedPane.getTitleAt(i)
070:                                                + "' (index "
071:                                                + i
072:                                                + ") - expected "
073:                                                + ColorUtils
074:                                                        .getColorDescription(color)
075:                                                + " but was "
076:                                                + ColorUtils
077:                                                        .getColorDescription(jTabbedPane
078:                                                                .getForegroundAt(i)));
079:                            }
080:                        }
081:                    }
082:                };
083:            }
084:
085:            public Assertion selectedTabEquals(final String tabLabel) {
086:                return new Assertion() {
087:                    public void check() {
088:                        Assert.assertEquals(tabLabel, jTabbedPane
089:                                .getTitleAt(jTabbedPane.getSelectedIndex()));
090:                    }
091:                };
092:            }
093:
094:            public Assertion tabNamesEquals(final String[] tabLabels) {
095:                return new Assertion() {
096:                    public void check() {
097:                        Assert.assertEquals(tabLabels.length, jTabbedPane
098:                                .getTabCount());
099:                        for (int i = 0; i < tabLabels.length; i++) {
100:                            Assert.assertEquals(tabLabels[i], jTabbedPane
101:                                    .getTitleAt(i));
102:                        }
103:                    }
104:                };
105:            }
106:
107:            protected void getSubDescription(Container container,
108:                    XmlWriter.Tag tag) {
109:                if (container == jTabbedPane) {
110:                    Component selectedComponent = jTabbedPane
111:                            .getSelectedComponent();
112:                    if (selectedComponent != null) {
113:                        getDescription(selectedComponent, tag, false);
114:                        return;
115:                    }
116:                } else {
117:                    super .getSubDescription(container, tag);
118:                }
119:            }
120:
121:            private int getTabIndex(String tabLabel) {
122:                int index = jTabbedPane.indexOfTab(tabLabel);
123:                if (index >= 0) {
124:                    return index;
125:                }
126:                for (int i = 0; i < jTabbedPane.getTabCount(); i++) {
127:                    String title = jTabbedPane.getTitleAt(i);
128:                    if (StringMatcher.substring(tabLabel).matches(title)) {
129:                        return i;
130:                    }
131:                }
132:                return -1;
133:            }
134:
135:            static String tabNotFound(String name) {
136:                return "There is no tab labelled '" + name + "'";
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.