From 224bf60e3077ccba0a008805ef3aea70725f5cae Mon Sep 17 00:00:00 2001 From: Alexandr Scherbatiy Date: Mon, 17 Oct 2011 15:10:42 +0400 Subject: [PATCH 01/13] 7099251: javax.swing.text.html.HTMLDocument.insertAfterStart(null, something) throws NPE Reviewed-by: rupashka --- .../share/classes/javax/swing/text/html/HTMLDocument.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java b/jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java index 5fc8c0f2bf4..a1f99e9cae8 100644 --- a/jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java +++ b/jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java @@ -1181,7 +1181,12 @@ public class HTMLDocument extends DefaultStyledDocument { public void insertAfterStart(Element elem, String htmlText) throws BadLocationException, IOException { verifyParser(); - if (elem != null && elem.isLeaf()) { + + if (elem == null || htmlText == null) { + return; + } + + if (elem.isLeaf()) { throw new IllegalArgumentException ("Can not insert HTML after start of a leaf"); } From 0819253023952f7a9de44a3f6b88134ddf75758d Mon Sep 17 00:00:00 2001 From: Alexandr Scherbatiy Date: Mon, 17 Oct 2011 16:40:34 +0400 Subject: [PATCH 02/13] 7100004: javax.swing.JTable.setAutoCreateRowSorter(boolean autoCreateRowSorter) should mention default value Reviewed-by: rupashka --- jdk/src/share/classes/javax/swing/JTable.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jdk/src/share/classes/javax/swing/JTable.java b/jdk/src/share/classes/javax/swing/JTable.java index 386b2a4628a..6314cb0a207 100644 --- a/jdk/src/share/classes/javax/swing/JTable.java +++ b/jdk/src/share/classes/javax/swing/JTable.java @@ -1828,6 +1828,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * table. While the {@code autoCreateRowSorter} property remains * {@code true}, every time the model is changed, a new {@code * TableRowSorter} is created and set as the table's row sorter. + * The default value for the {@code autoCreateRowSorter} + * property is {@code false}. * * @param autoCreateRowSorter whether or not a {@code RowSorter} * should be automatically created From 45109520ef121f3e1b1fdab0025e0eb3d98f4041 Mon Sep 17 00:00:00 2001 From: Alexandr Scherbatiy Date: Mon, 17 Oct 2011 17:19:43 +0400 Subject: [PATCH 03/13] 7077293: javax/swing/JComponent/4337267/bug4337267.java failed on windows 2003 Reviewed-by: rupashka --- .../classes/sun/swing/SwingUtilities2.java | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/jdk/src/share/classes/sun/swing/SwingUtilities2.java b/jdk/src/share/classes/sun/swing/SwingUtilities2.java index fc7fbf43f13..2094ec0c11d 100644 --- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java +++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java @@ -524,56 +524,67 @@ public class SwingUtilities2 { } // If we get here we're not printing - AATextInfo info = drawTextAntialiased(c); - if (info != null && (g instanceof Graphics2D)) { + if (g instanceof Graphics2D) { + AATextInfo info = drawTextAntialiased(c); Graphics2D g2 = (Graphics2D)g; - Object oldContrast = null; - Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING); - if (info.aaHint != oldAAValue) { - g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint); - } else { - oldAAValue = null; - } - if (info.lcdContrastHint != null) { - oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST); - if (info.lcdContrastHint.equals(oldContrast)) { - oldContrast = null; - } else { - g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, - info.lcdContrastHint); - } - } - boolean needsTextLayout = ((c != null) && (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null)); + if (needsTextLayout) { synchronized(charsBufferLock) { int length = syncCharsBuffer(text); needsTextLayout = isComplexLayout(charsBuffer, 0, length); } } - if (needsTextLayout) { + + if (info != null) { + Object oldContrast = null; + Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING); + if (info.aaHint != oldAAValue) { + g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint); + } else { + oldAAValue = null; + } + if (info.lcdContrastHint != null) { + oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST); + if (info.lcdContrastHint.equals(oldContrast)) { + oldContrast = null; + } else { + g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, + info.lcdContrastHint); + } + } + + if (needsTextLayout) { + TextLayout layout = createTextLayout(c, text, g2.getFont(), + g2.getFontRenderContext()); + layout.draw(g2, x, y); + } else { + g.drawString(text, x, y); + } + + if (oldAAValue != null) { + g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue); + } + if (oldContrast != null) { + g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast); + } + + return; + } + + if (needsTextLayout){ TextLayout layout = createTextLayout(c, text, g2.getFont(), g2.getFontRenderContext()); layout.draw(g2, x, y); - } else { - g.drawString(text, x, y); + return; } + } - if (oldAAValue != null) { - g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue); - } - if (oldContrast != null) { - g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast); - } - } - else { - g.drawString(text, x, y); - } + g.drawString(text, x, y); } - /** * Draws the string at the specified location underlining the specified * character. From 756974b448e19de1a4f6858e6f528cefd478c0d0 Mon Sep 17 00:00:00 2001 From: David Buck Date: Mon, 17 Oct 2011 19:06:24 -0700 Subject: [PATCH 04/13] 6887286: StackOverflowError at sun.awt.image.ImageWatched$WeakLink.isWatcher Fixed OffScreenImageSource to call imageComplete() with SINGLEFAMEDONE, not STATICIMAGEDONE. This fixed memory leak (that caused SOFE when we use recursion to iterate over linked list). Reviewed-by: bae --- jdk/src/share/classes/sun/awt/image/OffScreenImageSource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/sun/awt/image/OffScreenImageSource.java b/jdk/src/share/classes/sun/awt/image/OffScreenImageSource.java index 7e8e2dbc795..2b85b6b6d84 100644 --- a/jdk/src/share/classes/sun/awt/image/OffScreenImageSource.java +++ b/jdk/src/share/classes/sun/awt/image/OffScreenImageSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. 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 @@ -185,7 +185,7 @@ public class OffScreenImageSource implements ImageProducer { theConsumer.setDimensions(image.getWidth(), image.getHeight()); theConsumer.setProperties(properties); sendPixels(); - theConsumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE); + theConsumer.imageComplete(ImageConsumer.STATICIMAGEDONE); } catch (NullPointerException e) { if (theConsumer != null) { theConsumer.imageComplete(ImageConsumer.IMAGEERROR); From 60689cf49bbd52f9daaab6443621686bf4dacbbf Mon Sep 17 00:00:00 2001 From: Federico Tello Gentile Date: Tue, 1 Nov 2011 18:01:58 +0300 Subject: [PATCH 05/13] 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason Wrap logging calls with if(){} statements Reviewed-by: anthony, son --- .../classes/sun/awt/X11/XComponentPeer.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java index 7dd3812899e..6375a7b0cfb 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java @@ -466,12 +466,16 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget if (true) { switch(e.getID()) { case PaintEvent.UPDATE: - log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + + if (log.isLoggable(PlatformLogger.FINER)) { + log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); + } return; case PaintEvent.PAINT: - log.finer("XCP coalescePaintEvent : PAINT : add : x = " + + if (log.isLoggable(PlatformLogger.FINER)) { + log.finer("XCP coalescePaintEvent : PAINT : add : x = " + r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); + } return; } } @@ -1248,7 +1252,9 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify */ protected boolean isEventDisabled(XEvent e) { - enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable")); + if (enableLog.isLoggable(PlatformLogger.FINEST)) { + enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable")); + } if (!isEnabled()) { switch (e.get_type()) { case XConstants.ButtonPress: @@ -1258,7 +1264,9 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget case XConstants.EnterNotify: case XConstants.LeaveNotify: case XConstants.MotionNotify: - enableLog.finer("Event {0} is disable", e); + if (enableLog.isLoggable(PlatformLogger.FINER)) { + enableLog.finer("Event {0} is disable", e); + } return true; } } From d3cb1a4bdd713c692faed95e6457235bd4806a5b Mon Sep 17 00:00:00 2001 From: Federico Tello Gentile Date: Tue, 1 Nov 2011 18:03:56 +0300 Subject: [PATCH 06/13] 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator Replace string concatenation with StringBuilder.append() Reviewed-by: anthony, son --- .../awt/X11/generator/WrapperGenerator.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java b/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java index 272fda8d702..7ad7386070a 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java +++ b/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java @@ -678,7 +678,7 @@ public class WrapperGenerator { public void writeToString(StructType stp, PrintWriter pw) { int type; pw.println("\n\n\tString getName() {\n\t\treturn \"" + stp.getName()+ "\"; \n\t}"); - pw.println("\n\n\tString getFieldsAsString() {\n\t\tString ret=\"\";\n"); + pw.println("\n\n\tString getFieldsAsString() {\n\t\tStringBuilder ret = new StringBuilder(" + stp.getNumFields() * 40 + ");\n"); for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) { AtomicType tp = (AtomicType) e.nextElement(); @@ -688,24 +688,24 @@ public class WrapperGenerator { if ((name != null) && (name.length() > 0)) { if (type == AtomicType.TYPE_ATOM) { - pw.println("\t\tret += \"\"+\"" + name + " = \" + XAtom.get(get_" + name + "()) +\", \";"); + pw.println("\t\tret.append(\"" + name + " = \" ).append( XAtom.get(get_" + name + "()) ).append(\", \");"); } else if (name.equals("type")) { - pw.println("\t\tret += \"\"+\"type = \" + XlibWrapper.eventToString[get_type()] +\", \";"); + pw.println("\t\tret.append(\"type = \").append( XlibWrapper.eventToString[get_type()] ).append(\", \");"); } else if (name.equals("window")){ - pw.println("\t\tret += \"\"+\"window = \" + getWindow(get_window()) + \", \";"); + pw.println("\t\tret.append(\"window = \" ).append( getWindow(get_window()) ).append(\", \");"); } else if (type == AtomicType.TYPE_ARRAY) { - pw.print("\t\tret += \"{\""); + pw.print("\t\tret.append(\"{\")"); for (int i = 0; i < tp.getArrayLength(); i++) { - pw.print(" + get_" + name + "(" + i + ") + \" \""); + pw.print("\n\t\t.append( get_" + name + "(" + i + ") ).append(\" \")"); } - pw.println(" + \"}\";"); + pw.println(".append( \"}\");"); } else { - pw.println("\t\tret += \"\"+\"" + name +" = \" + get_"+ name+"() +\", \";"); + pw.println("\t\tret.append(\"" + name +" = \").append( get_"+ name+"() ).append(\", \");"); } } } - pw.println("\t\treturn ret;\n\t}\n\n"); + pw.println("\t\treturn ret.toString();\n\t}\n\n"); } public void writeStubs(StructType stp, PrintWriter pw) { From 6612f2a7e637d3d88037ba70eca840159e3cd73e Mon Sep 17 00:00:00 2001 From: Alexandr Scherbatiy Date: Wed, 2 Nov 2011 14:17:16 +0400 Subject: [PATCH 07/13] 6624077: Regression test fails: closed/javax/swing/ToolTipManager/6256140/bug6256140.java Reviewed-by: rupashka --- .../swing/ToolTipManager/Test6256140.java | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 jdk/test/javax/swing/ToolTipManager/Test6256140.java diff --git a/jdk/test/javax/swing/ToolTipManager/Test6256140.java b/jdk/test/javax/swing/ToolTipManager/Test6256140.java new file mode 100644 index 00000000000..12d5df8be03 --- /dev/null +++ b/jdk/test/javax/swing/ToolTipManager/Test6256140.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6256140 + * @summary Esc key doesn't restore old value in JFormattedtextField when ToolTip is set + * @author Alexander Potochkin + * @run main Test6256140 + */ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; + +public class Test6256140 { + + private static volatile JFormattedTextField ft; + + private final static String initialText = "value"; + private final static JLabel toolTipLabel = new JLabel("tip"); + + public static void main(String[] args) throws Exception { + + Robot robot = new Robot(); + robot.setAutoDelay(10); + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + createAndShowGUI(); + } + }); + toolkit.realSync(); + + Point point = ft.getLocationOnScreen(); + robot.mouseMove(point.x, point.y); + robot.mouseMove(point.x + 3, point.y + 3); + + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + toolkit.realSync(); + + if (!isTooltipShowning()) { + throw new RuntimeException("Tooltip is not shown"); + } + + robot.keyPress(KeyEvent.VK_ESCAPE); + robot.keyRelease(KeyEvent.VK_ESCAPE); + toolkit.realSync(); + + if (isTooltipShowning()) { + throw new RuntimeException("Tooltip must be hidden now"); + } + + if (isTextEqual()) { + throw new RuntimeException("FormattedTextField must *not* cancel the updated value this time"); + } + + robot.keyPress(KeyEvent.VK_ESCAPE); + robot.keyRelease(KeyEvent.VK_ESCAPE); + toolkit.realSync(); + + if (!isTextEqual()) { + throw new RuntimeException("FormattedTextField must cancel the updated value"); + } + } + + private static boolean isTooltipShowning() throws Exception { + final boolean[] result = new boolean[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + result[0] = toolTipLabel.isShowing(); + } + }); + + return result[0]; + } + + private static boolean isTextEqual() throws Exception { + final boolean[] result = new boolean[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + result[0] = initialText.equals(ft.getText()); + } + }); + + return result[0]; + } + + private static void createAndShowGUI() { + ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE); + ToolTipManager.sharedInstance().setInitialDelay(0); + + final JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLayout(new FlowLayout()); + + ft = new JFormattedTextField() { + + public JToolTip createToolTip() { + JToolTip toolTip = super.createToolTip(); + toolTip.setLayout(new BorderLayout()); + toolTip.add(toolTipLabel); + return toolTip; + } + }; + ft.setToolTipText(" "); + ft.setValue(initialText); + frame.add(ft); + + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + ft.requestFocus(); + } +} From 34c1a2b71680d900c65e93103f2160301b4a51e4 Mon Sep 17 00:00:00 2001 From: Alexander Kouznetsov Date: Wed, 2 Nov 2011 17:39:30 +0400 Subject: [PATCH 08/13] 7074853: TransparentRuler demos Readme should mention the correct jar file name Reviewed-by: rupashka --- jdk/src/share/demo/jfc/TransparentRuler/README.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/jdk/src/share/demo/jfc/TransparentRuler/README.txt b/jdk/src/share/demo/jfc/TransparentRuler/README.txt index ddcf9de1d5e..0b66bd213c2 100644 --- a/jdk/src/share/demo/jfc/TransparentRuler/README.txt +++ b/jdk/src/share/demo/jfc/TransparentRuler/README.txt @@ -1,14 +1,10 @@ To run the Ruler demo: - java -jar Ruler.jar + java -jar TransparentRuler.jar These instructions assume that this installation's version of the java command is in your path. If it isn't, then you should either specify the complete path to the java command or update your PATH environment variable as described in the installation instructions for the Java(TM) SE Development Kit. - -KNOWN ISSUES: -Context menu is clipped with the window shape. The issues are: -CR 7027486 JPopupMenu doesn't take window shape into account From c59424668d06bf7916ca34f7da2e87b12bc7f18b Mon Sep 17 00:00:00 2001 From: Sean Chou Date: Wed, 2 Nov 2011 23:53:16 +0300 Subject: [PATCH 09/13] 7049024: DnD fails with JTextArea and JTextField Reviewed-by: rupashka --- .../javax/swing/text/DefaultCaret.java | 2 +- .../swing/JTextArea/7049024/bug7049024.java | 134 ++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 jdk/test/javax/swing/JTextArea/7049024/bug7049024.java diff --git a/jdk/src/share/classes/javax/swing/text/DefaultCaret.java b/jdk/src/share/classes/javax/swing/text/DefaultCaret.java index ecbfdf0d6f4..464fff6822e 100644 --- a/jdk/src/share/classes/javax/swing/text/DefaultCaret.java +++ b/jdk/src/share/classes/javax/swing/text/DefaultCaret.java @@ -1326,7 +1326,7 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) { return; } - if (this.dot != this.mark && component != null) { + if (this.dot != this.mark && component != null && component.hasFocus()) { Clipboard clip = getSystemSelection(); if (clip != null) { String selectedText; diff --git a/jdk/test/javax/swing/JTextArea/7049024/bug7049024.java b/jdk/test/javax/swing/JTextArea/7049024/bug7049024.java new file mode 100644 index 00000000000..e6398b2f07c --- /dev/null +++ b/jdk/test/javax/swing/JTextArea/7049024/bug7049024.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2011 Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * Portions Copyright (c) 2011 IBM Corporation + */ + +/* @test + * @bug 7049024 + * @summary DnD fails with JTextArea and JTextField + * @author Sean Chou + */ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import javax.swing.text.DefaultCaret; +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; + +public class bug7049024 { + public static Clipboard clipboard = null; + + public static JTextField textField = null; + + // This button is used to move focus away from textField. + public static JButton button = null; + + public static JFrame frame = null; + + public static DefaultCaret caret = null; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame = new JFrame("Test"); + textField = new JTextField("test selection for textfield"); + button = new JButton("To compete the focus"); + + frame.setLayout(new FlowLayout()); + frame.getContentPane().add(textField); + frame.getContentPane().add(button); + + frame.pack(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + }); + toolkit.realSync(); + + clipboard = textField.getToolkit().getSystemSelection(); + if (null == clipboard) { + return; + } + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + textField.requestFocusInWindow(); + } + }); + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + caret = (DefaultCaret) textField.getCaret(); + caret.setDot(2); + caret.moveDot(4); + } + }); + toolkit.realSync(); + + String oldSelection = (String) clipboard.getData(DataFlavor.stringFlavor); + System.out.println("oldSelection is " + oldSelection); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + button.requestFocusInWindow(); + } + }); + toolkit.realSync(); // So JTextField loses the focus. + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + caret.setDot(4); + caret.moveDot(6); + } + }); + toolkit.realSync(); + + String newSelection = (String) clipboard.getData(DataFlavor.stringFlavor); + System.out.println("newSelection is " + newSelection); + + boolean passed = newSelection.equals(oldSelection); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.dispose(); + } + }); + + if (!passed) { + throw new RuntimeException("The test for bug 7049024 failed"); + } + } +} From bd73f1cc1d21831afb09ea298abe159c22b5bb8f Mon Sep 17 00:00:00 2001 From: Alexandr Scherbatiy Date: Thu, 3 Nov 2011 14:14:36 +0400 Subject: [PATCH 10/13] 6955919: Intermittent ClassCastException in bug4492274 test Reviewed-by: rupashka --- .../swing/JEditorPane/4492274/bug4492274.java | 111 ++++++++++++++++++ .../javax/swing/JEditorPane/4492274/test.html | 7 ++ 2 files changed, 118 insertions(+) create mode 100644 jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java create mode 100644 jdk/test/javax/swing/JEditorPane/4492274/test.html diff --git a/jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java b/jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java new file mode 100644 index 00000000000..cf732a9c5f2 --- /dev/null +++ b/jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + * @bug 4492274 + * @summary Tests if JEditorPane.getPage() correctly returns anchor reference. + * @author Denis Sharypov + */ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import javax.swing.text.html.HTMLEditorKit; +import java.awt.*; +import java.io.File; +import java.net.URL; + +public class bug4492274 { + + private static URL page; + + private static JEditorPane jep; + + public static void main(String args[]) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try { + page = new URL(page, "#linkname"); + jep.setPage(page); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + + toolkit.realSync(); + + if (getPageAnchor() == null) { + throw new RuntimeException("JEditorPane.getPage() returns null anchor reference"); + } + + } + + private static String getPageAnchor() throws Exception { + final String[] result = new String[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + result[0] = jep.getPage().getRef(); + } + }); + + return result[0]; + } + + private static void createAndShowGUI() { + try { + File file = new File(System.getProperty("test.src", "."), "test.html"); + page = file.toURI().toURL(); + + JFrame f = new JFrame(); + + jep = new JEditorPane(); + jep.setEditorKit(new HTMLEditorKit()); + jep.setEditable(false); + jep.setPage(page); + + JScrollPane sp = new JScrollPane(jep); + + f.getContentPane().add(sp); + f.setSize(500, 500); + f.setVisible(true); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/jdk/test/javax/swing/JEditorPane/4492274/test.html b/jdk/test/javax/swing/JEditorPane/4492274/test.html new file mode 100644 index 00000000000..2186cc326c8 --- /dev/null +++ b/jdk/test/javax/swing/JEditorPane/4492274/test.html @@ -0,0 +1,7 @@ + + +top + +bottom + + From 16b47aa1774a3c3d0c2887f94edab4d21a1e2230 Mon Sep 17 00:00:00 2001 From: Charles Lee Date: Thu, 13 Oct 2011 13:02:37 +0100 Subject: [PATCH 11/13] 7107957: AWT: Native code should include fcntl.h and unistd.h rather than sys/fcntl.h and sys/unistd.h Use POSIX defined includes for unistd.h and fcntl.h Reviewed-by: anthony, ngmr --- .../solaris/native/sun/awt/splashscreen/splashscreen_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/solaris/native/sun/awt/splashscreen/splashscreen_config.h b/jdk/src/solaris/native/sun/awt/splashscreen/splashscreen_config.h index bb031656aee..e312c2bc6dc 100644 --- a/jdk/src/solaris/native/sun/awt/splashscreen/splashscreen_config.h +++ b/jdk/src/solaris/native/sun/awt/splashscreen/splashscreen_config.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include From a346c5d21d0754eb9773be8bcb30b02e640bfe94 Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Mon, 7 Nov 2011 16:50:41 +0400 Subject: [PATCH 12/13] 7080203: JTree.getSelectionPaths() now returns empty array instead of null Reviewed-by: malenkov --- jdk/src/share/classes/javax/swing/JTree.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/javax/swing/JTree.java b/jdk/src/share/classes/javax/swing/JTree.java index 13a40562ebe..c5ca4b6dc70 100644 --- a/jdk/src/share/classes/javax/swing/JTree.java +++ b/jdk/src/share/classes/javax/swing/JTree.java @@ -1838,7 +1838,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * nodes, or null if nothing is currently selected */ public TreePath[] getSelectionPaths() { - return getSelectionModel().getSelectionPaths(); + TreePath[] selectionPaths = getSelectionModel().getSelectionPaths(); + + return (selectionPaths != null && selectionPaths.length > 0) ? selectionPaths : null; } /** From 856768a6c088ecb15649058e56d9384e629d2e0f Mon Sep 17 00:00:00 2001 From: Alexandr Scherbatiy Date: Tue, 8 Nov 2011 14:36:50 +0300 Subject: [PATCH 13/13] 7107585: Test incorrect calculate position of object on frame Reviewed-by: rupashka --- .../swing/JSlider/6348946/bug6348946.java | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 jdk/test/javax/swing/JSlider/6348946/bug6348946.java diff --git a/jdk/test/javax/swing/JSlider/6348946/bug6348946.java b/jdk/test/javax/swing/JSlider/6348946/bug6348946.java new file mode 100644 index 00000000000..7183debcb5e --- /dev/null +++ b/jdk/test/javax/swing/JSlider/6348946/bug6348946.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6348946 + * @summary Tests that JSlider's thumb moves in the right direction + * when it is used as a JTable cell editor. + * @author Mikhail Lapshin +*/ + +import sun.awt.SunToolkit; + +import java.awt.*; +import java.awt.event.InputEvent; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.table.*; + +public class bug6348946 { + + private static JFrame frame; + + private static JPanel panel; + + private static volatile boolean passed = false; + + public static void main(String[] args) throws Exception { + String lf = "javax.swing.plaf.metal.MetalLookAndFeel"; + UIManager.setLookAndFeel(lf); + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + setupUI(); + } + }); + toolkit.realSync(); + clickOnSlider(); + toolkit.realSync(); + checkResult(); + } finally { + stopEDT(); + } + } + + private static void setupUI() { + frame = new JFrame(); + + panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.add(new ParameterTable(), BorderLayout.CENTER); + frame.getContentPane().add(panel); + + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private static void clickOnSlider() throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(10); + + Rectangle rect = getPanelRectangle(); + + double clickX = rect.getX() + rect.getWidth() / 4; + double clickY = rect.getY() + rect.getHeight() / 2; + robot.mouseMove((int) clickX, (int) clickY); + + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + private static void checkResult(){ + if (passed) { + System.out.println("Test passed"); + } else { + throw new RuntimeException("The thumb moved " + + "to the right instead of the left!"); + } + } + + private static void stopEDT() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.dispose(); + } + }); + } + + private static class ParameterTable extends JTable { + public ParameterTable() { + super(new Object[][]{{5}}, new String[]{"Value"}); + getColumnModel().getColumn(0).setCellRenderer(new Renderer()); + getColumnModel().getColumn(0).setCellEditor(new Editor()); + } + } + + private static class Renderer implements TableCellRenderer { + private JSlider slider = new JSlider(0, 10); + + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, int col) { + int val = (Integer) value; + slider.setValue(val); + return slider; + } + } + + private static class Editor extends AbstractCellEditor implements TableCellEditor { + private JSlider slider = new JSlider(0, 10); + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, + int row, int col) { + int val = (Integer) value; + slider.setValue(val); + return slider; + } + + public Editor() { + slider.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + if (!slider.getValueIsAdjusting()) { + passed = slider.getValue() <= 5; + } + } + }); + } + + public Object getCellEditorValue() { + return slider.getValue(); + } + } + + private static Rectangle getPanelRectangle() throws Exception{ + final Rectangle[] result = new Rectangle[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + result[0] = new Rectangle(panel.getLocationOnScreen(), panel.getSize()); + } + }); + + return result[0]; + } +}