001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: * Created on 01.12.2004
021:
022: */package javax.swing.border;
023:
024: import java.awt.Color;
025: import java.awt.Insets;
026: import javax.swing.JPanel;
027: import javax.swing.SwingTestCase;
028:
029: public class CompoundBorderTest extends SwingTestCase {
030: /*
031: * Class under test for Insets getBorderInsets(Component, Insets)
032: */
033: public void testGetBorderInsetsComponentInsets() {
034: LineBorder border1 = new LineBorder(Color.red, 10, false);
035: LineBorder border2 = new LineBorder(Color.red, 3, false);
036: CompoundBorder border4 = new CompoundBorder(border1, border2);
037: Insets insets = new Insets(1, 1, 1, 1);
038: JPanel panel = new JPanel();
039: panel.setBorder(new LineBorder(Color.black, 10001));
040: border4.getBorderInsets(panel, insets);
041: assertEquals("insets values coincide", 13, insets.top);
042: assertEquals("insets values coincide", 13, insets.left);
043: assertEquals("insets values coincide", 13, insets.right);
044: assertEquals("insets values coincide", 13, insets.bottom);
045: insets = new Insets(1001, 1002, 1003, 1004);
046: panel.setBorder(new LineBorder(Color.black, 100001));
047: Insets newInsets = border4.getBorderInsets(panel, insets);
048: assertEquals("insets values coincide", 13, newInsets.top);
049: assertEquals("insets values coincide", 13, newInsets.left);
050: assertEquals("insets values coincide", 13, newInsets.right);
051: assertEquals("insets values coincide", 13, newInsets.bottom);
052: assertEquals("insets values coincide", 13, insets.top);
053: assertEquals("insets values coincide", 13, insets.left);
054: assertEquals("insets values coincide", 13, insets.right);
055: assertEquals("insets values coincide", 13, insets.bottom);
056: }
057:
058: /*
059: * Class under test for Insets getBorderInsets(Component)
060: */
061: public void testGetBorderInsetsComponent() {
062: LineBorder border1 = new LineBorder(Color.red, 10, false);
063: LineBorder border2 = new LineBorder(Color.red, 3, false);
064: EmptyBorder border3 = new EmptyBorder(101, 102, 103, 104);
065: CompoundBorder border4 = new CompoundBorder(border1, border2);
066: CompoundBorder border5 = new CompoundBorder(border2, border3);
067: CompoundBorder border6 = new CompoundBorder();
068: CompoundBorder border7 = new CompoundBorder(border2, null);
069: CompoundBorder border8 = new CompoundBorder(null, border3);
070: Insets insets1 = new Insets(13, 13, 13, 13);
071: Insets insets2 = new Insets(104, 105, 106, 107);
072: Insets insets3 = new Insets(0, 0, 0, 0);
073: Insets insets4 = new Insets(3, 3, 3, 3);
074: Insets insets5 = new Insets(101, 102, 103, 104);
075: JPanel panel = new JPanel();
076: panel.setBorder(new EmptyBorder(1000, 1001, 1002, 1003));
077: assertEquals("Insets coincide ", insets1, border4
078: .getBorderInsets(null));
079: assertEquals("Insets coincide ", insets1, border4
080: .getBorderInsets(panel));
081: assertEquals("Insets coincide ", insets2, border5
082: .getBorderInsets(null));
083: assertEquals("Insets coincide ", insets2, border5
084: .getBorderInsets(panel));
085: assertEquals("Insets coincide ", insets3, border6
086: .getBorderInsets(null));
087: assertEquals("Insets coincide ", insets3, border6
088: .getBorderInsets(panel));
089: assertEquals("Insets coincide ", insets4, border7
090: .getBorderInsets(null));
091: assertEquals("Insets coincide ", insets4, border7
092: .getBorderInsets(panel));
093: assertEquals("Insets coincide ", insets5, border8
094: .getBorderInsets(null));
095: assertEquals("Insets coincide ", insets5, border8
096: .getBorderInsets(panel));
097: }
098:
099: public void testPaintBorder() {
100: // JPanel panel1 = new JPanel();
101: // JPanel panel2 = new JPanel();
102: // JPanel panel3 = new JPanel();
103: // JPanel panel4 = new JPanel();
104: //
105: // LineBorder border1 = new LineBorder(Color.red, 10, false);
106: // LineBorder border2 = new LineBorder(Color.yellow, 30, true);
107: // CompoundBorder border3 = new CompoundBorder(border1, border2);
108: // CompoundBorder border4 = new CompoundBorder(null, border2);
109: // CompoundBorder border5 = new CompoundBorder(border1, null);
110: // panel2.setBorder(border3);
111: // panel3.setBorder(border4);
112: // panel4.setBorder(border5);
113: // panel2.setPreferredSize(new Dimension(200, 150));
114: // panel3.setPreferredSize(new Dimension(200, 150));
115: // panel4.setPreferredSize(new Dimension(200, 150));
116: //
117: // panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
118: // panel1.add(panel2);
119: // panel1.add(panel3);
120: // panel1.add(panel4);
121: //
122: // JFrame frame = new JFrame();
123: // frame.getContentPane().add(panel1);
124: // frame.pack();
125: // frame.show();
126: // while(!frame.isActive());
127: // while(frame.isActive());
128: }
129:
130: public void testIsBorderOpaque() {
131: LineBorder border1 = new LineBorder(Color.red, 33, false);
132: LineBorder border2 = new LineBorder(Color.red, 33, false);
133: EmptyBorder border3 = new EmptyBorder(1, 1, 1, 1);
134: CompoundBorder border4 = new CompoundBorder(border1, border2);
135: CompoundBorder border5 = new CompoundBorder(border2, border3);
136: CompoundBorder border6 = new CompoundBorder();
137: CompoundBorder border7 = new CompoundBorder(border2, null);
138: CompoundBorder border8 = new CompoundBorder(null, border3);
139: assertTrue("This border is opaque", border4.isBorderOpaque());
140: assertFalse("This border is not opaque", border5
141: .isBorderOpaque());
142: assertTrue("This border is opaque", border6.isBorderOpaque());
143: assertTrue("This border is opaque", border7.isBorderOpaque());
144: assertFalse("This border is not opaque", border8
145: .isBorderOpaque());
146: }
147:
148: /*
149: * Class under test for void CompoundBorder(Border, Border)
150: */
151: public void testCompoundBorderBorderBorder() {
152: LineBorder border1 = new LineBorder(Color.red, 33, false);
153: LineBorder border2 = new LineBorder(Color.red, 33, true);
154: EmptyBorder border3 = new EmptyBorder(1, 1, 1, 1);
155: CompoundBorder border4 = new CompoundBorder(border1, border2);
156: assertSame(border1, border4.getOutsideBorder());
157: assertSame(border2, border4.getInsideBorder());
158: CompoundBorder border5 = new CompoundBorder(border2, border3);
159: assertSame(border2, border5.getOutsideBorder());
160: assertSame(border3, border5.getInsideBorder());
161: CompoundBorder border7 = new CompoundBorder(border2, null);
162: assertSame(border2, border7.getOutsideBorder());
163: assertNull(border7.getInsideBorder());
164: CompoundBorder border8 = new CompoundBorder(null, border3);
165: assertNull(border8.getOutsideBorder());
166: assertSame(border3, border8.getInsideBorder());
167: }
168:
169: /*
170: * Class under test for void CompoundBorder()
171: */
172: public void testCompoundBorder() {
173: CompoundBorder border = new CompoundBorder();
174: assertNull(border.getInsideBorder());
175: assertNull(border.getOutsideBorder());
176: }
177:
178: public void testGetOutsideBorder() {
179: LineBorder border1 = new LineBorder(Color.red, 33, false);
180: LineBorder border2 = new LineBorder(Color.red, 33, true);
181: EmptyBorder border3 = new EmptyBorder(1, 1, 1, 1);
182: CompoundBorder border4 = new CompoundBorder(border1, border2);
183: CompoundBorder border5 = new CompoundBorder(border2, border3);
184: CompoundBorder border6 = new CompoundBorder();
185: CompoundBorder border7 = new CompoundBorder(border2, null);
186: CompoundBorder border8 = new CompoundBorder(null, border3);
187: assertEquals("Borders coincide", border1, border4
188: .getOutsideBorder());
189: assertEquals("Borders coincide", border2, border5
190: .getOutsideBorder());
191: assertNull("Borders coincide", border6.getOutsideBorder());
192: assertEquals("Borders coincide", border2, border7
193: .getOutsideBorder());
194: assertNull("Borders coincide", border8.getOutsideBorder());
195: }
196:
197: public void testGetInsideBorder() {
198: LineBorder border1 = new LineBorder(Color.red, 33, false);
199: LineBorder border2 = new LineBorder(Color.red, 33, true);
200: EmptyBorder border3 = new EmptyBorder(1, 1, 1, 1);
201: CompoundBorder border4 = new CompoundBorder(border1, border2);
202: CompoundBorder border5 = new CompoundBorder(border2, border3);
203: CompoundBorder border6 = new CompoundBorder();
204: CompoundBorder border7 = new CompoundBorder(border2, null);
205: CompoundBorder border8 = new CompoundBorder(null, border3);
206: assertEquals("Borders coincide", border2, border4
207: .getInsideBorder());
208: assertEquals("Borders coincide", border3, border5
209: .getInsideBorder());
210: assertNull("Borders coincide", border6.getInsideBorder());
211: assertNull("Borders coincide", border7.getInsideBorder());
212: assertEquals("Borders coincide", border3, border8
213: .getInsideBorder());
214: }
215:
216: public void testReadWriteObject() throws Exception {
217: LineBorder border1 = new LineBorder(Color.red, 33, false);
218: EmptyBorder border2 = new EmptyBorder(1, 1, 1, 1);
219: CompoundBorder border3 = new CompoundBorder(border1, border2);
220: CompoundBorder border4 = new CompoundBorder();
221: CompoundBorder resurrectedBorder = (CompoundBorder) serializeObject(border3);
222: assertNotNull(resurrectedBorder);
223: assertEquals("Deserialized values coincides", resurrectedBorder
224: .getOutsideBorder().getClass(), border1.getClass());
225: assertEquals("Deserialized values coincides", resurrectedBorder
226: .getInsideBorder().getClass(), border2.getClass());
227: resurrectedBorder = (CompoundBorder) serializeObject(border4);
228: assertNotNull(resurrectedBorder);
229: assertNull("Deserialized values coincides", resurrectedBorder
230: .getOutsideBorder());
231: assertNull("Deserialized values coincides", resurrectedBorder
232: .getInsideBorder());
233: }
234: }
|