Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6849396

Nimbus L&F:AbstractRegionPainter.decodeColor(Col,Col,f) not always return color2 if midPoint is 1.f

XMLWordPrintable

      Specification for method
      decodeColor(Color color1, Color color2, float midPoint)
      says
           * @param midPoint The offset between color 1 and color 2,
           * a value of 0.0 is color 1 and 1.0 is color 2;

      In fact midPoint value of 1.0 doesn't always lead to returning second color.
      Please see the following code sample:

      -------------------------------------
      import javax.swing.*;
      import java.awt.*;

      public class Test {
          public static void main(String[] args) {
              class MyARP extends javax.swing.plaf.nimbus.AbstractRegionPainter {
                  protected PaintContext getPaintContext() { return null; }
                  protected void doPaint(Graphics2D g, JComponent c,
                                         int width, int height,
                                         Object[] extendedCacheKeys) { }
                  void callDecodeColor() {
                      Color color = decodeColor(Color.BLUE, Color.BLACK, 1.f);
                      if ( !Color.BLACK.equals(color)) {
                          throw new RuntimeException("Expected " + Color.BLACK + ", returned " + color);
                      }
                  }
              }
              new MyARP().callDecodeColor();
          }
      }
      -------------------------------------

      The output will be

      Exception in thread "main" java.lang.RuntimeException: Expected java.awt.Color[r=0,g=0,b=0], returned java.awt.Color[r=0,g=0,b=1]
      at Test$1MyARP.callDecodeColor(Test.java:15)
      at Test.main(Test.java:19)

            peterz Peter Zhelezniakov
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: