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;
021:
022: import java.awt.Color;
023: import java.awt.Component;
024: import java.awt.Font;
025: import java.awt.Graphics;
026: import java.awt.Insets;
027: import javax.swing.Icon;
028: import javax.swing.JComponent;
029: import javax.swing.SwingTestCase;
030:
031: public class UIResourceTest extends SwingTestCase {
032: public void testIconUIResource() {
033: Icon imageIcon = new Icon() {
034: public void paintIcon(final Component c, final Graphics g,
035: final int x, final int y) {
036: }
037:
038: public int getIconWidth() {
039: return 0;
040: }
041:
042: public int getIconHeight() {
043: return 0;
044: }
045: };
046: IconUIResource icon = new IconUIResource(imageIcon);
047: assertEquals(imageIcon.getIconHeight(), icon.getIconHeight());
048: assertEquals(imageIcon.getIconWidth(), icon.getIconWidth());
049: }
050:
051: public void testNullDelegate() {
052: testExceptionalCase(new IllegalArgumentCase() {
053: @Override
054: public void exceptionalAction() throws Exception {
055: new BorderUIResource(null);
056: }
057: });
058: testExceptionalCase(new IllegalArgumentCase() {
059: @Override
060: public void exceptionalAction() throws Exception {
061: new IconUIResource(null);
062: }
063: });
064: }
065:
066: public void testBorderUIResourceBlackLine() {
067: assertNotNull(BorderUIResource.getBlackLineBorderUIResource());
068: assertTrue(BorderUIResource.getBlackLineBorderUIResource() instanceof BorderUIResource.LineBorderUIResource);
069: assertTrue(BorderUIResource.getBlackLineBorderUIResource() == BorderUIResource
070: .getBlackLineBorderUIResource());
071: assertNotNull(BorderUIResource.getBlackLineBorderUIResource());
072: BorderUIResource.LineBorderUIResource border = (BorderUIResource.LineBorderUIResource) BorderUIResource
073: .getBlackLineBorderUIResource();
074: assertFalse(border.getRoundedCorners());
075: assertTrue(border.isBorderOpaque());
076: assertEquals(new Insets(1, 1, 1, 1), border
077: .getBorderInsets(newJComponent()));
078: assertEquals(new Color(0, 0, 0), border.getLineColor());
079: assertEquals(1, border.getThickness());
080: }
081:
082: public void testBorderUIResourceEtched() {
083: assertNotNull(BorderUIResource.getEtchedBorderUIResource());
084: assertTrue(BorderUIResource.getEtchedBorderUIResource() instanceof BorderUIResource.EtchedBorderUIResource);
085: assertTrue(BorderUIResource.getEtchedBorderUIResource() == BorderUIResource
086: .getEtchedBorderUIResource());
087: assertNotNull(BorderUIResource.getEtchedBorderUIResource());
088: BorderUIResource.EtchedBorderUIResource border = (BorderUIResource.EtchedBorderUIResource) BorderUIResource
089: .getEtchedBorderUIResource();
090: assertTrue(border.isBorderOpaque());
091: assertEquals(new Insets(2, 2, 2, 2), border
092: .getBorderInsets(newJComponent()));
093: assertEquals(1, border.getEtchType());
094: assertNull(border.getHighlightColor());
095: assertNull(border.getShadowColor());
096: }
097:
098: public void testBorderUIResourceLoweredBevel() {
099: assertNotNull(BorderUIResource
100: .getLoweredBevelBorderUIResource());
101: assertTrue(BorderUIResource.getLoweredBevelBorderUIResource() instanceof BorderUIResource.BevelBorderUIResource);
102: assertTrue(BorderUIResource.getLoweredBevelBorderUIResource() == BorderUIResource
103: .getLoweredBevelBorderUIResource());
104: checkBevelBorderAttrs(
105: (BorderUIResource.BevelBorderUIResource) BorderUIResource
106: .getLoweredBevelBorderUIResource(), 1);
107: }
108:
109: public void testBorderUIResourceRaisedBevel() {
110: assertNotNull(BorderUIResource.getRaisedBevelBorderUIResource());
111: assertTrue(BorderUIResource.getRaisedBevelBorderUIResource() instanceof BorderUIResource.BevelBorderUIResource);
112: assertTrue(BorderUIResource.getRaisedBevelBorderUIResource() == BorderUIResource
113: .getRaisedBevelBorderUIResource());
114: checkBevelBorderAttrs(
115: (BorderUIResource.BevelBorderUIResource) BorderUIResource
116: .getRaisedBevelBorderUIResource(), 0);
117: }
118:
119: public void testColorUIResource() {
120: Color testColor = new Color(1, 2, 3);
121: ColorUIResource c = new ColorUIResource(testColor);
122: assertEquals(testColor.getRGB(), c.getRGB());
123: assertEquals(testColor.getRed(), c.getRed());
124: assertEquals(testColor.getGreen(), c.getGreen());
125: assertEquals(testColor.getBlue(), c.getBlue());
126: assertEquals(testColor.getAlpha(), c.getAlpha());
127: }
128:
129: public void testDimensionUIResource() {
130: DimensionUIResource d = new DimensionUIResource(1, 2);
131: assertTrue(1 == d.getWidth());
132: assertTrue(2 == d.getHeight());
133: }
134:
135: public void testFontUIResource() {
136: Font font = new Font("Dialog", Font.BOLD, 1);
137: FontUIResource f = new FontUIResource(font);
138: assertEquals("Dialog", f.getName());
139: assertEquals(1, f.getSize());
140: assertEquals(Font.BOLD, f.getStyle());
141: }
142:
143: public void testInsetsUIResource() {
144: InsetsUIResource ins = new InsetsUIResource(1, 2, 3, 4);
145: assertEquals(1, ins.top);
146: assertEquals(2, ins.left);
147: assertEquals(3, ins.bottom);
148: assertEquals(4, ins.right);
149: }
150:
151: private void checkBevelBorderAttrs(
152: final BorderUIResource.BevelBorderUIResource border,
153: final int type) {
154: assertNotNull(border);
155: assertTrue(border.isBorderOpaque());
156: assertEquals(type, border.getBevelType());
157: assertEquals(new Insets(2, 2, 2, 2), border
158: .getBorderInsets(newJComponent()));
159: assertNull(border.getHighlightInnerColor());
160: assertNull(border.getHighlightOuterColor());
161: assertNull(border.getShadowInnerColor());
162: assertNull(border.getShadowOuterColor());
163: }
164:
165: private JComponent newJComponent() {
166: return new JComponent() {
167: private static final long serialVersionUID = 1L;
168: };
169: }
170: }
|