Our handling of GraphicsConfigurations for AWT components was more or
less broken. We had duplicate fields in Canvas and Window, while the
field in Component has been unused. I fixed that along with a couple of
other issues (see below) in order to make JOGL work:
http://kennke.org/blog/2007/03/01/jogl-on-jamaica/
2007-03-01 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/Canvas.java
(graphicsConfiguration): Removed duplicate (from Component) field.
(Canvas(GraphicsConfiguration)): Set the Component's graphicsConfig
field.
(getGraphicsConfigurationImpl): Removed.
* java/awt/Component.java
(getGraphicsConfiguration): Moved implementation here. Synchronize
on tree lock to prevent threading nastiness. Don't query peer
and instead return the setting of the graphicsConfig field.
(getGraphicsConfigurationImpl): Removed.
* java/awt/Window.java
(graphicsConfiguration): Removed duplicate (from Component) field.
(Window): Set the Component's graphicsConfig field.
(Window(GraphicsConfiguration)): Set the Component's graphicsConfig
field.
(Window(Window,GraphicsConfiguration)): Set the Component's
graphicsConfig field.
(getGraphicsConfigurationImpl): Removed.
(getGraphicsConfiguration): Fetch the local graphics env here
if not already done and return that.
/Roman
--
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com * Tel: +49-721-663 968-0
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
Index: java/awt/Canvas.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Canvas.java,v
retrieving revision 1.18
diff -u -1 -5 -r1.18 Canvas.java
--- java/awt/Canvas.java 13 Jul 2006 17:30:24 -0000 1.18
+++ java/awt/Canvas.java 1 Mar 2007 01:00:09 -0000
@@ -63,63 +63,51 @@
extends Component
implements Serializable, Accessible
{
/**
* Compatible with Sun's JDK.
*/
private static final long serialVersionUID = -2284879212465893870L;
/**
* The number used to generate the name returned by getName.
*/
private static transient long next_canvas_number;
/**
- * The graphics configuration associated with the canvas.
- */
- transient GraphicsConfiguration graphicsConfiguration;
-
- /**
* The buffer strategy associated with this canvas.
*/
transient BufferStrategy bufferStrategy;
/**
* Initializes a new instance of <code>Canvas</code>.
*/
public Canvas()
{
}
/**
* Initializes a new instance of <code>Canvas</code>
* with the supplied graphics configuration.
*
* @param graphicsConfiguration the graphics configuration to use
* for this particular canvas.
*/
public Canvas(GraphicsConfiguration graphicsConfiguration)
{
- this.graphicsConfiguration = graphicsConfiguration;
- }
-
- GraphicsConfiguration getGraphicsConfigurationImpl()
- {
- if (graphicsConfiguration != null)
- return graphicsConfiguration;
- return super.getGraphicsConfigurationImpl();
+ this.graphicsConfig = graphicsConfiguration;
}
/**
* Creates the native peer for this object.
*/
public void addNotify()
{
if (peer == null)
peer = (ComponentPeer) getToolkit().createCanvas(this);
super.addNotify();
}
/**
* Repaints the canvas window. This method should be overridden by
* a subclass to do something useful, as this method simply paints
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.155
diff -u -1 -5 -r1.155 Component.java
--- java/awt/Component.java 7 Jan 2007 21:12:33 -0000 1.155
+++ java/awt/Component.java 1 Mar 2007 01:00:12 -0000
@@ -714,31 +714,47 @@
*/
public DropTarget getDropTarget()
{
return dropTarget;
}
/**
* Returns the graphics configuration of this component, if there is one.
* If it has not been set, it is inherited from the parent.
*
* @return the graphics configuration, or null
* @since 1.3
*/
public GraphicsConfiguration getGraphicsConfiguration()
{
- return getGraphicsConfigurationImpl();
+ GraphicsConfiguration conf = null;
+ synchronized (getTreeLock())
+ {
+ if (graphicsConfig != null)
+ {
+ conf = graphicsConfig;
+ }
+ else
+ {
+ Component par = getParent();
+ if (par != null)
+ {
+ conf = parent.getGraphicsConfiguration();
+ }
+ }
+ }
+ return conf;
}
/**
* Returns the object used for synchronization locks on this component
* when performing tree and layout functions.
*
* @return the synchronization lock for this component
*/
public final Object getTreeLock()
{
return treeLock;
}
/**
* Returns the toolkit in use for this component. The toolkit is associated
@@ -5422,51 +5438,30 @@
// Component is abstract.
return null;
}
/**
* Sets the peer for this component.
*
* @param peer the new peer
*/
final void setPeer(ComponentPeer peer)
{
this.peer = peer;
}
/**
- * Implementation method that allows classes such as Canvas and Window to
- * override the graphics configuration without violating the published API.
- *
- * @return the graphics configuration
- */
- GraphicsConfiguration getGraphicsConfigurationImpl()
- {
- if (peer != null)
- {
- GraphicsConfiguration config = peer.getGraphicsConfiguration();
- if (config != null)
- return config;
- }
-
- if (parent != null)
- return parent.getGraphicsConfiguration();
-
- return null;
- }
-
- /**
* Translate an AWT 1.1 event ([EMAIL PROTECTED] AWTEvent}) into an AWT 1.0
* event ([EMAIL PROTECTED] Event}).
*
* @param e an AWT 1.1 event to translate
*
* @return an AWT 1.0 event representing e
*/
static Event translateEvent (AWTEvent e)
{
Object target = e.getSource ();
Event translated = null;
if (e instanceof WindowEvent)
{
WindowEvent we = (WindowEvent) e;
Index: java/awt/Window.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Window.java,v
retrieving revision 1.79
diff -u -1 -5 -r1.79 Window.java
--- java/awt/Window.java 10 Dec 2006 20:25:43 -0000 1.79
+++ java/awt/Window.java 1 Mar 2007 01:00:12 -0000
@@ -75,31 +75,30 @@
/** @since 1.2 */
// private FocusManager focusMgr; // FIXME: what is this?
/** @since 1.2 */
private int state = 0;
/** @since 1.4 */
private boolean focusableWindowState = true;
/** @since 1.5 */
private boolean alwaysOnTop = false;
// A list of other top-level windows owned by this window.
private transient Vector ownedWindows = new Vector();
private transient WindowListener windowListener;
private transient WindowFocusListener windowFocusListener;
private transient WindowStateListener windowStateListener;
- private transient GraphicsConfiguration graphicsConfiguration;
private transient boolean shown;
// This is package-private to avoid an accessor method.
transient Component windowFocusOwner;
/*
* The number used to generate the name returned by getName.
*/
private static transient long next_window_number;
protected class AccessibleAWTWindow extends AccessibleAWTContainer
{
private static final long serialVersionUID = 4215068635060671780L;
@@ -120,37 +119,37 @@
/**
* This (package access) constructor is used by subclasses that want
* to build windows that do not have parents. Eg. toplevel
* application frames. Subclasses cannot call super(null), since
* null is an illegal argument.
*/
Window()
{
visible = false;
// Windows are the only Containers that default to being focus
// cycle roots.
focusCycleRoot = true;
setLayout(new BorderLayout());
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
- graphicsConfiguration = g.getDefaultScreenDevice().getDefaultConfiguration();
+ graphicsConfig = g.getDefaultScreenDevice().getDefaultConfiguration();
}
Window(GraphicsConfiguration gc)
{
this();
- graphicsConfiguration = gc;
+ graphicsConfig = gc;
}
/**
* Initializes a new instance of <code>Window</code> with the specified
* parent. The window will initially be invisible.
*
* @param owner The owning <code>Frame</code> of this window.
*
* @exception IllegalArgumentException If the owner's GraphicsConfiguration
* is not from a screen device, or if owner is null; this exception is always
* thrown when GraphicsEnvironment.isHeadless returns true.
*/
public Window(Frame owner)
{
this (owner, owner.getGraphicsConfiguration ());
@@ -192,43 +191,35 @@
parent = owner;
owner.ownedWindows.add(new WeakReference(this));
}
// FIXME: make this text visible in the window.
SecurityManager s = System.getSecurityManager();
if (s != null && ! s.checkTopLevelWindow(this))
warningString = System.getProperty("awt.appletWarning");
if (gc != null
&& gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN)
throw new IllegalArgumentException ("gc must be from a screen device");
if (gc == null)
- graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment()
- .getDefaultScreenDevice()
- .getDefaultConfiguration();
+ graphicsConfig = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice()
+ .getDefaultConfiguration();
else
- graphicsConfiguration = gc;
- }
-
- GraphicsConfiguration getGraphicsConfigurationImpl()
- {
- if (graphicsConfiguration != null)
- return graphicsConfiguration;
-
- return super.getGraphicsConfigurationImpl();
+ graphicsConfig = gc;
}
/**
* Creates the native peer for this window.
*/
public void addNotify()
{
if (peer == null)
peer = getToolkit().createWindow(this);
super.addNotify();
}
/**
* Relays out this window's child components at their preferred size.
*
@@ -1061,33 +1052,38 @@
public AccessibleContext getAccessibleContext()
{
/* Create the context if this is the first request */
if (accessibleContext == null)
accessibleContext = new AccessibleAWTWindow();
return accessibleContext;
}
/**
* Get graphics configuration. The implementation for Window will
* not ask any parent containers, since Window is a toplevel
* window and not actually embedded in the parent component.
*/
public GraphicsConfiguration getGraphicsConfiguration()
{
- if (graphicsConfiguration != null) return graphicsConfiguration;
- if (peer != null) return peer.getGraphicsConfiguration();
- return null;
+ GraphicsConfiguration conf = graphicsConfig;
+ if (conf == null)
+ {
+ conf = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice().getDefaultConfiguration();
+ graphicsConfig = conf;
+ }
+ return conf;
}
protected void processWindowFocusEvent(WindowEvent event)
{
if (windowFocusListener != null)
{
switch (event.getID ())
{
case WindowEvent.WINDOW_GAINED_FOCUS:
windowFocusListener.windowGainedFocus (event);
break;
case WindowEvent.WINDOW_LOST_FOCUS:
windowFocusListener.windowLostFocus (event);
break;