Source Code Cross Referenced for BasicRadioButtonUITest.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 Alexander T. Simbirtsev
019:         * @version $Revision$
020:         * Created on 29.04.2005
021:
022:         */package javax.swing.plaf.basic;
023:
024:        import java.awt.Color;
025:        import java.awt.Dimension;
026:        import java.awt.Font;
027:        import java.awt.Insets;
028:        import java.awt.image.BufferedImage;
029:        import javax.swing.AbstractButton;
030:        import javax.swing.BorderFactory;
031:        import javax.swing.Icon;
032:        import javax.swing.ImageIcon;
033:        import javax.swing.JButton;
034:        import javax.swing.JRadioButton;
035:        import javax.swing.SwingTestCase;
036:        import javax.swing.UIManager;
037:        import javax.swing.border.Border;
038:        import javax.swing.border.EmptyBorder;
039:        import javax.swing.plaf.BorderUIResource;
040:        import javax.swing.plaf.ColorUIResource;
041:        import javax.swing.plaf.FontUIResource;
042:        import javax.swing.plaf.IconUIResource;
043:        import javax.swing.plaf.InsetsUIResource;
044:
045:        public class BasicRadioButtonUITest extends SwingTestCase {
046:            public class MyBasicRadioButtonUI extends BasicRadioButtonUI {
047:                @Override
048:                public String getPropertyPrefix() {
049:                    return super .getPropertyPrefix();
050:                }
051:
052:                @Override
053:                public void installDefaults(final AbstractButton b) {
054:                    super .installDefaults(b);
055:                }
056:
057:                @Override
058:                public void uninstallDefaults(final AbstractButton b) {
059:                    super .uninstallDefaults(b);
060:                }
061:
062:                @Override
063:                public int getTextShiftOffset() {
064:                    return super .getTextShiftOffset();
065:                }
066:
067:                public void setIcon(final Icon newIcon) {
068:                    icon = newIcon;
069:                }
070:
071:                public void setTextIconGap(final int gap) {
072:                    defaultTextIconGap = gap;
073:                }
074:
075:                public void setTextShiftOffset(final int offset) {
076:                    defaultTextShiftOffset = offset;
077:                }
078:            };
079:
080:            public MyBasicRadioButtonUI ui = null;
081:
082:            /*
083:             * @see TestCase#setUp()
084:             */
085:            @Override
086:            protected void setUp() throws Exception {
087:                super .setUp();
088:                ui = new MyBasicRadioButtonUI();
089:            }
090:
091:            public void testGetPreferredSize() {
092:                Font font = new FontUIResource(
093:                        new Font("serif", Font.PLAIN, 24));
094:                UIManager.put("RadioButton.font", font);
095:                Border border = new BorderUIResource(BorderFactory
096:                        .createEmptyBorder(11, 11, 11, 11));
097:                UIManager.put("RadioButton.border", border);
098:                JRadioButton button1 = new JRadioButton();
099:                JRadioButton button2 = new JRadioButton("text");
100:                JRadioButton button3 = new JRadioButton("text");
101:                JRadioButton button6 = new JRadioButton("text");
102:                button3.setBorder(new EmptyBorder(10, 10, 10, 10));
103:                button6.setBorder(null);
104:                int iconH = 20;
105:                int iconW = 30;
106:                ui.setIcon(new ImageIcon(new BufferedImage(iconW, iconH,
107:                        BufferedImage.TYPE_INT_ARGB)));
108:                // following parameters are not being used by UI
109:                ui.setTextIconGap(100);
110:                ui.setTextShiftOffset(33);
111:                int horInsets = button1.getInsets().left
112:                        + button1.getInsets().right;
113:                int vertInsets = button1.getInsets().top
114:                        + button1.getInsets().bottom;
115:                int textWidth = button1.getFontMetrics(button1.getFont())
116:                        .stringWidth("text");
117:                int textHeight = button1.getFontMetrics(button1.getFont())
118:                        .getHeight();
119:                assertEquals("PreferredSize", new Dimension(horInsets + iconW,
120:                        vertInsets + iconH), ui.getPreferredSize(button1));
121:                assertEquals("PreferredSize", new Dimension(horInsets + iconW
122:                        + textWidth + button1.getIconTextGap(), vertInsets
123:                        + Math.max(iconH, textHeight)), ui
124:                        .getPreferredSize(button2));
125:                horInsets = button3.getInsets().left
126:                        + button3.getInsets().right;
127:                vertInsets = button3.getInsets().top
128:                        + button3.getInsets().bottom;
129:                assertEquals("PreferredSize", new Dimension(horInsets + iconW
130:                        + textWidth + button1.getIconTextGap(), vertInsets
131:                        + Math.max(iconH, textHeight)), ui
132:                        .getPreferredSize(button3));
133:                horInsets = button6.getInsets().left
134:                        + button6.getInsets().right;
135:                vertInsets = button6.getInsets().top
136:                        + button6.getInsets().bottom;
137:                assertEquals("PreferredSize", new Dimension(horInsets + iconW
138:                        + textWidth + button1.getIconTextGap(), vertInsets
139:                        + Math.max(iconH, textHeight)), ui
140:                        .getPreferredSize(button6));
141:            }
142:
143:            public void testCreateUI() {
144:                assertTrue("created UI is not null", null != BasicRadioButtonUI
145:                        .createUI(new JButton()));
146:                assertTrue(
147:                        "created UI is of the proper class",
148:                        BasicRadioButtonUI.createUI(null) instanceof  BasicRadioButtonUI);
149:                assertTrue("created UI is of unique", BasicRadioButtonUI
150:                        .createUI(null) == BasicRadioButtonUI.createUI(null));
151:            }
152:
153:            public void testUninstallDefaults() {
154:                JRadioButton button = new JRadioButton();
155:                UIManager.put("RadioButton.foreground", new ColorUIResource(
156:                        Color.cyan));
157:                UIManager.put("RadioButton.background", new ColorUIResource(
158:                        Color.blue));
159:                assertNotNull("font is installed", button.getFont());
160:                Font font = new FontUIResource(button.getFont()
161:                        .deriveFont(100f));
162:                UIManager.put("RadioButton.font", font);
163:                Border border = new BorderUIResource(BorderFactory
164:                        .createEmptyBorder(0, 0, 0, 0));
165:                UIManager.put("RadioButton.border", border);
166:                Insets margin = new InsetsUIResource(10, 20, 30, 40);
167:                UIManager.put("RadioButton.margin", margin);
168:                button.setUI(ui);
169:                ui.installDefaults(button);
170:                ui.uninstallDefaults(button);
171:                assertEquals("background", Color.blue, button.getBackground());
172:                assertEquals("foreground", Color.cyan, button.getForeground());
173:                assertEquals("font", font, button.getFont());
174:                assertNull("border", button.getBorder());
175:                assertEquals("margin", margin, button.getMargin());
176:            }
177:
178:            public void testInstallDefaults() {
179:                JRadioButton button = new JRadioButton();
180:                UIManager.put("RadioButton.foreground", new ColorUIResource(
181:                        Color.cyan));
182:                UIManager.put("RadioButton.background", new ColorUIResource(
183:                        Color.blue));
184:                assertNotNull("font is installed", button.getFont());
185:                Font font = new FontUIResource(button.getFont()
186:                        .deriveFont(100f));
187:                UIManager.put("RadioButton.font", font);
188:                Border border = new BorderUIResource(BorderFactory
189:                        .createEmptyBorder(0, 0, 0, 0));
190:                UIManager.put("RadioButton.border", border);
191:                Insets margin = new InsetsUIResource(10, 20, 30, 40);
192:                UIManager.put("RadioButton.margin", margin);
193:                Icon icon = new IconUIResource(new ImageIcon(new BufferedImage(
194:                        10, 10, BufferedImage.TYPE_INT_RGB)));
195:                UIManager.put("RadioButton.icon", icon);
196:                button.setUI(ui);
197:                ui.installDefaults(button);
198:                assertEquals("background", Color.blue, button.getBackground());
199:                assertEquals("foreground", Color.cyan, button.getForeground());
200:                assertEquals("font", font, button.getFont());
201:                assertEquals("border", border, button.getBorder());
202:                assertEquals("margin", margin, button.getMargin());
203:                assertEquals("icon", icon, ui.getDefaultIcon());
204:            }
205:
206:            public void testGetPropertyPrefix() {
207:                assertEquals("prefix ", "RadioButton.", ui.getPropertyPrefix());
208:            }
209:
210:            public void testGetDefaultIcon() {
211:                assertNull("icon", ui.getDefaultIcon());
212:                Icon icon = new ImageIcon();
213:                ui.setIcon(icon);
214:                assertEquals("icon", icon, ui.getDefaultIcon());
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.