diff options
author | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-08-04 10:53:49 +0000 |
---|---|---|
committer | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-08-04 10:53:49 +0000 |
commit | bfd03af53013b43663c88995c6d5943815e8d75b (patch) | |
tree | 871b70a606d87369d5aa9d6f621baedc13b49eba /libjava/classpath/gnu/java/awt/peer/swing | |
parent | befb0bace8afefe156fe5718f9d1f202d28560c7 (diff) | |
download | ppe42-gcc-bfd03af53013b43663c88995c6d5943815e8d75b.tar.gz ppe42-gcc-bfd03af53013b43663c88995c6d5943815e8d75b.zip |
libjava/
2007-08-04 Matthias Klose <doko@ubuntu.com>
Import GNU Classpath (libgcj-import-20070727).
* Regenerate class and header files.
* Regenerate auto* files.
* include/jvm.h:
* jni-libjvm.cc (Jv_JNI_InvokeFunctions): Rename type.
* jni.cc (_Jv_JNIFunctions, _Jv_JNI_InvokeFunctions): Likewise.
* jni.cc (_Jv_JNI_CallAnyMethodA, _Jv_JNI_CallAnyVoidMethodA,
_Jv_JNI_CallMethodA, _Jv_JNI_CallVoidMethodA,
_Jv_JNI_CallStaticMethodA, _Jv_JNI_CallStaticVoidMethodA,
_Jv_JNI_NewObjectA, _Jv_JNI_SetPrimitiveArrayRegion): Constify
jvalue parameter.
* java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Likewise.
* java/lang/VMFloat.java (toString, parseFloat): New.
* gnu/awt/xlib/XToolkit.java (setAlwaysOnTop, isModalityTypeSupported,
isModalExclusionTypeSupported): New (stub only).
* gnu/awt/xlib/XCanvasPeer.java (requestFocus): Likewise.
* gnu/awt/xlib/XFramePeer.java (updateMinimumSize, updateIconImages,
updateFocusableWindowState, setModalBlocked, getBoundsPrivate,
setAlwaysOnTop): Likewise.
* gnu/awt/xlib/XFontPeer.java (canDisplay): Update signature.
* scripts/makemake.tcl: Ignore gnu/javax/sound/sampled/gstreamer,
ignore javax.sound.sampled.spi.MixerProvider, ignore .in files.
* HACKING: Mention --enable-gstreamer-peer, removal of generated files.
libjava/classpath/
2007-08-04 Matthias Klose <doko@ubuntu.com>
* java/util/EnumMap.java (clone): Add cast.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127204 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/swing')
12 files changed, 679 insertions, 92 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java index 531d6f2db3b..192d612ee79 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java @@ -1,5 +1,5 @@ /* SwingButtonPeer.java -- A Swing based peer for AWT buttons - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,6 +44,7 @@ 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; @@ -70,12 +71,12 @@ public class SwingButtonPeer extends JButton implements SwingComponent { - Button button; + Button button; - SwingButton(Button button) - { - this.button = button; - } + SwingButton(Button button) + { + this.button = button; + } /** * Overridden so that this method returns the correct value even without a @@ -184,6 +185,26 @@ public class SwingButtonPeer 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); + } } /** 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 00000000000..a8e3cb01bab --- /dev/null +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingCheckboxPeer.java @@ -0,0 +1,261 @@ +/* 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.Button; +import java.awt.Checkbox; +import java.awt.CheckboxGroup; +import java.awt.Container; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Label; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +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.JLabel; +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 index 04ca7294f78..d22f55d6f19 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java @@ -37,6 +37,7 @@ 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; @@ -86,4 +87,13 @@ public interface SwingComponent * @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 index bfa14dddee3..71a7bac4d00 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java @@ -1,5 +1,5 @@ /* SwingComponentPeer.java -- An abstract base class for Swing based peers - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,6 +45,7 @@ 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; @@ -54,6 +55,7 @@ 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; @@ -349,12 +351,7 @@ public class SwingComponentPeer */ public Dimension getMinimumSize() { - Dimension retVal; - if (swingComponent != null) - retVal = swingComponent.getJComponent().getMinimumSize(); - else - retVal = new Dimension(0, 0); - return retVal; + return minimumSize(); } /** @@ -367,12 +364,7 @@ public class SwingComponentPeer */ public Dimension getPreferredSize() { - Dimension retVal; - if (swingComponent != null) - retVal = swingComponent.getJComponent().getPreferredSize(); - else - retVal = new Dimension(0, 0); - return retVal; + return preferredSize(); } /** @@ -395,30 +387,28 @@ public class SwingComponentPeer public void handleEvent(AWTEvent e) { switch (e.getID()) - { + { case PaintEvent.UPDATE: case PaintEvent.PAINT: - // Need to synchronize to avoid threading problems on the - // paint event list. - // We must synchronize on the tree lock first to avoid deadlock, - // because Container.paint() will grab it anyway. - synchronized (this) + if (awtComponent.isShowing()) { - assert paintArea != null; - if (awtComponent.isShowing()) + Rectangle clip ; + synchronized (this) { - Graphics g = awtComponent.getGraphics(); - try - { - Rectangle clip = paintArea; - g.clipRect(clip.x, clip.y, clip.width, clip.height); - peerPaint(g, e.getID() == PaintEvent.UPDATE); - } - finally - { - g.dispose(); - paintArea = null; - } + 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; @@ -438,10 +428,14 @@ public class SwingComponentPeer 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; - } + } } /** @@ -574,13 +568,16 @@ public class SwingComponentPeer * 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 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 @@ -602,8 +599,10 @@ public class SwingComponentPeer */ public void requestFocus() { - if (swingComponent != null) - swingComponent.getJComponent().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)); } /** @@ -612,18 +611,22 @@ public class SwingComponentPeer * * This calls requestFocus() on the Swing component. * - * @param source TODO - * @param bool1 TODO - * @param bool2 TODO - * @param x TODO + * @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 TODO + * @return true when the focus change is guaranteed to be granted, false + * otherwise */ - public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x) + public boolean requestFocus(Component source, boolean tmp, + boolean allowWindowFocus, long tm) { - if (swingComponent != null) - swingComponent.getJComponent().requestFocus(); - return swingComponent != null; + Toolkit tk = Toolkit.getDefaultToolkit(); + EventQueue q = tk.getSystemEventQueue(); + q.postEvent(new FocusEvent(source, FocusEvent.FOCUS_GAINED, tmp)); + return true; } /** @@ -1101,6 +1104,19 @@ public class SwingComponentPeer } /** + * 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 @@ -1109,4 +1125,12 @@ public class SwingComponentPeer { 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 index c78b644a765..2d5d97ff14b 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java @@ -1,5 +1,5 @@ /* SwingContainerPeer.java -- A Swing based peer for AWT containers - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -92,7 +92,7 @@ public class SwingContainerPeer * @see #peerPaintChildren(Graphics) * @see #removeHeavyweightDescendent(Component) */ - synchronized void addHeavyweightDescendent(Component comp) + protected synchronized void addHeavyweightDescendent(Component comp) { heavyweightDescendents.add(comp); focusOwner = null; @@ -106,13 +106,25 @@ public class SwingContainerPeer * @see #peerPaintChildren(Graphics) * @see #addHeavyweightDescendent(Component) */ - synchronized void removeHeavyweightDescendent(Component comp) + 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. @@ -339,7 +351,7 @@ public class SwingContainerPeer { Component owner = getFocusOwner(); if(owner != null) - owner.dispatchEvent(e); + owner.getPeer().handleEvent(e); else super.handleKeyEvent(e); } diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java index 349c5a0abe2..55c394ecb6e 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java @@ -1,5 +1,5 @@ /* SwingLabelPeer.java -- A Swing based peer for AWT labels - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,7 @@ 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; @@ -120,6 +121,17 @@ public class SwingLabelPeer } /** + * 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. * diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java index aca2070486d..22a6052bb7e 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingListPeer.java @@ -1,5 +1,5 @@ /* SwingListPeer.java -- A Swing based peer for AWT lists - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,6 +46,7 @@ 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; @@ -129,6 +130,17 @@ public class SwingListPeer } /** + * 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. * diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java index 3cea62ac4d1..37c6dbc7a5b 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java @@ -1,5 +1,5 @@ /* SwingPanelPeer.java -- A PanelPeer based on Swing - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,7 +47,7 @@ import java.awt.peer.PanelPeer; * @author Roman Kennke (kennke@aicas.com) */ // TODO: Maybe base implementation on JPanel. However, this doesn't seem -// necessary, but might be good for more consistend Look. +// necessary, but might be good for more consistent Look. public class SwingPanelPeer extends SwingContainerPeer implements PanelPeer diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java index 04ac011419f..2c438a1ccb1 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextAreaPeer.java @@ -1,5 +1,5 @@ /* SwingTextAreaPeer.java -- A Swing based peer for AWT textareas - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,14 +45,20 @@ 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 @@ -65,15 +71,19 @@ public class SwingTextAreaPeer * * @author Roman Kennke (kennke@aicas.com) */ - private class SwingTextArea + private class SwingScrollPane extends JScrollPane implements SwingComponent { - SwingTextArea(Component comp) + SwingTextArea textArea; + + SwingScrollPane(SwingTextArea textArea) { - super(comp, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + super(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + + this.textArea = textArea; } /** @@ -94,8 +104,17 @@ public class SwingTextAreaPeer */ public void handleMouseEvent(MouseEvent ev) { - ev.setSource(this); - dispatchEvent(ev); + JViewport viewPort = getViewport(); + if(viewPort.contains(ev.getPoint())) + { + ev.setSource(textArea); + textArea.dispatchEvent(ev); + } + else + { + ev.setSource(this); + this.dispatchEvent(ev); + } } /** @@ -114,7 +133,7 @@ public class SwingTextAreaPeer */ public void handleMouseMotionEvent(MouseEvent ev) { - processMouseMotionEvent(ev); + textArea.processMouseMotionEvent(ev); } /** @@ -124,7 +143,18 @@ public class SwingTextAreaPeer */ public void handleKeyEvent(KeyEvent ev) { - processKeyEvent(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); } /** @@ -179,35 +209,160 @@ public class SwingTextAreaPeer 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 JTextArea jTextArea; + private SwingTextArea jTextArea; public SwingTextAreaPeer(TextArea textArea) { super(); - System.err.println("new SwingTextAreaPeer"); - jTextArea = new JTextArea(); - SwingTextArea swingArea = new SwingTextArea(jTextArea); + 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) { - // TODO Auto-generated method stub - return null; + return jTextArea.getMinimumSize(); } public Dimension getPreferredSize(int rows, int cols) { - // TODO Auto-generated method stub - return null; + return jTextArea.getPreferredSize(); } public void insert(String text, int pos) @@ -220,16 +375,24 @@ public class SwingTextAreaPeer jTextArea.insert(text, pos); } + public Dimension minimumSize() + { + return jTextArea.getMinimumSize(); + } + + public Dimension preferredSize() + { + return jTextArea.getPreferredSize(); + } + public Dimension minimumSize(int rows, int cols) { - // TODO Auto-generated method stub - return null; + return jTextArea.getMinimumSize(); } public Dimension preferredSize(int rows, int cols) { - // TODO Auto-generated method stub - return null; + return jTextArea.getPreferredSize(); } public void replaceRange(String text, int start, int end) @@ -310,8 +473,16 @@ public class SwingTextAreaPeer public void setText(String text) { - System.err.println("setText: " + 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 index d7d574a0bb9..29a689da42a 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java @@ -1,5 +1,5 @@ /* SwingTextFieldPeer.java -- A Swing based peer for AWT textfields - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,6 +44,7 @@ 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; @@ -72,13 +73,13 @@ public class SwingTextFieldPeer implements SwingComponent { - TextField textField; - - SwingTextField(TextField textField) - { - this.textField = textField; - } - + TextField textField; + + SwingTextField(TextField textField) + { + this.textField = textField; + } + /** * Overridden to provide normal behaviour even without a real peer * attached. @@ -91,8 +92,8 @@ public class SwingTextFieldPeer } /** - * Overridden so that the isShowing method returns the correct value for the - * swing button, even if it has no peer on its own. + * 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 @@ -162,6 +163,18 @@ public class SwingTextFieldPeer 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; @@ -174,6 +187,16 @@ public class SwingTextFieldPeer { 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); + } + } /** diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java index 166e1f47b6f..63414050bfe 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java @@ -40,6 +40,7 @@ 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; @@ -162,4 +163,19 @@ public abstract class SwingToolkit extends ClasspathToolkit { 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 index 531552d902c..bdc494e958c 100644 --- a/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java @@ -71,4 +71,29 @@ public abstract class SwingWindowPeer 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. + } } |