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

SpashScreen.getGraphics() should returns a Graphics2D

XMLWordPrintable

    • b77
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b61)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b61, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Since java 1.2 (i think), all methods getGraphics() return
      a Graphics2D.
      Image.getGraphics() only returns a Graphics because of
      backward compatibility.

      The SplashScreen API is included since mustang,
      so there is no such compatibility requirement,
      SpashScreen.getGraphics() should returns a Graphics2D.

      And permits to avoid an ugly cast in all users code.

      Proposed fix :
      public Graphics2D getGraphics() throws IllegalStateException {
              if (image==null) {
                  Dimension dim = getSize();
                  image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
              }
              return image.createGraphics();
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      call getGraphics() on a splash screen instance.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Graphics2D g=splash.getGraphics();
      g.setPaint(new GradientPaint(...));

      ACTUAL -
      Graphics2D g=(Graphics2D)splash.getGraphics();
      g.setPaint(new GradientPaint(...));

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.GradientPaint;
      import java.awt.Graphics2D;
      import java.awt.Rectangle;
      import java.awt.SplashScreen;

      public class BugTest {
        public static void main(String[] args) throws InterruptedException {
          final SplashScreen splash=SplashScreen.getSplashScreen();
          Graphics2D graphics=(Graphics2D)splash.getGraphics();
          Dimension size=splash.getSize();
          graphics.setPaint(new GradientPaint(0,0,Color.BLUE,size.width,size.height,Color.BLACK));
          for(int i=0;i<5;i++) {
            graphics.fill(new Rectangle(20+i*70,size.height-70,50,50));
            splash.update();
            Thread.sleep(500);
          }
          
          graphics.dispose();
          splash.close();
        }
      }
      ---------- END SOURCE ----------

            osemenovsunw Oleg Semenov (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: