Source Code Cross Referenced for MetalBordersTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » metal » 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.metal 
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 Sergey Burlak
019:         * @version $Revision$
020:         */package javax.swing.plaf.metal;
021:
022:        import java.awt.Insets;
023:        import javax.swing.JButton;
024:        import javax.swing.JComponent;
025:        import javax.swing.JToolBar;
026:        import javax.swing.SwingConstants;
027:        import javax.swing.SwingTestCase;
028:        import javax.swing.border.AbstractBorder;
029:        import javax.swing.border.LineBorder;
030:        import javax.swing.border.MatteBorder;
031:        import javax.swing.plaf.BorderUIResource;
032:        import javax.swing.plaf.ColorUIResource;
033:        import javax.swing.plaf.basic.BasicBorders;
034:        import javax.swing.plaf.metal.MetalBorders.ButtonBorder;
035:        import javax.swing.plaf.metal.MetalBorders.MenuBarBorder;
036:        import javax.swing.plaf.metal.MetalBorders.MenuItemBorder;
037:        import javax.swing.plaf.metal.MetalBorders.PopupMenuBorder;
038:
039:        public class MetalBordersTest extends SwingTestCase {
040:            public void testButtonBorderClass() {
041:                MetalBorders.ButtonBorder border = new MetalBorders.ButtonBorder();
042:                assertFalse(border.isBorderOpaque());
043:                assertEquals(new Insets(3, 3, 3, 3), border
044:                        .getBorderInsets(newJComponent()));
045:                assertSame(ButtonBorder.borderInsets, border
046:                        .getBorderInsets(newJComponent()));
047:                checkInsets(border);
048:            }
049:
050:            public void testFlush3DBorderClass() {
051:                MetalBorders.Flush3DBorder border = new MetalBorders.Flush3DBorder();
052:                assertFalse(border.isBorderOpaque());
053:                assertEquals(new Insets(2, 2, 2, 2), border
054:                        .getBorderInsets(newJComponent()));
055:                checkInsets(border);
056:            }
057:
058:            public void testInternalFrameBorderClass() {
059:                MetalBorders.InternalFrameBorder border = new MetalBorders.InternalFrameBorder();
060:                assertFalse(border.isBorderOpaque());
061:                assertEquals(new Insets(5, 5, 5, 5), border
062:                        .getBorderInsets(newJComponent()));
063:                checkInsets(border);
064:            }
065:
066:            public void testFrameBorderClass() {
067:                MetalBorders.FrameBorder border = new MetalBorders.FrameBorder();
068:                assertFalse(border.isBorderOpaque());
069:                assertEquals(new Insets(5, 5, 5, 5), border
070:                        .getBorderInsets(newJComponent()));
071:                checkInsets(border);
072:            }
073:
074:            public void testMenuBarBorderClass() {
075:                MetalBorders.MenuBarBorder border = new MetalBorders.MenuBarBorder();
076:                assertFalse(border.isBorderOpaque());
077:                if (isHarmony()) {
078:                    assertEquals(new Insets(1, 0, 1, 0), border
079:                            .getBorderInsets(newJComponent()));
080:                    assertSame(MenuBarBorder.borderInsets, border
081:                            .getBorderInsets(newJComponent()));
082:                } else {
083:                    assertEquals(new Insets(1, 0, 1, 0),
084:                            MenuBarBorder.borderInsets);
085:                    assertNotSame(border.getBorderInsets(newJComponent()),
086:                            border.getBorderInsets(newJComponent()));
087:                    assertEquals(new Insets(0, 0, 2, 0), border
088:                            .getBorderInsets(newJComponent()));
089:                    assertEquals(border.getBorderInsets(newJComponent()),
090:                            border.getBorderInsets(newJComponent(), new Insets(
091:                                    0, 0, 0, 0)));
092:                }
093:                checkInsets(border);
094:            }
095:
096:            public void testMenuItemBorder() {
097:                MetalBorders.MenuItemBorder border = new MetalBorders.MenuItemBorder();
098:                assertFalse(border.isBorderOpaque());
099:                assertEquals(new Insets(2, 2, 2, 2),
100:                        MenuItemBorder.borderInsets);
101:                assertTrue(MenuItemBorder.borderInsets == border
102:                        .getBorderInsets(newJComponent()));
103:                checkInsets(border);
104:            }
105:
106:            public void testOptionDialogBorderClass() {
107:                MetalBorders.OptionDialogBorder border = new MetalBorders.OptionDialogBorder();
108:                assertFalse(border.isBorderOpaque());
109:                assertEquals(new Insets(3, 3, 3, 3), border
110:                        .getBorderInsets(newJComponent()));
111:                checkInsets(border);
112:            }
113:
114:            public void testPaletteBorderClass() {
115:                MetalBorders.PaletteBorder border = new MetalBorders.PaletteBorder();
116:                assertFalse(border.isBorderOpaque());
117:                assertEquals(new Insets(1, 1, 1, 1), border
118:                        .getBorderInsets(newJComponent()));
119:                checkInsets(border);
120:            }
121:
122:            public void testPopupMenuBorderClass() {
123:                MetalBorders.PopupMenuBorder border = new MetalBorders.PopupMenuBorder();
124:                assertFalse(border.isBorderOpaque());
125:                if (isHarmony()) {
126:                    assertEquals(new Insets(2, 2, 1, 1),
127:                            PopupMenuBorder.borderInsets);
128:                } else {
129:                    assertEquals(new Insets(3, 1, 2, 1),
130:                            PopupMenuBorder.borderInsets);
131:                }
132:                assertTrue(PopupMenuBorder.borderInsets == border
133:                        .getBorderInsets(newJComponent()));
134:                checkInsets(border);
135:            }
136:
137:            public void testRolloverButtonBorderClass() {
138:                MetalBorders.RolloverButtonBorder border = new MetalBorders.RolloverButtonBorder();
139:                assertFalse(border.isBorderOpaque());
140:                assertTrue(ButtonBorder.borderInsets == border
141:                        .getBorderInsets(newJComponent()));
142:                checkInsets(border);
143:            }
144:
145:            public void testScrollPaneBorderClass() {
146:                MetalBorders.ScrollPaneBorder border = new MetalBorders.ScrollPaneBorder();
147:                assertFalse(border.isBorderOpaque());
148:                assertEquals(new Insets(1, 1, 2, 2), border
149:                        .getBorderInsets(newJComponent()));
150:                assertSame(border.getBorderInsets(newJComponent()), border
151:                        .getBorderInsets(newJComponent()));
152:                Insets ins = new Insets(0, 1, 0, 2);
153:                border.getBorderInsets(newJComponent(), ins);
154:                assertEquals(ins, new Insets(0, 0, 0, 0));
155:            }
156:
157:            public void testTableHeaderBorderClass() {
158:                MetalBorders.TableHeaderBorder border = new MetalBorders.TableHeaderBorder();
159:                assertFalse(border.isBorderOpaque());
160:                assertEquals(new Insets(2, 2, 2, 0), border.editorBorderInsets);
161:                assertTrue(border.editorBorderInsets == border
162:                        .getBorderInsets(newJComponent()));
163:                Insets ins = new Insets(0, 1, 0, 2);
164:                border.getBorderInsets(newJComponent(), ins);
165:                assertEquals(ins, new Insets(0, 0, 0, 0));
166:            }
167:
168:            public void testTextFieldBorderClass() {
169:                MetalBorders.TextFieldBorder border = new MetalBorders.TextFieldBorder();
170:                assertFalse(border.isBorderOpaque());
171:                assertEquals(new Insets(2, 2, 2, 2), border
172:                        .getBorderInsets(newJComponent()));
173:                checkInsets(border);
174:            }
175:
176:            public void testToggleButtonBorderClass() {
177:                MetalBorders.ToggleButtonBorder border = new MetalBorders.ToggleButtonBorder();
178:                assertFalse(border.isBorderOpaque());
179:                assertTrue(ButtonBorder.borderInsets == border
180:                        .getBorderInsets(newJComponent()));
181:                checkInsets(border);
182:            }
183:
184:            public void testToolBarBorderClass() {
185:                JToolBar testToolBar = new JToolBar();
186:                MetalBorders.ToolBarBorder border = new MetalBorders.ToolBarBorder();
187:                assertFalse(border.isBorderOpaque());
188:                if (isHarmony()) {
189:                    assertEquals(new Insets(2, 16, 2, 2), border
190:                            .getBorderInsets(testToolBar));
191:                } else {
192:                    assertEquals(new Insets(1, 16, 3, 2), border
193:                            .getBorderInsets(testToolBar));
194:                }
195:                testToolBar.setOrientation(SwingConstants.VERTICAL);
196:                if (isHarmony()) {
197:                    assertEquals(new Insets(16, 2, 2, 2), border
198:                            .getBorderInsets(testToolBar));
199:                } else {
200:                    assertEquals(new Insets(16, 2, 3, 2), border
201:                            .getBorderInsets(testToolBar));
202:                }
203:                testToolBar.setFloatable(false);
204:                if (isHarmony()) {
205:                    assertEquals(new Insets(2, 2, 2, 2), border
206:                            .getBorderInsets(testToolBar));
207:                } else {
208:                    assertEquals(new Insets(1, 2, 3, 2), border
209:                            .getBorderInsets(testToolBar));
210:                }
211:                testToolBar.setOrientation(SwingConstants.HORIZONTAL);
212:                if (isHarmony()) {
213:                    assertEquals(new Insets(2, 2, 2, 2), border
214:                            .getBorderInsets(testToolBar));
215:                } else {
216:                    assertEquals(new Insets(1, 2, 3, 2), border
217:                            .getBorderInsets(testToolBar));
218:                }
219:                try {
220:                    border.getBorderInsets(new JButton());
221:                    fail("should throw ClassCastException");
222:                } catch (ClassCastException e) {
223:                    // Expected
224:                }
225:                checkInsets(border, testToolBar);
226:            }
227:
228:            public void testGetToggleButtonBorder() {
229:                JComponent testButton = newJComponent();
230:                assertTrue(MetalBorders.getToggleButtonBorder() instanceof  BorderUIResource.CompoundBorderUIResource);
231:                BorderUIResource.CompoundBorderUIResource border = (BorderUIResource.CompoundBorderUIResource) MetalBorders
232:                        .getToggleButtonBorder();
233:                assertTrue(border.getInsideBorder() instanceof  BasicBorders.MarginBorder);
234:                BasicBorders.MarginBorder insideBorder = (BasicBorders.MarginBorder) border
235:                        .getInsideBorder();
236:                assertTrue(border.getOutsideBorder() instanceof  MetalBorders.ToggleButtonBorder);
237:                MetalBorders.ToggleButtonBorder outsideBorder = (MetalBorders.ToggleButtonBorder) border
238:                        .getOutsideBorder();
239:                //        assertEquals(new Insets(2, 14, 2, 14), insideBorder.getBorderInsets(testButton));
240:                assertEquals(new Insets(3, 3, 3, 3), outsideBorder
241:                        .getBorderInsets(testButton));
242:                assertFalse(insideBorder.isBorderOpaque());
243:                assertFalse(outsideBorder.isBorderOpaque());
244:            }
245:
246:            public void testGetTextFieldBorder() {
247:                JComponent testButton = newJComponent();
248:                assertTrue(MetalBorders.getTextFieldBorder() instanceof  BorderUIResource.CompoundBorderUIResource);
249:                BorderUIResource.CompoundBorderUIResource border = (BorderUIResource.CompoundBorderUIResource) MetalBorders
250:                        .getTextFieldBorder();
251:                assertTrue(border.getInsideBorder() instanceof  BasicBorders.MarginBorder);
252:                BasicBorders.MarginBorder insideBorder = (BasicBorders.MarginBorder) border
253:                        .getInsideBorder();
254:                assertTrue(border.getOutsideBorder() instanceof  MetalBorders.TextFieldBorder);
255:                MetalBorders.TextFieldBorder outsideBorder = (MetalBorders.TextFieldBorder) border
256:                        .getOutsideBorder();
257:                //        assertEquals(new Insets(2, 14, 2, 14), insideBorder.getBorderInsets(testButton));
258:                assertEquals(new Insets(2, 2, 2, 2), outsideBorder
259:                        .getBorderInsets(testButton));
260:                assertFalse(insideBorder.isBorderOpaque());
261:                assertFalse(outsideBorder.isBorderOpaque());
262:            }
263:
264:            public void testGetTextBorder() {
265:                JComponent testButton = newJComponent();
266:                assertTrue(MetalBorders.getTextBorder() instanceof  BorderUIResource.CompoundBorderUIResource);
267:                BorderUIResource.CompoundBorderUIResource border = (BorderUIResource.CompoundBorderUIResource) MetalBorders
268:                        .getTextBorder();
269:                assertTrue(border.getInsideBorder() instanceof  BasicBorders.MarginBorder);
270:                BasicBorders.MarginBorder insideBorder = (BasicBorders.MarginBorder) border
271:                        .getInsideBorder();
272:                assertTrue(border.getOutsideBorder() instanceof  MetalBorders.Flush3DBorder);
273:                MetalBorders.Flush3DBorder outsideBorder = (MetalBorders.Flush3DBorder) border
274:                        .getOutsideBorder();
275:                //        assertEquals(new Insets(2, 14, 2, 14), insideBorder.getBorderInsets(testButton));
276:                assertEquals(new Insets(2, 2, 2, 2), outsideBorder
277:                        .getBorderInsets(testButton));
278:                assertFalse(insideBorder.isBorderOpaque());
279:                assertFalse(outsideBorder.isBorderOpaque());
280:            }
281:
282:            public void testGetDesktopIconBorder() {
283:                JComponent testButton = newJComponent();
284:                assertTrue(MetalBorders.getDesktopIconBorder() instanceof  BorderUIResource.CompoundBorderUIResource);
285:                BorderUIResource.CompoundBorderUIResource border = (BorderUIResource.CompoundBorderUIResource) MetalBorders
286:                        .getDesktopIconBorder();
287:                assertTrue(border.getInsideBorder() instanceof  MatteBorder);
288:                MatteBorder insideBorder = (MatteBorder) border
289:                        .getInsideBorder();
290:                assertTrue(border.getOutsideBorder() instanceof  LineBorder);
291:                LineBorder outsideBorder = (LineBorder) border
292:                        .getOutsideBorder();
293:                assertEquals(new Insets(2, 2, 1, 2), insideBorder
294:                        .getBorderInsets(testButton));
295:                assertEquals(new Insets(1, 1, 1, 1), outsideBorder
296:                        .getBorderInsets(testButton));
297:                assertTrue(insideBorder.isBorderOpaque());
298:                assertEquals(new ColorUIResource(238, 238, 238), insideBorder
299:                        .getMatteColor());
300:                assertFalse(outsideBorder.getRoundedCorners());
301:                assertTrue(outsideBorder.isBorderOpaque());
302:                assertEquals(new ColorUIResource(122, 138, 153), outsideBorder
303:                        .getLineColor());
304:                assertEquals(1, outsideBorder.getThickness());
305:            }
306:
307:            public void testGetButtonBorder() {
308:                JComponent testButton = newJComponent();
309:                assertTrue(MetalBorders.getButtonBorder() instanceof  BorderUIResource.CompoundBorderUIResource);
310:                BorderUIResource.CompoundBorderUIResource border = (BorderUIResource.CompoundBorderUIResource) MetalBorders
311:                        .getButtonBorder();
312:                assertTrue(border.getInsideBorder() instanceof  BasicBorders.MarginBorder);
313:                assertTrue(border.getOutsideBorder() instanceof  MetalBorders.ButtonBorder);
314:                MetalBorders.ButtonBorder outsideBorder = (MetalBorders.ButtonBorder) border
315:                        .getOutsideBorder();
316:                //        assertEquals(new Insets(2, 14, 2, 14), insideBorder.getBorderInsets(testButton));
317:                assertEquals(new Insets(3, 3, 3, 3), outsideBorder
318:                        .getBorderInsets(testButton));
319:                assertTrue(ButtonBorder.borderInsets == outsideBorder
320:                        .getBorderInsets(testButton));
321:                assertFalse(outsideBorder.isBorderOpaque());
322:            }
323:
324:            public void testDialogBorder() throws Exception {
325:                MetalBorders.DialogBorder border = new MetalBorders.DialogBorder();
326:                assertFalse(border.isBorderOpaque());
327:                assertEquals(new Insets(5, 5, 5, 5), border
328:                        .getBorderInsets(newJComponent()));
329:                checkInsets(border);
330:            }
331:
332:            public void testQuestionDialogBorder() throws Exception {
333:                MetalBorders.DialogBorder border = new MetalBorders.DialogBorder();
334:                assertFalse(border.isBorderOpaque());
335:                assertEquals(new Insets(5, 5, 5, 5), border
336:                        .getBorderInsets(newJComponent()));
337:                checkInsets(border);
338:            }
339:
340:            public void testWarningDialogBorder() throws Exception {
341:                MetalBorders.DialogBorder border = new MetalBorders.DialogBorder();
342:                assertFalse(border.isBorderOpaque());
343:                assertEquals(new Insets(5, 5, 5, 5), border
344:                        .getBorderInsets(newJComponent()));
345:                checkInsets(border);
346:            }
347:
348:            public void testErrorDialogBorder() throws Exception {
349:                MetalBorders.DialogBorder border = new MetalBorders.DialogBorder();
350:                assertFalse(border.isBorderOpaque());
351:                assertEquals(new Insets(5, 5, 5, 5), border
352:                        .getBorderInsets(newJComponent()));
353:                checkInsets(border);
354:            }
355:
356:            private void checkInsets(final AbstractBorder border) {
357:                checkInsets(border, newJComponent());
358:            }
359:
360:            private void checkInsets(final AbstractBorder border,
361:                    final JComponent c) {
362:                Insets ins = new Insets(100, 100, 100, 100);
363:                border.getBorderInsets(c, ins);
364:                assertEquals(border.getBorderInsets(c), ins);
365:            }
366:
367:            private JComponent newJComponent() {
368:                return new JComponent() {
369:                    private static final long serialVersionUID = 1L;
370:                };
371:            }
372:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.