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 Evgeniya G. Maenkova
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.Container;
023: import java.awt.GridLayout;
024: import javax.swing.JFrame;
025: import javax.swing.JTextField;
026: import javax.swing.SwingTestCase;
027: import javax.swing.plaf.ComponentUI;
028: import javax.swing.text.Element;
029: import javax.swing.text.FieldView;
030: import javax.swing.text.View;
031:
032: public class BasicTextFieldUITest extends SwingTestCase {
033: JFrame jf;
034:
035: JTextField jtf;
036:
037: JTextField jtfBidi;
038:
039: BasicTextFieldUI ui;
040:
041: final String S_RTL = "\u05dc" + "\u05dc" + "\u05dc" + "\u05dc";
042:
043: final String S_LTR = "aaaa";
044:
045: @Override
046: protected void setUp() throws Exception {
047: super .setUp();
048: jf = new JFrame();
049: jtf = new JTextField("JTextField \n JTextField");
050: jtfBidi = new JTextField(S_LTR + S_RTL + "\n" + S_LTR);
051: ui = new BasicTextFieldUI();
052: jtf.setUI(ui);
053: jtfBidi.setUI(new BasicTextFieldUI());
054: Container container = jf.getContentPane();
055: container.setLayout(new GridLayout(2, 1, 4, 4));
056: container.add(jtf);
057: container.add(jtfBidi);
058: jf.setSize(200, 200);
059: jf.pack();
060: }
061:
062: @Override
063: protected void tearDown() throws Exception {
064: jf.dispose();
065: super .tearDown();
066: }
067:
068: public void testCreateElement() {
069: Element element = jtf.getDocument().getDefaultRootElement();
070: View view = ui.create(element);
071: assertTrue(view instanceof FieldView);
072: element = element.getElement(0);
073: view = ui.create(element);
074: assertTrue(view instanceof FieldView);
075: /* no view support for bidi text
076: ui = (BasicTextFieldUI)jtfBidi.getUI();
077: element = jtfBidi.getDocument().getDefaultRootElement();
078: view = ui.create(element);
079: assertFalse(view instanceof FieldView);
080: */
081: }
082:
083: public void testGetPropertyPrefix() {
084: assertEquals("TextField", ui.getPropertyPrefix());
085: }
086:
087: public void testInstallUIJComponent() {
088: }
089:
090: public void testPropertyChange() {
091: }
092:
093: public void testBasicTextFieldUI() {
094: }
095:
096: public void testCreateUIJComponent() {
097: ComponentUI componentUI = BasicTextFieldUI.createUI(null);
098: assertTrue(componentUI instanceof BasicTextFieldUI);
099: assertNotSame(BasicTextFieldUI.createUI(jtf), componentUI);
100: }
101: }
|