Mercurial > hg > openjdk > icedtea > jdk7 > jdk
changeset 2522:e821a3568b0a
6925473: REGRESSION: JOptionPane in dialog is full-screen height
Reviewed-by: peterz
author | rupashka |
---|---|
date | Wed, 26 May 2010 22:02:32 +0400 |
parents | fc1ac6ea933c |
children | 824b0f8b68f6 |
files | src/share/classes/javax/swing/text/WrappedPlainView.java test/javax/swing/JTextArea/6925473/bug6925473.java test/javax/swing/JTextArea/6940863/bug6940863.java test/javax/swing/JTextArea/Test6593649.java |
diffstat | 4 files changed, 191 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/javax/swing/text/WrappedPlainView.java Wed May 26 20:22:23 2010 +0400 +++ b/src/share/classes/javax/swing/text/WrappedPlainView.java Wed May 26 22:02:32 2010 +0400 @@ -24,8 +24,6 @@ */ package javax.swing.text; -import java.util.Vector; -import java.util.Properties; import java.awt.*; import java.lang.ref.SoftReference; import javax.swing.event.*; @@ -236,9 +234,6 @@ Segment segment = SegmentCache.getSharedSegment(); loadText(segment, p0, p1); int currentWidth = getWidth(); - if (currentWidth == Integer.MAX_VALUE) { - currentWidth = (int) getDefaultSpan(View.X_AXIS); - } if (wordWrap) { p = p0 + Utilities.getBreakLocation(segment, metrics, tabBase, tabBase + currentWidth, @@ -324,53 +319,6 @@ tabSize = getTabSize() * metrics.charWidth('m'); } - /** - * Return reasonable default values for the view dimensions. The standard - * text terminal size 80x24 is pretty suitable for the wrapped plain view. - * - * The size should not be larger than the component housing the view's - * container. - */ - private float getDefaultSpan(int axis) { - Container host = getContainer(); - Component parent = null; - - if (host != null) { - parent = host.getParent(); - } - - switch (axis) { - case View.X_AXIS: - int defaultWidth = 80 * metrics.getWidths()['M']; - int parentWidth = 0; - - if (parent != null) { - parentWidth = parent.getWidth(); - } - - if (defaultWidth > parentWidth) { - return parentWidth; - } - return defaultWidth; - - case View.Y_AXIS: - int defaultHeight = 24 * metrics.getHeight(); - int parentHeight = 0; - - if (parent != null) { - parentHeight = parent.getHeight(); - } - - if (defaultHeight > parentHeight) { - return parentHeight; - } - return defaultHeight; - - default: - throw new IllegalArgumentException("Invalid axis: " + axis); - } - } - // --- TabExpander methods ------------------------------------------ /** @@ -605,18 +553,14 @@ if (width == Integer.MAX_VALUE) { // We have been initially set to MAX_VALUE, but we don't // want this as our preferred. - width = getDefaultSpan(axis); + return 100f; } return width; case View.Y_AXIS: - if (getDocument().getLength() > 0) { - if ((lineCount < 0) || widthChanging) { - breakLines(getStartOffset()); - } - return lineCount * metrics.getHeight(); - } else { - return getDefaultSpan(axis); + if (lineCount < 0 || widthChanging) { + breakLines(getStartOffset()); } + return lineCount * metrics.getHeight(); default: throw new IllegalArgumentException("Invalid axis: " + axis); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JTextArea/6925473/bug6925473.java Wed May 26 22:02:32 2010 +0400 @@ -0,0 +1,64 @@ +/* + * Copyright 2010 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 6925473 + * @summary REGRESSION: JOptionPane in dialog is full-screen height + * @author Pavel Porvatov + * @run main bug6925473 + */ + +import javax.swing.*; +import java.awt.*; + +public class bug6925473 { + private static final String LONG_TEXT = "Copyright 2010 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. "; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + JTextArea textArea = new JTextArea(LONG_TEXT); + + Dimension preferredSize = textArea.getPreferredSize(); + + if (preferredSize.width <= 0 || preferredSize.height <= 0) { + throw new RuntimeException("Invalid preferred size " + preferredSize); + } + + JTextArea textAreaLW = new JTextArea(LONG_TEXT); + + textAreaLW.setLineWrap(true); + + Dimension preferredSizeLW = textAreaLW.getPreferredSize(); + + if (preferredSizeLW.width <= 0 || preferredSizeLW.height <= 0) { + throw new RuntimeException("Invalid preferred size " + preferredSizeLW); + } + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JTextArea/6940863/bug6940863.java Wed May 26 22:02:32 2010 +0400 @@ -0,0 +1,87 @@ +/* + * Copyright 2010 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 6940863 + * @summary Textarea within scrollpane shows vertical scrollbar + * @author Pavel Porvatov + * @run main bug6940863 + */ + +import sun.awt.OSInfo; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class bug6940863 { + private static JFrame frame; + + private static JScrollPane scrollPane; + + private static final Timer timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent e) { + boolean failed = scrollPane.getVerticalScrollBar().isShowing() || + scrollPane.getHorizontalScrollBar().isShowing(); + + frame.dispose(); + + if (failed) { + throw new RuntimeException("The test failed"); + } + } + }); + + public static void main(String[] args) throws Exception { + if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) { + System.out.println("The test is suitable only for Windows OS. Skipped"); + } + + UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + JTextArea textArea = new JTextArea(); + + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + + scrollPane = new JScrollPane(textArea); + + scrollPane.setMinimumSize(new Dimension(200, 100)); + scrollPane.setPreferredSize(new Dimension(300, 150)); + + frame = new JFrame("Vertical scrollbar shown without text"); + + frame.setContentPane(scrollPane); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + + timer.setRepeats(false); + timer.start(); + } + }); + } +}
--- a/test/javax/swing/JTextArea/Test6593649.java Wed May 26 20:22:23 2010 +0400 +++ b/test/javax/swing/JTextArea/Test6593649.java Wed May 26 22:02:32 2010 +0400 @@ -30,60 +30,50 @@ import javax.swing.*; import java.awt.*; - -public class Test6593649 extends JFrame { - static JTextArea txt; - static JPanel innerPanel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; - public Test6593649(Dimension d) - { - super("Word Wrap Testcase"); +public class Test6593649 { + private static JFrame frame; - setSize(d); + private static JTextArea textArea; - final Container contentPane = getContentPane(); + private static final Timer timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent e) { + boolean failed = !textArea.getParent().getSize().equals(textArea.getSize()); - innerPanel = new JPanel(); - innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS)); + frame.dispose(); - txt = new JTextArea("This is a long line that should wrap, but doesn't..."); - txt.setLineWrap(true); - txt.setWrapStyleWord(true); - - innerPanel.add(txt); - - contentPane.add(innerPanel, BorderLayout.SOUTH); - } + if (failed) { + throw new RuntimeException("The test failed"); + } + } + }); - public static void main(String[] args) throws InterruptedException - { - int size = 100; - Dimension d; - Test6593649 cp; - Dimension txtSize; - Dimension innerSize; - Dimension cpSize; + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame = new JFrame(); + + frame.setSize(200, 100); - while (size <= 600) - { - d = new Dimension(size, size); - cp = new Test6593649(d); - cp.setVisible(true); + textArea = new JTextArea("This is a long line that should wrap, but doesn't..."); + + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + + JPanel innerPanel = new JPanel(); - txtSize = txt.getPreferredSize(); - innerSize = innerPanel.getPreferredSize(); - cpSize = cp.getSize(); + innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS)); + innerPanel.add(textArea); + + frame.getContentPane().add(innerPanel, BorderLayout.SOUTH); + + frame.setVisible(true); - if (!(txtSize.getWidth() == innerPanel.getWidth() && txtSize.getHeight() == innerPanel.getHeight() && - txtSize.getWidth() <= cpSize.getWidth() && txtSize.getHeight() <= cpSize.getHeight())) - { - throw new RuntimeException("Test failed: Text area size does not properly match panel and frame sizes"); - } - - Thread.sleep(2000); - - cp.hide(); - size += 50; + timer.setRepeats(false); + timer.start(); + } + }); } - } }