This makes the escher peers implement a Graphics2D and make use of the GNU Classpath TrueType implementation. Plus some other fixes and things.
Unfortunately, this will only compile with latest Escher SVN version
(which, right now, doesn't even fully compile, but that will beat me to
release a new Escher in the next two months - or how long it is till the
next classpath release).
2007-04-30 Roman Kennke <[EMAIL PROTECTED]>
* gnu/java/awt/peer/x/XLightweightPeer.java: Removed.
* gnu/java/awt/peer/x/XEventPump.java
(handleEvent): Improved handling of event ids to window mapping.
* gnu/java/awt/peer/x/XFontPeer2.java:
Load font.properties at startup.
(XLineMetrics.glyphVector): New field.
(XLineMetrics.XLineMetrics): Get glyphVector from font delegate.
(XLineMetrics.getHeight): Implemented using glyph vector.
(XLineMetrics.getLeading): Implemented.
(XFontPeer2): Change hardwired font to something more common.
(encodeFont): New methods, encodes a font to the font.properties
format.
(validName): New method. Checks and returns a valid font name.
* gnu/java/awt/peer/x/XGraphics2D.java
(foreground): New field.
(rawSetPixel): Removed.
(rawDrawLine): Draw a segment.
(rawSetForeground): Removed.
(fillScanline): New method.
(fillScanlineAA): New method.
(setPaint): Set the foreground color.
(fillShape): Synchronize super behaviour.
(rawDrawImage): Optimize XImage.
* gnu/java/awt/peer/x/XGraphicsDevice.java
(getDisplay): Improve creation of socket.
(createLocalSocket): New helper method to create a local socket.
* gnu/java/awt/peer/x/XImage.java
(getGraphics): Return an XGraphics2D.
* gnu/java/awt/peer/x/XToolkit.java
(getClasspathFontPeer): Use XFontPeer2.
(createComponent): Removed.
* gnu/java/awt/peer/x/XWindowPeer.java
(getGraphics): Return an XGraphics2D.
(show): Clear the window.
(getFontMetrics): Use XFontPeer2.
/Roman
--
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com * Tel: +49-721-663 968-0
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
Index: gnu/java/awt/peer/x/XEventPump.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XEventPump.java,v
retrieving revision 1.2
diff -u -1 -5 -r1.2 XEventPump.java
--- gnu/java/awt/peer/x/XEventPump.java 18 Jul 2006 10:23:20 -0000 1.2
+++ gnu/java/awt/peer/x/XEventPump.java 30 Apr 2007 20:29:41 -0000
@@ -136,33 +136,38 @@
*/
void registerWindow(gnu.x11.Window xWindow, Window awtWindow)
{
if (XToolkit.DEBUG)
System.err.println("registering window id: " + xWindow.id);
windows.put(new Integer(xWindow.id), awtWindow);
}
void unregisterWindow(gnu.x11.Window xWindow)
{
windows.remove(new Integer(xWindow.id));
}
private void handleEvent(Event xEvent)
{
- Integer key = new Integer(xEvent.window_id());;
- Window awtWindow = (Window) windows.get(key);
+ Integer key = null;
+ Window awtWindow = null;
+ if (xEvent instanceof Input)
+ {
+ key= new Integer(((Input) xEvent).child_window_id);
+ awtWindow = (Window) windows.get(key);
+ }
if (XToolkit.DEBUG)
System.err.println("fetched event: " + xEvent);
switch (xEvent.code())
{
case ButtonPress.CODE:
ButtonPress bp = (ButtonPress) xEvent;
// Create and post the mouse event.
int button = bp.detail();
drag = button;
MouseEvent mp = new MouseEvent(awtWindow, MouseEvent.MOUSE_PRESSED,
System.currentTimeMillis(), 0,
bp.event_x(), bp.event_y(),
1, false, button);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mp);
break;
@@ -183,48 +188,52 @@
mm = new MouseEvent(awtWindow, MouseEvent.MOUSE_MOVED,
System.currentTimeMillis(), 0,
mn.event_x(), mn.event_y(),
1, false);
}
else
{
mm = new MouseEvent(awtWindow, MouseEvent.MOUSE_DRAGGED,
System.currentTimeMillis(), 0,
mn.event_x(), mn.event_y(),
1, false);
}
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mm);
break;
case ConfigureNotify.CODE:
+ key= new Integer(((ConfigureNotify) xEvent).event_window_id);
+ awtWindow = (Window) windows.get(key);
ConfigureNotify c = (ConfigureNotify) xEvent;
if (XToolkit.DEBUG)
System.err.println("resize request for window id: " + key);
// Detect and report size changes.
if (c.width() != awtWindow.getWidth()
|| c.height() != awtWindow.getHeight())
{
if (XToolkit.DEBUG)
System.err.println("Setting size on AWT window: " + c.width()
+ ", " + c.height() + ", " + awtWindow.getWidth()
+ ", " + awtWindow.getHeight());
((XWindowPeer) awtWindow.getPeer()).callback = true;
awtWindow.setSize(c.width(), c.height());
((XWindowPeer) awtWindow.getPeer()).callback = false;
}
break;
case Expose.CODE:
+ key= new Integer(((Expose) xEvent).window_id);
+ awtWindow = (Window) windows.get(key);
Expose exp = (Expose) xEvent;
if (XToolkit.DEBUG)
System.err.println("expose request for window id: " + key);
Rectangle r = new Rectangle(exp.x(), exp.y(), exp.width(),
exp.height());
//System.err.println("expose paint: " + r);
// We need to clear the background of the exposed rectangle.
Graphics g = awtWindow.getGraphics();
g.clearRect(r.x, r.y, r.width, r.height);
g.dispose();
PaintEvent pev = new PaintEvent(awtWindow, PaintEvent.PAINT, r);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(pev);
break;
case KeyPress.CODE:
case KeyRelease.CODE:
Index: gnu/java/awt/peer/x/XFontPeer2.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XFontPeer2.java,v
retrieving revision 1.2
diff -u -1 -5 -r1.2 XFontPeer2.java
--- gnu/java/awt/peer/x/XFontPeer2.java 2 Nov 2006 11:02:28 -0000 1.2
+++ gnu/java/awt/peer/x/XFontPeer2.java 30 Apr 2007 20:29:41 -0000
@@ -30,105 +30,128 @@
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.x;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.LineMetrics;
+import java.awt.font.TextAttribute;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Locale;
import java.util.Map;
+import java.util.Properties;
import gnu.java.awt.font.FontDelegate;
import gnu.java.awt.font.FontFactory;
import gnu.java.awt.peer.ClasspathFontPeer;
public class XFontPeer2
extends ClasspathFontPeer
{
+ /**
+ * The font mapping as specified in the file fonts.properties.
+ */
+ private static Properties fontProperties;
+ static
+ {
+ fontProperties = new Properties();
+ InputStream in = XFontPeer2.class.getResourceAsStream("fonts.properties");
+ try
+ {
+ fontProperties.load(in);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
private class XLineMetrics
extends LineMetrics
{
private Font font;
+ private GlyphVector glyphVector;
// private CharacterIterator characterIterator;
// private int begin;
// private int limit;
private FontRenderContext fontRenderContext;
XLineMetrics(Font f, CharacterIterator ci, int b, int l,
FontRenderContext rc)
{
font = f;
// characterIterator = ci;
// begin = b;
// limit = l;
fontRenderContext = rc;
+ glyphVector = fontDelegate.createGlyphVector(font, fontRenderContext,
+ ci);
}
public float getAscent()
{
return fontDelegate.getAscent(font.getSize(), fontRenderContext.getTransform(),
fontRenderContext.isAntiAliased(),
fontRenderContext.usesFractionalMetrics(), true);
- }
+ }
public int getBaselineIndex()
{
// FIXME: Implement this.
throw new UnsupportedOperationException("Not yet implemented");
}
public float[] getBaselineOffsets()
{
// FIXME: Implement this.
throw new UnsupportedOperationException("Not yet implemented");
}
public float getDescent()
{
return (int) fontDelegate.getDescent(font.getSize(),
new AffineTransform(), false, false,
false);
}
public float getHeight()
{
- // FIXME: Implement this.
- throw new UnsupportedOperationException("Not yet implemented");
+ return (float) glyphVector.getLogicalBounds().getHeight();
}
public float getLeading()
{
- // FIXME: Implement this.
- throw new UnsupportedOperationException("Not yet implemented");
+ return getHeight() - getAscent() - getDescent();
}
public int getNumChars()
{
// FIXME: Implement this.
throw new UnsupportedOperationException("Not yet implemented");
}
public float getStrikethroughOffset()
{
return 0.F;
}
public float getStrikethroughThickness()
{
@@ -196,31 +219,31 @@
GlyphVector gv = fontDelegate.createGlyphVector(getFont(),
new FontRenderContext(new AffineTransform(), false, false),
new StringCharacterIterator(s));
Rectangle2D b = gv.getVisualBounds();
return (int) b.getWidth();
}
}
private FontDelegate fontDelegate;
XFontPeer2(String name, int style, int size)
{
super(name, style, size);
try
{
- File fontfile = new File("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf");
+ File fontfile = new File("/usr/share/fonts/truetype/freefont/FreeSans.ttf");
FileInputStream in = new FileInputStream(fontfile);
FileChannel ch = in.getChannel();
ByteBuffer buffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
fontfile.length());
fontDelegate = FontFactory.createFonts(buffer)[0];
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
XFontPeer2(String name, Map atts)
{
super(name, atts);
@@ -314,16 +337,124 @@
// FIXME: Implement this.
throw new UnsupportedOperationException("Not yet implemented");
}
public LineMetrics getLineMetrics(Font font, CharacterIterator ci, int begin, int limit, FontRenderContext rc)
{
return new XLineMetrics(font, ci, begin, limit, rc);
}
public Rectangle2D getMaxCharBounds(Font font, FontRenderContext rc)
{
// FIXME: Implement this.
throw new UnsupportedOperationException("Not yet implemented");
}
+ /**
+ * Encodes a font name + style + size specification into a X logical font
+ * description (XLFD) as described here:
+ *
+ * http://www.meretrx.com/e93/docs/xlfd.html
+ *
+ * This is implemented to look up the font description in the
+ * fonts.properties of this package.
+ *
+ * @param name the font name
+ * @param atts the text attributes
+ *
+ * @return the encoded font description
+ */
+ static String encodeFont(String name, Map atts)
+ {
+ String family = name;
+ if (family == null || family.equals(""))
+ family = (String) atts.get(TextAttribute.FAMILY);
+ if (family == null)
+ family = "SansSerif";
+
+ int size = 12;
+ Float sizeFl = (Float) atts.get(TextAttribute.SIZE);
+ if (sizeFl != null)
+ size = sizeFl.intValue();
+
+ int style = 0;
+ // Detect italic attribute.
+ Float posture = (Float) atts.get(TextAttribute.POSTURE);
+ if (posture != null && !posture.equals(TextAttribute.POSTURE_REGULAR))
+ style |= Font.ITALIC;
+
+ // Detect bold attribute.
+ Float weight = (Float) atts.get(TextAttribute.WEIGHT);
+ if (weight != null && weight.compareTo(TextAttribute.WEIGHT_REGULAR) > 0)
+ style |= Font.BOLD;
+
+ return encodeFont(name, style, size);
+ }
+
+ /**
+ * Encodes a font name + style + size specification into a X logical font
+ * description (XLFD) as described here:
+ *
+ * http://www.meretrx.com/e93/docs/xlfd.html
+ *
+ * This is implemented to look up the font description in the
+ * fonts.properties of this package.
+ *
+ * @param name the font name
+ * @param style the font style
+ * @param size the font size
+ *
+ * @return the encoded font description
+ */
+ static String encodeFont(String name, int style, int size)
+ {
+ StringBuilder key = new StringBuilder();
+ key.append(validName(name));
+ key.append('.');
+ switch (style)
+ {
+ case Font.BOLD:
+ key.append("bold");
+ break;
+ case Font.ITALIC:
+ key.append("italic");
+ break;
+ case (Font.BOLD | Font.ITALIC):
+ key.append("bolditalic");
+ break;
+ case Font.PLAIN:
+ default:
+ key.append("plain");
+
+ }
+
+ String protoType = fontProperties.getProperty(key.toString());
+ int s = size;
+ return protoType.replaceFirst("%d", String.valueOf(s * 10));
+ }
+
+ /**
+ * Checks the specified font name for a valid font name. If the font name
+ * is not known, then this returns 'sansserif' as fallback.
+ *
+ * @param name the font name to check
+ *
+ * @return a valid font name
+ */
+ static String validName(String name)
+ {
+ String retVal;
+ if (name.equalsIgnoreCase("sansserif")
+ || name.equalsIgnoreCase("serif")
+ || name.equalsIgnoreCase("monospaced")
+ || name.equalsIgnoreCase("dialog")
+ || name.equalsIgnoreCase("dialoginput"))
+ {
+ retVal = name.toLowerCase();
+ }
+ else
+ {
+ retVal = "sansserif";
+ }
+ return retVal;
+ }
}
Index: gnu/java/awt/peer/x/XGraphics2D.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XGraphics2D.java,v
retrieving revision 1.1
diff -u -1 -5 -r1.1 XGraphics2D.java
--- gnu/java/awt/peer/x/XGraphics2D.java 29 Jun 2006 15:15:56 -0000 1.1
+++ gnu/java/awt/peer/x/XGraphics2D.java 30 Apr 2007 20:29:41 -0000
@@ -25,116 +25,94 @@
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.x;
+import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
import java.awt.image.Raster;
+import java.util.HashMap;
import gnu.java.awt.java2d.AbstractGraphics2D;
+import gnu.x11.Colormap;
import gnu.x11.Drawable;
import gnu.x11.GC;
import gnu.x11.image.ZPixmap;
public class XGraphics2D
extends AbstractGraphics2D
{
/**
* The X Drawable to draw on.
*/
private Drawable xdrawable;
/**
* The X graphics context (GC).
*/
private GC xgc;
/**
* Indicates if this graphics has already been disposed.
*/
private boolean disposed;
+ /**
+ * The current foreground color, possibly null.
+ */
+ private Color foreground;
+
XGraphics2D(Drawable d)
{
super();
xdrawable = d;
xgc = new GC(d);
init();
disposed = false;
//setClip(new Rectangle(0, 0, xdrawable.width, xdrawable.height));
}
- /**
- * Draws a pixel in the target coordinate space using the specified color.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- */
- protected void rawSetPixel(int x, int y)
- {
- xdrawable.point(xgc, x, y);
- }
-
-// protected void rawFillPolygon(double[] xpoints, double[] ypoints, int npoints)
-// {
-// Point[] points = new Point[npoints];
-// for (int n = 0; n < npoints; n++)
-// {
-// points[n] = new Point((int) xpoints[n], (int) ypoints[n]);
-// }
-// xdrawable.fill_poly(xgc, points, Drawable.COMPLEX, Drawable.ORIGIN);
-// xdrawable.display.flush();
-// }
-
protected void rawDrawLine(int x0, int y0, int x1, int y1)
{
- xdrawable.line(xgc, x0, y0, x1, y1);
+ xdrawable.segment(xgc, x0, y0, x1, y1);
}
protected void rawFillRect(int x, int y, int w, int h)
{
xdrawable.rectangle(xgc, x, y, w, h, true);
}
- protected void rawSetForeground(java.awt.Color c)
- {
- if (c != null)
- xgc.set_foreground(c.getRGB());
- }
-
- protected void rawSetForeground(int r, int g, int b)
- {
- xgc.set_foreground( r << 16 | g << 8 | b );
- }
-
/**
* Returns the color model of this Graphics object.
*
* @return the color model of this Graphics object
*/
protected ColorModel getColorModel()
{
return Toolkit.getDefaultToolkit().getColorModel();
}
/**
* Returns the color model of the target device.
*
* @return the color model of the target device
*/
@@ -166,79 +144,30 @@
xgc.free();
xdrawable.display.flush();
disposed = true;
}
}
public Graphics create()
{
// super.create() returns a copy created by clone(), so it should
// be a XGraphics2D.
XGraphics2D copy = (XGraphics2D) super.create();
copy.xgc = xgc.copy();
return copy;
}
-// /**
-// * Draws the specified image on the drawable at position (x,y).
-// */
-//
-// public boolean drawImage(Image image, int x, int y, ImageObserver observer)
-// {
-// AffineTransform transform = getTransform();
-// int translateX = (int) transform.getTranslateX();
-// int translateY = (int) transform.getTranslateY();
-// if (image instanceof XImage)
-// {
-// XImage xim = (XImage) image;
-// Pixmap pm = xim.pixmap;
-// xdrawable.copy_area(pm, xgc, 0, 0, pm.width, pm.height,
-// x + translateX, y + translateY);
-// }
-// else if (image instanceof BufferedImage)
-// {
-// BufferedImage bufferedImage = (BufferedImage) image;
-// Raster raster = bufferedImage.getData();
-// int w = bufferedImage.getWidth();
-// int h = bufferedImage.getHeight();
-// // Push data to X server.
-// ZPixmap zPixmap = new ZPixmap(xdrawable.display, w, h,
-// xdrawable.display.default_pixmap_format);
-// System.err.println("data buffer length: " + zPixmap.data.length);
-// int[] pixel = new int[4];
-// for (int tx = 0; tx < w; tx++)
-// {
-// for (int ty = 0; ty < h; ty++)
-// {
-// pixel = raster.getPixel(tx, ty, pixel);
-//// System.err.print("r: " + pixel[0]);
-//// System.err.print(", g: " + pixel[1]);
-//// System.err.println(", b: " + pixel[2]);
-// zPixmap.set_red(tx, ty, pixel[0]);
-// zPixmap.set_green(tx, ty, pixel[1]);
-// zPixmap.set_blue(tx, ty, pixel[2]);
-// }
-// }
-// xdrawable.put_image(xgc, zPixmap, x, y);
-// }
-// else
-// {
-// throw new UnsupportedOperationException("Not yet implemented.");
-// }
-// return true;
-// }
-//
public void setClip(Shape c)
{
super.setClip(c);
if (c instanceof Rectangle)
{
Rectangle r = (Rectangle) c;
AffineTransform t = getTransform();
int translateX = (int) t.getTranslateX();
//System.err.println("translateX: " + translateX);
int translateY = (int) t.getTranslateY();
//System.err.println("translateY: " + translateY);
//System.err.println("clip: " + c);
gnu.x11.Rectangle clip = new gnu.x11.Rectangle(r.x, r.y, r.width,
r.height);
xgc.set_clip_rectangles(translateX, translateY,
@@ -275,21 +204,80 @@
{
pixel = raster.getPixel(tx, ty, pixel);
//System.err.println("tx: " + tx + ", ty: " + ty + ", pixel: " + pixel[0] + ", " + pixel[1] + ", " + pixel[2]);
// System.err.print("r: " + pixel[0]);
// System.err.print(", g: " + pixel[1]);
// System.err.println(", b: " + pixel[2]);
zPixmap.set_red(tx - x, ty - y, pixel[0]);
zPixmap.set_green(tx - x, ty - y, pixel[1]);
zPixmap.set_blue(tx - x, ty - y, pixel[2]);
}
}
xdrawable.put_image(xgc, zPixmap, x, y);
}
}
+ protected void fillScanline(int x0, int x1, int y)
+ {
+ xdrawable.segment(xgc, x0, y, x1, y);
+ }
+
+ protected void fillScanlineAA(int x0, int x1, int y, int alpha)
+ {
+ //System.err.println("fillScanlineAA: " + x0 + ", " + x1 + ", " + y + ", " + alpha);
+ // FIXME: This is for testing only.
+ Color c = getColor();
+ setColor(new Color(255-alpha, 255-alpha, 255-alpha));
+ xdrawable.segment(xgc, x0, y, x1, y);
+ setColor(c);
+ }
protected void init()
{
super.init();
}
+
+ public void setPaint(Paint p)
+ {
+ if (p instanceof Color)
+ {
+ Color c = (Color) p;
+ XToolkit tk = (XToolkit) Toolkit.getDefaultToolkit();
+ HashMap colorMap = tk.colorMap;
+ gnu.x11.Color col = (gnu.x11.Color) colorMap.get(c);
+ if (col == null)
+ {
+ Colormap map = xdrawable.display.default_colormap;
+ col = map.alloc_color (c.getRed() * 256,
+ c.getGreen() * 256,
+ c.getBlue() * 256);
+ colorMap.put(c, col);
+ }
+ xgc.set_foreground(col);
+ foreground = c;
+ }
+ }
+
+ protected void fillShape(Shape s, boolean isFont)
+ {
+ synchronized (xdrawable.display) {
+ super.fillShape(s, isFont);
+ }
+ }
+
+ protected boolean rawDrawImage(Image image, int x, int y, ImageObserver obs)
+ {
+ boolean ret;
+ if (image instanceof XImage)
+ {
+ XImage xImage = (XImage) image;
+ xdrawable.copy_area(xImage.pixmap, xgc, 0, 0, xImage.getWidth(obs),
+ xImage.getHeight(obs), x, y);
+ ret = true;
+ }
+ else
+ {
+ ret = super.rawDrawImage(image, x, y, obs);
+ }
+ return ret;
+ }
}
Index: gnu/java/awt/peer/x/XGraphicsDevice.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XGraphicsDevice.java,v
retrieving revision 1.1
diff -u -1 -5 -r1.1 XGraphicsDevice.java
--- gnu/java/awt/peer/x/XGraphicsDevice.java 29 Jun 2006 15:15:56 -0000 1.1
+++ gnu/java/awt/peer/x/XGraphicsDevice.java 30 Apr 2007 20:29:41 -0000
@@ -26,39 +26,36 @@
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.x;
import gnu.classpath.SystemProperties;
-import gnu.java.net.local.LocalSocket;
-import gnu.java.net.local.LocalSocketAddress;
-import gnu.x11.Connection;
import gnu.x11.Display;
-import java.awt.AWTError;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
-import java.net.SocketException;
+import java.lang.reflect.Constructor;
+import java.net.Socket;
/**
* This class represents an X Display. The actual connection is established
* lazily when it is first needed.
*
* @author Roman Kennke ([EMAIL PROTECTED])
*/
public class XGraphicsDevice
extends GraphicsDevice
{
private XGraphicsConfiguration defaultConfiguration;
/**
* The X display associated with the XGraphicsDevice. This is established
@@ -115,52 +112,72 @@
* @return the X Display associated with this XGraphicsDevice
*/
Display getDisplay()
{
if (display == null)
{
if (displayName.hostname.equals(""))
displayName.hostname = "localhost";
if (XToolkit.DEBUG)
System.err.println("connecting to : " + displayName);
// Try to connect via unix domain sockets when host == localhost.
if ((displayName.hostname.equals("localhost")
|| displayName.hostname.equals(""))
&& SystemProperties.getProperty("gnu.xawt.no_local_sockets") == null)
{
- // TODO: Is this 100% ok?
- String sockPath = "/tmp/.X11-unix/X" + displayName.display_no;
- LocalSocketAddress addr = new LocalSocketAddress(sockPath);
- try
+ Socket socket = createLocalSocket();
+ if (socket != null)
{
- if (XToolkit.DEBUG)
- System.err.println("connecting to local socket: "
- + sockPath);
- LocalSocket socket = new LocalSocket(addr);
display = new Display(socket, "localhost",
displayName.display_no,
displayName.screen_no);
- display.connection.send_mode = Connection.ASYNCHRONOUS;
- if (XToolkit.DEBUG)
- System.err.println("connected to local socket");
}
- catch (SocketException ex)
- {
- AWTError err = new AWTError("could not connect to X server");
- err.initCause(ex);
- throw err;
- }
- }
- else
- {
- display = new Display(displayName);
}
+
+ // The following happens when we are configured to use plain sockets,
+ // when the connection is probably remote or when we couldn't load
+ // the LocalSocket class stuff.
+ if (display == null)
+ display = new Display(displayName);
+
eventPump = new XEventPump(display);
}
return display;
}
XEventPump getEventPump()
{
return eventPump;
}
+
+ /**
+ * Tries to load the LocalSocket class and initiate a connection to the
+ * local X server.
+ */
+ private Socket createLocalSocket()
+ {
+ Socket socket = null;
+ try
+ {
+ // TODO: Is this 100% ok?
+ String sockPath = "/tmp/.X11-unix/X" + displayName.display_no;
+ Class localSocketAddressClass =
+ Class.forName("gnu.java.net.local.LocalSocketAddress");
+ Constructor localSocketAddressConstr =
+ localSocketAddressClass.getConstructor(new Class[]{ String.class });
+ Object addr =
+ localSocketAddressConstr.newInstance(new Object[]{ sockPath });
+ Class localSocketClass =
+ Class.forName("gnu.java.net.local.LocalSocket");
+ Constructor localSocketConstructor =
+ localSocketClass.getConstructor(new Class[]{localSocketAddressClass});
+ Object localSocket =
+ localSocketConstructor.newInstance(new Object[]{ addr });
+ socket = (Socket) localSocket;
+ }
+ catch (Exception ex)
+ {
+ // Whatever goes wrong here, we return null.
+ }
+ return socket;
+ }
}
Index: gnu/java/awt/peer/x/XImage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XImage.java,v
retrieving revision 1.3
diff -u -1 -5 -r1.3 XImage.java
--- gnu/java/awt/peer/x/XImage.java 18 Jul 2006 18:17:10 -0000 1.3
+++ gnu/java/awt/peer/x/XImage.java 30 Apr 2007 20:29:41 -0000
@@ -74,31 +74,31 @@
}
public ImageProducer getSource()
{
// TODO: Implement this.
throw new UnsupportedOperationException("Not yet implemented.");
}
/**
* Creates an XGraphics for drawing on this XImage.
*
* @return an XGraphics for drawing on this XImage
*/
public Graphics getGraphics()
{
- XGraphics g = new XGraphics(pixmap);
+ XGraphics2D g = new XGraphics2D(pixmap);
return g;
}
public Object getProperty(String name, ImageObserver observer)
{
Object val = null;
if (properties != null)
val = properties.get(val);
return val;
}
public void flush()
{
// TODO: Implement this.
throw new UnsupportedOperationException("Not yet implemented.");
Index: gnu/java/awt/peer/x/XLightweightPeer.java
===================================================================
RCS file: gnu/java/awt/peer/x/XLightweightPeer.java
diff -N gnu/java/awt/peer/x/XLightweightPeer.java
--- gnu/java/awt/peer/x/XLightweightPeer.java 29 Jun 2006 15:15:56 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,56 +0,0 @@
-/* XLightweightPeer.java -- A lightweight peer for X
- 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.x;
-
-import java.awt.Component;
-import java.awt.peer.LightweightPeer;
-
-import gnu.java.awt.peer.swing.SwingContainerPeer;
-
-public class XLightweightPeer
- extends SwingContainerPeer
- implements LightweightPeer
-{
-
- XLightweightPeer(Component c)
- {
- super(c);
- init(c, null);
- }
-}
Index: gnu/java/awt/peer/x/XToolkit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XToolkit.java,v
retrieving revision 1.6
diff -u -1 -5 -r1.6 XToolkit.java
--- gnu/java/awt/peer/x/XToolkit.java 20 Jul 2006 13:08:07 -0000 1.6
+++ gnu/java/awt/peer/x/XToolkit.java 30 Apr 2007 20:29:41 -0000
@@ -32,31 +32,30 @@
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.x;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Canvas;
import java.awt.Checkbox;
import java.awt.CheckboxMenuItem;
import java.awt.Choice;
-import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Label;
import java.awt.List;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
@@ -76,31 +75,30 @@
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.peer.ButtonPeer;
import java.awt.peer.CanvasPeer;
import java.awt.peer.CheckboxMenuItemPeer;
import java.awt.peer.CheckboxPeer;
import java.awt.peer.ChoicePeer;
import java.awt.peer.DialogPeer;
import java.awt.peer.FileDialogPeer;
import java.awt.peer.FontPeer;
import java.awt.peer.FramePeer;
import java.awt.peer.LabelPeer;
-import java.awt.peer.LightweightPeer;
import java.awt.peer.ListPeer;
import java.awt.peer.MenuBarPeer;
import java.awt.peer.MenuItemPeer;
import java.awt.peer.MenuPeer;
import java.awt.peer.PanelPeer;
import java.awt.peer.PopupMenuPeer;
import java.awt.peer.RobotPeer;
import java.awt.peer.ScrollPanePeer;
import java.awt.peer.ScrollbarPeer;
import java.awt.peer.TextAreaPeer;
import java.awt.peer.TextFieldPeer;
import java.awt.peer.WindowPeer;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@@ -167,40 +165,40 @@
public GraphicsEnvironment getLocalGraphicsEnvironment()
{
return new XGraphicsEnvironment();
}
/**
* Returns the font peer for a font with the specified name and attributes.
*
* @param name the font name
* @param attrs the font attributes
*
* @return the font peer for a font with the specified name and attributes
*/
public ClasspathFontPeer getClasspathFontPeer(String name, Map attrs)
{
- String canonical = XFontPeer.encodeFont(name, attrs);
+ String canonical = XFontPeer2.encodeFont(name, attrs);
ClasspathFontPeer font;
if (!fontCache.containsKey(canonical))
{
String graphics2d =
SystemProperties.getProperty("gnu.xawt.graphics2d");
- if (graphics2d != null && graphics2d.equals("gl"))
+ //if (graphics2d != null && graphics2d.equals("gl"))
font = new XFontPeer2(name, attrs);
- else
- font = new XFontPeer(name, attrs);
+// else
+// font = new XFontPeer(name, attrs);
fontCache.put(canonical, font);
}
else
{
font = (ClasspathFontPeer) fontCache.get(canonical);
}
return font;
}
public Font createFont(int format, InputStream stream)
{
return null;
}
public RobotPeer createRobot(GraphicsDevice screen) throws AWTException
@@ -589,20 +587,16 @@
throw new UnsupportedOperationException("Not yet implemented.");
}
/**
* Helper method to quickly fetch the default device (X Display).
*
* @return the default XGraphicsDevice
*/
static XGraphicsDevice getDefaultDevice()
{
XGraphicsEnvironment env = (XGraphicsEnvironment)
XGraphicsEnvironment.getLocalGraphicsEnvironment();
return (XGraphicsDevice) env.getDefaultScreenDevice();
}
- protected LightweightPeer createComponent(Component c)
- {
- return new XLightweightPeer(c);
- }
}
Index: gnu/java/awt/peer/x/XWindowPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XWindowPeer.java,v
retrieving revision 1.2
diff -u -1 -5 -r1.2 XWindowPeer.java
--- gnu/java/awt/peer/x/XWindowPeer.java 18 Jul 2006 10:23:20 -0000 1.2
+++ gnu/java/awt/peer/x/XWindowPeer.java 30 Apr 2007 20:29:41 -0000
@@ -123,31 +123,31 @@
return false;
}
public Point getLocationOnScreen()
{
return new Point(xwindow.x, xwindow.y);
}
/**
* Returns a XGraphics suitable for drawing on this frame.
*
* @return a XGraphics suitable for drawing on this frame
*/
public Graphics getGraphics()
{
- return new XGraphics(xwindow);
+ return new XGraphics2D(xwindow);
}
public Image createImage(int w, int h)
{
return new XImage(w, h);
}
/**
* Makes the component visible. This is called by [EMAIL PROTECTED] Component#show()}.
*
* This is implemented to call setVisible(true) on the Swing component.
*/
public void show()
{
// // Prevent ResizeRedirect events.
@@ -156,30 +156,33 @@
// atts.set_override_redirect(true);
// xwindow.change_attributes(atts);
// Prevent ResizeRedirect events.
//xwindow.select_input(Event.NO_EVENT_MASK);
//xwindow.select_input(noResizeRedirectSelect);
xwindow.map();
EventQueue eq = XToolkit.getDefaultToolkit().getSystemEventQueue();
java.awt.Window w = (java.awt.Window) super.awtComponent;
eq.postEvent(new WindowEvent(w, WindowEvent.WINDOW_OPENED));
eq.postEvent(new PaintEvent(w, PaintEvent.PAINT,
new Rectangle(0, 0, w.getWidth(),
w.getHeight())));
+ Graphics g = getGraphics();
+ g.clearRect(0, 0, awtComponent.getWidth(), awtComponent.getHeight());
+ g.dispose();
// // Reset input selection.
// atts.set_override_redirect(false);
// xwindow.change_attributes(atts);
}
/**
* Makes the component invisible. This is called from
* [EMAIL PROTECTED] Component#hide()}.
*
* This is implemented to call setVisible(false) on the Swing component.
*/
public void hide()
{
xwindow.unmap();
}
@@ -228,28 +231,28 @@
// i.right = wmSize.width() - g.width() - i.left ;
// i.top = wmSize.y() - g.y();
// i.bottom = wmSize.height() - g.height() - i.top;
// }
// System.err.println("insets: " + i);
return i;
}
/**
* Returns the font metrics for the specified font.
*
* @return the font metrics for the specified font
*/
public FontMetrics getFontMetrics(Font font)
{
- XFontPeer fontPeer = (XFontPeer) font.getPeer();
+ XFontPeer2 fontPeer = (XFontPeer2) font.getPeer();
return fontPeer.getFontMetrics(font);
}
/**
* Unregisters the window in the event pump when it is closed.
*/
protected void finalize()
{
XGraphicsDevice dev = XToolkit.getDefaultDevice();
dev.getEventPump().unregisterWindow(xwindow);
}
}
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
