Source Code Cross Referenced for SpringTest.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) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:        package javax.swing;
0018:
0019:        import java.awt.Component;
0020:        import java.awt.Dimension;
0021:
0022:        public class SpringTest extends SwingTestCase {
0023:            private Spring spring;
0024:            private Spring spring1;
0025:            private Spring spring2;
0026:
0027:            private Component component;
0028:
0029:            private Marker componentGetMinimumSizeCalled;
0030:            private Marker componentGetPreferedSizeCalled;
0031:            private Marker componentGetMaximumSizeCalled;
0032:
0033:            @Override
0034:            protected void setUp() throws Exception {
0035:                super .setUp();
0036:
0037:                componentGetMinimumSizeCalled = new Marker();
0038:                componentGetPreferedSizeCalled = new Marker();
0039:                componentGetMaximumSizeCalled = new Marker();
0040:
0041:                component = new JButton("test");
0042:                initComponentSizes(component);
0043:            }
0044:
0045:            public void testConstant() throws Exception {
0046:                Spring spring;
0047:                spring = Spring.constant(5);
0048:                assertSizes(5, 5, 5, 5, spring);
0049:                spring.setValue(10);
0050:                assertSizes(5, 5, 5, 10, spring);
0051:                spring = Spring.constant(1, 2, 3);
0052:                assertSizes(1, 2, 3, 2, spring);
0053:                spring.setValue(10);
0054:                assertSizes(1, 2, 3, 10, spring);
0055:                spring1 = Spring.constant(5);
0056:                spring2 = Spring.constant(5);
0057:                assertFalse(spring1.equals(spring2));
0058:            }
0059:
0060:            public void testConstant_UNSET() throws Exception {
0061:                spring = Spring.constant(5);
0062:                spring.setValue(1);
0063:                assertEquals(1, spring.getValue());
0064:                spring.setValue(Spring.UNSET);
0065:                assertEquals(5, spring.getValue());
0066:                spring = Spring.constant(2, 5, 6);
0067:                spring.setValue(1);
0068:                assertEquals(1, spring.getValue());
0069:                spring.setValue(Spring.UNSET);
0070:                assertEquals(spring.getPreferredValue(), spring.getValue());
0071:            }
0072:
0073:            public void testConstant_Overflow() throws Exception {
0074:                spring = Spring.constant(4, 5, 6);
0075:                spring.setValue(Integer.MAX_VALUE - 5);
0076:                assertEquals(Integer.MAX_VALUE - 5, spring.getValue());
0077:            }
0078:
0079:            public void testMinus() throws Exception {
0080:                testExceptionalCase(new NullPointerCase() {
0081:                    @Override
0082:                    public void exceptionalAction() throws Exception {
0083:                        Spring.minus(null).getValue();
0084:                    }
0085:                });
0086:                spring1 = Spring.constant(12, 13, 15);
0087:                spring = Spring.minus(spring1);
0088:                assertSizes(-spring1.getMaximumValue(), -spring1
0089:                        .getPreferredValue(), -spring1.getMinimumValue(),
0090:                        -spring1.getValue(), spring);
0091:                component = new JButton("Test");
0092:                setComponentSizes(component, new Dimension(59, 25));
0093:                spring1 = Spring.width(component);
0094:                spring = Spring.minus(spring1);
0095:                assertSizes(-spring1.getMaximumValue(), -spring1
0096:                        .getPreferredValue(), -spring1.getMinimumValue(),
0097:                        -spring1.getValue(), spring);
0098:                assertEquals(-spring.getMinimumValue(), component
0099:                        .getMinimumSize().width);
0100:                component.setMinimumSize(new Dimension(111, 112));
0101:                assertEquals(-spring.getMaximumValue(), component
0102:                        .getMinimumSize().width);
0103:                spring.setValue(333);
0104:                assertEquals(-333, spring1.getValue());
0105:                spring1.setValue(1);
0106:                assertSizes(-59, -59, -111, spring);
0107:                component.setMinimumSize(new Dimension(101, 201));
0108:                component.setPreferredSize(new Dimension(102, 202));
0109:                component.setMaximumSize(new Dimension(103, 203));
0110:                assertSizes(-103, -102, -101, spring);
0111:            }
0112:
0113:            public void testMinus_Overflow() throws Exception {
0114:                initComponentSizes(component);
0115:                spring = Spring.minus(Spring.width(component));
0116:                spring.setValue(Integer.MAX_VALUE - 5);
0117:                if (isHarmony()) {
0118:                    assertEquals(Short.MAX_VALUE, spring.getValue());
0119:                } else {
0120:                    assertEquals(Integer.MAX_VALUE - 5, spring.getValue());
0121:                }
0122:                spring = Spring.minus(Spring.width(component));
0123:                component.setMinimumSize(new Dimension(Integer.MAX_VALUE,
0124:                        Integer.MAX_VALUE));
0125:                if (isHarmony()) {
0126:                    assertEquals(Spring.TRIMMED_MIN_VALUE, spring
0127:                            .getMaximumValue());
0128:                } else {
0129:                    assertEquals(-Integer.MAX_VALUE, spring.getMaximumValue());
0130:                }
0131:                spring = Spring.minus(Spring.width(component));
0132:                component.setMinimumSize(new Dimension(Integer.MIN_VALUE,
0133:                        Integer.MIN_VALUE));
0134:                if (isHarmony()) {
0135:                    assertEquals(Spring.TRIMMED_MAX_VALUE, spring
0136:                            .getMaximumValue());
0137:                } else {
0138:                    assertEquals(Integer.MIN_VALUE, spring.getMaximumValue());
0139:                }
0140:            }
0141:
0142:            public void testMinus_SizesCashing() throws Exception {
0143:                spring1 = Spring.width(component);
0144:                spring = Spring.minus(spring1);
0145:                if (isHarmony()) {
0146:                    assertSizes(Short.MIN_VALUE, -75, -2, spring);
0147:                } else {
0148:                    assertSizes(-1 * Short.MAX_VALUE, -75, -2, spring);
0149:                }
0150:                setComponentSizes(component, new Dimension(1, 1));
0151:                assertSizes(-1, -1, -1, spring);
0152:                spring1.setValue(0);
0153:                assertEquals(0, spring.getValue());
0154:                assertEquals(0, spring1.getValue());
0155:                spring.setValue(3);
0156:                assertEquals(3, spring.getValue());
0157:                assertEquals(-3, spring1.getValue());
0158:            }
0159:
0160:            public void testMinus_UNSET() throws Exception {
0161:                spring1 = Spring.constant(4, 5, 6);
0162:                spring1.setValue(1);
0163:                spring = Spring.minus(spring1);
0164:                spring.setValue(Spring.UNSET);
0165:                assertSizes(4, 5, 6, 5, spring1);
0166:                spring1 = Spring.constant(4, 5, 6);
0167:                spring2 = Spring.sum(Spring.constant(5), spring1);
0168:                spring = Spring.minus(spring2);
0169:                spring.setValue(Spring.UNSET);
0170:                spring.getMaximumValue();
0171:                spring.setValue(Spring.UNSET);
0172:                spring.setValue(10);
0173:                assertEquals(-15, spring1.getValue());
0174:                spring1.setValue(100);
0175:                assertEquals(100, spring1.getValue());
0176:                spring.setValue(10);
0177:                assertEquals(-15, spring1.getValue());
0178:            }
0179:
0180:            public void testSum() throws Exception {
0181:                testExceptionalCase(new NullPointerCase() {
0182:                    @Override
0183:                    public void exceptionalAction() throws Exception {
0184:                        Spring.max(null, Spring.constant(11)).getValue();
0185:                    }
0186:                });
0187:                Component c1 = new JLabel("ss");
0188:                c1.setPreferredSize(new Dimension(15, 15));
0189:                c1.setMaximumSize(new Dimension(15, 15));
0190:                c1.setMinimumSize(new Dimension(15, 15));
0191:                Component c2 = new JTextField("ss");
0192:                c2.setPreferredSize(new Dimension(19, 19));
0193:                c2.setMinimumSize(new Dimension(19, 19));
0194:                Spring max = Spring.max(Spring.max(Spring.constant(0), Spring
0195:                        .height(c1)), Spring.height(c2));
0196:                Spring max6 = Spring.sum(max, Spring.constant(6));
0197:                spring1 = Spring.sum(Spring.sum(Spring.sum(Spring.constant(6),
0198:                        max6), max6), max6);
0199:
0200:                spring2 = max6;
0201:                spring = Spring.sum(spring1, spring2);
0202:                spring.setValue(418);
0203:                assertEquals(315, spring1.getValue()); //314
0204:                assertEquals(103, spring2.getValue()); //103
0205:
0206:                spring1 = Spring.constant(24, 81, 3 * Spring.TRIMMED_MAX_VALUE);
0207:                spring2 = Spring.constant(6, 25, Spring.TRIMMED_MAX_VALUE);
0208:                spring = Spring.sum(spring1, spring2);
0209:                spring.setValue(418);
0210:                assertEquals(314, spring1.getValue()); //314
0211:                assertEquals(104, spring2.getValue()); //103
0212:
0213:                checkStrains(Spring.constant(2), Spring.constant(1, 2, 3), 2,
0214:                        2, 0);
0215:                checkStrains(Spring.constant(1, 2, 3), Spring.constant(2), 2,
0216:                        0, 2);
0217:                checkStrains(Spring.constant(2), Spring.constant(1, 2, 3), 4,
0218:                        2, 2);
0219:                checkStrains(Spring.constant(1, 2, 3), Spring.constant(2), 4,
0220:                        2, 2);
0221:                checkStrains(Spring.constant(2), Spring.constant(1, 2, 3), 6,
0222:                        2, 4);
0223:                checkStrains(Spring.constant(1, 2, 3), Spring.constant(2), 6,
0224:                        4, 2);
0225:                checkStrains(Spring.constant(2, 2, 1),
0226:                        Spring.constant(2, 2, 4), 2, 2, 0);
0227:                checkStrains(Spring.constant(2, 2, 4),
0228:                        Spring.constant(2, 2, 1), 2, 2, 0);
0229:                checkStrains(Spring.constant(2, 2, 1),
0230:                        Spring.constant(2, 2, 4), 4, 2, 2);
0231:                checkStrains(Spring.constant(2, 2, 4),
0232:                        Spring.constant(2, 2, 1), 4, 2, 2);
0233:                checkStrains(Spring.constant(2, 2, 1),
0234:                        Spring.constant(2, 2, 4), 6, 0, 6);
0235:                checkStrains(Spring.constant(2, 2, 4),
0236:                        Spring.constant(2, 2, 1), 6, 6, 0);
0237:                checkStrains(Spring.constant(2, 2, 2),
0238:                        Spring.constant(2, 2, 2), 2, 2, 0);
0239:                checkStrains(Spring.constant(2, 2, 2),
0240:                        Spring.constant(2, 2, 2), 4, 2, 2);
0241:                checkStrains(Spring.constant(2, 2, 2),
0242:                        Spring.constant(2, 2, 2), 6, 2, 4);
0243:                checkStrains(Spring.constant(1, 3, 3),
0244:                        Spring.constant(1, 2, 2), 3, 2, 1);
0245:                checkStrains(Spring.constant(1, 2, 2),
0246:                        Spring.constant(1, 3, 3), 3, 2, 1);
0247:                checkStrains(Spring.constant(1, 3, 3),
0248:                        Spring.constant(1, 2, 2), 5, 3, 2);
0249:                checkStrains(Spring.constant(1, 2, 2),
0250:                        Spring.constant(1, 3, 3), 5, 2, 3);
0251:                checkStrains(Spring.constant(1, 3, 3),
0252:                        Spring.constant(1, 2, 2), 7, 3, 4);
0253:                checkStrains(Spring.constant(1, 2, 2),
0254:                        Spring.constant(1, 3, 3), 7, 2, 5);
0255:                checkStrains(Spring.constant(1, 3, 1),
0256:                        Spring.constant(1, 1, 3), 2, 1, 1);
0257:                checkStrains(Spring.constant(1, 1, 3),
0258:                        Spring.constant(1, 3, 1), 2, 1, 1);
0259:                checkStrains(Spring.constant(1, 3, 1),
0260:                        Spring.constant(1, 1, 3), 4, 3, 1);
0261:                checkStrains(Spring.constant(1, 1, 3),
0262:                        Spring.constant(1, 3, 1), 4, 1, 3);
0263:                if (isHarmony()) {
0264:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(1,
0265:                            1, 3), 6, Spring.TRIMMED_MAX_VALUE + 3,
0266:                            6 - Spring.TRIMMED_MAX_VALUE - 3);
0267:                } else {
0268:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(1,
0269:                            1, 3), 6, Spring.UNSET + 3, 6 - Spring.UNSET - 3);
0270:                }
0271:                checkStrains(Spring.constant(1, 1, 3),
0272:                        Spring.constant(1, 3, 1), 6, 1, 5);
0273:                checkStrains(Spring.constant(1, 3, 1),
0274:                        Spring.constant(0, 1, 3), 2, 2, 0);
0275:                checkStrains(Spring.constant(0, 1, 3),
0276:                        Spring.constant(1, 3, 1), 2, 1, 1);
0277:                checkStrains(Spring.constant(1, 3, 1),
0278:                        Spring.constant(0, 1, 3), 4, 3, 1);
0279:                checkStrains(Spring.constant(0, 1, 3),
0280:                        Spring.constant(1, 3, 1), 4, 1, 3);
0281:                checkStrains(Spring.constant(0, 3, 1),
0282:                        Spring.constant(1, 1, 3), 4, 3, 1);
0283:                if (isHarmony()) {
0284:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(0,
0285:                            1, 3), 6, Spring.TRIMMED_MAX_VALUE + 3,
0286:                            6 - Spring.TRIMMED_MAX_VALUE - 3);
0287:                } else {
0288:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(0,
0289:                            1, 3), 6, Spring.UNSET + 3, 6 - Spring.UNSET - 3);
0290:                }
0291:                checkStrains(Spring.constant(0, 1, 3),
0292:                        Spring.constant(1, 3, 1), 6, 1, 5);
0293:                if (isHarmony()) {
0294:                    checkStrains(Spring.constant(0, 3, 1), Spring.constant(1,
0295:                            1, 3), 6, Spring.TRIMMED_MAX_VALUE + 3,
0296:                            6 - Spring.TRIMMED_MAX_VALUE - 3);
0297:                } else {
0298:                    checkStrains(Spring.constant(0, 3, 1), Spring.constant(1,
0299:                            1, 3), 6, Spring.UNSET + 3, 6 - Spring.UNSET - 3);
0300:                }
0301:                checkStrains(Spring.constant(3, 1, 3),
0302:                        Spring.constant(1, 3, 1), 2, 1, 1);
0303:                if (isHarmony()) {
0304:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(3,
0305:                            1, 3), 2, Spring.TRIMMED_MAX_VALUE + 3,
0306:                            2 - Spring.TRIMMED_MAX_VALUE - 3);
0307:                } else {
0308:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(3,
0309:                            1, 3), 2, Spring.UNSET + 3, 2 - Spring.UNSET - 3);
0310:                }
0311:                checkStrains(Spring.constant(3, 1, 3),
0312:                        Spring.constant(1, 3, 1), 4, 1, 3);
0313:                checkStrains(Spring.constant(1, 3, 1),
0314:                        Spring.constant(3, 1, 3), 4, 3, 1);
0315:                checkStrains(Spring.constant(3, 1, 3),
0316:                        Spring.constant(1, 3, 1), 6, 1, 5);
0317:                if (isHarmony()) {
0318:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(3,
0319:                            1, 3), 6, Spring.TRIMMED_MAX_VALUE + 3,
0320:                            6 - Spring.TRIMMED_MAX_VALUE - 3);
0321:                } else {
0322:                    checkStrains(Spring.constant(1, 3, 1), Spring.constant(3,
0323:                            1, 3), 6, Spring.UNSET + 3, 6 - Spring.UNSET - 3);
0324:                }
0325:                checkStrains(Spring.constant(2, 2, 5), Spring.constant(3), 3,
0326:                        2, 1);
0327:                checkStrains(Spring.constant(3), Spring.constant(2, 2, 5), 3,
0328:                        3, 0);
0329:                checkStrains(Spring.constant(2, 2, 5), Spring.constant(3), 5,
0330:                        2, 3);
0331:                checkStrains(Spring.constant(3), Spring.constant(2, 2, 5), 5,
0332:                        3, 2);
0333:                checkStrains(Spring.constant(2, 2, 5), Spring.constant(3), 7,
0334:                        4, 3);
0335:                checkStrains(Spring.constant(3), Spring.constant(2, 2, 5), 7,
0336:                        3, 4);
0337:                if (isHarmony()) {
0338:                    checkStrains(Spring.constant(2, 4, 3), Spring.constant(3,
0339:                            1, 0), 2, Spring.TRIMMED_MAX_VALUE + 4,
0340:                            2 - Spring.TRIMMED_MAX_VALUE - 4);
0341:                } else {
0342:                    checkStrains(Spring.constant(2, 4, 3), Spring.constant(3,
0343:                            1, 0), 2, Spring.UNSET + 4, 2 - Spring.UNSET - 4);
0344:                }
0345:                if (isHarmony()) {
0346:                    checkStrains(Spring.constant(2, 4, 3), Spring.constant(3,
0347:                            1, 0), 2, Spring.TRIMMED_MAX_VALUE + 4,
0348:                            2 - Spring.TRIMMED_MAX_VALUE - 4);
0349:                } else {
0350:                    checkStrains(Spring.constant(2, 4, 3), Spring.constant(3,
0351:                            1, 0), 2, Spring.UNSET + 4, 2 - Spring.UNSET - 4);
0352:                }
0353:                checkStrains(Spring.constant(2, 3, 4),
0354:                        Spring.constant(3, 1, 1), 2, 5, -3);
0355:
0356:                if (isHarmony()) {
0357:                    checkStrains(Spring.constant(2, 3, 3), Spring.constant(3,
0358:                            1, 0), 2, 5, -3);
0359:                } else {
0360:                    checkStrains(Spring.constant(2, 3, 3), Spring.constant(3,
0361:                            1, 0), 2, 3, -1);
0362:                }
0363:            }
0364:
0365:            public void testSum_Overflow() throws Exception {
0366:                spring1 = Spring.constant(0);
0367:                spring2 = Spring.width(component);
0368:                spring = Spring.sum(spring1, spring2);
0369:                component.setMaximumSize(new Dimension(Integer.MAX_VALUE,
0370:                        Integer.MAX_VALUE));
0371:                assertEquals(Short.MAX_VALUE, spring.getMaximumValue());
0372:                spring1 = Spring.constant(4, 5, 6);
0373:                spring = Spring.sum(spring1, spring2);
0374:                assertEquals(Short.MAX_VALUE + 6, spring.getMaximumValue());
0375:                spring1 = Spring.constant(4, 5, Integer.MAX_VALUE);
0376:                spring = Spring.sum(spring1, spring2);
0377:                assertEquals(Integer.MAX_VALUE + Short.MAX_VALUE, spring
0378:                        .getMaximumValue());
0379:                component.setMaximumSize(new Dimension(Integer.MIN_VALUE,
0380:                        Integer.MIN_VALUE));
0381:                spring1 = Spring.constant(4, 5, -6);
0382:                spring = Spring.sum(spring1, spring2);
0383:                if (isHarmony()) {
0384:                    assertEquals(Spring.TRIMMED_MIN_VALUE - 6, spring
0385:                            .getMaximumValue());
0386:                } else {
0387:                    assertEquals(Integer.MIN_VALUE - 6, spring
0388:                            .getMaximumValue());
0389:                }
0390:                spring1 = Spring.constant(4, 5, Integer.MIN_VALUE);
0391:                spring = Spring.sum(spring1, spring2);
0392:                if (isHarmony()) {
0393:                    assertEquals(Spring.TRIMMED_MIN_VALUE + Integer.MIN_VALUE,
0394:                            spring.getMaximumValue());
0395:                } else {
0396:                    assertEquals(0, spring.getMaximumValue());
0397:                }
0398:            }
0399:
0400:            public void testSum_SizesCashing() throws Exception {
0401:                spring1 = Spring.constant(4, 5, 6);
0402:                spring2 = Spring.width(component);
0403:                spring = Spring.sum(spring1, spring2);
0404:                assertSizes(6, 80, Short.MAX_VALUE + 6, spring);
0405:                setComponentSizes(component, new Dimension(1, 1));
0406:                assertSizes(6, 80, Short.MAX_VALUE + 6, spring);
0407:                spring2.setValue(0);
0408:                assertEquals(5, spring.getValue());
0409:                assertEquals(5, spring1.getValue());
0410:                assertEquals(0, spring2.getValue());
0411:                spring.setValue(3);
0412:                assertSizes(6, 80, Short.MAX_VALUE + 6, spring);
0413:                assertEquals(3, spring.getValue());
0414:                assertEquals(4, spring1.getValue());
0415:                assertEquals(-1, spring2.getValue());
0416:                assertSizes(6, 80, Short.MAX_VALUE + 6, spring);
0417:                spring1.setValue(3);
0418:                assertEquals(3, spring.getValue());
0419:                assertSizes(6, 80, Short.MAX_VALUE + 6, spring);
0420:                spring.setValue(Spring.UNSET);
0421:                assertSizes(5, 6, 7, 6, spring);
0422:                spring1.setValue(10);
0423:                assertSizes(5, 6, 7, 6, spring);
0424:                spring.setValue(Spring.UNSET);
0425:                spring1.setValue(10);
0426:                assertSizes(5, 6, 7, 11, spring);
0427:                spring1.setValue(100);
0428:                assertSizes(5, 6, 7, 11, spring);
0429:                spring.setValue(Spring.UNSET);
0430:                component.setPreferredSize(new Dimension(10, 20));
0431:                assertSizes(5, 15, 7, 15, spring);
0432:                component.setPreferredSize(new Dimension(100, 200));
0433:                assertSizes(5, 15, 7, 15, spring);
0434:                spring.setValue(Spring.UNSET);
0435:                component.setMinimumSize(new Dimension(10, 20));
0436:                assertSizes(14, 105, 7, 105, spring);
0437:                component.setMinimumSize(new Dimension(100, 200));
0438:                assertSizes(14, 105, 7, 105, spring);
0439:                spring.setValue(Spring.UNSET);
0440:                component.setPreferredSize(new Dimension(10, 20));
0441:                component.setMinimumSize(new Dimension(30, 40));
0442:                assertSizes(34, 15, 7, spring);
0443:                component.setPreferredSize(new Dimension(100, 200));
0444:                assertSizes(34, 15, 7, spring);
0445:                spring.getValue();
0446:                component.setMinimumSize(new Dimension(300, 400));
0447:                assertSizes(34, 15, 7, 105, spring);
0448:                spring.setValue(Spring.UNSET);
0449:                spring.getValue();
0450:                assertEquals(105, spring.getPreferredValue());
0451:                component.setMinimumSize(new Dimension(30, 40));
0452:                assertEquals(34, spring.getMinimumValue());
0453:                spring.setValue(Spring.UNSET);
0454:                component.setPreferredSize(new Dimension(10, 20));
0455:                component.setMinimumSize(new Dimension(30, 40));
0456:                assertSizes(34, 15, 7, spring);
0457:                spring.setValue(Spring.UNSET);
0458:                component.setPreferredSize(new Dimension(100, 200));
0459:                assertSizes(34, 105, 7, spring);
0460:            }
0461:
0462:            public void testSum_UNSET() throws Exception {
0463:                spring1 = Spring.constant(2, 4, 5);
0464:                spring2 = Spring.constant(5);
0465:                spring1.setValue(4);
0466:                spring2.setValue(5);
0467:                spring = Spring.sum(spring1, spring2);
0468:                spring.getValue();
0469:                spring.setValue(Spring.UNSET);
0470:                assertSizes(2, 4, 5, 4, spring1);
0471:                assertSizes(5, 5, 5, 5, spring2);
0472:                spring.setValue(Spring.UNSET);
0473:                spring.setValue(100);
0474:                assertSizes(2, 4, 5, 95, spring1);
0475:                assertSizes(5, 5, 5, 5, spring2);
0476:                assertSizes(7, 9, 10, 100, spring);
0477:                spring1.setValue(1);
0478:                spring2.setValue(1);
0479:                spring.setValue(Spring.UNSET);
0480:                spring.setValue(-10);
0481:                assertSizes(2, 4, 5, -15, spring1);
0482:                assertSizes(5, 5, 5, 5, spring2);
0483:                assertSizes(7, 9, 10, -10, spring);
0484:                spring = Spring.sum(spring1, spring2);
0485:                spring1.setValue(1);
0486:                spring2.setValue(1);
0487:                spring = Spring.sum(spring1, spring2);
0488:                assertSizes(7, 9, 10, spring);
0489:                spring.setValue(Spring.UNSET);
0490:                assertSizes(2, 4, 5, 1, spring1);
0491:                assertSizes(5, 5, 5, 1, spring2);
0492:                assertSizes(7, 9, 10, 2, spring);
0493:                spring1 = Spring.constant(4, 5, 6);
0494:                spring2 = Spring.width(component);
0495:                component.setMinimumSize(new Dimension(4, 14));
0496:                component.setPreferredSize(new Dimension(5, 15));
0497:                component.setMaximumSize(new Dimension(6, 16));
0498:                spring = Spring.sum(spring1, spring2);
0499:                spring1.setValue(1);
0500:                spring2.setValue(2);
0501:                spring.setValue(3);
0502:                assertEquals(2, spring1.getValue());
0503:                assertEquals(1, spring2.getValue());
0504:                component.setMaximumSize(new Dimension(60, 160));
0505:                spring.setValue(3);
0506:                assertEquals(2, spring1.getValue());
0507:                assertEquals(1, spring2.getValue());
0508:            }
0509:
0510:            public void testMax() throws Exception {
0511:                testExceptionalCase(new NullPointerCase() {
0512:                    @Override
0513:                    public void exceptionalAction() throws Exception {
0514:                        Spring.max(null, Spring.constant(11)).getValue();
0515:                    }
0516:                });
0517:
0518:                spring1 = Spring.constant(12, 13, 15);
0519:                spring2 = Spring.constant(11, 11, 13);
0520:                spring = Spring.max(spring1, spring2);
0521:                spring.setValue(100);
0522:                assertEquals(100, spring1.getValue());
0523:                assertEquals(11, spring2.getValue());
0524:                assertEquals(100, spring.getValue());
0525:
0526:                spring.setValue(10);
0527:                assertEquals(10, spring1.getValue());
0528:                assertEquals(10, spring2.getValue());
0529:                assertEquals(10, spring.getValue());
0530:
0531:                spring.setValue(Spring.UNSET);
0532:                spring.setValue(10);
0533:                assertEquals(10, spring1.getValue());
0534:                assertEquals(10, spring2.getValue());
0535:                assertEquals(10, spring.getValue());
0536:
0537:                spring1 = Spring.constant(12, 13, 15);
0538:                spring2 = Spring.constant(11, 12, 13);
0539:                spring = Spring.max(spring1, spring2);
0540:                assertEquals(spring.getMaximumValue(), Math.max(spring1
0541:                        .getMaximumValue(), spring2.getMaximumValue()));
0542:                assertEquals(spring.getValue(), Math.max(spring1.getValue(),
0543:                        spring2.getValue()));
0544:                spring.setValue(335);
0545:                assertEquals(335, spring.getValue());
0546:                if (spring1.getValue() > spring2.getValue()) {
0547:                    assertEquals(335, spring1.getValue());
0548:                } else {
0549:                    assertEquals(335, spring2.getValue());
0550:                }
0551:
0552:                spring1 = Spring.constant(6, 13, 24);
0553:                spring2 = Spring.constant(11, 12, 13);
0554:                spring = Spring.max(spring1, spring2);
0555:                assertSizes(11, 13, 24, 13, spring);
0556:            }
0557:
0558:            public void testMax_SizesCashing() throws Exception {
0559:                spring1 = Spring.constant(5);
0560:                spring2 = Spring.width(component);
0561:                spring = Spring.max(spring1, spring2);
0562:                assertSizes(5, 75, Short.MAX_VALUE, spring);
0563:                setComponentSizes(component, new Dimension(1, 1));
0564:                assertSizes(5, 75, Short.MAX_VALUE, spring);
0565:                spring2.setValue(0);
0566:                assertEquals(5, spring.getValue());
0567:                assertEquals(5, spring1.getValue());
0568:                assertEquals(0, spring2.getValue());
0569:                spring.setValue(3);
0570:                assertSizes(5, 75, Short.MAX_VALUE, spring);
0571:                assertEquals(3, spring.getValue());
0572:                assertEquals(3, spring1.getValue());
0573:                assertEquals(1, spring2.getValue());
0574:                assertSizes(5, 75, Short.MAX_VALUE, spring);
0575:                spring.setValue(Spring.UNSET);
0576:                assertSizes(5, 5, 5, 5, spring);
0577:                spring1.setValue(10);
0578:                spring2.setValue(10);
0579:                assertSizes(5, 5, 5, 5, spring);
0580:                spring.setValue(Spring.UNSET);
0581:                spring1.setValue(10);
0582:                assertSizes(5, 5, 5, 10, spring);
0583:                spring1.setValue(100);
0584:                assertSizes(5, 5, 5, 10, spring);
0585:                spring.setValue(Spring.UNSET);
0586:                component.setPreferredSize(new Dimension(10, 20));
0587:                assertSizes(5, 10, 5, 10, spring);
0588:                component.setPreferredSize(new Dimension(100, 200));
0589:                assertSizes(5, 10, 5, 10, spring);
0590:                spring.setValue(Spring.UNSET);
0591:                component.setMinimumSize(new Dimension(10, 20));
0592:                assertSizes(10, 100, 5, 100, spring);
0593:                component.setMinimumSize(new Dimension(100, 200));
0594:                assertSizes(10, 100, 5, 100, spring);
0595:                spring.setValue(Spring.UNSET);
0596:                component.setPreferredSize(new Dimension(10, 20));
0597:                component.setMinimumSize(new Dimension(30, 40));
0598:                assertSizes(30, 10, 5, spring);
0599:                component.setPreferredSize(new Dimension(100, 200));
0600:                assertSizes(30, 10, 5, spring);
0601:                spring.getValue();
0602:                component.setMinimumSize(new Dimension(300, 400));
0603:                assertSizes(30, 10, 5, 100, spring);
0604:                spring.setValue(Spring.UNSET);
0605:                spring.getValue();
0606:                assertEquals(100, spring.getPreferredValue());
0607:                component.setMinimumSize(new Dimension(30, 40));
0608:                assertEquals(30, spring.getMinimumValue());
0609:                spring.setValue(Spring.UNSET);
0610:                component.setPreferredSize(new Dimension(10, 20));
0611:                component.setMinimumSize(new Dimension(30, 40));
0612:                assertSizes(30, 10, 5, spring);
0613:                spring.setValue(Spring.UNSET);
0614:                component.setPreferredSize(new Dimension(100, 200));
0615:                assertSizes(30, 100, 5, spring);
0616:            }
0617:
0618:            public void testMax_Overlow() throws Exception {
0619:                spring1 = Spring.constant(6, 13, 24);
0620:                spring2 = Spring.constant(11, 12, Integer.MAX_VALUE);
0621:                spring = Spring.max(spring1, spring2);
0622:                if (isHarmony()) {
0623:                    assertSizes(11, 13, Spring.TRIMMED_MAX_VALUE, 13, spring);
0624:                } else {
0625:                    assertSizes(11, 13, Integer.MAX_VALUE, 13, spring);
0626:                }
0627:                spring1 = Spring.constant(6, 13, Integer.MAX_VALUE);
0628:                spring2 = Spring.constant(11, 12, 13);
0629:                spring = Spring.max(spring1, spring2);
0630:                if (isHarmony()) {
0631:                    assertSizes(11, 13, Spring.TRIMMED_MAX_VALUE, 13, spring);
0632:                } else {
0633:                    assertSizes(11, 13, Integer.MAX_VALUE, 13, spring);
0634:                }
0635:            }
0636:
0637:            public void testMax_UNSET() throws Exception {
0638:                spring1 = Spring.constant(5);
0639:                spring2 = Spring.constant(4);
0640:                spring1.setValue(1);
0641:                spring2.setValue(1);
0642:                spring = Spring.max(spring1, spring2);
0643:                spring.getValue();
0644:                spring.setValue(Spring.UNSET);
0645:                assertSizes(5, 5, 5, 5, spring1);
0646:                assertSizes(4, 4, 4, 4, spring2);
0647:                spring.setValue(Spring.UNSET);
0648:                spring.setValue(10);
0649:                assertSizes(5, 5, 5, 10, spring1);
0650:                assertSizes(4, 4, 4, 4, spring2);
0651:                spring1.setValue(1);
0652:                spring2.setValue(1);
0653:                spring = Spring.max(spring1, spring2);
0654:                assertSizes(5, 5, 5, spring);
0655:                spring.setValue(Spring.UNSET);
0656:                assertSizes(5, 5, 5, 1, spring1);
0657:                assertSizes(4, 4, 4, 1, spring2);
0658:                spring1 = Spring.constant(4, 4, 6);
0659:                spring2 = Spring.constant(4, 5, 5);
0660:                spring = Spring.max(spring1, spring2);
0661:                spring1.setValue(2);
0662:                spring2.setValue(1);
0663:                spring.setValue(Math.max(spring1.getPreferredValue(), spring2
0664:                        .getPreferredValue()) + 5);
0665:                assertEquals(spring1.getPreferredValue(), spring1.getValue());
0666:                assertEquals(10, spring2.getValue());
0667:                spring1 = Spring.constant(4, 5, 6);
0668:                spring2 = Spring.width(component);
0669:                component.setMinimumSize(new Dimension(4, 14));
0670:                component.setPreferredSize(new Dimension(5, 15));
0671:                component.setMaximumSize(new Dimension(6, 16));
0672:                spring = Spring.max(spring1, spring2);
0673:                spring1.setValue(2);
0674:                spring2.setValue(1);
0675:                spring.setValue(6);
0676:                assertSizes(4, 5, 6, 6, spring1);
0677:                assertSizes(4, 5, 6, 5, spring2);
0678:                component.setPreferredSize(new Dimension(25, 35));
0679:                spring.setValue(6);
0680:                assertSizes(4, 5, 6, 5, spring1);
0681:                assertSizes(4, 25, 6, 6, spring2);
0682:            }
0683:
0684:            public void testScale() {
0685:                testExceptionalCase(new NullPointerCase() {
0686:                    @Override
0687:                    public void exceptionalAction() throws Exception {
0688:                        Spring.scale(null, 1).getValue();
0689:                    }
0690:                });
0691:                testScale(1);
0692:                testScale(0);
0693:                testScale(5);
0694:                testScale(1.3f);
0695:                testScale(1.5f);
0696:                testScale(1.7f);
0697:                testScale(-5);
0698:                testScale(-1.3f);
0699:                testScale(-1.5f);
0700:                testScale(-1.7f);
0701:            }
0702:
0703:            public void testScale_Overflow() throws Exception {
0704:                component = new JTextField();
0705:                spring = Spring.scale(Spring.width(component), 2f);
0706:                spring.setValue(2147483642);
0707:                if (isHarmony()) {
0708:                    assertEquals(Spring.TRIMMED_MAX_VALUE, spring.getValue());
0709:                } else {
0710:                    assertEquals(2147483647, spring.getValue());
0711:                }
0712:                component.setMaximumSize(new Dimension(Integer.MAX_VALUE,
0713:                        Integer.MAX_VALUE));
0714:                if (isHarmony()) {
0715:                    assertEquals(Spring.TRIMMED_MAX_VALUE, spring
0716:                            .getMaximumValue());
0717:                } else {
0718:                    assertEquals(2 * Short.MAX_VALUE, spring.getMaximumValue());
0719:                }
0720:                spring = Spring.scale(Spring.width(component), 2f);
0721:                component.setMaximumSize(new Dimension(Integer.MIN_VALUE,
0722:                        Integer.MIN_VALUE));
0723:                if (isHarmony()) {
0724:                    assertEquals(Spring.TRIMMED_MIN_VALUE, spring
0725:                            .getMaximumValue());
0726:                } else {
0727:                    assertEquals(Integer.MIN_VALUE, spring.getMaximumValue());
0728:                }
0729:                spring = Spring.scale(Spring.width(component), -2f);
0730:                component.setMaximumSize(new Dimension(Integer.MIN_VALUE,
0731:                        Integer.MIN_VALUE));
0732:                assertEquals(-8, spring.getMaximumValue());
0733:            }
0734:
0735:            public void testScale_SizesCashing() throws Exception {
0736:                spring1 = Spring.width(component);
0737:                spring = Spring.scale(spring1, 2);
0738:                if (isHarmony()) {
0739:                    assertSizes(4, 150, Short.MAX_VALUE, spring);
0740:                } else {
0741:                    assertSizes(4, 150, 2 * Short.MAX_VALUE, spring);
0742:                }
0743:                setComponentSizes(component, new Dimension(1, 1));
0744:                assertSizes(2, 2, 2, spring);
0745:                spring1.setValue(1);
0746:                assertEquals(2, spring.getValue());
0747:                assertEquals(1, spring1.getValue());
0748:                spring.setValue(6);
0749:                assertSizes(2, 2, 2, spring);
0750:                assertEquals(6, spring.getValue());
0751:                assertEquals(3, spring1.getValue());
0752:                spring.setValue(Spring.UNSET);
0753:                assertSizes(2, 2, 2, spring);
0754:                assertEquals(spring.getPreferredValue(), spring.getValue());
0755:                // No caching
0756:            }
0757:
0758:            public void testScale_UNSET() throws Exception {
0759:                spring1 = Spring.width(component);
0760:                spring1.setValue(10);
0761:                spring = Spring.scale(spring1, 2);
0762:                component.setMinimumSize(new Dimension(11, 12));
0763:                component.setPreferredSize(new Dimension(13, 14));
0764:                component.setMaximumSize(new Dimension(15, 16));
0765:                assertSizes(22, 26, 30, 20, spring);
0766:                spring.setValue(Spring.UNSET);
0767:                assertSizes(22, 26, 30, 2 * spring1.getPreferredValue(), spring);
0768:                component.setPreferredSize(new Dimension(101, 102));
0769:                assertEquals(101, spring1.getValue());
0770:                assertEquals(202, spring.getValue());
0771:                component.setPreferredSize(new Dimension(201, 202));
0772:                assertEquals(201, spring1.getValue());
0773:                assertEquals(402, spring.getValue());
0774:                component.setPreferredSize(new Dimension(201, 202));
0775:                assertEquals(201, spring1.getValue());
0776:                assertEquals(402, spring.getValue());
0777:                spring1.setValue(11);
0778:                assertEquals(22, spring.getValue());
0779:            }
0780:
0781:            public void testWidth() {
0782:                testExceptionalCase(new NullPointerCase() {
0783:                    @Override
0784:                    public void exceptionalAction() throws Exception {
0785:                        Spring.width(null).getValue();
0786:                    }
0787:                });
0788:                spring1 = Spring.width(new JButton());
0789:                spring2 = Spring.width(new JButton());
0790:                assertFalse(spring1.equals(spring2));
0791:
0792:                component = new JButton();
0793:                spring1 = Spring.width(component);
0794:                spring2 = Spring.width(component);
0795:                assertFalse(spring1.equals(spring2));
0796:
0797:                final Marker getMinimumSizeCalled = new Marker();
0798:                final Marker getMaximumSizeCalled = new Marker();
0799:                final Marker getPreferedSizeCalled = new Marker();
0800:                component = new JButton("Test") {
0801:                    private static final long serialVersionUID = 1L;
0802:
0803:                    @Override
0804:                    public java.awt.Dimension getMinimumSize() {
0805:                        getMinimumSizeCalled.setOccurred();
0806:                        return super .getMinimumSize();
0807:                    }
0808:
0809:                    @Override
0810:                    public java.awt.Dimension getPreferredSize() {
0811:                        getPreferedSizeCalled.setOccurred();
0812:                        return super .getPreferredSize();
0813:                    }
0814:
0815:                    @Override
0816:                    public java.awt.Dimension getMaximumSize() {
0817:                        getMaximumSizeCalled.setOccurred();
0818:                        return super .getMaximumSize();
0819:                    }
0820:                };
0821:                initComponentSizes(component);
0822:                spring = Spring.width(component);
0823:                assertFalse(getPreferedSizeCalled.isOccurred());
0824:                assertFalse(getMinimumSizeCalled.isOccurred());
0825:                assertFalse(getMaximumSizeCalled.isOccurred());
0826:                getPreferedSizeCalled.reset();
0827:                spring.getPreferredValue();
0828:                assertTrue(getPreferedSizeCalled.isOccurred());
0829:                getPreferedSizeCalled.reset();
0830:                spring.getPreferredValue();
0831:                assertTrue(getPreferedSizeCalled.isOccurred());
0832:                getMinimumSizeCalled.reset();
0833:                spring.getMinimumValue();
0834:                assertTrue(getMinimumSizeCalled.isOccurred());
0835:                getMaximumSizeCalled.reset();
0836:                spring.getMaximumValue();
0837:                assertTrue(getMaximumSizeCalled.isOccurred());
0838:                assertSizes(component.getMinimumSize().width, component
0839:                        .getPreferredSize().width, Short.MAX_VALUE, component
0840:                        .getPreferredSize().width, spring);
0841:                spring.setValue(10);
0842:                assertSizes(component.getMinimumSize().width, component
0843:                        .getPreferredSize().width, Short.MAX_VALUE, 10, spring);
0844:                component.setMinimumSize(new Dimension(11, 12));
0845:                component.setPreferredSize(new Dimension(13, 14));
0846:                component.setMaximumSize(new Dimension(15, 16));
0847:                assertSizes(11, 13, 15, 10, spring);
0848:                component.setSize(new Dimension(100, 200));
0849:                assertSizes(11, 13, 15, 10, spring);
0850:            }
0851:
0852:            public void testWidth_UNSET() throws Exception {
0853:                spring = Spring.width(component);
0854:                spring.setValue(10);
0855:                component.setMinimumSize(new Dimension(11, 12));
0856:                component.setPreferredSize(new Dimension(13, 14));
0857:                component.setMaximumSize(new Dimension(15, 16));
0858:                assertSizes(11, 13, 15, 10, spring);
0859:                spring.setValue(Spring.UNSET);
0860:                assertSizes(11, 13, 15, spring.getPreferredValue(), spring);
0861:                component.setPreferredSize(new Dimension(101, 102));
0862:                assertEquals(101, spring.getValue());
0863:                component.setPreferredSize(new Dimension(201, 102));
0864:                assertEquals(201, spring.getValue());
0865:                component.setSize(new Dimension(500, 600));
0866:                spring.setValue(Spring.UNSET);
0867:                assertSizes(11, 201, 15, 201, spring);
0868:            }
0869:
0870:            public void testWidth_Overflow() throws Exception {
0871:                spring = Spring.width(component);
0872:                spring.setValue(Integer.MAX_VALUE - 5);
0873:                assertEquals(Integer.MAX_VALUE - 5, spring.getValue());
0874:                spring.setValue(Integer.MAX_VALUE - 5);
0875:                component.setMaximumSize(new Dimension(Integer.MAX_VALUE,
0876:                        Integer.MAX_VALUE));
0877:                assertEquals(Short.MAX_VALUE, spring.getMaximumValue());
0878:                spring = Spring.width(component);
0879:                component.setMaximumSize(new Dimension(Integer.MIN_VALUE,
0880:                        Integer.MIN_VALUE));
0881:                if (isHarmony()) {
0882:                    assertEquals(Spring.TRIMMED_MIN_VALUE, spring
0883:                            .getMaximumValue());
0884:                } else {
0885:                    assertEquals(Integer.MIN_VALUE, spring.getMaximumValue());
0886:                }
0887:            }
0888:
0889:            public void testHeight() {
0890:                testExceptionalCase(new NullPointerCase() {
0891:                    @Override
0892:                    public void exceptionalAction() throws Exception {
0893:                        Spring.height(null).getValue();
0894:                    }
0895:                });
0896:
0897:                component = new JButton("Test") {
0898:                    private static final long serialVersionUID = 1L;
0899:
0900:                    @Override
0901:                    public java.awt.Dimension getMinimumSize() {
0902:                        componentGetMinimumSizeCalled.setOccurred();
0903:                        return super .getMinimumSize();
0904:                    }
0905:
0906:                    @Override
0907:                    public java.awt.Dimension getPreferredSize() {
0908:                        componentGetPreferedSizeCalled.setOccurred();
0909:                        return super .getPreferredSize();
0910:                    }
0911:
0912:                    @Override
0913:                    public java.awt.Dimension getMaximumSize() {
0914:                        componentGetMaximumSizeCalled.setOccurred();
0915:                        return super .getMaximumSize();
0916:                    }
0917:                };
0918:                initComponentSizes(component);
0919:                spring = Spring.height(component);
0920:                assertFalse(componentGetPreferedSizeCalled.isOccurred());
0921:                assertFalse(componentGetMinimumSizeCalled.isOccurred());
0922:                assertFalse(componentGetMaximumSizeCalled.isOccurred());
0923:                componentGetPreferedSizeCalled.reset();
0924:                spring.getPreferredValue();
0925:                assertTrue(componentGetPreferedSizeCalled.isOccurred());
0926:                componentGetPreferedSizeCalled.reset();
0927:                spring.getPreferredValue();
0928:                assertTrue(componentGetPreferedSizeCalled.isOccurred());
0929:                componentGetMinimumSizeCalled.reset();
0930:                spring.getMinimumValue();
0931:                assertTrue(componentGetMinimumSizeCalled.isOccurred());
0932:                componentGetMaximumSizeCalled.reset();
0933:                spring.getMaximumValue();
0934:                assertTrue(componentGetMaximumSizeCalled.isOccurred());
0935:                assertSizes(component.getMinimumSize().height, component
0936:                        .getPreferredSize().height, Short.MAX_VALUE, component
0937:                        .getPreferredSize().height, spring);
0938:                spring.setValue(10);
0939:                assertSizes(component.getMinimumSize().height, component
0940:                        .getPreferredSize().height, Short.MAX_VALUE, 10, spring);
0941:                component.setMinimumSize(new Dimension(11, 12));
0942:                component.setPreferredSize(new Dimension(13, 14));
0943:                component.setMaximumSize(new Dimension(15, 16));
0944:                assertSizes(12, 14, 16, 10, spring);
0945:            }
0946:
0947:            public void testHeight_UNSET() throws Exception {
0948:                spring = Spring.height(component);
0949:                spring.setValue(10);
0950:                component.setMinimumSize(new Dimension(11, 12));
0951:                component.setPreferredSize(new Dimension(13, 14));
0952:                component.setMaximumSize(new Dimension(15, 16));
0953:                assertSizes(12, 14, 16, 10, spring);
0954:                spring.setValue(Spring.UNSET);
0955:                assertSizes(12, 14, 16, spring.getPreferredValue(), spring);
0956:                component.setPreferredSize(new Dimension(101, 102));
0957:                assertEquals(102, spring.getValue());
0958:                component.setPreferredSize(new Dimension(201, 202));
0959:                assertEquals(202, spring.getValue());
0960:            }
0961:
0962:            public void testHeight_Overflow() throws Exception {
0963:                component = new JTextField();
0964:                spring = Spring.height(component);
0965:                spring.setValue(Integer.MAX_VALUE - 5);
0966:                assertEquals(Integer.MAX_VALUE - 5, spring.getValue());
0967:                spring.setValue(Integer.MAX_VALUE - 5);
0968:                component.setMaximumSize(new Dimension(Integer.MAX_VALUE,
0969:                        Integer.MAX_VALUE));
0970:                assertEquals(Short.MAX_VALUE, spring.getMaximumValue());
0971:                spring = Spring.height(component);
0972:                component.setMaximumSize(new Dimension(Integer.MIN_VALUE,
0973:                        Integer.MIN_VALUE));
0974:                if (isHarmony()) {
0975:                    assertEquals(Spring.TRIMMED_MIN_VALUE, spring
0976:                            .getMaximumValue());
0977:                } else {
0978:                    assertEquals(Integer.MIN_VALUE, spring.getMaximumValue());
0979:                }
0980:            }
0981:
0982:            public void testToString() {
0983:                component = new JButton("Test");
0984:                setComponentSizes(component, new Dimension(59, 25));
0985:                Spring spring1 = Spring.constant(1, 2, 3);
0986:                Spring spring2 = Spring.width(component);
0987:                if (isHarmony()) {
0988:                    assertEquals("[1, 2, 3]", spring1.toString());
0989:                    assertEquals("[5, 5, 5]", Spring.constant(5).toString());
0990:                    assertEquals(
0991:                            "[Width of javax.swing.JButton: (59, 59, 59)]",
0992:                            spring2.toString());
0993:                    assertEquals(
0994:                            "[Height of javax.swing.JButton: (25, 25, 25)]",
0995:                            Spring.height(component).toString());
0996:                    assertEquals("(-[1, 2, 3])", Spring.minus(spring1)
0997:                            .toString());
0998:                    assertEquals(
0999:                            "([1, 2, 3] + [Width of javax.swing.JButton: (59, 59, 59)])",
1000:                            Spring.sum(spring1, spring2).toString());
1001:                    assertEquals(
1002:                            "max([1, 2, 3], [Width of javax.swing.JButton: (59, 59, 59)])",
1003:                            Spring.max(spring1, spring2).toString());
1004:                    assertEquals("(0.3 * [1, 2, 3])", Spring.scale(spring1,
1005:                            0.3f).toString());
1006:                }
1007:            }
1008:
1009:            public static void assertSizes(final int min, final int pref,
1010:                    final int max, final Spring spring) {
1011:                assertEquals(min, spring.getMinimumValue());
1012:                assertEquals(pref, spring.getPreferredValue());
1013:                assertEquals(max, spring.getMaximumValue());
1014:            }
1015:
1016:            public static void assertSizes(final int min, final int pref,
1017:                    final int max, final int value, final Spring spring) {
1018:                assertSizes(min, pref, max, spring);
1019:                assertEquals(value, spring.getValue());
1020:            }
1021:
1022:            public static void assertValues(final Spring expectedSpring,
1023:                    final Spring spring) {
1024:                assertSizes(expectedSpring.getMinimumValue(), expectedSpring
1025:                        .getPreferredValue(), expectedSpring.getMaximumValue(),
1026:                        expectedSpring.getValue(), spring);
1027:            }
1028:
1029:            private void initComponentSizes(Component c) {
1030:                c.setMinimumSize(new Dimension(2, 2));
1031:                c.setPreferredSize(new Dimension(75, 25));
1032:                c.setMaximumSize(new Dimension(Integer.MAX_VALUE,
1033:                        Integer.MAX_VALUE));
1034:            }
1035:
1036:            private void checkStrains(final Spring spring1,
1037:                    final Spring spring2, final int newValue, final int val1,
1038:                    final int val2) {
1039:                Spring sum = Spring.sum(spring1, spring2);
1040:                assertSizes(spring1.getMinimumValue()
1041:                        + spring2.getMinimumValue(), spring1
1042:                        .getPreferredValue()
1043:                        + spring2.getPreferredValue(), spring1
1044:                        .getMaximumValue()
1045:                        + spring2.getMaximumValue(), spring1.getValue()
1046:                        + spring2.getValue(), sum);
1047:                sum.setValue(newValue);
1048:                assertEquals(val1, spring1.getValue());
1049:                assertEquals(val2, spring2.getValue());
1050:            }
1051:
1052:            private void testScale(final float factor) {
1053:                spring1 = Spring.constant(12, 13, 15);
1054:                spring = Spring.scale(spring1, factor);
1055:                if (factor > 0) {
1056:                    assertSizes(Math.round(factor * spring1.getMinimumValue()),
1057:                            Math.round(factor * spring1.getPreferredValue()),
1058:                            Math.round(factor * spring1.getMaximumValue()),
1059:                            Math.round(factor * spring1.getValue()), spring);
1060:                } else {
1061:                    assertSizes(Math.round(factor * spring1.getMaximumValue()),
1062:                            Math.round(factor * spring1.getPreferredValue()),
1063:                            Math.round(factor * spring1.getMinimumValue()),
1064:                            Math.round(factor * spring1.getValue()), spring);
1065:                }
1066:                assertFalse(Integer.MAX_VALUE == spring1.getMinimumValue());
1067:                assertFalse(Integer.MAX_VALUE == spring1.getMaximumValue());
1068:                assertFalse(Integer.MAX_VALUE == spring1.getPreferredValue());
1069:                spring.setValue(3);
1070:                if (factor != 0) {
1071:                    assertEquals(Math.round(spring.getValue() / factor),
1072:                            spring1.getValue());
1073:                } else {
1074:                    assertEquals(Integer.MAX_VALUE, spring1.getValue());
1075:                }
1076:                spring.setValue(0);
1077:                assertEquals(0, spring1.getValue());
1078:                assertFalse(spring1.getPreferredValue() == spring1.getValue());
1079:                spring.setValue(-6);
1080:                if (factor != 0) {
1081:                    assertEquals(Math.round(spring.getValue() / factor),
1082:                            spring1.getValue());
1083:                } else {
1084:                    assertEquals(spring1.getPreferredValue(), spring1
1085:                            .getValue());
1086:                }
1087:                spring.setValue(Spring.UNSET);
1088:                assertEquals(spring.getPreferredValue(), spring.getValue());
1089:            }
1090:
1091:            private void setComponentSizes(Component component, Dimension size) {
1092:                component.setMinimumSize(size);
1093:                component.setPreferredSize(size);
1094:                component.setMaximumSize(size);
1095:            }
1096:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.