/test/javax/swing/JScrollPane/Test6526631.java

https://github.com/ikeji/openjdk7-jdk · Java · 99 lines · 59 code · 11 blank · 29 comment · 9 complexity · 0a8660dc8f7178392ecae515d18cec5a MD5 · raw file

  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. * @test
  25. * @bug 6526631
  26. * @summary Resizes right-oriented scroll pane
  27. * @author Sergey Malenkov
  28. * @library ..
  29. */
  30. import java.awt.ComponentOrientation;
  31. import java.awt.Dimension;
  32. import javax.swing.JFrame;
  33. import javax.swing.JScrollBar;
  34. import javax.swing.JScrollPane;
  35. import javax.swing.JTextArea;
  36. import javax.swing.JViewport;
  37. public class Test6526631 {
  38. private static final int COLS = 90;
  39. private static final int ROWS = 50;
  40. private static final int OFFSET = 10;
  41. public static void main(String[] args) throws Throwable {
  42. SwingTest.start(Test6526631.class);
  43. }
  44. private final JScrollPane pane;
  45. private final JFrame frame;
  46. public Test6526631(JFrame frame) {
  47. this.pane = new JScrollPane(new JTextArea(ROWS, COLS));
  48. this.pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  49. this.frame = frame;
  50. this.frame.add(this.pane);
  51. }
  52. private void update(int offset) {
  53. Dimension size = this.frame.getSize();
  54. size.width += offset;
  55. this.frame.setSize(size);
  56. }
  57. public void validateFirst() {
  58. validateThird();
  59. update(OFFSET);
  60. }
  61. public void validateSecond() {
  62. validateThird();
  63. update(-OFFSET);
  64. }
  65. public void validateThird() {
  66. JViewport viewport = this.pane.getViewport();
  67. JScrollBar scroller = this.pane.getHorizontalScrollBar();
  68. if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
  69. throw new Error("unexpected component orientation");
  70. }
  71. int value = scroller.getValue();
  72. if (value != 0) {
  73. throw new Error("unexpected scroll value");
  74. }
  75. int extent = viewport.getExtentSize().width;
  76. if (extent != scroller.getVisibleAmount()) {
  77. throw new Error("unexpected visible amount");
  78. }
  79. int size = viewport.getViewSize().width;
  80. if (size != scroller.getMaximum()) {
  81. throw new Error("unexpected maximum");
  82. }
  83. int pos = size - extent - value;
  84. if (pos != viewport.getViewPosition().x) {
  85. throw new Error("unexpected position");
  86. }
  87. }
  88. }