[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] add support for blank ImageIcons
From: |
Thomas Fitzsimmons |
Subject: |
[cp-patches] add support for blank ImageIcons |
Date: |
Fri, 02 Sep 2005 02:39:32 -0400 |
Hi,
It turns out that some apps use ImageIcon("") to create blank icons.
This patch adds support for blank images to GtkToolkit and fixes
PR22979.
Tom
2005-09-02 Thomas Fitzsimmons <address@hidden>
PR awt/22979
* gnu/java/awt/peer/gtk/GtkImage.java,
native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c (GtkImage()):
New constructor.
(drawPixelsScaled): Return immediately if width or height is <= 0.
(drawPixelsScaledFlipped): Likewise for srcwidth, srcheight,
dstwidth, dstheight.
* gnu/java/awt/peer/gtk/GtkToolkit.java (createImage(String)):
Create a blank image when filename is "".
* javax/swing/ImageIcon.java (ImageIcon(String)): Mention blank
icons in documentation.
(ImageIcon(String,String)): Likewise.
Index: gnu/java/awt/peer/gtk/GtkImage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkImage.java,v
retrieving revision 1.24
diff -u -r1.24 GtkImage.java
--- gnu/java/awt/peer/gtk/GtkImage.java 2 Sep 2005 03:15:21 -0000 1.24
+++ gnu/java/awt/peer/gtk/GtkImage.java 2 Sep 2005 06:27:58 -0000
@@ -195,6 +195,21 @@
}
/**
+ * Constructs a blank GtkImage. This is called when
+ * GtkToolkit.createImage (String) is called with an empty string
+ * argument (""). A blank image is loaded immediately upon
+ * construction and has width -1 and height -1.
+ */
+ public GtkImage ()
+ {
+ isLoaded = true;
+ observers = null;
+ offScreen = false;
+ props = new Hashtable();
+ errorLoading = false;
+ }
+
+ /**
* Constructs a GtkImage by loading a given file.
*
* @throws IllegalArgumentException if the image could not be loaded.
Index: gnu/java/awt/peer/gtk/GtkToolkit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java,v
retrieving revision 1.77
diff -u -r1.77 GtkToolkit.java
--- gnu/java/awt/peer/gtk/GtkToolkit.java 2 Sep 2005 03:15:21 -0000
1.77
+++ gnu/java/awt/peer/gtk/GtkToolkit.java 2 Sep 2005 06:27:58 -0000
@@ -255,6 +255,9 @@
public Image createImage (String filename)
{
+ if (filename.length() == 0)
+ return new GtkImage ();
+
if (useGraphics2D())
return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage
(filename));
else
Index: javax/swing/ImageIcon.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/ImageIcon.java,v
retrieving revision 1.20
diff -u -r1.20 ImageIcon.java
--- javax/swing/ImageIcon.java 22 Aug 2005 19:19:46 -0000 1.20
+++ javax/swing/ImageIcon.java 2 Sep 2005 06:27:59 -0000
@@ -230,21 +230,28 @@
}
/**
- * Creates an ImageIcon from the given file with as initial
- * description the file name.
+ * Constructs an ImageIcon given a filename. The icon's description
+ * is initially set to the filename itself. A filename of "" means
+ * create a blank icon.
+ *
+ * @param filename name of file to load or "" for a blank icon
*/
- public ImageIcon(String file)
+ public ImageIcon(String filename)
{
- this(file, file);
+ this(filename, filename);
}
/**
- * Creates an ImageIcon from the given file and sets the given
- * description.
+ * Constructs an ImageIcon from the given filename, setting its
+ * description to the given description. A filename of "" means
+ * create a blank icon.
+ *
+ * @param filename name of file to load or "" for a blank icon
+ * @param description human-readable description of this icon
*/
- public ImageIcon(String file, String description)
+ public ImageIcon(String filename, String description)
{
- this(Toolkit.getDefaultToolkit().getImage(file), description);
+ this(Toolkit.getDefaultToolkit().getImage(filename), description);
}
/**
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c,v
retrieving revision 1.14
diff -u -r1.14 gnu_java_awt_peer_gtk_GtkImage.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c 2 Sep 2005
03:15:21 -0000 1.14
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c 2 Sep 2005
06:28:02 -0000
@@ -362,6 +362,12 @@
gdk_threads_enter ();
+ if (width <= 0 || height <= 0)
+ {
+ gdk_threads_leave ();
+ return;
+ }
+
bgColor = ((bg_red & 0xFF) << 16) |
((bg_green & 0xFF) << 8) | (bg_blue & 0xFF);
@@ -435,6 +441,13 @@
gdk_threads_enter ();
+ if (srcwidth <= 0 || srcheight <= 0
+ || dstwidth <= 0 || dstheight <= 0)
+ {
+ gdk_threads_leave ();
+ return;
+ }
+
bgColor = ((bg_red & 0xFF) << 16) |
((bg_green & 0xFF) << 8) | (bg_blue & 0xFF);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] add support for blank ImageIcons,
Thomas Fitzsimmons <=