Source Code Cross Referenced for BasicOptionPaneUI_ButtonAreaLayoutTest.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:         */package javax.swing.plaf.basic;
021:
022:        import java.awt.Container;
023:        import java.awt.Dimension;
024:        import java.awt.Point;
025:        import javax.swing.JButton;
026:        import javax.swing.JComponent;
027:        import javax.swing.JDialog;
028:        import javax.swing.JPanel;
029:        import javax.swing.SwingTestCase;
030:        import javax.swing.border.EmptyBorder;
031:
032:        public class BasicOptionPaneUI_ButtonAreaLayoutTest extends
033:                SwingTestCase {
034:            protected BasicOptionPaneUI.ButtonAreaLayout layout;
035:
036:            public static void main(String[] args) {
037:                junit.textui.TestRunner
038:                        .run(BasicOptionPaneUI_ButtonAreaLayoutTest.class);
039:            }
040:
041:            /*
042:             * @see TestCase#setUp()
043:             */
044:            @Override
045:            protected void setUp() throws Exception {
046:                super .setUp();
047:            }
048:
049:            public void testButtonAreaLayout() {
050:                int padding1 = 100;
051:                int padding2 = 200;
052:                boolean syncAll1 = true;
053:                boolean syncAll2 = false;
054:                layout = new BasicOptionPaneUI.ButtonAreaLayout(syncAll1,
055:                        padding1);
056:                assertEquals("syncAll", syncAll1, layout.getSyncAllWidths());
057:                assertEquals("padding", padding1, layout.getPadding());
058:                assertTrue("CentersChildren", layout.getCentersChildren());
059:                layout = new BasicOptionPaneUI.ButtonAreaLayout(syncAll2,
060:                        padding2);
061:                assertEquals("syncAll", syncAll2, layout.getSyncAllWidths());
062:                assertEquals("padding", padding2, layout.getPadding());
063:                assertTrue("CentersChildren", layout.getCentersChildren());
064:            }
065:
066:            public void testSetGetSyncAllWidths() {
067:                boolean syncAll1 = true;
068:                boolean syncAll2 = false;
069:                layout = new BasicOptionPaneUI.ButtonAreaLayout(syncAll1, 0);
070:                assertEquals("syncAll", syncAll1, layout.getSyncAllWidths());
071:                layout.setSyncAllWidths(syncAll2);
072:                assertEquals("syncAll", syncAll2, layout.getSyncAllWidths());
073:            }
074:
075:            public void testSetGetPadding() {
076:                int padding1 = 100;
077:                int padding2 = 200;
078:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, padding1);
079:                assertEquals("padding", padding1, layout.getPadding());
080:                layout.setPadding(padding2);
081:                assertEquals("padding", padding2, layout.getPadding());
082:            }
083:
084:            public void testSetGetCentersChildren() {
085:                boolean centersChildren1 = true;
086:                boolean centersChildren2 = false;
087:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 0);
088:                assertTrue("CentersChildren", layout.getCentersChildren());
089:                layout.setCentersChildren(centersChildren1);
090:                assertEquals("CentersChildren", centersChildren1, layout
091:                        .getCentersChildren());
092:                layout.setCentersChildren(centersChildren2);
093:                assertEquals("CentersChildren", centersChildren2, layout
094:                        .getCentersChildren());
095:            }
096:
097:            public void testAddLayoutComponent() {
098:                Container container = new JPanel();
099:                JComponent component1 = new JPanel();
100:                JComponent component2 = new JPanel();
101:                JComponent component3 = new JPanel();
102:                JComponent component4 = new JPanel();
103:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 10);
104:                container.add(component1);
105:                container.add(component2);
106:                layout.addLayoutComponent("aaa", component1);
107:                layout.addLayoutComponent("bbb", component2);
108:                component1.setMinimumSize(new Dimension(50, 50));
109:                component2.setMinimumSize(new Dimension(70, 80));
110:                component3.setMinimumSize(new Dimension(90, 70));
111:                component4.setMinimumSize(new Dimension(80, 120));
112:                assertEquals("Sizes ", new Dimension(30, 10), layout
113:                        .minimumLayoutSize(container));
114:                container.add(component3);
115:                assertEquals("Sizes ", new Dimension(50, 10), layout
116:                        .minimumLayoutSize(container));
117:                layout.addLayoutComponent("asd", component3);
118:                assertEquals("Sizes ", new Dimension(50, 10), layout
119:                        .minimumLayoutSize(container));
120:                container.add(component4);
121:                assertEquals("Sizes ", new Dimension(70, 10), layout
122:                        .minimumLayoutSize(container));
123:                layout.addLayoutComponent("dsa", component4);
124:                assertEquals("Sizes ", new Dimension(70, 10), layout
125:                        .minimumLayoutSize(container));
126:            }
127:
128:            public void testLayoutContainer() {
129:                JComponent container = new JPanel();
130:                JComponent component1 = new JButton();
131:                JComponent component2 = new JButton();
132:                JComponent component3 = new JButton();
133:                JComponent component4 = new JButton();
134:                component4.setMinimumSize(new Dimension(41, 26));
135:                component3.setMinimumSize(new Dimension(48, 26));
136:                component2.setMinimumSize(new Dimension(55, 26));
137:                component1.setMinimumSize(new Dimension(62, 26));
138:                component4.setPreferredSize(new Dimension(41, 26));
139:                component3.setPreferredSize(new Dimension(48, 26));
140:                component2.setPreferredSize(new Dimension(55, 26));
141:                component1.setPreferredSize(new Dimension(62, 26));
142:                component4.setMaximumSize(new Dimension(41, 26));
143:                component3.setMaximumSize(new Dimension(48, 26));
144:                component2.setMaximumSize(new Dimension(55, 26));
145:                component1.setMaximumSize(new Dimension(62, 26));
146:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 10);
147:                container.setLayout(layout);
148:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
149:                container.add(component1);
150:                container.add(component2);
151:                container.add(component3);
152:                container.add(component4);
153:                JDialog window = new JDialog();
154:                window.getContentPane().add(container);
155:                window.pack();
156:                assertEquals("Container's minimum requirements", new Dimension(
157:                        276, 66), layout.minimumLayoutSize(container));
158:                assertEquals("Container's preferred requirements",
159:                        new Dimension(276, 66), layout
160:                                .preferredLayoutSize(container));
161:                assertEquals("Component1 location ", new Point(20, 20),
162:                        component1.getLocation());
163:                assertEquals("Component1 size ", new Dimension(62, 26),
164:                        component1.getSize());
165:                assertEquals("Component2 location ", new Point(92, 20),
166:                        component2.getLocation());
167:                assertEquals("Component2 size ", new Dimension(55, 26),
168:                        component2.getSize());
169:                assertEquals("Component3 location ", new Point(157, 20),
170:                        component3.getLocation());
171:                assertEquals("Component3 size ", new Dimension(48, 26),
172:                        component3.getSize());
173:                assertEquals("Component4 location ", new Point(215, 20),
174:                        component4.getLocation());
175:                assertEquals("Component4 size ", new Dimension(41, 26),
176:                        component4.getSize());
177:                container.setPreferredSize(new Dimension(1000, 100));
178:                window.pack();
179:                assertEquals("Container's minimum requirements", new Dimension(
180:                        276, 66), layout.minimumLayoutSize(container));
181:                assertEquals("Container's preferred requirements",
182:                        new Dimension(276, 66), layout
183:                                .preferredLayoutSize(container));
184:                assertEquals("Component1 location ", new Point(382, 20),
185:                        component1.getLocation());
186:                assertEquals("Component1 size ", new Dimension(62, 26),
187:                        component1.getSize());
188:                assertEquals("Component2 location ", new Point(454, 20),
189:                        component2.getLocation());
190:                assertEquals("Component2 size ", new Dimension(55, 26),
191:                        component2.getSize());
192:                assertEquals("Component3 location ", new Point(519, 20),
193:                        component3.getLocation());
194:                assertEquals("Component3 size ", new Dimension(48, 26),
195:                        component3.getSize());
196:                assertEquals("Component4 location ", new Point(577, 20),
197:                        component4.getLocation());
198:                assertEquals("Component4 size ", new Dimension(41, 26),
199:                        component4.getSize());
200:                layout.setCentersChildren(false);
201:                container.setPreferredSize(new Dimension(1200, 100));
202:                window.pack();
203:                assertEquals("Container's minimum requirements", new Dimension(
204:                        276, 66), layout.minimumLayoutSize(container));
205:                assertEquals("Container's preferred requirements",
206:                        new Dimension(276, 66), layout
207:                                .preferredLayoutSize(container));
208:                assertEquals("Component1 location ", new Point(20, 20),
209:                        component1.getLocation());
210:                assertEquals("Component1 size ", new Dimension(62, 26),
211:                        component1.getSize());
212:                assertEquals("Component2 location ", new Point(390, 20),
213:                        component2.getLocation());
214:                assertEquals("Component2 size ", new Dimension(55, 26),
215:                        component2.getSize());
216:                assertEquals("Component3 location ", new Point(753, 20),
217:                        component3.getLocation());
218:                assertEquals("Component3 size ", new Dimension(48, 26),
219:                        component3.getSize());
220:                assertEquals("Component4 location ", new Point(1109, 20),
221:                        component4.getLocation());
222:                assertEquals("Component4 size ", new Dimension(41, 26),
223:                        component4.getSize());
224:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 30);
225:                container.setLayout(layout);
226:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
227:                container.setPreferredSize(null);
228:                window.pack();
229:                assertEquals("Container's minimum requirements", new Dimension(
230:                        378, 66), layout.minimumLayoutSize(container));
231:                assertEquals("Container's preferred requirements",
232:                        new Dimension(378, 66), layout
233:                                .preferredLayoutSize(container));
234:                int offset = isHarmony() ? 20 : 0;
235:                assertEquals("Component1 location ", new Point(offset + 0, 20),
236:                        component1.getLocation());
237:                assertEquals("Component1 size ", new Dimension(62, 26),
238:                        component1.getSize());
239:                assertEquals("Component2 location ",
240:                        new Point(offset + 92, 20), component2.getLocation());
241:                assertEquals("Component2 size ", new Dimension(62, 26),
242:                        component1.getSize());
243:                assertEquals("Component3 location ",
244:                        new Point(offset + 184, 20), component3.getLocation());
245:                assertEquals("Component3 size ", new Dimension(62, 26),
246:                        component1.getSize());
247:                assertEquals("Component4 location ",
248:                        new Point(offset + 276, 20), component4.getLocation());
249:                assertEquals("Component4 size ", new Dimension(62, 26),
250:                        component1.getSize());
251:            }
252:
253:            public void testMinimumLayoutSize() {
254:                JComponent container = new JPanel();
255:                JComponent component1 = new JPanel();
256:                JComponent component2 = new JPanel();
257:                JComponent component3 = new JPanel();
258:                JComponent component4 = new JPanel();
259:                component1.setMinimumSize(new Dimension(41, 26));
260:                component2.setMinimumSize(new Dimension(48, 26));
261:                component3.setMinimumSize(new Dimension(55, 26));
262:                component4.setMinimumSize(new Dimension(62, 26));
263:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 25);
264:                container.add(component1);
265:                container.add(component2);
266:                assertEquals("Minimum size: ", new Dimension(45, 10), layout
267:                        .minimumLayoutSize(container));
268:                assertEquals("Minimum size: ", new Dimension(45, 10), layout
269:                        .preferredLayoutSize(container));
270:                component1.setMinimumSize(new Dimension(50, 50));
271:                component2.setMinimumSize(new Dimension(70, 120));
272:                component3.setMinimumSize(new Dimension(90, 150));
273:                component4.setMinimumSize(new Dimension(80, 90));
274:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 30);
275:                assertEquals("Minimum size: ", new Dimension(50, 10), layout
276:                        .minimumLayoutSize(container));
277:                container.add(component3);
278:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 40);
279:                assertEquals("Minimum size: ", new Dimension(110, 10), layout
280:                        .minimumLayoutSize(container));
281:                container.add(component4);
282:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 60);
283:                assertEquals("Minimum size: ", new Dimension(220, 10), layout
284:                        .minimumLayoutSize(container));
285:                container = new JPanel();
286:                container.add(component1);
287:                container.add(component2);
288:                component1.setAlignmentX(0.75f);
289:                component2.setAlignmentY(0.75f);
290:                component3.setAlignmentX(0.25f);
291:                component4.setAlignmentY(0.25f);
292:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 10);
293:                assertEquals("Minimum size: ", new Dimension(30, 10), layout
294:                        .minimumLayoutSize(container));
295:                container.add(component3);
296:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 0);
297:                assertEquals("Minimum size: ", new Dimension(30, 10), layout
298:                        .minimumLayoutSize(container));
299:                container.add(component4);
300:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 0);
301:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
302:                assertEquals("Minimum size: ", new Dimension(80, 50), layout
303:                        .minimumLayoutSize(container));
304:            }
305:
306:            public void testPreferredLayoutSize() {
307:                JComponent container = new JPanel();
308:                JComponent component1 = new JPanel();
309:                JComponent component2 = new JPanel();
310:                JComponent component3 = new JPanel();
311:                JComponent component4 = new JPanel();
312:                component1.setPreferredSize(new Dimension(41, 26));
313:                component2.setPreferredSize(new Dimension(48, 26));
314:                component3.setPreferredSize(new Dimension(55, 26));
315:                component4.setPreferredSize(new Dimension(62, 26));
316:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 30);
317:                container.add(component1);
318:                container.add(component2);
319:                assertEquals("Preferred size: ", new Dimension(119, 26), layout
320:                        .preferredLayoutSize(container));
321:                assertEquals("Preferred size: ", new Dimension(119, 26), layout
322:                        .minimumLayoutSize(container));
323:                component1.setPreferredSize(new Dimension(50, 50));
324:                component2.setPreferredSize(new Dimension(70, 120));
325:                component3.setPreferredSize(new Dimension(90, 150));
326:                component4.setPreferredSize(new Dimension(80, 90));
327:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 40);
328:                assertEquals("Preferred size: ", new Dimension(180, 120),
329:                        layout.preferredLayoutSize(container));
330:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 40);
331:                assertEquals("Preferred size: ", new Dimension(160, 120),
332:                        layout.preferredLayoutSize(container));
333:                container.add(component3);
334:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 25);
335:                assertEquals("Preferred size: ", new Dimension(260, 150),
336:                        layout.preferredLayoutSize(container));
337:                layout.setCentersChildren(true);
338:                assertEquals("Preferred size: ", new Dimension(260, 150),
339:                        layout.preferredLayoutSize(container));
340:                container.add(component4);
341:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 20);
342:                assertEquals("Preferred size: ", new Dimension(350, 150),
343:                        layout.preferredLayoutSize(container));
344:                container = new JPanel();
345:                container.add(component1);
346:                container.add(component2);
347:                component1.setAlignmentX(0.75f);
348:                component2.setAlignmentY(0.75f);
349:                component3.setAlignmentX(0.25f);
350:                component4.setAlignmentY(0.25f);
351:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 20);
352:                assertEquals("Preferred size: ", new Dimension(140, 120),
353:                        layout.preferredLayoutSize(container));
354:                container.add(component3);
355:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 20);
356:                assertEquals("Preferred size: ", new Dimension(250, 150),
357:                        layout.preferredLayoutSize(container));
358:                container.add(component4);
359:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 20);
360:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
361:                assertEquals("Preferred size: ", new Dimension(390, 190),
362:                        layout.preferredLayoutSize(container));
363:            }
364:
365:            // Regression for HARMONY-2900
366:            public void testPreferedLayoutSize() {
367:                layout = new BasicOptionPaneUI.ButtonAreaLayout(false, 20);
368:                assertEquals(new Dimension(), layout.preferredLayoutSize(null));
369:                // no exception expected
370:            }
371:
372:            public void testRemoveLayoutComponent() {
373:                Container container = new JPanel();
374:                JComponent component1 = new JPanel();
375:                JComponent component2 = new JPanel();
376:                JComponent component3 = new JPanel();
377:                JComponent component4 = new JPanel();
378:                layout = new BasicOptionPaneUI.ButtonAreaLayout(true, 20);
379:                container.add(component1);
380:                container.add(component2);
381:                container.add(component3);
382:                container.add(component4);
383:                component1.setMinimumSize(new Dimension(50, 50));
384:                component2.setMinimumSize(new Dimension(70, 80));
385:                component3.setMinimumSize(new Dimension(90, 70));
386:                component4.setMinimumSize(new Dimension(80, 120));
387:                assertEquals("Sizes ", new Dimension(100, 10), layout
388:                        .minimumLayoutSize(container));
389:                container.remove(component4);
390:                assertEquals("Sizes ", new Dimension(70, 10), layout
391:                        .minimumLayoutSize(container));
392:                container.add(component4);
393:                layout.removeLayoutComponent(component4);
394:                container.remove(component4);
395:                assertEquals("Sizes ", new Dimension(70, 10), layout
396:                        .minimumLayoutSize(container));
397:                container.remove(component3);
398:                assertEquals("Sizes ", new Dimension(40, 10), layout
399:                        .minimumLayoutSize(container));
400:                container.add(component3);
401:                layout.removeLayoutComponent(component3);
402:                assertEquals("Sizes ", new Dimension(70, 10), layout
403:                        .minimumLayoutSize(container));
404:            }
405:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.