jdk/test/javax/swing/text/DefaultStyledDocument/6636983/bug6636983.java
author yan
Tue, 23 Jun 2015 11:59:27 +0300
changeset 31448 1066345d2a8a
parent 5763 9a942d6fb0aa
child 40128 e635645d2a8a
permissions -rw-r--r--
8076468: Add @modules to tests in jdk_desktop test group Reviewed-by: yan, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5763
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     1
/*
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 5763
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
5763
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     4
 *
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     8
 *
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    13
 * accompanied this code).
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    14
 *
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    18
 *
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    21
 * questions.
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    22
 */
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    23
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    24
/*
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    25
 * @test
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    26
 * @bug 6636983
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    27
 * @summary test that composed text at the line starts is handled correctly
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    28
 * @author Sergey Groznyh
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 5763
diff changeset
    29
 * @modules java.desktop/sun.swing
5763
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    30
 * @run main bug6636983
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    31
 */
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    32
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    33
import sun.swing.SwingUtilities2;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    34
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    35
import javax.swing.*;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    36
import javax.swing.text.*;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    37
import javax.swing.text.html.HTMLDocument;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    38
import java.awt.*;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    39
import java.awt.event.InputMethodEvent;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    40
import java.awt.event.KeyEvent;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    41
import java.text.AttributedString;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    42
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    43
public class bug6636983 {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    44
    private Robot robot;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    45
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    46
    private final AttributedString Hiragana_A = new AttributedString("\u3042");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    47
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    48
    void sendInputMethodEvent() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    49
        InputMethodEvent ime = new InputMethodEvent(
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    50
                ep,
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    51
                InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    52
                Hiragana_A.getIterator(),
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    53
                0,
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    54
                null,
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    55
                null);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    56
        ep.dispatchEvent(ime);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    57
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    58
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    59
    void checkComposedTextRun() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    60
        HTMLDocument d = (HTMLDocument) ep.getDocument();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    61
        ElementIterator it = new ElementIterator(d.getDefaultRootElement());
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    62
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    63
        while (true) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    64
            Element e = it.next();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    65
            if (e == null) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    66
                throw new RuntimeException("no composed text found");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    67
            }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    68
            AttributeSet a = e.getAttributes();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    69
            if (a.isDefined(StyleConstants.ComposedTextAttribute)) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    70
                if (!AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute))) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    71
                    throw new RuntimeException("AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute)) is false");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    72
                }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    73
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    74
                if (a.isDefined(SwingUtilities2.IMPLIED_CR)) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    75
                    throw new RuntimeException("a.isDefined(SwingUtilities2.IMPLIED_CR) is true");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    76
                }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    77
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    78
                return;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    79
            }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    80
        }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    81
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    82
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    83
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    84
    JEditorPane ep;
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    85
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    86
    void initAtParagraphStart() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    87
        ep.setText("A<p>B");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    88
        hitKey(KeyEvent.VK_LEFT);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    89
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    90
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    91
    void sendAtParagraphStart() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    92
        sendInputMethodEvent();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    93
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    94
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    95
    void checkAtParagraphStart() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    96
        checkComposedTextRun();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    97
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    98
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
    99
    void initAfterBRElement() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   100
        ep.setText("A<br>B");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   101
        hitKey(KeyEvent.VK_LEFT);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   102
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   103
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   104
    void sendAtBRElement() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   105
        sendInputMethodEvent();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   106
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   107
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   108
    void checkAtBrElement() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   109
        checkComposedTextRun();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   110
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   111
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   112
    private void hitKey(int keycode) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   113
        robot.keyPress(keycode);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   114
        robot.keyRelease(keycode);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   115
        robot.delay(550); // The magic number equals JRobot.DEFAULT_DELAY
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   116
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   117
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   118
    private void run() throws Exception {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   119
        robot = new Robot();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   120
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   121
        ep = new JEditorPane();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   122
        ep.setContentType("text/html");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   123
        ep.setPreferredSize(new Dimension(100, 100));
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   124
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   125
        JFrame frame = new JFrame("Test: " + getClass().getName());
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   126
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   127
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   128
        frame.add(ep);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   129
        frame.setVisible(true);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   130
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   131
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   132
    public static void main(String[] args) throws Throwable {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   133
        SwingUtilities.invokeAndWait(new Runnable() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   134
            public void run() {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   135
                try {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   136
                    bug6636983 bug6636983 = new bug6636983();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   137
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   138
                    bug6636983.run();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   139
                    bug6636983.initAtParagraphStart();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   140
                    bug6636983.sendAtParagraphStart();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   141
                    bug6636983.checkAtParagraphStart();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   142
                    bug6636983.initAfterBRElement();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   143
                    bug6636983.sendAtBRElement();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   144
                    bug6636983.checkAtBrElement();
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   145
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   146
                    System.out.println("OK");
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   147
                } catch (Exception e) {
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   148
                    throw new RuntimeException("The test failed", e);
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   149
                }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   150
            }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   151
        });
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   152
    }
9a942d6fb0aa 6636983: Japanese text does not display correctly in a JEditorPane
rupashka
parents:
diff changeset
   153
}