Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTextPane/JTextPaneDocumentAlignment.java
38839 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 813213625@summary [PIT] RTL orientation in JEditorPane is broken26@author Semyon Sadetsky27*/2829import javax.swing.*;30import javax.swing.text.BadLocationException;31import javax.swing.text.SimpleAttributeSet;32import javax.swing.text.StyleConstants;33import java.awt.*;3435public class JTextPaneDocumentAlignment {3637private static JFrame frame;38private static JTextPane jTextPane;39private static int position;4041public static void main(String[] args) throws Exception{42SwingUtilities.invokeAndWait(new Runnable() {43@Override44public void run() {45frame = new JFrame();46frame.setUndecorated(true);47frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);48frame.setSize(200, 200);49jTextPane = new JTextPane();50jTextPane.setContentType("text/html");51jTextPane.setText(52"<html><body><b id='test'>Test</b></body></html>");53SimpleAttributeSet right = new SimpleAttributeSet();54StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);55jTextPane.getStyledDocument()56.setParagraphAttributes(0, 10, right, true);57frame.getContentPane().add(jTextPane);58frame.setVisible(true);59}60});61Robot robot = new Robot();62robot.waitForIdle();63robot.delay(200);64SwingUtilities.invokeAndWait(new Runnable() {65@Override66public void run() {67try {68position = jTextPane.modelToView(1).x;69SimpleAttributeSet center = new SimpleAttributeSet();70StyleConstants.setAlignment(center,71StyleConstants.ALIGN_CENTER);72jTextPane.getStyledDocument()73.setParagraphAttributes(0, 10, center, true);74} catch (BadLocationException e) {75e.printStackTrace();76}77}78});79if(position < 100) {80throw new RuntimeException("Text is not right aligned " + position);81}82SwingUtilities.invokeAndWait(new Runnable() {83@Override84public void run() {85try {86position = jTextPane.modelToView(1).x;87} catch (BadLocationException e) {88e.printStackTrace();89}90frame.dispose();91}92});93if(position < 20) {94throw new RuntimeException("Text is not center aligned " + position);95}96System.out.println("ok");97}98}99100101