提交 b40b52ba 编写于 作者: R rupashka

6925473: REGRESSION: JOptionPane in dialog is full-screen height

Reviewed-by: peterz
上级 c1fe285e
......@@ -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 @@ public class WrappedPlainView extends BoxView implements TabExpander {
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 @@ public class WrappedPlainView extends BoxView implements TabExpander {
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 @@ public class WrappedPlainView extends BoxView implements TabExpander {
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) {
if (lineCount < 0 || widthChanging) {
breakLines(getStartOffset());
}
return lineCount * metrics.getHeight();
} else {
return getDefaultSpan(axis);
}
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
......
/*
* 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);
}
}
});
}
}
/*
* 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();
}
});
}
}
......@@ -30,60 +30,50 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Test6593649 extends JFrame {
static JTextArea txt;
static JPanel innerPanel;
public class Test6593649 {
private static JFrame frame;
public Test6593649(Dimension d)
{
super("Word Wrap Testcase");
private static JTextArea textArea;
setSize(d);
private static final Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean failed = !textArea.getParent().getSize().equals(textArea.getSize());
final Container contentPane = getContentPane();
frame.dispose();
innerPanel = new JPanel();
innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS));
if (failed) {
throw new RuntimeException("The test failed");
}
}
});
txt = new JTextArea("This is a long line that should wrap, but doesn't...");
txt.setLineWrap(true);
txt.setWrapStyleWord(true);
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
frame = new JFrame();
innerPanel.add(txt);
frame.setSize(200, 100);
contentPane.add(innerPanel, BorderLayout.SOUTH);
}
textArea = new JTextArea("This is a long line that should wrap, but doesn't...");
public static void main(String[] args) throws InterruptedException
{
int size = 100;
Dimension d;
Test6593649 cp;
Dimension txtSize;
Dimension innerSize;
Dimension cpSize;
while (size <= 600)
{
d = new Dimension(size, size);
cp = new Test6593649(d);
cp.setVisible(true);
txtSize = txt.getPreferredSize();
innerSize = innerPanel.getPreferredSize();
cpSize = cp.getSize();
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");
}
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JPanel innerPanel = new JPanel();
innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS));
innerPanel.add(textArea);
frame.getContentPane().add(innerPanel, BorderLayout.SOUTH);
Thread.sleep(2000);
frame.setVisible(true);
cp.hide();
size += 50;
timer.setRepeats(false);
timer.start();
}
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册