From 861ba88c865e865b17d539495f4b612903c9dfe1 Mon Sep 17 00:00:00 2001 From: Alexander Zvegintsev Date: Tue, 4 Aug 2015 12:34:08 +0300 Subject: [PATCH 1/4] 8130400: Test java/awt/image/DrawImage/IncorrectClipXorModeSurface2Surface.java fails with ClassCastException Reviewed-by: prr, serb --- .../classes/sun/java2d/xr/XRDrawImage.java | 28 +++++++++++-------- .../IncorrectClipXorModeSurface2Surface.java | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/jdk/src/java.desktop/unix/classes/sun/java2d/xr/XRDrawImage.java b/jdk/src/java.desktop/unix/classes/sun/java2d/xr/XRDrawImage.java index ea8edbb391a..69502f2ee2a 100644 --- a/jdk/src/java.desktop/unix/classes/sun/java2d/xr/XRDrawImage.java +++ b/jdk/src/java.desktop/unix/classes/sun/java2d/xr/XRDrawImage.java @@ -46,24 +46,28 @@ public class XRDrawImage extends DrawImage { SurfaceData dstData = sg.surfaceData; SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor); - int compRule = ((AlphaComposite) sg.composite).getRule(); - float extraAlpha = ((AlphaComposite) sg.composite).getAlpha(); - if (srcData != null && !isBgOperation(srcData, bgColor) + if (sg.composite instanceof AlphaComposite) { + int compRule = ((AlphaComposite) sg.composite).getRule(); + float extraAlpha = ((AlphaComposite) sg.composite).getAlpha(); + + if (srcData != null && !isBgOperation(srcData, bgColor) && interpType <= AffineTransformOp.TYPE_BILINEAR && (XRUtils.isMaskEvaluated(XRUtils.j2dAlphaCompToXR(compRule)) - || (XRUtils.isTransformQuadrantRotated(tx)) && extraAlpha == 1.0f)) - { - SurfaceType srcType = srcData.getSurfaceType(); - SurfaceType dstType = dstData.getSurfaceType(); + || (XRUtils.isTransformQuadrantRotated(tx)) + && extraAlpha == 1.0f)) + { + SurfaceType srcType = srcData.getSurfaceType(); + SurfaceType dstType = dstData.getSurfaceType(); - TransformBlit blit = TransformBlit.getFromCache(srcType, - sg.imageComp, dstType); - if (blit != null) { - blit.Transform(srcData, dstData, sg.composite, - sg.getCompClip(), tx, interpType, sx1, sy1, 0, 0, sx2 + TransformBlit blit = TransformBlit.getFromCache(srcType, + sg.imageComp, dstType); + if (blit != null) { + blit.Transform(srcData, dstData, sg.composite, + sg.getCompClip(), tx, interpType, sx1, sy1, 0, 0, sx2 - sx1, sy2 - sy1); return; + } } } diff --git a/jdk/test/java/awt/image/DrawImage/IncorrectClipXorModeSurface2Surface.java b/jdk/test/java/awt/image/DrawImage/IncorrectClipXorModeSurface2Surface.java index 8a9b1bd1ae7..c23a1cf0968 100644 --- a/jdk/test/java/awt/image/DrawImage/IncorrectClipXorModeSurface2Surface.java +++ b/jdk/test/java/awt/image/DrawImage/IncorrectClipXorModeSurface2Surface.java @@ -40,7 +40,7 @@ import static java.awt.geom.Rectangle2D.Double; /** * @test - * @bug 8061831 + * @bug 8061831 8130400 * @summary Tests drawing volatile image to volatile image using different * clips + xor mode. Results of the blit compatibleImage to * compatibleImage is used for comparison. From 21330b8cf8affa0195173c9897dcf1d2f4ba7493 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Tue, 4 Aug 2015 12:58:50 +0300 Subject: [PATCH 2/4] 8130892: Test javax/swing/plaf/basic/BasicTextUI/8001470/bug8001470.java fails in Solaris Sparcv9 Reviewed-by: alexsch, serb --- .../share/classes/javax/swing/plaf/basic/BasicTextUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java index 4058c912563..2941cc9e85b 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java @@ -940,7 +940,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { rootView.setSize(d.width - i.left - i.right - caretMargin, d.height - i.top - i.bottom); } - else if (d.width == 0 || d.height == 0) { + else if (d.width <= 0 || d.height <= 0) { // Probably haven't been layed out yet, force some sort of // initial sizing. rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); From b215a2b390f93eb59cb6595e0a6160f225fb3672 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Tue, 4 Aug 2015 13:14:28 +0300 Subject: [PATCH 3/4] 8132136: [PIT] RTL orientation in JEditorPane is broken Reviewed-by: alexsch, serb --- .../swing/plaf/basic/BasicTextFieldUI.java | 7 +- .../classes/javax/swing/text/GlyphView.java | 19 +--- .../JTextPane/JTextPaneDocumentAlignment.java | 99 +++++++++++++++++++ 3 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 jdk/test/javax/swing/JTextPane/JTextPaneDocumentAlignment.java diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextFieldUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextFieldUI.java index 5a5f119c48a..1db0d09a875 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextFieldUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextFieldUI.java @@ -97,12 +97,7 @@ public class BasicTextFieldUI extends BasicTextUI { String kind = elem.getName(); if (kind != null) { if (kind.equals(AbstractDocument.ContentElementName)) { - return new GlyphView(elem) { - @Override - public int getResizeWeight(int axis) { - return 0; - } - }; + return new GlyphView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { return new I18nFieldView(elem); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/text/GlyphView.java b/jdk/src/java.desktop/share/classes/javax/swing/text/GlyphView.java index ccd88f1fc82..31eb62d5d6b 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/text/GlyphView.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/text/GlyphView.java @@ -537,17 +537,6 @@ public class GlyphView extends View implements TabableView, Cloneable { } } - /** - * {@inheritDoc} - */ - @Override - public int getResizeWeight(int axis) { - if (axis == View.X_AXIS) { - return 1; - } - return 0; - } - /** * Determines the minimum span for this view along an axis. * @@ -561,11 +550,13 @@ public class GlyphView extends View implements TabableView, Cloneable { */ @Override public float getMinimumSpan(int axis) { + int w = getResizeWeight(axis); + if (w == 0) { + // can't resize + return getPreferredSpan(axis); + } switch (axis) { case View.X_AXIS: - if (getResizeWeight(X_AXIS) == 0) { - return getPreferredSpan(X_AXIS); - } if (minimumSpan < 0) { minimumSpan = 0; int p0 = getStartOffset(); diff --git a/jdk/test/javax/swing/JTextPane/JTextPaneDocumentAlignment.java b/jdk/test/javax/swing/JTextPane/JTextPaneDocumentAlignment.java new file mode 100644 index 00000000000..f75d1c08a28 --- /dev/null +++ b/jdk/test/javax/swing/JTextPane/JTextPaneDocumentAlignment.java @@ -0,0 +1,99 @@ +/* + * 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 8132136 + @summary [PIT] RTL orientation in JEditorPane is broken + @author Semyon Sadetsky + */ + +import javax.swing.*; +import javax.swing.text.BadLocationException; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import java.awt.*; + +public class JTextPaneDocumentAlignment { + + private static JFrame frame; + private static JTextPane jTextPane; + private static int position; + + public static void main(String[] args) throws Exception{ + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame = new JFrame(); + frame.setUndecorated(true); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setSize(200, 200); + jTextPane = new JTextPane(); + jTextPane.setContentType("text/html"); + jTextPane.setText( + "Test"); + SimpleAttributeSet right = new SimpleAttributeSet(); + StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT); + jTextPane.getStyledDocument() + .setParagraphAttributes(0, 10, right, true); + frame.getContentPane().add(jTextPane); + frame.setVisible(true); + } + }); + Robot robot = new Robot(); + robot.waitForIdle(); + robot.delay(200); + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try { + position = jTextPane.modelToView(1).x; + SimpleAttributeSet center = new SimpleAttributeSet(); + StyleConstants.setAlignment(center, + StyleConstants.ALIGN_CENTER); + jTextPane.getStyledDocument() + .setParagraphAttributes(0, 10, center, true); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + }); + if(position < 100) { + throw new RuntimeException("Text is not right aligned " + position); + } + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try { + position = jTextPane.modelToView(1).x; + } catch (BadLocationException e) { + e.printStackTrace(); + } + frame.dispose(); + } + }); + if(position < 20) { + throw new RuntimeException("Text is not center aligned " + position); + } + System.out.println("ok"); + } +} From de096038636476268a4e159c7642b0996e3dbe6b Mon Sep 17 00:00:00 2001 From: Alexander Stepanov Date: Tue, 4 Aug 2015 14:03:49 +0300 Subject: [PATCH 4/4] 8131055: bean annotations: add a test checking if a user-defined BeanInfo is top-priority as compared with the annotations Reviewed-by: alexsch, serb --- .../4058433/TestBeanInfoPriority.java | 294 ++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 jdk/test/java/beans/Introspector/4058433/TestBeanInfoPriority.java diff --git a/jdk/test/java/beans/Introspector/4058433/TestBeanInfoPriority.java b/jdk/test/java/beans/Introspector/4058433/TestBeanInfoPriority.java new file mode 100644 index 00000000000..589e9c06696 --- /dev/null +++ b/jdk/test/java/beans/Introspector/4058433/TestBeanInfoPriority.java @@ -0,0 +1,294 @@ +/* + * 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.event.ActionListener; +import java.awt.event.MouseListener; +import java.beans.BeanDescriptor; +import java.beans.BeanInfo; +import java.beans.BeanProperty; +import java.beans.EventSetDescriptor; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.JavaBean; +import java.beans.MethodDescriptor; +import java.beans.PropertyDescriptor; +import java.beans.SimpleBeanInfo; +import javax.swing.SwingContainer; +import java.util.Arrays; + +/** + * @test + * @bug 4058433 8131055 + * @summary Check if the user-defined bean info + * is not overridden with the annotated one. + * @author a.stepanov + */ + + +public class TestBeanInfoPriority { + + // ========== test bean (annotations must be ignored!) ========== + + @JavaBean( + description = "annotation-description", + defaultProperty = "other", + defaultEventSet = "mouse") + @SwingContainer(value = false) + public static class TestClass { + + private int value; + private double other; + + @BeanProperty( + bound = false, + expert = false, + hidden = false, + preferred = false, + required = false, + visualUpdate = false, + description = "annotation-value", + enumerationValues = { + "javax.swing.SwingConstants.NORTH"} + ) + public void setValue(int v) { value = v; } + public int getValue() { return value; } + + + @BeanProperty( + bound = true, + expert = true, + hidden = true, + preferred = true, + required = true, + visualUpdate = true, + description = "annotation-other", + enumerationValues = { + "javax.swing.SwingConstants.LEFT", + "javax.swing.SwingConstants.RIGHT", + "javax.swing.SwingConstants.CENTER"} + ) + public void setOther(double o) { other = o; } + public double getOther() { return other; } + + public void addActionListener(ActionListener l) {} + public void removeActionListener(ActionListener l) {} + + public void addMouseListener(MouseListener l) {} + public void removeMouseListener(MouseListener l) {} + } + + // ========== user-defined bean info ========== + + public static class TestClassBeanInfo extends SimpleBeanInfo { + + private static final int iOther = 0; + private static final int iValue = 1; + + private static final int iAction = 0; + private static final int iMouse = 1; + + + @Override + public BeanDescriptor getBeanDescriptor() { + + BeanDescriptor bd = new BeanDescriptor(TestClass.class, null); + bd.setShortDescription("user-defined-description"); + bd.setValue("isContainer", true); + bd.setValue("containerDelegate", "user-defined-delegate"); + + return bd; + } + + @Override + public PropertyDescriptor[] getPropertyDescriptors() { + + PropertyDescriptor[] p = new PropertyDescriptor[2]; + + try { + + // value + PropertyDescriptor pdValue = new PropertyDescriptor( + "value", TestClass.class, "getValue", "setValue"); + pdValue.setBound(true); + pdValue.setConstrained(true); + pdValue.setExpert(true); + pdValue.setHidden(true); + pdValue.setPreferred(true); + pdValue.setValue("required", true); + pdValue.setValue("visualUpdate", true); + pdValue.setShortDescription("user-defined-value"); + pdValue.setValue("enumerationValues", new Object[]{ + "EAST", 3, "javax.swing.SwingConstants.EAST", + "WEST", 7, "javax.swing.SwingConstants.WEST"}); + p[iValue] = pdValue; + + // other + PropertyDescriptor pdOther = new PropertyDescriptor( + "other", TestClass.class, "getOther", "setOther"); + pdOther.setBound(false); + pdOther.setConstrained(false); + pdOther.setExpert(false); + pdOther.setHidden(false); + pdOther.setPreferred(false); + pdOther.setValue("required", false); + pdOther.setValue("visualUpdate", false); + pdOther.setShortDescription("user-defined-other"); + pdOther.setValue("enumerationValues", new Object[]{ + "TOP", 1, "javax.swing.SwingConstants.TOP"}); + p[iOther] = pdOther; + + } catch(IntrospectionException e) { + e.printStackTrace(); + } + + return p; + } + + @Override + public EventSetDescriptor[] getEventSetDescriptors() { + EventSetDescriptor[] es = new EventSetDescriptor[2]; + try { + es[iAction] = new EventSetDescriptor( + TestClass.class, + "actionListener", + java.awt.event.ActionListener.class, + new String[] {"actionPerformed"}, + "addActionListener", + "removeActionListener"); + es[iMouse] = new EventSetDescriptor( + TestClass.class, + "mouseListener", + java.awt.event.MouseListener.class, + new String[] {"mouseClicked", "mousePressed", "mouseReleased", "mouseEntered", "mouseExited"}, + "addMouseListener", + "removeMouseListener"); + } catch(IntrospectionException e) { + e.printStackTrace(); + } + return es; + } + + @Override + public MethodDescriptor[] getMethodDescriptors() { + MethodDescriptor[] m = new MethodDescriptor[0]; + return m; + } + + @Override + public int getDefaultPropertyIndex() { return iValue; } // default: value + + @Override + public int getDefaultEventIndex() { return iAction; } // default: action + + @Override + public java.awt.Image getIcon(int iconKind) { return null; } + } + + // ========== auxiliary functions ========== + + static void checkEq(String what, Object v, Object ref) throws Exception { + + if ((v != null) && v.equals(ref)) { + System.out.println(what + ": ok (" + ref.toString() + ")"); + } else { + throw new Exception( + "invalid " + what + ", expected: \"" + ref + "\", got: \"" + v + "\""); + } + } + + static void checkEnumEq(String what, Object v, Object ref[]) throws Exception { + + what = "\"" + what + "\""; + if (v == null) { + throw new Exception("null " + what + " enumeration values"); + } + + String msg = "invalid " + what + " enumeration values"; + if (!(v instanceof Object[])) { throw new Exception(msg); } + + if (Arrays.equals((Object []) v, ref)) { + System.out.println(what + " enumeration values: ok"); + } else { throw new Exception(msg); } + } + + + // ========== test ========== + + + public static void main(String[] args) throws Exception { + + BeanInfo i = Introspector.getBeanInfo(TestClass.class, Object.class); + BeanDescriptor bd = i.getBeanDescriptor(); + + checkEq("description", bd.getShortDescription(), "user-defined-description"); + checkEq("default property index", i.getDefaultPropertyIndex(), 1); + checkEq("default event index", i.getDefaultEventIndex(), 0); + + checkEq("isContainer", i.getBeanDescriptor().getValue("isContainer"), true); + checkEq("containerDelegate", + i.getBeanDescriptor().getValue("containerDelegate"), "user-defined-delegate"); + System.out.println(""); + + PropertyDescriptor[] pds = i.getPropertyDescriptors(); + for (PropertyDescriptor pd: pds) { + String name = pd.getName(); + switch (name) { + case "value": + checkEq("\"value\" isBound", pd.isBound(), true); + checkEq("\"value\" isConstrained", pd.isConstrained(), true); + checkEq("\"value\" isExpert", pd.isExpert(), true); + checkEq("\"value\" isHidden", pd.isHidden(), true); + checkEq("\"value\" isPreferred", pd.isPreferred(), true); + checkEq("\"value\" required", pd.getValue("required"), true); + checkEq("\"value\" visualUpdate", pd.getValue("visualUpdate"), true); + + checkEq("\"value\" description", pd.getShortDescription(), "user-defined-value"); + + checkEnumEq(pd.getName(), pd.getValue("enumerationValues"), + new Object[]{ + "EAST", 3, "javax.swing.SwingConstants.EAST", + "WEST", 7, "javax.swing.SwingConstants.WEST"}); + System.out.println(""); + break; + case "other": + checkEq("\"other\" isBound", pd.isBound(), false); + checkEq("\"other\" isConstrained", pd.isConstrained(), false); + checkEq("\"other\" isExpert", pd.isExpert(), false); + checkEq("\"other\" isHidden", pd.isHidden(), false); + checkEq("\"other\" isPreferred", pd.isPreferred(), false); + checkEq("\"other\" required", pd.getValue("required"), false); + checkEq("\"other\" visualUpdate", pd.getValue("visualUpdate"), false); + + checkEq("\"other\" description", pd.getShortDescription(), "user-defined-other"); + + checkEnumEq(pd.getName(), pd.getValue("enumerationValues"), + new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"}); + System.out.println(""); + break; + default: + throw new Exception("invalid property descriptor: " + name); + } + } + } +}