diff options
Diffstat (limited to 'libjava/gnu/java/awt/peer')
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GdkGraphics.java | 11 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java | 337 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java | 87 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java | 9 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java | 10 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java | 4 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java | 13 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java | 12 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java | 15 | ||||
-rw-r--r-- | libjava/gnu/java/awt/peer/gtk/GtkToolkit.java | 29 |
10 files changed, 476 insertions, 51 deletions
diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java index 9012da2..d36ac2d 100644 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java +++ b/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java @@ -91,7 +91,7 @@ public class GdkGraphics extends Graphics this.component = component; int rgb[] = initState (component); color = new Color (rgb[0], rgb[1], rgb[2]); - font = new Font ("Dialog", Font.PLAIN, 10); + font = component.awtComponent.getFont(); Dimension d = component.awtComponent.getSize (); clip = new Rectangle (0, 0, d.width, d.height); } @@ -212,10 +212,10 @@ public class GdkGraphics extends Graphics native public void drawRect(int x, int y, int width, int height); native public void fillRect (int x, int y, int width, int height); - native void drawString (String str, int x, int y, String fname, int size); + native void drawString (String str, int x, int y, String fname, int style, int size); public void drawString (String str, int x, int y) { - drawString (str, x, y, font.getName(), font.getSize()); + drawString (str, x, y, font.getName(), font.getStyle(), font.getSize()); } public void drawString (AttributedCharacterIterator ci, int x, int y) @@ -287,7 +287,10 @@ public class GdkGraphics extends Graphics public void setColor (Color c) { - color = c; + if (c == null) + color = new Color (0, 0, 0); + else + color = c; if (xorColor == null) /* paint mode */ setFGColor (color.getRed (), color.getGreen (), color.getBlue ()); diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java index e985696..8bae336 100644 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -84,6 +84,7 @@ public class GdkGraphics2D extends Graphics2D private GtkComponentPeer component; private Font font; private RenderingHints hints; + private BufferedImage bimage; private Stack stateStack; @@ -91,6 +92,8 @@ public class GdkGraphics2D extends Graphics2D native private void initState (int width, int height); native private void copyState (GdkGraphics2D g); native public void dispose (); + native private int[] getImagePixels(); + native private void cairoSurfaceSetFilter(int filter); public void finalize () { @@ -179,6 +182,28 @@ public class GdkGraphics2D extends Graphics2D stateStack = new Stack (); } + GdkGraphics2D (BufferedImage bimage) + { + + this.bimage = bimage; + initState (bimage.getWidth(), bimage.getHeight()); + + setColor(Color.black); + setBackground (Color.black); + setPaint (getColor()); + setFont (new Font("SansSerif", Font.PLAIN, 12)); + setTransform (new AffineTransform ()); + setStroke (new BasicStroke ()); + setRenderingHints (getDefaultHints()); + + stateStack = new Stack(); + + // draw current buffered image to the pixmap associated + // with it. + + drawImage (bimage, new AffineTransform (1,0,0,1,0,0), null); + } + //////////////////////////////////// ////// Native Drawing Methods ////// @@ -364,6 +389,58 @@ public class GdkGraphics2D extends Graphics2D } + private void updateBufferedImage() + { + int[] pixels = getImagePixels(); + updateImagePixels(pixels); + } + + + private boolean isBufferedImageGraphics () + { + + if (bimage != null) + return true; + else + return false; + } + + private void updateImagePixels (int[] pixels) + { + + // This function can only be used if + // this graphics object is used to draw into + // buffered image + + if (! isBufferedImageGraphics ()) + return; + + WritableRaster raster = bimage.getRaster(); + DataBuffer db = raster.getDataBuffer (); + + // update pixels in the bufferedImage + + if (raster.getSampleModel ().getDataType () == DataBuffer.TYPE_INT + && db instanceof DataBufferInt + && db.getNumBanks () == 1) + { + + // single bank, ARGB-ints buffer in sRGB space + DataBufferInt dbi = (DataBufferInt) raster.getDataBuffer (); + + for (int i=0; i < pixels.length; i++) + dbi.setElem(i, pixels[i]); + + } + else + { + bimage.getRaster().setPixels (0, 0, raster.getWidth (), + raster.getHeight (), pixels); + } + } + + + ////////////////////////////////////////////////// ////// Implementation of Graphics2D Methods ////// ////////////////////////////////////////////////// @@ -401,6 +478,10 @@ public class GdkGraphics2D extends Graphics2D translate (-0.5,-0.5); stateRestore (); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + } public void fill (Shape s) @@ -416,6 +497,10 @@ public class GdkGraphics2D extends Graphics2D walkPath (s.getPathIterator (null)); cairoFill (); stateRestore (); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + } public void clip (Shape s) @@ -475,11 +560,21 @@ public class GdkGraphics2D extends Graphics2D { TexturePaint tp = (TexturePaint) paint; BufferedImage img = tp.getImage (); - int pixels[] = img.getRGB(0, 0, img.getWidth (), - img.getHeight (), null, - 0, img.getWidth ()); - setTexturePixels (pixels, img.getWidth (), - img.getHeight (), img.getWidth ()); + + // map the image to the anchor rectangle + + int width = (int) tp.getAnchorRect ().getWidth (); + int height = (int) tp.getAnchorRect ().getHeight (); + + double scaleX = width / (double) img.getWidth (); + double scaleY = width / (double) img.getHeight (); + + AffineTransform at = new AffineTransform (scaleX, 0, 0, scaleY, 0, 0); + AffineTransformOp op = new AffineTransformOp (at, getRenderingHints()); + BufferedImage texture = op.filter(img, null); + int pixels[] = texture.getRGB (0, 0, width, height, null, 0, width); + setTexturePixels (pixels, width, height, width); + } else if (paint instanceof GradientPaint) { @@ -518,6 +613,26 @@ public class GdkGraphics2D extends Graphics2D else transform.concatenate (tx); setTransform (transform); + if (clip != null) + { + // FIXME: this should actuall try to transform the shape + // rather than degrade to bounds. + Rectangle2D r = clip.getBounds2D(); + double[] coords = new double[] { r.getX(), r.getY(), + r.getX() + r.getWidth(), + r.getY() + r.getHeight() }; + try + { + tx.createInverse().transform(coords, 0, coords, 0, 2); + r.setRect(coords[0], coords[1], + coords[2] - coords[0], + coords[3] - coords[1]); + clip = r; + } + catch (java.awt.geom.NoninvertibleTransformException e) + { + } + } } public void rotate(double theta) @@ -645,19 +760,29 @@ public class GdkGraphics2D extends Graphics2D public void setClip (int x, int y, int width, int height) { - cairoNewPath (); - cairoRectangle (x, y, width, height); - cairoClosePath (); - cairoClip (); - clip = new Rectangle2D.Double ((double)x, (double)y, - (double)width, (double)height); + clip = new Rectangle2D.Double ((double)x, (double)y, + (double)width, (double)height); + setClip(clip); } - + public void setClip (Shape s) { - clip (s); + if (s != null) + { + cairoNewPath (); + if (s instanceof Rectangle2D) + { + Rectangle2D r = (Rectangle2D)s; + cairoRectangle (r.getX (), r.getY (), + r.getWidth (), r.getHeight ()); + } + else + walkPath (s.getPathIterator (null)); + cairoClosePath (); + cairoClip (); + } } - + public void draw3DRect(int x, int y, int width, int height, boolean raised) { @@ -708,6 +833,10 @@ public class GdkGraphics2D extends Graphics2D cairoStroke (); stateRestore (); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + } public void fill3DRect(int x, int y, int width, @@ -734,6 +863,10 @@ public class GdkGraphics2D extends Graphics2D cairoClosePath (); cairoFill (); stateRestore (); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + } @@ -759,6 +892,10 @@ public class GdkGraphics2D extends Graphics2D cairoClosePath (); cairoFill (); stateRestore (); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + } public void setBackground(Color c) @@ -849,7 +986,7 @@ public class GdkGraphics2D extends Graphics2D { i2u[0] = 1; i2u[1] = 0; i2u[2] = 0; i2u[3] = 1; - i2u[2] = 0; i2u[3] = 0; + i2u[4] = 0; i2u[5] = 0; } int pixels[] = null; @@ -879,6 +1016,10 @@ public class GdkGraphics2D extends Graphics2D translate (x, y); drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth (), i2u); stateRestore (); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + return true; } @@ -908,22 +1049,49 @@ public class GdkGraphics2D extends Graphics2D // we are being asked to flush a double buffer from Gdk GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics (); gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY()); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + return true; } else { - if (img instanceof BufferedImage) - { - // draw an image which has actually been loaded into memory fully - BufferedImage b = (BufferedImage) img; - return drawRaster (b.getColorModel (), b.getData (), xform); - } - else - { - // begin progressive loading in a separate thread - new PainterThread (this, img, xform); - return false; + + // In this case, xform is an AffineTransform that transforms bounding + // box of the specified image from image space to user space. However + // when we pass this transform to cairo, cairo will use this transform + // to map "user coordinates" to "pixel" coordinates, which is the + // other way around. Therefore to get the "user -> pixel" transform + // that cairo wants from "image -> user" transform that we currently + // have, we will need to invert the transformation matrix. + + AffineTransform invertedXform = new AffineTransform(); + + try + { + invertedXform = xform.createInverse(); + if (img instanceof BufferedImage) + { + // draw an image which has actually been loaded + // into memory fully + BufferedImage b = (BufferedImage) img; + return drawRaster (b.getColorModel (), + b.getData (), + invertedXform); + } + else + { + // begin progressive loading in a separate thread + new PainterThread (this, img, invertedXform); + return false; + } } + catch (NoninvertibleTransformException e) + { + throw new ImagingOpException("Unable to invert transform " + + xform.toString()); + } } } @@ -1061,6 +1229,28 @@ public class GdkGraphics2D extends Graphics2D Object hintValue) { hints.put (hintKey, hintValue); + + if (hintKey.equals(RenderingHints.KEY_INTERPOLATION) + || hintKey.equals(RenderingHints.KEY_ALPHA_INTERPOLATION)) + { + + if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) + cairoSurfaceSetFilter(0); + + else if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) + cairoSurfaceSetFilter(1); + + else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) + cairoSurfaceSetFilter(2); + + else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) + cairoSurfaceSetFilter(3); + + else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) + cairoSurfaceSetFilter(4); + + } + } public Object getRenderingHint(RenderingHints.Key hintKey) @@ -1072,6 +1262,27 @@ public class GdkGraphics2D extends Graphics2D { this.hints = new RenderingHints (getDefaultHints ()); this.hints.add (new RenderingHints (hints)); + + if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) + { + if(hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) + cairoSurfaceSetFilter(0); + + else if(hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) + cairoSurfaceSetFilter(1); + } + + if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) + { + if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) + cairoSurfaceSetFilter(2); + + else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) + cairoSurfaceSetFilter(3); + + else if(hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) + cairoSurfaceSetFilter(4); + } } public void addRenderingHints(Map hints) @@ -1104,6 +1315,10 @@ public class GdkGraphics2D extends Graphics2D int codes[] = g.getGlyphCodes (0, nglyphs, (int []) null); float posns[] = g.getGlyphPositions (0, nglyphs, (float []) null); cairoShowGlyphs (codes, posns); + + if (isBufferedImageGraphics ()) + updateBufferedImage(); + stateRestore (); } @@ -1124,33 +1339,89 @@ public class GdkGraphics2D extends Graphics2D public boolean drawImage (Image img, int x, int y, Color bgcolor, ImageObserver observer) { - throw new java.lang.UnsupportedOperationException (); + return drawImage (img, x, y, img.getWidth (observer), + img.getHeight (observer), bgcolor, observer); } public boolean drawImage (Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { - throw new java.lang.UnsupportedOperationException (); + + // FIXME: change all the transparent pixels in the image to + // bgcolor. + + return drawImage (img, x, y, width, height, observer); } public boolean drawImage (Image img, int x, int y, int width, int height, ImageObserver observer) { - throw new java.lang.UnsupportedOperationException (); + + double scaleX = width / (double) img.getWidth (observer); + double scaleY = height / (double) img.getHeight (observer); + + return drawImage (img, + new AffineTransform(scaleX, 0f, 0f, scaleY, x, y), + observer); + } public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { - throw new java.lang.UnsupportedOperationException (); + + // FIXME: change all transparent pixels in the image to + // bgcolor + + return drawImage (img, dx1, dy1, dx2, dy2, + sx1, sy1, sx2, sy2, observer); } public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { - throw new java.lang.UnsupportedOperationException (); + + Image subImage; + + int sourceWidth = sx2 - sx1; + int sourceHeight = sy2 - sy1; + + int destWidth = dx2 - dx1; + int destHeight = dy2 - dy1; + + double scaleX = destWidth / (double) sourceWidth; + double scaleY = destHeight / (double) sourceHeight; + + // Get the subimage of the source enclosed in the + // rectangle specified by sx1, sy1, sx2, sy2 + + if (img instanceof BufferedImage) + { + + BufferedImage b = (BufferedImage) img; + subImage = b.getSubimage(sx1,sy1,sx2,sy2); + } + else + { + + // FIXME: This code currently doesn't work. Null Pointer + // exception is thrown in this case. This happens + // because img.getSource() always returns null, since source gets + // never initialized when it is created with the help of + // createImage(int width, int height). + + CropImageFilter filter = new CropImageFilter(sx1,sx2,sx2,sy2); + FilteredImageSource src = new FilteredImageSource(img.getSource(), + filter); + + subImage = Toolkit.getDefaultToolkit().createImage(src); + } + + return drawImage(subImage, new AffineTransform(scaleX, 0, 0, + scaleY, dx1, dy1), + observer); } public void drawOval(int x, int y, int width, int height) @@ -1251,7 +1522,9 @@ public class GdkGraphics2D extends Graphics2D public String toString() { - throw new java.lang.UnsupportedOperationException (); + return getClass ().getName () + + "[font=" + font.toString () + + ",color=" + fg.toString () + "]"; } } diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java new file mode 100644 index 0000000..dbcd2d1 --- /dev/null +++ b/libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java @@ -0,0 +1,87 @@ +/* GdkGraphicsEnvironment.java -- information about the graphics environment + Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.gtk; + +import java.awt.*; +import java.awt.GraphicsEnvironment; +import java.awt.image.BufferedImage; +import java.util.Locale; + + +public class GdkGraphicsEnvironment extends GraphicsEnvironment +{ + + public GdkGraphicsEnvironment () + { + super(); + } + + public GraphicsDevice[] getScreenDevices () + { + throw new java.lang.UnsupportedOperationException (); + } + + public GraphicsDevice getDefaultScreenDevice () + { + throw new java.lang.UnsupportedOperationException (); + } + + public Graphics2D createGraphics (BufferedImage image) + { + return new GdkGraphics2D (image); + } + + public Font[] getAllFonts () + { + throw new java.lang.UnsupportedOperationException (); + } + + public String[] getAvailableFontFamilyNames () + { + throw new java.lang.UnsupportedOperationException (); + } + + public String[] getAvailableFontFamilyNames (Locale l) + { + throw new java.lang.UnsupportedOperationException (); + } + + +} // class GdkGraphicsEnvironment + diff --git a/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java index cf7260c..86c7c37 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java @@ -42,6 +42,7 @@ import java.awt.AWTEvent; import java.awt.Button; import java.awt.Component; import java.awt.Font; +import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; import java.awt.peer.ButtonPeer; @@ -69,11 +70,15 @@ public class GtkButtonPeer extends GtkComponentPeer public void handleEvent (AWTEvent e) { - if (e.getID () == MouseEvent.MOUSE_CLICKED && isEnabled ()) + if (e.getID () == MouseEvent.MOUSE_RELEASED && isEnabled ()) { MouseEvent me = (MouseEvent) e; + Point p = me.getPoint(); + p.translate(((Component) me.getSource()).getX(), + ((Component) me.getSource()).getY()); if (!me.isConsumed () - && (me.getModifiers () & MouseEvent.BUTTON1_MASK) != 0) + && (me.getModifiers () & MouseEvent.BUTTON1_MASK) != 0 + && awtComponent.getBounds().contains(p)) postActionEvent (((Button)awtComponent).getActionCommand (), me.getModifiers ()); } diff --git a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java index fba8c8f..2cff9cc 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java @@ -41,6 +41,7 @@ package gnu.java.awt.peer.gtk; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Component; +import java.awt.Font; import java.awt.peer.CheckboxPeer; public class GtkCheckboxPeer extends GtkComponentPeer @@ -55,6 +56,8 @@ public class GtkCheckboxPeer extends GtkComponentPeer boolean state); public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group); public native void connectSignals (); + public native void gtkSetFont (String name, int style, int size); + public native void gtkSetLabel (String label); public GtkCheckboxPeer (Checkbox c) { @@ -81,7 +84,12 @@ public class GtkCheckboxPeer extends GtkComponentPeer public void setLabel (String label) { - set ("label", label); + gtkSetLabel (label); + } + + public void setFont (Font f) + { + gtkSetFont(f.getName(), f.getStyle(), f.getSize()); } public void setCheckboxGroup (CheckboxGroup group) diff --git a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java index 4b29bcc..1a9d963 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java @@ -91,6 +91,7 @@ public class GtkComponentPeer extends GtkGenericPeer native void gtkWidgetSetCursor (int type); native void gtkWidgetSetBackground (int red, int green, int blue); native void gtkWidgetSetForeground (int red, int green, int blue); + native void gtkSetFont (String name, int style, int size); native void gtkWidgetQueueDrawArea(int x, int y, int width, int height); native void addExposeFilter(); native void removeExposeFilter(); @@ -234,7 +235,7 @@ public class GtkComponentPeer extends GtkGenericPeer // Some peers like GtkFileDialogPeer are repainted by Gtk itself if (g == null) break; - + g.setClip (((PaintEvent)event).getUpdateRect()); if (id == PaintEvent.PAINT) @@ -403,6 +404,7 @@ public class GtkComponentPeer extends GtkGenericPeer // FIXME: This should really affect the widget tree below me. // Currently this is only handled if the call is made directly on // a text widget, which implements setFont() itself. + gtkSetFont(f.getName(), f.getStyle(), f.getSize()); } public void setForeground (Color c) diff --git a/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java index 361dea7..32ac02f 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java @@ -42,6 +42,7 @@ import java.awt.AWTEvent; import java.awt.Color; import java.awt.Component; import java.awt.Container; +import java.awt.Font; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.PaintEvent; @@ -92,6 +93,18 @@ public class GtkContainerPeer extends GtkComponentPeer awtComponent.validate (); } + public void setFont(Font f) + { + super.setFont(f); + Component[] components = ((Container) awtComponent).getComponents(); + for (int i = 0; i < components.length; i++) + { + GtkComponentPeer peer = (GtkComponentPeer) components[i].getPeer(); + if (peer != null && ! peer.awtComponent.isFontSet()) + peer.setFont(f); + } + } + public Graphics getGraphics () { if (GtkToolkit.useGraphics2D ()) diff --git a/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java index 8c1ec8f..1ab7bc1 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java @@ -62,11 +62,17 @@ public class GtkFontPeer extends ClasspathFontPeer } } - final private String Xname; // uses %d for font size. + final private String Xname; public GtkFontPeer (String name, int style) { - super(name, style, 12 /* kludge */); + // All fonts get a default size of 12 if size is not specified. + this(name, style, 12); + } + + public GtkFontPeer (String name, int style, int size) + { + super(name, style, size); if (bundle != null) Xname = bundle.getString (name.toLowerCase () + "." + style); @@ -90,7 +96,7 @@ public class GtkFontPeer extends ClasspathFontPeer else spacing = "c"; - Xname = "-*-*-" + weight + "-" + slant + "-normal-*-%d-*-*-*-" + spacing + "-*-*-*"; + Xname = "-*-*-" + weight + "-" + slant + "-normal-*-*-" + size + "-*-*-" + spacing + "-*-*-*"; } } diff --git a/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java index b0a9ff7..cf39372 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java @@ -39,28 +39,35 @@ exception statement from your version. */ package gnu.java.awt.peer.gtk; import java.awt.Component; +import java.awt.Font; import java.awt.Label; import java.awt.peer.LabelPeer; public class GtkLabelPeer extends GtkComponentPeer implements LabelPeer { + native void create (String text, float alignment); + native void gtkSetFont(String name, int style, int size); + native void nativeSetAlignment (float alignment); + + native public void setText (String text); + void create () { Label label = (Label) awtComponent; create (label.getText (), getGtkAlignment (label.getAlignment ())); } - native void create (String text, float alignment); - public GtkLabelPeer (Label l) { super (l); } - native public void setText (String text); + public void setFont (Font f) + { + gtkSetFont(f.getName(), f.getStyle(), f.getSize()); + } - native void nativeSetAlignment (float alignment); public void setAlignment (int alignment) { nativeSetAlignment (getGtkAlignment (alignment)); diff --git a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java index 844fa68..1d961f2 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -47,6 +47,7 @@ import java.awt.im.InputMethodHighlight; import java.awt.image.ColorModel; import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; +import java.awt.GraphicsEnvironment; import java.awt.peer.*; import java.net.URL; import java.util.Hashtable; @@ -366,10 +367,18 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit * @deprecated part of the older "logical font" system in earlier AWT * implementations. Our newer Font class uses getClasspathFontPeer. */ - protected FontPeer getFontPeer (String name, int style) + protected FontPeer getFontPeer (String name, int style) { + // All fonts get a default size of 12 if size is not specified. + return getFontPeer(name, style, 12); + } + + /** + * Private method that allows size to be set at initialization time. + */ + private FontPeer getFontPeer (String name, int style, int size) { try { - GtkFontPeer fp = new GtkFontPeer (name, style); + GtkFontPeer fp = new GtkFontPeer (name, style, size); return fp; } catch (MissingResourceException ex) { return null; @@ -388,7 +397,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit return new GdkClasspathFontPeer (name, attrs); else { + // Default values + int size = 12; int style = Font.PLAIN; + if (name == null) + name = "Default"; if (attrs.containsKey (TextAttribute.WEIGHT)) { @@ -404,7 +417,13 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit style += Font.ITALIC; } - return (ClasspathFontPeer) this.getFontPeer (name, style); + if (attrs.containsKey (TextAttribute.SIZE)) + { + Float fsize = (Float) attrs.get (TextAttribute.SIZE); + size = fsize.intValue(); + } + + return (ClasspathFontPeer) this.getFontPeer (name, style, size); } } @@ -431,7 +450,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit public GraphicsEnvironment getLocalGraphicsEnvironment() { - throw new java.lang.UnsupportedOperationException (); + GraphicsEnvironment ge; + ge = new GdkGraphicsEnvironment (); + return ge; } public Font createFont(int format, java.io.InputStream stream) |