Test6526631.java revision 1457
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg/*
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * This code is free software; you can redistribute it and/or modify it
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * under the terms of the GNU General Public License version 2 only, as
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * published by the Free Software Foundation.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * This code is distributed in the hope that it will be useful, but WITHOUT
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * version 2 for more details (a copy is included in the LICENSE file that
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * accompanied this code).
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * You should have received a copy of the GNU General Public License version
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * 2 along with this work; if not, write to the Free Software Foundation,
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
01f87b9746ac246340e0e98d25e03193d83b071fJoe Bandenburg * CA 95054 USA or visit www.sun.com if you need additional information or
01f87b9746ac246340e0e98d25e03193d83b071fJoe Bandenburg * have any questions.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg */
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg/*
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @test
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @bug 6526631
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @summary Resizes right-oriented scroll pane
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @author Sergey Malenkov
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @library ..
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @build SwingTest
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * @run main Test6526631
01f87b9746ac246340e0e98d25e03193d83b071fJoe Bandenburg */
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport java.awt.Dimension;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport javax.swing.JFrame;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport javax.swing.JScrollBar;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport javax.swing.JScrollPane;
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostlerimport javax.swing.JTextArea;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport javax.swing.JViewport;
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler
01f87b9746ac246340e0e98d25e03193d83b071fJoe Bandenburgimport static java.awt.ComponentOrientation.RIGHT_TO_LEFT;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgpublic class Test6526631 {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg private static final int COLS = 90;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg private static final int ROWS = 50;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg private static final int OFFSET = 10;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg public static void main(String[] args) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg SwingTest.start(Test6526631.class);
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg private final JScrollPane pane;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg private final JFrame frame;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg public Test6526631(JFrame frame) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg this.pane = new JScrollPane(new JTextArea(ROWS, COLS));
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg this.pane.setComponentOrientation(RIGHT_TO_LEFT);
9798bfcb5c34f3b87217b619263fece5e9ffeec0Joe Bandenburg this.frame = frame;
494bebac1636810e5ff37c205fd77a119144957aJoe Bandenburg this.frame.add(this.pane);
9798bfcb5c34f3b87217b619263fece5e9ffeec0Joe Bandenburg }
9798bfcb5c34f3b87217b619263fece5e9ffeec0Joe Bandenburg
01f87b9746ac246340e0e98d25e03193d83b071fJoe Bandenburg private void update(int offset) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg Dimension size = this.frame.getSize();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg size.width += offset;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg this.frame.setSize(size);
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg public void validateFirst() {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg validateThird();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg update(OFFSET);
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg public void validateSecond() {
a4ca5e5077f7c2ed4bf14c3f5701955f716778f9Julian Kigwana validateThird();
a4ca5e5077f7c2ed4bf14c3f5701955f716778f9Julian Kigwana update(-OFFSET);
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler public void validateThird() {
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler JViewport viewport = this.pane.getViewport();
01f87b9746ac246340e0e98d25e03193d83b071fJoe Bandenburg JScrollBar scroller = this.pane.getHorizontalScrollBar();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg if (!scroller.getComponentOrientation().equals(RIGHT_TO_LEFT)) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg throw new IllegalStateException("unexpected component orientation");
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler }
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler int value = scroller.getValue();
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler if (value != 0) {
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler throw new IllegalStateException("unexpected scroll value");
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler }
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler int extent = viewport.getExtentSize().width;
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler if (extent != scroller.getVisibleAmount()) {
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler throw new IllegalStateException("unexpected visible amount");
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler }
825396f66be8e99fa60124ac9497cf1b454c43b7Phil Ostler int size = viewport.getViewSize().width;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg if (size != scroller.getMaximum()) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg throw new IllegalStateException("unexpected maximum");
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg int pos = size - extent - value;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg if (pos != viewport.getViewPosition().x) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg throw new IllegalStateException("unexpected position");
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg}
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg