4266N/A/*
4266N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4266N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4266N/A *
4266N/A * This code is free software; you can redistribute it and/or modify it
4266N/A * under the terms of the GNU General Public License version 2 only, as
4266N/A * published by the Free Software Foundation.
4266N/A *
4266N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4266N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4266N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4266N/A * version 2 for more details (a copy is included in the LICENSE file that
4266N/A * accompanied this code).
4266N/A *
4266N/A * You should have received a copy of the GNU General Public License version
4266N/A * 2 along with this work; if not, write to the Free Software Foundation,
4266N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4266N/A *
4266N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4266N/A * or visit www.oracle.com if you need additional information or have any
4266N/A * questions.
4266N/A */
4266N/A
4266N/A/*
4266N/A * @test
4266N/A * @bug 7045593
4266N/A * @summary Possible Regression : JTextfield cursor placement behavior algorithm has changed
4266N/A * @author Pavel Porvatov
4266N/A */
4266N/A
4266N/Aimport sun.awt.SunToolkit;
4266N/A
4266N/Aimport javax.swing.*;
4266N/Aimport javax.swing.text.BadLocationException;
4266N/Aimport java.awt.*;
4266N/A
4266N/Apublic class bug7045593 {
4266N/A private static volatile JTextField jtf;
4266N/A
4266N/A public static void main(String[] args) throws Exception {
4266N/A SwingUtilities.invokeAndWait(new Runnable() {
4266N/A public void run() {
4266N/A jtf = new JTextField("WW");
4266N/A
4266N/A JFrame frame = new JFrame();
4266N/A frame.getContentPane().add(jtf);
4266N/A frame.pack();
4266N/A frame.setVisible(true);
4266N/A }
4266N/A });
4266N/A
4266N/A ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
4266N/A
4266N/A SwingUtilities.invokeAndWait(new Runnable() {
4266N/A public void run() {
4266N/A try {
4266N/A Rectangle r = jtf.modelToView(1);
4266N/A
4266N/A int delta = 2;
4266N/A
4266N/A for (int x = r.x - delta; x < r.x + delta; x++) {
4266N/A assertEquals(jtf.viewToModel(new Point(x, r.y)), 1);
4266N/A }
4266N/A
4266N/A System.out.println("Passed.");
4266N/A } catch (BadLocationException e) {
4266N/A throw new RuntimeException("Test failed", e);
4266N/A }
4266N/A }
4266N/A });
4266N/A }
4266N/A
4266N/A private static void assertEquals(int i1, int i2) {
4266N/A if (i1 != i2) {
4266N/A throw new RuntimeException("Test failed, " + i1 + " != " + i2);
4266N/A }
4266N/A }
4266N/A}