bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/22887] Casting Graphics to Graphics2D


From: gcc-bugzilla at gcc dot gnu dot org
Subject: [Bug classpath/22887] Casting Graphics to Graphics2D
Date: 16 Oct 2005 01:27:35 -0000

If i do this:

-----
public void paint(Graphics g) {         
                Graphics2D g2 = (Graphics2D) g;
}
-----

i get this error:

-----
Exception during event dispatch:
java.lang.ClassCastException: gnu/java/awt/peer/gtk/GdkGraphics
   at MyGlassPane.paint (GlassPaneDemo.java:95)
   at java.awt.Container$GfxPaintVisitor.visit (Container.java:1693)
   at java.awt.Container.visitChild (Container.java:1514)
   at java.awt.Container.visitChildren (Container.java:1476)
   at java.awt.Container.paint (Container.java:725)
   at javax.swing.JComponent.paintChildren (JComponent.java:1477)
   at javax.swing.JComponent.paint (JComponent.java:1435)
   at java.awt.Container$GfxPaintVisitor.visit (Container.java:1693)
   at java.awt.Container.visitChild (Container.java:1514)
   at java.awt.Container.visitChildren (Container.java:1476)
   at java.awt.Container.paint (Container.java:725)
   at javax.swing.JComponent.paintImmediately (JComponent.java:1532)
   at javax.swing.RepaintManager.paintDirtyRegions (RepaintManager.java:459)
   at javax.swing.RepaintManager$RepaintWorker.run (RepaintManager.java:104)
   at java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:191)
   at java.awt.EventQueue.dispatchEvent (EventQueue.java:508)
   at java.awt.EventDispatchThread.run (EventDispatchThread.java:75)
-----


------- Comment #1 from from-classpath at savannah dot gnu dot org  2005-03-04 
13:43 -------
What do you expect ? When the API says you will get a Graphics object it *CAN*
be a Graphics2D object or not (becuase Graphics2D is derived from Graphics).
Every software that depends on a Graphics object being a Graphics2D object
without checking is clearly buggy.


------- Comment #2 from from-classpath at savannah dot gnu dot org  2005-03-04 
15:10 -------
Use of Graphics2D is only supported when GNU Classpath has been configured with
--enable-gtk-cairo (which is not the default at the moment) and you run your
program with the system property gnu.java.awt.peer.gtk.Graphics=Graphics2D set.
The cairo based Graphics2D is still experimental.

You should test if support for Graphics2D is available before blindly casting.


------- Comment #3 from from-classpath at savannah dot gnu dot org  2005-03-06 
00:17 -------
Mark, Michael:
I don't think it's reasonable to expect people to test for support for
Graphics2D before casting. The vast majority of code out there (I have yet to
see one that doesn't) does not do this because in Java 1.2+ it is safe to
assume the Graphics object is Graphics2D. 

The person running on Classpath needs to be aware that this doesn't hold true
for Classpath, but as I wrote on the mailing list, this isn't going to be a
long-term issue anyway.


------- Comment #4 from from-classpath at savannah dot gnu dot org  2005-03-13 
13:01 -------
Agreed to clearly document the fact and make people aware of the fact that a
Graphics object in GNU Classpath cannot currently be cast to a Graphics2D one
unless one configures with --enable-gtk-cairo and set the system property
gnu.java.awt.peer.gtk.Graphics=Graphics2D.

Two issues I think we should fix asap:

- We should default to gnu.java.awt.peer.gtk.Graphics=Graphics2D when confgured
with --enable-gtk-cairo. The two step system is a pain for users.
- We should port to the new cairo 0.4.0 snapshot asap for GNU Classpath 0.15.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22887





reply via email to

[Prev in Thread] Current Thread [Next in Thread]