summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/awt/peer/swing
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/classpath/gnu/java/awt/peer/swing
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/swing')
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java261
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java64
-rwxr-xr-xlibjava/classpath/gnu/java/awt/peer/swing/SwingCheckboxPeer.java256
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java99
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java1136
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java378
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java197
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java242
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java364
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java295
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java157
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java284
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java67
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java487
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java411
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java181
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java99
-rw-r--r--libjava/classpath/gnu/java/awt/peer/swing/package.html71
18 files changed, 5049 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java
new file mode 100644
index 000000000..1a42fc953
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java
@@ -0,0 +1,261 @@
+/* SwingButtonPeer.java -- A Swing based peer for AWT buttons
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Button;
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.ButtonPeer;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+
+/**
+ * A Swing based peer for the AWT button.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingButtonPeer
+ extends SwingComponentPeer
+ implements ButtonPeer
+{
+
+ /**
+ * A specialized Swing button to be used as AWT button.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ class SwingButton
+ extends JButton
+ implements SwingComponent
+ {
+ Button button;
+
+ SwingButton(Button button)
+ {
+ this.button = button;
+ }
+
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingButtonPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return <code>true</code> if the button is currently showing,
+ * <code>false</code> otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (button != null)
+ retVal = button.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingButtonPeer.this.createImage(w, h);
+ }
+
+ /**
+ * Overridden, so that the Swing button can create a Graphics without its
+ * own peer.
+ *
+ * @return a graphics instance for the button
+ */
+ public Graphics getGraphics()
+ {
+ return SwingButtonPeer.this.getGraphics();
+ }
+
+ /**
+ * Returns this button.
+ *
+ * @return this button
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * <code>processMouseEvent()</code> after having retargetted it to this
+ * button.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * <code>processMouseMotionEvent()</code> after having retargetted it to
+ * this button.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to
+ * <code>processKeyEvent()</code> after having retargetted it to this
+ * button.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ ev.setSource(this);
+ processKeyEvent(ev);
+ }
+
+ public Container getParent()
+ {
+ Container par = null;
+ if (button != null)
+ par = button.getParent();
+ return par;
+ }
+
+ /**
+ * Handles focus events by forwarding it to
+ * <code>processFocusEvent()</code>.
+ *
+ * @param ev the Focus event
+ */
+ public void handleFocusEvent(FocusEvent ev)
+ {
+ processFocusEvent(ev);
+ }
+
+ public void requestFocus() {
+ SwingButtonPeer.this.requestFocus(awtComponent, false, true, 0);
+ }
+
+ public boolean requestFocus(boolean temporary) {
+ return SwingButtonPeer.this.requestFocus(awtComponent, temporary,
+ true, 0);
+ }
+ }
+
+ /**
+ * Listens for ActionEvents on the Swing button and triggers corresponding
+ * ActionEvents on the AWT button.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ class SwingButtonListener implements ActionListener
+ {
+
+ /**
+ * Receives notification when an action was performend on the button.
+ *
+ * @param event the action event
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ Button b = (Button) SwingButtonPeer.this.awtComponent;
+ ActionListener[] l = b.getActionListeners();
+ if (l.length == 0)
+ return;
+ ActionEvent ev = new ActionEvent(b, ActionEvent.ACTION_PERFORMED,
+ b.getActionCommand());
+ for (int i = 0; i < l.length; ++i)
+ l[i].actionPerformed(ev);
+ }
+
+ }
+
+ /**
+ * Constructs a new SwingButtonPeer.
+ *
+ * @param theButton the AWT button for this peer
+ */
+ public SwingButtonPeer(Button theButton)
+ {
+ SwingButton button = new SwingButton(theButton);
+ button.setText(theButton.getLabel());
+ button.addActionListener(new SwingButtonListener());
+ init(theButton, button);
+ }
+
+ /**
+ * Sets the label of the button. This call is forwarded to the setText method
+ * of the managed Swing button.
+ *
+ * @param label the label to set
+ */
+ public void setLabel(String label)
+ {
+ ((SwingButton) swingComponent).setText(label);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java
new file mode 100644
index 000000000..abef9ef12
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java
@@ -0,0 +1,64 @@
+/* SwingCanvasPeer.java -- A canvas peer based on Swing
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Canvas;
+import java.awt.peer.CanvasPeer;
+import java.awt.peer.LightweightPeer;
+
+/**
+ * A CanvasPeer to be used together with the Swing peers.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingCanvasPeer
+ extends SwingComponentPeer
+ implements LightweightPeer, CanvasPeer
+{
+
+ /**
+ * Creates a new <code>SwingCanvasPeer</code> for the specified Canvas.
+ *
+ * @param canvas the canvas.
+ */
+ public SwingCanvasPeer(Canvas canvas)
+ {
+ init(canvas, null);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingCheckboxPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingCheckboxPeer.java
new file mode 100755
index 000000000..7080831a2
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingCheckboxPeer.java
@@ -0,0 +1,256 @@
+/* SwingCheckboxPeer.java -- A Swing based peer for AWT checkboxes
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.event.FocusEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.CheckboxPeer;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JToggleButton;
+
+/**
+ * A CheckboxPeer implementation that is backed by the Swing JCheckBox.
+ */
+public class SwingCheckboxPeer extends SwingComponentPeer implements
+ CheckboxPeer {
+
+ /**
+ * A spezialized Swing checkbox used to paint the checkbox for the
+ * AWT checkbox.
+ */
+ private class SwingCheckbox
+ extends JCheckBox
+ implements SwingComponent
+ {
+ Checkbox checkbox;
+
+ SwingCheckbox(Checkbox checkbox)
+ {
+ this.checkbox = checkbox;
+ }
+
+ /**
+ * Returns this checkbox.
+ *
+ * @return <code>this</code>
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * <code>processMouseEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * <code>processMouseMotionEvent()</code>.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to <code>processKeyEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ ev.setSource(this);
+ processKeyEvent(ev);
+ }
+
+ /**
+ * Handles focus events by forwarding it to
+ * <code>processFocusEvent()</code>.
+ *
+ * @param ev the Focus event
+ */
+ public void handleFocusEvent(FocusEvent ev)
+ {
+ processFocusEvent(ev);
+ }
+
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingCheckboxPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value
+ * for the swing button, even if it has no peer on its own.
+ *
+ * @return <code>true</code> if the button is currently showing,
+ * <code>false</code> otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (checkbox != null)
+ retVal = checkbox.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingCheckboxPeer.this.createImage(w, h);
+ }
+
+ public Graphics getGraphics()
+ {
+ return SwingCheckboxPeer.this.getGraphics();
+ }
+
+ public Container getParent()
+ {
+ Container par = null;
+ if (checkbox != null)
+ par = checkbox.getParent();
+ return par;
+ }
+
+ public void requestFocus() {
+ SwingCheckboxPeer.this.requestFocus(awtComponent, false, true, 0);
+ }
+
+ public boolean requestFocus(boolean temporary) {
+ return SwingCheckboxPeer.this.requestFocus(awtComponent, temporary,
+ true, 0);
+ }
+ }
+
+ /**
+ * Listens for ActionEvents on the Swing button and triggers corresponding
+ * ActionEvents on the AWT button.
+ */
+ class SwingCheckboxListener implements ItemListener
+ {
+ Checkbox awtCheckbox;
+
+ SwingCheckboxListener(Checkbox checkbox)
+ {
+ awtCheckbox = checkbox;
+ }
+
+ /**
+ * Receives notification when an action was performend on the button.
+ *
+ * @param event the action event
+ */
+ public void itemStateChanged(ItemEvent event)
+ {
+ awtCheckbox.setState(event.getStateChange()==ItemEvent.SELECTED);
+ ItemListener[] l = awtCheckbox.getItemListeners();
+ if (l.length == 0)
+ return;
+ ItemEvent ev = new ItemEvent(awtCheckbox, ItemEvent.ITEM_STATE_CHANGED,
+ awtCheckbox, event.getStateChange());
+ for (int i = 0; i < l.length; ++i)
+ l[i].itemStateChanged(ev);
+ }
+ }
+
+ /**
+ * Creates a new SwingCheckboxPeer instance.
+ */
+ public SwingCheckboxPeer(Checkbox checkbox)
+ {
+ SwingCheckbox swingCheckbox = new SwingCheckbox(checkbox);
+ swingCheckbox.addItemListener(new SwingCheckboxListener(checkbox));
+
+ init(checkbox, swingCheckbox);
+ setLabel(checkbox.getLabel());
+ setState(checkbox.getState());
+ }
+
+ public void setCheckboxGroup(CheckboxGroup group)
+ {
+ // TODO: Implement this.
+ }
+
+ public void setLabel(String label)
+ {
+ ((JToggleButton) swingComponent).setText(label);
+ }
+
+ public void setState(boolean state)
+ {
+ ((JToggleButton) swingComponent).setSelected(state);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java
new file mode 100644
index 000000000..ca42fb748
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java
@@ -0,0 +1,99 @@
+/* SwingComponent.java -- An interface that defines a Swing component for peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JComponent;
+
+/**
+ * Defines some additional methods that the Swing components must implement
+ * in order to work with the Swing peers. This is usually achieved by
+ * subclassing a Swing component and forwarding the method calls to some
+ * protected JComponent method.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public interface SwingComponent
+{
+
+ /**
+ * Returns the actual swing compenent.
+ *
+ * @return the actual swing compenent
+ */
+ JComponent getJComponent();
+
+ /**
+ * Handles a mouse event. This is usually forwarded to
+ * {@link 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
+ * {@link 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
+ * {@link Component#processKeyEvent(KeyEvent)} of the swing
+ * component.
+ *
+ * @param ev the key event
+ */
+ void handleKeyEvent(KeyEvent ev);
+
+ /**
+ * Handles a focus event. This is usually forwarded to
+ * {@link Component#processFocusEvent(FocusEvent)} of the swing
+ * component.
+ *
+ * @param ev the focus event
+ */
+ void handleFocusEvent(FocusEvent ev);
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java
new file mode 100644
index 000000000..8be95dcb7
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java
@@ -0,0 +1,1136 @@
+/* SwingComponentPeer.java -- An abstract base class for Swing based peers
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.AWTEvent;
+import java.awt.AWTException;
+import java.awt.BufferCapabilities;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+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.FocusEvent;
+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;
+import java.awt.image.ImageProducer;
+import java.awt.image.VolatileImage;
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.ContainerPeer;
+import java.awt.peer.LightweightPeer;
+
+import javax.swing.JComponent;
+import javax.swing.RepaintManager;
+
+/**
+ * The base class for Swing based component peers. This provides the basic
+ * functionality needed for Swing based component peers. Many methods are
+ * implemented to forward to the Swing component. Others however forward
+ * to the component's parent and expect the toplevel component peer to provide
+ * a real implementation of it. These are for example the key methods
+ * {@link #getGraphics()} and {@link #createImage(int, int)}, as well as
+ * {@link #getLocationOnScreen()}.
+ *
+ * This class also provides the necesary hooks into the Swing painting and
+ * event handling system. In order to achieve this, it traps paint, mouse and
+ * key events in {@link #handleEvent(AWTEvent)} and calls some special methods
+ * ({@link #peerPaint(Graphics)}, {@link #handleKeyEvent(KeyEvent)},
+ * {@link #handleMouseEvent(MouseEvent)} and
+ * {@link #handleMouseMotionEvent(MouseEvent)}) that call the corresponding
+ * Swing methods.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingComponentPeer
+ implements ComponentPeer
+{
+
+ /**
+ * The AWT component for this peer.
+ */
+ protected Component awtComponent;
+
+ /**
+ * The Swing component for this peer.
+ */
+ protected SwingComponent swingComponent;
+
+ /**
+ * The font that is set for this peer.
+ */
+ protected Font peerFont;
+
+ /**
+ * The current repaint area.
+ */
+ protected Rectangle paintArea;
+
+ /**
+ * Creates a SwingComponentPeer instance. Subclasses are expected to call
+ * this constructor and thereafter call {@link #init(Component, JComponent)}
+ * 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.
+ *
+ * @param awtComp the AWT component for this peer
+ * @param swingComp the Swing component for this peer
+ */
+ protected void init(Component awtComp, SwingComponent swingComp)
+ {
+ awtComponent = awtComp;
+ swingComponent = swingComp;
+ if (swingComponent != null)
+ {
+ JComponent c = swingComponent.getJComponent();
+ if (c != null)
+ {
+ c.addNotify();
+ RepaintManager.currentManager(c).setDoubleBufferingEnabled(false);
+ System.setProperty("gnu.awt.swing.doublebuffering", "true");
+ }
+ }
+
+ // Register this heavyweight component with the nearest heavyweight
+ // container, so we get peerPaint() triggered by that container.
+ if (! (this instanceof LightweightPeer))
+ {
+ Component comp = awtComponent;
+ Container parent = comp.getParent();
+ while (parent != null &&
+ ! (parent.getPeer() instanceof SwingContainerPeer))
+ {
+ comp = parent;
+ parent = comp.getParent();
+ }
+
+ // At this point we have the ancestor with a SwingContainerPeer
+ // (or null peer).
+ if (parent != null && parent.getPeer() instanceof SwingContainerPeer)
+ {
+ SwingContainerPeer p = (SwingContainerPeer) parent.getPeer();
+ p.addHeavyweightDescendent(awtComponent);
+ }
+ }
+ }
+
+ /**
+ * Returns the construction status of the specified image. This is called
+ * by {@link Component#checkImage(Image, int, int, ImageObserver)}.
+ *
+ * @param img the image
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param ob the image observer to be notified of updates of the status
+ *
+ * @return a bitwise ORed set of ImageObserver flags
+ */
+ public int checkImage(Image img, int width, int height, ImageObserver ob)
+ {
+ return Toolkit.getDefaultToolkit().checkImage(img, width, height, ob);
+ }
+
+ /**
+ * Creates an image by starting the specified image producer. This is called
+ * by {@link Component#createImage(ImageProducer)}.
+ *
+ * @param prod the image producer to be used to create the image
+ *
+ * @return the created image
+ */
+ public Image createImage(ImageProducer prod)
+ {
+ Image image = Toolkit.getDefaultToolkit().createImage(prod);
+ return image;
+ }
+
+ /**
+ * Creates an empty image with the specified <code>width</code> and
+ * <code>height</code>.
+ *
+ * This is implemented to let the parent component create the image. This
+ * 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);
+ }
+
+ /**
+ * Disables the component. This is called by {@link Component#disable()}.
+ */
+ public void disable()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setEnabled(false);
+ }
+
+ /**
+ * Disposes the component peer. This should release all resources held by the
+ * peer. This is called when the component is no longer in use.
+ */
+ public void dispose()
+ {
+ // Unregister this heavyweight component from the nearest heavyweight
+ // container.
+ if (! (this instanceof LightweightPeer))
+ {
+ Component comp = awtComponent;
+ Container parent = comp.getParent();
+ while (parent != null &&
+ ! (parent.getPeer() instanceof SwingContainerPeer))
+ {
+ comp = parent;
+ parent = comp.getParent();
+ }
+
+ // At this point we have the ancestor with a SwingContainerPeer
+ // (or null peer).
+ if (parent != null && parent.getPeer() instanceof SwingContainerPeer)
+ {
+ SwingContainerPeer p = (SwingContainerPeer) parent.getPeer();
+ p.removeHeavyweightDescendent(awtComponent);
+ }
+ }
+
+ awtComponent = null;
+ swingComponent = null;
+ }
+
+ /**
+ * Enables the component. This is called by {@link Component#enable()}.
+ */
+ public void enable()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setEnabled(true);
+ }
+
+ /**
+ * Returns the color model of the component. This is currently not used.
+ *
+ * @return the color model of the component
+ */
+ public ColorModel getColorModel()
+ {
+ // FIXME: When this peer method will be used, we need to provide an
+ // implementation of this, probably forwarding to the toplevel peer, like
+ // in the other methods.
+ return null;
+ }
+
+ /**
+ * Returns the font metrics for the specified font. This is called by
+ * {@link Component#getFontMetrics(Font)}.
+ *
+ * This is implemented to query the font metrics from the parent component.
+ * This will eventually call the top-level component peer, which is then
+ * expected to deliver a font metrics object.
+ *
+ * @param f the font for which to query the font metrics
+ *
+ * @return the font metrics for the specified font
+ */
+ public FontMetrics getFontMetrics(Font f)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.getFontMetrics(f);
+ }
+
+ /**
+ * Returns a {@link Graphics} object suitable for drawing on this component.
+ * This is called by {@link Component#getGraphics()}.
+ *
+ * This is implemented to query the graphics from the parent component and
+ * adjust the clip and translation to match this component.
+ * This will eventually call the top-level component peer, which is then
+ * expected to deliver a graphics object.
+ *
+ * @return a graphics object suitable for drawing on this component
+ */
+ public Graphics getGraphics()
+ {
+ Component parent = awtComponent.getParent();
+ Graphics g = parent.getGraphics();
+ g.translate(awtComponent.getX(), awtComponent.getY());
+ g.setClip(0, 0, awtComponent.getWidth(), awtComponent.getHeight());
+ return g;
+ }
+
+ /**
+ * Returns the location of this component in screen coordinates. This is
+ * called by {@link Component#getLocationOnScreen()}.
+ *
+ * This is implemented to query the parent component peer for its screen
+ * location and adds the offset of this component to it. This will eventually
+ * call the top-level component's peer, which is then expected to provide
+ * it's screen location.
+ *
+ * @return the location of this component in screen coordinates
+ */
+ public Point getLocationOnScreen()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ Point location = parentPeer.getLocationOnScreen();
+ location.x += awtComponent.getX();
+ location.y += awtComponent.getY();
+ return location;
+ }
+
+ /**
+ * Returns the minimum size for the component. This is called by
+ * {@link Component#getMinimumSize()}.
+ *
+ * This is implemented to return the Swing component's minimum size.
+ *
+ * @return the minimum size for the component
+ */
+ public Dimension getMinimumSize()
+ {
+ return minimumSize();
+ }
+
+ /**
+ * Returns the preferred size for the component. This is called by
+ * {@link Component#getPreferredSize()}.
+ *
+ * This is implemented to return the Swing component's preferred size.
+ *
+ * @return the preferred size for the component
+ */
+ public Dimension getPreferredSize()
+ {
+ return preferredSize();
+ }
+
+ /**
+ * Returns the toolkit that created this peer.
+ *
+ * @return the toolkit that created this peer
+ */
+ public Toolkit getToolkit()
+ {
+ return Toolkit.getDefaultToolkit();
+ }
+
+ /**
+ * Handles the given event. This is called from
+ * {@link Component#dispatchEvent(AWTEvent)} to give the peer a chance to
+ * react to events for the component.
+ *
+ * @param e the event
+ */
+ public void handleEvent(AWTEvent e)
+ {
+ switch (e.getID())
+ {
+ case PaintEvent.UPDATE:
+ case PaintEvent.PAINT:
+ if (awtComponent.isShowing())
+ {
+ Rectangle clip ;
+ synchronized (this)
+ {
+ coalescePaintEvent((PaintEvent) e);
+ assert paintArea != null;
+ clip = paintArea;
+ paintArea = null;
+ }
+ Graphics g = awtComponent.getGraphics();
+ try
+ {
+ g.clipRect(clip.x, clip.y, clip.width, clip.height);
+ peerPaint(g, e.getID() == PaintEvent.UPDATE);
+ }
+ finally
+ {
+ g.dispose();
+ }
+ }
+ break;
+ case MouseEvent.MOUSE_PRESSED:
+ case MouseEvent.MOUSE_RELEASED:
+ case MouseEvent.MOUSE_CLICKED:
+ case MouseEvent.MOUSE_ENTERED:
+ case MouseEvent.MOUSE_EXITED:
+ handleMouseEvent((MouseEvent) e);
+ break;
+ case MouseEvent.MOUSE_MOVED:
+ case MouseEvent.MOUSE_DRAGGED:
+ handleMouseMotionEvent((MouseEvent) e);
+ break;
+ case KeyEvent.KEY_PRESSED:
+ case KeyEvent.KEY_RELEASED:
+ case KeyEvent.KEY_TYPED:
+ handleKeyEvent((KeyEvent) e);
+ break;
+ case FocusEvent.FOCUS_GAINED:
+ case FocusEvent.FOCUS_LOST:
+ handleFocusEvent((FocusEvent)e);
+ break;
+ default:
+ // Other event types are not handled here.
+ break;
+ }
+ }
+
+ /**
+ * Makes the component invisible. This is called from
+ * {@link Component#hide()}.
+ *
+ * This is implemented to call setVisible(false) on the Swing component.
+ */
+ public void hide()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setVisible(false);
+
+ Component parent = awtComponent.getParent();
+ if (parent != null)
+ parent.repaint(awtComponent.getX(), awtComponent.getY(),
+ awtComponent.getWidth(), awtComponent.getHeight());
+ }
+
+ /**
+ * Returns <code>true</code> if the component can receive keyboard input
+ * focus. This is called from {@link Component#isFocusTraversable()}.
+ *
+ * This is implemented to return isFocusable() from the Swing component.
+ *
+ * @specnote Part of the earlier 1.1 API, replaced by isFocusable().
+ */
+ public boolean isFocusTraversable()
+ {
+ return swingComponent != null ?
+ swingComponent.getJComponent().isFocusable() : false;
+ }
+
+ /**
+ * Returns <code>true</code> if the component can receive keyboard input
+ * focus. This is called from {@link Component#isFocusable()}.
+ *
+ * This is implemented to return isFocusable() from the Swing component.
+ */
+ public boolean isFocusable()
+ {
+ return swingComponent != null ?
+ swingComponent.getJComponent().isFocusable() : false;
+ }
+
+ /**
+ * Returns the minimum size for the component. This is called by
+ * {@link Component#minimumSize()}.
+ *
+ * This is implemented to return the Swing component's minimum size.
+ *
+ * @return the minimum size for the component
+ */
+ public Dimension minimumSize()
+ {
+ Dimension retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getMinimumSize();
+ else
+ retVal = new Dimension(0, 0);
+ return retVal;
+ }
+
+ /**
+ * Returns the preferred size for the component. This is called by
+ * {@link Component#getPreferredSize()}.
+ *
+ * This is implemented to return the Swing component's preferred size.
+ *
+ * @return the preferred size for the component
+ */
+ public Dimension preferredSize()
+ {
+ Dimension retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getPreferredSize();
+ else
+ retVal = new Dimension(0, 0);
+ return retVal;
+ }
+
+ /**
+ * Paints the component. This is triggered by
+ * {@link Component#paintAll(Graphics)}.
+ *
+ * @param graphics the graphics to paint with
+ */
+ public void paint(Graphics graphics)
+ {
+ peerPaint(graphics, false);
+ }
+
+ /**
+ * Prepares an image for rendering on this component. This is called by
+ * {@link 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 boolean prepareImage(Image img, int width, int height, ImageObserver ob)
+ {
+ Component parent = awtComponent.getParent();
+ if(parent != null)
+ {
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.prepareImage(img, width, height, ob);
+ }
+ else
+ {
+ return Toolkit.getDefaultToolkit().prepareImage(img, width, height, ob);
+ }
+ }
+
+ 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
+ * {@link Component#repaint(long, int, int, int, int)}.
+ *
+ * This is implemented to call repaint() on the Swing component.
+ *
+ * @param tm number of milliseconds to wait with repainting
+ * @param x the X coordinate of the upper left corner of the damaged
+ * rectangle
+ * @param y the Y coordinate of the upper left corner of the damaged
+ * rectangle
+ * @param width the width of the damaged rectangle
+ * @param height the height of the damaged rectangle
+ */
+ public void repaint(long tm, int x, int y, int width, int height)
+ {
+ // NOTE: This is never called by AWT but is mandated by the peer interface.
+ if (swingComponent != null)
+ swingComponent.getJComponent().repaint(tm, x, y, width, height);
+ else
+ {
+ PaintEvent ev = new PaintEvent(awtComponent, PaintEvent.UPDATE,
+ new Rectangle(x, y, width, height));
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev);
+ }
+ }
+
+ /**
+ * Requests that this component receives the focus. This is called from
+ * {@link Component#requestFocus()}.
+ *
+ * This calls requestFocus() on the Swing component.
+ *
+ * @specnote Part of the earlier 1.1 API, apparently replaced by argument
+ * form of the same method.
+ */
+ public void requestFocus()
+ {
+ // NOTE: This is never called by AWT but is mandated by the peer interface.
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ EventQueue q = tk.getSystemEventQueue();
+ q.postEvent(new FocusEvent(awtComponent, FocusEvent.FOCUS_GAINED, false));
+ }
+
+ /**
+ * Requests that this component receives the focus. This is called from
+ * {@link Component#requestFocus()}.
+ *
+ * This calls requestFocus() on the Swing component.
+ *
+ * @param source the actual component that requests focus (may be a
+ * lightweight descendant of the heavyweight container)
+ * @param tmp true when the change is temporary
+ * @param allowWindowFocus
+ * @param tm the timestamp of the focus change
+ *
+ * @return true when the focus change is guaranteed to be granted, false
+ * otherwise
+ */
+ public boolean requestFocus(Component source, boolean tmp,
+ boolean allowWindowFocus, long tm)
+ {
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ EventQueue q = tk.getSystemEventQueue();
+ q.postEvent(new FocusEvent(source, FocusEvent.FOCUS_GAINED, tmp));
+ return true;
+ }
+
+ /**
+ * Notifies the peer that the bounds of this component have changed. This
+ * is called by {@link Component#reshape(int, int, int, int)}.
+ *
+ * This is implemented to call setBounds() on the Swing component.
+ *
+ * @param x the X coordinate of the upper left corner of the component
+ * @param y the Y coordinate of the upper left corner of the component
+ * @param width the width of the component
+ * @param height the height of the component
+ */
+ public void reshape(int x, int y, int width, int height)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ }
+
+ /**
+ * Sets the background color of the component. This is called by
+ * {@link Component#setBackground(Color)}.
+ *
+ * This is implemented to call setBackground() on the Swing component.
+ *
+ * @param color the background color to set
+ */
+ public void setBackground(Color color)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBackground(color);
+ }
+
+ /**
+ * Notifies the peer that the bounds of this component have changed. This
+ * is called by {@link Component#setBounds(int, int, int, int)}.
+ *
+ * This is implemented to call setBounds() on the Swing component.
+ *
+ * @param x the X coordinate of the upper left corner of the component
+ * @param y the Y coordinate of the upper left corner of the component
+ * @param width the width of the component
+ * @param height the height of the component
+ */
+ public void setBounds(int x, int y, int width, int height)
+ {
+ reshape(x, y, width, height);
+ }
+
+ /**
+ * Sets the cursor of the component. This is called by
+ * {@link Component#setCursor(Cursor)}.
+ *
+ * This is implemented to call setCursor() on the Swing component.
+ *
+ * @specnote Part of the earlier 1.1 API, apparently no longer needed.
+ */
+ public void setCursor(Cursor cursor)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setCursor(cursor);
+ }
+
+ /**
+ * Sets the enabled/disabled state of this component. This is called by
+ * {@link Component#setEnabled(boolean)}.
+ *
+ * This is implemented to call setEnabled() on the Swing component.
+ *
+ * @param enabled <code>true</code> to enable the component,
+ * <code>false</code> to disable it
+ */
+ public void setEnabled(boolean enabled)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setEnabled(enabled);
+ }
+
+ /**
+ * Sets the font of the component. This is called by
+ * {@link Component#setFont(Font)}.
+ *
+ * This is implemented to call setFont() on the Swing component.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ peerFont = font;
+ if (swingComponent != null)
+ swingComponent.getJComponent().setFont(font);
+ }
+
+ /**
+ * Sets the foreground color of the component. This is called by
+ * {@link Component#setForeground(Color)}.
+ *
+ * This is implemented to call setForeground() on the Swing component.
+ *
+ * @param color the foreground color to set
+ */
+ public void setForeground(Color color)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setForeground(color);
+ }
+
+ /**
+ * Sets the visibility state of the component. This is called by
+ * {@link Component#setVisible(boolean)}.
+ *
+ * This is implemented to call setVisible() on the Swing component.
+ *
+ * @param visible <code>true</code> to make the component visible,
+ * <code>false</code> to make it invisible
+ */
+ public void setVisible(boolean visible)
+ {
+ if (visible)
+ show();
+ else
+ hide();
+ }
+
+ /**
+ * Makes the component visible. This is called by {@link Component#show()}.
+ *
+ * This is implemented to call setVisible(true) on the Swing component.
+ */
+ public void show()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setVisible(true);
+ }
+
+ /**
+ * Get the graphics configuration of the component. The color model
+ * of the component can be derived from the configuration.
+ *
+ * This is implemented to return the GraphicsConfiguration of the parent
+ * component. This will eventually call the toplevel component peer, which
+ * is expected to provide a real implementation.
+ *
+ * @return the graphics configuration of the component
+ */
+ public GraphicsConfiguration getGraphicsConfiguration()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.getGraphicsConfiguration();
+ }
+
+ /**
+ * Part of an older API, no longer needed.
+ */
+ public void setEventMask(long mask)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns <code>true</code> if this component has been obscured,
+ * <code>false</code> otherwise. This will only work if
+ * {@link #canDetermineObscurity()} also returns <code>true</code>.
+ *
+ * This is not yet implemented.
+ *
+ * @return <code>true</code> if this component has been obscured,
+ * <code>false</code> otherwise.
+ */
+ public boolean isObscured()
+ {
+ return false;
+ }
+
+ /**
+ * Returns <code>true</code> if this component peer can determine if the
+ * component has been obscured, <code>false</code> otherwise.
+ *
+ * This is not yet implemented.
+ *
+ * @return <code>true</code> if this component peer can determine if the
+ * component has been obscured, <code>false</code> otherwise
+ */
+ public boolean canDetermineObscurity()
+ {
+ return false;
+ }
+
+ /**
+ * Coalesces the specified paint event.
+ *
+ * @param e the paint event
+ */
+ public void coalescePaintEvent(PaintEvent e)
+ {
+ synchronized (this)
+ {
+ Rectangle newRect = e.getUpdateRect();
+ if (paintArea == null)
+ paintArea = newRect;
+ else
+ Rectangle.union(paintArea, newRect, paintArea);
+ }
+ }
+
+ /**
+ * Updates the cursor. This is not yet implemented.
+ */
+ public void updateCursorImmediately()
+ {
+ // Nothing to do here yet.
+ }
+
+ /**
+ * Returns true, if this component can handle wheel scrolling,
+ * <code>false</code> otherwise.
+ *
+ * This is not yet implemented and returns <code>false</code>.
+ *
+ * @return true, if this component can handle wheel scrolling,
+ * <code>false</code> otherwise
+ */
+ public boolean handlesWheelScrolling()
+ {
+ return false;
+ }
+
+ /**
+ * A convenience method that creates a volatile image. The volatile
+ * image is created on the screen device on which this component is
+ * displayed, in the device's current graphics configuration.
+ *
+ * This is implemented to let the parent component peer create an image.
+ * This eventually ends up in the toplevel component peer, which is then
+ * responsible for creating the real image.
+ *
+ * @param width width of the image
+ * @param height height of the image
+ *
+ * @see VolatileImage
+ *
+ * @since 1.2
+ */
+ public VolatileImage createVolatileImage(int width, int height)
+ {
+ Component parent = awtComponent.getParent();
+ VolatileImage im = null;
+ if (parent != null)
+ {
+ ComponentPeer parentPeer = parent.getPeer();
+ im = parentPeer.createVolatileImage(width, height);
+ }
+ return im;
+ }
+
+ /**
+ * Create a number of image buffers that implement a buffering
+ * strategy according to the given capabilities.
+ *
+ * This is implemented to forward to the parent component peer. Eventually
+ * this ends up in the top level component peer, which is then responsible
+ * for doing the real work.
+ *
+ * @param numBuffers the number of buffers
+ * @param caps the buffering capabilities
+ *
+ * @throws AWTException if the specified buffering strategy is not
+ * implemented
+ *
+ * @since 1.2
+ */
+ public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ parentPeer.createBuffers(numBuffers, caps);
+ }
+
+ /**
+ * Return the back buffer of this component.
+ *
+ * This is implemented to forward to the parent. Eventually this ends
+ * up in the toplevel component, which is then responsible for providing
+ * a back buffer.
+ *
+ * @return the back buffer of this component.
+ *
+ * @since 1.2
+ */
+ public Image getBackBuffer()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.getBackBuffer();
+ }
+
+ /**
+ * Perform a page flip, leaving the contents of the back buffer in
+ * the specified state.
+ *
+ * This is implemented to forward to the parent. Eventually this ends
+ * up in the toplevel component, which is then responsible for doing the real
+ * work.
+ *
+ * @param contents the state in which to leave the back buffer
+ *
+ * @since 1.2
+ */
+ public void flip(FlipContents contents)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ parentPeer.flip(contents);
+ }
+
+ /**
+ * Destroy the resources created by createBuffers.
+ *
+ * This is implemented to forward to the parent component peer. Eventually
+ * this ends up in the top level component peer, which is then responsible
+ * for doing the real work.
+ *
+ * @since 1.2
+ */
+ public void destroyBuffers()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ parentPeer.destroyBuffers();
+ }
+
+ /**
+ * Get the bounds of this component peer.
+ *
+ * This is implemented to forward to the Swing component.
+ *
+ * @return component peer bounds
+ * @since 1.5
+ */
+ public Rectangle getBounds()
+ {
+ Rectangle retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getBounds();
+ else
+ retVal = new Rectangle();
+ return retVal;
+ }
+
+ /**
+ * Reparent this component under another container.
+ *
+ * @param parent
+ * @since 1.5
+ */
+ public void reparent(ContainerPeer parent)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Set the bounds of this component peer.
+ *
+ * This is implemented to forward to the swing component.
+ *
+ * @param x the new x co-ordinate
+ * @param y the new y co-ordinate
+ * @param width the new width
+ * @param height the new height
+ * @param z the new stacking level
+ * @since 1.5
+ */
+ public void setBounds(int x, int y, int width, int height, int z)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ // FIXME: Somehow handle the Z order.
+ }
+
+ /**
+ * Check if this component supports being reparented.
+ *
+ * @return true if this component can be reparented,
+ * false otherwise.
+ * @since 1.5
+ */
+ public boolean isReparentSupported()
+ {
+ return true;
+ }
+
+
+ /**
+ * Layout this component peer.
+ *
+ * @since 1.5
+ */
+ public void layout()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().doLayout();
+ }
+
+ /**
+ * Triggers 'heavyweight' painting of the components. This usually calls
+ * paint() on the Swing component.
+ *
+ * @param g the graphics context to use for painting
+ * @param update wether we need to call update or paint on the AWT component
+ */
+ protected void peerPaint(Graphics g, boolean update)
+ {
+ peerPaintComponent(g);
+
+ Graphics userGraphics = g.create();
+ try{
+ if (update)
+ awtComponent.update(userGraphics);
+ else
+ awtComponent.paint(userGraphics);
+ } finally {
+ userGraphics.dispose();
+ }
+
+ }
+
+ /**
+ * Paints the actual 'heavyweight' swing component, if there is one
+ * associated to this peer.
+ *
+ * @param g the graphics to paint the component with
+ */
+ protected void peerPaintComponent(Graphics g)
+ {
+ // Paint the actual Swing component if this peer has one.
+ if (swingComponent != null)
+ swingComponent.getJComponent().paint(g);
+ }
+
+ /**
+ * Handles mouse events on the component. This is usually forwarded to the
+ * SwingComponent's processMouseEvent() method.
+ *
+ * @param e the mouse event
+ */
+ protected void handleMouseEvent(MouseEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleMouseEvent(e);
+ }
+
+ /**
+ * Handles mouse motion events on the component. This is usually forwarded
+ * to the SwingComponent's processMouseMotionEvent() method.
+ *
+ * @param e the mouse motion event
+ */
+ protected void handleMouseMotionEvent(MouseEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleMouseMotionEvent(e);
+ }
+
+ /**
+ * Handles key events on the component. This is usually forwarded to the
+ * SwingComponent's processKeyEvent() method.
+ *
+ * @param e the key event
+ */
+ protected void handleKeyEvent(KeyEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleKeyEvent(e);
+ }
+
+ /**
+ * Handles focus events on the component. This is usually forwarded to the
+ * SwingComponent's processFocusEvent() method.
+ *
+ * @param e the key event
+ */
+ protected void handleFocusEvent(FocusEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleFocusEvent(e);
+ }
+
+
+ /**
+ * Returns the AWT component for this peer.
+ *
+ * @return the AWT component for this peer
+ */
+ public Component getComponent()
+ {
+ return awtComponent;
+ }
+
+ public boolean requestFocus(Component lightweightChild, boolean temporary,
+ boolean focusedWindowChangeAllowed,
+ long time, sun.awt.CausedFocusEvent.Cause cause)
+ {
+ return true;
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java
new file mode 100644
index 000000000..ca3adc4c7
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java
@@ -0,0 +1,378 @@
+/* SwingContainerPeer.java -- A Swing based peer for AWT containers
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import gnu.classpath.SystemProperties;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.ContainerPeer;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * A peer for Container to be used with the Swing based AWT peers.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingContainerPeer
+ extends SwingComponentPeer
+ implements ContainerPeer
+{
+
+ /**
+ * Stores all heavyweight descendents of the container. This is used
+ * in {@link #peerPaintChildren(Graphics)}.
+ */
+ private LinkedList heavyweightDescendents;
+
+ /**
+ * The backbuffer used for painting UPDATE events.
+ */
+ private Image backbuffer;
+
+ /**
+ * Creates a new SwingContainerPeer.
+ *
+ * @param awtCont
+ */
+ public SwingContainerPeer(Container awtCont)
+ {
+ heavyweightDescendents = new LinkedList();
+ }
+
+ /**
+ * Registers a heavyweight descendent. This is then painted by
+ * {@link #peerPaintChildren(Graphics)}.
+ *
+ * @param comp the descendent to register
+ *
+ * @see #peerPaintChildren(Graphics)
+ * @see #removeHeavyweightDescendent(Component)
+ */
+ protected synchronized void addHeavyweightDescendent(Component comp)
+ {
+ heavyweightDescendents.add(comp);
+ focusOwner = null;
+ }
+
+ /**
+ * Unregisters a heavyweight descendent.
+ *
+ * @param comp the descendent to unregister
+ *
+ * @see #peerPaintChildren(Graphics)
+ * @see #addHeavyweightDescendent(Component)
+ */
+ protected synchronized void removeHeavyweightDescendent(Component comp)
+ {
+ heavyweightDescendents.remove(comp);
+ focusOwner = null;
+ }
+
+ /**
+ * Returns an array of all registered heavyweight descendents.
+ *
+ * @return all registered heavyweight descendents
+ */
+ protected Component[] getHeavyweightDescendents()
+ {
+ Component[] heavyweights = new Component[heavyweightDescendents.size()];
+ heavyweights = (Component[]) heavyweightDescendents.toArray(heavyweights);
+ return heavyweights;
+ }
+
+ /**
+ * 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 insets()
+ {
+ Insets retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getInsets();
+ else
+ retVal = new Insets(0, 0, 0, 0);
+ return retVal;
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * Called before the validation of this containers begins.
+ */
+ public void beginValidate()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called after the validation of this containers ended.
+ */
+ public void endValidate()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called before the layout of this containers begins.
+ */
+ public void beginLayout()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called after the layout of this containers ended.
+ */
+ public void endLayout()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns <code>false</code> unconditionally. This method is not used at
+ * the moment.
+ *
+ * @return <code>false</code>
+ */
+ public boolean isPaintPending()
+ {
+ return false;
+ }
+
+ /**
+ * Returns <code>false</code> unconditionally. This method is not used at
+ * the moment.
+ *
+ * @return <code>false</code>
+ */
+ public boolean isRestackSupported()
+ {
+ return false;
+ }
+
+ /**
+ * This method is not used at the moment.
+ */
+ public void cancelPendingPaint(int x, int y, int width, int height)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method is not used at the moment.
+ */
+ public void restack()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Performs the super behaviour (call peerPaintComponent() and
+ * awtComponent.paint()), and forwards the paint request to the heavyweight
+ * descendents of the container.
+ */
+ protected void peerPaint(Graphics g, boolean update)
+ {
+ if (isDoubleBuffering())
+ {
+ int width = awtComponent.getWidth();
+ int height = awtComponent.getHeight();
+ if (backbuffer == null
+ || backbuffer.getWidth(awtComponent) < width
+ || backbuffer.getHeight(awtComponent) < height)
+ backbuffer = awtComponent.createImage(width, height);
+ Graphics g2 = backbuffer.getGraphics();
+ Rectangle clip = g.getClipRect();
+ try
+ {
+ g2.setClip(clip);
+ super.peerPaint(g2, update);
+ peerPaintChildren(g2);
+ }
+ finally
+ {
+ g2.dispose();
+ }
+ g.drawImage(backbuffer, 0, 0, awtComponent);
+ }
+ else
+ {
+ super.peerPaint(g, update);
+ peerPaintChildren(g);
+ }
+ }
+
+ /**
+ * Determines if we should do double buffering or not.
+ *
+ * @return if we should do double buffering or not
+ */
+ private boolean isDoubleBuffering()
+ {
+ Object prop =
+ SystemProperties.getProperty("gnu.awt.swing.doublebuffering", "false");
+ return prop.equals("true");
+ }
+
+ /**
+ * Paints any heavyweight child components.
+ *
+ * @param g the graphics to use for painting
+ */
+ protected synchronized void peerPaintChildren(Graphics g)
+ {
+ // TODO: Is this the right painting order?
+ for (Iterator i = heavyweightDescendents.iterator(); i.hasNext();)
+ {
+ Component child = (Component) i.next();
+ ComponentPeer peer = child.getPeer();
+
+ if (peer instanceof SwingComponentPeer && child.isVisible())
+ {
+ // TODO: The translation here doesn't work for deeper
+ // nested children. Fix this!
+ Graphics g2 = g.create(child.getX(), child.getY(),
+ child.getWidth(), child.getHeight());
+ try
+ {
+ // update() is only called for the topmost component if
+ // necessary, all other components only get paint() called.
+ ((SwingComponentPeer) peer).peerPaint(g2, false);
+ }
+ finally
+ {
+ g2.dispose();
+ }
+ }
+ }
+ }
+
+ /**
+ * 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;
+ 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);
+ }
+ }
+
+ /**
+ * Handles mouse events by dispatching it to the correct component.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseMotionEvent(MouseEvent ev)
+ {
+ Component comp = awtComponent.getComponentAt(ev.getPoint());
+ if (comp != null)
+ {
+ ComponentPeer peer = comp.getPeer();
+ if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+ {
+ ev.translatePoint(comp.getX(), comp.getY());
+ ((SwingComponentPeer) peer).handleMouseMotionEvent(ev);
+ }
+ }
+ }
+
+ /**
+ * Handles key events on the component. This is usually forwarded to the
+ * SwingComponent's processKeyEvent() method.
+ *
+ * @param e the key event
+ */
+ protected void handleKeyEvent(KeyEvent e)
+ {
+ Component owner = getFocusOwner();
+ if(owner != null)
+ owner.getPeer().handleEvent(e);
+ else
+ super.handleKeyEvent(e);
+ }
+
+ private Component focusOwner = null;
+
+ private Component getFocusOwner()
+ {
+ if(focusOwner == null)
+ {
+ for(Iterator iter=heavyweightDescendents.iterator(); iter.hasNext();)
+ {
+ Component child = (Component) iter.next();
+ if(child.isFocusable())
+ {
+ focusOwner = child;
+ break;
+ }
+ }
+ }
+ return focusOwner;
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java
new file mode 100644
index 000000000..56c7417cd
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java
@@ -0,0 +1,197 @@
+/* SwingFramePeer.java -- An abstract Swing based peer for AWT frames
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.MenuBar;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.peer.ComponentPeer;
+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>{@link ComponentPeer#getLocationOnScreen()}</li>
+ * <li>{@link ComponentPeer#getGraphics()}</li>
+ * <li>{@link ComponentPeer#createImage(int, int)}</li>
+ * </ul>
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public abstract class SwingFramePeer
+ extends SwingWindowPeer
+ implements FramePeer
+{
+ /**
+ * The menu bar to display.
+ */
+ SwingMenuBarPeer menuBar = null;
+
+ /**
+ * Creates a new SwingFramePeer.
+ *
+ * @param frame the frame
+ */
+ public SwingFramePeer(Frame frame)
+ {
+ super(frame);
+ }
+
+ /**
+ * Sets the menu bar to display in this frame.
+ *
+ * @param mb the menu bar to set
+ */
+ public void setMenuBar(MenuBar mb)
+ {
+ menuBar = (SwingMenuBarPeer) mb.getPeer();
+ menuBar.setFramePeer(this);
+ menuBar.setWidth(awtComponent.getWidth());
+ }
+
+ /**
+ * Triggers 'heavyweight' painting of the frame. This will paint a menu bar
+ * if present as well as the child components of this frame.
+ *
+ * @param g the graphics context to use for painting
+ */
+ protected void peerPaintComponent(Graphics g)
+ {
+ super.peerPaintComponent(g);
+ if (menuBar != null)
+ menuBar.peerPaint(g);
+ }
+
+ /**
+ * Sets the size and location of this frame. This resizes the menubar to fit
+ * within the frame.
+ *
+ * @param x the X coordinate of the screen location
+ * @param y the Y coordinate of the screen location
+ * @param w the width of the frame
+ * @param h the height of the frame
+ */
+ public void setBounds(int x, int y, int w, int h)
+ {
+ super.setBounds(x, y, w, h);
+ if (menuBar != null)
+ menuBar.setWidth(w);
+ }
+
+ /**
+ * Calculates the insets of this frame peer. This fetches the insets
+ * from the superclass and adds the insets of the menubar if one is present.
+ *
+ * @return the insets of the frame
+ */
+ public Insets getInsets()
+ {
+ Insets insets = super.getInsets();
+ if (menuBar != null)
+ insets.top += menuBar.getHeight();
+ return insets;
+ }
+
+ /**
+ * Returns the location of the menu on the screen. This is needed internally
+ * by the {@link SwingMenuBarPeer} in order to determine its screen location.
+ *
+ * @return the location of the menu on the screen
+ */
+ public Point getMenuLocationOnScreen()
+ {
+ Insets i = super.getInsets();
+ return new Point(i.top, i.left);
+ }
+
+ /**
+ * Overridden to provide the ability to handle menus.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseEvent(MouseEvent ev)
+ {
+ Point p = ev.getPoint();
+ Insets i = super.getInsets();
+ if (menuBar != null)
+ {
+ int menuHeight = menuBar.getHeight();
+ if (p.y >= i.top && p.y <= i.top + menuHeight)
+ menuBar.handleMouseEvent(ev);
+ else
+ {
+ ev.translatePoint(0, -menuHeight);
+ super.handleMouseMotionEvent(ev);
+ }
+ }
+
+ super.handleMouseEvent(ev);
+ }
+
+ /**
+ * Overridden to provide the ability to handle menus.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseMotionEvent(MouseEvent ev)
+ {
+ Point p = ev.getPoint();
+ Insets i = super.getInsets();
+ if (menuBar != null)
+ {
+ int menuHeight = menuBar.getHeight();
+ if (p.y >= i.top && p.y <= i.top + menuHeight)
+ menuBar.handleMouseMotionEvent(ev);
+ else
+ {
+ ev.translatePoint(0, -menuHeight);
+ super.handleMouseMotionEvent(ev);
+ }
+ }
+
+ super.handleMouseMotionEvent(ev);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java
new file mode 100644
index 000000000..5c979d613
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java
@@ -0,0 +1,242 @@
+/* SwingLabelPeer.java -- A Swing based peer for AWT labels
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Label;
+import java.awt.Point;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.LabelPeer;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+
+
+/**
+ * A Label peer based on {@link JLabel}.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingLabelPeer
+ extends SwingComponentPeer
+ implements LabelPeer
+{
+
+ /**
+ * A spezialized Swing label used to paint the label for the AWT Label.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingLabel
+ extends JLabel
+ implements SwingComponent
+ {
+ Label label;
+
+
+ SwingLabel(Label label)
+ {
+ this.label = label;
+ }
+
+ /**
+ * Returns this label.
+ *
+ * @return <code>this</code>
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * <code>processMouseEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * <code>processMouseMotionEvent()</code>.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to <code>processKeyEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ processKeyEvent(ev);
+ }
+
+ /**
+ * Handles focus events by forwarding it to
+ * <code>processFocusEvent()</code>.
+ *
+ * @param ev the Focus event
+ */
+ public void handleFocusEvent(FocusEvent ev)
+ {
+ processFocusEvent(ev);
+ }
+
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingLabelPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return <code>true</code> if the button is currently showing,
+ * <code>false</code> otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (label != null)
+ retVal = label.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingLabelPeer.this.createImage(w, h);
+ }
+
+ public Graphics getGraphics()
+ {
+ return SwingLabelPeer.this.getGraphics();
+ }
+
+ public Container getParent()
+ {
+ Container par = null;
+ if (label != null)
+ par = label.getParent();
+ return par;
+ }
+ }
+
+ /**
+ * Creates a new <code>SwingLabelPeer</code> for the specified AWT label.
+ *
+ * @param label the AWT label
+ */
+ public SwingLabelPeer(Label label)
+ {
+ super();
+ SwingLabel swingLabel = new SwingLabel(label);
+ swingLabel.setText(label.getText());
+ swingLabel.setOpaque(true);
+ init(label, swingLabel);
+ setAlignment(label.getAlignment());
+ }
+
+ /**
+ * Sets the text of the label. This is implemented to set the text on the
+ * Swing label.
+ *
+ * @param text the text to be set
+ */
+ public void setText(String text)
+ {
+ ((JLabel) swingComponent.getJComponent()).setText(text);
+ }
+
+ /**
+ * Sets the horizontal alignment of the label. This is implemented to
+ * set the alignment on the Swing label.
+ *
+ * @param alignment the horizontal alignment
+ *
+ * @see Label#LEFT
+ * @see Label#RIGHT
+ * @see Label#CENTER
+ */
+ public void setAlignment(int alignment)
+ {
+ JLabel swingLabel = (JLabel) swingComponent.getJComponent();
+ switch (alignment)
+ {
+ case Label.RIGHT:
+ swingLabel.setHorizontalAlignment(JLabel.RIGHT);
+ break;
+ case Label.CENTER:
+ swingLabel.setHorizontalAlignment(JLabel.CENTER);
+ break;
+ case Label.LEFT:
+ default:
+ swingLabel.setHorizontalAlignment(JLabel.LEFT);
+ break;
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java
new file mode 100644
index 000000000..cf766fd4f
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java
@@ -0,0 +1,364 @@
+/* SwingListPeer.java -- A Swing based peer for AWT lists
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.List;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.ListPeer;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JComponent;
+import javax.swing.JList;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+
+public class SwingListPeer
+ extends SwingComponentPeer
+ implements ListPeer
+{
+
+ /**
+ * A spezialized Swing scroller used to hold the list.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingList
+ extends JScrollPane
+ implements SwingComponent
+ {
+
+ SwingList(Component comp)
+ {
+ super(comp, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+ JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
+ }
+
+ /**
+ * Returns this label.
+ *
+ * @return <code>this</code>
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * <code>processMouseEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ dispatchEvent(ev);
+ }
+
+ /**
+ * Force lightweight mouse dispatching.
+ */
+ public boolean isLightweight()
+ {
+ return false;
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * <code>processMouseMotionEvent()</code>.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to <code>processKeyEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ processKeyEvent(ev);
+ }
+
+ /**
+ * Handles focus events by forwarding it to <code>processFocusEvent()</code>.
+ *
+ * @param ev the Focus event
+ */
+ public void handleFocusEvent(FocusEvent ev)
+ {
+ processFocusEvent(ev);
+ }
+
+
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingListPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return <code>true</code> if the button is currently showing,
+ * <code>false</code> otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (SwingListPeer.this.awtComponent != null)
+ retVal = SwingListPeer.this.awtComponent.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingListPeer.this.createImage(w, h);
+ }
+
+ public Graphics getGraphics()
+ {
+ return SwingListPeer.this.getGraphics();
+ }
+
+ public Container getParent()
+ {
+ Container par = null;
+ if (SwingListPeer.this.awtComponent != null)
+ par = SwingListPeer.this.awtComponent.getParent();
+ return par;
+ }
+ }
+
+ /**
+ * The actual Swing JList.
+ */
+ private JList jList;
+
+ private DefaultListModel listModel;
+
+ public SwingListPeer(List list)
+ {
+ super();
+ listModel = new DefaultListModel();
+ jList = new JList(listModel);
+ SwingList swingList = new SwingList(jList);
+ init(list, swingList);
+
+ // Pull over the items from the list.
+ String[] items = list.getItems();
+ for (int i = 0 ; i < items.length; i++)
+ addItem(items[i], i);
+ }
+
+ public void add(String item, int index)
+ {
+ if (listModel != null)
+ listModel.add(index, item);
+ }
+
+ public void addItem(String item, int index)
+ {
+ if (listModel != null)
+ listModel.add(index, item);
+ }
+
+ public void clear()
+ {
+ if (listModel != null)
+ listModel.clear();
+ }
+
+ public void delItems(int startIndex, int endIndex)
+ {
+ if (listModel != null)
+ listModel.removeRange(startIndex, endIndex);
+ }
+
+ public void deselect(int index)
+ {
+ if (jList != null)
+ {
+ jList.getSelectionModel().removeSelectionInterval(index, index);
+ }
+ }
+
+ public Dimension getMinimumSize(int s)
+ {
+ Dimension d = null;
+ if (jList != null)
+ {
+ d = jList.getComponent(s).getMinimumSize();
+ }
+ return d;
+ }
+
+ public Dimension getPreferredSize(int s)
+ {
+ Dimension d = null;
+ if (jList != null)
+ {
+ d = jList.getComponent(s).getPreferredSize();
+ }
+ return d;
+ }
+
+ public int[] getSelectedIndexes()
+ {
+ int[] sel = null;
+ if (jList != null)
+ {
+ sel = jList.getSelectedIndices();
+ }
+ return sel;
+ }
+
+ public void makeVisible(int index)
+ {
+ if (jList != null)
+ {
+ Component comp = jList.getComponent(index);
+ jList.scrollRectToVisible(comp.getBounds());
+ }
+ }
+
+ public Dimension minimumSize(int s)
+ {
+ Dimension d = null;
+ if (jList != null)
+ {
+ d = jList.getComponent(s).getMinimumSize();
+ }
+ return d;
+ }
+
+ public Dimension preferredSize(int s)
+ {
+ Dimension d = null;
+ if (jList != null)
+ {
+ d = jList.getComponent(s).getPreferredSize();
+ }
+ return d;
+ }
+
+ public void removeAll()
+ {
+ if (jList != null)
+ {
+ jList.removeAll();
+ }
+ }
+
+ public void select(int index)
+ {
+ if (jList != null)
+ {
+ jList.setSelectedIndex(index);
+ }
+ }
+
+ public void setMultipleMode(boolean multi)
+ {
+ if (jList != null)
+ {
+ jList.setSelectionMode(multi
+ ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
+ : ListSelectionModel.SINGLE_SELECTION);
+ }
+ }
+
+ public void setMultipleSelections(boolean multi)
+ {
+ if (jList != null)
+ {
+ jList.setSelectionMode(multi
+ ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
+ : ListSelectionModel.SINGLE_SELECTION);
+ }
+ }
+
+ public void reshape(int x, int y, int width, int height)
+ {
+ if (swingComponent != null)
+ {
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ swingComponent.getJComponent().validate();
+ }
+ }
+
+ protected void peerPaint(Graphics g, boolean update)
+ {
+ super.peerPaint(g, update);
+ jList.doLayout();
+ jList.list();
+
+ Rectangle r = getBounds();
+ g.setColor(Color.RED);
+ g.drawRect(r.x, r.y, r.width, r.height);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java
new file mode 100644
index 000000000..0033efb02
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java
@@ -0,0 +1,295 @@
+/* SwingMenuBarPeer.java -- A Swing based peer for AWT menu bars
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Container;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.peer.MenuBarPeer;
+
+import javax.swing.JMenuBar;
+
+/**
+ * A Swing based peer for the AWT menu bar. This is a little bit different from
+ * the other peers, since the AWT MenuBar is not derived from the AWT
+ * component.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingMenuBarPeer
+ implements MenuBarPeer
+{
+
+ /**
+ * The AWT menu bar.
+ */
+ MenuBar awtMenuBar;
+
+ /**
+ * The Swing menu bar.
+ */
+ SwingMenuBar menuBar;
+
+ /**
+ * The peer of the frame that contains this menu bar.
+ */
+ SwingFramePeer framePeer;
+
+ /**
+ * A specialized JMenuBar that can be used as 'backend' for AWT MenuBars.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingMenuBar
+ extends JMenuBar
+ {
+ /**
+ * Overridden in order to provide a parent frame for this menu bar. The
+ * menu bar still is not inside the component hierarchy, we are faking
+ * here.
+ */
+ public Container getParent()
+ {
+ Container result = null;
+ if (framePeer != null)
+ result = (Container) framePeer.awtComponent;
+ return result;
+ }
+
+ /**
+ * Unconditionally returns <code>true</code>, since we assume that when the
+ * menubar has a peer, it must be showing.
+ *
+ * @return <code>true</code>
+ */
+ public boolean isShowing()
+ {
+ // FIXME: This might be wrong. Maybe find a better way to do that.
+ return true;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * <code>processMouseEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Determines the menubar's screen location by asking the SwingFramePeer
+ * for it.
+ *
+ * @return the screen location of the menu bar
+ */
+ public Point getLocationOnScreen()
+ {
+ return framePeer.getMenuLocationOnScreen();
+ }
+ }
+
+ /**
+ * Creates a new <code>SwingMenuBarPeer</code> instance.
+ *
+ * @param awtMenuBar the AWT menu bar
+ */
+ public SwingMenuBarPeer(MenuBar awtMenuBar)
+ {
+ this.awtMenuBar = awtMenuBar;
+ menuBar = new SwingMenuBar();
+ menuBar.setDoubleBuffered(false);
+ // Add all the menus that are already in the MenuBar.
+ for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
+ {
+ Menu menu = awtMenuBar.getMenu(i);
+ menu.addNotify();
+ addMenu(awtMenuBar.getMenu(i));
+ }
+ }
+
+ /**
+ * Sets the <code>SwingFramePeer</code> of the frame that holds this menu.
+ *
+ * @param peer the <code>SwingFramePeer</code> to set
+ */
+ public void setFramePeer(SwingFramePeer peer)
+ {
+ framePeer = peer;
+ }
+
+ /**
+ * Adds a menu to the menu bar.
+ *
+ * @param m the menu to add
+ */
+ public void addMenu(Menu m)
+ {
+ SwingMenuPeer menuPeer = (SwingMenuPeer) m.getPeer();
+ menuBar.add(menuPeer.menu);
+ }
+
+ /**
+ * Adds a help menu to the menu bar.
+ *
+ * @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);
+ }
+
+ /**
+ * Removes the menu with the specified index.
+ *
+ * @param index the index of the menu to remove
+ */
+ public void delMenu(int index)
+ {
+ menuBar.remove(index);
+ }
+
+ /**
+ * Disposes this peer. This releases any reference to the AWT and Swing
+ * components.
+ */
+ public void dispose()
+ {
+ menuBar = null;
+ awtMenuBar = null;
+ }
+
+ /**
+ * Sets a font for the menu bar.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ menuBar.setFont(font);
+ }
+
+ /**
+ * Sets the width of the menu bar. This is called from the top level
+ * component peers to adjust the width of the menubar when their sizes
+ * change.
+ *
+ * @param w the width to set
+ */
+ public void setWidth(int w)
+ {
+ menuBar.setSize(w, menuBar.getPreferredSize().height);
+ menuBar.doLayout();
+ }
+
+ /**
+ * Paints the menu bar.
+ *
+ * @param g the graphics context to use for painting
+ */
+ public void peerPaint(Graphics g)
+ {
+ menuBar.paint(g);
+ }
+
+ /**
+ * Determines the height of the menubar.
+ *
+ * @return the height of the menu bar
+ */
+ public int getHeight()
+ {
+ return menuBar.getPreferredSize().height;
+ }
+
+ /**
+ * Handles mouse events.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ Point point = ev.getPoint();
+ for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
+ {
+ Menu menu = awtMenuBar.getMenu(i);
+ SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer();
+ int x1 = peer.getX();
+ int x2 = x1 + peer.getWidth();
+ if (point.x >= x1 && point.x <= x2)
+ {
+ ev.translatePoint(peer.getX(), peer.getY());
+ peer.handleMouseEvent(ev);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Handles mouse motion events.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ Point point = ev.getPoint();
+ for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
+ {
+ Menu menu = awtMenuBar.getMenu(i);
+ SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer();
+ int x1 = peer.getX();
+ int x2 = x1 + peer.getWidth();
+ if (point.x >= x1 && point.x <= x2)
+ {
+ ev.translatePoint(peer.getX(), peer.getY());
+ peer.handleMouseMotionEvent(ev);
+ break;
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java
new file mode 100644
index 000000000..721b3349f
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java
@@ -0,0 +1,157 @@
+/* SwingMenuItemPeer.java -- A Swing based peer for AWT menu items
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Font;
+import java.awt.MenuItem;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.peer.MenuItemPeer;
+
+import javax.swing.JMenuItem;
+
+/**
+ * A Swing based peer for the AWT MenuItem.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingMenuItemPeer
+ implements MenuItemPeer
+{
+ /**
+ * The AWT menu item.
+ */
+ MenuItem awtMenuItem;
+
+ /**
+ * The Swing menu item.
+ */
+ JMenuItem menuItem;
+
+ /**
+ * Receives ActionEvents from the Swing menu item and forwards them
+ * to the ActionListeners of the AWT MenuItem.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingMenuItemListener implements ActionListener
+ {
+
+ /**
+ * Receives notification when the action has been performed.
+ *
+ * @param event the action event
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ event.setSource(awtMenuItem);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
+ }
+
+ }
+
+ /**
+ * Creates a new instance of <code>SwingMenuItemPeer</code>.
+ *
+ * @param awtMenuItem the AWT menu item
+ */
+ public SwingMenuItemPeer(MenuItem awtMenuItem)
+ {
+ this.awtMenuItem = awtMenuItem;
+ menuItem = new JMenuItem(awtMenuItem.getLabel());
+ menuItem.addActionListener(new SwingMenuItemListener());
+ }
+
+ /**
+ * Disables the menu item.
+ */
+ public void disable()
+ {
+ menuItem.setEnabled(false);
+ }
+
+ /**
+ * Enables the menu item.
+ */
+ public void enable()
+ {
+ menuItem.setEnabled(true);
+ }
+
+ /**
+ * Sets the enabled state to <code>enabled</code>.
+ *
+ * @param enabled if the menu item should be enabled or not
+ */
+ public void setEnabled(boolean enabled)
+ {
+ menuItem.setEnabled(enabled);
+ }
+
+ /**
+ * Sets the label for the menu item.
+ *
+ * @param text the label to set
+ */
+ public void setLabel(String text)
+ {
+ menuItem.setText(text);
+ }
+
+ /**
+ * Disposes the menu item. This releases any reference to the Swing and AWT
+ * menu item.
+ */
+ public void dispose()
+ {
+ menuItem = null;
+ awtMenuItem = null;
+ }
+
+ /**
+ * Sets the font for this menu item.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ menuItem.setFont(font);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java
new file mode 100644
index 000000000..afe20616d
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java
@@ -0,0 +1,284 @@
+/* SwingMenuPeer.java -- A Swing based peer for AWT menus
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Font;
+import java.awt.Menu;
+import java.awt.MenuItem;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.peer.MenuPeer;
+
+import javax.swing.JMenu;
+
+/**
+ * A Swing based peer for the AWT menu.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingMenuPeer
+ implements MenuPeer
+{
+
+ /**
+ * The AWT menu.
+ */
+ Menu awtMenu;
+
+ /**
+ * The Swing menu.
+ */
+ SwingMenu menu;
+
+ /**
+ * A specialized JMenu that can be used as 'backend' for an AWT menu.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingMenu
+ extends JMenu
+ {
+
+ /**
+ * Unconditionally returns <code>true</code>, since we assume that when the
+ * menu has a peer, it must be showing.
+ *
+ * @return <code>true</code>
+ */
+ public boolean isShowing()
+ {
+ // FIXME: This might be wrong. Maybe find a better way to do that.
+ return true;
+ }
+
+ /**
+ * Overridden so that we can provide a location even without a real peer
+ * attached.
+ *
+ * @return the screen location of this menu
+ */
+ public Point getLocationOnScreen()
+ {
+ Point parentLoc = getParent().getLocationOnScreen();
+ parentLoc.x += getX();
+ parentLoc.y += getY();
+ return parentLoc;
+ }
+
+ /**
+ * Handles mouse events by forwarding them to
+ * <code>processMouseEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse events by forwarding them to
+ * <code>processMouseMotionEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+ }
+
+ /**
+ * Creates a new <code>SwingMenuPeer</code> instance.
+ *
+ * @param awtMenu the AWT menu
+ */
+ public SwingMenuPeer(Menu awtMenu)
+ {
+ this.awtMenu = awtMenu;
+ menu = new SwingMenu();
+ menu.setDoubleBuffered(false);
+ menu.setText(awtMenu.getLabel());
+ for (int i = 0; i < awtMenu.getItemCount(); i++)
+ {
+ MenuItem item = awtMenu.getItem(i);
+ item.addNotify();
+ SwingMenuItemPeer peer = (SwingMenuItemPeer) item.getPeer();
+ menu.add(peer.menuItem);
+ }
+ }
+
+ /**
+ * Adds a menu item to this menu.
+ *
+ * @param item the menu item to add
+ */
+ public void addItem(MenuItem item)
+ {
+ SwingMenuItemPeer menuItemPeer = (SwingMenuItemPeer) item.getPeer();
+ menu.add(menuItemPeer.menuItem);
+ }
+
+ /**
+ * Adds a separator to the menu.
+ */
+ public void addSeparator()
+ {
+ menu.addSeparator();
+ }
+
+ /**
+ * Removes a menu item from the menu.
+ *
+ * @param index the index of the menu item to remove
+ */
+ public void delItem(int index)
+ {
+ menu.remove(index);
+ }
+
+ /**
+ * Disables the menu.
+ */
+ public void disable()
+ {
+ menu.setEnabled(false);
+ }
+
+ /**
+ * Enables the menu.
+ */
+ public void enable()
+ {
+ menu.setEnabled(true);
+ }
+
+ /**
+ * Sets the enabled state of the menu to <code>enabled</code>.
+ *
+ * @param enabled if the menu should be enabled or not
+ */
+ public void setEnabled(boolean enabled)
+ {
+ menu.setEnabled(enabled);
+ }
+
+ /**
+ * Sets the label of the menu.
+ *
+ * @param text the label to set
+ */
+ public void setLabel(String text)
+ {
+ menu.setText(text);
+ }
+
+ /**
+ * Releases any reference to the AWT and Swing menu instances.
+ */
+ public void dispose()
+ {
+ menu = null;
+ awtMenu = null;
+ }
+
+ /**
+ * Sets the font for the menu.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ menu.setFont(font);
+ }
+
+ /**
+ * Handles mouse events by forwarding them to the Swing menu.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ menu.handleMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding them to the Swing menu.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ menu.handleMouseMotionEvent(ev);
+ }
+
+ /**
+ * Returns the X coordinate of the upper left corner of the menu. This is
+ * used internally by the SwingMenuBarPeer.
+ *
+ * @return the X coordinate of the upper left corner of the menu
+ */
+ int getX()
+ {
+ return menu.getX();
+ }
+
+ /**
+ * Returns the width of the menu. This is used internally by the
+ * SwingMenuBarPeer.
+ *
+ * @return the X coordinate of the upper left corner of the menu
+ */
+ int getWidth()
+ {
+ return menu.getWidth();
+ }
+
+ /**
+ * Returns the Y coordinate of the upper left corner of the menu. This is
+ * used internally by the SwingMenuBarPeer.
+ *
+ * @return the X coordinate of the upper left corner of the menu
+ */
+ public int getY()
+ {
+ return menu.getY();
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java
new file mode 100644
index 000000000..37c6dbc7a
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java
@@ -0,0 +1,67 @@
+/* SwingPanelPeer.java -- A PanelPeer based on Swing
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Panel;
+import java.awt.peer.PanelPeer;
+
+/**
+ * A panel peer based on Swing.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+// TODO: Maybe base implementation on JPanel. However, this doesn't seem
+// necessary, but might be good for more consistent Look.
+public class SwingPanelPeer
+ extends SwingContainerPeer
+ implements PanelPeer
+{
+
+ /**
+ * Creates a new instance of <code>SwingPanelPeer</code> for the specified
+ * AWT panel.
+ *
+ * @param panel the AWT panel
+ */
+ public SwingPanelPeer(Panel panel)
+ {
+ super(panel);
+ init(panel, null);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java
new file mode 100644
index 000000000..d56e950ec
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java
@@ -0,0 +1,487 @@
+/* SwingTextAreaPeer.java -- A Swing based peer for AWT textareas
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.TextArea;
+import java.awt.event.ComponentEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+import java.awt.im.InputMethodRequests;
+import java.awt.peer.TextAreaPeer;
+
+import javax.swing.JComponent;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JViewport;
+import javax.swing.text.BadLocationException;
+
+public class SwingTextAreaPeer
+ extends SwingComponentPeer
+ implements TextAreaPeer
+{
+
+ /**
+ * A spezialized Swing scroller used to hold the textarea.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingScrollPane
+ extends JScrollPane
+ implements SwingComponent
+ {
+
+ SwingTextArea textArea;
+
+ SwingScrollPane(SwingTextArea textArea)
+ {
+ super(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+ JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
+
+ this.textArea = textArea;
+ }
+
+ /**
+ * Returns this label.
+ *
+ * @return <code>this</code>
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * <code>processMouseEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ JViewport viewPort = getViewport();
+ if(viewPort.contains(ev.getPoint()))
+ {
+ ev.setSource(textArea);
+ textArea.dispatchEvent(ev);
+ }
+ else
+ {
+ ev.setSource(this);
+ this.dispatchEvent(ev);
+ }
+ }
+
+ /**
+ * Force lightweight mouse dispatching.
+ */
+ public boolean isLightweight()
+ {
+ return false;
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * <code>processMouseMotionEvent()</code>.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ textArea.processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to <code>processKeyEvent()</code>.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ textArea.processKeyEvent(ev);
+ }
+
+ /**
+ * Handles focus events by forwarding it to
+ * <code>processFocusEvent()</code>.
+ *
+ * @param ev the Focus event
+ */
+ public void handleFocusEvent(FocusEvent ev)
+ {
+ textArea.processFocusEvent(ev);
+ }
+
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingTextAreaPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return <code>true</code> if the button is currently showing,
+ * <code>false</code> otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (SwingTextAreaPeer.this.awtComponent != null)
+ retVal = SwingTextAreaPeer.this.awtComponent.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingTextAreaPeer.this.createImage(w, h);
+ }
+
+ public Graphics getGraphics()
+ {
+ return SwingTextAreaPeer.this.getGraphics();
+ }
+
+ public Container getParent()
+ {
+ Container par = null;
+ if (SwingTextAreaPeer.this.awtComponent != null)
+ par = SwingTextAreaPeer.this.awtComponent.getParent();
+ return par;
+ }
+
+ public void requestFocus() {
+ SwingTextAreaPeer.this.requestFocus(awtComponent, false, true, 0);
+ }
+
+ public boolean requestFocus(boolean temporary) {
+ return SwingTextAreaPeer.this.requestFocus(awtComponent, temporary,
+ true, 0);
+ }
+
+ }
+
+ private class SwingTextArea extends JTextArea
+ {
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processComponentKeyEvent(KeyEvent e)
+ {
+ super.processComponentKeyEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processMouseMotionEvent(MouseEvent ev)
+ {
+ super.processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processComponentEvent(ComponentEvent e)
+ {
+ super.processComponentEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processFocusEvent(FocusEvent e)
+ {
+ super.processFocusEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processHierarchyBoundsEvent(HierarchyEvent e)
+ {
+ super.processHierarchyBoundsEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processHierarchyEvent(HierarchyEvent e)
+ {
+ super.processHierarchyEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processInputMethodEvent(InputMethodEvent e)
+ {
+ super.processInputMethodEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processMouseEvent(MouseEvent e)
+ {
+ super.processMouseEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processMouseWheelEvent(MouseWheelEvent e)
+ {
+ super.processMouseWheelEvent(e);
+ }
+
+ /**
+ * Make this method accessible in this Package.
+ */
+ protected final void processKeyEvent(KeyEvent e)
+ {
+ super.processKeyEvent(e);
+ }
+
+ public void requestFocus() {
+ SwingTextAreaPeer.this.requestFocus(awtComponent, false, true, 0);
+ }
+
+ public boolean requestFocus(boolean temporary) {
+ return SwingTextAreaPeer.this.requestFocus(awtComponent, temporary,
+ true, 0);
+ }
+ }
+
+ /**
+ * The actual JTextArea.
+ */
+ private SwingTextArea jTextArea;
+
+ public SwingTextAreaPeer(TextArea textArea)
+ {
+ super();
+ jTextArea = new SwingTextArea();
+ SwingScrollPane swingArea = new SwingScrollPane(jTextArea);
+ init(textArea, swingArea);
+
+ JViewport viewport = new JViewport()
+ {
+ public Image createImage(int width, int height)
+ {
+ return awtComponent.createImage(width, height);
+ }
+ };
+
+ viewport.setView(jTextArea);
+ swingArea.setViewport(viewport);
+ // Pull over the text from the text area.
+ setText(textArea.getText());
+
+ // Pull over the number of rows and columns
+ // if non were set use default values
+ int columns = textArea.getColumns();
+ int rows = textArea.getRows();
+
+ if(columns == 0 && rows == 0)
+ {
+ columns = 25;
+ textArea.setColumns(columns);
+ rows = 5;
+ textArea.setRows(rows);
+ }
+
+ jTextArea.setColumns(columns);
+ jTextArea.setRows(rows);
+ }
+
+ public Dimension getMinimumSize(int rows, int cols)
+ {
+ return jTextArea.getMinimumSize();
+ }
+
+ public Dimension getPreferredSize(int rows, int cols)
+ {
+ return jTextArea.getPreferredSize();
+ }
+
+ public void insert(String text, int pos)
+ {
+ jTextArea.insert(text, pos);
+ }
+
+ public void insertText(String text, int pos)
+ {
+ jTextArea.insert(text, pos);
+ }
+
+ public Dimension minimumSize()
+ {
+ return jTextArea.getMinimumSize();
+ }
+
+ public Dimension preferredSize()
+ {
+ return jTextArea.getPreferredSize();
+ }
+
+ public Dimension minimumSize(int rows, int cols)
+ {
+ return jTextArea.getMinimumSize();
+ }
+
+ public Dimension preferredSize(int rows, int cols)
+ {
+ return jTextArea.getPreferredSize();
+ }
+
+ public void replaceRange(String text, int start, int end)
+ {
+ jTextArea.replaceRange(text, start, end);
+ }
+
+ public void replaceText(String text, int start, int end)
+ {
+ jTextArea.replaceRange(text, start, end);
+ }
+
+ public long filterEvents(long filter)
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getCaretPosition()
+ {
+ return jTextArea.getCaretPosition();
+ }
+
+ public Rectangle getCharacterBounds(int pos)
+ {
+ Rectangle r;
+ try
+ {
+ return jTextArea.modelToView(pos);
+ }
+ catch (BadLocationException ex)
+ {
+ r = null;
+ }
+ return r;
+ }
+
+ public int getIndexAtPoint(int x, int y)
+ {
+ return jTextArea.viewToModel(new Point(x, y));
+ }
+
+ public InputMethodRequests getInputMethodRequests()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getSelectionEnd()
+ {
+ return jTextArea.getSelectionEnd();
+ }
+
+ public int getSelectionStart()
+ {
+ return jTextArea.getSelectionStart();
+ }
+
+ public String getText()
+ {
+ return jTextArea.getText();
+ }
+
+ public void select(int start, int end)
+ {
+ jTextArea.select(start, end);
+ }
+
+ public void setCaretPosition(int pos)
+ {
+ jTextArea.setCaretPosition(pos);
+ }
+
+ public void setEditable(boolean editable)
+ {
+ jTextArea.setEditable(editable);
+ }
+
+ public void setText(String text)
+ {
+ jTextArea.setText(text);
+ }
+
+ public void reshape(int x, int y, int width, int height)
+ {
+ if (swingComponent != null)
+ {
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ swingComponent.getJComponent().validate();
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java
new file mode 100644
index 000000000..9750c9bf7
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java
@@ -0,0 +1,411 @@
+/* SwingTextFieldPeer.java -- A Swing based peer for AWT textfields
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+package gnu.java.awt.peer.swing;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.TextField;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.im.InputMethodRequests;
+import java.awt.peer.TextFieldPeer;
+
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+
+/**
+ * A TextFieldPeer based on Swing JTextField.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingTextFieldPeer
+ extends SwingComponentPeer
+ implements TextFieldPeer
+{
+
+ /**
+ * A specialized Swing textfield for use in the peer.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingTextField
+ extends JTextField
+ implements SwingComponent
+ {
+
+ TextField textField;
+
+ SwingTextField(TextField textField)
+ {
+ this.textField = textField;
+ }
+
+ /**
+ * Overridden to provide normal behaviour even without a real peer
+ * attached.
+ *
+ * @return the location of the textfield on screen
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingTextFieldPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value
+ * for the swing button, even if it has no peer on its own.
+ *
+ * @return <code>true</code> if the button is currently showing,
+ * <code>false</code> otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (textField != null)
+ retVal = textField.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingTextFieldPeer.this.createImage(w, h);
+ }
+
+ /**
+ * Returns this textfield.
+ *
+ * @return <code>this</code>
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to the swing textfield.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to the swing textfield.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to the swing textfield.
+ *
+ * @param ev the key event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ ev.setSource(this);
+ processKeyEvent(ev);
+ }
+
+ /**
+ * Handles focus events by forwarding it to
+ * <code>processFocusEvent()</code>.
+ *
+ * @param ev the Focus event
+ */
+ public void handleFocusEvent(FocusEvent ev)
+ {
+ processFocusEvent(ev);
+ }
+
+
+ public Container getParent()
+ {
+ Container par = null;
+ if (textField != null)
+ par = textField.getParent();
+ return par;
+ }
+
+ public Graphics getGraphics()
+ {
+ return SwingTextFieldPeer.this.getGraphics();
+ }
+
+ public void requestFocus() {
+ SwingTextFieldPeer.this.requestFocus(awtComponent, false, true, 0);
+ }
+
+ public boolean requestFocus(boolean temporary) {
+ return SwingTextFieldPeer.this.requestFocus(awtComponent, temporary,
+ true, 0);
+ }
+
+ }
+
+ /**
+ * Creates a new <code>SwingTextFieldPeer</code> instance for the specified
+ * AWT textfield.
+ *
+ * @param textField the AWT textfield
+ */
+ public SwingTextFieldPeer(TextField textField)
+ {
+ SwingTextField swingTextField = new SwingTextField(textField);
+ swingTextField.setText(textField.getText());
+ init(textField, swingTextField);
+ }
+
+ /**
+ * Returns the minimum size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the minimum size of the textfield
+ */
+ public Dimension minimumSize(int len)
+ {
+ return swingComponent.getJComponent().getMinimumSize();
+ }
+
+ /**
+ * Returns the preferred size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the preferred size of the textfield
+ */
+ public Dimension preferredSize(int len)
+ {
+ return swingComponent.getJComponent().getPreferredSize();
+ }
+
+ /**
+ * Returns the minimum size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the minimum size of the textfield
+ */
+ public Dimension getMinimumSize(int len)
+ {
+ return swingComponent.getJComponent().getMinimumSize();
+ }
+
+ /**
+ * Returns the preferred size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the preferred size of the textfield
+ */
+ public Dimension getPreferredSize(int len)
+ {
+ return swingComponent.getJComponent().getPreferredSize();
+ }
+
+ /**
+ * Sets the echo character.
+ *
+ * @param echoChar the echo character to be set
+ */
+ public void setEchoChar(char echoChar)
+ {
+ // TODO: Must be implemented.
+ }
+
+ /**
+ * Sets the echo character.
+ *
+ * @param echoChar the echo character to be set
+ */
+ public void setEchoCharacter(char echoChar)
+ {
+ // TODO: Must be implemented.
+ }
+
+ /**
+ * Returns the end index of the current selection.
+ *
+ * @return the end index of the current selection
+ */
+ public int getSelectionEnd()
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Returns the start index of the current selection.
+ *
+ * @return the start index of the current selection
+ */
+ public int getSelectionStart()
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Returns the current content of the textfield.
+ *
+ * @return the current content of the textfield
+ */
+ public String getText()
+ {
+ return ((JTextField) swingComponent.getJComponent()).getText();
+ }
+
+ /**
+ * Sets the content of the textfield.
+ *
+ * @param text the text to set
+ */
+ public void setText(String text)
+ {
+ ((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 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
+ */
+ public void setEditable(boolean editable)
+ {
+ ((JTextField) swingComponent.getJComponent()).setEditable(editable);
+ }
+
+ /**
+ * Returns the current caret position.
+ *
+ * @return the current caret position
+ */
+ public int getCaretPosition()
+ {
+ return ((JTextField) swingComponent.getJComponent()).getCaret().getDot();
+ }
+
+ /**
+ * Sets the current caret position.
+ *
+ * @param pos the caret position to set
+ */
+ public void setCaretPosition(int pos)
+ {
+ ((JTextField) swingComponent.getJComponent()).getCaret().setDot(pos);
+ }
+
+ /**
+ * Returns the index of the character at the specified location.
+ *
+ * @param x the X coordinate of the point to query
+ * @param y the Y coordinate of the point to query
+ *
+ * @return the index of the character at the specified location
+ */
+ public int getIndexAtPoint(int x, int y)
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Returns the bounds of the character at the specified index.
+ *
+ * @param pos the index of the character
+ *
+ * @return the bounds of the character at the specified index
+ */
+ public Rectangle getCharacterBounds(int pos)
+ {
+ // TODO: Must be implemented.
+ return null;
+ }
+
+ /**
+ * Not used.
+ */
+ public long filterEvents(long filter)
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Not used.
+ */
+ public InputMethodRequests getInputMethodRequests()
+ {
+ // TODO: Must be implemented.
+ return null;
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java
new file mode 100644
index 000000000..63414050b
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java
@@ -0,0 +1,181 @@
+/* SwingToolkit.java -- A base toolkit for Swing peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Button;
+import java.awt.Canvas;
+import java.awt.Dialog;
+import java.awt.Label;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.Panel;
+import java.awt.TextField;
+import java.awt.peer.ButtonPeer;
+import java.awt.peer.CanvasPeer;
+import java.awt.peer.LabelPeer;
+import java.awt.peer.MenuBarPeer;
+import java.awt.peer.MenuItemPeer;
+import java.awt.peer.MenuPeer;
+import java.awt.peer.PanelPeer;
+import java.awt.peer.TextFieldPeer;
+
+import gnu.java.awt.ClasspathToolkit;
+
+/**
+ * A base implementation for {@link java.awt.Toolkit} that provides the
+ * Swing based widgets. Concrete implementations still must provide the
+ * remaining abstract methods.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public abstract class SwingToolkit extends ClasspathToolkit
+{
+
+ /**
+ * Creates a SwingButtonPeer.
+ *
+ * @param button the AWT button
+ *
+ * @return the Swing button peer
+ */
+ protected ButtonPeer createButton(Button button)
+ {
+ return new SwingButtonPeer(button);
+ }
+
+ /**
+ * Creates a SwingCanvasPeer.
+ *
+ * @param canvas the AWT canvas
+ *
+ * @return the Swing canvas peer
+ */
+ protected CanvasPeer createCanvas(Canvas canvas)
+ {
+ return new SwingCanvasPeer(canvas);
+ }
+
+ /**
+ * Creates a SwingLabelPeer.
+ *
+ * @param label the AWT label
+ *
+ * @return the Swing label peer
+ */
+ protected LabelPeer createLabel(Label label)
+ {
+ return new SwingLabelPeer(label);
+ }
+
+ /**
+ * Creates a SwingMenuPeer.
+ *
+ * @param menu the AWT menu
+ *
+ * @return the Swing menu peer
+ */
+ protected MenuPeer createMenu(Menu menu)
+ {
+ return new SwingMenuPeer(menu);
+ }
+
+ /**
+ * Creates a SwingMenuBarPeer.
+ *
+ * @param menuBar the AWT menubar
+ *
+ * @return the Swing menu bar peer
+ */
+ protected MenuBarPeer createMenuBar(MenuBar menuBar)
+ {
+ return new SwingMenuBarPeer(menuBar);
+ }
+
+ /**
+ * Creates a SwingMenuItemPeer.
+ *
+ * @param menuItem the AWT menu item
+ *
+ * @return the Swing menu item peer
+ */
+ protected MenuItemPeer createMenuItem(MenuItem menuItem)
+ {
+ return new SwingMenuItemPeer(menuItem);
+ }
+
+ /**
+ * Creates a SwingPanelPeer.
+ *
+ * @param panel the AWT panel
+ *
+ * @return the Swing panel peer
+ */
+ protected PanelPeer createPanel(Panel panel)
+ {
+ return new SwingPanelPeer(panel);
+ }
+
+ /**
+ * Creates a SwingTextFieldPeer.
+ *
+ * @param textField the AWT text field
+ *
+ * @return the Swing text field peer
+ */
+ protected TextFieldPeer createTextField(TextField textField)
+ {
+ return new SwingTextFieldPeer(textField);
+ }
+
+ @Override
+ public boolean isModalExclusionTypeSupported
+ (Dialog.ModalExclusionType modalExclusionType)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isModalityTypeSupported(Dialog.ModalityType modalityType)
+ {
+ return false;
+ }
+
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java
new file mode 100644
index 000000000..bdc494e95
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java
@@ -0,0 +1,99 @@
+/* SwingWindowPeer.java -- An abstract base for Swing based window peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Window;
+import java.awt.peer.ComponentPeer;
+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>{@link ComponentPeer#getLocationOnScreen()}</li>
+ * <li>{@link ComponentPeer#getGraphics()}</li>
+ * <li>{@link ComponentPeer#createImage(int, int)}</li>
+ * </ul>
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public abstract class SwingWindowPeer
+ extends SwingContainerPeer
+ implements WindowPeer
+{
+
+ /**
+ * Creates a new instance of WindowPeer.
+ *
+ * @param window the AWT window
+ */
+ public SwingWindowPeer(Window window)
+ {
+ super(window);
+ init(window, null);
+ }
+
+ public void updateIconImages()
+ {
+ // TODO: Implement properly.
+ }
+
+ public void updateMinimumSize()
+ {
+ // TODO: Implement properly.
+ }
+
+ public void setModalBlocked(java.awt.Dialog d, boolean b)
+ {
+ // TODO: Implement properly.
+ }
+
+ public void updateFocusableWindowState()
+ {
+ // TODO: Implement properly.
+ }
+
+ public void setAlwaysOnTop(boolean b)
+ {
+ // TODO: Implement properly.
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/package.html b/libjava/classpath/gnu/java/awt/peer/swing/package.html
new file mode 100644
index 000000000..506eda883
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/package.html
@@ -0,0 +1,71 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in gnu.java.awt.peer.swing package.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+ <head>
+ <title>Swing based AWT peers</title>
+ </head>
+ <body>
+ <h1>Swing based AWT peers.</h1>
+ <p>This package defines an abstract set of AWT peers that is based on Swing
+ widgets. This can be used as an implementation base for peer implementors
+ who don't have access to native widgets or who want to build a quick
+ prototype of a peer set without implementing all of the AWT widgets.
+ </p>
+ <p>An actual implementation would have to provide the following:
+ <ul>
+ <li>A concrete implementation of {@link java.awt.Toolkit}, possibly based
+ on {@link SwingToolkit}. This implementation must provide all the missing
+ methods of the <code>SwingToolkit</code>.</li>
+ <li>Concrete implementations of {@link java.awt.peer.DialogPeer},
+ {@link java.awt.peer.FramePeer} and {@link java.awt.peer.WindowPeer},
+ ideally based on their <code>SwingXXXPeer</code> counterparts.
+ Some methods must be specially
+ overridden in those peers to provide useful functionality, like
+ <code>getLocationOnScreen()</code>. See the API documentation for more
+ details</li>
+ <li>An implementation of {@link java.awt.Image}. These must be provided by
+ the toplevel component peers.</li>
+ <li>An implementation of {@link java.awt.Graphics}. This must also be
+ provided by the toplevel peers.</li>
+ <li>An implementation of {@link java.awt.Font}. This must be
+ provided by the toolkit.</li>
+ </ul>
+ </p>
+ </body>
+</html>