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