Test6526631.java 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

/*
 * @test
 * @bug 6526631
 * @summary Resizes right-oriented scroll pane
 * @author Sergey Malenkov
 * @library ..
 */

32
import java.awt.ComponentOrientation;
33 34 35 36 37 38 39 40 41 42 43 44 45
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;

public class Test6526631 {

    private static final int COLS = 90;
    private static final int ROWS = 50;
    private static final int OFFSET = 10;

46
    public static void main(String[] args) throws Throwable {
47 48 49 50 51 52 53 54
        SwingTest.start(Test6526631.class);
    }

    private final JScrollPane pane;
    private final JFrame frame;

    public Test6526631(JFrame frame) {
        this.pane = new JScrollPane(new JTextArea(ROWS, COLS));
55
        this.pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        this.frame = frame;
        this.frame.add(this.pane);
    }

    private void update(int offset) {
        Dimension size = this.frame.getSize();
        size.width += offset;
        this.frame.setSize(size);
    }

    public void validateFirst() {
        validateThird();
        update(OFFSET);
    }

    public void validateSecond() {
        validateThird();
        update(-OFFSET);
    }

    public void validateThird() {
        JViewport viewport = this.pane.getViewport();
        JScrollBar scroller = this.pane.getHorizontalScrollBar();
79 80
        if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
            throw new Error("unexpected component orientation");
81 82 83
        }
        int value = scroller.getValue();
        if (value != 0) {
84
            throw new Error("unexpected scroll value");
85 86 87
        }
        int extent = viewport.getExtentSize().width;
        if (extent != scroller.getVisibleAmount()) {
88
            throw new Error("unexpected visible amount");
89 90 91
        }
        int size = viewport.getViewSize().width;
        if (size != scroller.getMaximum()) {
92
            throw new Error("unexpected maximum");
93 94 95
        }
        int pos = size - extent - value;
        if (pos != viewport.getViewPosition().x) {
96
            throw new Error("unexpected position");
97 98 99
        }
    }
}