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.JTextArea;
026: import javax.swing.SwingTestCase;
027: import javax.swing.UIManager;
028: import javax.swing.plaf.ComponentUI;
029: import javax.swing.text.Document;
030: import javax.swing.text.Element;
031: import javax.swing.text.PlainView;
032: import javax.swing.text.WrappedPlainView;
033: import junit.framework.AssertionFailedError;
034:
035: public class BasicTextAreaUITest extends SwingTestCase {
036: JFrame jf;
037:
038: JTextArea jta;
039:
040: JTextArea bidiJta;
041:
042: String sLTR = "aaaa";
043:
044: String sRTL = "\u05dc" + "\u05dc" + "\u05dc" + "\u05dc";
045:
046: String content = "Edison accumul\tator, Edison base: Edison battery"
047: + " Edison cap, \tEdison effect\n"
048: + "Edison screw, Edison screw cap, Edison screw \n"
049: + "holder, Edison screw lampholder, Edison screw "
050: + "plug\n"
051: + "Edison screw terminal, Edison storage battery"
052: + "Edison storage \t\tcell";
053:
054: String bidiContent = sLTR + sRTL + sRTL + " \t" + sLTR + sRTL
055: + sLTR + "\n" + sRTL + "." + sLTR + sRTL + "\t" + sRTL
056: + "\n" + sLTR + sLTR + sRTL + sRTL + sRTL + sLTR + sLTR
057: + sLTR + sRTL + sLTR + sRTL + sLTR;
058:
059: AssertionFailedError afe[];
060:
061: int i;
062:
063: @Override
064: protected void setUp() throws Exception {
065: super .setUp();
066: afe = new AssertionFailedError[50];
067: i = 0;
068: UIManager
069: .put("TextAreaUI", "javax.swing.plaf.basic.TextAreaUI");
070: jta = new JTextArea(content);
071: bidiJta = new JTextArea(bidiContent);
072: jf = new JFrame();
073: Container cont = jf.getContentPane();
074: cont.setLayout(new GridLayout(1, 2, 4, 4));
075: cont.add(jta);
076: cont.add(bidiJta);
077: jf.setLocation(200, 300);
078: jf.setSize(350, 400);
079: jf.pack();
080: }
081:
082: @Override
083: protected void tearDown() throws Exception {
084: jf.dispose();
085: UIManager.put("TextAreaUI",
086: "javax.swing.plaf.basic.BasicTextAreaUI");
087: super .tearDown();
088: }
089:
090: // TODO add test for bidirectional text (after creation PlainViewi18n)
091: public void testCreateElement() throws Exception {
092: Document doc = jta.getDocument();
093: Element elem = doc.getDefaultRootElement();
094: BasicTextUI ui = (BasicTextUI) jta.getUI();
095: assertTrue(ui.create(elem) instanceof PlainView);
096: jta.setLineWrap(true);
097: assertTrue(ui.create(elem) instanceof WrappedPlainView);
098: jta.setLineWrap(false);
099: elem = elem.getElement(0);
100: assertTrue(ui.create(elem) instanceof PlainView);
101: jta.setLineWrap(true);
102: assertTrue(ui.create(elem) instanceof WrappedPlainView);
103:
104: try {
105: new BasicTextAreaUI().create(null);
106: fail("NPE should be thrown");
107: } catch (NullPointerException npe) {
108: // PASSED
109: }
110: }
111:
112: public void testGetPropertyPrefix() {
113: assertEquals("TextArea", ((BasicTextAreaUI) jta.getUI())
114: .getPropertyPrefix());
115: assertEquals("TextArea", ((BasicTextAreaUI) bidiJta.getUI())
116: .getPropertyPrefix());
117: }
118:
119: public void testPropertyChange() throws Exception {
120: TextAreaUI ui = (TextAreaUI) jta.getUI();
121: ui.flagModelChanged = false;
122: jta.setLineWrap(true);
123: assertTrue(ui.flagModelChanged);
124: ui.flagModelChanged = false;
125: jta.setLineWrap(false);
126: assertTrue(ui.flagModelChanged);
127: ui.flagModelChanged = false;
128: jta.setWrapStyleWord(true);
129: assertTrue(ui.flagModelChanged);
130: ui.flagModelChanged = false;
131: jta.setWrapStyleWord(false);
132: assertTrue(ui.flagModelChanged);
133: }
134:
135: public void testCreateUIJComponent() {
136: JTextArea jta = new JTextArea();
137: ComponentUI ui = BasicTextAreaUI.createUI(jta);
138: assertTrue(ui instanceof BasicTextAreaUI);
139: assertNotSame(ui, BasicTextAreaUI.createUI(jta));
140: }
141:
142: public void testGetPrefferedSize() {
143: }
144:
145: public void testGetMinimumSize() {
146: }
147:
148: public void testInstallDefaults() {
149: }
150: }
|