Here comes a couple of fixes and adjustments for the Swing peers.

2006-05-10  Roman Kennke <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/swing/SwingComponent.java:
        Some API comment fixlets.
        * gnu/java/awt/peer/swing/SwingComponentPeer.java:
        (createImage): Create a BufferedImage, not a Toolkit image.
        (paint): Removed bogus API comment.
        (prepareImage): Added checks to avoid NPE.
        * gnu/java/awt/peer/swing/SwingContainerPeer.java:
        (getInsets): Added check to avoid NPE.
        (handleMouseEvent): Added check to avoid NPE.
        * gnu/java/awt/peer/swing/SwingFramePeer.java:
        Some API comment fixlets.
        * gnu/java/awt/peer/swing/SwingMenuBarPeer.java:
        Some API comment fixlets.
        * gnu/java/awt/peer/swing/SwingTextFieldPeer.java:
        Changed start_pos name to startPos.
        * gnu/java/awt/peer/swing/SwingWindowPeer.java:
        Some API comment fixlets.

/Roman
Index: gnu/java/awt/peer/swing/SwingComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingComponent.java,v
retrieving revision 1.1
diff -u -1 -0 -r1.1 SwingComponent.java
--- gnu/java/awt/peer/swing/SwingComponent.java	14 Jan 2006 00:26:26 -0000	1.1
+++ gnu/java/awt/peer/swing/SwingComponent.java	10 May 2006 15:13:50 -0000
@@ -55,35 +55,35 @@
 
   /**
    * Returns the actual swing compenent.
    *
    * @return the actual swing compenent
    */
   JComponent getJComponent();
 
   /**
    * Handles a mouse event. This is usually forwarded to
-   * [EMAIL PROTECTED] Component#processMouseMotionEvent(MouseEvent)} of the swing
+   * [EMAIL PROTECTED] java.awt.Component#processMouseMotionEvent(MouseEvent)} of the swing
    * component.
    *
    * @param ev the mouse event
    */
   void handleMouseEvent(MouseEvent ev);
 
   /**
    * Handles a mouse motion event. This is usually forwarded to
-   * [EMAIL PROTECTED] Component#processMouseEvent(MouseEvent)} of the swing
+   * [EMAIL PROTECTED] java.awt.Component#processMouseEvent(MouseEvent)} of the swing
    * component.
    *
    * @param ev the mouse motion event
    */
   void handleMouseMotionEvent(MouseEvent ev);
 
   /**
    * Handles a key event. This is usually forwarded to
-   * [EMAIL PROTECTED] Component#processKeyEvent(KeyEvent)} of the swing
+   * [EMAIL PROTECTED] java.awt.Component#processKeyEvent(KeyEvent)} of the swing
    * component.
    *
    * @param ev the key event
    */
   void handleKeyEvent(KeyEvent ev);
 }
Index: gnu/java/awt/peer/swing/SwingComponentPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java,v
retrieving revision 1.3
diff -u -1 -0 -r1.3 SwingComponentPeer.java
--- gnu/java/awt/peer/swing/SwingComponentPeer.java	18 Apr 2006 12:38:25 -0000	1.3
+++ gnu/java/awt/peer/swing/SwingComponentPeer.java	10 May 2006 15:13:50 -0000
@@ -41,20 +41,22 @@
 import java.awt.AWTException;
 import java.awt.BufferCapabilities;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.BufferCapabilities.FlipContents;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.PaintEvent;
 import java.awt.image.ColorModel;
 import java.awt.image.ImageObserver;
@@ -91,22 +93,23 @@
    */
   protected Component awtComponent;
 
   /**
    * The Swing component for this peer.
    */
   protected SwingComponent swingComponent;
 
   /**
    * Creates a SwingComponentPeer instance. Subclasses are expected to call
-   * this constructor and thereafter call [EMAIL PROTECTED] #init(Component, JComponent)}
-   * in order to setup the AWT and Swing components properly.
+   * this constructor and thereafter call
+   * [EMAIL PROTECTED] #init(Component, SwingComponent)} in order to setup the AWT and
+   * Swing components properly.
    */
   protected SwingComponentPeer()
   {
     // Nothing to do here.
   }
 
   /**
    * Initializes the AWT and Swing component for this peer. It is expected that
    * subclasses call this from within their constructor.
    *
@@ -157,23 +160,26 @@
    * eventually goes up to the top-level component peer, which is then expected
    * to deliver the image.
    *
    * @param width the width of the image to be created
    * @param height the height of the image to be created
    *
    * @return the created image
    */
   public Image createImage(int width, int height)
   {
-    Component parent = awtComponent.getParent();
-    ComponentPeer parentPeer = parent.getPeer();
-    return parentPeer.createImage(width, height);
+    GraphicsEnvironment graphicsEnv =
+      GraphicsEnvironment.getLocalGraphicsEnvironment();
+    GraphicsDevice dev = graphicsEnv.getDefaultScreenDevice();
+    GraphicsConfiguration conf = dev.getDefaultConfiguration();
+    Image image = conf.createCompatibleImage(width, height);
+    return image;
   }
 
   /**
    * Disables the component. This is called by [EMAIL PROTECTED] Component#disable()}.
    */
   public void disable()
   {
     if (swingComponent != null)
       swingComponent.getJComponent().setEnabled(false);
   }
@@ -435,34 +441,20 @@
   public Dimension preferredSize()
   {
     Dimension retVal;
     if (swingComponent != null)
       retVal = swingComponent.getJComponent().getPreferredSize();
     else
       retVal = new Dimension(0, 0);
     return retVal;
   }
 
-  /**
-   * Prepares an image for rendering on this component. This is called by
-   * [EMAIL PROTECTED] Component#prepareImage(Image, int, int, ImageObserver)}.
-   *
-   * @param img the image to prepare
-   * @param width the desired width of the rendered image
-   * @param height the desired height of the rendered image
-   * @param ob the image observer to be notified of updates in the preparation
-   *        process
-   *
-   * @return <code>true</code> if the image has been fully prepared,
-   *         <code>false</code> otherwise (in which case the image observer
-   *         receives updates)
-   */
   public void paint(Graphics graphics)
   {
     // FIXME: I don't know what this method is supposed to do.
   }
 
   /**
    * Prepares an image for rendering on this component. This is called by
    * [EMAIL PROTECTED] Component#prepareImage(Image, int, int, ImageObserver)}.
    *
    * @param img the image to prepare
@@ -471,22 +463,31 @@
    * @param ob the image observer to be notified of updates in the preparation
    *        process
    *
    * @return <code>true</code> if the image has been fully prepared,
    *         <code>false</code> otherwise (in which case the image observer
    *         receives updates)
    */
   public boolean prepareImage(Image img, int width, int height, ImageObserver ob)
   {
     Component parent = awtComponent.getParent();
-    ComponentPeer parentPeer = parent.getPeer();
-    return parentPeer.prepareImage(img, width, height, ob);
+    boolean res;
+    if(parent != null)
+      {
+        ComponentPeer parentPeer = parent.getPeer();
+        res = parentPeer.prepareImage(img, width, height, ob);
+      }
+    else
+      {
+        res = Toolkit.getDefaultToolkit().prepareImage(img, width, height, ob);
+      }
+    return res;
   }
 
   public void print(Graphics graphics)
   {
     // FIXME: I don't know what this method is supposed to do.
   }
 
   /**
    * Repaints the specified rectangle of this component. This is called from
    * [EMAIL PROTECTED] Component#repaint(long, int, int, int, int)}.
Index: gnu/java/awt/peer/swing/SwingContainerPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java,v
retrieving revision 1.2
diff -u -1 -0 -r1.2 SwingContainerPeer.java
--- gnu/java/awt/peer/swing/SwingContainerPeer.java	18 Apr 2006 12:38:26 -0000	1.2
+++ gnu/java/awt/peer/swing/SwingContainerPeer.java	10 May 2006 15:13:51 -0000
@@ -85,21 +85,26 @@
 
   /**
    * Returns the insets of the container.
    *
    * This is implemented to return the insets of the Swing container.
    *
    * @return the insets of the container
    */
   public Insets getInsets()
   {
-    return insets();
+    Insets retVal;
+    if (swingComponent != null)
+      retVal = swingComponent.getJComponent().getInsets();
+    else
+      retVal = new Insets(0, 0, 0, 0);
+    return retVal;
   }
 
   /**
    * Called before the validation of this containers begins.
    */
   public void beginValidate()
   {
     // Nothing to do here.
   }
 
@@ -202,20 +207,22 @@
   }
 
   /**
    * Handles mouse events by dispatching it to the correct component.
    *
    * @param ev the mouse event
    */
   protected void handleMouseEvent(MouseEvent ev)
   {
     Component comp = awtComponent.getComponentAt(ev.getPoint());
+    if(comp == null)
+      comp = awtComponent;
     if (comp != null)
       {
         ComponentPeer peer = comp.getPeer();
         if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
           {
             ev.translatePoint(comp.getX(), comp.getY());
             ev.setSource(comp);
             ((SwingComponentPeer) peer).handleMouseEvent(ev);
           }
       }
Index: gnu/java/awt/peer/swing/SwingFramePeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java,v
retrieving revision 1.2
diff -u -1 -0 -r1.2 SwingFramePeer.java
--- gnu/java/awt/peer/swing/SwingFramePeer.java	19 Jan 2006 20:19:04 -0000	1.2
+++ gnu/java/awt/peer/swing/SwingFramePeer.java	10 May 2006 15:13:51 -0000
@@ -46,23 +46,23 @@
 import java.awt.peer.FramePeer;
 
 /**
  * An abstract base class for FramePeer implementations based on Swing.
  * This class provides the ability to display and handle AWT MenuBars that
  * are based on Swing.
  *
  * As a minimum, a subclass must implement all the remaining abstract methods
  * as well as the following methods:
  * <ul>
- * <li>[EMAIL PROTECTED] ComponentPeer#getLocationOnScreen()}</li>
- * <li>[EMAIL PROTECTED] ComponentPeer#getGraphics()}</li>
- * <li>[EMAIL PROTECTED] ComponentPeer#createImage(int, int)}</li>
+ * <li>[EMAIL PROTECTED] java.awt.peer.ComponentPeer#getLocationOnScreen()}</li>
+ * <li>[EMAIL PROTECTED] java.awt.peer.ComponentPeer#getGraphics()}</li>
+ * <li>[EMAIL PROTECTED] java.awt.peer.ComponentPeer#createImage(int, int)}</li>
  * </ul>
  *
  * @author Roman Kennke ([EMAIL PROTECTED])
  */
 public abstract class SwingFramePeer
   extends SwingWindowPeer
   implements FramePeer
 {
   /**
    * The menu bar to display.
Index: gnu/java/awt/peer/swing/SwingMenuBarPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java,v
retrieving revision 1.1
diff -u -1 -0 -r1.1 SwingMenuBarPeer.java
--- gnu/java/awt/peer/swing/SwingMenuBarPeer.java	14 Jan 2006 00:26:26 -0000	1.1
+++ gnu/java/awt/peer/swing/SwingMenuBarPeer.java	10 May 2006 15:13:51 -0000
@@ -167,21 +167,21 @@
    */
   public void addMenu(Menu m)
   {
     SwingMenuPeer menuPeer = (SwingMenuPeer) m.getPeer();
     menuBar.add(menuPeer.menu);
   }
 
   /**
    * Adds a help menu to the menu bar.
    *
-   * @param m the menu to add
+   * @param menu the menu to add
    */
   public void addHelpMenu(Menu menu)
   {
     // FIXME: We should manage the help menu differently, so that it always
     // appears at the rightmost position.
     SwingMenuPeer menuPeer = (SwingMenuPeer) menu.getPeer();
     menuBar.add(menuPeer.menu);
   }
 
   /**
Index: gnu/java/awt/peer/swing/SwingTextFieldPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java,v
retrieving revision 1.1
diff -u -1 -0 -r1.1 SwingTextFieldPeer.java
--- gnu/java/awt/peer/swing/SwingTextFieldPeer.java	14 Jan 2006 00:26:26 -0000	1.1
+++ gnu/java/awt/peer/swing/SwingTextFieldPeer.java	10 May 2006 15:13:51 -0000
@@ -276,21 +276,21 @@
   {
     ((JTextField) swingComponent.getJComponent()).setText(text);
   }
 
   /**
    * Sets the current selection.
    *
    * @param startPos the start index of the selection
    * @param endPos the start index of the selection
    */
-  public void select(int start_pos, int endPos)
+  public void select(int startPos, int endPos)
   {
     // TODO: Must be implemented.
   }
 
   /**
    * Sets the editable flag of the text field.
    *
    * @param editable <code>true</code> to make the textfield editable,
    *        <code>false</code> to make it uneditable
    */
Index: gnu/java/awt/peer/swing/SwingWindowPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java,v
retrieving revision 1.1
diff -u -1 -0 -r1.1 SwingWindowPeer.java
--- gnu/java/awt/peer/swing/SwingWindowPeer.java	14 Jan 2006 00:26:26 -0000	1.1
+++ gnu/java/awt/peer/swing/SwingWindowPeer.java	10 May 2006 15:13:51 -0000
@@ -41,23 +41,23 @@
 import java.awt.peer.WindowPeer;
 
 /**
  * An abstract base class for Swing based WindowPeer implementation. Concrete
  * implementations of WindowPeers should subclass this class in order to get
  * the correct behaviour.
  *
  * As a minimum, a subclass must implement all the remaining abstract methods
  * as well as the following methods:
  * <ul>
- * <li>[EMAIL PROTECTED] ComponentPeer#getLocationOnScreen()}</li>
- * <li>[EMAIL PROTECTED] ComponentPeer#getGraphics()}</li>
- * <li>[EMAIL PROTECTED] ComponentPeer#createImage(int, int)}</li>
+ * <li>[EMAIL PROTECTED] java.awt.peer.ComponentPeer#getLocationOnScreen()}</li>
+ * <li>[EMAIL PROTECTED] java.awt.peer.ComponentPeer#getGraphics()}</li>
+ * <li>[EMAIL PROTECTED] java.awt.peer.ComponentPeer#createImage(int, int)}</li>
  * </ul>
  *
  * @author Roman Kennke ([EMAIL PROTECTED])
  */
 public abstract class SwingWindowPeer
   extends SwingContainerPeer
   implements WindowPeer
 {
 
   /**

Reply via email to