Source Code Cross Referenced for JButtonTest.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 Alexander T. Simbirtsev
019:         * @version $Revision$
020:         * Created on 01.02.2005
021:
022:         */package javax.swing;
023:
024:        import java.awt.event.ActionEvent;
025:        import javax.accessibility.AccessibleRole;
026:        import javax.swing.plaf.ButtonUI;
027:
028:        public class JButtonTest extends AbstractButtonTest {
029:            protected JButton jbutton;
030:
031:            /*
032:             * @see TestCase#setUp()
033:             */
034:            @Override
035:            protected void setUp() throws Exception {
036:                super .setUp();
037:                jbutton = new JButton();
038:                button = jbutton;
039:            }
040:
041:            /*
042:             * @see TestCase#tearDown()
043:             */
044:            @Override
045:            protected void tearDown() throws Exception {
046:                super .tearDown();
047:            }
048:
049:            /*
050:             * Class under test for void JButton(String, Icon)
051:             */
052:            public void testJButtonStringIcon() {
053:                Icon icon = createNewIcon();
054:                String text = "texttext";
055:                jbutton = new JButton(text, icon);
056:                assertEquals("icon ", icon, jbutton.getIcon());
057:                assertEquals("text ", text, jbutton.getText());
058:            }
059:
060:            /*
061:             * Class under test for void JButton(Icon)
062:             */
063:            public void testJButtonIcon() {
064:                Icon icon = createNewIcon();
065:                jbutton = new JButton(icon);
066:                assertEquals("icon ", icon, jbutton.getIcon());
067:                assertEquals("text ", "", jbutton.getText());
068:            }
069:
070:            /*
071:             * Class under test for void JButton(Action)
072:             */
073:            public void testJButtonAction() {
074:                final String command = "dnammoc";
075:                class MyAction extends AbstractAction {
076:                    private static final long serialVersionUID = 1L;
077:
078:                    public MyAction(final String text, final Icon icon) {
079:                        super (text, icon);
080:                        putValue(Action.ACTION_COMMAND_KEY, command);
081:                    }
082:
083:                    public void actionPerformed(final ActionEvent e) {
084:                    }
085:                }
086:                ;
087:                Icon icon = createNewIcon();
088:                String text = "texttext";
089:                MyAction action = new MyAction(text, icon);
090:                button = new JButton(action);
091:                assertEquals("icon ", icon, button.getIcon());
092:                assertEquals("text ", text, button.getText());
093:                assertEquals("action", action, button.getAction());
094:                assertEquals("command ", command, button.getActionCommand());
095:                assertFalse("selected ", button.isSelected());
096:                assertTrue("enabled ", button.isEnabled());
097:                action.setEnabled(false);
098:                button = new JButton(action);
099:                assertEquals("icon ", icon, button.getIcon());
100:                assertEquals("text ", text, button.getText());
101:                assertEquals("action", action, button.getAction());
102:                assertEquals("command ", command, button.getActionCommand());
103:                assertFalse("selected ", button.isSelected());
104:                assertFalse("enabled ", button.isEnabled());
105:                button = new JButton((Action) null);
106:                assertNull("icon ", button.getIcon());
107:                assertNull("text ", button.getText());
108:                assertNull("action", button.getAction());
109:                assertNull("command ", button.getActionCommand());
110:                assertFalse("selected ", button.isSelected());
111:                assertTrue("enabled ", button.isEnabled());
112:                assertTrue("button model is of the proper type", button
113:                        .getModel() instanceof  DefaultButtonModel);
114:            }
115:
116:            /*
117:             * Class under test for void JButton(String)
118:             */
119:            public void testJButtonString() {
120:                String text = "texttext";
121:                jbutton = new JButton(text);
122:                assertNull("icon ", jbutton.getIcon());
123:                assertEquals("text ", text, jbutton.getText());
124:            }
125:
126:            /*
127:             * Class under test for void JButton()
128:             */
129:            public void testJButton() {
130:                assertNotNull("default buttonModel ", button.getModel());
131:                assertNull("icon ", jbutton.getIcon());
132:                assertEquals("text ", "", jbutton.getText());
133:            }
134:
135:            public void testGetAccessibleContext() {
136:                boolean assertedValue = (jbutton.getAccessibleContext() != null && jbutton
137:                        .getAccessibleContext().getClass().getName().equals(
138:                                "javax.swing.JButton$AccessibleJButton"));
139:                assertTrue("AccessibleContext created properly ", assertedValue);
140:                assertEquals("AccessibleRole", AccessibleRole.PUSH_BUTTON,
141:                        jbutton.getAccessibleContext().getAccessibleRole());
142:            }
143:
144:            /*
145:             * Class under test for String paramString()
146:             */
147:            @Override
148:            public void testParamString() {
149:                assertTrue("ParamString returns a string ",
150:                        jbutton.toString() != null);
151:            }
152:
153:            public void testRemoveNotify() {
154:                JRootPane pane = new JRootPane();
155:                assertFalse("initial value for defaultButton ", jbutton
156:                        .isDefaultButton());
157:                pane.getContentPane().add(jbutton);
158:                pane.getContentPane().add(new JButton());
159:                pane.setDefaultButton(jbutton);
160:                assertTrue("'ve become defaultButton now ", jbutton
161:                        .isDefaultButton());
162:                jbutton.removeNotify();
163:                assertFalse("is not defaultButton now ", jbutton
164:                        .isDefaultButton());
165:                assertNull("rootPane now 've no default jbutton ", pane
166:                        .getDefaultButton());
167:            }
168:
169:            public void testGetUIClassID() {
170:                assertEquals("UI class ID", "ButtonUI", jbutton.getUIClassID());
171:            }
172:
173:            @Override
174:            public void testUpdateUI() {
175:                ButtonUI ui = new ButtonUI() {
176:                };
177:                jbutton.setUI(ui);
178:                assertEquals(ui, jbutton.getUI());
179:                jbutton.updateUI();
180:                assertNotSame(ui, jbutton.getUI());
181:            }
182:
183:            /*
184:             * Class under test for void configurePropertiesFromAction(Action)
185:             */
186:            public void testConfigurePropertiesFromActionAction() {
187:                Icon icon1 = createNewIcon();
188:                Icon icon2 = createNewIcon();
189:                String text1 = "texttext1";
190:                String text2 = "texttext2";
191:                AbstractAction action1 = new AbstractAction(text1, icon1) {
192:                    private static final long serialVersionUID = 1L;
193:
194:                    public void actionPerformed(final ActionEvent event) {
195:                    }
196:                };
197:                AbstractAction action2 = new AbstractAction(text2, icon2) {
198:                    private static final long serialVersionUID = 1L;
199:
200:                    public void actionPerformed(final ActionEvent event) {
201:                    }
202:                };
203:                jbutton.configurePropertiesFromAction(action1);
204:                assertEquals("icon ", icon1, jbutton.getIcon());
205:                assertEquals("text ", text1, jbutton.getText());
206:                jbutton.configurePropertiesFromAction(action2);
207:                assertEquals("icon ", icon2, jbutton.getIcon());
208:                assertEquals("text ", text2, jbutton.getText());
209:                jbutton.configurePropertiesFromAction(null);
210:                assertNull("icon ", jbutton.getIcon());
211:                assertNull("text ", jbutton.getText());
212:                assertNull("action", jbutton.getAction());
213:                assertNull("command ", jbutton.getActionCommand());
214:                assertFalse("selected ", jbutton.isSelected());
215:                assertTrue("enabled ", jbutton.isEnabled());
216:            }
217:
218:            public void testSetDefaultCapable() {
219:                jbutton.setDefaultCapable(false);
220:                assertFalse("DefaultCapable", jbutton.isDefaultCapable());
221:                PropertyChangeController listener = new PropertyChangeController();
222:                jbutton.addPropertyChangeListener(listener);
223:                jbutton.setDefaultCapable(true);
224:                assertTrue("DefaultCapable", jbutton.isDefaultCapable());
225:                listener.checkPropertyFired(jbutton, "defaultCapable",
226:                        Boolean.FALSE, Boolean.TRUE);
227:                jbutton.setDefaultCapable(false);
228:                assertFalse("DefaultCapable", jbutton.isDefaultCapable());
229:                listener.checkPropertyFired(jbutton, "defaultCapable",
230:                        Boolean.TRUE, Boolean.FALSE);
231:            }
232:
233:            public void testIsDefaultCapable() {
234:                assertTrue("initial DefaultCapable value", jbutton
235:                        .isDefaultCapable());
236:            }
237:
238:            public void testIsDefaultButton() {
239:                JRootPane pane = new JRootPane();
240:                assertFalse("initial value for defaultButton ", jbutton
241:                        .isDefaultButton());
242:                pane.getContentPane().add(jbutton);
243:                pane.getContentPane().add(new JButton());
244:                assertFalse("is not defaultButton yet ", jbutton
245:                        .isDefaultButton());
246:                pane.setDefaultButton(jbutton);
247:                assertTrue("'ve become defaultButton now ", jbutton
248:                        .isDefaultButton());
249:            }
250:
251:            public void testWriteObject() {
252:                /*
253:                 String text1 = "can you read betwwen the lines?";
254:                 String text2 = "can you look through the time?";
255:                 JButton button1 = new JButton(text1);
256:                 JButton button2 = new JButton(text2);
257:                 try {
258:                 FileOutputStream fo = new FileOutputStream("tmp");
259:                 ObjectOutputStream so = new ObjectOutputStream(fo);
260:                 so.writeObject(button1);
261:                 so.flush();
262:                 } catch (Exception e) {
263:                 System.out.println(e);
264:                 fail("serialization failed");
265:                 }
266:                 try {
267:                 FileOutputStream fo = new FileOutputStream("tmp");
268:                 ObjectOutputStream so = new ObjectOutputStream(fo);
269:                 so.writeObject(button2);
270:                 so.flush();
271:                 } catch (Exception e) {
272:                 fail("serialization failed");
273:                 }
274:                 */
275:            }
276:
277:            public void testReadObject() {
278:                /*
279:                 String text1 = "can you read betwwen the lines?";
280:                 String text2 = "can you look through the time?";
281:                 JButton button1 = new JButton(text1);
282:                 JButton button2 = new JButton(text2);
283:                 try {
284:                 FileOutputStream fo = new FileOutputStream("tmp");
285:                 ObjectOutputStream so = new ObjectOutputStream(fo);
286:                 so.writeObject(button1);
287:                 so.flush();
288:                 } catch (Exception e) {
289:                 fail("serialization failed");
290:                 }
291:                 try {
292:                 FileInputStream fi = new FileInputStream("tmp");
293:                 ObjectInputStream si = new ObjectInputStream(fi);
294:                 JButton ressurectedButton = (JButton)si.readObject();
295:                 assertEquals("text ", text1, ressurectedButton.getText());
296:                 } catch (Exception e) {
297:                 fail("deserialization failed");
298:                 }
299:
300:                 try {
301:                 FileOutputStream fo = new FileOutputStream("tmp");
302:                 ObjectOutputStream so = new ObjectOutputStream(fo);
303:                 so.writeObject(button2);
304:                 so.flush();
305:                 } catch (Exception e) {
306:                 fail("serialization failed");
307:                 }
308:                 try {
309:                 FileInputStream fi = new FileInputStream("tmp");
310:                 ObjectInputStream si = new ObjectInputStream(fi);
311:                 JButton ressurectedButton = (JButton)si.readObject();
312:                 assertEquals("text ", text2, ressurectedButton.getText());
313:                 } catch (Exception e) {
314:                 fail("deserialization failed");
315:                 }
316:                 */
317:            }
318:
319:            @Override
320:            public void testGetAlignmentXY() {
321:                assertEquals("alignmentX ", button.getAlignmentX(), 0f, 1e-5);
322:                assertEquals("alignmentY ", button.getAlignmentY(), 0.5f, 1e-5);
323:            }
324:
325:            @Override
326:            public void testGetUI() {
327:                assertTrue("ui is returned ", button.getUI() != null);
328:            }
329:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.