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;
021:
022: import javax.swing.plaf.metal.MetalIconFactory;
023: import javax.swing.text.BadLocationException;
024: import javax.swing.text.EditorKit;
025: import javax.swing.text.MutableAttributeSet;
026: import javax.swing.text.SimpleAttributeSet;
027: import javax.swing.text.StyleConstants;
028: import javax.swing.text.StyledDocument;
029: import javax.swing.text.StyledEditorKit;
030:
031: public class JEditorPaneRTest extends SwingTestCase {
032: public void testPlainViewFactory() {
033: JEditorPane jp = new JEditorPane();
034: String name = jp.getUI().getRootView(jp).getView(0).getClass()
035: .getName();
036: assertEquals("javax.swing.text.WrappedPlainView", name);
037: }
038:
039: public void testCreateDefaultEditorKit() {
040: JEditorPane pane = new JEditorPane() {
041: private static final long serialVersionUID = 1L;
042:
043: @Override
044: protected EditorKit createDefaultEditorKit() {
045: return new StyledEditorKit();
046: }
047: };
048: assertTrue(pane.getEditorKit() instanceof StyledEditorKit);
049: }
050:
051: public boolean wasInstallCall;
052:
053: public void testCreateDefaultEditorKit_installCall() {
054: JEditorPane pane = new JEditorPane() {
055: private static final long serialVersionUID = 1L;
056: };
057: pane.setEditorKit(new StyledEditorKit() {
058: private static final long serialVersionUID = 1L;
059:
060: @Override
061: public void install(JEditorPane component) {
062: wasInstallCall = true;
063: super .install(component);
064: }
065: });
066: assertTrue(wasInstallCall);
067: }
068:
069: public void testInputAttributes() {
070: JEditorPane pane = new JEditorPane() {
071: private static final long serialVersionUID = 1L;
072:
073: @Override
074: protected EditorKit createDefaultEditorKit() {
075: return new StyledEditorKit();
076: }
077: };
078: pane.setEditorKit(new StyledEditorKit());
079: StyledDocument doc = (StyledDocument) pane.getDocument();
080: StyledEditorKit kit = (StyledEditorKit) pane.getEditorKit();
081: try {
082: MutableAttributeSet attrs = new SimpleAttributeSet();
083: StyleConstants.setUnderline(attrs, true);
084: doc.insertString(0, "Hello word!", attrs);
085: pane.setCaretPosition(4);
086: attrs = new SimpleAttributeSet();
087: StyleConstants.setIcon(attrs, MetalIconFactory
088: .getTreeFolderIcon());
089: doc.insertString(4, " ", attrs);
090: pane.setCaretPosition(4);
091: doc.insertString(4, "\n", kit.getInputAttributes());
092: assertFalse(StyleConstants.isUnderline(kit
093: .getInputAttributes()));
094: pane.setCaretPosition(5);
095: assertFalse(StyleConstants.isUnderline(kit
096: .getInputAttributes()));
097: } catch (BadLocationException e) {
098: }
099: }
100: }
|