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 Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.Color;
023: import java.awt.Dimension;
024: import java.awt.Font;
025: import java.awt.FontMetrics;
026: import java.awt.Graphics;
027: import java.awt.Insets;
028: import java.awt.Toolkit;
029: import java.awt.image.BufferedImage;
030: import javax.swing.BorderFactory;
031: import javax.swing.DebugGraphics;
032: import javax.swing.Icon;
033: import javax.swing.ImageIcon;
034: import javax.swing.JFrame;
035: import javax.swing.JMenuItem;
036: import javax.swing.SwingTestCase;
037:
038: public class BasicGraphicsUtilsTest extends SwingTestCase {
039: private JFrame frame;
040:
041: private Graphics g;
042:
043: private int x = 0;
044:
045: private final int y = 0;
046:
047: private final int w = 10;
048:
049: private final int h = 7;
050:
051: private final Color shadow = Color.RED;
052:
053: private final Color darkShadow = Color.BLACK;
054:
055: private final Color highlight = Color.GREEN;
056:
057: private final Color lightHighlight = Color.ORANGE;
058:
059: public BasicGraphicsUtilsTest(final String name) {
060: super (name);
061: }
062:
063: @Override
064: protected void setUp() throws Exception {
065: super .setUp();
066: frame = new JFrame();
067: frame.setSize(30, 30);
068: frame.setVisible(true);
069: g = frame.getContentPane().getGraphics();
070: }
071:
072: @Override
073: protected void tearDown() throws Exception {
074: super .tearDown();
075: frame.dispose();
076: }
077:
078: public void testBasicGraphicsUtils() {
079: new BasicGraphicsUtils();
080: }
081:
082: public void testDrawEtchedRect() {
083: Color color = g.getColor();
084: BasicGraphicsUtils.drawEtchedRect(g, x, y, w, h, shadow,
085: darkShadow, highlight, lightHighlight);
086: assertSame(color, g.getColor());
087: }
088:
089: public void testGetEtchedInsets() {
090: assertEquals(new Insets(2, 2, 2, 2), BasicGraphicsUtils
091: .getEtchedInsets());
092: }
093:
094: public void testDrawGroove() {
095: Color color = g.getColor();
096: BasicGraphicsUtils.drawGroove(g, x, y, w, h, shadow, highlight);
097: assertSame(color, g.getColor());
098: }
099:
100: public void testGetGrooveInsets() {
101: assertEquals(new Insets(2, 2, 2, 2), BasicGraphicsUtils
102: .getGrooveInsets());
103: }
104:
105: public void testDrawBezel() {
106: Color color = g.getColor();
107: BasicGraphicsUtils.drawBezel(g, x, y, w, h, true, true, shadow,
108: darkShadow, highlight, lightHighlight);
109: BasicGraphicsUtils.drawBezel(g, x, y, w, h, true, false,
110: shadow, darkShadow, highlight, lightHighlight);
111: BasicGraphicsUtils.drawBezel(g, x, y, w, h, false, true,
112: shadow, darkShadow, highlight, lightHighlight);
113: BasicGraphicsUtils.drawBezel(g, x, y, w, h, false, false,
114: shadow, darkShadow, highlight, lightHighlight);
115: assertSame(color, g.getColor());
116: }
117:
118: public void testDrawLoweredBezel() {
119: Color color = g.getColor();
120: BasicGraphicsUtils.drawLoweredBezel(g, x, y, w, h, shadow,
121: darkShadow, highlight, lightHighlight);
122: if (isHarmony()) {
123: assertSame(color, g.getColor());
124: }
125: }
126:
127: public void testDrawString() {
128: // TODO: implement
129: }
130:
131: public void testDrawStringUnderlineCharAt() {
132: // TODO: implement
133: }
134:
135: public void testDrawDashedRect() {
136: g = new DebugGraphics(g);
137: Color color = g.getColor();
138: BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
139: assertSame(color, g.getColor());
140: }
141:
142: public void testGetPreferredButtonSize() {
143: Icon icon = new ImageIcon(new BufferedImage(10, 20,
144: BufferedImage.TYPE_INT_RGB));
145: JMenuItem item = new JMenuItem() {
146: private static final long serialVersionUID = 1L;
147:
148: @SuppressWarnings("deprecation")
149: @Override
150: public FontMetrics getFontMetrics(Font font) {
151: return Toolkit.getDefaultToolkit().getFontMetrics(font);
152: }
153: };
154: item.setBorder(BorderFactory.createEmptyBorder(10, 20, 30, 40));
155: item.setIcon(icon);
156: assertEquals(new Dimension(70, 60), BasicGraphicsUtils
157: .getPreferredButtonSize(item, 3));
158: }
159: }
|