KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > MatteBorderExtUnitTest


1 /*
2  * $Id: MatteBorderExtUnitTest.java,v 1.1 2004/07/31 00:03:28 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing;
9
10 import java.awt.Color JavaDoc;
11 import java.awt.Dimension JavaDoc;
12 import java.awt.Point JavaDoc;
13 import javax.swing.Icon JavaDoc;
14 import javax.swing.ImageIcon JavaDoc;
15 import javax.swing.JComponent JavaDoc;
16 import javax.swing.JFrame JavaDoc;
17 import javax.swing.JPanel JavaDoc;
18
19 import org.jdesktop.swing.MatteBorderExt;
20
21 public class MatteBorderExtUnitTest extends junit.framework.TestCase {
22     public MatteBorderExtUnitTest() {
23     super("MatteBorderExt unit test");
24     }
25
26     // XXX placeholder
27
public void testDummy() { }
28
29     public static void main(String JavaDoc[] args) {
30         try {
31         // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
32
}
33         catch (Exception JavaDoc ex) {
34
35         }
36
37         final TestCase[] testCases = createTestCases();
38         if (testCases.length > 0) {
39             // Automatically exit after last window is closed.
40
testCases[testCases.length - 1].frame.setDefaultCloseOperation(
41                 JFrame.EXIT_ON_CLOSE);
42
43             Point JavaDoc location = testCases[0].frame.getLocation();
44
45             for (int i = testCases.length - 1; i >= 0; i--) {
46                 location.translate(30, 30); // stagger frames
47
testCases[i].frame.setTitle("MatteBorderExt Unit Test " + (i +
48                                       1));
49                 testCases[i].frame.setLocation(location);
50                 testCases[i].frame.setVisible(true);
51             }
52         }
53     }
54
55     /**
56      * For unit testing only
57      * @return test cases to be run in sequence
58      */

59     private static TestCase[] createTestCases() {
60         final TestCase[] testCases = new TestCase[] {
61
62             new TestCase() { // 1
63
public JComponent JavaDoc define() {
64                     Class JavaDoc klass = MatteBorderExtUnitTest.class;
65                     Icon JavaDoc[] icons = new Icon JavaDoc[] {
66                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellTopLeft.gif")),
67                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellTop.gif")),
68                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellTopRight.gif")),
69                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellRight.gif")),
70                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellBottomRight.gif")),
71                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellBottom.gif")),
72                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellBottomLeft.gif")),
73                         new ImageIcon JavaDoc(klass.getResource("resources/images/wellLeft.gif")),
74                     };
75
76                     JPanel JavaDoc panel = new JPanel JavaDoc();
77                     panel.setBackground(Color.white);
78                     panel.setBorder(new MatteBorderExt(14, 14, 14, 14, icons));
79                     return panel;
80                 }
81             },
82
83         };
84         return testCases;
85     }
86
87     private static abstract class TestCase {
88
89         public TestCase() {
90             this.frame = wrap(define());
91         }
92
93         public abstract JComponent JavaDoc define();
94
95         public JFrame JavaDoc wrap(JComponent JavaDoc component) {
96             this.component = component;
97             final JFrame JavaDoc frame = new JFrame JavaDoc();
98             frame.getContentPane().add(component);
99             frame.pack();
100             frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
101             return frame;
102         }
103
104         public JComponent JavaDoc component;
105         public final JFrame JavaDoc frame;
106
107     }
108 }
109
Popular Tags