Imported GNU Classpath 0.90
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r111942
This commit is contained in:
@@ -229,9 +229,9 @@ public class GLightweightPeer
|
||||
|
||||
public void repaint(long tm, int x, int y, int width, int height)
|
||||
{
|
||||
Component p = comp.getParent ();
|
||||
if(p != null)
|
||||
p.repaint(tm,x+comp.getX(),y+comp.getY(),width,height);
|
||||
Component p = comp.getParent();
|
||||
if (p != null)
|
||||
p.repaint(tm, x + comp.getX(), y + comp.getY(), width, height);
|
||||
}
|
||||
|
||||
public void requestFocus() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkButtonPeer.java -- Implements ButtonPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2004, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -57,7 +57,10 @@ public class GtkButtonPeer extends GtkComponentPeer
|
||||
|
||||
public native void connectSignals ();
|
||||
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
/**
|
||||
* Overridden to set Font of Label inside Button inside EventBox.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
||||
native void gtkSetLabel (String label);
|
||||
native void gtkWidgetSetForeground (int red, int green, int blue);
|
||||
native void gtkWidgetSetBackground (int red, int green, int blue);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkCheckboxMenuItemPeer.java -- Implements CheckboxMenuItemPeer with GTK+
|
||||
Copyright (C) 1999, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -46,7 +46,7 @@ import java.awt.peer.CheckboxMenuItemPeer;
|
||||
public class GtkCheckboxMenuItemPeer extends GtkMenuItemPeer
|
||||
implements CheckboxMenuItemPeer
|
||||
{
|
||||
native void create (String label);
|
||||
protected native void create (String label);
|
||||
|
||||
public GtkCheckboxMenuItemPeer (CheckboxMenuItem menu)
|
||||
{
|
||||
@@ -56,6 +56,11 @@ public class GtkCheckboxMenuItemPeer extends GtkMenuItemPeer
|
||||
|
||||
public native void setState(boolean t);
|
||||
|
||||
/**
|
||||
* Called from the signal handler of the gtk widget. Posts a
|
||||
* ItemEvent to indicate a state changed, then calls super to post
|
||||
* an ActionEvent.
|
||||
*/
|
||||
protected void postMenuActionEvent ()
|
||||
{
|
||||
CheckboxMenuItem item = (CheckboxMenuItem)awtWidget;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkCheckboxPeer.java -- Implements CheckboxPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2002, 2003, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -42,6 +42,8 @@ import java.awt.Checkbox;
|
||||
import java.awt.CheckboxGroup;
|
||||
import java.awt.peer.CheckboxPeer;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
|
||||
public class GtkCheckboxPeer extends GtkComponentPeer
|
||||
implements CheckboxPeer
|
||||
{
|
||||
@@ -49,12 +51,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer
|
||||
public GtkCheckboxGroupPeer old_group;
|
||||
// The current state of the GTK checkbox.
|
||||
private boolean currentState;
|
||||
private boolean changing = false;
|
||||
|
||||
public native void create (GtkCheckboxGroupPeer group);
|
||||
public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group);
|
||||
public native void connectSignals ();
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
|
||||
/**
|
||||
* Overridden to set Font of label inside button.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
||||
native void gtkButtonSetLabel (String label);
|
||||
native void gtkToggleButtonSetActive (boolean is_active);
|
||||
|
||||
@@ -71,23 +76,24 @@ public class GtkCheckboxPeer extends GtkComponentPeer
|
||||
CheckboxGroup g = checkbox.getCheckboxGroup ();
|
||||
old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g);
|
||||
create (old_group);
|
||||
gtkToggleButtonSetActive (checkbox.getState ());
|
||||
currentState = checkbox.getState();
|
||||
gtkToggleButtonSetActive(currentState);
|
||||
gtkButtonSetLabel (checkbox.getLabel ());
|
||||
}
|
||||
|
||||
public void setState (boolean state)
|
||||
/**
|
||||
* Sets native GtkCheckButton is state is different from current
|
||||
* state. Will set currentState to state to prevent posting an
|
||||
* event since events should only be posted for user initiated
|
||||
* clicks on the GtkCheckButton.
|
||||
*/
|
||||
synchronized public void setState (boolean state)
|
||||
{
|
||||
// prevent item_toggled_cb -> postItemEvent ->
|
||||
// awtComponent.setState -> this.setState ->
|
||||
// gtkToggleButtonSetActive self-deadlock on the GDK lock.
|
||||
if (changing && Thread.currentThread() == GtkToolkit.mainThread)
|
||||
{
|
||||
changing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState != state)
|
||||
gtkToggleButtonSetActive (state);
|
||||
{
|
||||
currentState = state;
|
||||
gtkToggleButtonSetActive(state);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLabel (String label)
|
||||
@@ -111,22 +117,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer
|
||||
// Override the superclass postItemEvent so that the peer doesn't
|
||||
// need information that we have.
|
||||
// called back by native side: item_toggled_cb
|
||||
public void postItemEvent (Object item, int stateChange)
|
||||
synchronized public void postItemEvent(Object item, boolean state)
|
||||
{
|
||||
Checkbox currentCheckBox = ((Checkbox)awtComponent);
|
||||
// A firing of the event is only desired if the state has changed due to a
|
||||
// button press. The currentCheckBox's state must be different from the
|
||||
// one that the stateChange is changing to.
|
||||
// stateChange = 1 if it goes from false -> true
|
||||
// stateChange = 2 if it goes from true -> false
|
||||
if (( !currentCheckBox.getState() && stateChange == 1)
|
||||
|| (currentCheckBox.getState() && stateChange == 2))
|
||||
{
|
||||
super.postItemEvent (awtComponent, stateChange);
|
||||
currentState = !currentCheckBox.getState();
|
||||
changing = true;
|
||||
currentCheckBox.setState(currentState);
|
||||
}
|
||||
// Only fire event is state actually changed.
|
||||
if (currentState != state)
|
||||
{
|
||||
currentState = state;
|
||||
super.postItemEvent(awtComponent,
|
||||
state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose ()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* GtkComponentPeer.java -- Implements ComponentPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -46,10 +47,10 @@ 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.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
@@ -87,8 +88,6 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
|
||||
boolean isInRepaint;
|
||||
|
||||
static final Timer repaintTimer = new Timer (true);
|
||||
|
||||
/* this isEnabled differs from Component.isEnabled, in that it
|
||||
knows if a parent is disabled. In that case Component.isEnabled
|
||||
may return true, but our isEnabled will always return false */
|
||||
@@ -146,12 +145,7 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
|
||||
Component parent = awtComponent.getParent ();
|
||||
|
||||
// Only set our parent on the GTK side if our parent on the AWT
|
||||
// side is not showing. Otherwise the gtk peer will be shown
|
||||
// before we've had a chance to position and size it properly.
|
||||
if (awtComponent instanceof Window
|
||||
|| (parent != null && ! parent.isShowing ()))
|
||||
setParentAndBounds ();
|
||||
setParentAndBounds ();
|
||||
|
||||
setNativeEventMask ();
|
||||
|
||||
@@ -202,11 +196,6 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
void setComponentBounds ()
|
||||
{
|
||||
Rectangle bounds = awtComponent.getBounds ();
|
||||
|
||||
if (bounds.x == 0 && bounds.y == 0
|
||||
&& bounds.width == 0 && bounds.height == 0)
|
||||
return;
|
||||
|
||||
setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
|
||||
@@ -303,29 +292,29 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
{
|
||||
case PaintEvent.PAINT:
|
||||
case PaintEvent.UPDATE:
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics g = getGraphics ();
|
||||
|
||||
// Some peers like GtkFileDialogPeer are repainted by Gtk itself
|
||||
if (g == null)
|
||||
break;
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics g = getGraphics();
|
||||
|
||||
g.setClip (((PaintEvent) event).getUpdateRect());
|
||||
if (!awtComponent.isShowing() || awtComponent.getWidth() < 1
|
||||
|| awtComponent.getHeight() < 1 || g == null)
|
||||
break;
|
||||
|
||||
if (id == PaintEvent.PAINT)
|
||||
awtComponent.paint (g);
|
||||
else
|
||||
awtComponent.update (g);
|
||||
g.setClip(((PaintEvent) event).getUpdateRect());
|
||||
|
||||
g.dispose ();
|
||||
}
|
||||
catch (InternalError e)
|
||||
{
|
||||
System.err.println (e);
|
||||
}
|
||||
}
|
||||
if (id == PaintEvent.PAINT)
|
||||
awtComponent.paint(g);
|
||||
else
|
||||
awtComponent.update(g);
|
||||
|
||||
g.dispose();
|
||||
}
|
||||
catch (InternalError e)
|
||||
{
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEY_PRESSED:
|
||||
ke = (KeyEvent) event;
|
||||
@@ -383,19 +372,30 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
if (x == 0 && y == 0 && width == 0 && height == 0)
|
||||
return;
|
||||
|
||||
repaintTimer.schedule(new RepaintTimerTask(x, y, width, height), tm);
|
||||
if (tm <= 0)
|
||||
q().postEvent(new PaintEvent(awtComponent, PaintEvent.UPDATE,
|
||||
new Rectangle(x, y, width, height)));
|
||||
else
|
||||
RepaintTimerTask.schedule(tm, x, y, width, height, awtComponent);
|
||||
}
|
||||
|
||||
private class RepaintTimerTask extends TimerTask
|
||||
/**
|
||||
* Used for scheduling delayed paint updates on the event queue.
|
||||
*/
|
||||
private static class RepaintTimerTask extends TimerTask
|
||||
{
|
||||
private int x, y, width, height;
|
||||
private static final Timer repaintTimer = new Timer(true);
|
||||
|
||||
RepaintTimerTask(int x, int y, int width, int height)
|
||||
private int x, y, width, height;
|
||||
private Component awtComponent;
|
||||
|
||||
RepaintTimerTask(Component c, int x, int y, int width, int height)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.awtComponent = c;
|
||||
}
|
||||
|
||||
public void run()
|
||||
@@ -403,6 +403,12 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE,
|
||||
new Rectangle (x, y, width, height)));
|
||||
}
|
||||
|
||||
static void schedule(long tm, int x, int y, int width, int height,
|
||||
Component c)
|
||||
{
|
||||
repaintTimer.schedule(new RepaintTimerTask(c, x, y, width, height), tm);
|
||||
}
|
||||
}
|
||||
|
||||
public void requestFocus ()
|
||||
@@ -429,8 +435,7 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
int new_y = y;
|
||||
|
||||
Component parent = awtComponent.getParent ();
|
||||
Component next_parent;
|
||||
|
||||
|
||||
// Heavyweight components that are children of one or more
|
||||
// lightweight containers have to be handled specially. Because
|
||||
// calls to GLightweightPeer.setBounds do nothing, GTK has no
|
||||
@@ -441,33 +446,19 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
// so we need to continue adding offsets until we reach a
|
||||
// container whose position GTK knows -- that is, the first
|
||||
// non-lightweight.
|
||||
boolean lightweightChild = false;
|
||||
Insets i;
|
||||
while (parent.isLightweight ())
|
||||
Insets i;
|
||||
while (parent.isLightweight())
|
||||
{
|
||||
lightweightChild = true;
|
||||
|
||||
next_parent = parent.getParent ();
|
||||
|
||||
i = ((Container) parent).getInsets ();
|
||||
|
||||
if (next_parent instanceof Window)
|
||||
{
|
||||
new_x += i.left;
|
||||
new_y += i.top;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_x += parent.getX () + i.left;
|
||||
new_y += parent.getY () + i.top;
|
||||
}
|
||||
|
||||
parent = next_parent;
|
||||
i = ((Container) parent).getInsets();
|
||||
|
||||
new_x += parent.getX() + i.left;
|
||||
new_y += parent.getY() + i.top;
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
// We only need to convert from Java to GTK coordinates if we're
|
||||
// placing a heavyweight component in a Window.
|
||||
if (parent instanceof Window && !lightweightChild)
|
||||
if (parent instanceof Window)
|
||||
{
|
||||
GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer ();
|
||||
// important: we want the window peer's insets here, not the
|
||||
@@ -479,12 +470,17 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
int menuBarHeight = 0;
|
||||
if (peer instanceof GtkFramePeer)
|
||||
menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight ();
|
||||
|
||||
new_x = x - insets.left;
|
||||
new_y = y - insets.top + menuBarHeight;
|
||||
|
||||
new_x -= insets.left;
|
||||
new_y -= insets.top;
|
||||
new_y += menuBarHeight;
|
||||
}
|
||||
|
||||
setNativeBounds (new_x, new_y, width, height);
|
||||
|
||||
// If the height or width were (or are now) smaller than zero
|
||||
// then we want to adjust the visibility.
|
||||
setVisible(awtComponent.isVisible());
|
||||
}
|
||||
|
||||
void setCursor ()
|
||||
@@ -535,6 +531,13 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
|
||||
public void setVisible (boolean b)
|
||||
{
|
||||
// Only really set visible when component is bigger than zero pixels.
|
||||
if (b)
|
||||
{
|
||||
Rectangle bounds = awtComponent.getBounds();
|
||||
b = (bounds.width > 0) && (bounds.height > 0);
|
||||
}
|
||||
|
||||
if (Thread.currentThread() == GtkToolkit.mainThread)
|
||||
setVisibleNativeUnlocked (b);
|
||||
else
|
||||
@@ -571,6 +574,8 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
KeyEvent keyEvent = new KeyEvent (awtComponent, id, when, mods,
|
||||
keyCode, keyChar, keyLocation);
|
||||
|
||||
EventQueue q = q();
|
||||
|
||||
// Also post a KEY_TYPED event if keyEvent is a key press that
|
||||
// doesn't represent an action or modifier key.
|
||||
if (keyEvent.getID () == KeyEvent.KEY_PRESSED
|
||||
@@ -579,15 +584,17 @@ public class GtkComponentPeer extends GtkGenericPeer
|
||||
&& keyCode != KeyEvent.VK_CONTROL
|
||||
&& keyCode != KeyEvent.VK_ALT))
|
||||
{
|
||||
synchronized (q)
|
||||
{
|
||||
q().postEvent (keyEvent);
|
||||
q().postEvent (new KeyEvent (awtComponent, KeyEvent.KEY_TYPED, when, mods,
|
||||
KeyEvent.VK_UNDEFINED, keyChar, keyLocation));
|
||||
synchronized(q)
|
||||
{
|
||||
q.postEvent(keyEvent);
|
||||
keyEvent = new KeyEvent(awtComponent, KeyEvent.KEY_TYPED, when,
|
||||
mods, KeyEvent.VK_UNDEFINED, keyChar,
|
||||
keyLocation);
|
||||
q.postEvent(keyEvent);
|
||||
}
|
||||
}
|
||||
else
|
||||
q().postEvent (keyEvent);
|
||||
q.postEvent(keyEvent);
|
||||
}
|
||||
|
||||
protected void postFocusEvent (int id, boolean temporary)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkContainerPeer.java -- Implements ContainerPeer with GTK
|
||||
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -65,29 +65,6 @@ public class GtkContainerPeer extends GtkComponentPeer
|
||||
|
||||
public void endValidate ()
|
||||
{
|
||||
Component parent = awtComponent.getParent ();
|
||||
|
||||
// Only set our parent on the GTK side if our parent on the AWT
|
||||
// side is not showing. Otherwise the gtk peer will be shown
|
||||
// before we've had a chance to position and size it properly.
|
||||
if (parent != null && parent.isShowing ())
|
||||
{
|
||||
Component[] components = ((Container) awtComponent).getComponents ();
|
||||
int ncomponents = components.length;
|
||||
|
||||
for (int i = 0; i < ncomponents; i++)
|
||||
{
|
||||
ComponentPeer peer = components[i].getPeer ();
|
||||
|
||||
// Skip lightweight peers.
|
||||
if (peer instanceof GtkComponentPeer)
|
||||
((GtkComponentPeer) peer).setParentAndBounds ();
|
||||
}
|
||||
|
||||
// GTK windows don't have parents.
|
||||
if (!(awtComponent instanceof Window))
|
||||
setParentAndBounds ();
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getInsets()
|
||||
|
||||
@@ -41,8 +41,6 @@ package gnu.java.awt.peer.gtk;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.peer.FileDialogPeer;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
@@ -68,7 +66,8 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
|
||||
((FileDialog) awtComponent).getMode());
|
||||
|
||||
FileDialog fd = (FileDialog) awtComponent;
|
||||
|
||||
|
||||
nativeSetDirectory(System.getProperty("user.dir"));
|
||||
setDirectory(fd.getDirectory());
|
||||
setFile(fd.getFile());
|
||||
|
||||
@@ -117,13 +116,9 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
|
||||
// is not absolute, let's construct it based on current directory.
|
||||
currentFile = fileName;
|
||||
if (fileName.indexOf(FS) == 0)
|
||||
{
|
||||
nativeSetFile (fileName);
|
||||
}
|
||||
nativeSetFile(fileName);
|
||||
else
|
||||
{
|
||||
nativeSetFile (nativeGetDirectory() + FS + fileName);
|
||||
}
|
||||
nativeSetFile(nativeGetDirectory() + FS + fileName);
|
||||
}
|
||||
|
||||
public void setDirectory (String directory)
|
||||
@@ -132,18 +127,24 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
|
||||
the only way we have to set the directory in FileDialog is by
|
||||
calling its setDirectory which will call us back. */
|
||||
if ((directory == null && currentDirectory == null)
|
||||
|| (directory != null && directory.equals (currentDirectory)))
|
||||
|| (directory != null && directory.equals(currentDirectory)))
|
||||
return;
|
||||
|
||||
if (directory == null || directory.equals (""))
|
||||
if (directory == null || directory.equals(""))
|
||||
{
|
||||
currentDirectory = FS;
|
||||
nativeSetFile (FS);
|
||||
return;
|
||||
nativeSetDirectory(FS);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// GtkFileChooser requires absolute directory names. If the given directory
|
||||
// name is not absolute, construct it based on current directory if it is not
|
||||
// null. Otherwise, use FS.
|
||||
currentDirectory = directory;
|
||||
nativeSetDirectory (directory);
|
||||
if (directory.indexOf(FS) == 0)
|
||||
nativeSetDirectory(directory);
|
||||
else
|
||||
nativeSetDirectory(nativeGetDirectory() + FS + directory);
|
||||
}
|
||||
|
||||
public void setFilenameFilter (FilenameFilter filter)
|
||||
|
||||
@@ -43,10 +43,7 @@ import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.peer.FramePeer;
|
||||
import java.awt.peer.MenuBarPeer;
|
||||
|
||||
@@ -77,7 +74,10 @@ public class GtkFramePeer extends GtkWindowPeer
|
||||
removeMenuBarPeer ();
|
||||
insets.top -= menuBarHeight;
|
||||
menuBarHeight = 0;
|
||||
awtComponent.validate ();
|
||||
// if component has already been validated, we need to revalidate.
|
||||
// otherwise, it will be validated when it is shown.
|
||||
if (awtComponent.isValid())
|
||||
awtComponent.validate ();
|
||||
gtkFixedSetVisible (true);
|
||||
}
|
||||
else if (bar != null && menuBar == null)
|
||||
@@ -92,7 +92,10 @@ public class GtkFramePeer extends GtkWindowPeer
|
||||
setMenuBarWidth (menuBar, menuBarWidth);
|
||||
menuBarHeight = getMenuBarHeight ();
|
||||
insets.top += menuBarHeight;
|
||||
awtComponent.validate ();
|
||||
// if component has already been validated, we need to revalidate.
|
||||
// otherwise, it will be validated when it is shown.
|
||||
if (awtComponent.isValid())
|
||||
awtComponent.validate ();
|
||||
gtkFixedSetVisible (true);
|
||||
}
|
||||
else if (bar != null && menuBar != null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkGenericPeer.java - Has a hashcode. Yuck.
|
||||
Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2002, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -39,23 +39,28 @@ exception statement from your version. */
|
||||
package gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class GtkGenericPeer
|
||||
{
|
||||
// Used by Native State Association (NSA) functions to map
|
||||
// gtk_widget to peer object.
|
||||
final int native_state = getUniqueInteger ();
|
||||
|
||||
// Next native state value we will assign.
|
||||
private static int next_native_state = 0;
|
||||
|
||||
// The widget or other java-side object we wrap.
|
||||
protected Object awtWidget;
|
||||
protected final Object awtWidget;
|
||||
|
||||
// Global event queue.
|
||||
protected static EventQueue q = null;
|
||||
|
||||
// Dispose of our native state.
|
||||
/**
|
||||
* Dispose of our native state. Calls gtk_widget_destroy on the
|
||||
* native widget and removes the awtWidget from the native state
|
||||
* tables. Should be overridden by subclasses if this is not (all)
|
||||
* that needs to be done.
|
||||
*/
|
||||
public native void dispose ();
|
||||
|
||||
static EventQueue q ()
|
||||
@@ -68,12 +73,6 @@ public class GtkGenericPeer
|
||||
this.awtWidget = awtWidget;
|
||||
}
|
||||
|
||||
public static void enableQueue (EventQueue sq)
|
||||
{
|
||||
if (q == null)
|
||||
q = sq;
|
||||
}
|
||||
|
||||
protected void postActionEvent (String command, int mods)
|
||||
{
|
||||
q().postEvent (new ActionEvent (awtWidget, ActionEvent.ACTION_PERFORMED,
|
||||
@@ -88,8 +87,20 @@ public class GtkGenericPeer
|
||||
// Let's assume this will never wrap.
|
||||
return next_native_state++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set Font for Gtk Widget.
|
||||
*/
|
||||
protected void gtkWidgetModifyFont(Font f)
|
||||
{
|
||||
gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
|
||||
}
|
||||
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
/**
|
||||
* Sets font for this Gtk Widget. Should be overridden by peers which
|
||||
* are composed of different widgets or are contained in bins.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
||||
|
||||
static void printCurrentThread ()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkImage.java
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -329,6 +329,24 @@ public class GtkImage extends Image
|
||||
props = new Hashtable();
|
||||
}
|
||||
|
||||
// The singleton GtkImage that is returned on errors by GtkToolkit.
|
||||
private static GtkImage errorImage;
|
||||
|
||||
/**
|
||||
* Returns an empty GtkImage with the errorLoading flag set.
|
||||
* Called from GtkToolKit when some error occured, but an image needs
|
||||
* to be returned anyway.
|
||||
*/
|
||||
static synchronized GtkImage getErrorImage()
|
||||
{
|
||||
if (errorImage == null)
|
||||
{
|
||||
errorImage = new GtkImage();
|
||||
errorImage.errorLoading = true;
|
||||
}
|
||||
return errorImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Native helper function for constructor that takes a pixbuf Pointer.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkLabelPeer.java -- Implements LabelPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -48,7 +48,12 @@ public class GtkLabelPeer extends GtkComponentPeer
|
||||
implements LabelPeer
|
||||
{
|
||||
native void create (String text, float alignment);
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
|
||||
/**
|
||||
* Overridden to set the Font of the label inside the gtk_event_box.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
||||
|
||||
native void nativeSetAlignment (float alignment);
|
||||
|
||||
public native void setText(String text);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkListPeer.java -- Implements ListPeer with GTK
|
||||
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -59,7 +59,12 @@ public class GtkListPeer extends GtkComponentPeer
|
||||
|
||||
native void create (int rows);
|
||||
native void connectSignals ();
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
|
||||
/**
|
||||
* Overridden to set the Font of the text insode the gtk_scrolled_window.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
|
||||
native void gtkWidgetRequestFocus ();
|
||||
|
||||
native void getSize (int rows, int visibleRows, int dims[]);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkMenuBarPeer.java -- Implements MenuBarPeer with GTK+
|
||||
Copyright (C) 1999, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -48,38 +48,69 @@ import java.awt.peer.MenuPeer;
|
||||
public class GtkMenuBarPeer extends GtkMenuComponentPeer
|
||||
implements MenuBarPeer
|
||||
{
|
||||
/** Whether we already have an help menu set on this peer. */
|
||||
private boolean hasHelpMenu;
|
||||
|
||||
native void create ();
|
||||
native void addMenu (MenuPeer menu);
|
||||
/**
|
||||
* Creates the gtk+ widget for this peer and puts it in the nsa
|
||||
* table. Called from the (super class) constructor.
|
||||
*/
|
||||
protected native void create();
|
||||
|
||||
public GtkMenuBarPeer (MenuBar target)
|
||||
/**
|
||||
* Adds a new GtkMenuPeer to the end of the GtkMenuBarPeer.
|
||||
*/
|
||||
private native void addMenu(GtkMenuPeer menu);
|
||||
|
||||
/**
|
||||
* Creates a new GtkMenuBarPeer associated with the given MenuBar.
|
||||
*/
|
||||
public GtkMenuBarPeer(MenuBar menubar)
|
||||
{
|
||||
super (target);
|
||||
super(menubar);
|
||||
}
|
||||
|
||||
void setFont ()
|
||||
{
|
||||
MenuComponent mc = (MenuComponent) awtWidget;
|
||||
Font f = mc.getFont ();
|
||||
|
||||
if (f == null)
|
||||
mc.setFont (new Font ("Dialog", Font.PLAIN, 12));
|
||||
}
|
||||
|
||||
// FIXME: remove this method or replace it with one that does
|
||||
// something useful.
|
||||
/* In Gnome, help menus are no longer right flushed. */
|
||||
native void nativeSetHelpMenu(MenuPeer menuPeer);
|
||||
|
||||
/**
|
||||
* Adds a help menu to this MenuBar. Gnome styleguides say the help
|
||||
* menu is just the last item in the menubar (they are NOT right
|
||||
* justified).
|
||||
*/
|
||||
public void addHelpMenu (Menu menu)
|
||||
{
|
||||
// nativeSetHelpMenu((MenuPeer) menu.getPeer());
|
||||
if (hasHelpMenu)
|
||||
{
|
||||
// Remove the (help) menu, which is after all the other items.
|
||||
delMenu(((MenuBar) awtWidget).getMenuCount());
|
||||
hasHelpMenu = false;
|
||||
}
|
||||
|
||||
if (menu != null)
|
||||
{
|
||||
addMenu(menu);
|
||||
hasHelpMenu = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the menu at (zero-based) index from this GtkMenuBar.
|
||||
*/
|
||||
public native void delMenu(int index);
|
||||
|
||||
public void addMenu (Menu m)
|
||||
/**
|
||||
* Adds the GtkMenuPeer associated with the Menu to this
|
||||
* GtkMenuBarPeer. Makes sure that any help menus keep the last menu
|
||||
* on the bar.
|
||||
*/
|
||||
public void addMenu(Menu m)
|
||||
{
|
||||
// FIXME: implement
|
||||
// Make sure the help menu is the last one.
|
||||
if (hasHelpMenu)
|
||||
{
|
||||
addHelpMenu(null);
|
||||
addMenu((GtkMenuPeer) m.getPeer());
|
||||
addHelpMenu(((MenuBar) awtWidget).getHelpMenu());
|
||||
}
|
||||
else
|
||||
addMenu((GtkMenuPeer) m.getPeer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkMenuComponentPeer.java -- Implements MenuComponentPeer with GTK+
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -39,31 +39,66 @@ exception statement from your version. */
|
||||
package gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.MenuComponent;
|
||||
import java.awt.MenuContainer;
|
||||
import java.awt.peer.MenuComponentPeer;
|
||||
|
||||
public class GtkMenuComponentPeer extends GtkGenericPeer
|
||||
public abstract class GtkMenuComponentPeer extends GtkGenericPeer
|
||||
implements MenuComponentPeer
|
||||
{
|
||||
void create ()
|
||||
/**
|
||||
* Creates the associated gtk+ widget and stores it in the nsa table
|
||||
* for this peer. Called by the constructor.
|
||||
*/
|
||||
protected abstract void create ();
|
||||
|
||||
/**
|
||||
* Sets font based on MenuComponent font, or containing menu(bar)
|
||||
* parent font.
|
||||
*/
|
||||
private void setFont()
|
||||
{
|
||||
throw new RuntimeException ();
|
||||
MenuComponent mc = ((MenuComponent) awtWidget);
|
||||
Font f = mc.getFont();
|
||||
|
||||
if (f == null)
|
||||
{
|
||||
MenuContainer parent = mc.getParent ();
|
||||
// Submenus inherit the font of their containing Menu(Bar).
|
||||
if (parent instanceof MenuComponent)
|
||||
f = parent.getFont ();
|
||||
}
|
||||
|
||||
setFont(f);
|
||||
}
|
||||
|
||||
void setFont ()
|
||||
/**
|
||||
* Will call the abstract <code>create()</code> that needs to be
|
||||
* overridden by subclasses, to create the MenuComponent. It will
|
||||
* then correctly setup the font for the component based on the
|
||||
* component and/or its containing parent component.
|
||||
*/
|
||||
public GtkMenuComponentPeer(MenuComponent component)
|
||||
{
|
||||
super(component);
|
||||
create();
|
||||
setFont();
|
||||
}
|
||||
|
||||
public GtkMenuComponentPeer (Object awtWidget)
|
||||
{
|
||||
super (awtWidget);
|
||||
create ();
|
||||
setFont ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the awtWidget components from the native state tables.
|
||||
* Subclasses should call <code>super.dispose()</code> if they don't
|
||||
* remove these themselves.
|
||||
*/
|
||||
public native void dispose();
|
||||
|
||||
/**
|
||||
* Sets the font for this particular MenuComponent only (not any
|
||||
* containing items, if any).
|
||||
*/
|
||||
public void setFont(Font font)
|
||||
{
|
||||
// FIXME: implement
|
||||
if (font != null)
|
||||
gtkWidgetModifyFont(font);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkMenuItemPeer.java -- Implements MenuItemPeer with GTK+
|
||||
Copyright (C) 1999, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -49,70 +49,71 @@ import java.awt.peer.MenuPeer;
|
||||
public class GtkMenuItemPeer extends GtkMenuComponentPeer
|
||||
implements MenuItemPeer
|
||||
{
|
||||
native void create (String label);
|
||||
native void connectSignals ();
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
/**
|
||||
* Creates the associated gtk+ widget and stores it in the nsa table
|
||||
* for this peer. Called by the create() method with the label name
|
||||
* of the associated MenuItem. Needs to be overridden my subclasses
|
||||
* that want to create a different gtk+ widget.
|
||||
*/
|
||||
protected native void create (String label);
|
||||
|
||||
void create ()
|
||||
/**
|
||||
* Called from constructor to enable signals from an item. If a
|
||||
* subclass needs different (or no) signals connected this method
|
||||
* should be overridden.
|
||||
*/
|
||||
protected native void connectSignals ();
|
||||
|
||||
/**
|
||||
* Overridden to set font on menu item label.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
||||
|
||||
/**
|
||||
* Creates the associated gtk+ widget and stores it in the nsa table
|
||||
* for this peer. Called by the (super class) constructor.
|
||||
* Overridden to get the label if the assiociated MenuItem and to
|
||||
* call create(String).
|
||||
*/
|
||||
protected void create()
|
||||
{
|
||||
create (((MenuItem) awtWidget).getLabel());
|
||||
}
|
||||
|
||||
public GtkMenuItemPeer (MenuItem item)
|
||||
/**
|
||||
* Creates a new GtkMenuItemPeer associated with the given MenuItem.
|
||||
* It will call create(), setFont(), setEnabled() and
|
||||
* connectSignals() in that order.
|
||||
*/
|
||||
public GtkMenuItemPeer(MenuItem item)
|
||||
{
|
||||
super (item);
|
||||
setEnabled (item.isEnabled ());
|
||||
setParent (item);
|
||||
|
||||
if (item.getParent() instanceof Menu && ! (item instanceof Menu))
|
||||
connectSignals();
|
||||
super(item);
|
||||
setEnabled (item.isEnabled());
|
||||
connectSignals();
|
||||
}
|
||||
|
||||
void setFont ()
|
||||
/**
|
||||
* Calls setEnabled(false).
|
||||
*/
|
||||
public void disable()
|
||||
{
|
||||
MenuComponent mc = ((MenuComponent) awtWidget);
|
||||
Font f = mc.getFont ();
|
||||
|
||||
if (f == null)
|
||||
{
|
||||
MenuComponent parent = (MenuComponent) mc.getParent ();
|
||||
Font pf = parent.getFont ();
|
||||
gtkWidgetModifyFont (pf.getName (), pf.getStyle (), pf.getSize ());
|
||||
}
|
||||
else
|
||||
gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void setParent (MenuItem item)
|
||||
/**
|
||||
* Calls setEnabled(true).
|
||||
*/
|
||||
public void enable()
|
||||
{
|
||||
// add ourself differently, based on what type of parent we have
|
||||
// yes, the typecasting here is nasty.
|
||||
Object parent = item.getParent ();
|
||||
if (parent instanceof MenuBar)
|
||||
{
|
||||
((GtkMenuBarPeer)((MenuBar)parent).getPeer ()).addMenu ((MenuPeer) this);
|
||||
}
|
||||
else // parent instanceof Menu
|
||||
{
|
||||
((GtkMenuPeer)((Menu)parent).getPeer ()).addItem (this,
|
||||
item.getShortcut ());
|
||||
}
|
||||
}
|
||||
|
||||
public void disable ()
|
||||
{
|
||||
setEnabled (false);
|
||||
}
|
||||
|
||||
public void enable ()
|
||||
{
|
||||
setEnabled (true);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
public native void setEnabled(boolean b);
|
||||
|
||||
public native void setLabel(String label);
|
||||
|
||||
/**
|
||||
* Callback setup through connectSignals().
|
||||
*/
|
||||
protected void postMenuActionEvent ()
|
||||
{
|
||||
postActionEvent (((MenuItem)awtWidget).getActionCommand (), 0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkMenuPeer.java -- Implements MenuPeer with GTK+
|
||||
Copyright (C) 1999, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -49,10 +49,28 @@ import java.awt.peer.MenuPeer;
|
||||
public class GtkMenuPeer extends GtkMenuItemPeer
|
||||
implements MenuPeer
|
||||
{
|
||||
native void create (String label);
|
||||
native void addItem (MenuItemPeer item, int key, boolean shiftModifier);
|
||||
/**
|
||||
* Creates the associated gtk+ widget and stores it in the nsa table
|
||||
* for this peer. Called by the create() method with the label name
|
||||
* of the associated MenuItem. Overridden to greate a Menu widget.
|
||||
*/
|
||||
protected native void create (String label);
|
||||
|
||||
private native void addItem(MenuItemPeer item, int key,
|
||||
boolean shiftModifier);
|
||||
|
||||
/** XXX - Document this and the override in GtkPopupMenuPeer. */
|
||||
native void setupAccelGroup (GtkGenericPeer container);
|
||||
native void addTearOff ();
|
||||
|
||||
private native void addTearOff ();
|
||||
|
||||
/**
|
||||
* Overridden to not connect any signals.
|
||||
*/
|
||||
protected void connectSignals()
|
||||
{
|
||||
// No signals to connect.
|
||||
}
|
||||
|
||||
public GtkMenuPeer (Menu menu)
|
||||
{
|
||||
@@ -63,11 +81,11 @@ public class GtkMenuPeer extends GtkMenuItemPeer
|
||||
|
||||
MenuContainer parent = menu.getParent ();
|
||||
if (parent instanceof Menu)
|
||||
setupAccelGroup ((GtkGenericPeer)((Menu)parent).getPeer ());
|
||||
setupAccelGroup ((GtkMenuPeer)((Menu)parent).getPeer ());
|
||||
else if (parent instanceof Component)
|
||||
setupAccelGroup ((GtkGenericPeer)((Component)parent).getPeer ());
|
||||
setupAccelGroup ((GtkComponentPeer)((Component)parent).getPeer ());
|
||||
else
|
||||
setupAccelGroup (null);
|
||||
setupAccelGroup (null); // XXX, should we warn about unknown parent?
|
||||
}
|
||||
|
||||
public void addItem (MenuItem item)
|
||||
|
||||
@@ -39,8 +39,11 @@ exception statement from your version. */
|
||||
package gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.peer.PanelPeer;
|
||||
|
||||
public class GtkPanelPeer extends GtkContainerPeer
|
||||
@@ -53,17 +56,39 @@ public class GtkPanelPeer extends GtkContainerPeer
|
||||
super (p);
|
||||
}
|
||||
|
||||
public void handleEvent (AWTEvent event)
|
||||
public void handleEvent(AWTEvent event)
|
||||
{
|
||||
int id = event.getID();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case MouseEvent.MOUSE_PRESSED:
|
||||
awtComponent.requestFocusInWindow ();
|
||||
awtComponent.requestFocusInWindow();
|
||||
break;
|
||||
case PaintEvent.UPDATE:
|
||||
case PaintEvent.PAINT:
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics g = getGraphics();
|
||||
if (! awtComponent.isShowing() || awtComponent.getWidth() < 1
|
||||
|| awtComponent.getHeight() < 1 || g == null)
|
||||
return;
|
||||
|
||||
g.setClip(((PaintEvent) event).getUpdateRect());
|
||||
|
||||
// Do not want to clear anything before painting.);
|
||||
awtComponent.paint(g);
|
||||
|
||||
g.dispose();
|
||||
return;
|
||||
}
|
||||
catch (InternalError e)
|
||||
{
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
super.handleEvent (event);
|
||||
}
|
||||
super.handleEvent(event);
|
||||
}
|
||||
|
||||
native void connectSignals ();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkPopupMenuPeer.java -- Implements PopupMenuPeer with GTK+
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -55,11 +55,6 @@ public class GtkPopupMenuPeer extends GtkMenuPeer
|
||||
|
||||
native void setupAccelGroup (GtkGenericPeer container);
|
||||
|
||||
void setParent (MenuItem item)
|
||||
{
|
||||
// we don't need to "add" ourselves to our parent
|
||||
}
|
||||
|
||||
native void show (int x, int y, long time);
|
||||
public void show (Component origin, int x, int y)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GtkScrollbarPeer.java -- Implements ScrollbarPeer with GTK+
|
||||
Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -39,6 +39,7 @@ exception statement from your version. */
|
||||
package gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Adjustable;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Scrollbar;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.peer.ScrollbarPeer;
|
||||
@@ -69,12 +70,25 @@ public class GtkScrollbarPeer extends GtkComponentPeer
|
||||
|
||||
public native void setLineIncrement(int amount);
|
||||
public native void setPageIncrement(int amount);
|
||||
public native void setValues(int value, int visible, int min, int max);
|
||||
|
||||
public void setValues(int value, int visible, int min, int max)
|
||||
{
|
||||
Scrollbar sb = (Scrollbar) awtComponent;
|
||||
if (!sb.getValueIsAdjusting())
|
||||
setBarValues(value, visible, min, max);
|
||||
}
|
||||
|
||||
private native void setBarValues(int value, int visible, int min, int max);
|
||||
|
||||
/**
|
||||
* Called from the native site when the scrollbar changed.
|
||||
* Posts a "user generated" AdjustmentEvent to the queue.
|
||||
*/
|
||||
protected void postAdjustmentEvent (int type, int value)
|
||||
{
|
||||
q().postEvent (new AdjustmentEvent ((Adjustable)awtComponent,
|
||||
Scrollbar bar = (Scrollbar) awtComponent;
|
||||
q().postEvent(new AdjustmentEvent(bar,
|
||||
AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
|
||||
type, value));
|
||||
type, value, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,11 @@ public class GtkTextAreaPeer extends GtkComponentPeer
|
||||
|
||||
native void create (int width, int height, int scrollbarVisibility);
|
||||
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
/**
|
||||
* Overridden to set Font for text widget inside scrolled window.
|
||||
*/
|
||||
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
||||
|
||||
native void gtkWidgetRequestFocus ();
|
||||
|
||||
public native void connectSignals ();
|
||||
|
||||
@@ -112,8 +112,6 @@ public class GtkTextFieldPeer extends GtkComponentPeer
|
||||
|
||||
native int gtkEntryGetBorderWidth ();
|
||||
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
|
||||
public GtkTextFieldPeer (TextField tf)
|
||||
{
|
||||
super (tf);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
|
||||
Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -159,137 +160,93 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper class to return to clients in cases where a BufferedImage is
|
||||
* desired but its construction fails.
|
||||
* Helper to return either a Image -- the argument -- or a
|
||||
* GtkImage with the errorLoading flag set if the argument is null.
|
||||
*/
|
||||
private class GtkErrorImage extends Image
|
||||
{
|
||||
public GtkErrorImage()
|
||||
{
|
||||
}
|
||||
|
||||
public int getWidth(ImageObserver observer)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getHeight(ImageObserver observer)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ImageProducer getSource()
|
||||
{
|
||||
|
||||
return new ImageProducer()
|
||||
{
|
||||
HashSet consumers = new HashSet();
|
||||
public void addConsumer(ImageConsumer ic)
|
||||
{
|
||||
consumers.add(ic);
|
||||
}
|
||||
|
||||
public boolean isConsumer(ImageConsumer ic)
|
||||
{
|
||||
return consumers.contains(ic);
|
||||
}
|
||||
|
||||
public void removeConsumer(ImageConsumer ic)
|
||||
{
|
||||
consumers.remove(ic);
|
||||
}
|
||||
|
||||
public void startProduction(ImageConsumer ic)
|
||||
{
|
||||
consumers.add(ic);
|
||||
Iterator i = consumers.iterator();
|
||||
while(i.hasNext())
|
||||
{
|
||||
ImageConsumer c = (ImageConsumer) i.next();
|
||||
c.imageComplete(ImageConsumer.IMAGEERROR);
|
||||
}
|
||||
}
|
||||
public void requestTopDownLeftRightResend(ImageConsumer ic)
|
||||
{
|
||||
startProduction(ic);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Graphics getGraphics()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getProperty(String name, ImageObserver observer)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public Image getScaledInstance(int width, int height, int flags)
|
||||
{
|
||||
return new GtkErrorImage();
|
||||
}
|
||||
|
||||
public void flush()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper to return either a BufferedImage -- the argument -- or a
|
||||
* GtkErrorImage if the argument is null.
|
||||
*/
|
||||
|
||||
private Image bufferedImageOrError(BufferedImage b)
|
||||
private Image imageOrError(Image b)
|
||||
{
|
||||
if (b == null)
|
||||
return new GtkErrorImage();
|
||||
return GtkImage.getErrorImage();
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
public Image createImage (String filename)
|
||||
{
|
||||
if (filename.length() == 0)
|
||||
return new GtkImage ();
|
||||
|
||||
if (useGraphics2D())
|
||||
return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (filename));
|
||||
else
|
||||
return new GtkImage (filename);
|
||||
|
||||
Image image;
|
||||
try
|
||||
{
|
||||
if (useGraphics2D())
|
||||
image = GdkPixbufDecoder.createBufferedImage(filename);
|
||||
else
|
||||
image = new GtkImage(filename);
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
image = null;
|
||||
}
|
||||
return imageOrError(image);
|
||||
}
|
||||
|
||||
public Image createImage (URL url)
|
||||
{
|
||||
if (useGraphics2D())
|
||||
return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (url));
|
||||
else
|
||||
return new GtkImage (url);
|
||||
Image image;
|
||||
try
|
||||
{
|
||||
if (useGraphics2D())
|
||||
image = GdkPixbufDecoder.createBufferedImage(url);
|
||||
else
|
||||
image = new GtkImage(url);
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
image = null;
|
||||
}
|
||||
return imageOrError(image);
|
||||
}
|
||||
|
||||
public Image createImage (ImageProducer producer)
|
||||
{
|
||||
if (useGraphics2D())
|
||||
return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (producer));
|
||||
else
|
||||
return new GtkImage (producer);
|
||||
Image image;
|
||||
try
|
||||
{
|
||||
if (useGraphics2D())
|
||||
image = GdkPixbufDecoder.createBufferedImage(producer);
|
||||
else
|
||||
image = new GtkImage(producer);
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
image = null;
|
||||
}
|
||||
return imageOrError(image);
|
||||
}
|
||||
|
||||
public Image createImage (byte[] imagedata, int imageoffset,
|
||||
int imagelength)
|
||||
{
|
||||
if (useGraphics2D())
|
||||
return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (imagedata,
|
||||
imageoffset,
|
||||
imagelength));
|
||||
else
|
||||
Image image;
|
||||
try
|
||||
{
|
||||
byte[] datacopy = new byte[imagelength];
|
||||
System.arraycopy (imagedata, imageoffset, datacopy, 0, imagelength);
|
||||
return new GtkImage (datacopy);
|
||||
if (useGraphics2D())
|
||||
image = GdkPixbufDecoder.createBufferedImage(imagedata,
|
||||
imageoffset,
|
||||
imagelength);
|
||||
else
|
||||
{
|
||||
byte[] datacopy = new byte[imagelength];
|
||||
System.arraycopy(imagedata, imageoffset, datacopy, 0, imagelength);
|
||||
return new GtkImage(datacopy);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
image = null;
|
||||
}
|
||||
return imageOrError(image);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -608,7 +565,6 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
|
||||
if (q == null)
|
||||
{
|
||||
q = new EventQueue();
|
||||
GtkGenericPeer.enableQueue (q);
|
||||
}
|
||||
}
|
||||
return q;
|
||||
|
||||
@@ -38,9 +38,12 @@ exception statement from your version. */
|
||||
|
||||
package gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Component;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.peer.WindowPeer;
|
||||
|
||||
@@ -123,7 +126,23 @@ public class GtkWindowPeer extends GtkContainerPeer
|
||||
|
||||
native void nativeSetBounds (int x, int y, int width, int height);
|
||||
native void nativeSetBoundsUnlocked (int x, int y, int width, int height);
|
||||
native void nativeSetLocation (int x, int y);
|
||||
native void nativeSetLocationUnlocked (int x, int y);
|
||||
|
||||
public void setLocation (int x, int y)
|
||||
{
|
||||
// prevent window_configure_cb -> awtComponent.setSize ->
|
||||
// peer.setBounds -> nativeSetBounds self-deadlock on GDK lock.
|
||||
if (Thread.currentThread() == GtkToolkit.mainThread)
|
||||
return;
|
||||
nativeSetLocation (x, y);
|
||||
}
|
||||
|
||||
public void setLocationUnlocked (int x, int y)
|
||||
{
|
||||
nativeSetLocationUnlocked (x, y);
|
||||
}
|
||||
|
||||
public void setBounds (int x, int y, int width, int height)
|
||||
{
|
||||
// prevent window_configure_cb -> awtComponent.setSize ->
|
||||
@@ -192,12 +211,7 @@ public class GtkWindowPeer extends GtkContainerPeer
|
||||
|
||||
public void show ()
|
||||
{
|
||||
// Prevent the window manager from automatically placing this
|
||||
// window when it is shown.
|
||||
setBounds (awtComponent.getX(),
|
||||
awtComponent.getY(),
|
||||
awtComponent.getWidth(),
|
||||
awtComponent.getHeight());
|
||||
setLocation(awtComponent.getX(), awtComponent.getY());
|
||||
setVisible (true);
|
||||
}
|
||||
|
||||
@@ -235,4 +249,32 @@ public class GtkWindowPeer extends GtkContainerPeer
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleEvent(AWTEvent event)
|
||||
{
|
||||
int id = event.getID();
|
||||
if (id == PaintEvent.UPDATE || id == PaintEvent.PAINT)
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics g = getGraphics();
|
||||
if (! awtComponent.isShowing() || awtComponent.getWidth() < 1
|
||||
|| awtComponent.getHeight() < 1 || g == null)
|
||||
return;
|
||||
|
||||
g.setClip(((PaintEvent) event).getUpdateRect());
|
||||
|
||||
// Do not want to clear anything before painting.
|
||||
awtComponent.paint(g);
|
||||
|
||||
g.dispose();
|
||||
return;
|
||||
}
|
||||
catch (InternalError e)
|
||||
{
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
super.handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/* SwingButtonPeer.java -- A Swing based peer for AWT buttons
|
||||
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.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* 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 (SwingButtonPeer.this.awtComponent != null)
|
||||
retVal = SwingButtonPeer.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 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/* 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.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);
|
||||
}
|
||||
@@ -0,0 +1,994 @@
|
||||
/* SwingComponentPeer.java -- An abstract base class for Swing based 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.AWTEvent;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BufferCapabilities;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.BufferCapabilities.FlipContents;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.ContainerPeer;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
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();
|
||||
ComponentPeer parentPeer = parent.getPeer();
|
||||
Graphics g = parentPeer.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()
|
||||
{
|
||||
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 getPreferredSize()
|
||||
{
|
||||
Dimension retVal;
|
||||
if (swingComponent != null)
|
||||
retVal = swingComponent.getJComponent().getPreferredSize();
|
||||
else
|
||||
retVal = new Dimension(0, 0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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:
|
||||
Graphics g = getGraphics();
|
||||
Rectangle clip = ((PaintEvent)e).getUpdateRect();
|
||||
g.clipRect(clip.x, clip.y, clip.width, clip.height);
|
||||
//if (this instanceof LightweightPeer)
|
||||
// {
|
||||
if (e.getID() == PaintEvent.UPDATE)
|
||||
awtComponent.update(g);
|
||||
else
|
||||
awtComponent.paint(g);
|
||||
// }
|
||||
// We paint the 'heavyweights' at last, so that they appear on top of
|
||||
// everything else.
|
||||
peerPaint(g);
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 void paint(Graphics graphics)
|
||||
{
|
||||
// FIXME: I don't know what this method is supposed to do.
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an image for rendering on this component. This is called by
|
||||
* {@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();
|
||||
ComponentPeer parentPeer = parent.getPeer();
|
||||
return parentPeer.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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
if (swingComponent != null)
|
||||
swingComponent.getJComponent().requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that this component receives the focus. This is called from
|
||||
* {@link Component#requestFocus()}.
|
||||
*
|
||||
* This calls requestFocus() on the Swing component.
|
||||
*
|
||||
* @param source TODO
|
||||
* @param bool1 TODO
|
||||
* @param bool2 TODO
|
||||
* @param x TODO
|
||||
*
|
||||
* @return TODO
|
||||
*/
|
||||
public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x)
|
||||
{
|
||||
if (swingComponent != null)
|
||||
swingComponent.getJComponent().requestFocus();
|
||||
return swingComponent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (swingComponent != null)
|
||||
swingComponent.getJComponent().setBounds(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)
|
||||
{
|
||||
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 (swingComponent != null)
|
||||
swingComponent.getJComponent().setVisible(visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// Nothing to do here yet.
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
ComponentPeer parentPeer = parent.getPeer();
|
||||
return parentPeer.createVolatileImage(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected void peerPaint(Graphics g)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AWT component for this peer.
|
||||
*
|
||||
* @return the AWT component for this peer
|
||||
*/
|
||||
public Component getComponent()
|
||||
{
|
||||
return awtComponent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
/* SwingContainerPeer.java -- A Swing based peer for AWT containers
|
||||
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.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Shape;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.ContainerPeer;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new SwingContainerPeer.
|
||||
*
|
||||
* @param awtCont
|
||||
*/
|
||||
public SwingContainerPeer(Container awtCont)
|
||||
{
|
||||
init(awtCont, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
Insets retVal;
|
||||
if (swingComponent != null)
|
||||
retVal = swingComponent.getJComponent().getInsets();
|
||||
else
|
||||
retVal = new Insets(0, 0, 0, 0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the validation of this containers begins.
|
||||
*/
|
||||
public void beginValidate()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers painting of a component. This calls peerPaint on all the child
|
||||
* components of this container.
|
||||
*
|
||||
* @param g the graphics context to paint to
|
||||
*/
|
||||
protected void peerPaint(Graphics g)
|
||||
{
|
||||
Container c = (Container) awtComponent;
|
||||
Component[] children = c.getComponents();
|
||||
for (int i = children.length - 1; i >= 0; --i)
|
||||
{
|
||||
Component child = children[i];
|
||||
ComponentPeer peer = child.getPeer();
|
||||
boolean translated = false;
|
||||
boolean clipped = false;
|
||||
Shape oldClip = g.getClip();
|
||||
try
|
||||
{
|
||||
g.translate(child.getX(), child.getY());
|
||||
translated = true;
|
||||
g.setClip(0, 0, child.getWidth(), child.getHeight());
|
||||
clipped = true;
|
||||
if (peer instanceof SwingComponentPeer)
|
||||
((SwingComponentPeer) peer).peerPaint(g);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (translated)
|
||||
g.translate(- child.getX(), - child.getY());
|
||||
if (clipped)
|
||||
g.setClip(oldClip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
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());
|
||||
ComponentPeer peer = comp.getPeer();
|
||||
if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
|
||||
{
|
||||
ev.translatePoint(comp.getX(), comp.getY());
|
||||
((SwingComponentPeer) peer).handleMouseMotionEvent(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/* 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.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 peerPaint(Graphics g)
|
||||
{
|
||||
super.peerPaint(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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/* SwingLabelPeer.java -- A Swing based peer for AWT labels
|
||||
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.Image;
|
||||
import java.awt.Label;
|
||||
import java.awt.Point;
|
||||
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
|
||||
{
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (SwingLabelPeer.this.awtComponent != null)
|
||||
retVal = SwingLabelPeer.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 SwingLabelPeer.this.createImage(w, h);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
swingLabel.setText(label.getText());
|
||||
swingLabel.setHorizontalAlignment(label.getAlignment());
|
||||
swingLabel.setOpaque(true);
|
||||
init(label, swingLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) swingComponent.getJComponent()).setHorizontalAlignment(alignment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 m 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/* SwingPanelPeer.java -- A PanelPeer 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.Panel;
|
||||
import java.awt.peer.LightweightPeer;
|
||||
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 consistend Look.
|
||||
public class SwingPanelPeer
|
||||
extends SwingContainerPeer
|
||||
implements PanelPeer, LightweightPeer
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>SwingPanelPeer</code> for the specified
|
||||
* AWT panel.
|
||||
*
|
||||
* @param panel the AWT panel
|
||||
*/
|
||||
public SwingPanelPeer(Panel panel)
|
||||
{
|
||||
super(panel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
/* SwingTextFieldPeer.java -- A Swing based peer for AWT textfields
|
||||
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.Dimension;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.TextField;
|
||||
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
|
||||
{
|
||||
|
||||
/**
|
||||
* 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 (SwingTextFieldPeer.this.awtComponent != null)
|
||||
retVal = SwingTextFieldPeer.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 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
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 start_pos, 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/* 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.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/* 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.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);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user