01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Evgeniya G. Maenkova
19: * @version $Revision$
20: */package javax.swing.text;
21:
22: import java.awt.FontMetrics;
23: import javax.swing.JFrame;
24: import javax.swing.JTextField;
25: import javax.swing.SwingTestCase;
26: import javax.swing.plaf.basic.BasicTextUI;
27:
28: public class FieldViewTest extends SwingTestCase {
29: JFrame jf;
30:
31: JTextField jtf;
32:
33: FieldView fv;
34:
35: @Override
36: protected void setUp() throws Exception {
37: super .setUp();
38: jf = new JFrame();
39: jtf = new JTextField("JTextField for FieldView testing");
40: jf.getContentPane().add(jtf);
41: fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf)
42: .getView(0);
43: jf.setSize(200, 100);
44: jf.pack();
45: }
46:
47: @Override
48: protected void tearDown() throws Exception {
49: jf.dispose();
50: super .tearDown();
51: }
52:
53: public void testGetPreferredSpan() {
54: FontMetrics fm = fv.getFontMetrics();
55: assertEquals(fm.getHeight(), (int) fv
56: .getPreferredSpan(View.Y_AXIS));
57: assertEquals(fm.stringWidth(jtf.getText()), (int) fv
58: .getPreferredSpan(View.X_AXIS));
59: jtf.setFont(new java.awt.Font("SimSun", 0, 12));
60: fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf)
61: .getView(0);
62: fm = jtf.getFontMetrics(jtf.getFont());
63: assertEquals(fm.stringWidth(jtf.getText()), (int) fv
64: .getPreferredSpan(View.X_AXIS));
65: }
66:
67: public void testGetResizeWeight() {
68: assertEquals(1, fv.getResizeWeight(View.X_AXIS));
69: assertEquals(0, fv.getResizeWeight(View.Y_AXIS));
70: assertEquals(0, fv.getResizeWeight(5000));
71: }
72:
73: public void testGetFontMetrics() {
74: assertEquals(jtf.getFontMetrics(jtf.getFont()), fv
75: .getFontMetrics());
76: jtf.setFont(new java.awt.Font("SimSun", 0, 12));
77: fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf)
78: .getView(0);
79: assertEquals(jtf.getFontMetrics(jtf.getFont()), fv
80: .getFontMetrics());
81: }
82: }
|