summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/awt/peer
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer')
-rw-r--r--libjava/classpath/gnu/java/awt/peer/ClasspathDesktopPeer.java301
-rw-r--r--libjava/classpath/gnu/java/awt/peer/ClasspathFontPeer.java32
-rw-r--r--libjava/classpath/gnu/java/awt/peer/GnomeDesktopPeer.java153
-rw-r--r--libjava/classpath/gnu/java/awt/peer/KDEDesktopPeer.java135
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/AsyncImage.java10
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java116
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java527
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java299
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java123
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java108
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java157
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GThreadMutex.java109
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java303
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java40
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java16
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java137
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java4
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java19
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java26
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboard.java202
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboardNotifier.java85
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java70
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java20
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java20
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java138
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkImageConsumer.java74
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java6
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java26
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkMainThread.java14
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java16
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java6
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java8
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java6
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java6
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java14
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkSelection.java642
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java12
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java4
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java114
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java60
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java20
-rw-r--r--libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java49
42 files changed, 2411 insertions, 1816 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/ClasspathDesktopPeer.java b/libjava/classpath/gnu/java/awt/peer/ClasspathDesktopPeer.java
new file mode 100644
index 00000000000..bef42dcea34
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/ClasspathDesktopPeer.java
@@ -0,0 +1,301 @@
+/* ClasspathDesktopPeer.java -- Offers a concrete implementation for DesktopPeer
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+package gnu.java.awt.peer;
+
+import java.awt.AWTPermission;
+import java.awt.Desktop.Action;
+import java.awt.peer.DesktopPeer;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.net.URI;
+
+import java.util.prefs.Preferences;
+
+/**
+ * Offers a common implementation for the Desktop peers, that enables
+ * access to default system application within java processes.
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class ClasspathDesktopPeer
+ implements DesktopPeer
+{
+ /** This is the fallback browser, if no desktop was detected. */
+ protected static final String _DEFAULT_BROWSER = "firefox";
+
+ /** gnu.java.awt.peer.Desktop.html.command */
+ protected static final String _BROWSE = "html";
+
+ /** gnu.java.awt.peer.Desktop.mail.command */
+ protected static final String _MAIL = "mail";
+
+ /** gnu.java.awt.peer.Desktop.edit.command */
+ protected static final String _EDIT = "edit";
+
+ /** gnu.java.awt.peer.Desktop.print.command */
+ protected static final String _PRINT = "print";
+
+ /** gnu.java.awt.peer.Desktop.open.command */
+ protected static final String _OPEN = "open";
+
+ /** */
+ protected static final KDEDesktopPeer kde = new KDEDesktopPeer();
+
+ /** */
+ protected static final GnomeDesktopPeer gnome = new GnomeDesktopPeer();
+
+ /** */
+ protected static final ClasspathDesktopPeer classpath =
+ new ClasspathDesktopPeer();
+
+ /**
+ * Preference subsystem. Packagers and users can override the default
+ * behaviour of this class via preferences and system properties.
+ */
+ protected Preferences prefs =
+ Preferences.userNodeForPackage(ClasspathDesktopPeer.class).node("Desktop");
+
+ /**
+ * @param target
+ */
+ protected ClasspathDesktopPeer()
+ {
+ /* nothing to do */
+ }
+
+ public boolean isSupported(Action action)
+ {
+ String check = null;
+
+ switch(action)
+ {
+ case BROWSE:
+ check = _BROWSE;
+ break;
+
+ case MAIL:
+ check = _MAIL;
+ break;
+
+ case EDIT:
+ check = _EDIT;
+ break;
+
+ case PRINT:
+ check = _PRINT;
+ break;
+
+ case OPEN: default:
+ check = _OPEN;
+ break;
+ }
+
+ return this.supportCommand(check);
+ }
+
+ public void browse(URI url) throws IOException
+ {
+ checkPermissions();
+
+ String browser = getCommand(_BROWSE);
+
+ if (browser == null)
+ throw new UnsupportedOperationException();
+
+ browser = browser + " " + url.toString();
+
+ Runtime.getRuntime().exec(browser);
+ }
+
+ public void edit(File file) throws IOException
+ {
+ checkPermissions(file, false);
+
+ String edit = getCommand(_EDIT);
+
+ if (edit == null)
+ throw new UnsupportedOperationException();
+
+ edit = edit + " " + file.getAbsolutePath();
+ Runtime.getRuntime().exec(edit);
+ }
+
+ public void mail(URI mailtoURL) throws IOException
+ {
+ checkPermissions();
+
+ String scheme = mailtoURL.getScheme();
+ if (scheme == null || !scheme.equalsIgnoreCase("mailto"))
+ throw new IllegalArgumentException("URI Scheme not of type mailto");
+
+ String mail = getCommand(_MAIL);
+
+ if (mail == null)
+ throw new UnsupportedOperationException();
+
+ mail = mail + " " + mailtoURL.toString();
+
+ Runtime.getRuntime().exec(mail);
+ }
+
+ public void mail() throws IOException
+ {
+ checkPermissions();
+
+ String mail = getCommand(_MAIL);
+
+ if (mail == null)
+ throw new UnsupportedOperationException();
+
+ Runtime.getRuntime().exec(mail);
+ }
+
+ public void open(File file) throws IOException
+ {
+ checkPermissions(file, true);
+
+ String open = getCommand(_OPEN);
+
+ if (open == null)
+ throw new UnsupportedOperationException();
+
+ open = open + " " + file.getAbsolutePath();
+ Runtime.getRuntime().exec(open);
+ }
+
+ public void print(File file) throws IOException
+ {
+ checkPrintPermissions(file);
+
+ String print = getCommand(_PRINT);
+
+ if (print == null)
+ throw new UnsupportedOperationException();
+
+ print = print + " " + file.getAbsolutePath();
+ Runtime.getRuntime().exec(print);
+ }
+
+ protected String getCommand(String action)
+ {
+ // check if a system property exist
+ String command =
+ System.getProperty("gnu.java.awt.peer.Desktop." + action + ".command");
+
+ // otherwise, get it from preferences, if any
+ if (command == null)
+ {
+ command = prefs.node(action).get("command", null);
+ }
+
+ return command;
+ }
+
+ /**
+ * Note: Checks for AWTPermission("showWindowWithoutWarningBanner") only.
+ */
+ protected void checkPermissions()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(new AWTPermission("showWindowWithoutWarningBanner"));
+ }
+ }
+
+ /**
+ * Calls checkPermissions() and checks for SecurityManager.checkRead()
+ * and, if readOnly is false, for SecurityManager.checkWrite()
+ */
+ protected void checkPermissions(File file, boolean readOnly)
+ {
+ checkPermissions();
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkRead(file.toString());
+ if (!readOnly) sm.checkWrite(file.toString());
+ }
+ }
+
+ /**
+ * Calls checkPermissions(file, true) and checks for
+ * SecurityManager.checkPrintJobAccess()
+ */
+ protected void checkPrintPermissions(File file)
+ {
+ checkPermissions(file, true);
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPrintJobAccess();
+ }
+ }
+
+ /**
+ * @param check
+ * @return
+ */
+ protected boolean supportCommand(String check)
+ {
+ return ((this.getCommand(check) != null) ? true : false);
+ }
+
+ /**
+ * @return
+ */
+ public static DesktopPeer getDesktop()
+ {
+ // check if we are under Gnome or KDE or anything else
+ String desktopSession = System.getenv("GNOME_DESKTOP_SESSION_ID");
+ if (desktopSession == null)
+ {
+ desktopSession = System.getenv("KDE_FULL_SESSION");
+ if (desktopSession != null)
+ return kde;
+ }
+ else
+ {
+ return gnome;
+ }
+
+ // revert to this class for default values
+ return classpath;
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/ClasspathFontPeer.java b/libjava/classpath/gnu/java/awt/peer/ClasspathFontPeer.java
index 2176f34a5f1..60fde2557ac 100644
--- a/libjava/classpath/gnu/java/awt/peer/ClasspathFontPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/ClasspathFontPeer.java
@@ -54,6 +54,7 @@ import java.awt.peer.FontPeer;
import java.text.AttributedCharacterIterator;
import java.text.CharacterIterator;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
@@ -120,6 +121,23 @@ public abstract class ClasspathFontPeer
*/
protected AffineTransform transform;
+ static class LRUCache<K,V> extends LinkedHashMap<K,V>
+ {
+ int max_entries;
+ public LRUCache(int max)
+ {
+ super(max, 0.75f, true);
+ max_entries = max;
+ }
+ protected boolean removeEldestEntry(Map.Entry eldest)
+ {
+ return size() > max_entries;
+ }
+ }
+
+ private static LRUCache<AffineTransform,TransformAttribute> transCache =
+ new LRUCache<AffineTransform,TransformAttribute>(50);
+
protected static ClasspathToolkit tk()
{
return (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
@@ -200,7 +218,19 @@ public abstract class ClasspathFontPeer
protected static void copyTransformToAttrs (AffineTransform trans, Map attrs)
{
if (trans != null)
- attrs.put(TextAttribute.TRANSFORM, new TransformAttribute (trans));
+ {
+ TransformAttribute ta;
+ synchronized(transCache)
+ {
+ ta = transCache.get(trans);
+ if (ta == null)
+ {
+ ta = new TransformAttribute(trans);
+ transCache.put(trans, ta);
+ }
+ }
+ attrs.put(TextAttribute.TRANSFORM, ta);
+ }
}
diff --git a/libjava/classpath/gnu/java/awt/peer/GnomeDesktopPeer.java b/libjava/classpath/gnu/java/awt/peer/GnomeDesktopPeer.java
new file mode 100644
index 00000000000..be216318140
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/GnomeDesktopPeer.java
@@ -0,0 +1,153 @@
+/* GnomeDesktopPeer.java -- Offers a GNOME Desktop peer for DesktopPeer
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+package gnu.java.awt.peer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class GnomeDesktopPeer
+ extends ClasspathDesktopPeer
+{
+ /**
+ * Query string to use if a GNOME desktop is detected to get the name of the
+ * default browser. This requires gconftool-2 (part of GNOME).
+ */
+ private static final String BROWSER_QUERY_GNOME =
+ "gconftool-2 -g /desktop/gnome/url-handlers/http/command";
+
+ protected String getCommand(String action)
+ {
+ // check if a command already exists
+ String command = super.getCommand(action);
+
+ if (command == null)
+ {
+ try
+ {
+ if (action == _BROWSE)
+ {
+ command = execQuery(BROWSER_QUERY_GNOME);
+ }
+ else if (action == _PRINT)
+ {
+ command = null;
+ }
+ else
+ {
+ command = "gnome-open";
+ }
+ }
+ catch (Exception e)
+ {
+ command = null;
+ }
+ }
+
+ return command;
+ }
+
+ public void browse(URI url) throws IOException
+ {
+ checkPermissions();
+
+ String browser = getCommand(_BROWSE);
+
+ if (browser == null)
+ throw new UnsupportedOperationException();
+
+ browser = browser + " " + url.toString();
+
+ Runtime.getRuntime().exec(browser);
+ }
+
+ protected boolean supportCommand(String check)
+ {
+ if (check == _PRINT)
+ {
+ return super.supportCommand(check);
+ }
+
+ return true;
+ }
+
+ public void mail() throws IOException
+ {
+ checkPermissions();
+
+ String mail = getCommand(_MAIL);
+
+ if (mail == null)
+ throw new UnsupportedOperationException();
+
+ Runtime.getRuntime().exec(mail + " mailto:");
+ }
+
+ protected String execQuery(String command) throws IOException
+ {
+ InputStream in = null;
+ StringBuilder output = new StringBuilder();
+
+ try
+ {
+ Process process = Runtime.getRuntime().exec(command);
+
+ // Get the input stream and read from it
+ in = process.getInputStream();
+ int c;
+ while ((c = in.read()) != - 1)
+ {
+ output.append((char) c);
+ }
+ }
+ finally
+ {
+ if (in != null)
+ in.close();
+ }
+
+ // remove %s from the string, leave only the command line
+ int index = output.indexOf("%s");
+ output.delete(index, index + 1);
+
+ return output.toString().trim();
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/KDEDesktopPeer.java b/libjava/classpath/gnu/java/awt/peer/KDEDesktopPeer.java
new file mode 100644
index 00000000000..676bd891758
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/KDEDesktopPeer.java
@@ -0,0 +1,135 @@
+/* GnomeDesktopPeer.java -- Offers a KDE Desktop peer for DesktopPeer
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+package gnu.java.awt.peer;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class KDEDesktopPeer
+ extends ClasspathDesktopPeer
+{
+ /**
+ * Query string to use if a GNOME desktop is detected to get the name of the
+ * default browser. This requires gconftool-2 (part of GNOME).
+ */
+ private static final String BROWSER_QUERY_GNOME =
+ "gconftool-2 -g /desktop/gnome/url-handlers/http/command";
+
+ protected String getCommand(String action)
+ {
+ // check if a command already exists
+ String command = super.getCommand(action);
+
+ if (command == null)
+ {
+ try
+ {
+ if (action == _MAIL)
+ {
+ command = "kfmclient exec";
+ }
+ else if (action == _PRINT)
+ {
+ command = "kprinter";
+ }
+ else
+ {
+ command = "kfmclient openURL";
+ }
+ }
+ catch (Exception e)
+ {
+ command = null;
+ }
+ }
+
+ return command;
+ }
+
+ protected boolean supportCommand(String check)
+ {
+ return true;
+ }
+
+ public void mail() throws IOException
+ {
+ checkPermissions();
+
+ String mail = getCommand(_MAIL);
+
+ if (mail == null)
+ throw new UnsupportedOperationException();
+
+ Runtime.getRuntime().exec(mail + " 'mailto: '");
+ }
+
+ protected String execQuery(String command) throws IOException
+ {
+ InputStream in = null;
+ StringBuilder output = new StringBuilder();
+
+ try
+ {
+ Process process = Runtime.getRuntime().exec(command);
+
+ // Get the input stream and read from it
+ in = process.getInputStream();
+ int c;
+ while ((c = in.read()) != - 1)
+ {
+ output.append((char) c);
+ }
+ }
+ finally
+ {
+ if (in != null)
+ in.close();
+ }
+
+ // remove %s from the string, leave only the command line
+ int index = output.indexOf("%s");
+ output.delete(index, index + 1);
+
+ return output.toString().trim();
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/AsyncImage.java b/libjava/classpath/gnu/java/awt/peer/gtk/AsyncImage.java
index 5238bfe7410..dad537aa748 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/AsyncImage.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/AsyncImage.java
@@ -61,11 +61,11 @@ public class AsyncImage
private class NullImageSource
implements ImageProducer
{
- private ArrayList consumers;
+ private ArrayList<ImageConsumer> consumers;
NullImageSource()
{
- consumers = new ArrayList();
+ consumers = new ArrayList<ImageConsumer>();
}
public void addConsumer(ImageConsumer ic)
@@ -145,14 +145,14 @@ public class AsyncImage
*
* This is package private to avoid accessor methods.
*/
- HashSet observers;
+ HashSet<ImageObserver> observers;
/**
* Creates a new AsyncImage that loads from the specified URL.
*/
AsyncImage(URL url)
{
- observers = new HashSet();
+ observers = new HashSet<ImageObserver>();
Loader l = new Loader(url);
Thread t = new Thread(l);
t.start();
@@ -221,7 +221,7 @@ public class AsyncImage
{
// This field gets null when image loading is complete and we don't
// need to store any more observers.
- HashSet observs = observers;
+ HashSet<ImageObserver> observs = observers;
if (observs != null)
{
observs.add(obs);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java b/libjava/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java
index c792645d3e8..31c5e641ec8 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java
@@ -40,6 +40,7 @@ package gnu.java.awt.peer.gtk;
import java.awt.AlphaComposite;
import java.awt.Color;
+import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
@@ -49,7 +50,6 @@ import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
-import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -75,12 +75,6 @@ public class BufferedImageGraphics extends CairoGraphics2D
private BufferedImage image, buffer;
/**
- * Allows us to lock the image from updates (if we want to perform a few
- * intermediary operations on the cairo surface, then update it all at once)
- */
- private boolean locked;
-
- /**
* Image size.
*/
private int imageWidth, imageHeight;
@@ -93,7 +87,8 @@ public class BufferedImageGraphics extends CairoGraphics2D
/**
* Cache BufferedImageGraphics surfaces.
*/
- static WeakHashMap bufferedImages = new WeakHashMap();
+ static WeakHashMap<BufferedImage, CairoSurface> bufferedImages
+ = new WeakHashMap<BufferedImage, CairoSurface>();
/**
* Its corresponding cairo_t.
@@ -109,30 +104,30 @@ public class BufferedImageGraphics extends CairoGraphics2D
this.image = bi;
imageWidth = bi.getWidth();
imageHeight = bi.getHeight();
- locked = false;
if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel))
hasFastCM = false;
else if(bi.getColorModel().equals(CairoSurface.cairoCM_opaque))
{
- hasFastCM = true;
- hasAlpha = false;
+ hasFastCM = true;
+ hasAlpha = false;
}
- else if(bi.getColorModel().equals(CairoSurface.cairoColorModel))
+ else if(bi.getColorModel().equals(CairoSurface.cairoColorModel)
+ || bi.getColorModel().equals(CairoSurface.cairoCM_pre))
{
- hasFastCM = true;
- hasAlpha = true;
+ hasFastCM = true;
+ hasAlpha = true;
}
else
hasFastCM = false;
// Cache surfaces.
if( bufferedImages.get( bi ) != null )
- surface = (CairoSurface)bufferedImages.get( bi );
+ surface = bufferedImages.get( bi );
else
{
- surface = new CairoSurface( imageWidth, imageHeight );
- bufferedImages.put(bi, surface);
+ surface = new CairoSurface( imageWidth, imageHeight );
+ bufferedImages.put(bi, surface);
}
cairo_t = surface.newCairoContext();
@@ -148,10 +143,7 @@ public class BufferedImageGraphics extends CairoGraphics2D
int minY = image.getRaster().getSampleModelTranslateY();
// Pull pixels directly out of data buffer
- if(raster instanceof CairoSurface)
- pixels = ((CairoSurface)raster).getPixels(raster.getWidth() * raster.getHeight());
- else
- pixels = ((DataBufferInt)raster.getDataBuffer()).getData();
+ pixels = ((DataBufferInt)raster.getDataBuffer()).getData();
// Discard pixels that fall outside of the image's bounds
// (ie, this image is actually a subimage of a different image)
@@ -161,7 +153,8 @@ public class BufferedImageGraphics extends CairoGraphics2D
int scanline = sm.getScanlineStride();
for (int i = 0; i < imageHeight; i++)
- System.arraycopy(pixels, (i - minY) * scanline - minX, pixels2, i * imageWidth, imageWidth);
+ System.arraycopy(pixels, (i - minY) * scanline - minX, pixels2,
+ i * imageWidth, imageWidth);
pixels = pixels2;
}
@@ -173,11 +166,13 @@ public class BufferedImageGraphics extends CairoGraphics2D
}
else
{
- pixels = CairoGraphics2D.findSimpleIntegerArray(image.getColorModel(),image.getData());
+ pixels = CairoGraphics2D.findSimpleIntegerArray(image.getColorModel(),
+ image.getData());
+ if (pixels != null)
+ System.arraycopy(pixels, 0, surface.getData(),
+ 0, pixels.length);
}
- surface.setPixels( pixels );
-
setup( cairo_t );
setClip(0, 0, imageWidth, imageHeight);
}
@@ -189,7 +184,6 @@ public class BufferedImageGraphics extends CairoGraphics2D
cairo_t = surface.newCairoContext();
imageWidth = copyFrom.imageWidth;
imageHeight = copyFrom.imageHeight;
- locked = false;
hasFastCM = copyFrom.hasFastCM;
hasAlpha = copyFrom.hasAlpha;
@@ -202,17 +196,14 @@ public class BufferedImageGraphics extends CairoGraphics2D
*/
private void updateBufferedImage(int x, int y, int width, int height)
{
- if (locked)
- return;
-
- double[] points = new double[]{x, y, width+x, height+y};
- transform.transform(points, 0, points, 0, 2);
- x = (int)points[0];
- y = (int)points[1];
- width = (int)Math.ceil(points[2] - points[0]);
- height = (int)Math.ceil(points[3] - points[1]);
+ Rectangle bounds = new Rectangle(x, y, width, height);
+ bounds = getTransformedBounds(bounds, transform).getBounds();
+ x = bounds.x;
+ y = bounds.y;
+ width = bounds.width;
+ height = bounds.height;
- int[] pixels = surface.getPixels(imageWidth * imageHeight);
+ int[] pixels = surface.getData();
if( x > imageWidth || y > imageHeight )
return;
@@ -403,14 +394,10 @@ public class BufferedImageGraphics extends CairoGraphics2D
BufferedImage bImg = (BufferedImage) img;
// Find translated bounds
- Point2D origin = new Point2D.Double(bImg.getMinX(), bImg.getMinY());
- Point2D pt = new Point2D.Double(bImg.getWidth() + bImg.getMinX(),
- bImg.getHeight() + bImg.getMinY());
+ Rectangle2D bounds = new Rectangle(bImg.getMinX(), bImg.getMinY(),
+ bImg.getWidth(), bImg.getHeight());
if (xform != null)
- {
- origin = xform.transform(origin, origin);
- pt = xform.transform(pt, pt);
- }
+ bounds = getTransformedBounds(bounds, xform);
// Create buffer and draw image
createBuffer();
@@ -420,10 +407,7 @@ public class BufferedImageGraphics extends CairoGraphics2D
g2d.drawImage(img, xform, obs);
// Perform compositing
- return drawComposite(new Rectangle2D.Double(origin.getX(),
- origin.getY(),
- pt.getX(), pt.getY()),
- obs);
+ return drawComposite(bounds, obs);
}
}
@@ -438,6 +422,11 @@ public class BufferedImageGraphics extends CairoGraphics2D
if (comp == null || comp instanceof AlphaComposite)
{
super.drawGlyphVector(gv, x, y);
+
+ // this returns an integer-based Rectangle (rather than a
+ // Rectangle2D), which takes care of any necessary rounding for us.
+ bounds = bounds.getBounds();
+
updateBufferedImage((int)bounds.getX(), (int)bounds.getY(),
(int)bounds.getWidth(), (int)bounds.getHeight());
}
@@ -468,12 +457,7 @@ public class BufferedImageGraphics extends CairoGraphics2D
private boolean drawComposite(Rectangle2D bounds, ImageObserver observer)
{
// Find bounds in device space
- double[] points = new double[] {bounds.getX(), bounds.getY(),
- bounds.getMaxX(), bounds.getMaxY()};
- transform.transform(points, 0, points, 0, 2);
- bounds = new Rectangle2D.Double(points[0], points[1],
- (points[2] - points[0]),
- (points[3] - points[1]));
+ bounds = getTransformedBounds(bounds, transform);
// Clip bounds by the stored clip, and by the internal buffer
Rectangle2D devClip = this.getClipInDevSpace();
@@ -482,17 +466,15 @@ public class BufferedImageGraphics extends CairoGraphics2D
buffer.getWidth(), buffer.getHeight());
Rectangle2D.intersect(bounds, devClip, bounds);
- // Round bounds as needed, but be conservative in our rounding
+ // Round bounds as needed, but be careful in our rounding
// (otherwise it may leave unpainted stripes)
double x = bounds.getX();
double y = bounds.getY();
- double w = bounds.getWidth();
- double h = bounds.getHeight();
- if (Math.floor(x) != x)
- w--;
- if (Math.floor(y) != y)
- h--;
- bounds.setRect(Math.ceil(x), Math.ceil(y), Math.floor(w), Math.floor(h));
+ double maxX = x + bounds.getWidth();
+ double maxY = y + bounds.getHeight();
+ x = Math.round(x);
+ y = Math.round(y);
+ bounds.setRect(x, y, Math.round(maxX - x), Math.round(maxY - y));
// Find subimage of internal buffer for updating
BufferedImage buffer2 = buffer;
@@ -511,9 +493,10 @@ public class BufferedImageGraphics extends CairoGraphics2D
compCtx.compose(buffer2.getRaster(), current.getRaster(),
current.getRaster());
- // Prevent the clearRect in CairoGraphics2D.drawImage from clearing
- // our composited image
- locked = true;
+ // Set cairo's composite to direct SRC, since we've already done our own
+ // compositing
+ Composite oldcomp = comp;
+ setComposite(AlphaComposite.Src);
// This MUST call directly into the "action" method in CairoGraphics2D,
// not one of the wrappers, to ensure that the composite isn't processed
@@ -521,8 +504,9 @@ public class BufferedImageGraphics extends CairoGraphics2D
boolean rv = super.drawImage(current,
AffineTransform.getTranslateInstance(bounds.getX(),
bounds.getY()),
- new Color(0,0,0,0), null);
- locked = false;
+ null, null);
+ setComposite(oldcomp);
+ updateColor();
return rv;
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/libjava/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java
index 4a6ad008259..3a386075a69 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java
@@ -172,6 +172,12 @@ public abstract class CairoGraphics2D extends Graphics2D
* Rendering hint map.
*/
private RenderingHints hints;
+
+ /**
+ * Status of the anti-alias flag in cairo.
+ */
+ private boolean antialias = false;
+ private boolean ignoreAA = false;
/**
* Some operations (drawing rather than filling) require that their
@@ -228,6 +234,7 @@ public abstract class CairoGraphics2D extends Graphics2D
setPaint(Color.black);
setStroke(new BasicStroke());
setTransform(new AffineTransform());
+ cairoSetAntialias(nativePointer, antialias);
}
/**
@@ -244,7 +251,7 @@ public abstract class CairoGraphics2D extends Graphics2D
if (g.fg.getAlpha() != -1)
foreground = new Color(g.fg.getRed(), g.fg.getGreen(), g.fg.getBlue(),
- g.fg.getAlpha());
+ g.fg.getAlpha());
else
foreground = new Color(g.fg.getRGB());
@@ -274,6 +281,9 @@ public abstract class CairoGraphics2D extends Graphics2D
setTransformImpl(transform);
setClip(clip);
setComposite(comp);
+
+ antialias = !g.antialias;
+ setAntialias(g.antialias);
}
/**
@@ -311,8 +321,8 @@ public abstract class CairoGraphics2D extends Graphics2D
public abstract GraphicsConfiguration getDeviceConfiguration();
- protected abstract void copyAreaImpl(int x, int y,
- int width, int height, int dx, int dy);
+ protected abstract void copyAreaImpl(int x, int y, int width, int height,
+ int dx, int dy);
/**
@@ -345,8 +355,8 @@ public abstract class CairoGraphics2D extends Graphics2D
int g2, int b2, int a2, boolean cyclic);
protected native void setPaintPixels(long pointer, int[] pixels, int w,
- int h, int stride, boolean repeat,
- int x, int y);
+ int h, int stride, boolean repeat,
+ int x, int y);
/**
* Set the current transform matrix
@@ -390,9 +400,9 @@ public abstract class CairoGraphics2D extends Graphics2D
/*
* Draws a Glyph Vector
*/
- native void cairoDrawGlyphVector(long pointer, GdkFontPeer font,
+ protected native void cairoDrawGlyphVector(long pointer, GdkFontPeer font,
float x, float y, int n,
- int[] codes, float[] positions);
+ int[] codes, float[] positions, long[] fontset);
/**
* Set the font in cairo.
@@ -454,9 +464,15 @@ public abstract class CairoGraphics2D extends Graphics2D
protected native void cairoClip(long pointer);
/**
- * Save clip
+ * Clear clip
*/
protected native void cairoResetClip(long pointer);
+
+ /**
+ * Set antialias.
+ */
+ protected native void cairoSetAntialias(long pointer, boolean aa);
+
///////////////////////// TRANSFORMS ///////////////////////////////////
/**
@@ -648,33 +664,35 @@ public abstract class CairoGraphics2D extends Graphics2D
setColor((Color) paint);
customPaint = false;
}
+
else if (paint instanceof TexturePaint)
{
- TexturePaint tp = (TexturePaint) paint;
- BufferedImage img = tp.getImage();
+ TexturePaint tp = (TexturePaint) paint;
+ BufferedImage img = tp.getImage();
- // map the image to the anchor rectangle
- int width = (int) tp.getAnchorRect().getWidth();
- int height = (int) tp.getAnchorRect().getHeight();
+ // 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 = height / (double) img.getHeight();
+ double scaleX = width / (double) img.getWidth();
+ double scaleY = height / (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);
- setPaintPixels(nativePointer, pixels, width, height, width, true, 0, 0);
+ 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);
+ setPaintPixels(nativePointer, pixels, width, height, width, true, 0, 0);
customPaint = false;
}
+
else if (paint instanceof GradientPaint)
{
- GradientPaint gp = (GradientPaint) paint;
- Point2D p1 = gp.getPoint1();
- Point2D p2 = gp.getPoint2();
- Color c1 = gp.getColor1();
- Color c2 = gp.getColor2();
- setGradient(nativePointer, p1.getX(), p1.getY(), p2.getX(), p2.getY(),
+ GradientPaint gp = (GradientPaint) paint;
+ Point2D p1 = gp.getPoint1();
+ Point2D p2 = gp.getPoint2();
+ Color c1 = gp.getColor1();
+ Color c2 = gp.getColor2();
+ setGradient(nativePointer, p1.getX(), p1.getY(), p2.getX(), p2.getY(),
c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha(),
c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha(),
gp.isCyclic());
@@ -703,15 +721,11 @@ public abstract class CairoGraphics2D extends Graphics2D
int userHeight = bounds.height;
// Find bounds in device space
- Point2D origin = transform.transform(new Point2D.Double(userX, userY),
- null);
- Point2D extreme = transform.transform(new Point2D.Double(userWidth + userX,
- userHeight + userY),
- null);
- int deviceX = (int)origin.getX();
- int deviceY = (int)origin.getY();
- int deviceWidth = (int)Math.ceil(extreme.getX() - origin.getX());
- int deviceHeight = (int)Math.ceil(extreme.getY() - origin.getY());
+ Rectangle2D bounds2D = getTransformedBounds(bounds, transform);
+ int deviceX = (int)bounds2D.getX();
+ int deviceY = (int)bounds2D.getY();
+ int deviceWidth = (int)Math.ceil(bounds2D.getWidth());
+ int deviceHeight = (int)Math.ceil(bounds2D.getHeight());
// Get raster of the paint background
PaintContext pc = paint.createContext(CairoSurface.cairoColorModel,
@@ -792,21 +806,22 @@ public abstract class CairoGraphics2D extends Graphics2D
stroke = st;
if (stroke instanceof BasicStroke)
{
- BasicStroke bs = (BasicStroke) stroke;
- cairoSetLine(nativePointer, bs.getLineWidth(), bs.getEndCap(),
- bs.getLineJoin(), bs.getMiterLimit());
-
- float[] dashes = bs.getDashArray();
- if (dashes != null)
- {
- double[] double_dashes = new double[dashes.length];
- for (int i = 0; i < dashes.length; i++)
- double_dashes[i] = dashes[i];
- cairoSetDash(nativePointer, double_dashes, double_dashes.length,
- (double) bs.getDashPhase());
- }
- else
- cairoSetDash(nativePointer, new double[0], 0, 0.0);
+ BasicStroke bs = (BasicStroke) stroke;
+ cairoSetLine(nativePointer, bs.getLineWidth(), bs.getEndCap(),
+ bs.getLineJoin(), bs.getMiterLimit());
+
+ float[] dashes = bs.getDashArray();
+ if (dashes != null)
+ {
+ double[] double_dashes = new double[dashes.length];
+ for (int i = 0; i < dashes.length; i++)
+ double_dashes[i] = dashes[i];
+
+ cairoSetDash(nativePointer, double_dashes, double_dashes.length,
+ (double) bs.getDashPhase());
+ }
+ else
+ cairoSetDash(nativePointer, new double[0], 0, 0.0);
}
}
@@ -864,6 +879,7 @@ public abstract class CairoGraphics2D extends Graphics2D
{
if (fg == null)
fg = Color.BLACK;
+
cairoSetRGBAColor(nativePointer, fg.getRed() / 255.0,
fg.getGreen() / 255.0,fg.getBlue() / 255.0,
fg.getAlpha() / 255.0);
@@ -916,18 +932,7 @@ public abstract class CairoGraphics2D extends Graphics2D
if (transform == null)
return uclip;
else
- {
- Point2D pos = transform.transform(new Point2D.Double(uclip.getX(),
- uclip.getY()),
- (Point2D) null);
- Point2D extent = transform.deltaTransform(new Point2D.Double(uclip
- .getWidth(),
- uclip
- .getHeight()),
- (Point2D) null);
- return new Rectangle2D.Double(pos.getX(), pos.getY(), extent.getX(),
- extent.getY());
- }
+ return getTransformedBounds(clip.getBounds2D(), transform);
}
public void setClip(int x, int y, int width, int height)
@@ -946,8 +951,8 @@ public abstract class CairoGraphics2D extends Graphics2D
// initial clip properly.
if( firstClip )
{
- originalClip = s;
- firstClip = false;
+ originalClip = s;
+ firstClip = false;
}
clip = s;
@@ -1007,7 +1012,7 @@ public abstract class CairoGraphics2D extends Graphics2D
if (comp instanceof AlphaComposite)
{
- AlphaComposite a = (AlphaComposite) comp;
+ AlphaComposite a = (AlphaComposite) comp;
cairoSetOperator(nativePointer, a.getRule());
}
@@ -1066,7 +1071,9 @@ public abstract class CairoGraphics2D extends Graphics2D
Rectangle r = findStrokedBounds(s);
setCustomPaint(r);
}
-
+
+ setAntialias(!hints.get(RenderingHints.KEY_ANTIALIASING)
+ .equals(RenderingHints.VALUE_ANTIALIAS_OFF));
createPath(s, true);
cairoStroke(nativePointer);
}
@@ -1077,7 +1084,9 @@ public abstract class CairoGraphics2D extends Graphics2D
if (customPaint)
setCustomPaint(s.getBounds());
-
+
+ setAntialias(!hints.get(RenderingHints.KEY_ANTIALIASING)
+ .equals(RenderingHints.VALUE_ANTIALIAS_OFF));
double alpha = 1.0;
if (comp instanceof AlphaComposite)
alpha = ((AlphaComposite) comp).getAlpha();
@@ -1263,13 +1272,15 @@ public abstract class CairoGraphics2D extends Graphics2D
public void copyArea(int ox, int oy, int owidth, int oheight,
int odx, int ody)
{
+ // FIXME: does this handle a rotation transform properly?
+ // (the width/height might not be correct)
Point2D pos = transform.transform(new Point2D.Double(ox, oy),
- (Point2D) null);
+ (Point2D) null);
Point2D dim = transform.transform(new Point2D.Double(ox + owidth,
- oy + oheight),
- (Point2D) null);
+ oy + oheight),
+ (Point2D) null);
Point2D p2 = transform.transform(new Point2D.Double(ox + odx, oy + ody),
- (Point2D) null);
+ (Point2D) null);
int x = (int)pos.getX();
int y = (int)pos.getY();
int width = (int)(dim.getX() - pos.getX());
@@ -1291,14 +1302,14 @@ public abstract class CairoGraphics2D extends Graphics2D
// Clip edges if necessary
if( x + dx < r.getX() ) // left
{
- width = x + dx + width;
- x = (int)r.getX() - dx;
+ width = x + dx + width;
+ x = (int)r.getX() - dx;
}
if( y + dy < r.getY() ) // top
{
- height = y + dy + height;
- y = (int)r.getY() - dy;
+ height = y + dy + height;
+ y = (int)r.getY() - dy;
}
if( x + dx + width >= r.getWidth() ) // right
@@ -1325,10 +1336,10 @@ public abstract class CairoGraphics2D extends Graphics2D
return hints.get(hintKey);
}
- public void setRenderingHints(Map hints)
+ public void setRenderingHints(Map<?,?> hints)
{
this.hints = new RenderingHints(getDefaultHints());
- this.hints.add(new RenderingHints(hints));
+ this.hints.putAll(hints);
shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE)
|| hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT);
@@ -1342,7 +1353,7 @@ public abstract class CairoGraphics2D extends Graphics2D
public void addRenderingHints(Map hints)
{
- this.hints.add(new RenderingHints(hints));
+ this.hints.putAll(hints);
}
public RenderingHints getRenderingHints()
@@ -1373,6 +1384,24 @@ public abstract class CairoGraphics2D extends Graphics2D
// Do bilinear interpolation as default
return INTERPOLATION_BILINEAR;
}
+
+ /**
+ * Set antialias if needed. If the ignoreAA flag is set, this method will
+ * return without doing anything.
+ *
+ * @param needAA RenderingHints.VALUE_ANTIALIAS_ON or RenderingHints.VALUE_ANTIALIAS_OFF
+ */
+ private void setAntialias(boolean needAA)
+ {
+ if (ignoreAA)
+ return;
+
+ if (needAA != antialias)
+ {
+ antialias = !antialias;
+ cairoSetAntialias(nativePointer, antialias);
+ }
+ }
///////////////////////// IMAGE. METHODS ///////////////////////////////////
@@ -1396,12 +1425,12 @@ public abstract class CairoGraphics2D extends Graphics2D
try
{
- invertedXform = xform.createInverse();
+ invertedXform = xform.createInverse();
}
catch (NoninvertibleTransformException e)
{
- throw new ImagingOpException("Unable to invert transform "
- + xform.toString());
+ throw new ImagingOpException("Unable to invert transform "
+ + xform.toString());
}
// Unrecognized image - convert to a BufferedImage
@@ -1411,10 +1440,10 @@ public abstract class CairoGraphics2D extends Graphics2D
img = AsyncImage.realImage(img, obs);
if( !(img instanceof BufferedImage) )
{
- ImageProducer source = img.getSource();
- if (source == null)
- return false;
- img = Toolkit.getDefaultToolkit().createImage(source);
+ ImageProducer source = img.getSource();
+ if (source == null)
+ return false;
+ img = Toolkit.getDefaultToolkit().createImage(source);
}
BufferedImage b = (BufferedImage) img;
@@ -1427,7 +1456,7 @@ public abstract class CairoGraphics2D extends Graphics2D
// use the cached CairoSurface that BIG is drawing onto
if( BufferedImageGraphics.bufferedImages.get( b ) != null )
- raster = (Raster)BufferedImageGraphics.bufferedImages.get( b );
+ raster = BufferedImageGraphics.bufferedImages.get( b );
else
raster = b.getRaster();
@@ -1437,12 +1466,12 @@ public abstract class CairoGraphics2D extends Graphics2D
if (comp instanceof AlphaComposite)
alpha = ((AlphaComposite) comp).getAlpha();
- if(raster instanceof CairoSurface)
+ if(raster instanceof CairoSurface
+ && ((CairoSurface)raster).sharedBuffer == true)
{
- ((CairoSurface)raster).drawSurface(nativePointer, i2u, alpha,
- getInterpolation());
+ drawCairoSurface((CairoSurface)raster, xform, alpha, getInterpolation());
updateColor();
- return true;
+ return true;
}
if( bgcolor != null )
@@ -1450,24 +1479,31 @@ public abstract class CairoGraphics2D extends Graphics2D
Color oldColor = bg;
setBackground(bgcolor);
- double[] origin = new double[] {0,0};
- double[] dimensions = new double[] {width, height};
- xform.transform(origin, 0, origin, 0, 1);
- xform.deltaTransform(dimensions, 0, dimensions, 0, 1);
- clearRect((int)origin[0], (int)origin[1],
- (int)dimensions[0], (int)dimensions[1]);
+ Rectangle2D bounds = new Rectangle2D.Double(0, 0, width, height);
+ bounds = getTransformedBounds(bounds, xform);
+
+ clearRect((int)bounds.getX(), (int)bounds.getY(),
+ (int)bounds.getWidth(), (int)bounds.getHeight());
setBackground(oldColor);
}
int[] pixels = b.getRGB(0, 0, width, height, null, 0, width);
-
// FIXME: The above method returns data in the standard ARGB colorspace,
// meaning data should NOT be alpha pre-multiplied; however Cairo expects
// data to be premultiplied.
+
+ cairoSave(nativePointer);
+ Rectangle2D bounds = new Rectangle2D.Double(0, 0, width, height);
+ bounds = getTransformedBounds(bounds, xform);
+ cairoRectangle(nativePointer, bounds.getX(), bounds.getY(),
+ bounds.getWidth(), bounds.getHeight());
+ cairoClip(nativePointer);
drawPixels(nativePointer, pixels, width, height, width, i2u, alpha,
getInterpolation());
+
+ cairoRestore(nativePointer);
// Cairo seems to lose the current color which must be restored.
updateColor();
@@ -1578,6 +1614,66 @@ public abstract class CairoGraphics2D extends Graphics2D
{
return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, observer);
}
+
+ /**
+ * Optimized method for drawing a CairoSurface onto this graphics context.
+ *
+ * @param surface The surface to draw.
+ * @param tx The transformation matrix (cannot be null).
+ * @param alpha The alpha value to paint with ( 0 <= alpha <= 1).
+ * @param interpolation The interpolation type.
+ */
+ protected void drawCairoSurface(CairoSurface surface, AffineTransform tx,
+ double alpha, int interpolation)
+ {
+ // Find offset required if this surface is a sub-raster, and append offset
+ // to transformation.
+ if (surface.getSampleModelTranslateX() != 0
+ || surface.getSampleModelTranslateY() != 0)
+ {
+ Point2D origin = new Point2D.Double(0, 0);
+ Point2D offset = new Point2D.Double(surface.getSampleModelTranslateX(),
+ surface.getSampleModelTranslateY());
+
+ tx.transform(origin, origin);
+ tx.transform(offset, offset);
+
+ tx.translate(offset.getX() - origin.getX(),
+ offset.getY() - origin.getY());
+ }
+
+ // Find dimensions of this surface relative to the root parent surface
+ Rectangle bounds = new Rectangle(-surface.getSampleModelTranslateX(),
+ -surface.getSampleModelTranslateY(),
+ surface.width, surface.height);
+
+ // Clip to the translated image
+ // We use direct cairo methods to avoid the overhead of maintaining a
+ // java copy of the clip, since we will be reverting it immediately
+ // after drawing
+ Shape newBounds = tx.createTransformedShape(bounds);
+ cairoSave(nativePointer);
+ walkPath(newBounds.getPathIterator(null), false);
+ cairoClip(nativePointer);
+
+ // Draw the surface
+ try
+ {
+ double[] i2u = new double[6];
+ tx.createInverse().getMatrix(i2u);
+ surface.nativeDrawSurface(surface.surfacePointer, nativePointer, i2u,
+ alpha, interpolation);
+ }
+ catch (NoninvertibleTransformException ex)
+ {
+ // This should never happen(?), so we don't need to do anything here.
+ ;
+ }
+
+ // Restore clip
+ cairoRestore(nativePointer);
+ }
+
///////////////////////// TEXT METHODS ////////////////////////////////////
@@ -1592,7 +1688,15 @@ public abstract class CairoGraphics2D extends Graphics2D
tl = new TextLayout( str, getFont(), getFontRenderContext() );
fontPeer.textLayoutCache.put(str, tl);
}
+
+ // Set antialias to text_antialiasing, and set the ignoreAA flag so that
+ // the setting doesn't get overridden in a draw() or fill() call.
+ setAntialias(!hints.get(RenderingHints.KEY_TEXT_ANTIALIASING)
+ .equals(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF));
+ ignoreAA = true;
+
tl.draw(this, x, y);
+ ignoreAA = false;
}
public void drawString(String str, int x, int y)
@@ -1617,19 +1721,25 @@ public abstract class CairoGraphics2D extends Graphics2D
if (comp instanceof AlphaComposite)
alpha = ((AlphaComposite) comp).getAlpha();
+
+ setAntialias(!hints.get(RenderingHints.KEY_TEXT_ANTIALIASING)
+ .equals(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF));
+ ignoreAA = true;
+
if (gv instanceof FreetypeGlyphVector && alpha == 1.0)
{
int n = gv.getNumGlyphs ();
int[] codes = gv.getGlyphCodes (0, n, null);
+ long[] fontset = ((FreetypeGlyphVector)gv).getGlyphFonts (0, n, null);
float[] positions = gv.getGlyphPositions (0, n, null);
setFont (gv.getFont ());
GdkFontPeer fontPeer = (GdkFontPeer) font.getPeer();
- synchronized (fontPeer)
- {
- cairoDrawGlyphVector(nativePointer, fontPeer,
- x, y, n, codes, positions);
- }
+ synchronized (fontPeer)
+ {
+ cairoDrawGlyphVector(nativePointer, fontPeer,
+ x, y, n, codes, positions, fontset);
+ }
}
else
{
@@ -1637,6 +1747,8 @@ public abstract class CairoGraphics2D extends Graphics2D
fill(gv.getOutline());
translate(-x, -y);
}
+
+ ignoreAA = false;
}
public void drawString(AttributedCharacterIterator ci, float x, float y)
@@ -1702,9 +1814,9 @@ public abstract class CairoGraphics2D extends Graphics2D
{
if( onStroke )
{
- Shape stroked = stroke.createStrokedShape( s );
- return stroked.intersects( (double)rect.x, (double)rect.y,
- (double)rect.width, (double)rect.height );
+ Shape stroked = stroke.createStrokedShape( s );
+ return stroked.intersects( (double)rect.x, (double)rect.y,
+ (double)rect.width, (double)rect.height );
}
return s.intersects( (double)rect.x, (double)rect.y,
(double)rect.width, (double)rect.height );
@@ -1747,34 +1859,34 @@ public abstract class CairoGraphics2D extends Graphics2D
imageToUser.getMatrix(i2u);
else
{
- i2u[0] = 1;
- i2u[1] = 0;
- i2u[2] = 0;
- i2u[3] = 1;
- i2u[4] = 0;
- i2u[5] = 0;
+ i2u[0] = 1;
+ i2u[1] = 0;
+ i2u[2] = 0;
+ i2u[3] = 1;
+ i2u[4] = 0;
+ i2u[5] = 0;
}
int[] pixels = findSimpleIntegerArray(cm, r);
if (pixels == null)
{
- // FIXME: I don't think this code will work correctly with a non-RGB
- // MultiPixelPackedSampleModel. Although this entire method should
- // probably be rewritten to better utilize Cairo's different supported
- // data formats.
- if (sm instanceof MultiPixelPackedSampleModel)
- {
- pixels = r.getPixels(0, 0, r.getWidth(), r.getHeight(), pixels);
- for (int i = 0; i < pixels.length; i++)
- pixels[i] = cm.getRGB(pixels[i]);
- }
- else
- {
- pixels = new int[r.getWidth() * r.getHeight()];
- for (int i = 0; i < pixels.length; i++)
- pixels[i] = cm.getRGB(db.getElem(i));
- }
+ // FIXME: I don't think this code will work correctly with a non-RGB
+ // MultiPixelPackedSampleModel. Although this entire method should
+ // probably be rewritten to better utilize Cairo's different supported
+ // data formats.
+ if (sm instanceof MultiPixelPackedSampleModel)
+ {
+ pixels = r.getPixels(0, 0, r.getWidth(), r.getHeight(), pixels);
+ for (int i = 0; i < pixels.length; i++)
+ pixels[i] = cm.getRGB(pixels[i]);
+ }
+ else
+ {
+ pixels = new int[r.getWidth() * r.getHeight()];
+ for (int i = 0; i < pixels.length; i++)
+ pixels[i] = cm.getRGB(db.getElem(i));
+ }
}
// Change all transparent pixels in the image to the specified bgcolor,
@@ -1782,20 +1894,21 @@ public abstract class CairoGraphics2D extends Graphics2D
// correctly.
if (cm.hasAlpha())
{
- if (bgcolor != null && cm.hasAlpha())
- for (int i = 0; i < pixels.length; i++)
- {
- if (cm.getAlpha(pixels[i]) == 0)
- pixels[i] = bgcolor.getRGB();
- }
+ if (bgcolor != null && cm.hasAlpha())
+ for (int i = 0; i < pixels.length; i++)
+ {
+ if (cm.getAlpha(pixels[i]) == 0)
+ pixels[i] = bgcolor.getRGB();
+ }
}
else
for (int i = 0; i < pixels.length; i++)
- pixels[i] |= 0xFF000000;
+ pixels[i] |= 0xFF000000;
double alpha = 1.0;
if (comp instanceof AlphaComposite)
alpha = ((AlphaComposite) comp).getAlpha();
+
drawPixels(nativePointer, pixels, r.getWidth(), r.getHeight(),
r.getWidth(), i2u, alpha, getInterpolation());
@@ -1815,7 +1928,7 @@ public abstract class CairoGraphics2D extends Graphics2D
double shift = 0.5;
if (!transform.isIdentity())
shift /= transform.getScaleX();
- return Math.round(coord) + shift;
+ return (coord + shift);
}
else
return coord;
@@ -1831,7 +1944,7 @@ public abstract class CairoGraphics2D extends Graphics2D
double shift = 0.5;
if (!transform.isIdentity())
shift /= transform.getScaleY();
- return Math.round(coord) + shift;
+ return (coord + shift);
}
else
return coord;
@@ -1849,53 +1962,54 @@ public abstract class CairoGraphics2D extends Graphics2D
cairoSetFillRule(nativePointer, p.getWindingRule());
for (; ! p.isDone(); p.next())
{
- int seg = p.currentSegment(coords);
- switch (seg)
- {
- case PathIterator.SEG_MOVETO:
- x = shiftX(coords[0], doShift);
- y = shiftY(coords[1], doShift);
- cairoMoveTo(nativePointer, x, y);
- break;
- case PathIterator.SEG_LINETO:
- x = shiftX(coords[0], doShift);
- y = shiftY(coords[1], doShift);
- cairoLineTo(nativePointer, x, y);
- break;
- case PathIterator.SEG_QUADTO:
- // splitting a quadratic bezier into a cubic:
- // see: http://pfaedit.sourceforge.net/bezier.html
- double x1 = x + (2.0 / 3.0) * (shiftX(coords[0], doShift) - x);
- double y1 = y + (2.0 / 3.0) * (shiftY(coords[1], doShift) - y);
-
- double x2 = x1 + (1.0 / 3.0) * (shiftX(coords[2], doShift) - x);
- double y2 = y1 + (1.0 / 3.0) * (shiftY(coords[3], doShift) - y);
-
- x = shiftX(coords[2], doShift);
- y = shiftY(coords[3], doShift);
- cairoCurveTo(nativePointer, x1, y1, x2, y2, x, y);
- break;
- case PathIterator.SEG_CUBICTO:
- x = shiftX(coords[4], doShift);
- y = shiftY(coords[5], doShift);
- cairoCurveTo(nativePointer, shiftX(coords[0], doShift),
- shiftY(coords[1], doShift),
- shiftX(coords[2], doShift),
- shiftY(coords[3], doShift), x, y);
- break;
- case PathIterator.SEG_CLOSE:
- cairoClosePath(nativePointer);
- break;
- }
+ int seg = p.currentSegment(coords);
+ switch (seg)
+ {
+ case PathIterator.SEG_MOVETO:
+ x = shiftX(coords[0], doShift);
+ y = shiftY(coords[1], doShift);
+ cairoMoveTo(nativePointer, x, y);
+ break;
+ case PathIterator.SEG_LINETO:
+ x = shiftX(coords[0], doShift);
+ y = shiftY(coords[1], doShift);
+ cairoLineTo(nativePointer, x, y);
+ break;
+ case PathIterator.SEG_QUADTO:
+ // splitting a quadratic bezier into a cubic:
+ // see: http://pfaedit.sourceforge.net/bezier.html
+ double x1 = x + (2.0 / 3.0) * (shiftX(coords[0], doShift) - x);
+ double y1 = y + (2.0 / 3.0) * (shiftY(coords[1], doShift) - y);
+
+ double x2 = x1 + (1.0 / 3.0) * (shiftX(coords[2], doShift) - x);
+ double y2 = y1 + (1.0 / 3.0) * (shiftY(coords[3], doShift) - y);
+
+ x = shiftX(coords[2], doShift);
+ y = shiftY(coords[3], doShift);
+ cairoCurveTo(nativePointer, x1, y1, x2, y2, x, y);
+ break;
+ case PathIterator.SEG_CUBICTO:
+ x = shiftX(coords[4], doShift);
+ y = shiftY(coords[5], doShift);
+ cairoCurveTo(nativePointer, shiftX(coords[0], doShift),
+ shiftY(coords[1], doShift),
+ shiftX(coords[2], doShift),
+ shiftY(coords[3], doShift), x, y);
+ break;
+ case PathIterator.SEG_CLOSE:
+ cairoClosePath(nativePointer);
+ break;
+ }
}
}
/**
* Used by setRenderingHints()
*/
- private Map getDefaultHints()
+ private Map<RenderingHints.Key, Object> getDefaultHints()
{
- HashMap defaultHints = new HashMap();
+ HashMap<RenderingHints.Key, Object> defaultHints =
+ new HashMap<RenderingHints.Key, Object>();
defaultHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
@@ -1972,11 +2086,27 @@ public abstract class CairoGraphics2D extends Graphics2D
if (clip == null)
return;
- if (! (clip instanceof GeneralPath))
- clip = new GeneralPath(clip);
-
- GeneralPath p = (GeneralPath) clip;
- p.transform(t);
+ // If the clip is a rectangle, and the transformation preserves the shape
+ // (translate/stretch only), then keep the clip as a rectangle
+ double[] matrix = new double[4];
+ t.getMatrix(matrix);
+ if (clip instanceof Rectangle2D && matrix[1] == 0 && matrix[2] == 0)
+ {
+ Rectangle2D rect = (Rectangle2D)clip;
+ double[] origin = new double[] {rect.getX(), rect.getY()};
+ double[] dimensions = new double[] {rect.getWidth(), rect.getHeight()};
+ t.transform(origin, 0, origin, 0, 1);
+ t.deltaTransform(dimensions, 0, dimensions, 0, 1);
+ rect.setRect(origin[0], origin[1], dimensions[0], dimensions[1]);
+ }
+ else
+ {
+ if (! (clip instanceof GeneralPath))
+ clip = new GeneralPath(clip);
+
+ GeneralPath p = (GeneralPath) clip;
+ p.transform(t);
+ }
}
private static Rectangle computeIntersection(int x, int y, int w, int h,
@@ -1999,4 +2129,39 @@ public abstract class CairoGraphics2D extends Graphics2D
return rect;
}
+
+ static Rectangle2D getTransformedBounds(Rectangle2D bounds, AffineTransform tx)
+ {
+ double x1 = bounds.getX();
+ double x2 = bounds.getX() + bounds.getWidth();
+ double x3 = x1;
+ double x4 = x2;
+ double y1 = bounds.getY();
+ double y2 = y1;
+ double y3 = bounds.getY() + bounds.getHeight();
+ double y4 = y3;
+
+ double[] points = new double[] {x1, y1, x2, y2, x3, y3, x4, y4};
+ tx.transform(points, 0, points, 0, 4);
+
+ double minX = points[0];
+ double maxX = minX;
+ double minY = points[1];
+ double maxY = minY;
+ for (int i = 0; i < 8; i++)
+ {
+ if (points[i] < minX)
+ minX = points[i];
+ if (points[i] > maxX)
+ maxX = points[i];
+ i++;
+
+ if (points[i] < minY)
+ minY = points[i];
+ if (points[i] > maxY)
+ maxY = points[i];
+ }
+
+ return new Rectangle2D.Double(minX, minY, (maxX - minX), (maxY - minY));
+ }
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java b/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java
index 5b63e62e7ed..b45a79fd6e7 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java
@@ -1,5 +1,5 @@
/* CairoSurface.java
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,15 +42,22 @@ import gnu.java.awt.Buffers;
import java.awt.Graphics2D;
import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Shape;
import java.awt.color.ColorSpace;
+import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferInt;
import java.awt.image.DirectColorModel;
+import java.awt.image.Raster;
+import java.awt.image.RasterFormatException;
import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
import java.nio.ByteOrder;
+import java.util.Arrays;
import java.util.Hashtable;
/**
@@ -68,9 +75,9 @@ public class CairoSurface extends WritableRaster
long surfacePointer;
/**
- * The native pointer to the image's data buffer
+ * Whether the data buffer is shared between java and cairo.
*/
- long bufferPointer;
+ boolean sharedBuffer;
// FIXME: use only the cairoCM_pre colormodel
// since that's what Cairo really uses (is there a way to do this cheaply?
@@ -98,22 +105,12 @@ public class CairoSurface extends WritableRaster
* @param width, height - the image size
* @param stride - the buffer row stride. (in ints)
*/
- private native void create(int width, int height, int stride);
+ private native void create(int width, int height, int stride, int[] buf);
/**
* Destroys the cairo surface and frees the buffer.
*/
- private native void destroy(long surfacePointer, long bufferPointer);
-
- /**
- * Gets buffer elements
- */
- private native int nativeGetElem(long bufferPointer, int i);
-
- /**
- * Sets buffer elements.
- */
- private native void nativeSetElem(long bufferPointer, int i, int val);
+ private native void destroy(long surfacePointer, int[] buf);
/**
* Draws this image to a given CairoGraphics context,
@@ -123,33 +120,30 @@ public class CairoSurface extends WritableRaster
double[] i2u, double alpha,
int interpolation);
- public void drawSurface(long contextPointer, double[] i2u, double alpha,
- int interpolation)
- {
- nativeDrawSurface(surfacePointer, contextPointer, i2u, alpha, interpolation);
- }
-
/**
- * getPixels -return the pixels as a java array.
+ * Synchronizes the image's data buffers, copying any changes made in the
+ * Java array into the native array.
+ *
+ * This method should only be called if (sharedBuffers == false).
*/
- native int[] nativeGetPixels(long bufferPointer, int size);
-
- public int[] getPixels(int size)
- {
- return nativeGetPixels(bufferPointer, size);
- }
-
+ native void syncNativeToJava(long surfacePointer, int[] buffer);
+
/**
- * getPixels -return the pixels as a java array.
+ * Synchronizes the image's data buffers, copying any changes made in the
+ * native array into the Java array.
+ *
+ * This method should only be called if (sharedBuffers == false).
*/
- native void nativeSetPixels(long bufferPointer, int[] pixels);
-
- public void setPixels(int[] pixels)
- {
- nativeSetPixels(bufferPointer, pixels);
- }
-
- native long getFlippedBuffer(long bufferPointer, int size);
+ native void syncJavaToNative(long surfacePointer, int[] buffer);
+
+ /**
+ * Return the buffer, with the sample values of each pixel reversed
+ * (ie, in ABGR instead of ARGB).
+ *
+ * @return A pointer to a flipped buffer. The memory is allocated in native
+ * code, and must be explicitly freed when it is no longer needed.
+ */
+ native long getFlippedBuffer(long surfacePointer);
/**
* Create a cairo_surface_t with specified width and height.
@@ -158,20 +152,38 @@ public class CairoSurface extends WritableRaster
*/
public CairoSurface(int width, int height)
{
- super(createCairoSampleModel(width, height),
- null, new Point(0, 0));
+ this(0, 0, width, height);
+ }
+
+ public CairoSurface(int x, int y, int width, int height)
+ {
+ super(createCairoSampleModel(width, height), null, new Point(x, y));
if(width <= 0 || height <= 0)
throw new IllegalArgumentException("Image must be at least 1x1 pixels.");
this.width = width;
this.height = height;
- create(width, height, width);
+ dataBuffer = new DataBufferInt(width * height);
+ create(width, height, width, getData());
- if(surfacePointer == 0 || bufferPointer == 0)
+ if(surfacePointer == 0)
throw new Error("Could not allocate bitmap.");
-
- dataBuffer = new CairoDataBuffer();
+ }
+
+ /**
+ * Create a Cairo Surface that is a subimage of another Cairo Surface
+ */
+ public CairoSurface(SampleModel sm, CairoSurface parent, Rectangle bounds,
+ Point origin)
+ {
+ super(sm, parent.dataBuffer, bounds, origin, parent);
+
+ this.width = super.width;
+ this.height = super.height;
+ this.surfacePointer = parent.surfacePointer;
+ this.sharedBuffer = parent.sharedBuffer;
+ this.dataBuffer = parent.dataBuffer;
}
/**
@@ -188,39 +200,39 @@ public class CairoSurface extends WritableRaster
// Swap ordering from GdkPixbuf to Cairo
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
{
- for (int i = 0; i < data.length; i++ )
- {
- // On a big endian system we get a RRGGBBAA data array.
- int alpha = data[i] & 0xFF;
- if( alpha == 0 ) // I do not know why we need this, but it works.
- data[i] = 0;
- else
- {
- // Cairo needs a ARGB32 native array.
- data[i] = (data[i] >>> 8) | (alpha << 24);
- }
- }
+ for (int i = 0; i < data.length; i++ )
+ {
+ // On a big endian system we get a RRGGBBAA data array.
+ int alpha = data[i] & 0xFF;
+ if( alpha == 0 ) // I do not know why we need this, but it works.
+ data[i] = 0;
+ else
+ {
+ // Cairo needs a ARGB32 native array.
+ data[i] = (data[i] >>> 8) | (alpha << 24);
+ }
+ }
}
else
{
- for (int i = 0; i < data.length; i++ )
- {
- // On a little endian system we get a AABBGGRR data array.
- int alpha = data[i] & 0xFF000000;
- if( alpha == 0 ) // I do not know why we need this, but it works.
- data[i] = 0;
- else
- {
- int b = (data[i] & 0xFF0000) >> 16;
- int g = (data[i] & 0xFF00);
- int r = (data[i] & 0xFF) << 16;
- // Cairo needs a ARGB32 native array.
- data[i] = alpha | r | g | b;
- }
- }
+ for (int i = 0; i < data.length; i++ )
+ {
+ // On a little endian system we get a AABBGGRR data array.
+ int alpha = data[i] & 0xFF000000;
+ if( alpha == 0 ) // I do not know why we need this, but it works.
+ data[i] = 0;
+ else
+ {
+ int b = (data[i] & 0xFF0000) >> 16;
+ int g = (data[i] & 0xFF00);
+ int r = (data[i] & 0xFF) << 16;
+ // Cairo needs a ARGB32 native array.
+ data[i] = alpha | r | g | b;
+ }
+ }
}
- setPixels( data );
+ System.arraycopy(data, 0, getData(), 0, data.length);
}
/**
@@ -228,8 +240,8 @@ public class CairoSurface extends WritableRaster
*/
public void dispose()
{
- if(surfacePointer != 0)
- destroy(surfacePointer, bufferPointer);
+ if(surfacePointer != 0 && parent == null)
+ destroy(surfacePointer, getData());
}
/**
@@ -245,8 +257,17 @@ public class CairoSurface extends WritableRaster
*/
public GtkImage getGtkImage()
{
- return new GtkImage( width, height,
- getFlippedBuffer(bufferPointer, width * height ));
+ return new GtkImage(width, height, getFlippedBuffer(surfacePointer));
+ }
+
+ /**
+ * Convenience method to quickly grab the data array backing this Raster.
+ *
+ * @return The array behind the databuffer.
+ */
+ public int[] getData()
+ {
+ return ((DataBufferInt)dataBuffer).getData();
}
/**
@@ -276,34 +297,6 @@ public class CairoSurface extends WritableRaster
new Hashtable());
}
- private class CairoDataBuffer extends DataBuffer
- {
- public CairoDataBuffer()
- {
- super(DataBuffer.TYPE_INT, width * height);
- }
-
- /**
- * DataBuffer.getElem implementation
- */
- public int getElem(int bank, int i)
- {
- if(bank != 0 || i < 0 || i >= width * height)
- throw new IndexOutOfBoundsException(i+" size: "+width * height);
- return nativeGetElem(bufferPointer, i);
- }
-
- /**
- * DataBuffer.setElem implementation
- */
- public void setElem(int bank, int i, int val)
- {
- if(bank != 0 || i < 0 || i >= width*height)
- throw new IndexOutOfBoundsException(i+" size: "+width * height);
- nativeSetElem(bufferPointer, i, val);
- }
- }
-
/**
* Return a Graphics2D drawing to the CairoSurface.
*/
@@ -325,16 +318,25 @@ public class CairoSurface extends WritableRaster
}
/**
- * Copy an area of the surface. Expects parameters must be within bounds.
- * Count on a segfault otherwise.
+ * Copy a portion of this surface to another area on the surface. The given
+ * parameters must be within bounds - count on a segfault otherwise.
+ *
+ * @param x The x coordinate of the area to be copied from.
+ * @param y The y coordinate of the area to be copied from.
+ * @param width The width of the area to be copied.
+ * @param height The height of the area to be copied.
+ * @param dx The destination x coordinate.
+ * @param dy The destination y coordinate.
+ * @param stride The scanline stride.
*/
- native void copyAreaNative2(long bufferPointer, int x, int y, int width,
- int height, int dx, int dy, int stride);
public void copyAreaNative(int x, int y, int width,
int height, int dx, int dy, int stride)
{
- copyAreaNative2(bufferPointer, x, y, width, height, dx, dy, stride);
+ copyAreaNative2(surfacePointer, x, y, width, height, dx, dy, stride);
}
+ native void copyAreaNative2(long surfacePointer,
+ int x, int y, int width, int height,
+ int dx, int dy, int stride);
/**
* Creates a SampleModel that matches Cairo's native format
@@ -345,4 +347,83 @@ public class CairoSurface extends WritableRaster
new int[]{0x00FF0000, 0x0000FF00,
0x000000FF, 0xFF000000});
}
+
+ /**
+ * Returns whether this ColorModel is compatible with Cairo's native types.
+ *
+ * @param cm The color model to check.
+ * @return Whether it is compatible.
+ */
+ public static boolean isCompatibleColorModel(ColorModel cm)
+ {
+ return (cm.equals(cairoCM_pre) || cm.equals(cairoCM_opaque) ||
+ cm.equals(cairoColorModel));
+ }
+
+ /**
+ * Returns whether this SampleModel is compatible with Cairo's native types.
+ *
+ * @param sm The sample model to check.
+ * @return Whether it is compatible.
+ */
+ public static boolean isCompatibleSampleModel(SampleModel sm)
+ {
+ return (sm instanceof SinglePixelPackedSampleModel
+ && sm.getDataType() == DataBuffer.TYPE_INT
+ && Arrays.equals(((SinglePixelPackedSampleModel)sm).getBitMasks(),
+ new int[]{0x00FF0000, 0x0000FF00,
+ 0x000000FF, 0xFF000000}));
+ }
+
+ ///// Methods interhited from Raster and WritableRaster /////
+ public Raster createChild(int parentX, int parentY, int width, int height,
+ int childMinX, int childMinY, int[] bandList)
+ {
+ return createWritableChild(parentX, parentY, width, height,
+ childMinX, childMinY, bandList);
+ }
+
+ public WritableRaster createCompatibleWritableRaster()
+ {
+ return new CairoSurface(width, height);
+ }
+
+ public WritableRaster createCompatibleWritableRaster (int x, int y,
+ int w, int h)
+ {
+ return new CairoSurface(x, y, w, h);
+ }
+
+ public Raster createTranslatedChild(int childMinX, int childMinY)
+ {
+ return createWritableTranslatedChild(childMinX, childMinY);
+ }
+
+ public WritableRaster createWritableChild(int parentX, int parentY,
+ int w, int h, int childMinX,
+ int childMinY, int[] bandList)
+ {
+ if (parentX < minX || parentX + w > minX + width
+ || parentY < minY || parentY + h > minY + height)
+ throw new RasterFormatException("Child raster extends beyond parent");
+
+ SampleModel sm = (bandList == null) ?
+ sampleModel :
+ sampleModel.createSubsetSampleModel(bandList);
+
+ return new CairoSurface(sm, this,
+ new Rectangle(childMinX, childMinY, w, h),
+ new Point(sampleModelTranslateX + childMinX - parentX,
+ sampleModelTranslateY + childMinY - parentY));
+ }
+
+ public WritableRaster createWritableTranslatedChild(int x, int y)
+ {
+ int tcx = sampleModelTranslateX - minX + x;
+ int tcy = sampleModelTranslateY - minY + y;
+
+ return new CairoSurface(sampleModel, this,
+ new Rectangle(x, y, width, height),
+ new Point(tcx, tcy));
+ }
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java b/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
index 36743b9c2da..35b015f3200 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
@@ -40,6 +40,7 @@ package gnu.java.awt.peer.gtk;
import java.awt.AlphaComposite;
import java.awt.Color;
+import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
@@ -50,7 +51,6 @@ import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
-import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -116,6 +116,18 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
*/
public void draw(Shape s)
{
+ if (!surface.sharedBuffer)
+ surface.syncJavaToNative(surface.surfacePointer, surface.getData());
+
+ // Find total bounds of shape
+ Rectangle r = findStrokedBounds(s);
+ if (shiftDrawCalls)
+ {
+ r.width++;
+ r.height++;
+ }
+
+ // Do the drawing
if (comp == null || comp instanceof AlphaComposite)
super.draw(s);
@@ -126,14 +138,21 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setStroke(this.getStroke());
g2d.setColor(this.getColor());
+ g2d.setTransform(transform);
g2d.draw(s);
- drawComposite(s.getBounds2D(), null);
+ drawComposite(r.getBounds2D(), null);
}
+
+ if (!surface.sharedBuffer)
+ surface.syncNativeToJava(surface.surfacePointer, surface.getData());
}
public void fill(Shape s)
{
+ if (!surface.sharedBuffer)
+ surface.syncJavaToNative(surface.surfacePointer, surface.getData());
+
if (comp == null || comp instanceof AlphaComposite)
super.fill(s);
@@ -144,14 +163,21 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setPaint(this.getPaint());
g2d.setColor(this.getColor());
+ g2d.setTransform(transform);
g2d.fill(s);
drawComposite(s.getBounds2D(), null);
}
+
+ if (!surface.sharedBuffer)
+ surface.syncNativeToJava(surface.surfacePointer, surface.getData());
}
public void drawRenderedImage(RenderedImage image, AffineTransform xform)
{
+ if (!surface.sharedBuffer)
+ surface.syncJavaToNative(surface.surfacePointer, surface.getData());
+
if (comp == null || comp instanceof AlphaComposite)
super.drawRenderedImage(image, xform);
@@ -161,18 +187,25 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setRenderingHints(this.getRenderingHints());
+ g2d.setTransform(transform);
g2d.drawRenderedImage(image, xform);
drawComposite(buffer.getRaster().getBounds(), null);
}
-
+
+ if (!surface.sharedBuffer)
+ surface.syncNativeToJava(surface.surfacePointer, surface.getData());
}
protected boolean drawImage(Image img, AffineTransform xform,
Color bgcolor, ImageObserver obs)
{
+ if (!surface.sharedBuffer)
+ surface.syncJavaToNative(surface.surfacePointer, surface.getData());
+
+ boolean ret;
if (comp == null || comp instanceof AlphaComposite)
- return super.drawImage(img, xform, bgcolor, obs);
+ ret = super.drawImage(img, xform, bgcolor, obs);
else
{
@@ -187,14 +220,10 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
BufferedImage bImg = (BufferedImage) img;
// Find translated bounds
- Point2D origin = new Point2D.Double(bImg.getMinX(), bImg.getMinY());
- Point2D pt = new Point2D.Double(bImg.getWidth() + bImg.getMinX(),
- bImg.getHeight() + bImg.getMinY());
+ Rectangle2D bounds = new Rectangle(bImg.getMinX(), bImg.getMinY(),
+ bImg.getWidth(), bImg.getHeight());
if (xform != null)
- {
- origin = xform.transform(origin, origin);
- pt = xform.transform(pt, pt);
- }
+ bounds = getTransformedBounds(bounds, xform);
// Create buffer and draw image
createBuffer();
@@ -204,15 +233,20 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
g2d.drawImage(img, xform, obs);
// Perform compositing
- return drawComposite(new Rectangle2D.Double(origin.getX(),
- origin.getY(),
- pt.getX(), pt.getY()),
- obs);
+ ret = drawComposite(bounds, obs);
}
+
+ if (!surface.sharedBuffer)
+ surface.syncNativeToJava(surface.surfacePointer, surface.getData());
+
+ return ret;
}
public void drawGlyphVector(GlyphVector gv, float x, float y)
{
+ if (!surface.sharedBuffer)
+ surface.syncJavaToNative(surface.surfacePointer, surface.getData());
+
if (comp == null || comp instanceof AlphaComposite)
super.drawGlyphVector(gv, x, y);
@@ -230,51 +264,64 @@ public class CairoSurfaceGraphics extends CairoGraphics2D
bounds.getWidth(), bounds.getHeight());
drawComposite(bounds, null);
}
+
+ if (!surface.sharedBuffer)
+ surface.syncNativeToJava(surface.surfacePointer, surface.getData());
}
private boolean drawComposite(Rectangle2D bounds, ImageObserver observer)
{
- // Clip source to visible areas that need updating
- Rectangle2D clip = this.getClipBounds();
- Rectangle2D.intersect(bounds, clip, bounds);
- clip = new Rectangle(buffer.getMinX(), buffer.getMinY(),
- buffer.getWidth(), buffer.getHeight());
- Rectangle2D.intersect(bounds, clip, bounds);
+ // Find bounds in device space
+ bounds = getTransformedBounds(bounds, transform);
+
+ // Clip bounds by the stored clip, and by the internal buffer
+ Rectangle2D devClip = this.getClipInDevSpace();
+ Rectangle2D.intersect(bounds, devClip, bounds);
+ devClip = new Rectangle(buffer.getMinX(), buffer.getMinY(),
+ buffer.getWidth(), buffer.getHeight());
+ Rectangle2D.intersect(bounds, devClip, bounds);
+
+ // Round bounds as needed, but be careful in our rounding
+ // (otherwise it may leave unpainted stripes)
+ double x = bounds.getX();
+ double y = bounds.getY();
+ double maxX = x + bounds.getWidth();
+ double maxY = y + bounds.getHeight();
+ x = Math.round(x);
+ y = Math.round(y);
+ bounds.setRect(x, y, Math.round(maxX - x), Math.round(maxY - y));
+ // Find subimage of internal buffer for updating
BufferedImage buffer2 = buffer;
if (!bounds.equals(buffer2.getRaster().getBounds()))
buffer2 = buffer2.getSubimage((int)bounds.getX(), (int)bounds.getY(),
(int)bounds.getWidth(),
(int)bounds.getHeight());
-
- // Get destination clip to bounds
- double[] points = new double[] {bounds.getX(), bounds.getY(),
- bounds.getMaxX(), bounds.getMaxY()};
- transform.transform(points, 0, points, 0, 2);
-
- Rectangle2D deviceBounds = new Rectangle2D.Double(points[0], points[1],
- points[2] - points[0],
- points[3] - points[1]);
-
- Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds);
-
+
+ // Find subimage of main image for updating
BufferedImage current = CairoSurface.getBufferedImage(surface);
- current = current.getSubimage((int)deviceBounds.getX(),
- (int)deviceBounds.getY(),
- (int)deviceBounds.getWidth(),
- (int)deviceBounds.getHeight());
+ current = current.getSubimage((int)bounds.getX(), (int)bounds.getY(),
+ (int)bounds.getWidth(),
+ (int)bounds.getHeight());
// Perform actual composite operation
compCtx.compose(buffer2.getRaster(), current.getRaster(),
buffer2.getRaster());
+ // Set cairo's composite to direct SRC, since we've already done our own
+ // compositing
+ Composite oldcomp = comp;
+ setComposite(AlphaComposite.Src);
+
// This MUST call directly into the "action" method in CairoGraphics2D,
// not one of the wrappers, to ensure that the composite isn't processed
// more than once!
boolean rv = super.drawImage(buffer2,
AffineTransform.getTranslateInstance(bounds.getX(),
bounds.getY()),
- new Color(0,0,0,0), null);
+ null, null);
+ setComposite(oldcomp);
+ updateColor();
return rv;
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java b/libjava/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java
index 8adf275ad44..e54320697d8 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java
@@ -52,7 +52,6 @@ import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
@@ -78,7 +77,7 @@ public class ComponentGraphics extends CairoGraphics2D
protected long cairo_t;
private BufferedImage buffer, componentBuffer;
- private static ThreadLocal hasLock = new ThreadLocal();
+ private static ThreadLocal<Integer> hasLock = new ThreadLocal<Integer>();
private static Integer ONE = Integer.valueOf(1);
ComponentGraphics()
@@ -122,11 +121,11 @@ public class ComponentGraphics extends CairoGraphics2D
*/
private void lock()
{
- Integer i = (Integer) hasLock.get();
+ Integer i = hasLock.get();
if (i == null)
{
- start_gdk_drawing();
- hasLock.set(ONE);
+ start_gdk_drawing();
+ hasLock.set(ONE);
}
else
hasLock.set(Integer.valueOf(i.intValue() + 1));
@@ -137,14 +136,16 @@ public class ComponentGraphics extends CairoGraphics2D
*/
private void unlock()
{
- Integer i = (Integer) hasLock.get();
+ Integer i = hasLock.get();
if (i == null)
throw new IllegalStateException();
if (i == ONE)
{
- hasLock.set(null);
- end_gdk_drawing();
+ hasLock.set(null);
+ end_gdk_drawing();
}
+ else if (i.intValue() == 2)
+ hasLock.set(ONE);
else
hasLock.set(Integer.valueOf(i.intValue() - 1));
}
@@ -176,11 +177,11 @@ public class ComponentGraphics extends CairoGraphics2D
private static native Pointer nativeGrab(GtkComponentPeer component);
private native void copyAreaNative(GtkComponentPeer component, int x, int y,
- int width, int height, int dx, int dy);
+ int width, int height, int dx, int dy);
private native void drawVolatile(GtkComponentPeer component,
- long vimg, int x, int y,
- int width, int height, int cx, int cy,
+ long vimg, int x, int y,
+ int width, int height, int cx, int cy,
int cw, int ch);
/**
@@ -232,16 +233,16 @@ public class ComponentGraphics extends CairoGraphics2D
{
if (comp == null || comp instanceof AlphaComposite)
super.draw(s);
-
+
else
{
createBuffer();
-
+
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setStroke(this.getStroke());
g2d.setColor(this.getColor());
g2d.draw(s);
-
+
drawComposite(s.getBounds2D(), null);
}
}
@@ -250,16 +251,16 @@ public class ComponentGraphics extends CairoGraphics2D
{
if (comp == null || comp instanceof AlphaComposite)
super.fill(s);
-
+
else
{
createBuffer();
-
+
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setPaint(this.getPaint());
g2d.setColor(this.getColor());
g2d.fill(s);
-
+
drawComposite(s.getBounds2D(), null);
}
}
@@ -268,7 +269,7 @@ public class ComponentGraphics extends CairoGraphics2D
{
if (comp == null || comp instanceof AlphaComposite)
super.drawRenderedImage(image, xform);
-
+
else
{
createBuffer();
@@ -276,7 +277,7 @@ public class ComponentGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setRenderingHints(this.getRenderingHints());
g2d.drawRenderedImage(image, xform);
-
+
drawComposite(buffer.getRaster().getBounds(), null);
}
}
@@ -287,7 +288,7 @@ public class ComponentGraphics extends CairoGraphics2D
boolean rv;
if (comp == null || comp instanceof AlphaComposite)
rv = super.drawImage(img, xform, bgcolor, obs);
-
+
else
{
// Get buffered image of source
@@ -299,7 +300,7 @@ public class ComponentGraphics extends CairoGraphics2D
img = Toolkit.getDefaultToolkit().createImage(source);
}
BufferedImage bImg = (BufferedImage) img;
-
+
// Find translated bounds
Point2D origin = new Point2D.Double(bImg.getMinX(), bImg.getMinY());
Point2D pt = new Point2D.Double(bImg.getWidth() + bImg.getMinX(),
@@ -309,18 +310,18 @@ public class ComponentGraphics extends CairoGraphics2D
origin = xform.transform(origin, origin);
pt = xform.transform(pt, pt);
}
-
+
// Create buffer and draw image
createBuffer();
-
+
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setRenderingHints(this.getRenderingHints());
g2d.drawImage(img, xform, obs);
// Perform compositing
rv = drawComposite(new Rectangle2D.Double(origin.getX(),
- origin.getY(),
- pt.getX(), pt.getY()),
+ origin.getY(),
+ pt.getX(), pt.getY()),
obs);
}
return rv;
@@ -330,7 +331,7 @@ public class ComponentGraphics extends CairoGraphics2D
{
if (comp == null || comp instanceof AlphaComposite)
super.drawGlyphVector(gv, x, y);
-
+
else
{
createBuffer();
@@ -339,7 +340,7 @@ public class ComponentGraphics extends CairoGraphics2D
g2d.setPaint(this.getPaint());
g2d.setStroke(this.getStroke());
g2d.drawGlyphVector(gv, x, y);
-
+
Rectangle2D bounds = gv.getLogicalBounds();
bounds = new Rectangle2D.Double(x + bounds.getX(), y + bounds.getY(),
bounds.getWidth(), bounds.getHeight());
@@ -373,8 +374,8 @@ public class ComponentGraphics extends CairoGraphics2D
(int) r.getHeight());
return true;
}
- else
- return super.drawImage(vimg.getSnapshot(), x, y, observer);
+ else
+ return super.drawImage(vimg.getSnapshot(), x, y, observer);
}
BufferedImage bimg;
@@ -382,7 +383,7 @@ public class ComponentGraphics extends CairoGraphics2D
bimg = (BufferedImage) img;
else
{
- ImageProducer source = img.getSource();
+ ImageProducer source = img.getSource();
if (source == null)
return false;
bimg = (BufferedImage) Toolkit.getDefaultToolkit().createImage(source);
@@ -418,9 +419,9 @@ public class ComponentGraphics extends CairoGraphics2D
(int) r.getHeight());
return true;
}
- else
- return super.drawImage(vimg.getSnapshot(), x, y,
- width, height, observer);
+ else
+ return super.drawImage(vimg.getSnapshot(), x, y,
+ width, height, observer);
}
BufferedImage bimg;
@@ -429,7 +430,7 @@ public class ComponentGraphics extends CairoGraphics2D
bimg = (BufferedImage) img;
else
{
- ImageProducer source = img.getSource();
+ ImageProducer source = img.getSource();
if (source == null)
return false;
bimg = (BufferedImage) Toolkit.getDefaultToolkit().createImage(source);
@@ -458,8 +459,8 @@ public class ComponentGraphics extends CairoGraphics2D
transform.transform(points, 0, points, 0, 2);
Rectangle2D deviceBounds = new Rectangle2D.Double(points[0], points[1],
- points[2] - points[0],
- points[3] - points[1]);
+ points[2] - points[0],
+ points[3] - points[1]);
Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds);
@@ -519,8 +520,8 @@ public class ComponentGraphics extends CairoGraphics2D
new Point(0,0));
componentBuffer = new BufferedImage(GtkVolatileImage.gdkColorModel, rst,
- GtkVolatileImage.gdkColorModel.isAlphaPremultiplied(),
- new Hashtable());
+ GtkVolatileImage.gdkColorModel.isAlphaPremultiplied(),
+ new Hashtable());
}
}
@@ -723,7 +724,7 @@ public class ComponentGraphics extends CairoGraphics2D
unlock();
}
}
-
+
@Override
protected void cairoRectangle(long pointer, double x, double y,
double width, double height)
@@ -908,4 +909,33 @@ public class ComponentGraphics extends CairoGraphics2D
unlock();
}
}
+
+ @Override
+ protected void cairoSetAntialias(long pointer, boolean aa)
+ {
+ try
+ {
+ lock();
+ super.cairoSetAntialias(pointer, aa);
+ }
+ finally
+ {
+ unlock();
+ }
+ }
+
+ @Override
+ protected void drawCairoSurface(CairoSurface surface, AffineTransform tx,
+ double alpha, int interpolation)
+ {
+ try
+ {
+ lock();
+ super.drawCairoSurface(surface, tx, alpha, interpolation);
+ }
+ finally
+ {
+ unlock();
+ }
+ }
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java b/libjava/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
index 131a964488f..280f3e6fbcd 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
@@ -79,6 +79,11 @@ public class FreetypeGlyphVector extends GlyphVector
* The glyph codes
*/
private int[] glyphCodes;
+
+ /**
+ * The set of fonts used in this glyph vector.
+ */
+ private long[] fontSet = null;
/**
* Glyph transforms. (de facto only the translation is used)
@@ -86,6 +91,19 @@ public class FreetypeGlyphVector extends GlyphVector
private AffineTransform[] glyphTransforms;
private GlyphMetrics[] metricsCache;
+
+ private native void dispose(long[] fonts);
+
+ /**
+ * Returns a pointer to the native PangoFcFont object.
+ *
+ * The object will be referenced with g_object_ref n times before being
+ * returned, and must be unreferenced a corresponding number of times.
+ *
+ * @param n Number of times to reference the object.
+ * @return Pointer to the native default font.
+ */
+ private native long getNativeFontPointer(int n);
/**
* Create a glyphvector from a given (Freetype) font and a String.
@@ -112,11 +130,11 @@ public class FreetypeGlyphVector extends GlyphVector
getGlyphs();
if( flags == Font.LAYOUT_RIGHT_TO_LEFT )
{
- // reverse the glyph ordering.
- int[] temp = new int[ nGlyphs ];
- for(int i = 0; i < nGlyphs; i++)
- temp[ i ] = glyphCodes[ nGlyphs - i - 1];
- glyphCodes = temp;
+ // reverse the glyph ordering.
+ int[] temp = new int[ nGlyphs ];
+ for(int i = 0; i < nGlyphs; i++)
+ temp[i] = glyphCodes[nGlyphs - i - 1];
+ glyphCodes = temp;
}
performDefaultLayout();
}
@@ -135,6 +153,13 @@ public class FreetypeGlyphVector extends GlyphVector
glyphCodes = new int[ codes.length ];
System.arraycopy(codes, 0, glyphCodes, 0, codes.length);
nGlyphs = glyphCodes.length;
+
+ if (fontSet == null)
+ {
+ fontSet = new long[nGlyphs];
+ Arrays.fill(fontSet, getNativeFontPointer(nGlyphs));
+ }
+
performDefaultLayout();
}
@@ -152,11 +177,12 @@ public class FreetypeGlyphVector extends GlyphVector
if( gv.metricsCache != null )
{
- metricsCache = new GlyphMetrics[ nGlyphs ];
- System.arraycopy(gv.metricsCache, 0, metricsCache, 0, nGlyphs);
+ metricsCache = new GlyphMetrics[ nGlyphs ];
+ System.arraycopy(gv.metricsCache, 0, metricsCache, 0, nGlyphs);
}
glyphCodes = new int[ nGlyphs ];
+ fontSet = new long[nGlyphs];
glyphPositions = new float[(nGlyphs + 1) * 2];
glyphTransforms = new AffineTransform[ nGlyphs ];
for(int i = 0; i < nGlyphs; i++ )
@@ -166,6 +192,13 @@ public class FreetypeGlyphVector extends GlyphVector
}
System.arraycopy(gv.glyphPositions, 0, glyphPositions, 0,
glyphPositions.length);
+ System.arraycopy(gv.glyphCodes, 0, glyphCodes, 0, nGlyphs);
+ System.arraycopy(gv.fontSet, 0, fontSet, 0, nGlyphs);
+ }
+
+ public void finalize()
+ {
+ dispose(fontSet);
}
/**
@@ -175,16 +208,17 @@ public class FreetypeGlyphVector extends GlyphVector
{
nGlyphs = s.codePointCount( 0, s.length() );
glyphCodes = new int[ nGlyphs ];
+ fontSet = new long[ nGlyphs ];
int[] codePoints = new int[ nGlyphs ];
int stringIndex = 0;
for(int i = 0; i < nGlyphs; i++)
{
- codePoints[i] = s.codePointAt( stringIndex );
+ codePoints[i] = s.codePointAt( stringIndex );
// UTF32 surrogate handling
- if( codePoints[i] != (int)s.charAt( stringIndex ) )
- stringIndex ++;
- stringIndex ++;
+ if( codePoints[i] != (int)s.charAt( stringIndex ) )
+ stringIndex ++;
+ stringIndex ++;
if (Character.isISOControl(codePoints[i]))
{
@@ -194,22 +228,22 @@ public class FreetypeGlyphVector extends GlyphVector
}
}
- glyphCodes = getGlyphs( codePoints );
+ getGlyphs( codePoints, glyphCodes, fontSet );
}
/**
* Returns the glyph code within the font for a given character
*/
- public native int[] getGlyphs(int[] codepoints);
+ public native void getGlyphs(int[] codepoints, int[] glyphs, long[] fonts);
/**
* Returns the kerning of a glyph pair
*/
- private native Point2D getKerning(int leftGlyph, int rightGlyph);
+ private native Point2D getKerning(int leftGlyph, int rightGlyph, long font);
- private native double[] getMetricsNative( int glyphCode );
+ private native double[] getMetricsNative(int glyphCode, long font);
- private native GeneralPath getGlyphOutlineNative(int glyphIndex);
+ private native GeneralPath getGlyphOutlineNative(int glyphIndex, long font);
public Object clone()
@@ -267,10 +301,12 @@ public class FreetypeGlyphVector extends GlyphVector
x += gm.getAdvanceX();
y += gm.getAdvanceY();
-
- if (i != nGlyphs-1)
+
+ // Get the kerning only if it's not the last glyph, and the two glyphs are
+ // using the same font
+ if (i != nGlyphs-1 && fontSet[i] == fontSet[i+1])
{
- Point2D p = getKerning(glyphCodes[i], glyphCodes[i + 1]);
+ Point2D p = getKerning(glyphCodes[i], glyphCodes[i + 1], fontSet[i]);
x += p.getX();
y += p.getY();
}
@@ -291,7 +327,7 @@ public class FreetypeGlyphVector extends GlyphVector
* Returns multiple glyphcodes.
*/
public int[] getGlyphCodes(int beginGlyphIndex, int numEntries,
- int[] codeReturn)
+ int[] codeReturn)
{
int[] rval;
@@ -305,6 +341,26 @@ public class FreetypeGlyphVector extends GlyphVector
return rval;
}
+ /**
+ * Returns pointers to the fonts used in this glyph vector.
+ *
+ * The array index matches that of the glyph vector itself.
+ */
+ protected long[] getGlyphFonts(int beginGlyphIndex, int numEntries,
+ long[] codeReturn)
+ {
+ long[] rval;
+
+ if( codeReturn == null || codeReturn.length < numEntries)
+ rval = new long[ numEntries ];
+ else
+ rval = codeReturn;
+
+ System.arraycopy(fontSet, beginGlyphIndex, rval, 0, numEntries);
+
+ return rval;
+ }
+
public Shape getGlyphLogicalBounds(int glyphIndex)
{
GlyphMetrics gm = getGlyphMetrics( glyphIndex );
@@ -335,26 +391,24 @@ public class FreetypeGlyphVector extends GlyphVector
for(int i = 0; i < nGlyphs; i++)
{
- GlyphMetrics gm = (GlyphMetrics)
- peer.getGlyphMetrics( glyphCodes[ i ] );
- if( gm == null )
- {
- double[] val = getMetricsNative( glyphCodes[ i ] );
- if( val == null )
- gm = null;
- else
- {
- gm = new GlyphMetrics( true,
- (float)val[1],
- (float)val[2],
- new Rectangle2D.Double
- ( val[3], val[4],
- val[5], val[6] ),
- GlyphMetrics.STANDARD );
- peer.putGlyphMetrics( glyphCodes[ i ], gm );
- }
- }
- metricsCache[ i ] = gm;
+ GlyphMetrics gm = (GlyphMetrics)peer.getGlyphMetrics(glyphCodes[i]);
+ if( gm == null )
+ {
+ double[] val = getMetricsNative(glyphCodes[i], fontSet[i]);
+ if( val == null )
+ gm = null;
+ else
+ {
+ gm = new GlyphMetrics(true,
+ (float)val[1],
+ (float)val[2],
+ new Rectangle2D.Double(val[3], val[4],
+ val[5], val[6] ),
+ GlyphMetrics.STANDARD );
+ peer.putGlyphMetrics( glyphCodes[ i ], gm );
+ }
+ }
+ metricsCache[ i ] = gm;
}
}
@@ -371,13 +425,21 @@ public class FreetypeGlyphVector extends GlyphVector
/**
* Returns the outline of a single glyph.
+ *
+ * Despite what the Sun API says, this method returns the glyph relative to
+ * the origin of the *entire string*, not each individual glyph.
*/
public Shape getGlyphOutline(int glyphIndex)
{
- GeneralPath gp = getGlyphOutlineNative( glyphCodes[ glyphIndex ] );
- if (glyphTransforms[glyphIndex] != null)
- gp.transform( glyphTransforms[glyphIndex]);
+ GeneralPath gp = getGlyphOutlineNative(glyphCodes[glyphIndex],
+ fontSet[glyphIndex]);
+ AffineTransform tx = AffineTransform.getTranslateInstance(glyphPositions[glyphIndex*2],
+ glyphPositions[glyphIndex*2+1]);
+ if (glyphTransforms[glyphIndex] != null)
+ tx.concatenate( glyphTransforms[glyphIndex]);
+
+ gp.transform(tx);
return gp;
}
@@ -432,7 +494,6 @@ public class FreetypeGlyphVector extends GlyphVector
return logicalBounds;
Rectangle2D rect = (Rectangle2D)getGlyphLogicalBounds( 0 );
- AffineTransform tx = new AffineTransform();
for( int i = 1; i < nGlyphs; i++ )
{
Rectangle2D r2 = (Rectangle2D)getGlyphLogicalBounds( i );
@@ -458,14 +519,8 @@ public class FreetypeGlyphVector extends GlyphVector
public Shape getOutline()
{
GeneralPath path = new GeneralPath();
- AffineTransform tx = new AffineTransform();
for( int i = 0; i < getNumGlyphs(); i++ )
- {
- Shape outline = getGlyphOutline(i);
- tx.setToTranslation(glyphPositions[i*2], glyphPositions[i*2 +1]);
- outline = tx.createTransformedShape(outline);
- path.append(outline, false);
- }
+ path.append(getGlyphOutline(i), false);
return path;
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GThreadMutex.java b/libjava/classpath/gnu/java/awt/peer/gtk/GThreadMutex.java
deleted file mode 100644
index e73df9e5509..00000000000
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GThreadMutex.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/* GThreadMutex.java -- Implements a mutex object for glib's gthread
- abstraction, for use with GNU Classpath's --portable-native-sync option.
- This is used in gthread-jni.c
-
- 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., 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.gtk;
-
-/** Implements a mutex object for glib's gthread
- abstraction, for use with GNU Classpath's --portable-native-sync option.
- This is used in gthread-jni.c.
-
- We use this object to implement the POSIX semantics for Mutexes. They are
- needed are needed for the function vector that is passed to glib's
- g_thread subpackage's initialization function.
-
- The GThreadMutex object itself serves as the Real Lock; if code has
- entered the monitor for this GThreadMutex object (in Java language, if
- it's synchronized on this object) then it holds the lock that this object
- represents.
-
- @author Steven Augart
- May, 2004
-
-
-*/
-
-class GThreadMutex
-{
- /** Might "lock" be locked? Is anyone waiting
- to get that lock? How long is the queue?
-
- If zero, nobody holds a lock on this GThreadMutex object, and nobody is
- trying to get one. Before someone attempts to acquire a lock on this
- object, they must increment potentialLockers. After they release their
- lock on this object, they must decrement potentialLockers.
-
- Access to this field is guarded by synchronizing on the object
- <code>lockForPotentialLockers</code>.
-
- After construction, we only access this field via JNI.
- */
- volatile int potentialLockers;
-
- /** An object to synchronize to if you want to examine or modify the
- <code>potentialLockers</code> field. Only hold this lock for brief
- moments, just long enough to check or set the value of
- <code>lockForPotentialLockers</code>.
-
- We use this representation so that g_thread_mutex_trylock() will work
- with the POSIX semantics. This is the only case in which you ever hold a
- lock on <code>lockForPotentialLockers</code> while trying to get another
- lock -- if you are the mutex_trylock() implementation, and you have just
- checked that <code>potentialLockers</code> has the value zero. In that
- case, mutex_trylock() holds the lock on lockForPotentialLockers so that
- another thread calling mutex_trylock() or mutex_lock() won't increment
- potentialLockers after we've checked it and before we've gained the lock
- on the POSIX mutex. Of course, in that case the operation of gaining
- the POSIX lock itself will succeed immediately, and once it has
- succeeded, trylock releases lockForPotentialLockers right away,
- incremented to 1 (one).
-
- After construction, we only access this field via JNI.
- */
- Object lockForPotentialLockers;
-
- GThreadMutex()
- {
- potentialLockers = 0;
- lockForPotentialLockers = new Object();
- }
-}
-// Local Variables:
-// c-file-style: "gnu"
-// End:
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java b/libjava/classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java
deleted file mode 100644
index 9a1b8e3a30a..00000000000
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/* GThreadNativeMethodRunner.java -- Implements pthread_create(), under
- glib's gthread abstraction, for use with GNU Classpath's
- --portable-native-sync option.
- This is used by gthread-jni.c
-
- Copyright (C) 2004, 2005 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.gtk;
-
-import java.lang.ref.WeakReference;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/** Implements pthread_create(), under glib's gthread abstraction, for use
- with GNU Classpath's --portable-native-sync option. This is used in
- gthread-jni.c
-
- Also implements a registry for threads, mapping Thread objects to small
- integers. The registry uses weak references for threads that aren't
- joinable, so that they will be garbage collected.
-
- There are a number of possible alternative implementations.
-
-
- The rest of this comment consists of an answer to a question that was
- raised on the commit-classpath mailing list:
-
- Mark Wielaard wrote:
-
- > Can't we assume that jobject and gpointer are both (void *) so we don't
- > need the int <-> Thread (global jobject ref) mapping?
- > Maybe there are platforms where jobject and gpointer aren't the same,
- > but I guess that is pretty unlikely.
-
-
- I agree with you on the pointer size issues. A gpointer is a void *, so
- it's certainly guaranteed to be at least as large as any other
- pointer. And a jobject is implicitly an opaque pointer (in Jikes RVM, we
- use small integers, but we coerce them into the representation of a
- pointer).
-
- The int <==> Thread mapping addresses a different issue. I realize that I
- did not document this properly (two and a half lines in thread_create),
- and the point is subtle (at least to me; took me a while to figure out).
-
- The int => Thread mapping always returns jobjects that are local
- references, not global ones. This is because Thread objects need to be
- able to go away and be garbage collected after the thread they refer to
- has died.
-
- If we keep a global object reference to a thread, then when do we delete
- that global object reference? We have an answer in the case of GThread
- objects that were explicitly created with the joinable attribute. It is
- safe for us to maintain a global reference to any joinable thread, since
- the joinable thread must linger (even if only in a zombie state)
- until it's explicitly joined via a g_thread_join() call. The global ref
- could be cleaned up at that point too.
-
- However, in the case of GThreads that were created non-joinable by
- g_thread_create(), and in the case of Java threads that were created
- within pure Java code (not via g_thread_create()), we don't want them to
- linger forever, and there is no way to tell when the last reference
- to such threads needs to expire. In the case of this application -- AWT
- with GTK peers -- it would probably be safe anyway, since there are not
- very many threads we create, but I was going for correctness even in the
- case of long-running programs that might set up and tear down AWT
- interfaces many times.
-
- So, I duplicated the POSIX thread-ID semantics. The thread ID of a
- non-joinable thread remains valid as long as that thread is still alive.
- Once that thread dies, the old thread ID may be reused at any moment. And
- that's why the array indexed by thread ID numbers is an array of weak
- references.
-
- That's also why the int => Thread jobject mapping function always returns
- local references, since global references would lock the Thread in memory
- forever.
-
- I would dearly love there to be a cleaner solution. I dislike the
- repeated dips from C code into Java that are necessary to look up thread
- ID numbers. If anyone can think of one, I'm all ears.
-*/
-
-class GThreadNativeMethodRunner
- extends Thread
-{
- /** The C function pointer that was passed to g_thread_create().
- Specifically, this the numeric address of an object of
- C type "void *(*funcPtr)(void *funcArg)".
- */
- private final long funcPtr;
-
- /** The argument for the function "funcPtr(funcArg)". */
- private final long funcArg;
-
- GThreadNativeMethodRunner(long funcPtr, long funcArg, boolean joinable)
- {
- this.funcPtr = funcPtr;
- this.funcArg = funcArg;
-
- if (joinable)
- registerSelfJoinable();
- }
-
- public void run()
- {
- nativeRun(funcPtr, funcArg);
- }
-
- private native void nativeRun(long funcPtr, long funcArg);
-
- /** THREADS is an array of threads, indexed by thread ID codes. Not sure
- whether this is the "best" approach but it does make it O(1) to look up a
- thread by its ID.
-
- Zero is a valid thread ID code. Any negative number is invalid.
-
- Possible future fixes (TODO?)
-
- - The THREADS array will only grow. probably not a problem.
- But we could keep count when nulling entries and shrink when we have
- lots of nulls at the end. Probably not worth it. --mjw
-
- - Could make this a set of Object; see the comment on "joinable" below.
-
- The initial size of 17 is just a starting point. Any number will do,
- including zero.
- */
- private static WeakReference[] threads = new WeakReference[17];
-
- /** Used by threadToThreadID, below. Returns the registration number of
- the newly-registered thread.
- */
- private static synchronized int registerThread(Thread t)
- {
- int i;
-
- for (i = 0; i < threads.length; ++i)
- {
- WeakReference ref = threads[i];
- if (ref == null)
- break; // found an empty spot.
- }
-
- if (i == threads.length)
- {
- /* expand the array */
- WeakReference[] bigger = new WeakReference[threads.length * 2];
- System.arraycopy(threads, 0, bigger, 0, threads.length);
- threads = bigger;
- }
-
- threads[i] = new WeakReference(t);
-
- return i;
- }
-
- /** Look up the Thread ID # for a Thread. Assign a Thread ID # if none
- exists. This is a general routine for handling all threads, including
- the VM's main thread, if appropriate.
-
-
- Runs in O(n/2) time.
-
- We can't just issue a threadID upon thread creation. If we were to do
- that, not all threads would have a threadID, because not all threads
- are launched by GThreadNativeMethodRunner.
- */
- static synchronized int threadToThreadID(Thread t)
- {
- for (int i = 0; i < threads.length; ++i )
- {
- if (threads[i] == null)
- continue;
- Thread referent = (Thread) threads[i].get();
- if (referent == null)
- {
- threads[i] = null; // Purge the dead WeakReference.
- continue;
- }
- if (referent.equals(t))
- return i;
- } // for()
-
- /* No match found. */
- return registerThread(t);
- }
-
- /** @param threadID Must be a non-negative integer.
-
- Used to return null if the thread number was out of range or if
- the thread was unregistered. Now we throw an exception.
-
- Possible Alternative Interface: We could go back to returning null in
- some sort of check-free mode, so code that calls this function must
- be prepared to get null.
- */
- static Thread threadIDToThread(int threadID)
- throws IllegalArgumentException
- {
- if (threadID < 0)
- throw new IllegalArgumentException("Received a negative threadID, "
- + threadID);
- if (threadID >= threads.length)
- throw new IllegalArgumentException("Received a threadID (" + threadID
- + ") higher than was"
- + " ever issued");
-
- /* Note: if the user is using a stale reference, things will just
- break. We might end up getting a different thread than the one
- expected.
-
- TODO: Add an error-checking mode where the user's problems with threads
- are announced. For instance, if the user asks for the thread
- associated with a threadID that was never issued, we could print a
- warning or even abort.
-
- TODO: Consider optionally disabling all of the error-checking we
- already have; it probably slows down the implementation. We could
- just return NULL. This is just the reverse of the above TODO item.
- */
-
- WeakReference threadRef = threads[threadID];
-
- if (threadRef == null)
- throw new IllegalArgumentException("Asked to look up a stale or unissued"
- + "threadID (" + threadID + ")" );
-
-
- Thread referent = (Thread) threadRef.get();
- if (referent == null)
- throw new IllegalArgumentException ("Asked to look up a stale threadID ("
- + threadID + ")");
- return referent;
- }
-
- /** Joinable threads need a hard reference, so that they won't go away when
- they die. That is because their thread IDs need to stay valid until the
- thread is joined via thread_join(threadID). Joinable threads have to be
- explicitly joined before they are allowed to go away completely.
-
- Possible Alternative Implementation: Eliminate the Joinable set. When
- calling getThreadIDFromThread() you know whether or not the thread
- is joinable. So just store the Thread itself in the threads array?
- Make that array an Object array and check with instanceof. This
- looks cleaner and more robust to me and it saves a native -> Java
- call. But instanceof might be expensive. --mjw
- */
- private static final Set joinable =
- Collections.synchronizedSet(new HashSet());
-
- /** Only called from the constructor. */
- private void registerSelfJoinable()
- {
- joinable.add(this);
- }
-
- /** This method is only called from JNI, and only after we have succeeded in
- a thread_join() operation. */
- static void deRegisterJoinable(Thread thread)
- {
- joinable.remove(thread);
- }
-}
-
-// Local Variables:
-// c-file-style: "gnu"
-// End:
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java
index 5f5126ac590..c3c94d8a935 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java
@@ -67,7 +67,7 @@ public class GdkFontPeer extends ClasspathFontPeer
* The size of the cache has been chosen so that relativly large GUIs with
* text documents are still efficient.
*/
- HashMap textLayoutCache = new GtkToolkit.LRUCache(500);
+ HashMap<String,TextLayout> textLayoutCache = new GtkToolkit.LRUCache<String,TextLayout>(500);
private class GdkFontMetrics extends FontMetrics
{
@@ -79,7 +79,7 @@ public class GdkFontPeer extends ClasspathFontPeer
public int stringWidth (String str)
{
- TextLayout tl = (TextLayout) textLayoutCache.get(str);
+ TextLayout tl = textLayoutCache.get(str);
if (tl == null)
{
tl = new TextLayout(str, font, DEFAULT_CTX);
@@ -140,7 +140,7 @@ public class GdkFontPeer extends ClasspathFontPeer
/**
* Cache GlyphMetrics objects.
*/
- private HashMap metricsCache;
+ private HashMap<Integer,GlyphMetrics> metricsCache;
private static final int FONT_METRICS_ASCENT = 0;
private static final int FONT_METRICS_MAX_ASCENT = 1;
@@ -235,7 +235,7 @@ public class GdkFontPeer extends ClasspathFontPeer
super(name, style, size);
initState ();
setFont (this.familyName, this.style, (int)this.size);
- metricsCache = new HashMap();
+ metricsCache = new HashMap<Integer,GlyphMetrics>();
setupMetrics();
}
@@ -244,7 +244,7 @@ public class GdkFontPeer extends ClasspathFontPeer
super(name, attributes);
initState ();
setFont (this.familyName, this.style, (int)this.size);
- metricsCache = new HashMap();
+ metricsCache = new HashMap<Integer,GlyphMetrics>();
setupMetrics();
}
@@ -261,9 +261,9 @@ public class GdkFontPeer extends ClasspathFontPeer
return font;
else
{
- ClasspathToolkit toolkit;
- toolkit = (ClasspathToolkit) Toolkit.getDefaultToolkit();
- return toolkit.getFont(font.getName(), font.getAttributes());
+ ClasspathToolkit toolkit;
+ toolkit = (ClasspathToolkit) Toolkit.getDefaultToolkit();
+ return toolkit.getFont(font.getName(), font.getAttributes());
}
}
@@ -294,9 +294,9 @@ public class GdkFontPeer extends ClasspathFontPeer
name = getName(NameDecoder.NAME_SUBFAMILY, locale);
if (name == null)
{
- name = getName(NameDecoder.NAME_SUBFAMILY, Locale.ENGLISH);
- if ("Regular".equals(name))
- name = null;
+ name = getName(NameDecoder.NAME_SUBFAMILY, Locale.ENGLISH);
+ if ("Regular".equals(name))
+ name = null;
}
return name;
@@ -340,12 +340,12 @@ public class GdkFontPeer extends ClasspathFontPeer
{
if (nameTable == null)
{
- byte[] data = getTrueTypeTable((byte)'n', (byte) 'a',
- (byte) 'm', (byte) 'e');
- if( data == null )
- return null;
+ byte[] data = getTrueTypeTable((byte)'n', (byte) 'a',
+ (byte) 'm', (byte) 'e');
+ if( data == null )
+ return null;
- nameTable = ByteBuffer.wrap( data );
+ nameTable = ByteBuffer.wrap( data );
}
return NameDecoder.getName(nameTable, name, locale);
@@ -492,8 +492,8 @@ public class GdkFontPeer extends ClasspathFontPeer
char[] chars, int start, int limit,
int flags)
{
- return new FreetypeGlyphVector( font, chars, start, limit - start,
- frc, flags);
+ return new FreetypeGlyphVector(font, chars, start, limit - start,
+ frc, flags);
}
public LineMetrics getLineMetrics (Font font, String str,
@@ -515,13 +515,13 @@ public class GdkFontPeer extends ClasspathFontPeer
*/
GlyphMetrics getGlyphMetrics( int glyphCode )
{
- return (GlyphMetrics)metricsCache.get( new Integer( glyphCode ) );
+ return metricsCache.get(new Integer(glyphCode));
}
/**
* Put a GlyphMetrics object in the cache.
*/
- void putGlyphMetrics( int glyphCode, Object metrics )
+ void putGlyphMetrics( int glyphCode, GlyphMetrics metrics )
{
metricsCache.put( new Integer( glyphCode ), metrics );
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java
index db725b697df..bd6daa2d1e5 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java
@@ -38,16 +38,21 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
+import gnu.java.awt.ClasspathGraphicsEnvironment;
+
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
import java.awt.image.Raster;
+import java.awt.image.SampleModel;
+import java.awt.image.WritableRaster;
import java.util.Locale;
-public class GdkGraphicsEnvironment extends GraphicsEnvironment
+public class GdkGraphicsEnvironment extends ClasspathGraphicsEnvironment
{
private final int native_state = GtkGenericPeer.getUniqueInteger ();
@@ -139,4 +144,13 @@ public class GdkGraphicsEnvironment extends GraphicsEnvironment
* Used by GtkMouseInfoPeer.
*/
native int[] getMouseCoordinates();
+
+ public WritableRaster createRaster(ColorModel cm, SampleModel sm)
+ {
+ if (CairoSurface.isCompatibleSampleModel(sm)
+ && CairoSurface.isCompatibleColorModel(cm))
+ return new CairoSurface(sm.getWidth(), sm.getHeight());
+ else
+ return null;
+ }
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
index 6d0a52b91be..6f6ea560db7 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
@@ -184,22 +184,22 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
int len = 0;
synchronized(pixbufLock)
{
- initState();
+ initState();
}
needsClose = true;
// Note: We don't want the pixbufLock while reading from the InputStream.
while ((len = is.read (bytes)) != -1)
{
- synchronized(pixbufLock)
- {
- pumpBytes (bytes, len);
- }
+ synchronized(pixbufLock)
+ {
+ pumpBytes (bytes, len);
+ }
}
synchronized(pixbufLock)
{
- pumpDone();
+ pumpDone();
}
needsClose = false;
@@ -217,7 +217,7 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
{
synchronized(pixbufLock)
{
- finish(needsClose);
+ finish(needsClose);
}
}
@@ -226,8 +226,8 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
{
public String name;
public boolean writable = false;
- public ArrayList mimeTypes = new ArrayList();
- public ArrayList extensions = new ArrayList();
+ public ArrayList<String> mimeTypes = new ArrayList<String>();
+ public ArrayList<String> extensions = new ArrayList<String>();
public ImageFormatSpec(String name, boolean writable)
{
@@ -246,7 +246,7 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
}
}
- static ArrayList imageFormatSpecs;
+ static ArrayList<ImageFormatSpec> imageFormatSpecs;
public static ImageFormatSpec registerFormat(String name, boolean writable)
{
@@ -254,7 +254,7 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
synchronized(GdkPixbufDecoder.class)
{
if (imageFormatSpecs == null)
- imageFormatSpecs = new ArrayList();
+ imageFormatSpecs = new ArrayList<ImageFormatSpec>();
imageFormatSpecs.add(ifs);
}
return ifs;
@@ -262,13 +262,13 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
static String[] getFormatNames(boolean writable)
{
- ArrayList names = new ArrayList();
+ ArrayList<String> names = new ArrayList<String>();
synchronized (imageFormatSpecs)
{
- Iterator i = imageFormatSpecs.iterator();
+ Iterator<ImageFormatSpec> i = imageFormatSpecs.iterator();
while (i.hasNext())
{
- ImageFormatSpec ifs = (ImageFormatSpec) i.next();
+ ImageFormatSpec ifs = i.next();
if (writable && !ifs.writable)
continue;
names.add(ifs.name);
@@ -279,62 +279,50 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
* This generally means "all the extensions people might use".
*/
- Iterator j = ifs.extensions.iterator();
+ Iterator<String> j = ifs.extensions.iterator();
while (j.hasNext())
- names.add((String) j.next());
+ names.add(j.next());
}
}
- Object[] objs = names.toArray();
- String[] strings = new String[objs.length];
- for (int i = 0; i < objs.length; ++i)
- strings[i] = (String) objs[i];
- return strings;
+ return names.toArray(new String[names.size()]);
}
static String[] getFormatExtensions(boolean writable)
{
- ArrayList extensions = new ArrayList();
+ ArrayList<String> extensions = new ArrayList<String>();
synchronized (imageFormatSpecs)
{
- Iterator i = imageFormatSpecs.iterator();
+ Iterator<ImageFormatSpec> i = imageFormatSpecs.iterator();
while (i.hasNext())
{
- ImageFormatSpec ifs = (ImageFormatSpec) i.next();
+ ImageFormatSpec ifs = i.next();
if (writable && !ifs.writable)
continue;
- Iterator j = ifs.extensions.iterator();
+ Iterator<String> j = ifs.extensions.iterator();
while (j.hasNext())
- extensions.add((String) j.next());
+ extensions.add(j.next());
}
}
- Object[] objs = extensions.toArray();
- String[] strings = new String[objs.length];
- for (int i = 0; i < objs.length; ++i)
- strings[i] = (String) objs[i];
- return strings;
+ return extensions.toArray(new String[extensions.size()]);
}
static String[] getFormatMimeTypes(boolean writable)
{
- ArrayList mimeTypes = new ArrayList();
+ ArrayList<String> mimeTypes = new ArrayList<String>();
synchronized (imageFormatSpecs)
{
- Iterator i = imageFormatSpecs.iterator();
+ Iterator<ImageFormatSpec> i = imageFormatSpecs.iterator();
while (i.hasNext())
{
- ImageFormatSpec ifs = (ImageFormatSpec) i.next();
+ ImageFormatSpec ifs = i.next();
if (writable && !ifs.writable)
continue;
- Iterator j = ifs.mimeTypes.iterator();
+ Iterator<String> j = ifs.mimeTypes.iterator();
while (j.hasNext())
- mimeTypes.add((String) j.next());
+ mimeTypes.add(j.next());
}
}
- Object[] objs = mimeTypes.toArray();
- String[] strings = new String[objs.length];
- for (int i = 0; i < objs.length; ++i)
- strings[i] = (String) objs[i];
- return strings;
+ return mimeTypes.toArray(new String[mimeTypes.size()]);
}
@@ -348,10 +336,10 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
String str = (String) ext;
- Iterator i = imageFormatSpecs.iterator();
+ Iterator<ImageFormatSpec> i = imageFormatSpecs.iterator();
while (i.hasNext())
{
- ImageFormatSpec ifs = (ImageFormatSpec) i.next();
+ ImageFormatSpec ifs = i.next();
if (needWritable && !ifs.writable)
continue;
@@ -359,10 +347,10 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
if (ifs.name.equals(str))
return str;
- Iterator j = ifs.extensions.iterator();
+ Iterator<String> j = ifs.extensions.iterator();
while (j.hasNext())
{
- String extension = (String)j.next();
+ String extension = j.next();
if (extension.equals(str))
return ifs.name;
}
@@ -370,7 +358,7 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
j = ifs.mimeTypes.iterator();
while (j.hasNext())
{
- String mimeType = (String)j.next();
+ String mimeType = j.next();
if (mimeType.equals(str))
return ifs.name;
}
@@ -510,10 +498,10 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
if (pixels == null)
{
- BufferedImage img;
- if(model != null && model.hasAlpha())
- img = CairoSurface.getBufferedImage(width, height);
- img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ BufferedImage img;
+ if(model != null && model.hasAlpha())
+ img = CairoSurface.getBufferedImage(width, height);
+ img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int[] pix = new int[4];
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
@@ -527,10 +515,10 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
workerThread.start();
processImageStarted(1);
synchronized(pixbufLock)
- {
- streamImage(pixels, this.ext, width, height, model.hasAlpha(),
- this);
- }
+ {
+ streamImage(pixels, this.ext, width, height, model.hasAlpha(),
+ this);
+ }
synchronized(data)
{
data.add(DATADONE);
@@ -539,18 +527,18 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
while (workerThread.isAlive())
{
- try
- {
- workerThread.join();
- }
- catch (InterruptedException ioe)
- {
- // Ignored.
- }
+ try
+ {
+ workerThread.join();
+ }
+ catch (InterruptedException ioe)
+ {
+ // Ignored.
+ }
}
if (exception != null)
- throw exception;
+ throw exception;
processImageComplete();
}
@@ -566,7 +554,7 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
* Needs to be synchronized for access.
* The special object DATADONE is added when all data has been delivered.
*/
- private ArrayList data = new ArrayList();
+ private ArrayList<Object> data = new ArrayList<Object>();
/**
* Holds any IOException thrown by the run method that needs
@@ -643,7 +631,8 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
this.ext = findFormatName(ext, false);
}
- public GdkPixbufReader(GdkPixbufReaderSpi ownerSpi, Object ext, GdkPixbufDecoder d)
+ public GdkPixbufReader(GdkPixbufReaderSpi ownerSpi, Object ext,
+ GdkPixbufDecoder d)
{
this(ownerSpi, ext);
dec = d;
@@ -680,10 +669,12 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
if (bufferedImage == null)
{
- if(model != null && model.hasAlpha())
- bufferedImage = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB);
- else
- bufferedImage = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);
+ if(model != null && model.hasAlpha())
+ bufferedImage = new BufferedImage (width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ else
+ bufferedImage = new BufferedImage (width, height,
+ BufferedImage.TYPE_INT_RGB);
}
int pixels2[];
@@ -735,11 +726,11 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
return null;
}
- public Iterator getImageTypes(int imageIndex)
+ public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
throws IOException
{
BufferedImage img = getBufferedImage();
- Vector vec = new Vector();
+ Vector<ImageTypeSpecifier> vec = new Vector<ImageTypeSpecifier>();
vec.add(new ImageTypeSpecifier(img));
return vec.iterator();
}
@@ -767,8 +758,8 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
else if (get instanceof DataInput)
dec = new GdkPixbufDecoder((DataInput) get);
else
- throw new IllegalArgumentException("input object not supported: "
- + get);
+ throw new IllegalArgumentException("input object not supported: "
+ + get);
}
public BufferedImage read(int imageIndex, ImageReadParam param)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java
index 62116a3226c..a69c6f0659e 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java
@@ -188,7 +188,7 @@ class GdkScreenGraphicsDevice extends GraphicsDevice
displayModes = nativeGetDisplayModes(env);
}
- ArrayList list = new ArrayList();
+ ArrayList<DisplayMode> list = new ArrayList<DisplayMode>();
for(int i=0;i<displayModes.length;i++)
for(int j=0;j<displayModes[i].rates.length;j++)
list.add(new DisplayMode(displayModes[i].width,
@@ -196,7 +196,7 @@ class GdkScreenGraphicsDevice extends GraphicsDevice
DisplayMode.BIT_DEPTH_MULTI,
displayModes[i].rates[j]));
- return (DisplayMode[]) list.toArray(new DisplayMode[list.size()]);
+ return list.toArray(new DisplayMode[list.size()]);
}
native X11DisplayMode[] nativeGetDisplayModes(GdkGraphicsEnvironment env);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
index 90d16c57282..4a41d0696c3 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
@@ -57,7 +57,8 @@ public class GtkCheckboxPeer extends GtkComponentPeer
private boolean currentState;
// A map from CheckboxGroup to GSList* GTK option group pointer.
- private static WeakHashMap groupMap = new WeakHashMap();
+ private static WeakHashMap<CheckboxGroup,Long> groupMap
+ = new WeakHashMap<CheckboxGroup,Long>();
public native void createCheckButton ();
public native void createRadioButton (long groupPointer);
@@ -98,7 +99,7 @@ public class GtkCheckboxPeer extends GtkComponentPeer
Long groupPointer = null;
synchronized (groupMap)
{
- groupPointer = (Long) groupMap.get(current_group);
+ groupPointer = groupMap.get(current_group);
}
if (groupPointer == null)
@@ -133,8 +134,8 @@ public class GtkCheckboxPeer extends GtkComponentPeer
{
if (currentState != state)
{
- currentState = state;
- gtkToggleButtonSetActive(state);
+ currentState = state;
+ gtkToggleButtonSetActive(state);
}
}
@@ -158,7 +159,7 @@ public class GtkCheckboxPeer extends GtkComponentPeer
Long groupPointer = null;
synchronized (groupMap)
{
- groupPointer = (Long) groupMap.get(current_group);
+ groupPointer = groupMap.get(current_group);
}
if (groupPointer == null)
@@ -203,7 +204,7 @@ public class GtkCheckboxPeer extends GtkComponentPeer
Long groupPointer = null;
synchronized (groupMap)
{
- groupPointer = (Long) groupMap.get(current_group);
+ groupPointer = groupMap.get(current_group);
}
if (groupPointer == null)
@@ -230,9 +231,9 @@ public class GtkCheckboxPeer extends GtkComponentPeer
// Only fire event is state actually changed.
if (currentState != state)
{
- currentState = state;
- super.postItemEvent(awtComponent,
- state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
+ currentState = state;
+ super.postItemEvent(awtComponent,
+ state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java
index d866cefd33c..ff061d35c74 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java
@@ -55,12 +55,12 @@ public class GtkChoicePeer extends GtkComponentPeer
int count = c.getItemCount ();
if (count > 0)
{
- for (int i = 0; i < count; i++)
- add( c.getItem(i), i );
+ for (int i = 0; i < count; i++)
+ add(c.getItem(i), i);
- selected = c.getSelectedIndex();
- if( selected >= 0 )
- select( selected );
+ selected = c.getSelectedIndex();
+ if (selected >= 0)
+ select( selected );
}
else
selected = -1;
@@ -121,9 +121,9 @@ public class GtkChoicePeer extends GtkComponentPeer
{
if( selected != index )
{
- selected = index;
- postItemEvent (((Choice) awtComponent).getItem( selected ),
- ItemEvent.SELECTED);
+ selected = index;
+ postItemEvent (((Choice) awtComponent).getItem( selected ),
+ ItemEvent.SELECTED);
}
}
@@ -133,11 +133,11 @@ public class GtkChoicePeer extends GtkComponentPeer
*/
public void handleEvent (AWTEvent event)
{
- super.handleEvent( event );
- if( event instanceof ItemEvent )
- if( ((ItemEvent)event).getItemSelectable() == awtComponent &&
- ((ItemEvent)event).getStateChange() == ItemEvent.SELECTED )
- ((Choice)awtComponent).select( selected );
+ super.handleEvent (event);
+ if (event instanceof ItemEvent)
+ if (((ItemEvent)event).getItemSelectable() == awtComponent
+ && ((ItemEvent)event).getStateChange() == ItemEvent.SELECTED)
+ ((Choice)awtComponent).select( selected );
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboard.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboard.java
index f520fe224b1..e41754641bb 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboard.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboard.java
@@ -71,9 +71,9 @@ public class GtkClipboard extends Clipboard
// cached by GtkSelection. True if
// gdk_display_supports_selection_notification.
static final boolean canCache = initNativeState(clipboard, selection,
- stringMimeType,
- imageMimeType,
- filesMimeType);
+ stringMimeType,
+ imageMimeType,
+ filesMimeType);
/**
* Creates the clipboard and sets the initial contents to the
@@ -140,8 +140,8 @@ public class GtkClipboard extends Clipboard
if (contents == null)
{
- advertiseContent(null, false, false, false);
- return;
+ advertiseContent(null, false, false, false);
+ return;
}
// We don't need to do anything for a GtkSelection facade.
@@ -153,46 +153,45 @@ public class GtkClipboard extends Clipboard
boolean files = false;
if (contents instanceof StringSelection
- || contents.isDataFlavorSupported(DataFlavor.stringFlavor)
- || contents.isDataFlavorSupported(DataFlavor.plainTextFlavor)
- || contents.isDataFlavorSupported(DataFlavor
- .getTextPlainUnicodeFlavor()))
+ || contents.isDataFlavorSupported(DataFlavor.stringFlavor)
+ || contents.isDataFlavorSupported(DataFlavor.plainTextFlavor)
+ || contents.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor()))
text = true;
DataFlavor[] flavors = contents.getTransferDataFlavors();
String[] mimeTargets = new String[flavors.length];
for (int i = 0; i < flavors.length; i++)
{
- DataFlavor flavor = flavors[i];
- String mimeType = flavor.getMimeType();
- mimeTargets[i] = mimeType;
-
- if (! text)
- if ("text".equals(flavor.getPrimaryType())
- || flavor.isRepresentationClassReader())
- text = true;
-
- if (! images && flavors[i].equals(DataFlavor.imageFlavor))
- {
- try
- {
- Object o = contents.getTransferData(DataFlavor.imageFlavor);
- if (o instanceof Image)
- images = true;
- }
- catch (UnsupportedFlavorException ufe)
- {
- }
- catch (IOException ioe)
- {
- }
- catch (ClassCastException cce)
- {
- }
- }
-
- if (flavors[i].equals(DataFlavor.javaFileListFlavor))
- files = true;
+ DataFlavor flavor = flavors[i];
+ String mimeType = flavor.getMimeType();
+ mimeTargets[i] = mimeType;
+
+ if (! text)
+ if ("text".equals(flavor.getPrimaryType())
+ || flavor.isRepresentationClassReader())
+ text = true;
+
+ if (! images && flavors[i].equals(DataFlavor.imageFlavor))
+ {
+ try
+ {
+ Object o = contents.getTransferData(DataFlavor.imageFlavor);
+ if (o instanceof Image)
+ images = true;
+ }
+ catch (UnsupportedFlavorException ufe)
+ {
+ }
+ catch (IOException ioe)
+ {
+ }
+ catch (ClassCastException cce)
+ {
+ }
+ }
+
+ if (flavors[i].equals(DataFlavor.javaFileListFlavor))
+ files = true;
}
advertiseContent(mimeTargets, text, images, files);
@@ -207,9 +206,9 @@ public class GtkClipboard extends Clipboard
* selection has explicitly been erased.
*/
private native void advertiseContent(String[] targets,
- boolean text,
- boolean images,
- boolean files);
+ boolean text,
+ boolean images,
+ boolean files);
/**
* Called by the gtk+ clipboard when an application has requested
@@ -228,7 +227,7 @@ public class GtkClipboard extends Clipboard
try
{
return (String) contents.getTransferData(DataFlavor.stringFlavor);
- }
+ }
catch (UnsupportedFlavorException ufe)
{
}
@@ -244,20 +243,20 @@ public class GtkClipboard extends Clipboard
// turn the result into a string.
try
{
- DataFlavor plainText = DataFlavor.getTextPlainUnicodeFlavor();
- Reader r = plainText.getReaderForText(contents);
- if (r != null)
- {
- StringBuffer sb = new StringBuffer();
- char[] cs = new char[1024];
- int l = r.read(cs);
- while (l != -1)
- {
- sb.append(cs, 0, l);
- l = r.read(cs);
- }
- return sb.toString();
- }
+ DataFlavor plainText = DataFlavor.getTextPlainUnicodeFlavor();
+ Reader r = plainText.getReaderForText(contents);
+ if (r != null)
+ {
+ StringBuffer sb = new StringBuffer();
+ char[] cs = new char[1024];
+ int l = r.read(cs);
+ while (l != -1)
+ {
+ sb.append(cs, 0, l);
+ l = r.read(cs);
+ }
+ return sb.toString();
+ }
}
catch (IllegalArgumentException iae)
{
@@ -288,11 +287,11 @@ public class GtkClipboard extends Clipboard
try
{
- Object o = contents.getTransferData(DataFlavor.imageFlavor);
- if( o instanceof GtkImage )
- return (GtkImage) o;
- else
- return new GtkImage(((Image)o).getSource());
+ Object o = contents.getTransferData(DataFlavor.imageFlavor);
+ if( o instanceof GtkImage )
+ return (GtkImage) o;
+ else
+ return new GtkImage(((Image)o).getSource());
}
catch (UnsupportedFlavorException ufe)
{
@@ -321,14 +320,13 @@ public class GtkClipboard extends Clipboard
try
{
- List list = (List) contents.getTransferData
- (DataFlavor.javaFileListFlavor);
- String[] uris = new String[list.size()];
- int u = 0;
- Iterator it = list.iterator();
- while (it.hasNext())
- uris[u++] = ((File) it.next()).toURI().toString();
- return uris;
+ List list = (List) contents.getTransferData(DataFlavor.javaFileListFlavor);
+ String[] uris = new String[list.size()];
+ int u = 0;
+ Iterator it = list.iterator();
+ while (it.hasNext())
+ uris[u++] = ((File) it.next()).toURI().toString();
+ return uris;
}
catch (UnsupportedFlavorException ufe)
{
@@ -365,34 +363,34 @@ public class GtkClipboard extends Clipboard
// the other provideXXX() methods.
try
{
- DataFlavor flavor = new DataFlavor(target);
- Object o = contents.getTransferData(flavor);
-
- if (o instanceof byte[])
- return (byte[]) o;
-
- if (o instanceof InputStream)
- {
- InputStream is = (InputStream) o;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] bs = new byte[1024];
- int l = is.read(bs);
- while (l != -1)
- {
- baos.write(bs, 0, l);
- l = is.read(bs);
- }
- return baos.toByteArray();
- }
-
- if (o instanceof Serializable)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(o);
- oos.close();
- return baos.toByteArray();
- }
+ DataFlavor flavor = new DataFlavor(target);
+ Object o = contents.getTransferData(flavor);
+
+ if (o instanceof byte[])
+ return (byte[]) o;
+
+ if (o instanceof InputStream)
+ {
+ InputStream is = (InputStream) o;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] bs = new byte[1024];
+ int l = is.read(bs);
+ while (l != -1)
+ {
+ baos.write(bs, 0, l);
+ l = is.read(bs);
+ }
+ return baos.toByteArray();
+ }
+
+ if (o instanceof Serializable)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(o);
+ oos.close();
+ return baos.toByteArray();
+ }
}
catch (ClassNotFoundException cnfe)
{
@@ -416,8 +414,8 @@ public class GtkClipboard extends Clipboard
* Clipboard can be cached (gdk_display_supports_selection_notification).
*/
private static native boolean initNativeState(GtkClipboard clipboard,
- GtkClipboard selection,
- String stringTarget,
- String imageTarget,
- String filesTarget);
+ GtkClipboard selection,
+ String stringTarget,
+ String imageTarget,
+ String filesTarget);
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboardNotifier.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboardNotifier.java
index 61df796dc00..8e593455774 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboardNotifier.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkClipboardNotifier.java
@@ -74,11 +74,11 @@ class GtkClipboardNotifier extends Thread
{
synchronized (notifier)
{
- if (clipboard == GtkClipboard.clipboard)
- announceClipboardChange = true;
- else
- announcePrimaryChange = true;
- notifier.notifyAll();
+ if (clipboard == GtkClipboard.clipboard)
+ announceClipboardChange = true;
+ else
+ announcePrimaryChange = true;
+ notifier.notifyAll();
}
}
@@ -87,44 +87,43 @@ class GtkClipboardNotifier extends Thread
GtkClipboard clipboard;
while (true)
{
- synchronized (this)
- {
- while (! announceClipboardChange && ! announcePrimaryChange)
- {
- try
- {
- this.wait();
- }
- catch (InterruptedException ie)
- {
- // ignore
- }
- }
-
- if (announceClipboardChange)
- {
- clipboard = GtkClipboard.clipboard;
- announceClipboardChange = false;
- }
- else
- {
- clipboard = GtkClipboard.selection;
- announcePrimaryChange = false;
- }
- }
-
- // Do the actual announcement without the lock held. We will
- // notice a new change after this notification has finished.
- try
- {
- clipboard.setContents(new GtkSelection(clipboard), null);
- }
- catch (Throwable t)
- {
- // should never happen, but might if we have some faulty
- // listener.
- t.printStackTrace();
- }
+ synchronized (this)
+ {
+ while (! announceClipboardChange && ! announcePrimaryChange)
+ {
+ try
+ {
+ this.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignore
+ }
+ }
+
+ if (announceClipboardChange)
+ {
+ clipboard = GtkClipboard.clipboard;
+ announceClipboardChange = false;
+ }
+ else
+ {
+ clipboard = GtkClipboard.selection;
+ announcePrimaryChange = false;
+ }
+ }
+
+ // Do the actual announcement without the lock held. We will
+ // notice a new change after this notification has finished.
+ try
+ {
+ clipboard.setContents(new GtkSelection(clipboard), null);
+ }
+ catch (Throwable t)
+ {
+ // should never happen, but might if we have some faulty listener.
+ t.printStackTrace();
+ }
}
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index b1ef09d6e1b..a7ae8e17f2b 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -109,7 +109,7 @@ public class GtkComponentPeer extends GtkGenericPeer
native void gtkWidgetGetLocationOnScreen (int[] point);
native void gtkWidgetSetCursor (int type, GtkImage image, int x, int y);
native void gtkWidgetSetCursorUnlocked (int type, GtkImage image,
- int x, int y);
+ int x, int y);
native void gtkWidgetSetBackground (int red, int green, int blue);
native void gtkWidgetSetForeground (int red, int green, int blue);
native void gtkWidgetSetSensitive (boolean sensitive);
@@ -206,7 +206,7 @@ public class GtkComponentPeer extends GtkGenericPeer
}
public int checkImage (Image image, int width, int height,
- ImageObserver observer)
+ ImageObserver observer)
{
return getToolkit().checkImage(image, width, height, observer);
}
@@ -402,7 +402,7 @@ public class GtkComponentPeer extends GtkGenericPeer
}
public boolean prepareImage (Image image, int width, int height,
- ImageObserver observer)
+ ImageObserver observer)
{
return getToolkit().prepareImage(image, width, height, observer);
}
@@ -539,17 +539,17 @@ public class GtkComponentPeer extends GtkGenericPeer
int type = cursor.getType();
if (cursor instanceof GtkCursor)
{
- GtkCursor gtkCursor = (GtkCursor) cursor;
- image = gtkCursor.getGtkImage();
- Point hotspot = gtkCursor.getHotspot();
- x = hotspot.x;
- y = hotspot.y;
+ GtkCursor gtkCursor = (GtkCursor) cursor;
+ image = gtkCursor.getGtkImage();
+ Point hotspot = gtkCursor.getHotspot();
+ x = hotspot.x;
+ y = hotspot.y;
}
else
{
- image = null;
- x = 0;
- y = 0;
+ image = null;
+ x = 0;
+ y = 0;
}
if (Thread.currentThread() == GtkMainThread.mainThread)
@@ -597,7 +597,7 @@ public class GtkComponentPeer extends GtkGenericPeer
if (b && ! (awtComponent instanceof Window))
{
Rectangle bounds = awtComponent.getBounds();
- b = (bounds.width > 0) && (bounds.height > 0);
+ b = (bounds.width > 0) && (bounds.height > 0);
}
if (Thread.currentThread() == GtkMainThread.mainThread)
@@ -617,23 +617,23 @@ public class GtkComponentPeer extends GtkGenericPeer
}
protected void postMouseEvent(int id, long when, int mods, int x, int y,
- int clickCount, boolean popupTrigger)
+ int clickCount, boolean popupTrigger)
{
q().postEvent(new MouseEvent(awtComponent, id, when, mods, x, y,
- clickCount, popupTrigger));
+ clickCount, popupTrigger));
}
/**
* Callback for component_scroll_cb.
*/
protected void postMouseWheelEvent(int id, long when, int mods,
- int x, int y, int clickCount,
- boolean popupTrigger,
- int type, int amount, int rotation)
+ int x, int y, int clickCount,
+ boolean popupTrigger,
+ int type, int amount, int rotation)
{
q().postEvent(new MouseWheelEvent(awtComponent, id, when, mods,
- x, y, clickCount, popupTrigger,
- type, amount, rotation));
+ x, y, clickCount, popupTrigger,
+ type, amount, rotation));
}
protected void postExposeEvent (int x, int y, int width, int height)
@@ -659,12 +659,12 @@ public class GtkComponentPeer extends GtkGenericPeer
&& keyCode != KeyEvent.VK_ALT))
{
synchronized(q)
- {
- q.postEvent(keyEvent);
- keyEvent = new KeyEvent(awtComponent, KeyEvent.KEY_TYPED, when,
- mods, KeyEvent.VK_UNDEFINED, keyChar,
- keyLocation);
- q.postEvent(keyEvent);
+ {
+ q.postEvent(keyEvent);
+ keyEvent = new KeyEvent(awtComponent, KeyEvent.KEY_TYPED, when,
+ mods, KeyEvent.VK_UNDEFINED, keyChar,
+ keyLocation);
+ q.postEvent(keyEvent);
}
}
else
@@ -685,8 +685,8 @@ public class GtkComponentPeer extends GtkGenericPeer
protected void postItemEvent (Object item, int stateChange)
{
q().postEvent (new ItemEvent ((ItemSelectable)awtComponent,
- ItemEvent.ITEM_STATE_CHANGED,
- item, stateChange));
+ ItemEvent.ITEM_STATE_CHANGED,
+ item, stateChange));
}
protected void postTextEvent ()
@@ -828,8 +828,8 @@ public class GtkComponentPeer extends GtkGenericPeer
// buffer and one front buffer.
if (numBuffers == 2)
backBuffer = new GtkVolatileImage(this, awtComponent.getWidth(),
- awtComponent.getHeight(),
- caps.getBackBufferCapabilities());
+ awtComponent.getHeight(),
+ caps.getBackBufferCapabilities());
else
throw new AWTException("GtkComponentPeer.createBuffers:"
+ " multi-buffering not supported");
@@ -846,18 +846,18 @@ public class GtkComponentPeer extends GtkGenericPeer
public void flip (BufferCapabilities.FlipContents contents)
{
getGraphics().drawImage(backBuffer,
- awtComponent.getWidth(),
- awtComponent.getHeight(),
- null);
+ awtComponent.getWidth(),
+ awtComponent.getHeight(),
+ null);
// create new back buffer and clear it to the background color.
if (contents == BufferCapabilities.FlipContents.BACKGROUND)
{
backBuffer = createVolatileImage(awtComponent.getWidth(),
- awtComponent.getHeight());
+ awtComponent.getHeight());
backBuffer.getGraphics().clearRect(0, 0,
- awtComponent.getWidth(),
- awtComponent.getHeight());
+ awtComponent.getWidth(),
+ awtComponent.getHeight());
}
// FIXME: support BufferCapabilities.FlipContents.PRIOR
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
index 8650578f70e..7d5ef91de13 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
@@ -40,7 +40,6 @@ package gnu.java.awt.peer.gtk;
import java.awt.Dialog;
import java.awt.FileDialog;
-import java.awt.Graphics;
import java.awt.event.PaintEvent;
import java.awt.peer.FileDialogPeer;
import java.io.File;
@@ -160,7 +159,8 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
in turn call the filter's accept() method and give back the return
value. */
// called back by native side: filename_filter_cb
- boolean filenameFilterCallback (String fullname) {
+ boolean filenameFilterCallback (String fullname)
+ {
String filename = fullname.substring(fullname.lastIndexOf(FS) + 1);
String dirname = fullname.substring(0, fullname.lastIndexOf(FS));
File dir = new File(dirname);
@@ -205,19 +205,19 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
if (sepIndex < 0)
{
/* This should never happen on Unix (all paths start with '/') */
- currentFile = fileName;
+ currentFile = fileName;
}
else
{
if (fileName.length() > (sepIndex + 1))
- {
- String fn = fileName.substring (sepIndex + 1);
- currentFile = fn;
- }
- else
- {
+ {
+ String fn = fileName.substring (sepIndex + 1);
+ currentFile = fn;
+ }
+ else
+ {
currentFile = null;
- }
+ }
String dn = fileName.substring (0, sepIndex + 1);
currentDirectory = dn;
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java
index d113e92f5b4..b35be522746 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java
@@ -1,5 +1,5 @@
/* GtkFramePeer.java -- Implements FramePeer with GTK
- Copyright (C) 1999, 2002, 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004, 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -176,13 +176,17 @@ public class GtkFramePeer extends GtkWindowPeer
public void setIconImage (Image image)
{
- if (image != null)
- {
- if (image instanceof GtkImage)
- nativeSetIconImage((GtkImage) image);
- else
- nativeSetIconImage(new GtkImage(image.getSource()));
- }
+ if (image != null)
+ {
+ GtkImage gtkImage;
+ if (image instanceof GtkImage)
+ gtkImage = (GtkImage) image;
+ else
+ gtkImage = new GtkImage(image.getSource());
+
+ if (gtkImage.isLoaded && ! gtkImage.errorLoading)
+ nativeSetIconImage(gtkImage);
+ }
}
protected void postConfigureEvent (int x, int y, int width, int height)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java
index 0fd98bbd7b4..719669eae0d 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java
@@ -71,7 +71,7 @@ public class GtkImage extends Image
/**
* Properties.
*/
- Hashtable props;
+ Hashtable<?,?> props;
/**
* Loaded or not flag, for asynchronous compatibility.
@@ -87,7 +87,7 @@ public class GtkImage extends Image
/**
* Observer queue.
*/
- Vector observers;
+ Vector<ImageObserver> observers;
/**
* Error flag for loading.
@@ -103,10 +103,10 @@ public class GtkImage extends Image
* The 32-bit AABBGGRR format the GDK uses.
*/
static ColorModel nativeModel = new DirectColorModel(32,
- 0x000000FF,
- 0x0000FF00,
- 0x00FF0000,
- 0xFF000000);
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000);
/**
* The singleton GtkImage that is returned on errors by GtkToolkit.
@@ -178,7 +178,7 @@ public class GtkImage extends Image
public GtkImage (ImageProducer producer)
{
isLoaded = false;
- observers = new Vector();
+ observers = new Vector<ImageObserver>();
source = producer;
errorLoading = false;
source.startProduction(new GtkImageConsumer(this, source));
@@ -194,7 +194,7 @@ public class GtkImage extends Image
{
isLoaded = true;
observers = null;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
errorLoading = false;
}
@@ -208,26 +208,26 @@ public class GtkImage extends Image
File f = new File(filename);
try
{
- String path = f.getCanonicalPath();
- synchronized(pixbufLock)
- {
- if (loadPixbuf(f.getCanonicalPath()) != true)
- throw new IllegalArgumentException("Couldn't load image: "
- + filename);
- }
+ String path = f.getCanonicalPath();
+ synchronized(pixbufLock)
+ {
+ if (loadPixbuf(f.getCanonicalPath()) != true)
+ throw new IllegalArgumentException("Couldn't load image: "
+ + filename);
+ }
}
catch(IOException e)
{
- IllegalArgumentException iae;
- iae = new IllegalArgumentException("Couldn't load image: "
- + filename);
- iae.initCause(e);
- throw iae;
+ IllegalArgumentException iae;
+ iae = new IllegalArgumentException("Couldn't load image: "
+ + filename);
+ iae.initCause(e);
+ throw iae;
}
isLoaded = true;
observers = null;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
}
/**
@@ -240,13 +240,13 @@ public class GtkImage extends Image
{
synchronized(pixbufLock)
{
- if (loadImageFromData (data) != true)
- throw new IllegalArgumentException ("Couldn't load image.");
+ if (loadImageFromData (data) != true)
+ throw new IllegalArgumentException ("Couldn't load image.");
}
isLoaded = true;
observers = null;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
errorLoading = false;
}
@@ -256,7 +256,7 @@ public class GtkImage extends Image
public GtkImage (URL url)
{
isLoaded = false;
- observers = new Vector();
+ observers = new Vector<ImageObserver>();
errorLoading = false;
if( url == null)
return;
@@ -269,23 +269,23 @@ public class GtkImage extends Image
int n = 0;
while ((n = bis.read(buf)) != -1)
- baos.write(buf, 0, n);
+ baos.write(buf, 0, n);
bis.close();
}
catch(IOException e)
{
- throw new IllegalArgumentException ("Couldn't load image.");
+ throw new IllegalArgumentException ("Couldn't load image.");
}
byte[] array = baos.toByteArray();
synchronized(pixbufLock)
{
- if (loadImageFromData(array) != true)
- throw new IllegalArgumentException ("Couldn't load image.");
+ if (loadImageFromData(array) != true)
+ throw new IllegalArgumentException ("Couldn't load image.");
}
isLoaded = true;
observers = null;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
}
/**
@@ -295,14 +295,14 @@ public class GtkImage extends Image
{
this.width = width;
this.height = height;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
isLoaded = true;
observers = null;
// Use the GDK scaling method.
synchronized(pixbufLock)
{
- createScaledPixbuf(src, hints);
+ createScaledPixbuf(src, hints);
}
}
@@ -315,11 +315,11 @@ public class GtkImage extends Image
this.pixbuf = pixbuf;
synchronized(pixbufLock)
{
- createFromPixbuf();
+ createFromPixbuf();
}
isLoaded = true;
observers = null;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
}
/**
@@ -331,7 +331,7 @@ public class GtkImage extends Image
{
this.width = width;
this.height = height;
- props = new Hashtable();
+ props = new Hashtable<String,Object>();
isLoaded = true;
observers = null;
initFromBuffer( bufferPointer );
@@ -346,8 +346,8 @@ public class GtkImage extends Image
{
if (errorImage == null)
{
- errorImage = new GtkImage();
- errorImage.errorLoading = true;
+ errorImage = new GtkImage();
+ errorImage.errorLoading = true;
}
return errorImage;
}
@@ -362,25 +362,25 @@ public class GtkImage extends Image
* Callback from the image consumer.
*/
public void setImage(int width, int height,
- int[] pixels, Hashtable properties)
+ int[] pixels, Hashtable<?,?> properties)
{
this.width = width;
this.height = height;
- props = (properties != null) ? properties : new Hashtable();
+ props = (properties != null) ? properties : new Hashtable<String,Object>();
if (width <= 0 || height <= 0 || pixels == null)
{
- errorLoading = true;
- return;
+ errorLoading = true;
+ return;
}
- isLoaded = true;
- deliver();
synchronized(pixbufLock)
{
- createPixbuf();
- setPixels(pixels);
+ createPixbuf();
+ setPixels(pixels);
}
+ isLoaded = true;
+ deliver();
}
// java.awt.Image methods ////////////////////////////////////////////////
@@ -427,7 +427,7 @@ public class GtkImage extends Image
return null;
}
return new MemoryImageSource(width, height, nativeModel, pixels,
- 0, width);
+ 0, width);
}
/**
@@ -436,19 +436,19 @@ public class GtkImage extends Image
public Graphics getGraphics ()
{
throw new IllegalAccessError("This method only works for off-screen"
- +" Images.");
+ +" Images.");
}
/**
* Returns a scaled instance of this pixbuf.
*/
public Image getScaledInstance(int width,
- int height,
- int hints)
+ int height,
+ int hints)
{
if (width <= 0 || height <= 0)
- throw new IllegalArgumentException("Width and height of scaled bitmap"+
- "must be >= 0");
+ throw new IllegalArgumentException("Width and height of scaled bitmap"
+ + "must be >= 0");
return new GtkImage(this, width, height, hints);
}
@@ -465,13 +465,13 @@ public class GtkImage extends Image
{
if (isLoaded && source != null)
{
- observers = new Vector();
- isLoaded = false;
- synchronized(pixbufLock)
+ observers = new Vector<ImageObserver>();
+ isLoaded = false;
+ synchronized(pixbufLock)
{
freePixbuf();
}
- source.startProduction(new GtkImageConsumer(this, source));
+ source.startProduction(new GtkImageConsumer(this, source));
}
}
@@ -479,10 +479,10 @@ public class GtkImage extends Image
{
if (isLoaded)
{
- synchronized(pixbufLock)
- {
- freePixbuf();
- }
+ synchronized(pixbufLock)
+ {
+ freePixbuf();
+ }
}
}
@@ -493,10 +493,10 @@ public class GtkImage extends Image
{
if (addObserver(observer))
{
- if (errorLoading == true)
- return ImageObserver.ERROR;
- else
- return 0;
+ if (errorLoading == true)
+ return ImageObserver.ERROR;
+ else
+ return 0;
}
return ImageObserver.ALLBITS | ImageObserver.WIDTH | ImageObserver.HEIGHT;
@@ -517,8 +517,8 @@ public class GtkImage extends Image
if (observers != null)
for(int i=0; i < observers.size(); i++)
- ((ImageObserver)observers.elementAt(i)).
- imageUpdate(this, flags, 0, 0, width, height);
+ ((ImageObserver)observers.elementAt(i)).imageUpdate(this, flags, 0, 0,
+ width, height);
observers = null;
}
@@ -531,10 +531,10 @@ public class GtkImage extends Image
{
if (!isLoaded)
{
- if(observer != null)
- if (!observers.contains (observer))
- observers.addElement (observer);
- return true;
+ if(observer != null)
+ if (!observers.contains (observer))
+ observers.addElement (observer);
+ return true;
}
return false;
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkImageConsumer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkImageConsumer.java
index 53e97bb1a8a..44cfaf9266a 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkImageConsumer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkImageConsumer.java
@@ -55,7 +55,7 @@ public class GtkImageConsumer implements ImageConsumer
{
private GtkImage target;
private int width, height;
- private Hashtable properties;
+ private Hashtable<?,?> properties;
private int[] pixelCache = null;
private ImageProducer source;
@@ -97,55 +97,55 @@ public class GtkImageConsumer implements ImageConsumer
}
public synchronized void setPixels (int x, int y, int width, int height,
- ColorModel cm, byte[] pixels,
- int offset, int scansize)
+ ColorModel cm, byte[] pixels,
+ int offset, int scansize)
{
setPixels (x, y, width, height, cm, convertPixels (pixels), offset,
scansize);
}
public synchronized void setPixels (int x, int y, int width, int height,
- ColorModel cm, int[] pixels,
- int offset, int scansize)
+ ColorModel cm, int[] pixels,
+ int offset, int scansize)
{
if (pixelCache == null)
return; // Not sure this should ever happen.
if (cm.equals(GtkImage.nativeModel))
for (int i = 0; i < height; i++)
- System.arraycopy (pixels, offset + (i * scansize),
- pixelCache, (y + i) * this.width + x,
- width);
+ System.arraycopy (pixels, offset + (i * scansize),
+ pixelCache, (y + i) * this.width + x,
+ width);
else
{
- if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
- {
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- {
- // get in RRGGBBAA and convert to AARRGGBB
- int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
- int a = ((pix & 0xFF000000) >> 24) & 0xFF;
- int rgb = (pix & 0x00FFFFFF) << 8;
- pix = rgb | a;
- pixelCache[(y + i) * this.width + x + j] = pix;
- }
- }
- else
- {
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- {
- // get in AARRGGBB and convert to AABBGGRR
- int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
- byte b = (byte)(pix & 0xFF);
- byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF);
- pix &= 0xFF00FF00;
- pix |= ((b & 0xFF) << 16);
- pix |= (r & 0xFF);
- pixelCache[(y + i) * this.width + x + j] = pix;
- }
- }
+ if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
+ {
+ for (int i = 0; i < height; i++)
+ for (int j = 0; j < width; j++)
+ {
+ // get in RRGGBBAA and convert to AARRGGBB
+ int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
+ int a = ((pix & 0xFF000000) >> 24) & 0xFF;
+ int rgb = (pix & 0x00FFFFFF) << 8;
+ pix = rgb | a;
+ pixelCache[(y + i) * this.width + x + j] = pix;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < height; i++)
+ for (int j = 0; j < width; j++)
+ {
+ // get in AARRGGBB and convert to AABBGGRR
+ int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
+ byte b = (byte)(pix & 0xFF);
+ byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF);
+ pix &= 0xFF00FF00;
+ pix |= ((b & 0xFF) << 16);
+ pix |= (r & 0xFF);
+ pixelCache[(y + i) * this.width + x + j] = pix;
+ }
+ }
}
}
@@ -162,7 +162,7 @@ public class GtkImageConsumer implements ImageConsumer
return ret;
}
- public synchronized void setProperties (Hashtable props)
+ public synchronized void setProperties (Hashtable<?,?> props)
{
this.properties = props;
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java
index 02db90d72bd..76f8e5fe331 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java
@@ -90,11 +90,11 @@ public class GtkLabelPeer extends GtkComponentPeer
switch (alignment)
{
case Label.LEFT:
- return 0.0f;
+ return 0.0f;
case Label.CENTER:
- return 0.5f;
+ return 0.5f;
case Label.RIGHT:
- return 1.0f;
+ return 1.0f;
}
return 0.0f;
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java
index bd6ec0aef75..f943a75d171 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java
@@ -148,33 +148,33 @@ public class GtkListPeer extends GtkComponentPeer
{
// Only generate the ActionEvent on the second click of a
// multiple click.
- MouseEvent me = (MouseEvent) e;
- if (!me.isConsumed ()
- && (me.getModifiersEx () & MouseEvent.BUTTON1_DOWN_MASK) != 0
- && me.getClickCount() == 2)
- {
+ MouseEvent me = (MouseEvent) e;
+ if (!me.isConsumed ()
+ && (me.getModifiersEx () & MouseEvent.BUTTON1_DOWN_MASK) != 0
+ && me.getClickCount() == 2)
+ {
String selectedItem = ((List) awtComponent).getSelectedItem ();
// Double-click only generates an Action event if
// something is selected.
if (selectedItem != null)
- postActionEvent (((List) awtComponent).getSelectedItem (),
- me.getModifiersEx ());
- }
+ postActionEvent (((List) awtComponent).getSelectedItem (),
+ me.getModifiersEx ());
+ }
}
if (e.getID () == KeyEvent.KEY_PRESSED)
{
- KeyEvent ke = (KeyEvent) e;
- if (!ke.isConsumed () && ke.getKeyCode () == KeyEvent.VK_ENTER)
- {
+ KeyEvent ke = (KeyEvent) e;
+ if (!ke.isConsumed () && ke.getKeyCode () == KeyEvent.VK_ENTER)
+ {
String selectedItem = ((List) awtComponent).getSelectedItem ();
// Enter only generates an Action event if something is
// selected.
if (selectedItem != null)
- postActionEvent (selectedItem, ke.getModifiersEx ());
- }
+ postActionEvent (selectedItem, ke.getModifiersEx ());
+ }
}
super.handleEvent (e);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMainThread.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMainThread.java
index a4e280fe45f..e40a04eed92 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMainThread.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMainThread.java
@@ -40,8 +40,6 @@ package gnu.java.awt.peer.gtk;
import gnu.java.awt.peer.NativeEventLoopRunningEvent;
-import java.awt.AWTEvent;
-
/**
* The Java thread representing the native GTK main loop, that is,
* GtkMainThread.mainThread, terminates when GtkToolkit.gtkMain()
@@ -172,9 +170,9 @@ public class GtkMainThread extends Thread
{
synchronized (nWindowsLock)
{
- if (numberOfWindows == 0)
- startMainThread();
- numberOfWindows++;
+ if (numberOfWindows == 0)
+ startMainThread();
+ numberOfWindows++;
}
}
@@ -182,9 +180,9 @@ public class GtkMainThread extends Thread
{
synchronized (nWindowsLock)
{
- numberOfWindows--;
- if (numberOfWindows == 0)
- endMainThread();
+ numberOfWindows--;
+ if (numberOfWindows == 0)
+ endMainThread();
}
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java
index 898f224f5e1..c3427b18f36 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java
@@ -76,15 +76,15 @@ public class GtkMenuBarPeer extends GtkMenuComponentPeer
{
if (hasHelpMenu)
{
- // Remove the (help) menu, which is after all the other items.
- delMenu(((MenuBar) awtWidget).getMenuCount());
- hasHelpMenu = false;
+ // Remove the (help) menu, which is after all the other items.
+ delMenu(((MenuBar) awtWidget).getMenuCount());
+ hasHelpMenu = false;
}
if (menu != null)
{
- addMenu(menu);
- hasHelpMenu = true;
+ addMenu(menu);
+ hasHelpMenu = true;
}
}
@@ -103,9 +103,9 @@ public class GtkMenuBarPeer extends GtkMenuComponentPeer
// Make sure the help menu is the last one.
if (hasHelpMenu)
{
- addHelpMenu(null);
- addMenu((GtkMenuPeer) m.getPeer());
- addHelpMenu(((MenuBar) awtWidget).getHelpMenu());
+ addHelpMenu(null);
+ addMenu((GtkMenuPeer) m.getPeer());
+ addHelpMenu(((MenuBar) awtWidget).getHelpMenu());
}
else
addMenu((GtkMenuPeer) m.getPeer());
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
index 55b95a18d0f..1e37cefc144 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
@@ -64,9 +64,9 @@ public abstract class GtkMenuComponentPeer extends GtkGenericPeer
if (f == null)
{
MenuContainer parent = mc.getParent ();
- // Submenus inherit the font of their containing Menu(Bar).
- if (parent instanceof MenuComponent)
- f = parent.getFont ();
+ // Submenus inherit the font of their containing Menu(Bar).
+ if (parent instanceof MenuComponent)
+ f = parent.getFont ();
}
setFont(f);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java
index 1d581c1a15c..ff6bdca9fbe 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java
@@ -96,8 +96,8 @@ public class GtkMenuPeer extends GtkMenuItemPeer
MenuShortcut ms = item.getShortcut ();
if (ms != null)
{
- key = ms.getKey ();
- shiftModifier = ms.usesShiftModifier ();
+ key = ms.getKey ();
+ shiftModifier = ms.usesShiftModifier ();
}
addItem ((MenuItemPeer) item.getPeer (), key, shiftModifier);
@@ -110,8 +110,8 @@ public class GtkMenuPeer extends GtkMenuItemPeer
if (ms != null)
{
- key = ms.getKey ();
- shiftModifier = ms.usesShiftModifier ();
+ key = ms.getKey ();
+ shiftModifier = ms.usesShiftModifier ();
}
addItem (item, key, shiftModifier);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java
index 02bf84d4e8e..7aea50991df 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java
@@ -53,9 +53,9 @@ public class GtkMouseInfoPeer implements MouseInfoPeer
public int fillPointWithCoords(Point p)
{
int[] coords = gde.getMouseCoordinates();
- p.x = coords[1];
- p.y = coords[2];
- return coords[0];
+ p.x = coords[1];
+ p.y = coords[2];
+ return coords[0];
}
public boolean isWindowUnderMouse(Window w)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java
index 69f8b494625..657a2760876 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java
@@ -74,10 +74,8 @@ public class GtkScrollPanePeer extends GtkContainerPeer
// If the child is in this range, GTK adds both scrollbars, but
// the AWT doesn't. So set the peer's scroll policy to
// GTK_POLICY_NEVER.
- if ((width > dim[0] - getVScrollbarWidth ()
- && width <= dim[0])
- && (height > dim[1] - getHScrollbarHeight ()
- && height <= dim[1]))
+ if ((width > dim[0] - getVScrollbarWidth () && width <= dim[0])
+ && (height > dim[1] - getHScrollbarHeight () && height <= dim[1]))
setPolicy (ScrollPane.SCROLLBARS_NEVER);
else
setPolicy (((ScrollPane) awtComponent).getScrollbarDisplayPolicy ());
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java
index e4147d36c97..c29706f408f 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java
@@ -50,14 +50,14 @@ public class GtkScrollbarPeer extends GtkComponentPeer
Scrollbar sb = (Scrollbar) awtComponent;
create (sb.getOrientation (), sb.getValue (),
- sb.getMinimum (), sb.getMaximum (),
- sb.getUnitIncrement (), sb.getBlockIncrement (),
- sb.getVisibleAmount ());
+ sb.getMinimum (), sb.getMaximum (),
+ sb.getUnitIncrement (), sb.getBlockIncrement (),
+ sb.getVisibleAmount ());
}
native void create (int orientation, int value,
- int min, int max, int stepIncr, int pageIncr,
- int visibleAmount);
+ int min, int max, int stepIncr, int pageIncr,
+ int visibleAmount);
native void connectSignals ();
@@ -86,7 +86,7 @@ public class GtkScrollbarPeer extends GtkComponentPeer
{
Scrollbar bar = (Scrollbar) awtComponent;
q().postEvent(new AdjustmentEvent(bar,
- AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
- type, value, true));
+ AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
+ type, value, true));
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkSelection.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkSelection.java
index 6a92f86e8b0..967a2edb432 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkSelection.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkSelection.java
@@ -130,7 +130,7 @@ public class GtkSelection implements Transferable
* Set as response to a requestURIs() call. Only valid when
* urisDelivered is true
*/
- private List uris;
+ private List<File> uris;
/**
* Indicates a requestBytes(String) call was made and the
@@ -163,51 +163,51 @@ public class GtkSelection implements Transferable
DataFlavor[] result;
synchronized (requestLock)
{
- // Did we request already and cache the result?
- if (mimeTypesDelivered)
- result = (DataFlavor[]) dataFlavors.clone();
- else
- {
- // Wait till there are no pending requests.
- while (requestInProgress)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
-
- // If nobody else beat us and cached the result we try
- // ourselves to get it.
- if (! mimeTypesDelivered)
- {
- requestInProgress = true;
- requestMimeTypes(clipboard);
- while (! mimeTypesDelivered)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
- requestInProgress = false;
- }
- result = dataFlavors;
- if (! GtkClipboard.canCache)
- {
- dataFlavors = null;
- mimeTypesDelivered = false;
- }
- requestLock.notifyAll();
- }
+ // Did we request already and cache the result?
+ if (mimeTypesDelivered)
+ result = (DataFlavor[]) dataFlavors.clone();
+ else
+ {
+ // Wait till there are no pending requests.
+ while (requestInProgress)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+
+ // If nobody else beat us and cached the result we try
+ // ourselves to get it.
+ if (! mimeTypesDelivered)
+ {
+ requestInProgress = true;
+ requestMimeTypes(clipboard);
+ while (! mimeTypesDelivered)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+ requestInProgress = false;
+ }
+ result = dataFlavors;
+ if (! GtkClipboard.canCache)
+ {
+ dataFlavors = null;
+ mimeTypesDelivered = false;
+ }
+ requestLock.notifyAll();
+ }
}
return result;
}
@@ -220,53 +220,55 @@ public class GtkSelection implements Transferable
{
synchronized (requestLock)
{
- if (mimeTypes == null)
- dataFlavors = new DataFlavor[0];
- else
- {
- // Most likely the mimeTypes include text in which case we add an
- // extra element.
- ArrayList flavorsList = new ArrayList(mimeTypes.length + 1);
- for (int i = 0; i < mimeTypes.length; i++)
- {
- try
- {
- if (mimeTypes[i] == GtkClipboard.stringMimeType)
- {
- // XXX - Fix DataFlavor.getTextPlainUnicodeFlavor()
- // and also add it to the list.
- flavorsList.add(DataFlavor.stringFlavor);
- flavorsList.add(DataFlavor.plainTextFlavor);
- }
- else if (mimeTypes[i] == GtkClipboard.imageMimeType)
- flavorsList.add(DataFlavor.imageFlavor);
- else if (mimeTypes[i] == GtkClipboard.filesMimeType)
- flavorsList.add(DataFlavor.javaFileListFlavor);
- else
- {
- // We check the target to prevent duplicates
- // of the "magic" targets above.
- DataFlavor target = new DataFlavor(mimeTypes[i]);
- if (! flavorsList.contains(target))
- flavorsList.add(target);
- }
- }
- catch (ClassNotFoundException cnfe)
- {
- cnfe.printStackTrace();
- }
- catch (NullPointerException npe)
- {
- npe.printStackTrace();
- }
- }
+ if (mimeTypes == null)
+ dataFlavors = new DataFlavor[0];
+ else
+ {
+ // Most likely the mimeTypes include text in which case we add an
+ // extra element.
+ ArrayList<DataFlavor> flavorsList =
+ new ArrayList<DataFlavor>(mimeTypes.length + 1);
+
+ for (int i = 0; i < mimeTypes.length; i++)
+ {
+ try
+ {
+ if (mimeTypes[i] == GtkClipboard.stringMimeType)
+ {
+ // XXX - Fix DataFlavor.getTextPlainUnicodeFlavor()
+ // and also add it to the list.
+ flavorsList.add(DataFlavor.stringFlavor);
+ flavorsList.add(DataFlavor.plainTextFlavor);
+ }
+ else if (mimeTypes[i] == GtkClipboard.imageMimeType)
+ flavorsList.add(DataFlavor.imageFlavor);
+ else if (mimeTypes[i] == GtkClipboard.filesMimeType)
+ flavorsList.add(DataFlavor.javaFileListFlavor);
+ else
+ {
+ // We check the target to prevent duplicates
+ // of the "magic" targets above.
+ DataFlavor target = new DataFlavor(mimeTypes[i]);
+ if (! flavorsList.contains(target))
+ flavorsList.add(target);
+ }
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ cnfe.printStackTrace();
+ }
+ catch (NullPointerException npe)
+ {
+ npe.printStackTrace();
+ }
+ }
- dataFlavors = new DataFlavor[flavorsList.size()];
- flavorsList.toArray(dataFlavors);
- }
+ dataFlavors = new DataFlavor[flavorsList.size()];
+ flavorsList.toArray(dataFlavors);
+ }
- mimeTypesDelivered = true;
- requestLock.notifyAll();
+ mimeTypesDelivered = true;
+ requestLock.notifyAll();
}
}
@@ -279,7 +281,7 @@ public class GtkSelection implements Transferable
DataFlavor[] dfs = getTransferDataFlavors();
for (int i = 0; i < dfs.length; i++)
if (flavor.equals(dfs[i]))
- return true;
+ return true;
return false;
}
@@ -294,51 +296,51 @@ public class GtkSelection implements Transferable
String result;
synchronized (requestLock)
{
- // Did we request already and cache the result?
- if (textDelivered)
- result = text;
- else
- {
- // Wait till there are no pending requests.
- while (requestInProgress)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
-
- // If nobody else beat us we try ourselves to get and
- // caching the result.
- if (! textDelivered)
- {
- requestInProgress = true;
- requestText(clipboard);
- while (! textDelivered)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
- requestInProgress = false;
- }
- result = text;
- if (! GtkClipboard.canCache)
- {
- text = null;
- textDelivered = false;
- }
- requestLock.notifyAll();
- }
+ // Did we request already and cache the result?
+ if (textDelivered)
+ result = text;
+ else
+ {
+ // Wait till there are no pending requests.
+ while (requestInProgress)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+
+ // If nobody else beat us we try ourselves to get and
+ // caching the result.
+ if (! textDelivered)
+ {
+ requestInProgress = true;
+ requestText(clipboard);
+ while (! textDelivered)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+ requestInProgress = false;
+ }
+ result = text;
+ if (! GtkClipboard.canCache)
+ {
+ text = null;
+ textDelivered = false;
+ }
+ requestLock.notifyAll();
+ }
}
return result;
}
@@ -351,9 +353,9 @@ public class GtkSelection implements Transferable
{
synchronized (requestLock)
{
- this.text = text;
- textDelivered = true;
- requestLock.notifyAll();
+ this.text = text;
+ textDelivered = true;
+ requestLock.notifyAll();
}
}
@@ -367,54 +369,56 @@ public class GtkSelection implements Transferable
Image result;
synchronized (requestLock)
{
- // Did we request already and cache the result?
- if (imageDelivered)
- result = image;
- else
- {
- // Wait till there are no pending requests.
- while (requestInProgress)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
-
- // If nobody else beat us we try ourselves to get and
- // caching the result.
- if (! imageDelivered)
- {
- requestInProgress = true;
- requestImage(clipboard);
- while (! imageDelivered)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
- requestInProgress = false;
- }
- if (imagePointer != null)
- image = new GtkImage(imagePointer);
- imagePointer = null;
- result = image;
- if (! GtkClipboard.canCache)
- {
- image = null;
- imageDelivered = false;
- }
- requestLock.notifyAll();
- }
+ // Did we request already and cache the result?
+ if (imageDelivered)
+ result = image;
+ else
+ {
+ // Wait till there are no pending requests.
+ while (requestInProgress)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+
+ // If nobody else beat us we try ourselves to get and
+ // caching the result.
+ if (! imageDelivered)
+ {
+ requestInProgress = true;
+ requestImage(clipboard);
+ while (! imageDelivered)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+ requestInProgress = false;
+ }
+
+ if (imagePointer != null)
+ image = new GtkImage(imagePointer);
+
+ imagePointer = null;
+ result = image;
+ if (! GtkClipboard.canCache)
+ {
+ image = null;
+ imageDelivered = false;
+ }
+ requestLock.notifyAll();
+ }
}
return result;
}
@@ -430,9 +434,9 @@ public class GtkSelection implements Transferable
{
synchronized (requestLock)
{
- this.imagePointer = pointer;
- imageDelivered = true;
- requestLock.notifyAll();
+ this.imagePointer = pointer;
+ imageDelivered = true;
+ requestLock.notifyAll();
}
}
@@ -441,56 +445,56 @@ public class GtkSelection implements Transferable
* URIs/Files and if not requests them and waits till they are
* available.
*/
- private List getURIs()
+ private List<File> getURIs()
{
- List result;
+ List<File> result;
synchronized (requestLock)
{
- // Did we request already and cache the result?
- if (urisDelivered)
- result = uris;
- else
- {
- // Wait till there are no pending requests.
- while (requestInProgress)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
-
- // If nobody else beat us we try ourselves to get and
- // caching the result.
- if (! urisDelivered)
- {
- requestInProgress = true;
- requestURIs(clipboard);
- while (! urisDelivered)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
- requestInProgress = false;
- }
- result = uris;
- if (! GtkClipboard.canCache)
- {
- uris = null;
- urisDelivered = false;
- }
- requestLock.notifyAll();
- }
+ // Did we request already and cache the result?
+ if (urisDelivered)
+ result = uris;
+ else
+ {
+ // Wait till there are no pending requests.
+ while (requestInProgress)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+
+ // If nobody else beat us we try ourselves to get and
+ // caching the result.
+ if (! urisDelivered)
+ {
+ requestInProgress = true;
+ requestURIs(clipboard);
+ while (! urisDelivered)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+ requestInProgress = false;
+ }
+ result = uris;
+ if (! GtkClipboard.canCache)
+ {
+ uris = null;
+ urisDelivered = false;
+ }
+ requestLock.notifyAll();
+ }
}
return result;
}
@@ -503,26 +507,26 @@ public class GtkSelection implements Transferable
{
synchronized (requestLock)
{
- if (uris != null && uris.length != 0)
- {
- ArrayList list = new ArrayList(uris.length);
- for (int i = 0; i < uris.length; i++)
- {
- try
- {
- URI uri = new URI(uris[i]);
- if (uri.getScheme().equals("file"))
- list.add(new File(uri));
- }
- catch (URISyntaxException use)
- {
- }
- }
- this.uris = list;
- }
-
- urisDelivered = true;
- requestLock.notifyAll();
+ if (uris != null && uris.length != 0)
+ {
+ ArrayList<File> list = new ArrayList<File>(uris.length);
+ for (int i = 0; i < uris.length; i++)
+ {
+ try
+ {
+ URI uri = new URI(uris[i]);
+ if (uri.getScheme().equals("file"))
+ list.add(new File(uri));
+ }
+ catch (URISyntaxException use)
+ {
+ }
+ }
+ this.uris = list;
+ }
+
+ urisDelivered = true;
+ requestLock.notifyAll();
}
}
@@ -537,39 +541,39 @@ public class GtkSelection implements Transferable
byte[] result;
synchronized (requestLock)
{
- // Wait till there are no pending requests.
- while (requestInProgress)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
-
- // Request bytes and wait till they are available.
- requestInProgress = true;
- requestBytes(clipboard, target);
- while (! bytesDelivered)
- {
- try
- {
- requestLock.wait();
- }
- catch (InterruptedException ie)
- {
- // ignored
- }
- }
- result = bytes;
- bytes = null;
- bytesDelivered = false;
- requestInProgress = false;
+ // Wait till there are no pending requests.
+ while (requestInProgress)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+
+ // Request bytes and wait till they are available.
+ requestInProgress = true;
+ requestBytes(clipboard, target);
+ while (! bytesDelivered)
+ {
+ try
+ {
+ requestLock.wait();
+ }
+ catch (InterruptedException ie)
+ {
+ // ignored
+ }
+ }
+ result = bytes;
+ bytes = null;
+ bytesDelivered = false;
+ requestInProgress = false;
- requestLock.notifyAll();
+ requestLock.notifyAll();
}
return result;
}
@@ -583,9 +587,9 @@ public class GtkSelection implements Transferable
{
synchronized (requestLock)
{
- this.bytes = bytes;
- bytesDelivered = true;
- requestLock.notifyAll();
+ this.bytes = bytes;
+ bytesDelivered = true;
+ requestLock.notifyAll();
}
}
@@ -596,30 +600,30 @@ public class GtkSelection implements Transferable
// try one more time through getBytes().
if (flavor.equals(DataFlavor.stringFlavor))
{
- String text = getText();
- if (text != null)
- return text;
+ String text = getText();
+ if (text != null)
+ return text;
}
if (flavor.equals(DataFlavor.plainTextFlavor))
{
- String text = getText();
- if (text != null)
- return new StringBufferInputStream(text);
+ String text = getText();
+ if (text != null)
+ return new StringBufferInputStream(text);
}
if (flavor.equals(DataFlavor.imageFlavor))
{
- Image image = getImage();
- if (image != null)
- return image;
+ Image image = getImage();
+ if (image != null)
+ return image;
}
if (flavor.equals(DataFlavor.javaFileListFlavor))
{
- List uris = getURIs();
- if (uris != null)
- return uris;
+ List<File> uris = getURIs();
+ if (uris != null)
+ return uris;
}
byte[] bytes = getBytes(flavor.getMimeType());
@@ -628,20 +632,20 @@ public class GtkSelection implements Transferable
if (flavor.isMimeTypeSerializedObject())
{
- try
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- return ois.readObject();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- catch (ClassNotFoundException cnfe)
- {
- cnfe.printStackTrace();
- }
+ try
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return ois.readObject();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ cnfe.printStackTrace();
+ }
}
if (flavor.isRepresentationClassInputStream())
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
index 5d9be1aec63..0c7d3a860e8 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
@@ -100,8 +100,8 @@ public class GtkTextAreaPeer extends GtkComponentPeer
// GtkComponent.create.
if (f == null)
{
- f = new Font ("Dialog", Font.PLAIN, 12);
- awtComponent.setFont (f);
+ f = new Font ("Dialog", Font.PLAIN, 12);
+ awtComponent.setFont (f);
}
FontMetrics fm = getFontMetrics (f);
@@ -154,11 +154,11 @@ public class GtkTextAreaPeer extends GtkComponentPeer
int width = 0;
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
- || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
height = getHScrollbarHeight ();
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
- || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
width = getVScrollbarWidth ();
Font f = awtComponent.getFont ();
@@ -183,11 +183,11 @@ public class GtkTextAreaPeer extends GtkComponentPeer
int width = 0;
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
- || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
height = getHScrollbarHeight ();
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
- || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
width = getVScrollbarWidth ();
Font f = awtComponent.getFont ();
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
index 763304864e0..9e62c8e7975 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
@@ -94,8 +94,8 @@ public class GtkTextFieldPeer extends GtkComponentPeer
// GtkComponent.create.
if (f == null)
{
- f = new Font ("Dialog", Font.PLAIN, 12);
- awtComponent.setFont (f);
+ f = new Font ("Dialog", Font.PLAIN, 12);
+ awtComponent.setFont (f);
}
FontMetrics fm = getFontMetrics (f);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
index f746a47479f..df18d39c9d2 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
@@ -1,5 +1,5 @@
/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
- Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006
+ Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006, 2007
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 gnu.java.awt.AWTUtilities;
import gnu.java.awt.EmbeddedWindow;
import gnu.java.awt.dnd.GtkMouseDragGestureRecognizer;
import gnu.java.awt.dnd.peer.gtk.GtkDragSourceContextPeer;
@@ -86,6 +87,7 @@ import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.font.TextAttribute;
import java.awt.im.InputMethodHighlight;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
@@ -104,8 +106,8 @@ import java.awt.peer.LabelPeer;
import java.awt.peer.ListPeer;
import java.awt.peer.MenuBarPeer;
import java.awt.peer.MenuItemPeer;
-import java.awt.peer.MouseInfoPeer;
import java.awt.peer.MenuPeer;
+import java.awt.peer.MouseInfoPeer;
import java.awt.peer.PanelPeer;
import java.awt.peer.PopupMenuPeer;
import java.awt.peer.RobotPeer;
@@ -132,9 +134,11 @@ import javax.imageio.spi.IIORegistry;
public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
{
+ static final Object GTK_LOCK;
+
private static EventQueue q;
- static native void gtkInit(int portableNativeSync);
+ static native void gtkInit(int portableNativeSync, Object lock);
static native void gtkMain();
@@ -154,8 +158,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
portableNativeSync = 1; // true
else
portableNativeSync = 0; // false
-
- gtkInit(portableNativeSync);
+
+ GTK_LOCK = new String("GTK LOCK");
+ gtkInit(portableNativeSync, GTK_LOCK);
}
public GtkToolkit ()
@@ -167,14 +172,14 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
private native void getScreenSizeDimensions(int[] xy);
public int checkImage (Image image, int width, int height,
- ImageObserver observer)
+ ImageObserver observer)
{
int status = ImageObserver.ALLBITS
| ImageObserver.WIDTH
| ImageObserver.HEIGHT;
if (image instanceof GtkImage)
- return ((GtkImage) image).checkImage (observer);
+ return ((GtkImage) image).checkImage (observer);
if (image instanceof AsyncImage)
return ((AsyncImage) image).checkImage(observer);
@@ -208,11 +213,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
Image image;
try
{
- image = CairoSurface.getBufferedImage( new GtkImage( filename ) );
+ image = CairoSurface.getBufferedImage( new GtkImage( filename ) );
}
catch (IllegalArgumentException iae)
{
- image = null;
+ image = null;
}
return imageOrError(image);
}
@@ -230,11 +235,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
Image image;
try
{
- image = CairoSurface.getBufferedImage( new GtkImage( producer ) );
+ image = CairoSurface.getBufferedImage( new GtkImage( producer ) );
}
catch (IllegalArgumentException iae)
{
- image = null;
+ image = null;
}
return imageOrError(image);
}
@@ -245,13 +250,13 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
Image image;
try
{
- byte[] data = new byte[ imagelength ];
- System.arraycopy(imagedata, imageoffset, data, 0, imagelength);
- image = CairoSurface.getBufferedImage( new GtkImage( data ) );
+ byte[] data = new byte[ imagelength ];
+ System.arraycopy(imagedata, imageoffset, data, 0, imagelength);
+ image = CairoSurface.getBufferedImage( new GtkImage( data ) );
}
catch (IllegalArgumentException iae)
{
- image = null;
+ image = null;
}
return imageOrError(image);
}
@@ -275,22 +280,22 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
{
/* Return the GDK-native ABGR format */
return new DirectColorModel(32,
- 0x000000FF,
- 0x0000FF00,
- 0x00FF0000,
- 0xFF000000);
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000);
}
public String[] getFontList ()
{
return (new String[] { "Dialog",
- "DialogInput",
- "Monospaced",
- "Serif",
- "SansSerif" });
+ "DialogInput",
+ "Monospaced",
+ "Serif",
+ "SansSerif" });
}
- static class LRUCache extends LinkedHashMap
+ static class LRUCache<K,V> extends LinkedHashMap<K,V>
{
int max_entries;
public LRUCache(int max)
@@ -304,8 +309,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
}
}
- private LRUCache fontCache = new LRUCache(50);
- private LRUCache imageCache = new LRUCache(50);
+ private LRUCache<Map,ClasspathFontPeer> fontCache =
+ new LRUCache<Map,ClasspathFontPeer>(50);
+ private LRUCache<Object,Image> imageCache = new LRUCache<Object,Image>(50);
public FontMetrics getFontMetrics (Font font)
{
@@ -315,7 +321,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
public Image getImage (String filename)
{
if (imageCache.containsKey(filename))
- return (Image) imageCache.get(filename);
+ return imageCache.get(filename);
else
{
Image im = createImage(filename);
@@ -327,7 +333,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
public Image getImage (URL url)
{
if (imageCache.containsKey(url))
- return (Image) imageCache.get(url);
+ return imageCache.get(url);
else
{
Image im = createImage(url);
@@ -378,12 +384,12 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
* assumes the image is already prepared for rendering.
*/
public boolean prepareImage (Image image, int width, int height,
- ImageObserver observer)
+ ImageObserver observer)
{
/* GtkImages are always prepared, as long as they're loaded. */
if (image instanceof GtkImage)
- return ((((GtkImage)image).checkImage (observer) &
- ImageObserver.ALLBITS) != 0);
+ return ((((GtkImage)image).checkImage (observer)
+ & ImageObserver.ALLBITS) != 0);
if (image instanceof AsyncImage)
{
@@ -411,11 +417,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
/* Make the Peer reflect the state of the Component */
if (! (c instanceof Window))
{
- cp.setCursor (c.getCursor ());
+ cp.setCursor (c.getCursor ());
- Rectangle bounds = c.getBounds ();
- cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
- cp.setVisible (c.isVisible ());
+ Rectangle bounds = c.getBounds ();
+ cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
+ cp.setVisible (c.isVisible ());
}
}
@@ -563,7 +569,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
*/
private FontPeer getFontPeer (String name, int style, int size)
{
- Map attrs = new HashMap ();
+ Map<TextAttribute,Object> attrs = new HashMap<TextAttribute,Object>();
ClasspathFontPeer.copyStyleToAttrs (style, attrs);
ClasspathFontPeer.copySizeToAttrs (size, attrs);
return getClasspathFontPeer (name, attrs);
@@ -575,16 +581,17 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
* model, hence "ClasspathFontPeer".
*/
- public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
+ public ClasspathFontPeer getClasspathFontPeer (String name,
+ Map<?,?> attrs)
{
- Map keyMap = new HashMap (attrs);
+ Map<Object,Object> keyMap = new HashMap<Object,Object>(attrs);
// We don't know what kind of "name" the user requested (logical, face,
// family), and we don't actually *need* to know here. The worst case
// involves failure to consolidate fonts with the same backend in our
// cache. This is harmless.
keyMap.put ("GtkToolkit.RequestedFontName", name);
if (fontCache.containsKey (keyMap))
- return (ClasspathFontPeer) fontCache.get (keyMap);
+ return fontCache.get (keyMap);
else
{
ClasspathFontPeer newPeer = new GdkFontPeer (name, attrs);
@@ -619,11 +626,10 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
return new GtkDragSourceContextPeer(e);
}
- public DragGestureRecognizer createDragGestureRecognizer(Class recognizer,
- DragSource ds,
- Component comp,
- int actions,
- DragGestureListener l)
+ public <T extends DragGestureRecognizer> T
+ createDragGestureRecognizer(Class<T> recognizer, DragSource ds,
+ Component comp, int actions,
+ DragGestureListener l)
{
if (recognizer.getName().equals("java.awt.dnd.MouseDragGestureRecognizer")
&& ! GraphicsEnvironment.isHeadless())
@@ -631,7 +637,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
GtkMouseDragGestureRecognizer gestureRecognizer
= new GtkMouseDragGestureRecognizer(ds, comp, actions, l);
gestureRecognizer.registerListeners();
- return gestureRecognizer;
+ return recognizer.cast(gestureRecognizer);
}
else
{
@@ -639,7 +645,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
}
}
- public Map mapInputMethodHighlight(InputMethodHighlight highlight)
+ public Map<TextAttribute,?> mapInputMethodHighlight(InputMethodHighlight highlight)
{
throw new Error("not implemented");
}
@@ -668,6 +674,22 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
return new GdkRobotPeer (screen);
}
+ public boolean getLockingKeyState(int keyCode)
+ {
+ int state = getLockState(keyCode);
+
+ if (state != -1)
+ return state == 1;
+
+ if (AWTUtilities.isValidKey(keyCode))
+ throw new UnsupportedOperationException
+ ("cannot get locking state of key code " + keyCode);
+
+ throw new IllegalArgumentException("invalid key code " + keyCode);
+ }
+
+ protected native int getLockState(int keyCode);
+
public void registerImageIOSpis(IIORegistry reg)
{
GdkPixbufDecoder.registerSpis(reg);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java
index 8d49719b1d3..1451dd93354 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java
@@ -172,19 +172,17 @@ public class GtkWindowPeer extends GtkContainerPeer
public void setBounds (int x, int y, int width, int height)
{
- if (x != getX()
- || y != getY()
- || width != getWidth()
- || height != getHeight())
+ if (x != getX() || y != getY() || width != getWidth()
+ || height != getHeight())
{
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
- nativeSetBounds (x, y,
- width - insets.left - insets.right,
- height - insets.top - insets.bottom);
+ nativeSetBounds (x, y,
+ width - insets.left - insets.right,
+ height - insets.top - insets.bottom);
}
}
@@ -211,7 +209,7 @@ public class GtkWindowPeer extends GtkContainerPeer
width = awtComponent.getWidth();
height = awtComponent.getHeight();
setSize (width - insets.left - insets.right,
- height - insets.top - insets.bottom);
+ height - insets.top - insets.bottom);
gtkWindowSetResizable (resizable);
}
@@ -253,22 +251,20 @@ public class GtkWindowPeer extends GtkContainerPeer
awtComponent.dispatchEvent(ev);
}
- if (frame_width != getWidth()
- || frame_height != getHeight())
+ if (frame_width != getWidth() || frame_height != getHeight())
{
- this.width = frame_width;
- this.height = frame_height;
- q().postEvent(new ComponentEvent(awtComponent,
- ComponentEvent.COMPONENT_RESIZED));
+ this.width = frame_width;
+ this.height = frame_height;
+ q().postEvent(new ComponentEvent(awtComponent,
+ ComponentEvent.COMPONENT_RESIZED));
}
- if (frame_x != getX()
- || frame_y != getY())
+ if (frame_x != getX() || frame_y != getY())
{
- this.x = frame_x;
- this.y = frame_y;
- q().postEvent(new ComponentEvent(awtComponent,
- ComponentEvent.COMPONENT_MOVED));
+ this.x = frame_x;
+ this.y = frame_y;
+ q().postEvent(new ComponentEvent(awtComponent,
+ ComponentEvent.COMPONENT_MOVED));
}
}
@@ -287,8 +283,8 @@ public class GtkWindowPeer extends GtkContainerPeer
{
if (id == WindowEvent.WINDOW_STATE_CHANGED)
{
- if (windowState != newState)
- {
+ if (windowState != newState)
+ {
// Post old styleWindowEvent with WINDOW_ICONIFIED or
// WINDOW_DEICONIFIED if appropriate.
if ((windowState & Frame.ICONIFIED) != 0
@@ -302,10 +298,10 @@ public class GtkWindowPeer extends GtkContainerPeer
WindowEvent.WINDOW_ICONIFIED,
opposite, 0, 0));
// Post new-style WindowStateEvent.
- q().postEvent (new WindowEvent ((Window) awtComponent, id,
+ q().postEvent (new WindowEvent ((Window) awtComponent, id,
opposite, windowState, newState));
- windowState = newState;
- }
+ windowState = newState;
+ }
}
else
q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite));
@@ -384,7 +380,7 @@ public class GtkWindowPeer extends GtkContainerPeer
}
protected void postMouseEvent(int id, long when, int mods, int x, int y,
- int clickCount, boolean popupTrigger)
+ int clickCount, boolean popupTrigger)
{
// Translate AWT co-ordinates, which include a window frame's
// insets, to GTK co-ordinates, which do not include a window
@@ -392,8 +388,8 @@ public class GtkWindowPeer extends GtkContainerPeer
// insets but GtkFramePeer and GtkDialogPeer insets will be
// non-zero.
super.postMouseEvent (id, when, mods,
- x + insets.left, y + insets.top,
- clickCount, popupTrigger);
+ x + insets.left, y + insets.top,
+ clickCount, popupTrigger);
}
// We override this to keep it in sync with our internal
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java b/libjava/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java
index 62dbb45d81a..88438862b34 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java
@@ -207,11 +207,11 @@ public class VolatileImageGraphics extends ComponentGraphics
if (img instanceof GtkVolatileImage
&& (comp == null || comp instanceof AlphaComposite))
{
- owner.drawVolatile( ((GtkVolatileImage)img).nativePointer,
- x, y,
- ((GtkVolatileImage)img).width,
- ((GtkVolatileImage)img).height );
- return true;
+ owner.drawVolatile( ((GtkVolatileImage)img).nativePointer,
+ x, y,
+ ((GtkVolatileImage)img).width,
+ ((GtkVolatileImage)img).height );
+ return true;
}
return super.drawImage( img, x, y, observer );
}
@@ -222,9 +222,9 @@ public class VolatileImageGraphics extends ComponentGraphics
if ((img instanceof GtkVolatileImage)
&& (comp == null || comp instanceof AlphaComposite))
{
- owner.drawVolatile( ((GtkVolatileImage)img).nativePointer,
- x, y, width, height );
- return true;
+ owner.drawVolatile( ((GtkVolatileImage)img).nativePointer,
+ x, y, width, height );
+ return true;
}
return super.drawImage( img, x, y, width, height, observer );
}
@@ -254,8 +254,8 @@ public class VolatileImageGraphics extends ComponentGraphics
transform.transform(points, 0, points, 0, 2);
Rectangle2D deviceBounds = new Rectangle2D.Double(points[0], points[1],
- points[2] - points[0],
- points[3] - points[1]);
+ points[2] - points[0],
+ points[3] - points[1]);
Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds);
current = current.getSubimage((int)deviceBounds.getX(),
diff --git a/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java b/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java
index 5116769389e..9b53b278b26 100644
--- a/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java
+++ b/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java
@@ -1,5 +1,5 @@
/* QtToolkit.java --
- Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,6 +37,7 @@ exception statement from your version. */
package gnu.java.awt.peer.qt;
+import gnu.java.awt.ClasspathToolkit;
import gnu.java.awt.EmbeddedWindow;
import gnu.java.awt.peer.ClasspathFontPeer;
import gnu.java.awt.peer.EmbeddedWindowPeer;
@@ -50,56 +51,56 @@ import java.awt.Choice;
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.MenuBar;
import java.awt.Menu;
+import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Panel;
-import java.awt.TextArea;
-import java.awt.TextField;
-import java.awt.FileDialog;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
import java.awt.PopupMenu;
import java.awt.PrintJob;
-import java.awt.Scrollbar;
import java.awt.ScrollPane;
+import java.awt.Scrollbar;
+import java.awt.TextArea;
+import java.awt.TextField;
import java.awt.Window;
import java.awt.datatransfer.Clipboard;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.event.AWTEventListener;
+import java.awt.im.InputMethodHighlight;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
-import java.awt.im.InputMethodHighlight;
import java.awt.peer.ButtonPeer;
-import java.awt.peer.FontPeer;
-import java.awt.peer.PanelPeer;
import java.awt.peer.CanvasPeer;
-import java.awt.peer.FramePeer;
-import java.awt.peer.PopupMenuPeer;
import java.awt.peer.CheckboxMenuItemPeer;
-import java.awt.peer.LabelPeer;
-import java.awt.peer.RobotPeer;
import java.awt.peer.CheckboxPeer;
-import java.awt.peer.ScrollPanePeer;
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.ListPeer;
-import java.awt.peer.ScrollbarPeer;
import java.awt.peer.MenuBarPeer;
-import java.awt.peer.TextAreaPeer;
-import java.awt.peer.DialogPeer;
import java.awt.peer.MenuItemPeer;
-import java.awt.peer.TextFieldPeer;
-import java.awt.peer.FileDialogPeer;
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.InputStream;
import java.net.URL;
@@ -107,8 +108,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import gnu.java.awt.ClasspathToolkit;
-
public class QtToolkit extends ClasspathToolkit
{
public static EventQueue eventQueue = null; // the native event queue
@@ -163,7 +162,9 @@ public class QtToolkit extends ClasspathToolkit
if( guiThread == null )
initToolkit();
- while (!guiThread.isRunning()); // make sure the GUI thread has started.
+ // make sure the GUI thread has started.
+ while (!guiThread.isRunning())
+ ;
if( graphicsEnv == null )
graphicsEnv = new QtGraphicsEnvironment( this );