7025987: Nimbus L&F increases insets unexpectedly
authormalenkov
Mon, 04 Apr 2011 19:55:10 +0400
changeset 8988 a4ce9022541e
parent 8987 60d22853a57c
child 8989 09e49dac04d8
7025987: Nimbus L&F increases insets unexpectedly Reviewed-by: alexp
jdk/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java
jdk/test/javax/swing/border/Test4856008.java
jdk/test/javax/swing/border/Test6978482.java
--- a/jdk/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java	Mon Apr 04 13:22:40 2011 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java	Mon Apr 04 19:55:10 2011 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,13 +26,11 @@
 
 import javax.swing.border.Border;
 import javax.swing.JComponent;
-import javax.swing.plaf.UIResource;
 import java.awt.Insets;
 import java.awt.Component;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Color;
-import java.awt.Transparency;
 import java.awt.RenderingHints;
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
@@ -58,7 +56,9 @@
 
     @Override
     protected Object[] getExtendedCacheKeys(JComponent c) {
-        return new Object[] {c.getBackground()};
+        return (c != null)
+                ? new Object[] { c.getBackground() }
+                : null;
     }
 
     /**
@@ -85,6 +85,7 @@
      */
     protected void doPaint(Graphics2D g, JComponent c, int width, int height,
             Object[] extendedCacheKeys) {
+        Color color = (c == null) ? Color.BLACK : c.getBackground();
         BufferedImage img1 = new BufferedImage(IMG_SIZE,IMG_SIZE,
                     BufferedImage.TYPE_INT_ARGB);
         BufferedImage img2 = new BufferedImage(IMG_SIZE,IMG_SIZE,
@@ -93,14 +94,14 @@
         Graphics2D g2 = (Graphics2D)img1.getGraphics();
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                 RenderingHints.VALUE_ANTIALIAS_ON);
-        g2.setColor(c.getBackground());
+        g2.setColor(color);
         g2.fillRoundRect(2,0,26,26,RADIUS,RADIUS);
         g2.dispose();
         // draw shadow
         InnerShadowEffect effect = new InnerShadowEffect();
         effect.setDistance(1);
         effect.setSize(3);
-        effect.setColor(getLighter(c.getBackground(),2.1f));
+        effect.setColor(getLighter(color, 2.1f));
         effect.setAngle(90);
         effect.applyEffect(img1,img2,IMG_SIZE,IMG_SIZE);
         // draw outline to img2
@@ -108,7 +109,7 @@
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                 RenderingHints.VALUE_ANTIALIAS_ON);
         g2.setClip(0,28,IMG_SIZE,1);
-        g2.setColor(getLighter(c.getBackground(),0.90f));
+        g2.setColor(getLighter(color, 0.90f));
         g2.drawRoundRect(2,1,25,25,RADIUS,RADIUS);
         g2.dispose();
         // draw final image
@@ -150,7 +151,7 @@
      * @param c the component for which this border insets value applies
      */
     public Insets getBorderInsets(Component c) {
-        return INSETS;
+        return (Insets) INSETS.clone();
     }
 
     /**
--- a/jdk/test/javax/swing/border/Test4856008.java	Mon Apr 04 13:22:40 2011 +0400
+++ b/jdk/test/javax/swing/border/Test4856008.java	Mon Apr 04 19:55:10 2011 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4856008
+ * @bug 4856008 7025987
  * @summary Tests border insets
  * @author Sergey Malenkov
  */
@@ -59,6 +59,7 @@
 import javax.swing.plaf.basic.BasicToolBarUI;
 import javax.swing.plaf.metal.MetalBorders;
 import javax.swing.plaf.metal.MetalComboBoxEditor;
+import javax.swing.plaf.nimbus.NimbusLookAndFeel;
 
 import sun.swing.plaf.synth.SynthFileChooserUI;
 
@@ -134,6 +135,9 @@
 
             //+ SynthFileChooserUI.UIBorder:
             new SynthFileChooser().getUIBorder(),
+
+            //+ LoweredBorder:
+            new NimbusLookAndFeel().getDefaults().getBorder("TitledBorder.border"),
     };
 
     public static void main(String[] args) {
--- a/jdk/test/javax/swing/border/Test6978482.java	Mon Apr 04 13:22:40 2011 +0400
+++ b/jdk/test/javax/swing/border/Test6978482.java	Mon Apr 04 19:55:10 2011 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6978482
+ * @bug 6978482 7025987
  * @summary Tests unchecked casts
  * @author Sergey Malenkov
  */
@@ -58,6 +58,7 @@
 import javax.swing.plaf.basic.BasicToolBarUI;
 import javax.swing.plaf.metal.MetalBorders;
 import javax.swing.plaf.metal.MetalComboBoxEditor;
+import javax.swing.plaf.nimbus.NimbusLookAndFeel;
 
 import sun.swing.plaf.synth.SynthFileChooserUI;
 
@@ -132,6 +133,9 @@
 
             //+ SynthFileChooserUI.UIBorder:
             new SynthFileChooser().getUIBorder(),
+
+            //+ LoweredBorder:
+            new NimbusLookAndFeel().getDefaults().getBorder("TitledBorder.border"),
     };
 
     public static void main(String[] args) {