From 1409c46772b02ec91ec81456a42b605beefef769 Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Wed, 17 Dec 2014 14:58:58 +0300 Subject: [PATCH 01/41] 6219960: null reference in ToolTipManager Reviewed-by: serb, azvegint --- .../classes/javax/swing/ToolTipManager.java | 5 +- .../swing/JToolTip/6219960/bug6219960.java | 210 ++++++++++++++++++ 2 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 jdk/test/javax/swing/JToolTip/6219960/bug6219960.java diff --git a/jdk/src/java.desktop/share/classes/javax/swing/ToolTipManager.java b/jdk/src/java.desktop/share/classes/javax/swing/ToolTipManager.java index b127284be09..9bb7f00f14b 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/ToolTipManager.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/ToolTipManager.java @@ -28,6 +28,7 @@ package javax.swing; import java.awt.event.*; import java.awt.*; +import java.util.Objects; /** * Manages all the ToolTips in the system. @@ -476,8 +477,8 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener preferredLocation.equals(newPreferredLocation) : (newPreferredLocation == null); - if (!sameComponent || !toolTipText.equals(newToolTipText) || - !sameLoc) { + if (!sameComponent || !Objects.equals(toolTipText, newToolTipText) + || !sameLoc) { toolTipText = newToolTipText; preferredLocation = newPreferredLocation; showTipWindow(); diff --git a/jdk/test/javax/swing/JToolTip/6219960/bug6219960.java b/jdk/test/javax/swing/JToolTip/6219960/bug6219960.java new file mode 100644 index 00000000000..c23fa2c8472 --- /dev/null +++ b/jdk/test/javax/swing/JToolTip/6219960/bug6219960.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2014, 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. + */ + +import java.awt.Component; +import java.awt.Container; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.AWTException; +import java.awt.IllegalComponentStateException; +import java.awt.event.InputEvent; +import javax.swing.JButton; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.ToolTipManager; +import javax.swing.table.DefaultTableModel; + +/** + * @test + * @bug 6219960 + * @summary null reference in ToolTipManager + * @run main bug6219960 + */ +public class bug6219960 { + + private static final String QUESTION = "Question"; + + static volatile JFrame frame; + static JTable table; + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + SwingUtilities.invokeAndWait(bug6219960::createAndShowGUI); + robot.waitForIdle(); + showModal("The tooltip should be showing. Press ok with mouse. And don't move it."); + robot.waitForIdle(); + showModal("Now press ok and move the mouse inside the table (don't leave it)."); + robot.waitForIdle(); + } + + private static void createAndShowGUI() { + ToolTipManager.sharedInstance().setDismissDelay(10 * 60 * 1000); + frame = new JFrame(); + frame.setLocation(20, 20); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JDesktopPane desk = new JDesktopPane(); + JInternalFrame iframe = new JInternalFrame(); + iframe.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); + desk.add(iframe); + JButton save = new JButton(); + save.setToolTipText("Wait for dialog to show."); + save.setText("Wait for the tooltip to show."); + JPanel panel = new JPanel(new GridLayout(1, 2)); + panel.add(save); + table = createTable(); + panel.add(new JScrollPane(table)); + iframe.setContentPane(panel); + frame.getContentPane().add(desk); + frame.setSize(800, 600); + iframe.setSize(640, 480); + iframe.validate(); + iframe.setVisible(true); + frame.validate(); + frame.setVisible(true); + try { + iframe.setSelected(true); + } catch (Exception e) { + throw new AssertionError(e); + } + + try { + Robot robot = new Robot(); + Rectangle bounds = frame.getBounds(); + int centerX = (int) (bounds.getX() + bounds.getWidth() / 6); + int centerY = (int) (bounds.getY() + bounds.getHeight() / 6); + robot.mouseMove(centerX, centerY); + } catch (AWTException e) { + throw new RuntimeException(e); + } + } + + private static void showModal(final String msg) throws Exception { + + new Thread(() -> { + + int timeout = 3000; + long endTime = System.currentTimeMillis() + timeout; + + while (System.currentTimeMillis() <= endTime) { + if (pressOK(frame)) { + return; + } + } + throw new RuntimeException("Internal frame has not been found!"); + }).start(); + + Thread.sleep(900); + + SwingUtilities.invokeAndWait(() -> { + JOptionPane.showInternalMessageDialog(table, msg, + QUESTION, + JOptionPane.PLAIN_MESSAGE); + }); + } + + private static JTable createTable() { + DefaultTableModel model = new DefaultTableModel(); + JTable table = new JTable(model); + table.setFillsViewportHeight(true); + return table; + } + + private static boolean pressOK(Component comp) { + + JInternalFrame internalFrame + = findModalInternalFrame(comp, QUESTION); + + if (internalFrame == null) { + return false; + } + + JButton button = (JButton) findButton(internalFrame); + + if (button == null) { + return false; + } + + try { + Robot robot = new Robot(); + Point location = button.getLocationOnScreen(); + Rectangle bounds = button.getBounds(); + int centerX = (int) (location.getX() + bounds.getWidth() / 2); + int centerY = (int) (location.getY() + bounds.getHeight() / 2); + robot.mouseMove(centerX, centerY); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } catch (IllegalComponentStateException ignore) { + return false; + } catch (AWTException e) { + throw new RuntimeException(e); + } + return true; + } + + private static JInternalFrame findModalInternalFrame(Component comp, String title) { + + if (comp instanceof JInternalFrame) { + JInternalFrame internalFrame = (JInternalFrame) comp; + if (internalFrame.getTitle().equals(title)) { + return (JInternalFrame) comp; + } + } + + if (comp instanceof Container) { + Container cont = (Container) comp; + for (int i = 0; i < cont.getComponentCount(); i++) { + JInternalFrame result = findModalInternalFrame(cont.getComponent(i), title); + if (result != null) { + return result; + } + } + } + return null; + } + + private static JButton findButton(Component comp) { + + if (comp instanceof JButton) { + return (JButton) comp; + } + + if (comp instanceof Container) { + Container cont = (Container) comp; + for (int i = 0; i < cont.getComponentCount(); i++) { + JButton result = findButton(cont.getComponent(i)); + if (result != null) { + return result; + } + } + } + return null; + } +} From e047f11b3bbc6ce2ccef964adb3ca30c75691d63 Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Wed, 17 Dec 2014 17:56:11 +0300 Subject: [PATCH 02/41] 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F Reviewed-by: serb --- .../swing/plaf/windows/WindowsButtonUI.java | 3 +- .../swing/JButton/4796987/bug4796987.java | 102 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 jdk/test/javax/swing/JButton/4796987/bug4796987.java diff --git a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java index 0ea400d53da..89a2a18e115 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java +++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java @@ -248,7 +248,8 @@ public class WindowsButtonUI extends BasicButtonUI Part part = getXPButtonType(b); - if (b.isContentAreaFilled() && xp != null) { + if (b.isContentAreaFilled() && b.getBorder() != null + && b.isBorderPainted() && xp != null) { Skin skin = xp.getSkin(b, part); diff --git a/jdk/test/javax/swing/JButton/4796987/bug4796987.java b/jdk/test/javax/swing/JButton/4796987/bug4796987.java new file mode 100644 index 00000000000..ac41799da61 --- /dev/null +++ b/jdk/test/javax/swing/JButton/4796987/bug4796987.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2013, 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 4796987 + * @summary XP Only: JButton.setBorderPainted() does not work with XP L&F + * @author Alexander Scherbatiy + * @library ../../regtesthelpers + * @build Util + * @run main bug4796987 + */ + +import java.awt.*; +import javax.swing.*; +import sun.awt.OSInfo; +import sun.awt.SunToolkit; +import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; + +public class bug4796987 { + + private static JButton button1; + private static JButton button2; + + public static void main(String[] args) throws Exception { + if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS + && OSInfo.getWindowsVersion() == OSInfo.WINDOWS_XP) { + UIManager.setLookAndFeel(new WindowsLookAndFeel()); + testButtonBorder(); + } + } + + private static void testButtonBorder() throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + Thread.sleep(500); + + Point p1 = Util.getCenterPoint(button1); + Point p2 = Util.getCenterPoint(button2); + + Color color = robot.getPixelColor(p1.x, p2.x); + for (int dx = p1.x; dx < p2.x - p1.x; dx++) { + robot.mouseMove(p1.x + dx, p1.y); + if (!color.equals(robot.getPixelColor(p1.x + dx, p1.y))) { + throw new RuntimeException("Button has border and background!"); + } + } + } + + private static JButton getButton() { + JButton button = new JButton(); + button.setBorderPainted(false); + button.setFocusable(false); + return button; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(200, 200); + + JButton button = new JButton(); + button.setBorder(null); + + JPanel panel = new JPanel(new BorderLayout(50, 50)); + panel.add(getButton(), BorderLayout.CENTER); + panel.add(button1 = getButton(), BorderLayout.WEST); + panel.add(button2 = getButton(), BorderLayout.EAST); + frame.getContentPane().add(panel); + frame.setVisible(true); + } +} From d5a220d6737bbd0a3cc22e15b5fe19ea8e974f94 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 25 Dec 2014 14:43:49 +0300 Subject: [PATCH 03/41] 7180976: Pending String deadlocks UIDefaults Reviewed-by: azvegint, alexsch --- .../share/classes/javax/swing/UIDefaults.java | 6 +-- .../swing/plaf/synth/DefaultSynthStyle.java | 4 +- .../swing/UIDefaults/7180976/Pending.java | 50 +++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 jdk/test/javax/swing/UIDefaults/7180976/Pending.java diff --git a/jdk/src/java.desktop/share/classes/javax/swing/UIDefaults.java b/jdk/src/java.desktop/share/classes/javax/swing/UIDefaults.java index 82e4e2e5103..95cdb149aa9 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/UIDefaults.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/UIDefaults.java @@ -44,9 +44,7 @@ import java.awt.Font; import java.awt.Color; import java.awt.Insets; import java.awt.Dimension; -import java.lang.reflect.Method; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; import java.security.AccessController; import java.security.AccessControlContext; import java.security.PrivilegedAction; @@ -76,7 +74,7 @@ import sun.util.CoreResourceBundleControl; @SuppressWarnings("serial") // Same-version serialization only public class UIDefaults extends Hashtable { - private static final Object PENDING = "Pending"; + private static final Object PENDING = new Object(); private SwingPropertyChangeSupport changeSupport; @@ -170,7 +168,7 @@ public class UIDefaults extends Hashtable * Looks up the given key in our Hashtable and resolves LazyValues * or ActiveValues. */ - private Object getFromHashtable(Object key) { + private Object getFromHashtable(final Object key) { /* Quickly handle the common case, without grabbing * a lock. */ diff --git a/jdk/src/java.desktop/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java b/jdk/src/java.desktop/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java index 4906d6ba14c..8829f369460 100644 --- a/jdk/src/java.desktop/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java +++ b/jdk/src/java.desktop/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java @@ -28,7 +28,6 @@ import javax.swing.plaf.synth.*; import java.awt.*; import java.util.*; import javax.swing.*; -import javax.swing.border.Border; import javax.swing.plaf.*; /** @@ -44,7 +43,8 @@ import javax.swing.plaf.*; * @author Scott Violet */ public class DefaultSynthStyle extends SynthStyle implements Cloneable { - private static final String PENDING = "Pending"; + + private static final Object PENDING = new Object(); /** * Should the component be opaque? diff --git a/jdk/test/javax/swing/UIDefaults/7180976/Pending.java b/jdk/test/javax/swing/UIDefaults/7180976/Pending.java new file mode 100644 index 00000000000..23ece57ebb0 --- /dev/null +++ b/jdk/test/javax/swing/UIDefaults/7180976/Pending.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, 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. + */ + +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +/** + * @test + * @bug 7180976 + * @author Sergey Bylokhov + */ +public final class Pending implements Runnable { + + private static volatile boolean passed; + + public static void main(final String[] args) throws Exception { + SwingUtilities.invokeLater(new Pending()); + Thread.sleep(10000); + if (!passed) { + throw new RuntimeException("Test failed"); + } + } + + @Override + public void run() { + UIManager.put("foobar", "Pending"); + UIManager.get("foobar"); + passed = true; + } +} \ No newline at end of file From 6a1f047a778c22f187d609ba16b7945d2f076e54 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 25 Dec 2014 14:54:32 +0300 Subject: [PATCH 04/41] 8067657: Dead/outdated links in Javadoc of package java.beans Reviewed-by: azvegint, prr --- jdk/src/java.desktop/share/classes/java/beans/package.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/java/beans/package.html b/jdk/src/java.desktop/share/classes/java/beans/package.html index 2b68012cee5..81a9cdafd7b 100644 --- a/jdk/src/java.desktop/share/classes/java/beans/package.html +++ b/jdk/src/java.desktop/share/classes/java/beans/package.html @@ -1,5 +1,5 @@ don't test defines max and min in + // terms of preferred + runTest(new JScrollPane()); + runTest(new JViewport()); + runTest(new JSplitPane()); + runTest(new JTabbedPane()); + runTest(new JToolBar()); + runTest(new JSeparator()); + runTest(new JProgressBar()); + if (!failures.isEmpty()) { + System.out.println("These classes failed"); + for (final Component failure : failures) { + System.out.println(failure.getClass()); + } + throw new RuntimeException("Test failed"); + } + } + + public void runTest(final Component c) { + try { + test(c); + c.setMinimumSize(new Dimension(100, 10)); + c.setMaximumSize(new Dimension(200, 20)); + c.setPreferredSize(new Dimension(300, 30)); + test(c); + } catch (final Throwable ignored) { + failures.add(c); + } + } + + public void test(final Component component) { + final Dimension psize = component.getPreferredSize(); + psize.width += 200; + if (Objects.equals(psize, component.getPreferredSize())) { + throw new RuntimeException("PreferredSize is wrong"); + } + final Dimension msize = component.getMaximumSize(); + msize.width += 200; + if (Objects.equals(msize, component.getMaximumSize())) { + throw new RuntimeException("MaximumSize is wrong"); + } + final Dimension misize = component.getMinimumSize(); + misize.width += 200; + if (Objects.equals(misize, component.getMinimumSize())) { + throw new RuntimeException("MinimumSize is wrong"); + } + } + + private static void setLookAndFeel(final LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println("LookAndFeel: " + laf.getClassName()); + } catch (ClassNotFoundException | InstantiationException | + UnsupportedLookAndFeelException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file From c604e674ee9baa0fdc921590735513a63b783edd Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 21 Jan 2015 18:04:49 +0300 Subject: [PATCH 24/41] 7056797: The test failed automatically,because throw a ArrayIndexOutOfBoundsException Reviewed-by: azvegint, alexsch --- .../swing/JTabbedPane/4209065/bug4209065.html | 35 ++++++++++++ .../swing/JTabbedPane/4209065/bug4209065.java | 57 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.html create mode 100644 jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.java diff --git a/jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.html b/jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.html new file mode 100644 index 00000000000..5737912f130 --- /dev/null +++ b/jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.html @@ -0,0 +1,35 @@ + + + + + + + + diff --git a/jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.java b/jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.java new file mode 100644 index 00000000000..c2e2c14d7d8 --- /dev/null +++ b/jdk/test/javax/swing/JTabbedPane/4209065/bug4209065.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1999, 2015, 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. + */ + +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JApplet; +import javax.swing.JLabel; +import javax.swing.JTabbedPane; + +/** + * @test + * @bug 4209065 + * @author Georges Saab + * @run applet/manual=yesno bug4209065.html + */ +public final class bug4209065 extends JApplet { + + @Override + public void init() { + try { + EventQueue.invokeAndWait(this::createTabbedPane); + } catch (InterruptedException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + private void createTabbedPane() { + JTabbedPane tp = new JTabbedPane(); + getContentPane().add(tp); + String text = "
If the style of the text on the tabs matches" + + "
the descriptions, press PASS
"; + tp.addTab("
big
", new JLabel(text)); + tp.addTab("
red
", new JLabel(text)); + tp.addTab("
Bold Italic!
", new JLabel(text)); + } +} From 00949632cd5242ab947ca3b483da0c0a892ae1ba Mon Sep 17 00:00:00 2001 From: Mikhail Cherkasov Date: Thu, 22 Jan 2015 17:42:17 +0400 Subject: [PATCH 25/41] 8065709: Deadlock in awt/logging apparently introduced by 8019623 Reviewed-by: ant, serb --- .../share/classes/java/awt/EventQueue.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/java/awt/EventQueue.java b/jdk/src/java.desktop/share/classes/java/awt/EventQueue.java index c398db77fdc..620c3c4ece8 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/EventQueue.java +++ b/jdk/src/java.desktop/share/classes/java/awt/EventQueue.java @@ -182,7 +182,14 @@ public class EventQueue { private FwDispatcher fwDispatcher; - private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue"); + private static volatile PlatformLogger eventLog; + + private static final PlatformLogger getEventLog() { + if(eventLog == null) { + eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue"); + } + return eventLog; + } static { AWTAccessor.setEventQueueAccessor( @@ -762,8 +769,8 @@ public class EventQueue { dispatchThread.stopDispatching(); } } else { - if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { - eventLog.fine("Unable to dispatch event: " + event); + if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { + getEventLog().fine("Unable to dispatch event: " + event); } } } @@ -860,8 +867,8 @@ public class EventQueue { * @since 1.2 */ public void push(EventQueue newEventQueue) { - if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { - eventLog.fine("EventQueue.push(" + newEventQueue + ")"); + if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { + getEventLog().fine("EventQueue.push(" + newEventQueue + ")"); } pushPopLock.lock(); @@ -886,8 +893,8 @@ public class EventQueue { // Use getNextEventPrivate() as it doesn't call flushPendingEvents() newEventQueue.postEventPrivate(topQueue.getNextEventPrivate()); } catch (InterruptedException ie) { - if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { - eventLog.fine("Interrupted push", ie); + if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { + getEventLog().fine("Interrupted push", ie); } } } @@ -925,8 +932,8 @@ public class EventQueue { * @since 1.2 */ protected void pop() throws EmptyStackException { - if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { - eventLog.fine("EventQueue.pop(" + this + ")"); + if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { + getEventLog().fine("EventQueue.pop(" + this + ")"); } pushPopLock.lock(); @@ -948,8 +955,8 @@ public class EventQueue { try { prevQueue.postEventPrivate(topQueue.getNextEventPrivate()); } catch (InterruptedException ie) { - if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { - eventLog.fine("Interrupted pop", ie); + if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { + getEventLog().fine("Interrupted pop", ie); } } } From d34b9b430ca28e1dc0fc4eb1c283c084d47b2468 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Fri, 23 Jan 2015 13:47:46 +0300 Subject: [PATCH 26/41] 7185221: [macosx] Regtest should not throw exception if a suitable display mode found Reviewed-by: azvegint, ant --- .../NonExistentDisplayModeTest.java | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 jdk/test/java/awt/FullScreen/NonExistentDisplayModeTest/NonExistentDisplayModeTest.java diff --git a/jdk/test/java/awt/FullScreen/NonExistentDisplayModeTest/NonExistentDisplayModeTest.java b/jdk/test/java/awt/FullScreen/NonExistentDisplayModeTest/NonExistentDisplayModeTest.java new file mode 100644 index 00000000000..5387391f5e6 --- /dev/null +++ b/jdk/test/java/awt/FullScreen/NonExistentDisplayModeTest/NonExistentDisplayModeTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2006, 2015, 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. + */ + +import java.awt.DisplayMode; +import java.awt.Frame; +import java.awt.GraphicsDevice; +import java.util.ArrayList; +import java.util.Random; + +import static java.awt.DisplayMode.REFRESH_RATE_UNKNOWN; + +/** + * @test + * @bug 6430607 + * @summary Test that we throw an exception for incorrect display modes + * @author Dmitri.Trembovetski@Sun.COM area=FullScreen + * @run main/othervm NonExistentDisplayModeTest + * @run main/othervm -Dsun.java2d.noddraw=true NonExistentDisplayModeTest + * @run main/othervm -Dsun.java2d.opengl=true NonExistentDisplayModeTest + */ +public class NonExistentDisplayModeTest { + + public static void main(String[] args) { + new NonExistentDisplayModeTest().start(); + } + + private void start() { + Frame f = new Frame("Testing, please wait.."); + f.pack(); + GraphicsDevice gd = f.getGraphicsConfiguration().getDevice(); + if (!gd.isFullScreenSupported()) { + System.out.println("Exclusive FS mode not supported, test passed."); + f.dispose(); + return; + } + + gd.setFullScreenWindow(f); + if (!gd.isDisplayChangeSupported()) { + System.out.println("DisplayMode change not supported, test passed."); + f.dispose(); + return; + } + + DisplayMode dms[] = gd.getDisplayModes(); + ArrayList dmList = new ArrayList(dms.length); + for (DisplayMode dm : dms) { + dmList.add(dm); + } + + ArrayList nonExistentDms = createNonExistentDMList(dmList); + + for (DisplayMode dm : nonExistentDms) { + boolean exThrown = false; + try { + System.out.printf("Testing mode: (%4dx%4d) depth=%3d rate=%d\n", + dm.getWidth(), dm.getHeight(), + dm.getBitDepth(), dm.getRefreshRate()); + gd.setDisplayMode(dm); + } catch (IllegalArgumentException e) { + exThrown = true; + } + if (!exThrown) { + gd.setFullScreenWindow(null); + f.dispose(); + throw new + RuntimeException("Failed: No exception thrown for dm "+dm); + } + } + gd.setFullScreenWindow(null); + f.dispose(); + System.out.println("Test passed."); + } + + private static final Random rnd = new Random(); + private ArrayList + createNonExistentDMList(ArrayList dmList) + { + ArrayList newList = + new ArrayList(dmList.size()); + // vary one parameter at a time + int param = 0; + for (DisplayMode dm : dmList) { + param = ++param % 3; + switch (param) { + case 0: { + DisplayMode newDM = deriveSize(dm); + if (!dmList.contains(newDM)) { + newList.add(newDM); + } + break; + } + case 1: { + DisplayMode newDM = deriveDepth(dm); + if (!dmList.contains(newDM)) { + newList.add(newDM); + } + break; + } + case 2: { + if (dm.getRefreshRate() != REFRESH_RATE_UNKNOWN) { + DisplayMode newDM = deriveRR(dm); + if (!dmList.contains(newDM)) { + newList.add(newDM); + } + } + break; + } + } + } + return newList; + } + + private static DisplayMode deriveSize(DisplayMode dm) { + int w = dm.getWidth() / 7; + int h = dm.getHeight() / 3; + return new DisplayMode(w, h, dm.getBitDepth(), dm.getRefreshRate()); + } + private static DisplayMode deriveRR(DisplayMode dm) { + return new DisplayMode(dm.getWidth(), dm.getHeight(), + dm.getBitDepth(), 777); + } + private static DisplayMode deriveDepth(DisplayMode dm) { + int depth; + if (dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) { + depth = 77; + } else { + depth = DisplayMode.BIT_DEPTH_MULTI; + } + return new DisplayMode(dm.getWidth(), dm.getHeight(), + depth, dm.getRefreshRate()); + } +} From fda56d3c54b1b130620d98f4da96f2af884641b7 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Sun, 25 Jan 2015 15:53:46 -0800 Subject: [PATCH 27/41] 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name Reviewed-by: bae, serb --- .../macosx/classes/sun/font/CFont.java | 68 ++++++- .../macosx/classes/sun/font/CFontManager.java | 39 +++- .../macosx/native/libawt_lwawt/font/AWTFont.m | 60 +++++-- .../share/classes/sun/font/Font2D.java | 15 ++ .../share/classes/sun/font/FontFamily.java | 113 +++++++++++- .../share/classes/sun/font/TrueTypeFont.java | 21 ++- .../java/awt/FontClass/HelvLtOblTest.java | 166 ++++++++++++++++++ 7 files changed, 460 insertions(+), 22 deletions(-) create mode 100644 jdk/test/java/awt/FontClass/HelvLtOblTest.java diff --git a/jdk/src/java.desktop/macosx/classes/sun/font/CFont.java b/jdk/src/java.desktop/macosx/classes/sun/font/CFont.java index 0173bfc9d23..c88e53c0663 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/font/CFont.java +++ b/jdk/src/java.desktop/macosx/classes/sun/font/CFont.java @@ -77,14 +77,72 @@ public final class CFont extends PhysicalFont { } private static native long createNativeFont(final String nativeFontName, - final int style, - final boolean isFakeItalic); + final int style); private static native void disposeNativeFont(final long nativeFontPtr); private boolean isFakeItalic; private String nativeFontName; private long nativeFontPtr; + private native float getWidthNative(final long nativeFontPtr); + private native float getWeightNative(final long nativeFontPtr); + + private int fontWidth = -1; + private int fontWeight = -1; + + @Override + public int getWidth() { + if (fontWidth == -1) { + // Apple use a range of -1 -> +1, where 0.0 is normal + // OpenType uses a % range from 50% -> 200% where 100% is normal + // and maps these onto the integer values 1->9. + // Since that is what Font2D.getWidth() expects, remap to that. + float fw = getWidthNative(getNativeFontPtr()); + if (fw == 0.0) { // short cut the common case + fontWidth = Font2D.FWIDTH_NORMAL; + return fontWidth; + } + fw += 1.0; fw *= 100.0; + if (fw <= 50.0) { + fontWidth = 1; + } else if (fw <= 62.5) { + fontWidth = 2; + } else if (fw <= 75.0) { + fontWidth = 3; + } else if (fw <= 87.5) { + fontWidth = 4; + } else if (fw <= 100.0) { + fontWidth = 5; + } else if (fw <= 112.5) { + fontWidth = 6; + } else if (fw <= 125.0) { + fontWidth = 7; + } else if (fw <= 150.0) { + fontWidth = 8; + } else { + fontWidth = 9; + } + } + return fontWidth; + } + + @Override + public int getWeight() { + if (fontWeight == -1) { + // Apple use a range of -1 -> +1, where 0 is medium/regular + // Map this on to the OpenType range of 100->900 where + // 500 is medium/regular. + // We'll actually map to 0->1000 but that's close enough. + float fw = getWeightNative(getNativeFontPtr()); + if (fw == 0) { + return Font2D.FWEIGHT_NORMAL; + } + fw += 1.0; fw *= 500; + fontWeight = (int)fw; + } + return fontWeight; + } + // this constructor is called from CFontWrapper.m public CFont(String name) { this(name, name); @@ -94,10 +152,11 @@ public final class CFont extends PhysicalFont { handle = new Font2DHandle(this); fullName = name; familyName = inFamilyName; - nativeFontName = inFamilyName; + nativeFontName = fullName; setStyle(); } + /* Called from CFontManager too */ public CFont(CFont other, String logicalFamilyName) { handle = new Font2DHandle(this); fullName = logicalFamilyName; @@ -109,6 +168,7 @@ public final class CFont extends PhysicalFont { public CFont createItalicVariant() { CFont font = new CFont(this, familyName); + font.nativeFontName = fullName; font.fullName = fullName + (style == Font.BOLD ? "" : "-") + "Italic-Derived"; font.style |= Font.ITALIC; @@ -118,7 +178,7 @@ public final class CFont extends PhysicalFont { protected synchronized long getNativeFontPtr() { if (nativeFontPtr == 0L) { - nativeFontPtr = createNativeFont(nativeFontName, style, isFakeItalic); + nativeFontPtr = createNativeFont(nativeFontName, style); } return nativeFontPtr; } diff --git a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java index 28c59712fe7..e37e9e449ea 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java +++ b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java @@ -252,13 +252,42 @@ public final class CFontManager extends SunFontManager { final CFont font = new CFont(fontName, fontFamilyName); registerGenericFont(font); + } - if ((font.getStyle() & Font.ITALIC) == 0) { - registerGenericFont(font.createItalicVariant(), true); + void registerItalicDerived() { + FontFamily[] famArr = FontFamily.getAllFontFamilies(); + for (int i=0; i() { public Object run() { - loadNativeFonts(); + if (!loadedAllFonts) { + loadNativeFonts(); + registerItalicDerived(); + loadedAllFonts = true; + } return null; } } diff --git a/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m b/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m index 0adeff0de06..bfb90ec6a59 100644 --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m @@ -35,15 +35,11 @@ #import "AWTStrike.h" #import "CoreTextSupport.h" - -#define DEBUG - @implementation AWTFont -- (id) initWithFont:(NSFont *)font isFakeItalic:(BOOL)isFakeItalic { +- (id) initWithFont:(NSFont *)font { self = [super init]; if (self) { - fIsFakeItalic = isFakeItalic; fFont = [font retain]; fNativeCGFont = CTFontCopyGraphicsFont((CTFontRef)font, NULL); } @@ -72,7 +68,6 @@ + (AWTFont *) awtFontForName:(NSString *)name style:(int)style - isFakeItalic:(BOOL)isFakeItalic { // create font with family & size NSFont *nsFont = [NSFont fontWithName:name size:1.0]; @@ -95,7 +90,7 @@ nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask]; } - return [[[AWTFont alloc] initWithFont:nsFont isFakeItalic:isFakeItalic] autorelease]; + return [[[AWTFont alloc] initWithFont:nsFont] autorelease]; } + (NSFont *) nsFontForJavaFont:(jobject)javaFont env:(JNIEnv *)env { @@ -354,7 +349,7 @@ JNF_COCOA_EXIT(env); JNIEXPORT jlong JNICALL Java_sun_font_CFont_createNativeFont (JNIEnv *env, jclass clazz, - jstring nativeFontName, jint style, jboolean isFakeItalic) + jstring nativeFontName, jint style) { AWTFont *awtFont = nil; @@ -362,8 +357,7 @@ JNF_COCOA_ENTER(env); awtFont = [AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName) - style:style - isFakeItalic:isFakeItalic]; // autoreleased + style:style]; // autoreleased if (awtFont) { CFRetain(awtFont); // GC @@ -374,6 +368,52 @@ JNF_COCOA_EXIT(env); return ptr_to_jlong(awtFont); } +/* + * Class: sun_font_CFont + * Method: getWidthNative + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL +Java_sun_font_CFont_getWidthNative + (JNIEnv *env, jobject cfont, jlong awtFontPtr) +{ + float widthVal; +JNF_COCOA_ENTER(env); + + AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr); + NSFont* nsFont = awtFont->fFont; + NSFontDescriptor *fontDescriptor = nsFont.fontDescriptor; + NSDictionary *fontTraits = [fontDescriptor objectForKey : NSFontTraitsAttribute]; + NSNumber *width = [fontTraits objectForKey : NSFontWidthTrait]; + widthVal = (float)[width floatValue]; + +JNF_COCOA_EXIT(env); + return (jfloat)widthVal; +} + +/* + * Class: sun_font_CFont + * Method: getWeightNative + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL +Java_sun_font_CFont_getWeightNative + (JNIEnv *env, jobject cfont, jlong awtFontPtr) +{ + float weightVal; +JNF_COCOA_ENTER(env); + + AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr); + NSFont* nsFont = awtFont->fFont; + NSFontDescriptor *fontDescriptor = nsFont.fontDescriptor; + NSDictionary *fontTraits = [fontDescriptor objectForKey : NSFontTraitsAttribute]; + NSNumber *weight = [fontTraits objectForKey : NSFontWeightTrait]; + weightVal = (float)[weight floatValue]; + +JNF_COCOA_EXIT(env); + return (jfloat)weightVal; +} + /* * Class: sun_font_CFont * Method: disposeNativeFont diff --git a/jdk/src/java.desktop/share/classes/sun/font/Font2D.java b/jdk/src/java.desktop/share/classes/sun/font/Font2D.java index 6fa3ca45e92..e1c7c912e3d 100644 --- a/jdk/src/java.desktop/share/classes/sun/font/Font2D.java +++ b/jdk/src/java.desktop/share/classes/sun/font/Font2D.java @@ -157,6 +157,21 @@ public abstract class Font2D { } } + public static final int FWIDTH_NORMAL = 5; // OS/2 usWidthClass + public static final int FWEIGHT_NORMAL = 400; // OS/2 usWeightClass + public static final int FWEIGHT_BOLD = 700; // OS/2 usWeightClass + + public int getWidth() { + return FWIDTH_NORMAL; + } + + public int getWeight() { + if ((style & Font.BOLD) !=0) { + return FWEIGHT_BOLD; + } else { + return FWEIGHT_NORMAL; + } + } int getRank() { return fontRank; diff --git a/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java b/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java index 6a4cd2552f9..b450f86930b 100644 --- a/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java +++ b/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java @@ -27,6 +27,7 @@ package sun.font; import java.io.File; import java.awt.Font; +import java.util.Collection; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.Locale; @@ -134,7 +135,98 @@ public class FontFamily { return java.util.Objects.equals(newDir, existDir); } + /* + * We want a family to be of the same width and prefer medium/normal width. + * Once we find a particular width we accept more of the same width + * until we find one closer to normal when we 'evict' all existing fonts. + * So once we see a 'normal' width font we evict all members that are not + * normal width and then accept only new ones that are normal width. + * + * Once a font passes the width test we subject it to the weight test. + * For Plain we target the weight the closest that is <= NORMAL (400) + * For Bold we target the weight that is closest to BOLD (700). + * + * In the future, rather than discarding these fonts, we should + * extend the family to include these so lookups on these properties + * can locate them, as presently they will only be located by full name + * based lookup. + */ + + private int familyWidth = 0; + private boolean preferredWidth(Font2D font) { + + int newWidth = font.getWidth(); + + if (familyWidth == 0) { + familyWidth = newWidth; + return true; + } + + if (newWidth == familyWidth) { + return true; + } + + if (Math.abs(Font2D.FWIDTH_NORMAL - newWidth) < + Math.abs(Font2D.FWIDTH_NORMAL - familyWidth)) + { + if (FontUtilities.debugFonts()) { + FontUtilities.getLogger().info( + "Found more preferred width. New width = " + newWidth + + " Old width = " + familyWidth + " in font " + font + + " nulling out fonts plain: " + plain + " bold: " + bold + + " italic: " + italic + " bolditalic: " + bolditalic); + } + familyWidth = newWidth; + plain = bold = italic = bolditalic = null; + return true; + } else if (FontUtilities.debugFonts()) { + FontUtilities.getLogger().info( + "Family rejecting font " + font + + " of less preferred width " + newWidth); + } + return false; + } + + private boolean closerWeight(Font2D currFont, Font2D font, int style) { + if (familyWidth != font.getWidth()) { + return false; + } + + if (currFont == null) { + return true; + } + + if (FontUtilities.debugFonts()) { + FontUtilities.getLogger().info( + "New weight for style " + style + ". Curr.font=" + currFont + + " New font="+font+" Curr.weight="+ + currFont.getWeight()+ + " New weight="+font.getWeight()); + } + + int newWeight = font.getWeight(); + switch (style) { + case Font.PLAIN: + case Font.ITALIC: + return (newWeight <= Font2D.FWEIGHT_NORMAL && + newWeight > currFont.getWeight()); + + case Font.BOLD: + case Font.BOLD|Font.ITALIC: + return (Math.abs(newWeight - Font2D.FWEIGHT_BOLD) < + Math.abs(currFont.getWeight() - Font2D.FWEIGHT_BOLD)); + + default: + return false; + } + } + public void setFont(Font2D font, int style) { + + if (FontUtilities.isLogging()) { + FontUtilities.getLogger().info( + "Request to add " + font + " with style " + style + + " to family " + this); + } /* Allow a lower-rank font only if its a file font * from the exact same source as any previous font. */ @@ -152,19 +244,27 @@ public class FontFamily { switch (style) { case Font.PLAIN: - plain = font; + if (preferredWidth(font) && closerWeight(plain, font, style)) { + plain = font; + } break; case Font.BOLD: - bold = font; + if (preferredWidth(font) && closerWeight(bold, font, style)) { + bold = font; + } break; case Font.ITALIC: - italic = font; + if (preferredWidth(font) && closerWeight(italic, font, style)) { + italic = font; + } break; case Font.BOLD|Font.ITALIC: - bolditalic = font; + if (preferredWidth(font) && closerWeight(bolditalic, font, style)) { + bolditalic = font; + } break; default: @@ -316,6 +416,11 @@ public class FontFamily { return allLocaleNames.get(name.toLowerCase()); } + public static FontFamily[] getAllFontFamilies() { + Collection families = familyNameMap.values(); + return families.toArray(new FontFamily[0]); + } + public String toString() { return "Font family: " + familyName + diff --git a/jdk/src/java.desktop/share/classes/sun/font/TrueTypeFont.java b/jdk/src/java.desktop/share/classes/sun/font/TrueTypeFont.java index 047a9309095..0e8647cc734 100644 --- a/jdk/src/java.desktop/share/classes/sun/font/TrueTypeFont.java +++ b/jdk/src/java.desktop/share/classes/sun/font/TrueTypeFont.java @@ -963,6 +963,18 @@ public class TrueTypeFont extends FileFont { setStyle(getTableBuffer(os_2Tag)); } + private int fontWidth = 0; + @Override + public int getWidth() { + return (fontWidth > 0) ? fontWidth : super.getWidth(); + } + + private int fontWeight = 0; + @Override + public int getWeight() { + return (fontWeight > 0) ? fontWeight : super.getWeight(); + } + /* TrueTypeFont can use the fsSelection fields of OS/2 table * to determine the style. In the unlikely case that doesn't exist, * can use macStyle in the 'head' table but simpler to @@ -978,8 +990,15 @@ public class TrueTypeFont extends FileFont { private static final int fsSelectionBoldBit = 0x00020; private static final int fsSelectionRegularBit = 0x00040; private void setStyle(ByteBuffer os_2Table) { + if (os_2Table == null) { + return; + } + if (os_2Table.capacity() >= 8) { + fontWeight = os_2Table.getChar(4) & 0xffff; + fontWidth = os_2Table.getChar(6) & 0xffff; + } /* fsSelection is unsigned short at buffer offset 62 */ - if (os_2Table == null || os_2Table.capacity() < 64) { + if (os_2Table.capacity() < 64) { super.setStyle(); return; } diff --git a/jdk/test/java/awt/FontClass/HelvLtOblTest.java b/jdk/test/java/awt/FontClass/HelvLtOblTest.java new file mode 100644 index 00000000000..bc88d381f9e --- /dev/null +++ b/jdk/test/java/awt/FontClass/HelvLtOblTest.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2015, 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 8064833 + * @summary Test correct font is obtained via famil+style + * @run main HelvLtOblTest + */ + +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; +import java.awt.RenderingHints; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.image.BufferedImage; + +public class HelvLtOblTest extends JComponent { + + static Font helvFont = null; + + static int[] codes = { 0x23, 0x4a, 0x48, 0x3, 0x4a, 0x55, 0x42, 0x4d, + 0x4a, 0x44, 0x3, + 0x53, 0x46, 0x45, 0x3, 0x55, 0x46, 0x59, 0x55, }; + + static String str = "Big italic red text"; + + public static void main(String[] args) throws Exception { + String os = System.getProperty("os.name"); + if (!os.startsWith("Mac")) { + return; + } + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + Font[] fonts = ge.getAllFonts(); + for (int i=0; i { + JFrame f = new JFrame(); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.add("Center", test); + f.pack(); + f.setVisible(true); + }); + test.compareImages(); + } + + public Dimension getPreferredSize() { + return new Dimension(400,400); + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D)g; + FontRenderContext frc = new FontRenderContext(null, true, true); + Font f = helvFont.deriveFont(Font.PLAIN, 40); + System.out.println("font = " +f.getFontName()); + GlyphVector gv = f.createGlyphVector(frc, codes); + g.setFont(f); + g.setColor(Color.white); + g.fillRect(0,0,400,400); + g.setColor(Color.black); + g2.drawGlyphVector(gv, 5,200); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g2.drawString(str, 5, 250); + } + + void compareImages() { + BufferedImage bi0 = drawText(false); + BufferedImage bi1 = drawText(true); + compare(bi0, bi1); + } + + BufferedImage drawText(boolean doGV) { + int w = 400; + int h = 50; + BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics2D g = bi.createGraphics(); + g.setColor(Color.white); + g.fillRect(0,0,w,h); + g.setColor(Color.black); + Font f = helvFont.deriveFont(Font.PLAIN, 40); + g.setFont(f); + int x = 5; + int y = h - 10; + if (doGV) { + FontRenderContext frc = new FontRenderContext(null, true, true); + GlyphVector gv = f.createGlyphVector(frc, codes); + g.drawGlyphVector(gv, 5, y); + } else { + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.drawString(str, x, y); + } + return bi; + } + + // Need to allow for minimal rounding error, so allow each component + // to differ by 1. + void compare(BufferedImage bi0, BufferedImage bi1) { + int wid = bi0.getWidth(); + int hgt = bi0.getHeight(); + for (int x=0; x> 16; + int r1 = (rgb1 & 0xff0000) >> 16; + int rdiff = r0-r1; if (rdiff<0) rdiff = -rdiff; + int g0 = (rgb0 & 0x00ff00) >> 8; + int g1 = (rgb1 & 0x00ff00) >> 8; + int gdiff = g0-g1; if (gdiff<0) gdiff = -gdiff; + int b0 = (rgb0 & 0x0000ff); + int b1 = (rgb1 & 0x0000ff); + int bdiff = b0-b1; if (bdiff<0) bdiff = -bdiff; + if (rdiff > 1 || gdiff > 1 || bdiff > 1) { + throw new RuntimeException( + "Images differ at x=" + x + " y="+ y + " " + + Integer.toHexString(rgb0) + " vs " + + Integer.toHexString(rgb1)); + } + } + } + } + +} From cfe8daa596d70a43a2f0a463a74348450d9c9313 Mon Sep 17 00:00:00 2001 From: Alexander Zvegintsev Date: Mon, 26 Jan 2015 12:37:20 +0300 Subject: [PATCH 28/41] 8071483: Possible case-folding collision for color/Color subdirectories of jdk/test/java/awt/ Reviewed-by: rriggs, serb --- jdk/test/java/awt/{color => Color}/LoadProfileWithSM.java | 0 jdk/test/java/awt/{color => Color}/LoadStandardProfilesTest.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename jdk/test/java/awt/{color => Color}/LoadProfileWithSM.java (100%) rename jdk/test/java/awt/{color => Color}/LoadStandardProfilesTest.java (100%) diff --git a/jdk/test/java/awt/color/LoadProfileWithSM.java b/jdk/test/java/awt/Color/LoadProfileWithSM.java similarity index 100% rename from jdk/test/java/awt/color/LoadProfileWithSM.java rename to jdk/test/java/awt/Color/LoadProfileWithSM.java diff --git a/jdk/test/java/awt/color/LoadStandardProfilesTest.java b/jdk/test/java/awt/Color/LoadStandardProfilesTest.java similarity index 100% rename from jdk/test/java/awt/color/LoadStandardProfilesTest.java rename to jdk/test/java/awt/Color/LoadStandardProfilesTest.java From deeb4faa8024b875c85c7f2b9277b84b2d00250e Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Mon, 26 Jan 2015 16:32:47 +0300 Subject: [PATCH 29/41] 8069015: Re-examine Solaris/Linux java.desktop dependency on java.logging Reviewed-by: azvegint, ant --- .../classes/sun/awt/X11/XAWTFormatter.java | 150 ------------------ .../classes/sun/awt/X11/XEmbeddedFrame.java | 12 +- 2 files changed, 7 insertions(+), 155 deletions(-) delete mode 100644 jdk/src/java.desktop/unix/classes/sun/awt/X11/XAWTFormatter.java diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XAWTFormatter.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XAWTFormatter.java deleted file mode 100644 index 198d7a79508..00000000000 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XAWTFormatter.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2014, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package sun.awt.X11; - -import java.util.logging.*; -import java.text.*; -import java.util.*; -import java.io.*; - -/** - * Formatter class providing ANSI output. Based on java.util.logging.SimpleFormatter sources. - */ - -public class XAWTFormatter extends java.util.logging.Formatter { - Date dat = new Date(); - private final static String format = "{0,date} {0,time}"; - private MessageFormat formatter; - - private Object args[] = new Object[1]; - - // Line separator string. This is the value of the line.separator - // property at the moment that the SimpleFormatter was created. - private String lineSeparator = System.lineSeparator(); - - boolean displayFullRecord = false; - boolean useANSI = false; - boolean showDate = true; - boolean showLevel = true; - boolean swapMethodClass = false; - public XAWTFormatter() { - displayFullRecord = "true".equals(LogManager.getLogManager().getProperty("XAWTFormatter.displayFullRecord")); - useANSI = "true".equals(LogManager.getLogManager().getProperty("XAWTFormatter.useANSI")); - showDate = !"false".equals(LogManager.getLogManager().getProperty("XAWTFormatter.showDate")); - showLevel = !"false".equals(LogManager.getLogManager().getProperty("XAWTFormatter.showLevel")); - swapMethodClass = "true".equals(LogManager.getLogManager().getProperty("XAWTFormatter.swapMethodClass")); - } - - /** - * Format the given LogRecord. - * @param record the log record to be formatted. - * @return a formatted log record - */ - public synchronized String format(LogRecord record) { - StringBuffer sb = new StringBuffer(); - if (useANSI) { - Level lev = record.getLevel(); - if (Level.FINEST.equals(lev)) { - sb.append(""); - } else if (Level.FINER.equals(lev)) { - sb.append(""); - } else if (Level.FINE.equals(lev)) { - sb.append(""); - } - } - if (displayFullRecord) { - if (showDate) { - // Minimize memory allocations here. - dat.setTime(record.getMillis()); - args[0] = dat; - StringBuffer text = new StringBuffer(); - if (formatter == null) { - formatter = new MessageFormat(format); - } - formatter.format(args, text, null); - sb.append(text); - sb.append(" "); - } else { - sb.append(" "); - } - if (swapMethodClass) { - if (record.getSourceMethodName() != null) { - sb.append(" "); - sb.append(record.getSourceMethodName()); - sb.append(" "); - } - if (record.getSourceClassName() != null) { - sb.append(record.getSourceClassName()); - } else { - sb.append(record.getLoggerName()); - } - } else { - if (record.getSourceClassName() != null) { - sb.append(record.getSourceClassName()); - } else { - sb.append(record.getLoggerName()); - } - if (record.getSourceMethodName() != null) { - sb.append(" "); - sb.append(record.getSourceMethodName()); - sb.append(""); - } - } - sb.append(lineSeparator); - } - if (useANSI) { - Level lev = record.getLevel(); - if (Level.FINEST.equals(lev)) { - sb.append(""); - } else if (Level.FINER.equals(lev)) { - sb.append(""); - } else if (Level.FINE.equals(lev)) { - sb.append(""); - } - } - if (showLevel) { - sb.append(record.getLevel().getLocalizedName()); - sb.append(": "); - } - String message = formatMessage(record); - sb.append(message); - sb.append(lineSeparator); - if (record.getThrown() != null) { - try { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - record.getThrown().printStackTrace(pw); - pw.close(); - sb.append(sw.toString()); - } catch (Exception ex) { - } - } - if (useANSI) { - sb.append(""); - } - return sb.toString(); - } -} diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbeddedFrame.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbeddedFrame.java index 489558b18bd..9b9431893cb 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbeddedFrame.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbeddedFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -25,15 +25,17 @@ package sun.awt.X11; -import sun.awt.EmbeddedFrame; -import java.awt.*; import java.awt.AWTKeyStroke; -import java.util.logging.Logger; +import java.awt.Toolkit; + +import sun.awt.EmbeddedFrame; +import sun.util.logging.PlatformLogger; @SuppressWarnings("serial") // JDK-implementation class public class XEmbeddedFrame extends EmbeddedFrame { - private static final Logger log = Logger.getLogger(XEmbeddedFrame.class.getName()); + private static final PlatformLogger log = + PlatformLogger.getLogger(XEmbeddedFrame.class.getName()); long handle; public XEmbeddedFrame() { From 8dd67e74592ebd16ca1c660e3f3f16d69d3a9514 Mon Sep 17 00:00:00 2001 From: Shobhit Gupta Date: Thu, 29 Jan 2015 14:03:23 +0300 Subject: [PATCH 30/41] 8068292: [TEST_BUG] Test javax/swing/JLayer/6824395/bug6824395.java fails with -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel Reviewed-by: alexsch, azvegint --- jdk/test/javax/swing/JLayer/6824395/bug6824395.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/test/javax/swing/JLayer/6824395/bug6824395.java b/jdk/test/javax/swing/JLayer/6824395/bug6824395.java index f2040f4b327..fd35608d478 100644 --- a/jdk/test/javax/swing/JLayer/6824395/bug6824395.java +++ b/jdk/test/javax/swing/JLayer/6824395/bug6824395.java @@ -59,7 +59,7 @@ public class bug6824395 { editorPaneLayer.setUI(layerUI); scrollPane = new JScrollPane(editorPaneLayer); - + scrollPane.setViewportBorder(null); scrollPane.setPreferredSize(new Dimension(200, 250)); frame.add(scrollPane); From 8717474863e78daeb8e212d74c9e624bbd3b2721 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 29 Jan 2015 09:34:05 -0800 Subject: [PATCH 31/41] 8071710: [solaris] libfontmanager should be linked against headless awt library Reviewed-by: ihse, erikj --- jdk/make/lib/Awt2dLibraries.gmk | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk index fca33420271..a20b85b59c1 100644 --- a/jdk/make/lib/Awt2dLibraries.gmk +++ b/jdk/make/lib/Awt2dLibraries.gmk @@ -562,10 +562,6 @@ ifeq ($(OPENJDK_TARGET_OS), linux) BUILD_LIBFONTMANAGER_ExtensionSubtables.cpp_CXXFLAGS := -fno-strict-aliasing endif -# Libfontmanager doesn't actually need X_LIBS to link, but if building -# on a Solaris machine without X installed, using a devkit, linking -# to libawt_xawt will fail without the -L parameters from X_LIBS. Filter -# out the -R parameters since they aren't needed. $(eval $(call SetupNativeCompilation,BUILD_LIBFONTMANAGER, \ LIBRARY := fontmanager, \ OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ @@ -583,9 +579,8 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBFONTMANAGER, \ LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_SUFFIX := $(BUILD_LIBFONTMANAGER_FONTLIB), \ LDFLAGS_SUFFIX_linux := -lawt $(LIBM) $(LIBCXX) -ljava -ljvm -lc, \ - LDFLAGS_SUFFIX_solaris := $(filter-out -R%, $(X_LIBS)) \ - -lawt -lawt_xawt -lc $(LIBM) $(LIBCXX) -ljava -ljvm, \ - LDFLAGS_SUFFIX_aix := -lawt -lawt_xawt $(LIBM) $(LIBCXX) -ljava -ljvm,\ + LDFLAGS_SUFFIX_solaris := -lawt -lawt_headless -lc $(LIBM) $(LIBCXX) -ljava -ljvm, \ + LDFLAGS_SUFFIX_aix := -lawt -lawt_headless $(LIBM) $(LIBCXX) -ljava -ljvm,\ LDFLAGS_SUFFIX_macosx := -lawt $(LIBM) $(LIBCXX) -undefined dynamic_lookup \ -ljava -ljvm, \ LDFLAGS_SUFFIX_windows := $(WIN_JAVA_LIB) advapi32.lib user32.lib gdi32.lib \ @@ -601,7 +596,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBFONTMANAGER, \ $(BUILD_LIBFONTMANAGER): $(BUILD_LIBAWT) ifneq (, $(findstring $(OPENJDK_TARGET_OS), solaris aix)) - $(BUILD_LIBFONTMANAGER): $(BUILD_LIBAWT_XAWT) + $(BUILD_LIBFONTMANAGER): $(BUILD_LIBAWT_HEADLESS) endif TARGETS += $(BUILD_LIBFONTMANAGER) From 7c658a76106f0ff5ca203128236e134a473fd23b Mon Sep 17 00:00:00 2001 From: Shobhit Gupta Date: Fri, 30 Jan 2015 13:27:33 +0300 Subject: [PATCH 32/41] 8068301: [TEST_BUG] Test javax/swing/JColorChooser/Test4177735.java fails with ArrayIndexOutOfBoundsException with GTKL&F Reviewed-by: alexsch, azvegint --- jdk/test/javax/swing/JColorChooser/Test4177735.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jdk/test/javax/swing/JColorChooser/Test4177735.java b/jdk/test/javax/swing/JColorChooser/Test4177735.java index 84e77300571..338bf99bf25 100644 --- a/jdk/test/javax/swing/JColorChooser/Test4177735.java +++ b/jdk/test/javax/swing/JColorChooser/Test4177735.java @@ -38,9 +38,20 @@ public class Test4177735 implements Runnable { private static final long DELAY = 1000L; public static void main(String[] args) throws Exception { + int hsvIndex = 0; + int panelsLength; + int finalIndex; JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); - chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] }); + panelsLength = panels.length; + + for(int i = 0; i < panelsLength; i++) { + if(panels[i].getDisplayName().equals("HSV")) { + hsvIndex = i; + } + } + finalIndex = Math.min(hsvIndex, panelsLength - 1); + chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[finalIndex] }); JDialog dialog = show(chooser); pause(DELAY); From afa1e6d6706d74251ec0ad8ab35139fb57b0299b Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Mon, 2 Feb 2015 18:21:24 +0300 Subject: [PATCH 33/41] 8015085: [macosx] Label shortening via " ... " broken when String contains combining diaeresis Reviewed-by: alexsch, azvegint --- .../classes/sun/swing/SwingUtilities2.java | 12 +-- .../TestBadBreak/TestBadBreak.java | 92 +++++++++++++++++++ 2 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 jdk/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java diff --git a/jdk/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java b/jdk/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java index 10e4e3bfa7f..3953297184c 100644 --- a/jdk/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java +++ b/jdk/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -31,6 +31,7 @@ import static java.awt.RenderingHints.*; import java.awt.event.*; import java.awt.font.*; import java.awt.print.PrinterGraphics; +import java.text.BreakIterator; import java.text.CharacterIterator; import java.text.AttributedCharacterIterator; import java.text.AttributedString; @@ -461,16 +462,15 @@ public class SwingUtilities2 { } } if (needsTextLayout) { - FontRenderContext frc = getFontRenderContext(c, fm); AttributedString aString = new AttributedString(string); if (c != null) { aString.addAttribute(TextAttribute.NUMERIC_SHAPING, c.getClientProperty(TextAttribute.NUMERIC_SHAPING)); } - LineBreakMeasurer measurer = - new LineBreakMeasurer(aString.getIterator(), frc); - int nChars = measurer.nextOffset(availTextWidth); - string = string.substring(0, nChars); + LineBreakMeasurer measurer = new LineBreakMeasurer( + aString.getIterator(), BreakIterator.getCharacterInstance(), + getFontRenderContext(c, fm)); + string = string.substring(0, measurer.nextOffset(availTextWidth)); } return string + clipString; diff --git a/jdk/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java b/jdk/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java new file mode 100644 index 00000000000..59806a33a0a --- /dev/null +++ b/jdk/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; + +import javax.imageio.ImageIO; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; + +import static java.awt.image.BufferedImage.TYPE_INT_ARGB; + +/** + * @test + * @bug 8015085 + * @summary Shortening via " ... " is broken for Strings containing a combining + * diaeresis. + * @author Sergey Bylokhov + */ +public class TestBadBreak { + + static JFrame frame; + static Robot robot; + static final String withCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/a\u0308" ; + static final String withoutCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/\u00E4" ; + + public static void main(final String[] args) throws Exception { + robot = new Robot(); + final BufferedImage bi1 = new BufferedImage(200, 90, TYPE_INT_ARGB); + final BufferedImage bi2 = new BufferedImage(200, 90, TYPE_INT_ARGB); + test(withCombiningDiaeresis, bi1); + test(withoutCombiningDiaeresis, bi2); + for (int x = 0; x < bi1.getWidth(); ++x) { + for (int y = 0; y < bi1.getHeight(); ++y) { + if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { + ImageIO.write(bi1, "png", new File("image1.png")); + ImageIO.write(bi2, "png", new File("image2.png")); + throw new RuntimeException("Wrong color"); + } + } + } + } + + private static void test(final String text, final BufferedImage i1) + throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame = new JFrame(); + final JLabel label = new JLabel(text) { + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2d = i1.createGraphics(); + super.paintComponent(g2d); + g2d.dispose(); + } + }; + frame.getContentPane().add(label); + frame.setBounds(200, 200, 200, 90); + } + }); + robot.waitForIdle(); + SwingUtilities.invokeAndWait(() -> frame.setVisible(true)); + robot.waitForIdle(); + SwingUtilities.invokeAndWait(frame::dispose); + robot.waitForIdle(); + } +} From 5a65a2cc13965dd52b1409936ed31a20fa0cc03f Mon Sep 17 00:00:00 2001 From: Dmitry Markov Date: Tue, 3 Feb 2015 11:51:30 +0400 Subject: [PATCH 34/41] 8064934: Incorrect Exception message from java.awt.Desktop.open() Reviewed-by: azvegint, serb --- .../native/libawt/windows/awt_Desktop.cpp | 3 +- .../java/awt/Desktop/8064934/bug8064934.java | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 jdk/test/java/awt/Desktop/8064934/bug8064934.java diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp index 828818bad4a..36b54670642 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp @@ -52,6 +52,7 @@ JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute // 6457572: ShellExecute possibly changes FPU control word - saving it here unsigned oldcontrol87 = _control87(0, 0); HINSTANCE retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL, SW_SHOWNORMAL); + DWORD error = ::GetLastError(); _control87(oldcontrol87, 0xffffffff); JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c); @@ -65,7 +66,7 @@ JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - (int)retval, + error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR)&buffer, 0, diff --git a/jdk/test/java/awt/Desktop/8064934/bug8064934.java b/jdk/test/java/awt/Desktop/8064934/bug8064934.java new file mode 100644 index 00000000000..8824f883cf5 --- /dev/null +++ b/jdk/test/java/awt/Desktop/8064934/bug8064934.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015, 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 8064934 + * @summary Incorrect Exception message from java.awt.Desktop.open() + * @author Dmitry Markov + * @run main bug8064934 + */ +import sun.awt.OSInfo; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.security.AccessController; + +public class bug8064934 { + private static final String NO_ASSOCIATION_ERROR_MESSAGE = "Error message: No application is associated with" + + " the specified file for this operation."; + + public static void main(String[] args) { + // This test is intended only for Windows + if (AccessController.doPrivileged(OSInfo.getOSTypeAction()) != OSInfo.OSType.WINDOWS) { + System.out.println("The test is for Windows platform only"); + return; + } + + // Test whether Desktop is supported of not + if (!Desktop.isDesktopSupported()) { + System.out.println("Desktop is not supported"); + return; + } + + Desktop desktop = Desktop.getDesktop(); + // Test whether open action is supported or not + if (!desktop.isSupported(Desktop.Action.OPEN)) { + System.out.println("Desktop.Action.OPEN is not supported"); + return; + } + + File file = null; + try { + file = File.createTempFile("test", ".foo"); + if (!file.exists()) { + throw new RuntimeException("Can not create temp file"); + } + desktop.open(file); + } catch (IOException ioe) { + String errorMessage = ioe.getMessage().trim(); + if (errorMessage != null && !errorMessage.endsWith(NO_ASSOCIATION_ERROR_MESSAGE)) { + throw new RuntimeException("Test FAILED! Wrong Error message: \n" + + "Actual " + errorMessage.substring(errorMessage.indexOf("Error message:")) + "\n" + + "Expected " + NO_ASSOCIATION_ERROR_MESSAGE); + } + } finally { + if (file != null) { + file.delete(); + } + } + + System.out.println("Test PASSED!"); + } +} From cec84ed1f2b5d2c20b1ce0d7805b5e169859ab75 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Tue, 3 Feb 2015 09:28:21 -0800 Subject: [PATCH 35/41] 8072116: [Solaris] : Fix for 8071710 needs to be updated for build dependency checking Reviewed-by: ihse --- jdk/make/lib/Awt2dLibraries.gmk | 142 ++++++++++++++++---------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk index a20b85b59c1..d7e50779625 100644 --- a/jdk/make/lib/Awt2dLibraries.gmk +++ b/jdk/make/lib/Awt2dLibraries.gmk @@ -515,6 +515,77 @@ TARGETS += $(BUILD_LIBJAVAJPEG) ################################################################################ +ifeq ($(BUILD_HEADLESS), true) + # Mac and Windows only use the native AWT lib, do not build libawt_headless + ifeq ($(findstring $(OPENJDK_TARGET_OS), windows macosx),) + + LIBAWT_HEADLESS_DIRS := $(JDK_TOPDIR)/src/java.desktop/unix/native/libawt_headless/awt \ + $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \ + $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/opengl \ + $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/x11 \ + $(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \ + $(JDK_TOPDIR)/src/java.desktop/share/native/common/font \ + # + + LIBAWT_HEADLESS_EXCLUDES := medialib + LIBAWT_HEADLESS_CFLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \ + $(addprefix -I, $(LIBAWT_HEADLESS_DIRS)) \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/loops \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/pipe \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image \ + -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/java2d \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/font \ + -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/awt/debug \ + -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/font \ + -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libsunwjdga/ \ + $(LIBJAVA_HEADER_FLAGS) \ + # + + LIBAWT_HEADLESS_REORDER := + ifeq ($(OPENJDK_TARGET_OS), solaris) + ifneq ($(OPENJDK_TARGET_CPU), x86_64) + LIBAWT_HEADLESS_REORDER := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/reorder-$(OPENJDK_TARGET_CPU) + endif + endif + + $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_HEADLESS, \ + LIBRARY := awt_headless, \ + OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ + SRC := $(LIBAWT_HEADLESS_DIRS), \ + EXCLUDES := $(LIBAWT_HEADLESS_EXCLUDES), \ + LANG := C, \ + OPTIMIZATION := LOW, \ + CFLAGS := $(CFLAGS_JDKLIB) \ + -DHEADLESS=true \ + -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \ + $(CUPS_CFLAGS) \ + $(X_CFLAGS) \ + $(LIBAWT_HEADLESS_CFLAGS), \ + MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/mapfile-vers, \ + LDFLAGS := $(LDFLAGS_JDKLIB) \ + $(call SET_SHARED_LIBRARY_ORIGIN), \ + LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ + LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \ + LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \ + LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN)., \ + REORDER := $(LIBAWT_HEADLESS_REORDER), \ + LDFLAGS_SUFFIX_linux := -ljvm -lawt -lm $(LIBDL) -ljava, \ + LDFLAGS_SUFFIX_aix := -ljvm -lawt -ljava,\ + LDFLAGS_SUFFIX_solaris := $(LIBDL) -ljvm -lawt -lm -ljava $(LIBCXX) -lc, \ + OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libawt_headless, \ + DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES))) + + $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT) + + TARGETS += $(BUILD_LIBAWT_HEADLESS) + + endif +endif + +################################################################################ + LIBFONTMANAGER_SRC := $(JDK_TOPDIR)/src/java.desktop/share/native/libfontmanager \ $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libfontmanager LIBFONTMANAGER_CFLAGS := \ @@ -718,77 +789,6 @@ TARGETS += $(BUILD_LIBJAWT) ################################################################################ -ifeq ($(BUILD_HEADLESS), true) - # Mac and Windows only use the native AWT lib, do not build libawt_headless - ifeq ($(findstring $(OPENJDK_TARGET_OS), windows macosx),) - - LIBAWT_HEADLESS_DIRS := $(JDK_TOPDIR)/src/java.desktop/unix/native/libawt_headless/awt \ - $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \ - $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/opengl \ - $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/x11 \ - $(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \ - $(JDK_TOPDIR)/src/java.desktop/share/native/common/font \ - # - - LIBAWT_HEADLESS_EXCLUDES := medialib - LIBAWT_HEADLESS_CFLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \ - $(addprefix -I, $(LIBAWT_HEADLESS_DIRS)) \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/loops \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/pipe \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image \ - -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/java2d \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/font \ - -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/awt/debug \ - -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/font \ - -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libsunwjdga/ \ - $(LIBJAVA_HEADER_FLAGS) \ - # - - LIBAWT_HEADLESS_REORDER := - ifeq ($(OPENJDK_TARGET_OS), solaris) - ifneq ($(OPENJDK_TARGET_CPU), x86_64) - LIBAWT_HEADLESS_REORDER := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/reorder-$(OPENJDK_TARGET_CPU) - endif - endif - - $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_HEADLESS, \ - LIBRARY := awt_headless, \ - OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ - SRC := $(LIBAWT_HEADLESS_DIRS), \ - EXCLUDES := $(LIBAWT_HEADLESS_EXCLUDES), \ - LANG := C, \ - OPTIMIZATION := LOW, \ - CFLAGS := $(CFLAGS_JDKLIB) \ - -DHEADLESS=true \ - -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \ - $(CUPS_CFLAGS) \ - $(X_CFLAGS) \ - $(LIBAWT_HEADLESS_CFLAGS), \ - MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/mapfile-vers, \ - LDFLAGS := $(LDFLAGS_JDKLIB) \ - $(call SET_SHARED_LIBRARY_ORIGIN), \ - LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ - LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \ - LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \ - LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN)., \ - REORDER := $(LIBAWT_HEADLESS_REORDER), \ - LDFLAGS_SUFFIX_linux := -ljvm -lawt -lm $(LIBDL) -ljava, \ - LDFLAGS_SUFFIX_aix := -ljvm -lawt -ljava,\ - LDFLAGS_SUFFIX_solaris := $(LIBDL) -ljvm -lawt -lm -ljava $(LIBCXX) -lc, \ - OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libawt_headless, \ - DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES))) - - $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT) - - TARGETS += $(BUILD_LIBAWT_HEADLESS) - - endif -endif - -################################################################################ - ifndef BUILD_HEADLESS_ONLY LIBSPLASHSCREEN_DIRS := \ From a75613049be8177abfaad709f1e9ddfe2d2647c4 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 4 Feb 2015 10:28:40 -0800 Subject: [PATCH 36/41] 6243376: JPEGImageWriter corrupts color for non-JFIF images with differing sample factor Reviewed-by: bae, serb --- .../imageio/plugins/jpeg/JPEGImageWriter.java | 2 +- .../imageio/plugins/jpeg/MagentaEXIFTest.java | 205 ++++++++++++++++++ 2 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 jdk/test/javax/imageio/plugins/jpeg/MagentaEXIFTest.java diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java index 477e6738b5f..b71c73fd54d 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java @@ -1652,7 +1652,7 @@ public class JPEGImageWriter extends ImageWriter { int vsamp0 = specs[0].VsamplingFactor; for (int i = 1; i < specs.length; i++) { if ((specs[i].HsamplingFactor != hsamp0) || - (specs[i].HsamplingFactor != hsamp0)) + (specs[i].VsamplingFactor != vsamp0)) return true; } return false; diff --git a/jdk/test/javax/imageio/plugins/jpeg/MagentaEXIFTest.java b/jdk/test/javax/imageio/plugins/jpeg/MagentaEXIFTest.java new file mode 100644 index 00000000000..8f3cfcf7929 --- /dev/null +++ b/jdk/test/javax/imageio/plugins/jpeg/MagentaEXIFTest.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2015, 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 8071707 6243376 + * @summary Test verifies that EXIF images with differing sampling factors + * are written correctly + * + * @run main MagentaEXIFTest + */ + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.metadata.IIOInvalidTreeException; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.metadata.IIOMetadataNode; +import javax.imageio.stream.ImageInputStream; +import javax.imageio.stream.ImageOutputStream; + +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public class MagentaEXIFTest { + + public static void main(final String[] argv) throws Exception { + + IIOMetadata jpegmetadata = null; + ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); + try { + jpegmetadata = createJPEGMetadata(jpgWriter); + } catch (Exception e) { + throw new RuntimeException(e); + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageOutputStream output = ImageIO.createImageOutputStream(baos); + jpgWriter.setOutput(output); + int w=100, h=100; + BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = bi.createGraphics(); + g2d.setColor(Color.white); + g2d.fillRect(0, 0, w, h); + IIOImage image = new IIOImage(bi, null, jpegmetadata); + jpgWriter.write(null, image, null); + jpgWriter.dispose(); + + baos.flush(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ImageInputStream iis = ImageIO.createImageInputStream(bais); + bi = ImageIO.read(iis); + for (int i=0; i"); // close current tag + while (child != null) { // emit child tags recursively + displayMetadata(child, level + 1); + child = child.getNextSibling(); + } + for (int i = 0; i < level; i++) System.out.print(" "); + System.out.println(""); + } else { + System.out.println("/>"); + } + } + + /* + * Construct a JPEG IIOMetadata that has had the JFIF marker removed and + * an APP1 EXIF marker added, and further massaged so that we have differing + * horizontal and vertical sampling factors for one channel. + */ + static IIOMetadata createJPEGMetadata(ImageWriter iw) throws IIOInvalidTreeException { + String jpegMDName = "javax_imageio_jpeg_image_1.0"; + ImageWriter imgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); + BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + ImageTypeSpecifier ist = new ImageTypeSpecifier(bi); + IIOMetadata metadata = imgWriter.getDefaultImageMetadata(ist, null); + + IIOMetadataNode root = new IIOMetadataNode(jpegMDName); + IIOMetadataNode header = new IIOMetadataNode("JPEGvariety"); + IIOMetadataNode sequence = new IIOMetadataNode("markerSequence"); + + root.appendChild(header); + root.appendChild(sequence); + + IIOMetadataNode app1 = new IIOMetadataNode("unknown"); + app1.setUserObject(new byte[255]); + app1.setAttribute("MarkerTag", "255"); + sequence.appendChild(app1); + + IIOMetadataNode sof = new IIOMetadataNode("sof"); + sof.setAttribute("process", "0"); + sof.setAttribute("samplePrecision", "8"); + sof.setAttribute("numLines", "100"); + sof.setAttribute("samplesPerLine", "100"); + sof.setAttribute("numFrameComponents", "3"); + IIOMetadataNode c1 = new IIOMetadataNode("componentSpec"); + c1.setAttribute("componentId", "1"); + c1.setAttribute("HsamplingFactor", "1"); + c1.setAttribute("VsamplingFactor", "2"); + c1.setAttribute("QtableSelector", "1"); + sof.appendChild(c1); + IIOMetadataNode c2 = new IIOMetadataNode("componentSpec"); + c2.setAttribute("componentId", "2"); + c2.setAttribute("HsamplingFactor", "1"); + c2.setAttribute("VsamplingFactor", "1"); + c2.setAttribute("QtableSelector", "1"); + sof.appendChild(c2); + IIOMetadataNode c3 = new IIOMetadataNode("componentSpec"); + c3.setAttribute("componentId", "3"); + c3.setAttribute("HsamplingFactor", "1"); + c3.setAttribute("VsamplingFactor", "1"); + c3.setAttribute("QtableSelector", "1"); + sof.appendChild(c3); + sequence.appendChild(sof); + metadata.setFromTree(jpegMDName, root); + IIOMetadata def = imgWriter.getDefaultImageMetadata(ist, null); + metadata.mergeTree(jpegMDName, def.getAsTree(jpegMDName)); + Node tree = metadata.getAsTree(jpegMDName); + Node variety = tree.getFirstChild(); + Node jfif = variety.getFirstChild(); + variety.removeChild(jfif); + sequence = (IIOMetadataNode)tree.getLastChild(); + NodeList markers = sequence.getChildNodes(); + IIOMetadataNode n, sofNode=null; + for (int i=0;i Date: Wed, 4 Feb 2015 10:29:51 -0800 Subject: [PATCH 37/41] 8072433: copy/paste duplicated tests in some condition statements Reviewed-by: bae, serb --- jdk/src/java.desktop/share/classes/sun/font/FontFamily.java | 2 +- jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java b/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java index b450f86930b..2b67e5122f6 100644 --- a/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java +++ b/jdk/src/java.desktop/share/classes/sun/font/FontFamily.java @@ -78,7 +78,7 @@ public class FontFamily { family.bolditalic = null; } if (family.plain == null && family.bold == null && - family.plain == null && family.bold == null) { + family.italic == null && family.bolditalic == null) { familyNameMap.remove(name); } } diff --git a/jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java b/jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java index dd99535251f..ece4f48ef97 100644 --- a/jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java +++ b/jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java @@ -1564,7 +1564,7 @@ public class ServiceDialog extends JDialog implements ActionListener { bmObj = bmTmpObj; } else { if (lmObj == null || rmObj == null || - tmObj == null || rmObj == null) { + tmObj == null || bmObj == null) { return; } else { leftMargin.setValue(lmObj); From d32000a7105450439c5b86f949b2e90cb5acb2e4 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 5 Feb 2015 14:20:05 +0300 Subject: [PATCH 38/41] 4952954: abort flag is not cleared for every write operation for JPEG ImageWriter Reviewed-by: bae, prr --- .../imageio/plugins/jpeg/JPEGImageWriter.java | 29 ++- .../plugins/shared/WriteAfterAbort.java | 212 ++++++++++++++++++ 2 files changed, 237 insertions(+), 4 deletions(-) create mode 100644 jdk/test/javax/imageio/plugins/shared/WriteAfterAbort.java diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java index b71c73fd54d..0daa7d38b79 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -43,8 +43,6 @@ import org.w3c.dom.Node; import java.awt.image.Raster; import java.awt.image.WritableRaster; -import java.awt.image.SampleModel; -import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; @@ -1048,7 +1046,13 @@ public class JPEGImageWriter extends ImageWriter { // Call the writer, who will call back for every scanline - processImageStarted(currentImage); + clearAbortRequest(); + cbLock.lock(); + try { + processImageStarted(currentImage); + } finally { + cbLock.unlock(); + } boolean aborted = false; @@ -1225,6 +1229,23 @@ public class JPEGImageWriter extends ImageWriter { } } + @Override + protected synchronized void clearAbortRequest() { + setThreadLock(); + try { + cbLock.check(); + if (abortRequested()) { + super.clearAbortRequest(); + // reset C structures + resetWriter(structPointer); + // reset the native destination + setDest(structPointer); + } + } finally { + clearThreadLock(); + } + } + private void resetInternalState() { // reset C structures resetWriter(structPointer); diff --git a/jdk/test/javax/imageio/plugins/shared/WriteAfterAbort.java b/jdk/test/javax/imageio/plugins/shared/WriteAfterAbort.java new file mode 100644 index 00000000000..4b503d2fe6f --- /dev/null +++ b/jdk/test/javax/imageio/plugins/shared/WriteAfterAbort.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Iterator; + +import javax.imageio.ImageIO; +import javax.imageio.ImageWriter; +import javax.imageio.event.IIOWriteProgressListener; +import javax.imageio.spi.IIORegistry; +import javax.imageio.spi.ImageWriterSpi; +import javax.imageio.stream.ImageOutputStream; + +import static java.awt.image.BufferedImage.TYPE_BYTE_BINARY; + +/** + * @test + * @bug 4952954 + * @summary abortFlag must be cleared for every ImageWriter.write operation + * @author Sergey Bylokhov + */ +public final class WriteAfterAbort implements IIOWriteProgressListener { + + private volatile boolean abortFlag = true; + private volatile boolean isAbortCalled; + private volatile boolean isCompleteCalled; + private volatile boolean isProgressCalled; + private volatile boolean isStartedCalled; + private static final int WIDTH = 100; + private static final int HEIGHT = 100; + + private void test(final ImageWriter writer) throws IOException { + // Image initialization + final BufferedImage imageWrite = new BufferedImage(WIDTH, HEIGHT, + TYPE_BYTE_BINARY); + final Graphics2D g = imageWrite.createGraphics(); + g.setColor(Color.WHITE); + g.fillRect(0, 0, WIDTH, HEIGHT); + g.dispose(); + + // File initialization + final File file = File.createTempFile("temp", ".img"); + file.deleteOnExit(); + final FileOutputStream fos = new SkipWriteOnAbortOutputStream(file); + final ImageOutputStream ios = ImageIO.createImageOutputStream(fos); + writer.setOutput(ios); + writer.addIIOWriteProgressListener(this); + + // This write will be aborted, and file will not be touched + writer.write(imageWrite); + if (!isStartedCalled) { + throw new RuntimeException("Started should be called"); + } + if (!isProgressCalled) { + throw new RuntimeException("Progress should be called"); + } + if (!isAbortCalled) { + throw new RuntimeException("Abort should be called"); + } + if (isCompleteCalled) { + throw new RuntimeException("Complete should not be called"); + } + // Flush aborted data + ios.flush(); + + // This write should be completed successfully and the file should + // contain correct image data. + abortFlag = false; + isAbortCalled = false; + isCompleteCalled = false; + isProgressCalled = false; + isStartedCalled = false; + writer.write(imageWrite); + + if (!isStartedCalled) { + throw new RuntimeException("Started should be called"); + } + if (!isProgressCalled) { + throw new RuntimeException("Progress should be called"); + } + if (isAbortCalled) { + throw new RuntimeException("Abort should not be called"); + } + if (!isCompleteCalled) { + throw new RuntimeException("Complete should be called"); + } + writer.dispose(); + ios.close(); + + // Validates content of the file. + final BufferedImage imageRead = ImageIO.read(file); + for (int x = 0; x < WIDTH; ++x) { + for (int y = 0; y < HEIGHT; ++y) { + if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) { + throw new RuntimeException("Test failed."); + } + } + } + } + + public static void main(final String[] args) throws IOException { + final IIORegistry registry = IIORegistry.getDefaultInstance(); + final Iterator iter = registry.getServiceProviders( + ImageWriterSpi.class, provider -> true, true); + + // Validates all supported ImageWriters + while (iter.hasNext()) { + final WriteAfterAbort writeAfterAbort = new WriteAfterAbort(); + final ImageWriter writer = iter.next().createWriterInstance(); + System.out.println("ImageWriter = " + writer); + writeAfterAbort.test(writer); + } + System.out.println("Test passed"); + } + + // Callbacks + + @Override + public void imageComplete(ImageWriter source) { + isCompleteCalled = true; + } + + @Override + public void imageProgress(ImageWriter source, float percentageDone) { + isProgressCalled = true; + if (percentageDone > 50 && abortFlag) { + source.abort(); + } + } + + @Override + public void imageStarted(ImageWriter source, int imageIndex) { + isStartedCalled = true; + } + + @Override + public void writeAborted(final ImageWriter source) { + isAbortCalled = true; + } + + @Override + public void thumbnailComplete(ImageWriter source) { + } + + @Override + public void thumbnailProgress(ImageWriter source, float percentageDone) { + } + + @Override + public void thumbnailStarted(ImageWriter source, int imageIndex, + int thumbnailIndex) { + } + + /** + * We need to skip writes on abort, because content of the file after abort + * is undefined. + */ + private class SkipWriteOnAbortOutputStream extends FileOutputStream { + + SkipWriteOnAbortOutputStream(File file) throws FileNotFoundException { + super(file); + } + + @Override + public void write(int b) throws IOException { + if (!abortFlag) { + super.write(b); + } + } + + @Override + public void write(byte[] b) throws IOException { + if (!abortFlag) { + super.write(b); + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (!abortFlag) { + super.write(b, off, len); + } + } + } +} + From 3cd8a07dc75753b00f85d56baf25c9f5ac636a72 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 5 Feb 2015 16:16:46 +0300 Subject: [PATCH 39/41] 8062738: Test java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug fails in Windows Reviewed-by: azvegint, ant --- .../share/classes/java/awt/datatransfer/SystemFlavorMap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java b/jdk/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java index 3dc096d235a..e6462146274 100644 --- a/jdk/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java +++ b/jdk/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -215,7 +215,7 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable { line = line.substring(0, line.length() - 1) + reader.readLine().trim(); } int delimiterPosition = line.indexOf('='); - String key = line.substring(0, delimiterPosition).replaceAll("\\ ", " "); + String key = line.substring(0, delimiterPosition).replace("\\ ", " "); String[] values = line.substring(delimiterPosition + 1, line.length()).split(","); for (String value : values) { try { From 47d0ae0d368fa0ed6d66478d5f2a3092026ff584 Mon Sep 17 00:00:00 2001 From: Alexander Zvegintsev Date: Mon, 2 Feb 2015 21:38:19 +0300 Subject: [PATCH 40/41] 8072088: [PIT] NPE in DnD tests apparently because of the fix to JDK-8061636 Reviewed-by: ant, prr, serb --- jdk/src/java.desktop/share/classes/java/awt/Container.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/java.desktop/share/classes/java/awt/Container.java b/jdk/src/java.desktop/share/classes/java/awt/Container.java index dbf60f849fc..86607534163 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Container.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Container.java @@ -4636,7 +4636,7 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { // drag has an associated drop target. MOUSE_ENTERED comes when the // mouse is in the native container already. To propagate this event // properly we should null out targetLastEntered. - targetLastEnteredDT = null; + targetLastEnteredDT.clear(); } else if (id == MouseEvent.MOUSE_ENTERED) { isMouseDTInNativeContainer = true; } else if (id == MouseEvent.MOUSE_EXITED) { From 67c555e0533ddb1caad85e6b5674138675611327 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Fri, 6 Feb 2015 19:49:20 +0300 Subject: [PATCH 41/41] 8063066: Some look and feels ignores the JSlider.PaintTrack property Reviewed-by: ant, azvegint, alexsch --- .../java.desktop/share/classes/javax/swing/JSlider.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java b/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java index 956c57a166c..5475d51ffc4 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -1287,10 +1287,10 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { return paintTrack; } - /** - * Determines whether the track is painted on the slider. - * By default, this property is {@code true}. + * Determines whether the track is painted on the slider. By default, this + * property is {@code true}. It is up to the look and feel to honor this + * property, some may choose to ignore it. * * @param b whether or not to paint the slider track * @see #getPaintTrack