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 javax.swing.Action;
023: import javax.swing.JEditorPane;
024: import javax.swing.JFrame;
025: import javax.swing.JTextArea;
026: import javax.swing.JTextField;
027: import javax.swing.SwingTestCase;
028: import javax.swing.plaf.ComponentUI;
029: import javax.swing.text.DefaultEditorKit;
030:
031: public class BasicEditorPaneUITest extends SwingTestCase {
032: JEditorPane jep;
033:
034: JFrame jf;
035:
036: BasicEditorPaneUI ui;
037:
038: @Override
039: protected void setUp() throws Exception {
040: super .setUp();
041: setIgnoreNotImplemented(true);
042: jf = new JFrame();
043: jep = new JEditorPane();
044: ui = (BasicEditorPaneUI) jep.getUI();
045: jf.getContentPane().add(jep);
046: jf.setSize(200, 300);
047: jf.pack();
048: }
049:
050: @Override
051: protected void tearDown() throws Exception {
052: jf.dispose();
053: super .tearDown();
054: }
055:
056: public void testCreateUI() {
057: ComponentUI ui1 = BasicEditorPaneUI.createUI(jep);
058: ComponentUI ui2 = BasicEditorPaneUI.createUI(jep);
059: assertTrue(ui1 instanceof BasicEditorPaneUI);
060: assertTrue(ui2 instanceof BasicEditorPaneUI);
061: ui1 = BasicEditorPaneUI.createUI(new JTextField());
062: assertTrue(ui1 instanceof BasicEditorPaneUI);
063: ui1 = BasicEditorPaneUI.createUI(new JTextArea());
064: assertTrue(ui1 instanceof BasicEditorPaneUI);
065: }
066:
067: public void testGetEditorKit() {
068: assertEquals(jep.getEditorKit(), ui.getEditorKit(jep));
069: jep.setContentType("text/html");
070: assertEquals(jep.getEditorKit(), ui.getEditorKit(jep));
071: jep.setContentType("text/rtf");
072: assertEquals(jep.getEditorKit(), ui.getEditorKit(jep));
073: DefaultEditorKit kit = new DefaultEditorKit();
074: jep.setEditorKit(kit);
075: assertEquals(jep.getEditorKit(), ui.getEditorKit(jep));
076: assertEquals(kit, ui.getEditorKit(new JTextField()));
077: assertEquals(kit, ui.getEditorKit(new JTextArea()));
078: BasicEditorPaneUI editorPaneUI = (BasicEditorPaneUI) BasicEditorPaneUI
079: .createUI(jep);
080: assertNull(editorPaneUI.getComponent());
081: }
082:
083: public void testGetPropertyPrefix() {
084: assertEquals("EditorPane", ui.getPropertyPrefix());
085: }
086:
087: void checkNames(final Action a1[], final Object a2[]) {
088: for (int i = 0; i < a1.length; i++) {
089: String name = (String) a1[i].getValue(Action.NAME);
090: boolean wasFound = false;
091: for (int j = 0; j < a2.length; j++) {
092: if (a2[j].equals(name)) {
093: wasFound = true;
094: break;
095: }
096: }
097: assertTrue(wasFound);
098: if (!wasFound) {
099: System.out.println(name);
100: }
101: }
102: }
103:
104: public void testPropertyChange() {
105: Action a1[] = jep.getActions();
106: Object a2[] = jep.getActionMap().getParent().getParent()
107: .allKeys();
108: checkNames(a1, a2);
109: jep.setContentType("text/html");
110: a1 = jep.getActions();
111: a2 = jep.getActionMap().getParent().getParent().allKeys();
112: checkNames(a1, a2);
113: jep.setContentType("text/rtf");
114: a1 = jep.getActions();
115: a2 = jep.getActionMap().getParent().getParent().allKeys();
116: checkNames(a1, a2);
117: }
118: }
|