[kaffe] ZipInputStream problem while running jlGui
jserv at linux2.cc.ntu.edu.tw
jserv at linux2.cc.ntu.edu.tw
Tue Apr 6 07:53:03 PDT 2004
Hi all,
I attempt to get jlGui [1] run on KaffeVM. jlGui needs some Swing,
and I just replace it with drop-in implementation from GNU Classpath.
With my patch against jlGui 2.2, jikes successfuly compiles jlGui
with Kaffe's rt.jar. However, I find jlGui runs out of memory due to
infinite loop while getNextEntry() method operated in ZipInputStream.
I wonder why jlGui running on KaffeVM has the strange behavior.
I am seeking for solutions, especially the help from mailing-list.
My patch is attached in this mail, and I do hope your taking a look.
Thanks,
Jim Huang
[1] http://www.javazoom.net/jlgui/jlgui.html
-------------- next part --------------
diff -urN jlgui-orig/build.xml jlgui/build.xml
--- jlgui-orig/build.xml 2003-06-17 07:23:16.000000000 +0800
+++ jlgui/build.xml 2004-04-05 11:05:12.000000000 +0800
@@ -16,6 +16,7 @@
<!-- Build -->
<target name="build" depends="init">
<echo message="------ Compiling application"/>
+ <property name="build.compiler" value="jikes"/>
<javac srcdir="${sources}" destdir="${classes}" includes="**">
<classpath>
<pathelement location="${lib}/jl020.jar"/>
diff -urN jlgui-orig/src/javazoom/jlGui/Player.java jlgui/src/javazoom/jlGui/Player.java
--- jlgui-orig/src/javazoom/jlGui/Player.java 2003-06-16 00:56:10.000000000 +0800
+++ jlgui/src/javazoom/jlGui/Player.java 2004-04-05 16:28:24.000000000 +0800
@@ -27,7 +27,7 @@
import java.awt.event.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
-import javax.swing.ImageIcon;
+import kaffex.swing.ImageIcon;
import javax.sound.sampled.*;
import javazoom.jlGui.skin.*;
@@ -296,7 +296,7 @@
URL iconURL = cl.getResource("jlguiicon.gif");
if (iconURL != null)
{
- ImageIcon jlguiIcon = new ImageIcon(iconURL);
+ ImageIcon jlguiIcon = new ImageIcon(iconURL.getPath());
topFrame.setIconImage(jlguiIcon.getImage());
}
topFrame.show();
@@ -1331,7 +1331,7 @@
{
// Iconify top frame.
topFrame.setLocation(OrigineX, OrigineY);
- topFrame.setState(Frame.ICONIFIED);
+ // FIXME: topFrame.setState(Frame.ICONIFIED);
//topFrame.show();
}
diff -urN jlgui-orig/src/javazoom/jlGui/playlist/ui/MP3Files.java jlgui/src/javazoom/jlGui/playlist/ui/MP3Files.java
--- jlgui-orig/src/javazoom/jlGui/playlist/ui/MP3Files.java 2003-06-18 05:48:50.000000000 +0800
+++ jlgui/src/javazoom/jlGui/playlist/ui/MP3Files.java 2004-04-05 12:05:15.000000000 +0800
@@ -40,7 +40,7 @@
* @author: JOHN YANG
* @date: 02/11/2002
*/
-public class MP3Files extends Window implements ActionListener
+public class MP3Files extends Frame implements ActionListener
{
//private FileDialog FD = null ; // use for add music to playlist
@@ -111,7 +111,7 @@
*/
public MP3Files(Frame parent, Player player, Playlist playlist, SkinLoader skl, int xPos, int yPos, boolean showit)
{
- super(parent);
+ // super(parent);
setLayout(null);
addMouseListener(new MouseAdapter()
{
diff -urN jlgui-orig/src/javazoom/jlGui/skin/SkinLoader.java jlgui/src/javazoom/jlGui/skin/SkinLoader.java
--- jlgui-orig/src/javazoom/jlGui/skin/SkinLoader.java 2002-11-24 23:21:28.000000000 +0800
+++ jlgui/src/javazoom/jlGui/skin/SkinLoader.java 2004-04-05 16:16:09.000000000 +0800
@@ -71,35 +71,25 @@
*/
public void loadImages() throws Exception
{
- ZipEntry entry = _zis.getNextEntry();
- while (entry != null)
+ ZipEntry entry;
+ int counter = 0;
+ while ((entry = _zis.getNextEntry()) != null)
{
- if( entry.getName().toLowerCase().endsWith("bmp") )
+ System.out.println("Counter goes " + counter++);
+
+ if( entry.getName().toLowerCase().endsWith("bmp") )
{
BMPLoader bmp = new BMPLoader();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buffer[] = new byte [256] ;
- do
- {
- int bytesRead = _zis.read(buffer);
- if(bytesRead == -1)
- break;
- baos.write(buffer, 0, bytesRead);
- } while(true);
+ int bytesRead;
+ while ( (bytesRead = _zis.read(buffer)) != -1)
+ baos.write(buffer, 0, bytesRead);
baos.close();
- /* modify by John Yang $$$$$$$$$$$$$
- StringTokenizer strtoken = new StringTokenizer(entry.getName().toLowerCase(), "/");
- String name;
- for(name = entry.getName().toLowerCase(); strtoken.hasMoreTokens(); name = (String)strtoken.nextElement())
- {
- // System.out.println ("Put skin bmp " + name) ;
- _images.put(name, bmp.getBMPImage(new ByteArrayInputStream(baos.toByteArray())));
- }
- */
String name = entry.getName().toLowerCase() ;
int pos = name.lastIndexOf ("/") ;
if ( pos != -1 ) name = name.substring (pos+1) ;
- //System.out.println ("Put skin bmp " + name) ;
+ System.out.println ("Put skin bmp " + name) ;
_images.put(name, bmp.getBMPImage(new ByteArrayInputStream(baos.toByteArray())));
}
// Added by John Yang (Read others entries as TXT) - 02/05/2001
@@ -120,7 +110,6 @@
if ( pos != -1 ) name = name.substring (pos+1) ;
_images.put (name, tmp.toString()) ;
}
- entry = _zis.getNextEntry();
}
_zis.close();
}
diff -urN jlgui-orig/src/kaffex/swing/Icon.java jlgui/src/kaffex/swing/Icon.java
--- jlgui-orig/src/kaffex/swing/Icon.java 1970-01-01 08:00:00.000000000 +0800
+++ jlgui/src/kaffex/swing/Icon.java 2004-04-05 14:15:51.000000000 +0800
@@ -0,0 +1,48 @@
+/* Icon.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package kaffex.swing;
+
+import java.awt.Component;
+import java.awt.Graphics;
+
+public interface Icon
+{
+ int getIconHeight();
+ int getIconWidth();
+ void paintIcon(Component c, Graphics g, int x, int y);
+}
diff -urN jlgui-orig/src/kaffex/swing/ImageIcon.java jlgui/src/kaffex/swing/ImageIcon.java
--- jlgui-orig/src/kaffex/swing/ImageIcon.java 1970-01-01 08:00:00.000000000 +0800
+++ jlgui/src/kaffex/swing/ImageIcon.java 2004-04-05 14:16:13.000000000 +0800
@@ -0,0 +1,101 @@
+/* ImageIcon.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package kaffex.swing;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.MediaTracker;
+import java.awt.Toolkit;
+import java.io.Serializable;
+import java.net.URL;
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+
+public class ImageIcon implements Icon
+{
+ Image image;
+ String file, descr;
+ Component observer;
+
+ public ImageIcon(String s)
+ {
+ this(s, "");
+ }
+
+ public ImageIcon(String file,
+ String descr)
+ {
+ this.file = file;
+ this.descr = descr;
+
+ image = Toolkit.getDefaultToolkit().getImage(file);
+ if (image == null) {
+ return;
+ }
+ //loadImage(image);
+ }
+
+ // not in SUN's spec !!!
+ public void setParent(Component p)
+ {
+ observer = p;
+ }
+
+ public Image getImage()
+ { return image; }
+
+ public String getDescription()
+ { return descr; }
+ public void setDescription(String description)
+ { this.descr = description; }
+
+ public int getIconHeight()
+ { return image.getHeight(observer); }
+ public int getIconWidth()
+ { return image.getWidth(observer); }
+
+ public void paintIcon(Component c,
+ Graphics g,
+ int x,
+ int y)
+ {
+ g.drawImage(image, x, y, observer);
+ }
+}
More information about the kaffe
mailing list