Test6526631.java revision 15235:fe58d505fffd
1/*
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @key headful
27 * @bug 6526631
28 * @summary Resizes right-oriented scroll pane
29 * @author Sergey Malenkov
30 * @library ..
31 */
32
33import java.awt.ComponentOrientation;
34import java.awt.Dimension;
35import javax.swing.JFrame;
36import javax.swing.JScrollBar;
37import javax.swing.JScrollPane;
38import javax.swing.JTextArea;
39import javax.swing.JViewport;
40
41public class Test6526631 {
42
43    private static final int COLS = 90;
44    private static final int ROWS = 50;
45    private static final int OFFSET = 10;
46
47    public static void main(String[] args) throws Throwable {
48        SwingTest.start(Test6526631.class);
49    }
50
51    private final JScrollPane pane;
52    private final JFrame frame;
53
54    public Test6526631(JFrame frame) {
55        this.pane = new JScrollPane(new JTextArea(ROWS, COLS));
56        this.pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
57        this.frame = frame;
58        this.frame.add(this.pane);
59    }
60
61    private void update(int offset) {
62        Dimension size = this.frame.getSize();
63        size.width += offset;
64        this.frame.setSize(size);
65    }
66
67    public void validateFirst() {
68        validateThird();
69        update(OFFSET);
70    }
71
72    public void validateSecond() {
73        validateThird();
74        update(-OFFSET);
75    }
76
77    public void validateThird() {
78        JViewport viewport = this.pane.getViewport();
79        JScrollBar scroller = this.pane.getHorizontalScrollBar();
80        if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
81            throw new Error("unexpected component orientation");
82        }
83        int value = scroller.getValue();
84        if (value != 0) {
85            throw new Error("unexpected scroll value");
86        }
87        int extent = viewport.getExtentSize().width;
88        if (extent != scroller.getVisibleAmount()) {
89            throw new Error("unexpected visible amount");
90        }
91        int size = viewport.getViewSize().width;
92        if (size != scroller.getMaximum()) {
93            throw new Error("unexpected maximum");
94        }
95        int pos = size - extent - value;
96        if (pos != viewport.getViewPosition().x) {
97            throw new Error("unexpected position");
98        }
99    }
100}
101